@antv/g6 5.0.0-beta.29 → 5.0.0-beta.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/g6.min.js +2 -3
  2. package/dist/lib/__tests__/demo/case/index.d.ts +7 -2
  3. package/dist/lib/__tests__/demo/case/layout-antv-dagre-flow-combo.d.ts +2 -0
  4. package/dist/lib/__tests__/demo/case/layout-antv-dagre-flow.d.ts +2 -0
  5. package/dist/lib/__tests__/demo/case/layout-dagre.d.ts +2 -0
  6. package/dist/lib/__tests__/demo/case/plugin-contextmenu.d.ts +2 -0
  7. package/dist/lib/__tests__/demo/case/plugin-tooltip.d.ts +2 -0
  8. package/dist/lib/__tests__/demo/case/plugin-watermark-image.d.ts +2 -0
  9. package/dist/lib/__tests__/demo/case/plugin-watermark.d.ts +2 -0
  10. package/dist/lib/__tests__/demo/static/common.d.ts +1 -1
  11. package/dist/lib/__tests__/demo/static/controller-layout-antv-dagre.d.ts +2 -0
  12. package/dist/lib/__tests__/setup.d.ts +1 -0
  13. package/dist/lib/__tests__/unit/layouts/dagre.spec.d.ts +1 -0
  14. package/dist/lib/__tests__/unit/plugins/plugin-contextmenu.spec.d.ts +1 -0
  15. package/dist/lib/__tests__/unit/plugins/plugin-watermark.spec.d.ts +1 -0
  16. package/dist/lib/__tests__/unit/plugins/tooltip.spec.d.ts +1 -0
  17. package/dist/lib/src/behaviors/drag-element.d.ts +4 -10
  18. package/dist/lib/src/behaviors/zoom-canvas.d.ts +1 -0
  19. package/dist/lib/src/elements/nodes/base-node.d.ts +1 -1
  20. package/dist/lib/src/exports.d.ts +2 -2
  21. package/dist/lib/src/layouts/index.d.ts +1 -1
  22. package/dist/lib/src/layouts/types.d.ts +8 -2
  23. package/dist/lib/src/plugins/contextmenu.d.ts +88 -0
  24. package/dist/lib/src/plugins/grid-line.d.ts +0 -1
  25. package/dist/lib/src/plugins/index.d.ts +6 -0
  26. package/dist/lib/src/plugins/tooltip.d.ts +39 -0
  27. package/dist/lib/src/plugins/watermark.d.ts +51 -0
  28. package/dist/lib/src/registry/extension/types.d.ts +5 -3
  29. package/dist/lib/src/runtime/element.d.ts +2 -2
  30. package/dist/lib/src/runtime/graph.d.ts +40 -0
  31. package/dist/lib/src/spec/behavior.d.ts +10 -2
  32. package/dist/lib/src/spec/plugin.d.ts +10 -2
  33. package/dist/lib/src/types/event.d.ts +6 -2
  34. package/dist/lib/src/types/plugin.d.ts +5 -0
  35. package/dist/lib/src/utils/contextmenu.d.ts +26 -0
  36. package/dist/lib/src/utils/dom.d.ts +7 -0
  37. package/dist/lib/src/utils/watermark.d.ts +18 -0
  38. package/esm/behaviors/drag-element.d.ts +4 -10
  39. package/esm/behaviors/drag-element.js +17 -20
  40. package/esm/behaviors/drag-element.js.map +1 -1
  41. package/esm/behaviors/zoom-canvas.d.ts +1 -0
  42. package/esm/behaviors/zoom-canvas.js +8 -7
  43. package/esm/behaviors/zoom-canvas.js.map +1 -1
  44. package/esm/elements/nodes/base-node.d.ts +1 -1
  45. package/esm/exports.d.ts +2 -2
  46. package/esm/layouts/index.d.ts +1 -1
  47. package/esm/layouts/index.js +1 -1
  48. package/esm/layouts/index.js.map +1 -1
  49. package/esm/layouts/types.d.ts +8 -2
  50. package/esm/plugins/contextmenu.d.ts +88 -0
  51. package/esm/plugins/contextmenu.js +123 -0
  52. package/esm/plugins/contextmenu.js.map +1 -0
  53. package/esm/plugins/grid-line.d.ts +0 -1
  54. package/esm/plugins/grid-line.js +5 -13
  55. package/esm/plugins/grid-line.js.map +1 -1
  56. package/esm/plugins/index.d.ts +6 -0
  57. package/esm/plugins/index.js +3 -0
  58. package/esm/plugins/index.js.map +1 -1
  59. package/esm/plugins/tooltip.d.ts +39 -0
  60. package/esm/plugins/tooltip.js +232 -0
  61. package/esm/plugins/tooltip.js.map +1 -0
  62. package/esm/plugins/watermark.d.ts +51 -0
  63. package/esm/plugins/watermark.js +53 -0
  64. package/esm/plugins/watermark.js.map +1 -0
  65. package/esm/registry/build-in.js +6 -2
  66. package/esm/registry/build-in.js.map +1 -1
  67. package/esm/registry/extension/types.d.ts +5 -3
  68. package/esm/runtime/behavior.js +1 -1
  69. package/esm/runtime/element.d.ts +2 -2
  70. package/esm/runtime/graph.d.ts +40 -0
  71. package/esm/runtime/graph.js +52 -0
  72. package/esm/runtime/graph.js.map +1 -1
  73. package/esm/runtime/layout.js +7 -1
  74. package/esm/runtime/layout.js.map +1 -1
  75. package/esm/spec/behavior.d.ts +10 -2
  76. package/esm/spec/plugin.d.ts +10 -2
  77. package/esm/types/event.d.ts +6 -2
  78. package/esm/types/plugin.d.ts +5 -0
  79. package/esm/types/plugin.js +2 -0
  80. package/esm/types/plugin.js.map +1 -0
  81. package/esm/utils/contextmenu.d.ts +26 -0
  82. package/esm/utils/contextmenu.js +45 -0
  83. package/esm/utils/contextmenu.js.map +1 -0
  84. package/esm/utils/dom.d.ts +7 -0
  85. package/esm/utils/dom.js +21 -0
  86. package/esm/utils/dom.js.map +1 -1
  87. package/esm/utils/layout.js +1 -1
  88. package/esm/utils/layout.js.map +1 -1
  89. package/esm/utils/watermark.d.ts +18 -0
  90. package/esm/utils/watermark.js +73 -0
  91. package/esm/utils/watermark.js.map +1 -0
  92. package/lib/behaviors/drag-element.d.ts +4 -10
  93. package/lib/behaviors/drag-element.js +16 -19
  94. package/lib/behaviors/drag-element.js.map +1 -1
  95. package/lib/behaviors/zoom-canvas.d.ts +1 -0
  96. package/lib/behaviors/zoom-canvas.js +7 -6
  97. package/lib/behaviors/zoom-canvas.js.map +1 -1
  98. package/lib/elements/nodes/base-node.d.ts +1 -1
  99. package/lib/exports.d.ts +2 -2
  100. package/lib/layouts/index.d.ts +1 -1
  101. package/lib/layouts/index.js +2 -1
  102. package/lib/layouts/index.js.map +1 -1
  103. package/lib/layouts/types.d.ts +8 -2
  104. package/lib/plugins/contextmenu.d.ts +88 -0
  105. package/lib/plugins/contextmenu.js +127 -0
  106. package/lib/plugins/contextmenu.js.map +1 -0
  107. package/lib/plugins/grid-line.d.ts +0 -1
  108. package/lib/plugins/grid-line.js +5 -13
  109. package/lib/plugins/grid-line.js.map +1 -1
  110. package/lib/plugins/index.d.ts +6 -0
  111. package/lib/plugins/index.js +7 -1
  112. package/lib/plugins/index.js.map +1 -1
  113. package/lib/plugins/tooltip.d.ts +39 -0
  114. package/lib/plugins/tooltip.js +236 -0
  115. package/lib/plugins/tooltip.js.map +1 -0
  116. package/lib/plugins/watermark.d.ts +51 -0
  117. package/lib/plugins/watermark.js +57 -0
  118. package/lib/plugins/watermark.js.map +1 -0
  119. package/lib/registry/build-in.js +4 -0
  120. package/lib/registry/build-in.js.map +1 -1
  121. package/lib/registry/extension/types.d.ts +5 -3
  122. package/lib/runtime/behavior.js +1 -1
  123. package/lib/runtime/element.d.ts +2 -2
  124. package/lib/runtime/graph.d.ts +40 -0
  125. package/lib/runtime/graph.js +52 -0
  126. package/lib/runtime/graph.js.map +1 -1
  127. package/lib/runtime/layout.js +7 -1
  128. package/lib/runtime/layout.js.map +1 -1
  129. package/lib/spec/behavior.d.ts +10 -2
  130. package/lib/spec/plugin.d.ts +10 -2
  131. package/lib/types/event.d.ts +6 -2
  132. package/lib/types/plugin.d.ts +5 -0
  133. package/lib/types/plugin.js +3 -0
  134. package/lib/types/plugin.js.map +1 -0
  135. package/lib/utils/contextmenu.d.ts +26 -0
  136. package/lib/utils/contextmenu.js +49 -0
  137. package/lib/utils/contextmenu.js.map +1 -0
  138. package/lib/utils/dom.d.ts +7 -0
  139. package/lib/utils/dom.js +23 -1
  140. package/lib/utils/dom.js.map +1 -1
  141. package/lib/utils/layout.js +1 -1
  142. package/lib/utils/layout.js.map +1 -1
  143. package/lib/utils/watermark.d.ts +18 -0
  144. package/lib/utils/watermark.js +78 -0
  145. package/lib/utils/watermark.js.map +1 -0
  146. package/package.json +13 -5
  147. package/src/behaviors/drag-element.ts +20 -28
  148. package/src/behaviors/zoom-canvas.ts +12 -7
  149. package/src/layouts/index.ts +1 -0
  150. package/src/layouts/types.ts +17 -5
  151. package/src/plugins/contextmenu.ts +199 -0
  152. package/src/plugins/grid-line.ts +7 -14
  153. package/src/plugins/index.ts +6 -0
  154. package/src/plugins/tooltip.ts +268 -0
  155. package/src/plugins/watermark.ts +98 -0
  156. package/src/registry/build-in.ts +6 -1
  157. package/src/registry/extension/types.ts +5 -3
  158. package/src/runtime/behavior.ts +1 -1
  159. package/src/runtime/graph.ts +60 -0
  160. package/src/runtime/layout.ts +7 -1
  161. package/src/spec/behavior.ts +11 -2
  162. package/src/spec/plugin.ts +11 -2
  163. package/src/types/event.ts +7 -2
  164. package/src/types/plugin.ts +6 -0
  165. package/src/utils/contextmenu.ts +62 -0
  166. package/src/utils/dom.ts +26 -0
  167. package/src/utils/layout.ts +1 -1
  168. package/src/utils/watermark.ts +93 -0
  169. package/dist/lib/__tests__/demo/case/layout-dagre-flow-combo.d.ts +0 -2
  170. package/dist/lib/__tests__/demo/case/layout-dagre-flow.d.ts +0 -2
  171. package/dist/lib/__tests__/demo/static/controller-layout-dagre.d.ts +0 -2
  172. /package/dist/lib/__tests__/unit/{layouts/dagre-flow.spec.d.ts → behaviors/drag-element-bug.spec.d.ts} +0 -0
