Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adapt combo, add drag-element / collapse-expand behaviors #5543

Merged
merged 25 commits into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
78a5618
refactor(runtime): merge into getChildrenData, getComboData, add get …
Aarebecca Mar 11, 2024
fff2fa6
refactor(runtime): move translate logic from graph to data controller
Aarebecca Mar 12, 2024
89e2826
feat(utils): add positionOf util
Aarebecca Mar 12, 2024
2dbcf2b
refactor(runtime): adjust the order of drawing combos
Aarebecca Mar 12, 2024
e4e468f
refactor(elements): sync combo position to model, adjust combo size calc
Aarebecca Mar 13, 2024
9294e45
refactor(utils): dfs provide depth info
Aarebecca Mar 13, 2024
dce9270
refactor(elements): combo sync position and zIndex
Aarebecca Mar 14, 2024
cf63f50
feat(utils): add zIndexOf util
Aarebecca Mar 14, 2024
655bd55
refactor(runtime): refactor data/element controller to fit combo update
Aarebecca Mar 14, 2024
79a61a6
test: assign graph into window.graph
Aarebecca Mar 14, 2024
4df707d
refactor(elements): combo use childrenData to get marker text
Aarebecca Mar 14, 2024
7f7e331
refactor(elements): filter zIndex from graphicStyle
Aarebecca Mar 14, 2024
bf879f6
feat(utils): add getSubgraphRelatedEdges util
Aarebecca Mar 14, 2024
1fa6654
refactor(animation): add combo-collapse-expand animation
Aarebecca Mar 14, 2024
5daa737
refactor(runtime): add combo collapse and expand flow
Aarebecca Mar 14, 2024
2c29c6a
fix: fix issue in data controller and base-combo
Aarebecca Mar 15, 2024
a6814f0
test: update test case and snapshots
Aarebecca Mar 15, 2024
963ad2b
feat(behaviors): support click collapse-expand, drag-combo
Aarebecca Mar 15, 2024
5e37e5d
refactor: merge drag node and drag combo into drag element
Aarebecca Mar 15, 2024
22936b8
fix(behaviors): fix issue drag element between combo wont update
Aarebecca Mar 15, 2024
c40f431
test(behaviors): add drag-element test case and snapshots
Aarebecca Mar 15, 2024
7f68fd8
test: fix snapshot
Aarebecca Mar 15, 2024
ce8eab5
test: update test case and snapshots
Aarebecca Mar 15, 2024
976dd5b
fix: fix format and types
Aarebecca Mar 15, 2024
a58b9ef
chore: adjust drag-node to drag element
Aarebecca Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -23,7 +23,7 @@ export const behaviorDragNode: STDTestCase = async (context) => {
edge: {
style: { endArrow: true },
},
behaviors: [{ type: 'drag-node' }],
behaviors: [{ type: 'drag-element' }],
});

await graph.render();
Expand All @@ -35,7 +35,7 @@ export const behaviorDragNode: STDTestCase = async (context) => {
shadow: false,
};
const handleChange = () => {
graph.setBehaviors([{ type: 'drag-node', ...config }]);
graph.setBehaviors([{ type: 'drag-element', ...config }]);
};
return [
panel.add(config, 'enable').onChange(handleChange),
Expand Down
81 changes: 81 additions & 0 deletions packages/g6/__tests__/demo/case/combo-expand-collapse.ts
@@ -0,0 +1,81 @@
import { Graph } from '@/src';
import { isObject } from '@antv/util';
import type { STDTestCase } from '../types';

export const comboExpandCollapse: STDTestCase = async (context) => {
const graph = new Graph({
...context,
data: {
nodes: [
{ id: 'node-1', style: { parentId: 'combo-2', x: 120, y: 100 } },
{ id: 'node-2', style: { parentId: 'combo-1', x: 300, y: 200 } },
{ id: 'node-3', style: { parentId: 'combo-1', x: 200, y: 300 } },
],
edges: [
{ id: 'edge-1', source: 'node-1', target: 'node-2' },
{ id: 'edge-2', source: 'node-2', target: 'node-3' },
],
combos: [
{
id: 'combo-1',
style: { type: 'rect', parentId: 'combo-2', collapsed: true },
},
{ id: 'combo-2' },
],
},
node: {
style: {
labelText: (d) => d.id,
},
},
combo: {
style: {
labelText: (d) => d.id,
lineDash: 0,
collapsedLineDash: [5, 5],
},
},
behaviors: [{ type: 'drag-element' }, 'collapse-expand'],
});

await graph.render();

comboExpandCollapse.form = (panel) => {
const config = {
element: 'combo-1',
dropEffect: 'move',
collapse: () => graph.collapse(config.element),
expand: () => graph.expand(config.element),
};

return [
panel
.add(config, 'element', {
'combo-1': 'combo-1',
'combo-2': 'combo-2',
'combo-3': 'combo-3',
'combo-4': 'combo-4',
})
.name('Combo'),
panel.add(config, 'collapse').name('Collapse'),
panel.add(config, 'expand').name('Expand'),
panel.add(config, 'dropEffect', ['link', 'move', 'none']).onChange((value: string) => {
graph.setBehaviors((behaviors) => {
return behaviors.map((behavior) => {
if (isObject(behavior) && behavior.type === 'drag-element') {
return {
...behavior,
dropEffect: value,
};
}
return behavior;
});
});
}),
];
};

Object.assign(window, { graph });

return graph;
};
7 changes: 2 additions & 5 deletions packages/g6/__tests__/demo/case/combo.ts
Expand Up @@ -19,9 +19,6 @@ export const combo: STDTestCase = async (context) => {
},
{
id: 'combo-2',
style: {
zIndex: -10, // TODO: zIndex?
},
},
],
};
Expand All @@ -41,6 +38,7 @@ export const combo: STDTestCase = async (context) => {
collapsedLineDash: [5, 5],
},
},
behaviors: ['drag-element'],
});

