-
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 type define of toolbar plugin * feat: add toolbar plugin * docs: add toolbar demo * test: add test case * chore: fix typo * fix: remove insert-css * chore: update test case * chore: fix cr
- Loading branch information
Showing
17 changed files
with
590 additions
and
136 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
74 changes: 74 additions & 0 deletions
74
packages/g6/__tests__/demo/case/plugin-toolbar-build-in.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,74 @@ | ||
import { Graph } from '@/src'; | ||
import data from '@@/dataset/cluster.json'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const pluginToolbarBuildIn: STDTestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
autoResize: true, | ||
data, | ||
layout: { type: 'd3force' }, | ||
plugins: [ | ||
{ | ||
type: 'toolbar', | ||
position: 'top-left', | ||
onClick: (item: string, e: MouseEvent) => { | ||
console.log('item clicked:', item, e); | ||
}, | ||
getItems: () => { | ||
return [ | ||
{ id: 'zoom-in', value: 'zoom-in' }, | ||
{ id: 'zoom-out', value: 'zoom-out' }, | ||
{ id: 'redo', value: 'redo' }, | ||
{ id: 'undo', value: 'undo' }, | ||
{ id: 'edit', value: 'edit' }, | ||
{ id: 'delete', value: 'delete' }, | ||
{ id: 'auto-fit', value: 'auto-fit' }, | ||
{ id: 'export', value: 'export' }, | ||
{ id: 'reset', value: 'reset' }, | ||
]; | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
await graph.render(); | ||
|
||
pluginToolbarBuildIn.form = (panel) => { | ||
const config = { | ||
position: 'top-left', | ||
}; | ||
return [ | ||
panel | ||
.add(config, 'position', { | ||
'top-right': 'top-right', | ||
'top-left': 'top-left', | ||
'bottom-right': 'bottom-right', | ||
'bottom-left': 'bottom-left', | ||
'left-top': 'left-top', | ||
'left-bottom': 'left-bottom', | ||
'right-top': 'right-top', | ||
'right-bottom': 'right-bottom', | ||
}) | ||
.name('Position') | ||
.onChange((position: string) => { | ||
graph.setPlugins([ | ||
{ | ||
type: 'toolbar', | ||
position, | ||
getItems: () => { | ||
return [ | ||
{ id: 'zoom-in', value: 'zoom-in' }, | ||
{ id: 'zoom-out', value: 'zoom-out' }, | ||
]; | ||
}, | ||
enable: true, | ||
}, | ||
]); | ||
graph.render(); | ||
}), | ||
]; | ||
}; | ||
|
||
return graph; | ||
}; |
37 changes: 37 additions & 0 deletions
37
packages/g6/__tests__/demo/case/plugin-toolbar-iconfont.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,37 @@ | ||
import { Graph } from '@/src'; | ||
import data from '@@/dataset/cluster.json'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const pluginToolbarIconfont: STDTestCase = async (context) => { | ||
// Use iconfont for toolbar items. | ||
const iconFont = document.createElement('script'); | ||
iconFont.src = '//at.alicdn.com/t/font_8d5l8fzk5b87iudi.js'; | ||
document.head.appendChild(iconFont); | ||
|
||
const graph = new Graph({ | ||
...context, | ||
autoResize: true, | ||
data, | ||
layout: { type: 'd3force' }, | ||
plugins: [ | ||
{ | ||
type: 'toolbar', | ||
position: 'right-top', | ||
onClick: (item: string, e: MouseEvent) => { | ||
console.log('item clicked:', item, e); | ||
}, | ||
getItems: () => { | ||
return [ | ||
{ id: 'icon-xinjian', value: 'new' }, | ||
{ id: 'icon-fenxiang', value: 'share' }, | ||
{ id: 'icon-chexiao', value: 'undo' }, | ||
]; | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
await graph.render(); | ||
|
||
return graph; | ||
}; |
20 changes: 20 additions & 0 deletions
20
packages/g6/__tests__/unit/plugins/toolbar/plugin-toolbar.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,20 @@ | ||
import { pluginToolbarBuildIn } from '@@/demo/case'; | ||
import { createDemoGraph } from '@@/utils'; | ||
import { get } from '@antv/util'; | ||
|
||
describe('plugin toolbar', () => { | ||
it('toolbar', async () => { | ||
const graph = await createDemoGraph(pluginToolbarBuildIn); | ||
const container = graph.getCanvas().getContainer()!; | ||
|
||
const el = container.querySelector('.g6-toolbar') as HTMLDivElement; | ||
|
||
expect(graph.getPlugins().length).toBe(1); | ||
expect(get(graph.getPlugins(), [0, 'position'])).toBe('top-left'); | ||
|
||
expect(el.querySelectorAll('.g6-toolbar-item').length).toBe(9); | ||
|
||
await graph.destroy(); | ||
expect(container.querySelector('.g6-toolbar-item')).toBeFalsy(); | ||
}); | ||
}); |
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,63 @@ | ||
import { parsePositionToStyle } from '@/src/plugins/toolbar/util'; | ||
|
||
describe('util', () => { | ||
it('parsePositionToStyle', () => { | ||
expect(parsePositionToStyle('top-left')).toEqual({ | ||
top: '8px', | ||
right: 'unset', | ||
bottom: 'unset', | ||
left: '8px', | ||
flexDirection: 'row', | ||
}); | ||
expect(parsePositionToStyle('top-right')).toEqual({ | ||
top: '8px', | ||
right: '8px', | ||
bottom: 'unset', | ||
left: 'unset', | ||
flexDirection: 'row', | ||
}); | ||
expect(parsePositionToStyle('bottom-left')).toEqual({ | ||
top: 'unset', | ||
right: 'unset', | ||
bottom: '8px', | ||
left: '8px', | ||
flexDirection: 'row', | ||
}); | ||
expect(parsePositionToStyle('bottom-right')).toEqual({ | ||
top: 'unset', | ||
right: '8px', | ||
bottom: '8px', | ||
left: 'unset', | ||
flexDirection: 'row', | ||
}); | ||
|
||
expect(parsePositionToStyle('left-top')).toEqual({ | ||
top: '8px', | ||
right: 'unset', | ||
bottom: 'unset', | ||
left: '8px', | ||
flexDirection: 'column', | ||
}); | ||
expect(parsePositionToStyle('right-top')).toEqual({ | ||
top: '8px', | ||
right: '8px', | ||
bottom: 'unset', | ||
left: 'unset', | ||
flexDirection: 'column', | ||
}); | ||
expect(parsePositionToStyle('left-bottom')).toEqual({ | ||
top: 'unset', | ||
right: 'unset', | ||
bottom: '8px', | ||
left: '8px', | ||
flexDirection: 'column', | ||
}); | ||
expect(parsePositionToStyle('right-bottom')).toEqual({ | ||
top: 'unset', | ||
right: '8px', | ||
bottom: '8px', | ||
left: 'unset', | ||
flexDirection: 'column', | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
export { BasePlugin } from './base-plugin'; | ||
export { Contextmenu } from './contextmenu'; | ||
export { GridLine } from './grid-line'; | ||
export { Toolbar } from './toolbar'; | ||
export { Tooltip } from './tooltip'; | ||
export { Watermark } from './watermark'; | ||
|
||
export type { BasePluginOptions } from './base-plugin'; | ||
export type { ContextmenuOptions } from './contextmenu'; | ||
export type { GridLineOptions } from './grid-line'; | ||
export type { ToolbarOptions } from './toolbar'; | ||
export type { TooltipOptions } from './tooltip'; | ||
export type { WatermarkOptions } from './watermark'; |
Oops, something went wrong.