Skip to content

Commit

Permalink
refactor: move type config to element.type (#5661)
Browse files Browse the repository at this point in the history
* refactor: redefine type of id

* refactor: move type config
  • Loading branch information
Aarebecca authored Apr 18, 2024
1 parent 54bc5f9 commit 7efd20e
Show file tree
Hide file tree
Showing 117 changed files with 664 additions and 579 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const behaviorDragCanvas: TestCase = async (context) => {
renderer,
data,
node: {
type: 'sphere',
style: {
type: 'sphere',
materialType: 'phong',
labelText: '',
x: (d) => +d.style!.x! + 250,
Expand All @@ -24,9 +24,7 @@ export const behaviorDragCanvas: TestCase = async (context) => {
palette: 'spectral',
},
edge: {
style: {
type: 'line3d',
},
type: 'line3d',
},
behaviors: [
'drag-canvas-3d',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const behaviorObserveCanvas: TestCase = async (context) => {
renderer,
data,
node: {
type: 'sphere',
style: {
type: 'sphere',
materialType: 'phong',
labelText: '',
x: (d) => +d.style!.x! + 250,
Expand All @@ -25,9 +25,7 @@ export const behaviorObserveCanvas: TestCase = async (context) => {
palette: 'spectral',
},
edge: {
style: {
type: 'line3d',
},
type: 'line3d',
},
behaviors: ['zoom-canvas-3d', { key: 'observe-canvas-3d', type: 'observe-canvas-3d' }],
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const behaviorRollCanvas: TestCase = async (context) => {
renderer,
data,
node: {
type: 'sphere',
style: {
type: 'sphere',
materialType: 'phong',
labelText: '',
x: (d) => +d.style!.x! + 250,
Expand All @@ -24,9 +24,7 @@ export const behaviorRollCanvas: TestCase = async (context) => {
palette: 'spectral',
},
edge: {
style: {
type: 'line3d',
},
type: 'line3d',
},
behaviors: ['roll-canvas-3d'],
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const behaviorZoomCanvas: TestCase = async (context) => {
renderer,
data,
node: {
type: 'sphere',
style: {
type: 'sphere',
materialType: 'phong',
labelText: '',
x: (d) => +d.style!.x! + 250,
Expand All @@ -24,9 +24,7 @@ export const behaviorZoomCanvas: TestCase = async (context) => {
palette: 'spectral',
},
edge: {
style: {
type: 'line3d',
},
type: 'line3d',
},
behaviors: ['zoom-canvas-3d'],
plugins: [
Expand Down
9 changes: 3 additions & 6 deletions packages/g6-extension-3d/__tests__/demos/layer-top.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const layerTop: TestCase = async (context) => {
data.nodes = nodes.map(({ name, pos, layer }: any) => ({
id: name,
data: { layer },
type: 'sphere',
style: {
type: 'sphere',
radius: 10,
color: colors[layer - 1],
materialType: 'phong',
Expand All @@ -29,8 +29,8 @@ export const layerTop: TestCase = async (context) => {
new Array(3).fill(0).forEach((_, i) => {
data.nodes!.push({
id: `plane-${i + 1}`,
type: 'plane',
style: {
type: 'plane',
size: 1000,
color: colors[i],
y: -300 + 300 * i + 10,
Expand All @@ -50,12 +50,9 @@ export const layerTop: TestCase = async (context) => {
y: 100,
data,
zoom: 0.4,
node: {
style: {},
},
edge: {
type: 'line3d',
style: {
type: 'line3d',
lineWidth: 5,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const layoutD3Force3D: TestCase = async (context) => {
type: 'd3-force-3d',
},
node: {
type: 'sphere',
style: {
type: 'sphere',
materialType: 'phong',
},
palette: {
Expand All @@ -30,9 +30,7 @@ export const layoutD3Force3D: TestCase = async (context) => {
},
},
edge: {
style: {
type: 'line3d',
},
type: 'line3d',
},
behaviors: ['observe-canvas-3d', 'zoom-canvas-3d'],
plugins: [
Expand Down
6 changes: 2 additions & 4 deletions packages/g6-extension-3d/__tests__/demos/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ export const positionValidate: TestCase = async (context) => {
],
},
node: {
type: 'sphere',
style: {
type: 'sphere',
materialType: 'phong',
labelText: '',
},
palette: 'spectral',
},
edge: {
style: {
type: 'line3d',
},
type: 'line3d',
},
behaviors: ['drag-canvas-3d'],
plugins: [
Expand Down
71 changes: 38 additions & 33 deletions packages/g6-extension-3d/__tests__/demos/shapes.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
import { Graph, register } from '@antv/g6';
import { Capsule, Cone, Cube, Cylinder, Light, Plane, Sphere, Torus, renderer } from '../../src';
import type { NodeData } from '@antv/g6';
import { ExtensionCategory, Graph, register } from '@antv/g6';
import { Capsule, Cone, Cube, Cylinder, Light, ObserveCanvas3D, Plane, Sphere, Torus, renderer } from '../../src';

export const shapes: TestCase = async (context) => {
register('plugin', '3d-light', Light);
register('node', 'sphere', Sphere);
register('node', 'plane', Plane);
register('node', 'cylinder', Cylinder);
register('node', 'cone', Cone);
register('node', 'cube', Cube);
register('node', 'capsule', Capsule);
register('node', 'torus', Torus);
register(ExtensionCategory.PLUGIN, '3d-light', Light);
register(ExtensionCategory.NODE, 'sphere', Sphere);
register(ExtensionCategory.NODE, 'plane', Plane);
register(ExtensionCategory.NODE, 'cylinder', Cylinder);
register(ExtensionCategory.NODE, 'cone', Cone);
register(ExtensionCategory.NODE, 'cube', Cube);
register(ExtensionCategory.NODE, 'capsule', Capsule);
register(ExtensionCategory.NODE, 'torus', Torus);
register(ExtensionCategory.BEHAVIOR, 'observe-canvas-3d', ObserveCanvas3D);

const nodes: NodeData[] = [
{
id: '1',
type: 'sphere',
style: {
texture: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*cdTdTI2bNl8AAAAAAAAAAAAADmJ7AQ/original',
},
},
{ id: '2', type: 'plane', style: { size: 50 } },
{ id: '3', type: 'cylinder' },
{ id: '4', type: 'cone' },
{
id: '5',
type: 'cube',
style: {
texture: 'https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*8TlCRIsKeUkAAAAAAAAAAAAAARQnAQ',
},
},
{ id: '6', type: 'capsule' },
{ id: '7', type: 'torus' },
];

const graph = new Graph({
...context,
renderer,
data: {
nodes: [
{
id: '1',
style: {
type: 'sphere',
texture: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*cdTdTI2bNl8AAAAAAAAAAAAADmJ7AQ/original',
},
},
{ id: '2', style: { type: 'plane', size: 50 } },
{ id: '3', style: { type: 'cylinder' } },
{ id: '4', style: { type: 'cone' } },
{
id: '5',
style: {
type: 'cube',
texture: 'https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*8TlCRIsKeUkAAAAAAAAAAAAAARQnAQ',
},
},
{ id: '6', style: { type: 'capsule' } },
{ id: '7', style: { type: 'torus' } },
],
nodes,
},
node: {
style: {
materialType: 'phong',
x: (_, i) => 100 + (i % 5) * 100,
y: (_, i) => 100 + Math.floor(i / 5) * 100,
x: (d) => 100 + (nodes.findIndex((n) => n.id === d.id) % 5) * 100,
y: (d) => 100 + Math.floor(nodes.findIndex((n) => n.id === d.id) / 5) * 100,
},
},
plugins: [
Expand All @@ -52,6 +56,7 @@ export const shapes: TestCase = async (context) => {
},
},
],
behaviors: ['observe-canvas-3d'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6-extension-3d/__tests__/demos/solar-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export const solarSystem: TestCase = async (context) => {
],
},
node: {
type: 'sphere',
style: {
type: 'sphere',
materialShininess: 0,
labelText: (d) => d.id,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const animationElementEdgeCubic: TestCase = async (context) => {
],
},
edge: {
type: 'cubic',
style: {
type: 'cubic',
lineWidth: 2,
stroke: '#1890FF',
labelText: 'cubic-edge',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const animationElementEdgeQuadratic: TestCase = async (context) => {
],
},
edge: {
type: 'quadratic',
style: {
type: 'quadratic',
lineWidth: 2,
stroke: '#1890FF',
labelText: 'quadratic-edge',
Expand Down
4 changes: 2 additions & 2 deletions packages/g6/__tests__/demos/animation-element-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export const animationElementState: TestCase = async (context) => {
],
},
node: {
type: 'breathing-circle',
style: {
type: 'breathing-circle',
halo: true,
haloLineWidth: 5,
},
},
edge: {
type: 'fly-line',
style: {
type: 'fly-line',
lineDash: [10, 10],
},
},
Expand Down
6 changes: 5 additions & 1 deletion packages/g6/__tests__/demos/combo-expand-collapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export const comboExpandCollapse: TestCase = async (context) => {
combos: [
{
id: 'combo-1',
style: { type: 'rect', parentId: 'combo-2', collapsed: true },
type: 'rect',
style: {
parentId: 'combo-2',
collapsed: true,
},
},
{ id: 'combo-2' },
],
Expand Down
5 changes: 4 additions & 1 deletion packages/g6/__tests__/demos/combo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export const combo: TestCase = async (context) => {
combos: [
{
id: 'combo-1',
style: { type: 'rect', parentId: 'combo-2' },
type: 'rect',
style: {
parentId: 'combo-2',
},
},
{
id: 'combo-2',
Expand Down
4 changes: 2 additions & 2 deletions packages/g6/__tests__/demos/element-change-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const elementChangeType: TestCase = async (context) => {
...context,
data: {
nodes: [
{ id: 'node-1', style: { x: 100, y: 100, type: 'rect', color: 'transparent', stroke: '#1783ff' } },
{ id: 'node-1', type: 'rect', style: { x: 100, y: 100, color: 'transparent', stroke: '#1783ff' } },
{ id: 'node-2', style: { x: 200, y: 100 } },
],
edges: [{ id: 'edge-1', source: 'node-1', target: 'node-2' }],
Expand All @@ -22,7 +22,7 @@ export const elementChangeType: TestCase = async (context) => {
const options = { Circle: 'circle', Rect: 'rect', Diamond: 'diamond', Star: 'star' };

const changeType = (id: string, type: string) => {
graph.updateNodeData([{ id, style: { type } }]);
graph.updateNodeData([{ id, type }]);
graph.draw();
};

Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demos/element-edge-arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const elementEdgeArrow: TestCase = async (context) => {
...context,
data,
edge: {
type: 'line', // 👈🏻 Edge shape type.
style: {
type: 'line', // 👈🏻 Edge shape type.
labelText: (d) => d.id!,
labelBackground: true,
endArrow: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const elementEdgeCubicHorizontal: TestCase = async (context) => {
},
},
edge: {
type: 'cubic-horizontal', // 👈🏻 Edge shape type.
style: {
type: 'cubic-horizontal', // 👈🏻 Edge shape type.
labelText: (d) => d.id!,
labelBackground: true,
endArrow: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demos/element-edge-cubic-vertical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const elementEdgeCubicVertical: TestCase = async (context) => {
},
},
edge: {
type: 'cubic-vertical', // 👈🏻 Edge shape type.
style: {
type: 'cubic-vertical', // 👈🏻 Edge shape type.
labelText: (d) => d.id!,
labelBackground: true,
endArrow: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demos/element-edge-cubic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const elementEdgeCubic: TestCase = async (context) => {
...context,
data,
edge: {
type: 'cubic', // 👈🏻 Edge shape type.
style: {
type: 'cubic', // 👈🏻 Edge shape type.
labelText: (d) => d.id!,
labelBackground: true,
endArrow: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demos/element-edge-custom-arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const elementEdgeCustomArrow: TestCase = async (context) => {
...context,
data,
edge: {
type: 'line', // 👈🏻 Edge shape type.
style: {
type: 'line', // 👈🏻 Edge shape type.
color: '#F6BD16',
labelText: (d) => d.id!,
labelBackground: true,
Expand Down
Loading

0 comments on commit 7efd20e

Please sign in to comment.