-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adapt combo, add drag-element / collapse-expand behaviors (#5543)
* refactor(runtime): merge into getChildrenData, getComboData, add get getAncestorsData * refactor(runtime): move translate logic from graph to data controller * feat(utils): add positionOf util * refactor(runtime): adjust the order of drawing combos * refactor(elements): sync combo position to model, adjust combo size calc * refactor(utils): dfs provide depth info * refactor(elements): combo sync position and zIndex * feat(utils): add zIndexOf util * refactor(runtime): refactor data/element controller to fit combo update * test: assign graph into window.graph * refactor(elements): combo use childrenData to get marker text * refactor(elements): filter zIndex from graphicStyle * feat(utils): add getSubgraphRelatedEdges util * refactor(animation): add combo-collapse-expand animation * refactor(runtime): add combo collapse and expand flow * fix: fix issue in data controller and base-combo * test: update test case and snapshots * feat(behaviors): support click collapse-expand, drag-combo * refactor: merge drag node and drag combo into drag element * fix(behaviors): fix issue drag element between combo wont update * test(behaviors): add drag-element test case and snapshots * test: fix snapshot * test: update test case and snapshots * fix: fix format and types * chore: adjust drag-node to drag element
- Loading branch information
Showing
193 changed files
with
10,776 additions
and
4,185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.