-
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(plugin): add fisheye plugin (#6235)
* feat(plugin): add fisheye plugin * test: add fisheye unit tests * docs: add fisheye demo * fix: remove useless values * fix: remove undefined value
- Loading branch information
Showing
32 changed files
with
40,226 additions
and
2 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,37 @@ | ||
import data from '@@/dataset/relations.json'; | ||
import type { NodeData } from '@antv/g6'; | ||
import { Graph } from '@antv/g6'; | ||
|
||
export const pluginFisheye: TestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
autoFit: 'view', | ||
data, | ||
node: { | ||
style: { | ||
size: (datum: NodeData) => datum.id.length * 2 + 10, | ||
label: false, | ||
labelText: (datum: NodeData) => datum.id, | ||
labelBackground: true, | ||
icon: false, | ||
iconFontFamily: 'iconfont', | ||
iconText: '\ue6f6', | ||
iconFill: '#fff', | ||
}, | ||
palette: { | ||
type: 'group', | ||
field: (datum: NodeData) => datum.id, | ||
color: ['#1783FF', '#00C9C9', '#F08F56', '#D580FF'], | ||
}, | ||
}, | ||
edge: { | ||
style: { | ||
stroke: '#e2e2e2', | ||
}, | ||
}, | ||
plugins: [{ key: 'fisheye', type: 'fisheye', nodeStyle: { label: true, icon: true } }], | ||
}); | ||
|
||
await graph.render(); | ||
return graph; | ||
}; |
2,172 changes: 2,172 additions & 0 deletions
2,172
packages/g6/__tests__/snapshots/plugins/fisheye/default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,449 changes: 2,449 additions & 0 deletions
2,449
packages/g6/__tests__/snapshots/plugins/fisheye/hide-D-percent.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,459 changes: 2,459 additions & 0 deletions
2,459
packages/g6/__tests__/snapshots/plugins/fisheye/lens-style.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,425 changes: 2,425 additions & 0 deletions
2,425
packages/g6/__tests__/snapshots/plugins/fisheye/move-lens-click-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,459 changes: 2,459 additions & 0 deletions
2,459
packages/g6/__tests__/snapshots/plugins/fisheye/move-lens-click-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,561 changes: 2,561 additions & 0 deletions
2,561
packages/g6/__tests__/snapshots/plugins/fisheye/move-lens-drag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,459 changes: 2,459 additions & 0 deletions
2,459
packages/g6/__tests__/snapshots/plugins/fisheye/move-lens-pointermove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,507 changes: 2,507 additions & 0 deletions
2,507
packages/g6/__tests__/snapshots/plugins/fisheye/node-style.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,459 changes: 2,459 additions & 0 deletions
2,459
packages/g6/__tests__/snapshots/plugins/fisheye/scale-D-drag-larger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,459 changes: 2,459 additions & 0 deletions
2,459
packages/g6/__tests__/snapshots/plugins/fisheye/scale-D-drag-smaller.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,459 changes: 2,459 additions & 0 deletions
2,459
packages/g6/__tests__/snapshots/plugins/fisheye/scale-D-wheel-larger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,459 changes: 2,459 additions & 0 deletions
2,459
packages/g6/__tests__/snapshots/plugins/fisheye/scale-D-wheel-smaller.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,612 changes: 2,612 additions & 0 deletions
2,612
packages/g6/__tests__/snapshots/plugins/fisheye/scale-R-drag-larger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,408 changes: 2,408 additions & 0 deletions
2,408
packages/g6/__tests__/snapshots/plugins/fisheye/scale-R-drag-smaller.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,612 changes: 2,612 additions & 0 deletions
2,612
packages/g6/__tests__/snapshots/plugins/fisheye/scale-R-wheel-larger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,408 changes: 2,408 additions & 0 deletions
2,408
packages/g6/__tests__/snapshots/plugins/fisheye/scale-R-wheel-smaller.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,135 @@ | ||
import { pluginFisheye } from '@@/demos'; | ||
import { CommonEvent, Graph } from '@antv/g6'; | ||
import { createDemoGraph, dispatchCanvasEvent } from '../../utils'; | ||
import { emitWheelEvent } from '../../utils/dom'; | ||
|
||
describe('plugin-fisheye', () => { | ||
let graph: Graph; | ||
|
||
beforeAll(async () => { | ||
graph = await createDemoGraph(pluginFisheye, { animation: false }); | ||
}); | ||
|
||
afterAll(() => { | ||
graph.destroy(); | ||
}); | ||
|
||
it('move lens by pointermove', async () => { | ||
await expect(graph).toMatchSnapshot(__filename); | ||
|
||
dispatchCanvasEvent(graph, CommonEvent.POINTER_MOVE, { canvas: { x: 420, y: 150 } }); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'move-lens-pointermove'); | ||
}); | ||
|
||
it('move lens by drag', async () => { | ||
graph.updatePlugin({ key: 'fisheye', trigger: 'drag' }); | ||
|
||
dispatchCanvasEvent(graph, CommonEvent.CLICK, { canvas: { x: 420, y: 150 } }); | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG_START, { canvas: { x: 420, y: 150 } }); | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG, { canvas: { x: 400, y: 180 } }); | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG_END); | ||
|
||
await expect(graph).toMatchSnapshot(__filename, 'move-lens-drag'); | ||
}); | ||
|
||
it('move lens by click', async () => { | ||
graph.updatePlugin({ key: 'fisheye', trigger: 'click' }); | ||
|
||
dispatchCanvasEvent(graph, CommonEvent.CLICK, { canvas: { x: 180, y: 100 } }); | ||
await expect(graph).toMatchSnapshot(__filename, 'move-lens-click-1'); | ||
|
||
dispatchCanvasEvent(graph, CommonEvent.CLICK, { canvas: { x: 200, y: 100 } }); | ||
await expect(graph).toMatchSnapshot(__filename, 'move-lens-click-2'); | ||
}); | ||
|
||
it('scale lens R/D by wheel', async () => { | ||
graph.updatePlugin({ key: 'fisheye', scaleRBy: 'wheel', scaleDBy: 'unset' }); | ||
|
||
const emitWheelUpEvent = (count: number) => { | ||
for (let i = 0; i < count; i++) { | ||
emitWheelEvent(graph, { deltaX: 1, deltaY: 2, clientX: 420, clientY: 150 }); | ||
} | ||
}; | ||
const emitWheelDownEvent = (count: number) => { | ||
for (let i = 0; i < count; i++) { | ||
emitWheelEvent(graph, { deltaX: -1, deltaY: -2, clientX: 420, clientY: 150 }); | ||
} | ||
}; | ||
|
||
dispatchCanvasEvent(graph, CommonEvent.CLICK, { canvas: { x: 420, y: 150 } }); | ||
|
||
emitWheelUpEvent(5); | ||
await expect(graph).toMatchSnapshot(__filename, 'scale-R-wheel-larger'); | ||
emitWheelDownEvent(10); | ||
await expect(graph).toMatchSnapshot(__filename, 'scale-R-wheel-smaller'); | ||
emitWheelUpEvent(5); | ||
|
||
graph.updatePlugin({ key: 'fisheye', scaleRBy: 'unset', scaleDBy: 'wheel' }); | ||
|
||
emitWheelUpEvent(5); | ||
await expect(graph).toMatchSnapshot(__filename, 'scale-D-wheel-larger'); | ||
emitWheelDownEvent(10); | ||
await expect(graph).toMatchSnapshot(__filename, 'scale-D-wheel-smaller'); | ||
emitWheelUpEvent(5); | ||
}); | ||
|
||
it('scale lens R/D by drag', async () => { | ||
graph.updatePlugin({ key: 'fisheye', scaleRBy: 'drag', scaleDBy: 'unset' }); | ||
|
||
const emitPositionDragEvent = (count: number) => { | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG_START, { canvas: { x: 420, y: 150 } }); | ||
for (let i = 0; i < count; i++) { | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG, { dx: 1, dy: -2 }); | ||
} | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG_END); | ||
}; | ||
|
||
const emitNegativeDragEvent = (count: number) => { | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG_START, { canvas: { x: 420, y: 150 } }); | ||
for (let i = 0; i < count; i++) { | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG, { dx: -1, dy: 2 }); | ||
} | ||
dispatchCanvasEvent(graph, CommonEvent.DRAG_END); | ||
}; | ||
|
||
emitPositionDragEvent(5); | ||
await expect(graph).toMatchSnapshot(__filename, 'scale-R-drag-larger'); | ||
emitNegativeDragEvent(10); | ||
await expect(graph).toMatchSnapshot(__filename, 'scale-R-drag-smaller'); | ||
emitPositionDragEvent(5); | ||
|
||
graph.updatePlugin({ key: 'fisheye', scaleRBy: 'unset', scaleDBy: 'drag' }); | ||
|
||
emitPositionDragEvent(5); | ||
await expect(graph).toMatchSnapshot(__filename, 'scale-D-drag-larger'); | ||
emitNegativeDragEvent(10); | ||
await expect(graph).toMatchSnapshot(__filename, 'scale-D-drag-smaller'); | ||
emitPositionDragEvent(5); | ||
}); | ||
|
||
it('show D percent', async () => { | ||
graph.updatePlugin({ key: 'fisheye', showDPercent: false }); | ||
|
||
dispatchCanvasEvent(graph, CommonEvent.CLICK, { canvas: { x: 420, y: 150 } }); | ||
await expect(graph).toMatchSnapshot(__filename, 'hide-D-percent'); | ||
}); | ||
|
||
it('lens style', async () => { | ||
graph.updatePlugin({ | ||
key: 'fisheye', | ||
showDPercent: true, | ||
style: { fill: '#f00', lineDash: [5, 5], stroke: '#666' }, | ||
}); | ||
|
||
dispatchCanvasEvent(graph, CommonEvent.CLICK, { canvas: { x: 420, y: 150 } }); | ||
await expect(graph).toMatchSnapshot(__filename, 'lens-style'); | ||
}); | ||
|
||
it('node style in lens', async () => { | ||
graph.updatePlugin({ key: 'fisheye', style: { lineDash: 0 }, nodeStyle: { halo: true } }); | ||
|
||
dispatchCanvasEvent(graph, CommonEvent.CLICK, { canvas: { x: 420, y: 150 } }); | ||
await expect(graph).toMatchSnapshot(__filename, 'node-style'); | ||
}); | ||
}); |
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,10 @@ | ||
import type { Graph } from '@/src'; | ||
import { CommonEvent } from '@/src'; | ||
|
||
export function emitWheelEvent( | ||
graph: Graph, | ||
options?: { deltaX: number; deltaY: number; clientX: number; clientY: number }, | ||
) { | ||
const dom = graph.getCanvas().getContextService().getDomElement(); | ||
dom?.dispatchEvent(new WheelEvent(CommonEvent.WHEEL, options)); | ||
} |
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.