-
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(test): demo support disable default grid * refactor(runtime): uniform graph lifecycle event, emit size change event * feat(utils): add mod util * feat(plugin): add grid plugin * refactor(register): adjust extension type definitions * refactor(runtime): adjust rest widget define * refactor(test): add test case
- Loading branch information
Showing
26 changed files
with
394 additions
and
82 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,54 @@ | ||
import { Graph, GraphEvent } from '@/src'; | ||
import data from '@@/dataset/cluster.json'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const graphEvent: STDTestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data, | ||
node: { | ||
style: { | ||
size: 20, | ||
}, | ||
}, | ||
autoResize: true, | ||
layout: { type: 'd3force' }, | ||
}); | ||
|
||
const events = [ | ||
GraphEvent.BEFORE_RENDER, | ||
GraphEvent.AFTER_RENDER, | ||
GraphEvent.BEFORE_DRAW, | ||
GraphEvent.AFTER_DRAW, | ||
GraphEvent.BEFORE_LAYOUT, | ||
GraphEvent.AFTER_LAYOUT, | ||
GraphEvent.BEFORE_SIZE_CHANGE, | ||
GraphEvent.AFTER_SIZE_CHANGE, | ||
]; | ||
|
||
const now = performance.now(); | ||
events.forEach((event) => { | ||
graph.on(event, (e: any) => { | ||
console.log('Time: ', performance.now() - now); | ||
console.log(event, e); | ||
}); | ||
}); | ||
|
||
await graph.render(); | ||
|
||
graphEvent.form = (panel) => { | ||
const config = { | ||
note: 'See The Console', | ||
resize: () => { | ||
const $container = document.getElementById('container')!; | ||
Object.assign($container.style, { width: '600px', height: '600px' }); | ||
window.dispatchEvent(new Event('resize')); | ||
}, | ||
follow: false, | ||
size: 20, | ||
}; | ||
return [panel.add(config, 'note').name('⚠️ Note').disable()]; | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Graph } from '@/src'; | ||
import data from '@@/dataset/cluster.json'; | ||
import { isObject } from '@antv/util'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const pluginGridLine: STDTestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data, | ||
node: { | ||
style: { | ||
size: 20, | ||
}, | ||
}, | ||
autoResize: true, | ||
layout: { type: 'd3force' }, | ||
behaviors: ['drag-canvas'], | ||
plugins: [{ type: 'grid-line', follow: false }], | ||
}); | ||
|
||
await graph.render(); | ||
|
||
pluginGridLine.form = (panel) => { | ||
const config = { | ||
resize: () => { | ||
const $container = document.getElementById('container')!; | ||
Object.assign($container.style, { width: '600px', height: '600px' }); | ||
window.dispatchEvent(new Event('resize')); | ||
}, | ||
follow: false, | ||
size: 20, | ||
}; | ||
return [ | ||
panel.add(config, 'resize').name('Emit Resize'), | ||
panel | ||
.add(config, 'follow') | ||
.name('Follow The Graph') | ||
.onChange((follow: boolean) => { | ||
graph.setPlugins((plugins) => | ||
plugins.map((plugin) => { | ||
if (isObject(plugin) && plugin.type === 'grid-line') return { ...plugin, follow }; | ||
return plugin; | ||
}), | ||
); | ||
}), | ||
panel | ||
.add(config, 'size', 10, 50, 5) | ||
.name('Grid Size') | ||
.onChange((size: number) => { | ||
graph.setPlugins((plugins) => | ||
plugins.map((plugin) => { | ||
if (isObject(plugin) && plugin.type === 'grid-line') return { ...plugin, size }; | ||
return plugin; | ||
}), | ||
); | ||
}), | ||
]; | ||
}; | ||
|
||
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
3 changes: 2 additions & 1 deletion
3
packages/g6/__tests__/unit/behaviors/behavior-drag-canvas.spec.ts
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
45 changes: 45 additions & 0 deletions
45
packages/g6/__tests__/unit/plugins/plugin-grid-line.spec.ts
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 type { Graph } from '@/src'; | ||
import { pluginGridLine } from '@@/demo/case'; | ||
import { createDemoGraph } from '@@/utils'; | ||
|
||
describe('plugin grid line', () => { | ||
let graph: Graph; | ||
let gridLineElement: HTMLCollectionOf<HTMLElement>; | ||
|
||
beforeAll(async () => { | ||
graph = await createDemoGraph(pluginGridLine, { animation: false }); | ||
gridLineElement = graph | ||
.getCanvas() | ||
.getContainer()! | ||
.getElementsByClassName('g6-grid-line')! as HTMLCollectionOf<HTMLElement>; | ||
}); | ||
|
||
it('default status', () => { | ||
expect(graph.getPlugins()).toEqual([{ type: 'grid-line', follow: false }]); | ||
expect(gridLineElement.length).toBe(1); | ||
expect(gridLineElement[0].style.backgroundSize).toBe('20px 20px'); | ||
}); | ||
|
||
it('update grid line', () => { | ||
graph.setPlugins((plugins) => | ||
plugins.map((plugin) => { | ||
if (typeof plugin === 'object') { | ||
return { | ||
...plugin, | ||
follow: true, | ||
size: 30, | ||
}; | ||
} | ||
return plugin; | ||
}), | ||
); | ||
|
||
expect(graph.getPlugins()).toEqual([{ type: 'grid-line', follow: true, size: 30 }]); | ||
expect(gridLineElement[0].style.backgroundSize).toBe('30px 30px'); | ||
}); | ||
|
||
it('drag', () => { | ||
graph.emit('aftertransform', { data: { translate: [10, 10] } }); | ||
expect(gridLineElement[0].style.backgroundPosition).toBe('10px 10px'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import type { DragCanvasOptions } from './drag-canvas'; | ||
import type { ZoomCanvasOptions } from './zoom-canvas'; | ||
|
||
export { BaseBehavior } from './base-behavior'; | ||
export { DragCanvas } from './drag-canvas'; | ||
export { ZoomCanvas } from './zoom-canvas'; | ||
|
||
export type { BaseBehaviorOptions } from './base-behavior'; | ||
export type { DragCanvasOptions, ZoomCanvasOptions }; | ||
export type BuiltInBehaviorOptions = DragCanvasOptions | ZoomCanvasOptions; | ||
export type { DragCanvasOptions } from './drag-canvas'; | ||
export type { ZoomCanvasOptions } from './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
Oops, something went wrong.