@@ -13,6 +13,8 @@ export * from './element-state';
13
13
  export * from './element-visibility';
14
14
  export * from './element-z-index';
15
15
  export * from './graph-event';
16
+ export * from './layout-antv-dagre-flow';
17
+ export * from './layout-antv-dagre-flow-combo';
16
18
  export * from './layout-circular-basic';
17
19
  export * from './layout-circular-configuration-translate';
18
20
  export * from './layout-circular-degree';
@@ -23,8 +25,7 @@ export * from './layout-compact-box-basic';
23
25
  export * from './layout-compact-box-left-align';
24
26
  export * from './layout-compact-box-top-to-bottom';
25
27
  export * from './layout-concentric';
26
- export * from './layout-dagre-flow';
27
- export * from './layout-dagre-flow-combo';
28
+ export * from './layout-dagre';
28
29
  export * from './layout-dendrogram-basic';
29
30
  export * from './layout-dendrogram-tb';
30
31
  export * from './layout-force';
@@ -42,6 +43,10 @@ export * from './layout-radial-configuration-translate';
42
43
  export * from './layout-radial-prevent-overlap';
43
44
  export * from './layout-radial-prevent-overlap-unstrict';
44
45
  export * from './layout-radial-sort';
46
+ export * from './plugin-contextmenu';
45
47
  export * from './plugin-grid-line';