await graph.render();
Expand Down Expand Up @@ -96,8 +94,7 @@ export const combo: STDTestCase = async (context) => {
graph.render();
},
collapseCombo2: () => {
graph.updateComboData((data) => [
...data,
graph.updateComboData([
{
id: 'combo-2',
style: {
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/edge-polyline.ts
Expand Up @@ -18,7 +18,7 @@ export const edgePolyline: STDTestCase = async (context) => {
type: 'polyline',
},
},
behaviors: [{ type: 'drag-node' }],
behaviors: [{ type: 'drag-element' }],
});

await graph.render();
Expand Down
39 changes: 39 additions & 0 deletions packages/g6/__tests__/demo/case/element-position-combo.ts
@@ -0,0 +1,39 @@
import { Graph } from '@/src';
import type { STDTestCase } from '../types';

export const elementPositionCombo: STDTestCase = async (context) => {
const graph = new Graph({
...context,
data: {
nodes: [
{ id: 'node-1', style: { x: 100, y: 150, parentId: 'combo-1' } },
{ id: 'node-2', style: { x: 200, y: 150, parentId: 'combo-1' } },
{ id: 'node-3', style: { x: 400, y: 200, parentId: 'combo-2' } },
{ id: 'node-4', style: { x: 150, y: 300, parentId: 'combo-3' } },
],
combos: [
{ id: 'combo-1', style: { parentId: 'combo-2' } },
{ id: 'combo-2' },
{ id: 'combo-3', style: { parentId: 'combo-1' } },
],
},
node: {
style: {
size: 20,
labelWordWrapWidth: 200,
labelText: (d) => d.id,
},
},
combo: {
style: {
labelText: (d) => d.id,
},
},
padding: 20,
autoFit: 'view',
});

await graph.render();

return graph;
};
45 changes: 45 additions & 0 deletions packages/g6/__tests__/demo/case/element-z-index.ts
@@ -0,0 +1,45 @@
import { Graph } from '@/src';
import type { STDTestCase } from '../types';

export const elementZIndex: STDTestCase = async (context) => {
const graph = new Graph({
...context,
data: {
nodes: [
{ id: 'node-1', style: { x: 50, y: 50 } },
{ id: 'node-2', style: { x: 200, y: 50 } },
{ id: 'node-3', style: { x: 125, y: 150 } },
],
edges: [
{ id: 'edge-1', source: 'node-1', target: 'node-2' },
{ id: 'edge-2', source: 'node-2', target: 'node-3' },
{ id: 'edge-3', source: 'node-3', target: 'node-1' },
],
combos: [
{ id: 'combo-1', style: { x: 50, y: 250 } },
{ id: 'combo-2', style: { x: 50, y: 250, parentId: 'combo-1' } },
{ id: 'combo-3', style: { x: 150, y: 250, parentId: 'combo-2' } },
{ id: 'combo-4', style: { x: 350, y: 250 } },
],
},
node: {
style: {
size: 40,
labelText: (d) => d.id,
labelWordWrapWidth: 200,
color: (d, index) => ['red', 'green', 'blue'][index],
},
},
combo: {
style: {
labelText: (d) => d.id,
color: (d, index: number) => ['pink', 'cyan', 'purple', 'orange'][index],
},
},
behaviors: ['drag-element'],
});

await graph.render();

return graph;
};
5 changes: 4 additions & 1 deletion packages/g6/__tests__/demo/case/index.ts
@@ -1,14 +1,17 @@
export * from './behavior-drag-canvas';
export * from './behavior-drag-node';
export * from './behavior-drag-element';
export * from './behavior-zoom-canvas';
export * from './combo';
export * from './combo-expand-collapse';
export * from './common-graph';
export * from './edge-polyline';
export * from './element-change-type';
export * from './element-port';
export * from './element-position';
export * from './element-position-combo';
export * from './element-state';
export * from './element-visibility';
export * from './element-z-index';
export * from './graph-event';
export * from './layout-circular-basic';
export * from './layout-circular-configuration-translate';
Expand Down
Expand Up @@ -16,7 +16,7 @@ export const layoutCircularConfigurationTranslate: STDTestCase = async (context)
layout: {
type: 'circular',
},
behaviors: ['drag-canvas', 'drag-node'],
behaviors: ['drag-canvas', 'drag-element'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-combo-combined.ts
Expand Up @@ -22,7 +22,7 @@ export const layoutComboCombined: STDTestCase = async (context) => {
return { stroke: color || '#99ADD1', lineWidth: size || 1 };
},
},
behaviors: ['drag-combo', 'drag-node', 'drag-canvas', 'zoom-canvas'],
behaviors: ['drag-element', 'drag-canvas', 'zoom-canvas'],
autoFit: 'view',
});

Expand Down
Expand Up @@ -7,7 +7,7 @@ export const layoutCompactBoxBasic: STDTestCase = async (context) => {
...context,
autoFit: 'view',
data: Utils.treeToGraphData(data),
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-node'],
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element'],
node: {
style: {
labelText: (data) => data.id,
Expand Down
Expand Up @@ -8,7 +8,7 @@ export const layoutCompactBoxTopToBottom: STDTestCase = async (context) => {
...context,
autoFit: 'view',
data: Utils.treeToGraphData(data),
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-node'],
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element'],
node: {
style: {
labelText: (data) => data.id,
Expand Down
Expand Up @@ -45,7 +45,7 @@ export const layoutCompactBoxLeftAlign: STDTestCase = async (context) => {
return 20;
},
},
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-node'],
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element'],
animation: false,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-concentric.ts
Expand Up @@ -12,7 +12,7 @@ export const layoutConcentric: STDTestCase = async (context) => {
maxLevelDiff: 0.5,
preventOverlap: true,
},
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node'],
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-element'],
animation: false,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-dagre-flow-combo.ts
Expand Up @@ -39,7 +39,7 @@ export const layoutDagreFlowCombo: STDTestCase = async (context) => {
ranksep: 50,
nodesep: 5,
},
behaviors: ['drag-combo', 'drag-node', 'drag-canvas', 'zoom-canvas'],
behaviors: ['drag-element', 'drag-canvas', 'zoom-canvas'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-dagre-flow.ts
Expand Up @@ -31,7 +31,7 @@ export const layoutDagreFlow: STDTestCase = async (context) => {
ranksep: 70,
controlPoints: true,
},
behaviors: ['drag-combo', 'drag-node', 'drag-canvas', 'zoom-canvas'],
behaviors: ['drag-element', 'drag-canvas', 'zoom-canvas'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-dendrogram-basic.ts
Expand Up @@ -25,7 +25,7 @@ export const layoutDendrogramBasic: STDTestCase = async (context) => {
nodeSep: 36,
rankSep: 250,
},
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-node', 'collapse-expand-tree'],
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element', 'collapse-expand-tree'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-dendrogram-tb.ts
Expand Up @@ -32,7 +32,7 @@ export const layoutDendrogramTb: STDTestCase = async (context) => {
nodeSep: 40,
rankSep: 100,
},
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-node', 'collapse-expand-tree'],
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-element', 'collapse-expand-tree'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-force.ts
Expand Up @@ -8,7 +8,7 @@ export const layoutForce: STDTestCase = async (context) => {
data,
padding: 20,
autoFit: 'view',
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node', 'click-select'],
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-element', 'click-select'],
layout: {
type: 'force',
},
Expand Down
Expand Up @@ -17,7 +17,7 @@ export const layoutFruchtermanBasic: STDTestCase = async (context) => {
gravity: 5,
speed: 5,
},
behaviors: ['drag-canvas', 'drag-node'],
behaviors: ['drag-canvas', 'drag-element'],
});

await graph.render();
Expand Down
Expand Up @@ -22,7 +22,7 @@ export const layoutFruchtermanCluster: STDTestCase = async (context) => {
clustering: true,
nodeClusterBy: 'cluster',
},
behaviors: ['drag-canvas', 'drag-node'],
behaviors: ['drag-canvas', 'drag-element'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-fruchterman-fix.ts
Expand Up @@ -11,7 +11,7 @@ export const layoutFruchtermanFix: STDTestCase = async (context) => {
speed: 10,
maxIteration: 500,
},
behaviors: ['drag-canvas', 'drag-node'],
behaviors: ['drag-canvas', 'drag-element'],
});

graph.on('node:dragstart', function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-grid.ts
Expand Up @@ -15,7 +15,7 @@ export const layoutGrid: STDTestCase = async (context) => {
type: 'grid',
sortBy: 'cluster',
},
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-node', 'click-select'],
behaviors: ['zoom-canvas', 'drag-canvas', 'drag-element', 'click-select'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-mds.ts
Expand Up @@ -18,7 +18,7 @@ export const layoutMDS: STDTestCase = async (context) => {
type: 'mds',
linkDistance: 100,
},
behaviors: ['drag-node', 'drag-canvas', 'zoom-canvas', 'click-select'],
behaviors: ['drag-element', 'drag-canvas', 'zoom-canvas', 'click-select'],
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-radial-basic.ts
Expand Up @@ -16,7 +16,7 @@ export const layoutRadialBasic: STDTestCase = async (context) => {
type: 'radial',
unitRadius: 50,
},
behaviors: ['drag-canvas', 'drag-node'],
behaviors: ['drag-canvas', 'drag-element'],
});

await graph.render();
Expand Down