-
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: add behavior controller and zoom-canvas (#5470)
* feat(utils): add parseBehaviors util * feat(constants): add events definition * refactor(event): rename Event to BaseEvent * refactor(utils): adjust events * refactor(utils): move isNode to element * feat(utils): add isEdge util * feat(utils): add eventTargetOf util * feat(runtime): add behavior controller * refactor(runtime): viewport emit standard event * feat(behaviors): add zoom-canvas * chore(test): update test env * refactor(runtime): export event, destroy behavior, add test cases
- Loading branch information
Showing
52 changed files
with
3,743 additions
and
191 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 data from '@@/dataset/cluster.json'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const behaviorZoomCanvas: STDTestCase = async (context) => { | ||
const { canvas, animation } = context; | ||
const graph = new Graph({ | ||
animation, | ||
container: canvas, | ||
data, | ||
layout: { | ||
type: 'd3force', | ||
}, | ||
node: { | ||
style: { | ||
size: 20, | ||
}, | ||
}, | ||
zoomRange: [0.5, 5], | ||
behaviors: [{ type: 'zoom-canvas' }], | ||
}); | ||
|
||
await graph.render(); | ||
|
||
behaviorZoomCanvas.form = [ | ||
{ | ||
label: 'Disable Zoom: ', | ||
type: 'input', | ||
onload: (input) => { | ||
input.onchange = (e) => { | ||
graph.setBehaviors((currBehaviors) => { | ||
return currBehaviors.map((behavior, index) => { | ||
const target = e.target as HTMLInputElement; | ||
if (index === 0 && typeof behavior === 'object') { | ||
return { ...behavior, enable: !target.checked }; | ||
} | ||
return behavior; | ||
}); | ||
}); | ||
}; | ||
}, | ||
options: { type: 'checkbox' }, | ||
}, | ||
{ | ||
type: 'button', | ||
onload: (button) => { | ||
button.innerText = 'Add Shortcut Zoom'; | ||
button.onclick = () => { | ||
graph.setBehaviors((currBehaviors) => [ | ||
...currBehaviors, | ||
{ | ||
key: 'shortcut-zoom-canvas', | ||
type: 'zoom-canvas', | ||
trigger: { | ||
zoomIn: ['Control', '='], | ||
zoomOut: ['Control', '-'], | ||
reset: ['Control', '0'], | ||
}, | ||
}, | ||
]); | ||
alert('Zoom behavior added'); | ||
}; | ||
}, | ||
}, | ||
|
||
{ | ||
type: 'button', | ||
onload: (button) => { | ||
button.innerText = 'Remove Shortcut Zoom'; | ||
button.onclick = () => { | ||
graph.setBehaviors((currBehaviors) => { | ||
return currBehaviors.slice(0, 1); | ||
}); | ||
alert('Zoom behavior removed'); | ||
}; | ||
}, | ||
}, | ||
]; | ||
|
||
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 @@ | ||
export * from './behavior-zoom-canvas'; |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './static'; | ||
export * as animations from './animation'; | ||
export * as cases from './case'; | ||
export * as statics from './static'; |
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.