48
+ export * from './plugin-tooltip';
49
+ export * from './plugin-watermark';
50
+ export * from './plugin-watermark-image';
46
51
  export * from './theme';
47
52
  export * from './viewport-fit';
@@ -0,0 +1,2 @@
1
+ import type { STDTestCase } from '../types';
2
+ export declare const layoutAntVDagreFlowCombo: STDTestCase;
@@ -0,0 +1,2 @@
1
+ import type { STDTestCase } from '../types';
2
+ export declare const layoutAntVDagreFlow: STDTestCase;
@@ -0,0 +1,2 @@
1
+ import type { STDTestCase } from '../types';
2
+ export declare const layoutDagre: STDTestCase;
@@ -0,0 +1,2 @@
1
+ import type { STDTestCase } from '../types';
2
+ export declare const pluginContextmenu: STDTestCase;
@@ -0,0 +1,2 @@
1
+ import type { STDTestCase } from '../types';
2
+ export declare const pluginTooltip: STDTestCase;
@@ -0,0 +1,2 @@
1
+ import type { STDTestCase } from '../types';
2
+ export declare const pluginWatermarkImage: STDTestCase;
@@ -0,0 +1,2 @@
1
+ import type { STDTestCase } from '../types';
2
+ export declare const pluginWatermark: STDTestCase;
@@ -7,10 +7,10 @@ export * from './controller-element';
7
7
  export * from './controller-element-position';
8
8
  export * from './controller-element-visibility';
9
9
  export * from './controller-element-z-index';
10
+ export * from './controller-layout-antv-dagre';
10
11
  export * from './controller-layout-circular';
11
12
  export * from './controller-layout-compact-box';
12
13
  export * from './controller-layout-d3-force';
13
- export * from './controller-layout-dagre';
14
14
  export * from './controller-layout-dendrogram';
15
15
  export * from './controller-layout-force';
16
16
  export * from './controller-layout-grid';
@@ -0,0 +1,2 @@
1
+ import type { STDTestCase } from '../types';
2
+ export declare const controllerLayoutAntVDagre: STDTestCase;
@@ -1,3 +1,4 @@
1
1
  import '@/src/preset';
2
+ import 'jest-canvas-mock';
2
3
  import './utils/to-be-close-to';
3
4
  import './utils/use-snapshot-matchers';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -17,12 +17,6 @@ export interface DragElementOptions extends BaseBehaviorOptions, PrefixObject<Ba
17
17
  * <en/> Whether to enable the function of dragging the node
18
18
  */
19
19
  enable?: boolean | ((event: BehaviorEvent<FederatedMouseEvent> | BehaviorEvent<KeyboardEvent>) => boolean);
20
- /**
21
- * <zh/> 支持拖拽的元素类型
22
- *
23
- * <en/> Supported element types for dragging
24
- */
25
- draggableElement: ('node' | 'combo')[];
26
20
  /**
27
21
  * <zh/> 拖拽操作效果
28
22
  * - link: 将拖拽元素置入为目标元素的子元素
@@ -64,7 +58,7 @@ export interface DragElementOptions extends BaseBehaviorOptions, PrefixObject<Ba
64
58
  *
65
59
  * <en/> Edges will not be hidden when using the drag shadow
66
60
  */
