-
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.
refactor: adjust element controller (#5513)
* refactor(runtime): element split draw to draw and computeDrawData * feat(utils): add parentIdOf util * refactor(runtime): element controller use data flow * refactor(utils): toGraphlibData does a shallow copy * refactor: base-shape set visibility, setVisibility support keep raw attributes * refactor(runtime): refactor element controller, merge runtime style into model * test: update test case and snapshots * test(elements): add test case and snapshots * chore(site): update site demo * refactor(runtime): add syntax sugar for runtime api * test: remove layout case demo * refactor(animation): recover to enter, exit animation stage * refactor(runtime): add frontElement, backElement api * refactor(runtime): add showElement, hideElement API * refactor(behaviors): drag-node adpat new api
- Loading branch information
Showing
86 changed files
with
5,795 additions
and
916 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Graph } from '@/src'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const elementPosition: 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' }, | ||
], | ||
}, | ||
node: { | ||
style: { | ||
size: 20, | ||
}, | ||
}, | ||
}); | ||
|
||
await graph.render(); | ||
|
||
elementPosition.form = (panel) => { | ||
const config = { | ||
element: 'node-1', | ||
x: 50, | ||
y: 50, | ||
}; | ||
|
||
const translate = () => { | ||
graph.translateElementTo( | ||
{ | ||
[config.element]: [config.x, config.y], | ||
}, | ||
false, | ||
); | ||
}; | ||
|
||
const element = panel.add(config, 'element', ['node-1', 'node-2', 'node-3']).onChange((id: string) => { | ||
const position = graph.getElementPosition(id); | ||
x.setValue(position[0]); | ||
y.setValue(position[1]); | ||
}); | ||
const x = panel.add(config, 'x', 0, 300, 1).onChange(translate); | ||
const y = panel.add(config, 'y', 0, 300, 1).onChange(translate); | ||
return [element, x, y]; | ||
}; | ||
|
||
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,87 @@ | ||
import { Graph } from '@/src'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const elementState: STDTestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data: { | ||
nodes: [ | ||
{ id: 'node-1', style: { x: 50, y: 50, states: ['active', 'selected'] } }, | ||
{ id: 'node-2', style: { x: 200, y: 50 } }, | ||
{ id: 'node-3', style: { x: 125, y: 150, states: ['active'] } }, | ||
], | ||
edges: [ | ||
{ id: 'edge-1', source: 'node-1', target: 'node-2', style: { states: ['active'] } }, | ||
{ id: 'edge-2', source: 'node-2', target: 'node-3' }, | ||
{ id: 'edge-3', source: 'node-3', target: 'node-1' }, | ||
], | ||
}, | ||
theme: 'light', | ||
node: { | ||
style: { | ||
lineWidth: 1, | ||
size: 20, | ||
}, | ||
state: { | ||
active: { | ||
lineWidth: 2, | ||
}, | ||
selected: { | ||
fill: 'pink', | ||
}, | ||
}, | ||
animation: { | ||
update: [{ fields: ['lineWidth', 'fill'] }], | ||
}, | ||
}, | ||
edge: { | ||
style: { | ||
lineWidth: 1, | ||
}, | ||
state: { | ||
active: { | ||
lineWidth: 2, | ||
stroke: 'pink', | ||
}, | ||
}, | ||
animation: { | ||
update: [ | ||
{ | ||
fields: ['lineWidth', 'stroke'], | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
await graph.render(); | ||
|
||
elementState.form = (panel) => { | ||
const config = { | ||
element: 'node-1', | ||
active: true, | ||
selected: true, | ||
}; | ||
|
||
const setState = () => { | ||
const state: string[] = []; | ||
if (config.active) state.push('active'); | ||
if (config.selected) state.push('selected'); | ||
graph.setElementState({ [config.element]: state }); | ||
}; | ||
|
||
const element = panel | ||
.add(config, 'element', ['node-1', 'node-2', 'node-3', 'edge-1', 'edge-2', 'edge-3']) | ||
.onChange((id: string) => { | ||
const states = graph.getElementState(id); | ||
selected.setValue(states.includes('selected')); | ||
active.setValue(states.includes('active')); | ||
}); | ||
const active = panel.add(config, 'active').onChange(setState); | ||
const selected = panel.add(config, 'selected').onChange(setState); | ||
|
||
return [element, active, selected]; | ||
}; | ||
|
||
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,44 @@ | ||
import { Graph } from '@/src'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const elementVisibility: 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 } }, | ||
{ id: 'node-4', style: { x: 125, y: 200, visibility: 'hidden' } }, | ||
], | ||
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' }, | ||
], | ||
}, | ||
theme: 'light', | ||
node: { style: { size: 20, labelText: (d: any) => d.id.at(-1) } }, | ||
edge: { style: { endArrow: true, labelText: (d: any) => d.id } }, | ||
}); | ||
|
||
await graph.render(); | ||
|
||
elementVisibility.form = (panel) => { | ||
const config = { | ||
element: 'node-1', | ||
visible: true, | ||
}; | ||
const element = panel | ||
.add(config, 'element', ['node-1', 'node-2', 'node-3', 'node-4', 'edge-1', 'edge-2', 'edge-3']) | ||
.onChange((id: string) => { | ||
visible.setValue(graph.getElementVisibility(id) !== 'hidden'); | ||
}); | ||
const visible = panel.add(config, 'visible').onChange((value: boolean) => { | ||
value ? graph.showElement(config.element) : graph.hideElement(config.element); | ||
}); | ||
return [element, visible]; | ||
}; | ||
|
||
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
Oops, something went wrong.