67
- hideEdges?: 'none' | 'all' | EdgeDirection;
61
+ hideEdge?: 'none' | 'all' | EdgeDirection;
68
62
  /**
69
63
  * <zh/> 是否启用幽灵节点,即用一个图形代替节点跟随鼠标移动
70
64
  *
@@ -76,17 +70,17 @@ export interface DragElementOptions extends BaseBehaviorOptions, PrefixObject<Ba
76
70
  *
77
71
  * <en/> Callback when dragging is completed
78
72
  */
79
- onfinish?: (ids: ID[]) => void;
73
+ onFinish?: (ids: ID[]) => void;
80
74
  }
81
75
  export declare class DragElement extends BaseBehavior<DragElementOptions> {
82
76
  static defaultOptions: Partial<DragElementOptions>;
83
77
  private enable;
78
+ private enableElements;
84
79
  private target;
85
80
  private shadow?;
86
81
  private shadowOrigin;
87
82
  private hiddenEdges;
88
83
  private get animation();
89
- private get element();
90
84
  constructor(context: RuntimeContext, options: DragElementOptions);
91
85
  update(options: Partial<DragElementOptions>): void;
92
86
  private bindEvents;
@@ -100,7 +94,7 @@ export declare class DragElement extends BaseBehavior<DragElementOptions> {
100
94
  private moveShadow;
101
95
  private createShadow;
102
96
  private showEdges;
103
- private hideEdges;
97
+ private hideEdge;
104
98
  private unbindEvents;
105
99
  destroy(): void;
106
100
  }
@@ -60,6 +60,7 @@ export declare class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
60
60
  * <en/> Zoom canvas
61
61
  * @param value - <zh/> 缩放值, > 0 放大, < 0 缩小 | <en/> Zoom value, > 0 zoom in, < 0 zoom out
62
62
  * @param event - <zh/> 事件对象 | <en/> Event object
63
+ * @param animation - <zh/> 缩放动画配置 | <en/> Zoom animation configuration
63
64
  */
64
65
  private zoom;
65
66
  private onReset;
@@ -30,7 +30,7 @@ export declare abstract class BaseNode<S extends BaseNodeStyleProps = any> exten
30
30
  type: string;
31
31
  static defaultStyleProps: Partial<BaseNodeStyleProps>;
32
32
  constructor(options: DisplayObjectConfig<S>);
33
- protected getSize(attributes?: Required<S>): import("@/src/types/vector").Vector3;
33
+ protected getSize(attributes?: Required<S>): import("../../types").Vector3;
34
34
  protected getKeyStyle(attributes: Required<S>): any;
35
35
  protected getLabelStyle(attributes: Required<S>): false | LabelStyleProps;
36
36
  protected getHaloStyle(attributes: Required<S>): any;
@@ -18,7 +18,7 @@ declare const Utils: {
18
18
  treeToGraphData: typeof treeToGraphData;
19
19
  };
20
20
  declare const Theme: {
21
- dark: import("@/src/themes/types").Theme;
22
- light: import("@/src/themes/types").Theme;
21
+ dark: import("./themes/types").Theme;
22
+ light: import("./themes/types").Theme;
23
23
  };
24
24
  export { Theme, Utils };
@@ -1,3 +1,3 @@
1
1
  /// <reference types="@/src/layouts/hierarchy" />
2
2
  export { compactBox, dendrogram, indented, mindmap } from '@antv/hierarchy';
3
- export { CircularLayout, ComboCombinedLayout, ConcentricLayout, D3ForceLayout, DagreLayout, ForceAtlas2Layout, ForceLayout, FruchtermanLayout, GridLayout, MDSLayout, RadialLayout, RandomLayout, } from '@antv/layout';
3
+ export { AntVDagreLayout, CircularLayout, ComboCombinedLayout, ConcentricLayout, D3ForceLayout, DagreLayout, ForceAtlas2Layout, ForceLayout, FruchtermanLayout, GridLayout, MDSLayout, RadialLayout, RandomLayout, } from '@antv/layout';
@@ -1,6 +1,6 @@
1
- import type { CircularLayoutOptions, ConcentricLayoutOptions, D3ForceLayoutOptions, ForceAtlas2LayoutOptions, ForceLayoutOptions, FruchtermanLayoutOptions, GridLayoutOptions, MDSLayoutOptions, RadialLayoutOptions, RandomLayoutOptions } from '@antv/layout';
1
+ import type { AntVDagreLayoutOptions, CircularLayoutOptions, ConcentricLayoutOptions, D3ForceLayoutOptions, DagreLayoutOptions, ForceAtlas2LayoutOptions, ForceLayoutOptions, FruchtermanLayoutOptions, GridLayoutOptions, MDSLayoutOptions, RadialLayoutOptions, RandomLayoutOptions } from '@antv/layout';
2
2
  import type { NodeData } from '../spec/data';
3
- export type BuiltInLayoutOptions = CircularLayout | RandomLayout | ConcentricLayout | GridLayout | MDSLayout | RadialLayout | FruchtermanLayout | D3ForceLayout | ForceLayout | ForceAtlas2;
3
+ export type BuiltInLayoutOptions = AntVDagreLayout | CircularLayout | ConcentricLayout | D3ForceLayout | DagreLayout | ForceAtlas2 | ForceLayout | FruchtermanLayout | GridLayout | MDSLayout | RadialLayout | RandomLayout;
4
4
  export interface BaseLayoutOptions extends AnimationOptions, WebWorkerLayoutOptions, PresetLayoutOptions {
5
5
  type: string;
6
6
  /**
@@ -43,6 +43,12 @@ interface ForceLayout extends BaseLayoutOptions, ForceLayoutOptions {
43
43
  interface ForceAtlas2 extends BaseLayoutOptions, ForceAtlas2LayoutOptions {
44
44
  type: 'forceAtlas2';
45
45
  }
46
+ interface AntVDagreLayout extends BaseLayoutOptions, AntVDagreLayoutOptions {
47
+ type: 'antv-dagre';
48
+ }
49
+ interface DagreLayout extends BaseLayoutOptions, DagreLayoutOptions {
50
+ type: 'dagre';
51
+ }
46
52
  export interface PresetLayoutOptions {
47
53
  presetLayout?: BaseLayoutOptions;
48
54
  }
@@ -0,0 +1,88 @@
1
+ import type { RuntimeContext } from '../runtime/types';
2
+ import type { ElementEvent } from '../types/event';
3
+ import type { Item } from '../utils/contextmenu';
4
+ import type { BasePluginOptions } from './base-plugin';
5
+ import { BasePlugin } from './base-plugin';
6
+ /**
7
+ * <zh/> 右键菜单插件的配置项。
8
+ * <en/> The configuration item of the right-click menu plugin.
9
+ */
10
+ export type ContextmenuOptions = BasePluginOptions & {
11
+ /**
12
+ * <zh/> 给菜单的 DOM 追加的 classname,便于自定义样式。默认是包含 `g6-contextmenu`。
13
+ * <en/> The classname appended to the menu DOM for custom styles. The default is `g6-contextmenu`.
14
+ */
15
+ className?: string;
16
+ /**
17
+ * <zh/> 如何触发右键菜单,可以是 'click' 或者 'contextmenu',默认是 'contextmenu'。
18
+ * <en/> How to trigger the context menu, default is 'contextmenu'.
19
+ */
20
+ trigger?: 'click' | 'contextmenu';
21
+ /**
22
+ * <zh/> 菜单显式 X、Y 方向的偏移量,默认是 [4, 4]。
23
+ * <en/> The offset X, y direction of the menu, default is [4, 4].
24
+ */
25
+ offset?: [number, number];
26
+ /**
27
+ * <zh/> 当菜单被点击后,出发的回调方法。
28
+ * <en/> The callback method triggered when the menu is clicked.
29
+ */
30
+ onClick?: (v: string, target: HTMLElement) => void;
31
+ /**
32
+ * <zh/> 返回菜单的项目列表,支持 `Promise` 类型的返回值。是 `getContent` 的快捷配置。
33
+ * <en/> Return the list of menu items, support the `Promise` type return value. It is a shortcut configuration of `getContent`.
34
+ */
35
+ getItems?: (event: ElementEvent) => Item[] | Promise<Item[]>;
36
+ /**
37
+ * <zh/> 返回菜单的内容,支持 `Promise` 类型的返回值,也可以使用 `getItems` 来快捷配置。
38
+ * <en/> Return the content of menu, support the `Promise` type return value, you can also use `getItems` for shortcut configuration.
39
+ */
40
+ getContent?: (event: ElementEvent) => HTMLElement | string | Promise<HTMLElement | string>;
41
+ /**
42
+ * <zh/> Loading 时候的菜单内容,用于 getContent 返回 Promise 的时候。
43
+ * <en/> The menu content when loading is used when getContent returns a Promise.
44
+ */
45
+ loadingContent: HTMLElement | string;
46
+ /**
47
+ * <zh/> 插件是否可用,通过参数来判断是否支持右键菜单,默认全部可用。
48
+ * <en/> Whether the plugin is available, determine whether the right-click menu is supported through parameters, The default is all available.
49
+ */
50
+ enable?: boolean | ((event: ElementEvent) => boolean);
51
+ };
52
+ /**
53
+ * <zh/> 支持处理事件,并显示右键菜单,在菜单点击之后,可以触发相应的事件。
54
+ * <en/> Support processing events and displaying right-click menus.
55
+ * After clicking the menu, you can trigger the corresponding event.
56
+ */
57
+ export declare class Contextmenu extends BasePlugin<ContextmenuOptions> {
58
+ static defaultOptions: Partial<ContextmenuOptions>;
59
+ private $element;
60
+ constructor(context: RuntimeContext, options: ContextmenuOptions);
61
+ /**
62
+ * <zh/> 根据传入的元素,显示右键菜单。
63
+ * <en/> Display the right-click menu based on the incoming element.
64
+ * @param e - 事件
65
+ */
66
+ showContextmenu(e: ElementEvent): Promise<void>;
67
+ /**
68
+ * <zh/> 隐藏右键菜单。
69
+ * <en/> Hide the right-click menu.
70
+ */
71
+ hideContextmenu(): void;
72
+ /**
73
+ * <zh/> 更新右键菜单的配置项。
74
+ * <en/> Update the configuration of the right-click menu.
75
+ * @param options - 配置项
76
+ */
77
+ update(options: Partial<ContextmenuOptions>): void;
78
+ /**
79
+ * <zh/> 销毁右键菜单。
80
+ * <en/> Destroy the right-click menu.
81
+ */
82
+ destroy(): void;
83
+ private getDOMContent;
84
+ private bindEvents;
85
+ private unbindEvents;
86
+ private onTriggerEvent;
87
+ private onMenuItemClick;
88
+ }
@@ -23,7 +23,6 @@ export declare class GridLine extends BasePlugin<GridLineOptions> {
23
23
  constructor(context: RuntimeContext, options: GridLineOptions);
24
24
  update(options: Partial<GridLineOptions>): void;
25
25
  private bindEvents;
26
- private render;
27
26
  private updateStyle;
28
27
  private updateOffset;
29
28
  private onTransform;
@@ -1,4 +1,10 @@
1
1
  export { BasePlugin } from './base-plugin';
2
+ export { Contextmenu } from './contextmenu';
2
3
  export { GridLine } from './grid-line';
4
+ export { Tooltip } from './tooltip';
5
+ export { Watermark } from './watermark';
3
6
  export type { BasePluginOptions } from './base-plugin';
7
+ export type { ContextmenuOptions } from './contextmenu';
4
8
  export type { GridLineOptions } from './grid-line';
9
+ export type { TooltipOptions } from './tooltip';
10
+ export type { WatermarkOptions } from './watermark';
@@ -0,0 +1,39 @@
1
+ import type { TooltipStyleProps } from '@antv/component';
2
+ import type { RuntimeContext } from '../runtime/types';
3
+ import type { ElementDatum, ElementEvent, ElementType } from '../types';
4
+ import type { BasePluginOptions } from './base-plugin';
5
+ import { BasePlugin } from './base-plugin';
6
+ export interface TooltipOptions extends BasePluginOptions, Pick<TooltipStyleProps, 'position' | 'offset' | 'enterable' | 'style' | 'container'> {
7
+ /** <zh/> 触发方式 | <en/> Event type that triggers display of tooltip */
8
+ trigger?: 'hover' | 'click';
9
+ /** <zh/> 自定义内容 | <en/> Function for getting tooltip content */
10
+ getContent?: (evt: ElementEvent, items: ElementDatum[]) => HTMLElement | string;
11
+ /** <zh/> 是否启用 | <en/> Is enable */
12
+ enable?: boolean | ((evt: ElementEvent) => boolean);
13
+ }
14
+ export declare class Tooltip extends BasePlugin<TooltipOptions> {
15
+ static defaultOptions: Partial<TooltipOptions>;
16
+ private currentTarget;
17
+ private tooltipElement;
18
+ private container;
19
+ constructor(context: RuntimeContext, options: TooltipOptions);
20
+ getEvents(): {
21
+ [key: string]: Function;
22
+ };
23
+ update(options: Partial<TooltipOptions>): void;
24
+ private render;
25
+ private unbundEvents;
26
+ private bindEvents;
27
+ private isEnable;
28
+ onClick: (e: ElementEvent) => void;
29
+ onPointerMove: (e: ElementEvent) => void;
30
+ onPointerLeave: (e: ElementEvent) => void;
31
+ onCanvasMove: (e: ElementEvent) => void;
32
+ private onPointerEnter;
33
+ showTooltipById: (id: string, elementType?: ElementType) => void;
34
+ private getItems;
35
+ showTooltip: (e: ElementEvent) => void;
36
+ hideTooltip: (e?: ElementEvent) => void;
37
+ private initTooltip;
38
+ destroy(): void;
39
+ }
@@ -0,0 +1,51 @@
1
+ import type { RuntimeContext } from '../runtime/types';
2
+ import type { BasePluginOptions } from './base-plugin';
3
+ import { BasePlugin } from './base-plugin';
4
+ export type WatermarkOptions = BasePluginOptions & {
5
+ /** 单独一个水印的大小,这个水印最终会用来填充整个大小,所以 repeat 后的间距大小,通过这个 width height 设置 */
6
+ width?: number;
7
+ height?: number;
8
+ /** 透明度 */
9
+ opacity?: number;
10
+ /** 旋转角度 */
11
+ rotate?: number;
12
+ /** 图片地址,如果有值,则使用,否则使用文本 */
13
+ imageURL?: string;
14
+ /** 水印文本 */
15
+ text?: string;
16
+ /** 文本水印的文本样式 */
17
+ textFill: string;
18
+ textFontSize: number;
19
+ textFontFamily: string;
20
+ textFontWeight: string;
21
+ textFontVariant: string;
22
+ textAlign: CanvasTextAlign;
23
+ textBaseline: CanvasTextBaseline;
24
+ /** 背景的 CSS 样式 */
25
+ backgroundAttachment: string;
26
+ backgroundBlendMode: string;
27
+ backgroundClip: string;
28
+ backgroundColor: string;
29
+ backgroundImage: string;
30
+ backgroundOrigin: string;
31
+ backgroundPosition: string;
32
+ backgroundPositionX: string;
33
+ backgroundPositionY: string;
34
+ backgroundRepeat: string;
35
+ backgroundSize: string;
36
+ };
37
+ /**
38
+ * <zh/> 支持使用文本和图片作为水印,实现原理是在 Graph 容器的 div 上加上 background-image 属性,然后就可以通过 css 来控制水印的位置和样式。
39
+ * 对于文本,会使用隐藏 canvas 转成图片的方式来实现。
40
+ * <en/> Support using text and images as watermarks.
41
+ * The principle is to add the background-image property to the div of the Graph container,
42
+ * and then you can control the position and style of the watermark through css. For text,
43
+ * it will be converted to an image using a hidden canvas.
44
+ */
45
+ export declare class Watermark extends BasePlugin<WatermarkOptions> {
46
+ static defaultOptions: Partial<WatermarkOptions>;
47
+ private $element;
48
+ constructor(context: RuntimeContext, options: WatermarkOptions);
49
+ update(options: Partial<WatermarkOptions>): Promise<void>;
50
+ destroy(): void;
51
+ }
@@ -1,8 +1,10 @@
1
- type ExtensionMetaOptions = {
1
+ interface ExtensionMetaOptions {
2
2
  type: string;
3
3
  key: string;
4
- };
5
- type CustomExtensionOptions = Record<string, any>;
4
+ }
5
+ interface CustomExtensionOptions {
6
+ [key: string]: any;
7
+ }
6
8
  /**
7
9
  * <zh/> 扩展配置项
8
10
  *
@@ -14,7 +14,7 @@ export declare class ElementController {
14
14
  private emit;
15
15
  private forEachElementData;
16
16
  private getTheme;
17
- getThemeStyle(elementType: ElementType): import("@/src/spec/element/node").NodeStyle | import("@/src/spec/element/edge").EdgeStyle | import("@/src/spec/element/combo").ComboStyle;
17
+ getThemeStyle(elementType: ElementType): import("../spec/element/node").NodeStyle | import("../spec/element/edge").EdgeStyle | import("../spec/element/combo").ComboStyle;
18
18
  getThemeStateStyle(elementType: ElementType, states: State[]): any;
19
19
  private paletteStyle;
20
20
  private computePaletteStyle;
@@ -57,7 +57,7 @@ export declare class ElementController {
57
57
  private computeStyle;
58
58
  getElement<T extends DisplayObject = BaseShape<any>>(id: ID): T | undefined;
59
59
  getNodes(): Node[];
60
- getEdges(): import("@/src").BaseEdge[];
60
+ getEdges(): import("..").BaseEdge[];
61
61
  getCombos(): Combo[];
62
62
  private getAnimation;
63
63
  private getAnimationExecutor;
@@ -2,6 +2,8 @@ import EventEmitter from '@antv/event-emitter';
2
2
  import type { AABB, BaseStyleProps, DataURLOptions } from '@antv/g';
3
3
  import type { ID } from '@antv/graphlib';
4
4
  import type { BehaviorOptions, ComboData, ComboOptions, EdgeData, EdgeOptions, G6Spec, GraphData, LayoutOptions, NodeData, NodeOptions, PluginOptions, ThemeOptions } from '../spec';
5
+ import { UpdateBehaviorOption } from '../spec/behavior';
6
+ import { UpdatePluginOption } from '../spec/plugin';
5
7
  import type { CallableValue, DataID, EdgeDirection, ElementType, FitViewOptions, NodeLikeData, PartialEdgeData, PartialGraphData, PartialNodeLikeData, Point, Position, State, ViewportAnimationEffectTiming } from '../types';
6
8
  import { Canvas } from './canvas';
7
9
  import type { HierarchyKey } from './data';
@@ -42,9 +44,47 @@ export declare class Graph extends EventEmitter {
42
44
  setTheme(theme: CallableValue<ThemeOptions>): void;
43
45
  setLayout(layout: CallableValue<LayoutOptions>): void;
44
46
  getLayout(): LayoutOptions;
47
+ /**
48
+ * <zh/> 设置交互
49
+ *
50
+ * <en/> Set behaviors
51
+ * @param behaviors - <zh/> 交互配置 | <en/> behavior configuration
52
+ */
45
53
  setBehaviors(behaviors: CallableValue<BehaviorOptions>): void;
54
+ /**
55
+ * <zh/> 更新交互
56
+ *
57
+ * <en/> Update behavior
58
+ * @param behavior - <zh/> 交互配置 | <en/> behavior configuration
59
+ */
60
+ updateBehavior(behavior: UpdateBehaviorOption): void;
61
+ /**
62
+ * <zh/> 获取交互
63
+ *
64
+ * <en/> Get behaviors
65
+ * @returns <zh/> 交互配置 | <en/> behavior configuration
66
+ */
46
67
  getBehaviors(): BehaviorOptions;
68
+ /**
69
+ * <zh/> 设置插件
70
+ *
71
+ * <en/> Set plugins
72
+ * @param plugins - <zh/> 插件配置 | <en/> plugin configuration
73
+ */
47
74
  setPlugins(plugins: CallableValue<PluginOptions>): void;
75
+ /**
76
+ * <zh/> 更新插件
77
+ *
78
+ * <en/> Update plugin
79
+ * @param plugin - <zh/> 插件配置 | <en/> plugin configuration
80
+ */
81
+ updatePlugin(plugin: UpdatePluginOption): void;
82
+ /**
83
+ * <zh/> 获取插件
84
+ *
85
+ * <en/> Get plugins
86
+ * @returns <zh/> 插件配置 | <en/> plugin configuration
87
+ */
48
88
  getPlugins(): PluginOptions;
49
89
  getData(): GraphData;
50
90
  getNodeData(): NodeData[];
@@ -1,4 +1,12 @@
1
1
  import type { BuiltInBehaviorOptions } from '../behaviors/types';
2
- import type { ExtensionOptions, LooselyExtensionOption } from '../registry/extension/types';
2
+ import type { ExtensionOptions } from '../registry/extension/types';
3
3
  export type BehaviorOptions = ExtensionOptions<BuiltInBehaviorOptions>;
4
- export type CustomBehaviorOption = LooselyExtensionOption;
4
+ export interface UpdateBehaviorOption {
5
+ key: string;
6
+ [key: string]: any;
7
+ }
8
+ export interface CustomBehaviorOption {
9
+ type?: string;
10
+ key?: string;
11
+ [key: string]: any;
12
+ }
@@ -1,4 +1,12 @@
1
1
  import type { BuiltInPluginOptions } from '../plugins/types';
2
- import type { ExtensionOptions, LooselyExtensionOption } from '../registry/extension/types';
2
+ import type { ExtensionOptions } from '../registry/extension/types';
3
3
  export type PluginOptions = ExtensionOptions<BuiltInPluginOptions>;
4
- export type CustomPluginOption = LooselyExtensionOption;
4
+ export interface UpdatePluginOption {
5
+ key: string;
6
+ [key: string]: any;
7
+ }
8
+ export interface CustomPluginOption {
9
+ type?: string;
10
+ key?: string;
11
+ [key: string]: any;
12
+ }
@@ -1,4 +1,8 @@
1
- import type { Document } from '@antv/g';
2
- import { Edge, Node } from './element';
1
+ import type { Document, FederatedMouseEvent } from '@antv/g';
2
+ import type { BehaviorEvent } from './behavior';
3
+ import { Edge, ElementType, Node } from './element';
3
4
  export type Listener = (event: any) => void;
4
5
  export type Target = Document | Node | Edge | null;
6
+ export interface ElementEvent extends BehaviorEvent<FederatedMouseEvent> {
7
+ targetType: ElementType;
8
+ }
@@ -0,0 +1,5 @@
1
+ import type { DisplayObject, FederatedEvent } from '@antv/g';
2
+ export type PluginEvent<T extends Event | FederatedEvent = Event> = Omit<T, 'target'> & {
3
+ targetType: 'canvas' | 'node' | 'edge' | 'combo';
4
+ target: DisplayObject;
5
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * <zh/> 右键菜单显示项目。
3
+ * <en/> The item of the right-click menu.
4
+ */
5
+ export type Item = {
6
+ /**
7
+ * <zh/> 菜单项显示的名字。
8
+ * <en/> The name of the menu item.
9
+ */
10
+ name: string;
11
+ /**
12
+ * <zh/> 菜单项对应的值。
13
+ * <en/> The value corresponding to the menu item.
14
+ */
15
+ value: string;
16
+ };
17
+ /**
18
+ * Get the content of the right-click menu.
19
+ * @param items - context menu items
20
+ * @returns HTML string
21
+ */
22
+ export declare function getContentFromItems(items: Item[]): string;
23
+ /**
24
+ * Style of the right-click menu, same with `tooltip`.
25
+ */
26
+ export declare const CONTEXTMENU_CSS = "\n .g6-contextmenu {\n font-size: 12px;\n background-color: rgba(255, 255, 255, 0.96);\n border-radius: 4px;\n overflow: hidden;\n box-shadow: rgba(0, 0, 0, 0.12) 0px 6px 12px 0px;\n transition: visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1) 0s, left 0.4s cubic-bezier(0.23, 1, 0.32, 1) 0s, top 0.4s cubic-bezier(0.23, 1, 0.32, 1) 0s;\n }\n\n .g6-contextmenu-ul {\n max-width: 256px;\n min-width: 96px;\n list-style: none;\n padding: 0;\n margin: 0;\n }\n\n .g6-contextmenu-li {\n padding: 8px 12px;\n cursor: pointer;\n user-select: none;\n }\n\n .g6-contextmenu-li:hover {\n background-color: #f5f5f5;\n cursor: pointer;\n }\n";
@@ -4,3 +4,10 @@
4
4
  * @returns Size of Graph
5
5
  */
6
6
  export declare function sizeOf(container: HTMLElement): [number, number];
7
+ /**
8
+ * Create a plugin DOM element.
9
+ * @param type - plugin type
10
+ * @param cover - cover the container
11
+ * @returns plugin DOM element
12
+ */
13
+ export declare function createPluginContainer(type: string, cover?: boolean): HTMLDivElement;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 从文本获取水印的 base64
3
+ * @param width - width
4
+ * @param height - height
5
+ * @param text - 样式
6
+ * @param style - 样式
7
+ * @returns 水印的 base64
8
+ */
9
+ export declare function getTextWateramrk(width: number, height: number, text: string, style: any): Promise<string>;
10
+ /**
11
+ * Get the image base64 of the watermark.
12
+ * @param width - width
13
+ * @param height - height
14
+ * @param imageURL - image URL
15
+ * @param style - 样式
16
+ * @returns 水印的 base64
17
+ */
18
+ export declare function getImageWatermark(width: number, height: number, imageURL: string, style: any): Promise<unknown>;