@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
@@ -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';
@@ -1,3 +1,6 @@
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
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"src/","sources":["plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -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,232 @@
1
+ import { Tooltip as TooltipComponent } from '@antv/component';
2
+ import { get } from '@antv/util';
3
+ import { BasePlugin } from './base-plugin';
4
+ export class Tooltip extends BasePlugin {
5
+ static defaultOptions = {
6
+ trigger: 'hover',
7
+ position: 'top-right',
8
+ enterable: false,
9
+ enable: true,
10
+ style: {
11
+ '.tooltip': {
12
+ visibility: 'hidden',
13
+ },
14
+ },
15
+ };
16
+ currentTarget = null;
17
+ tooltipElement = null;
18
+ container = null;
19
+ constructor(context, options) {
20
+ super(context, Object.assign({}, Tooltip.defaultOptions, options));
21
+ this.render();
22
+ this.bindEvents();
23
+ }
24
+ getEvents() {
25
+ if (this.options.trigger === 'click') {
26
+ return {
27
+ 'node:click': this.onClick,
28
+ 'edge:click': this.onClick,
29
+ 'combo:click': this.onClick,
30
+ 'canvas:click': this.onPointerLeave,
31
+ afterremoveitem: this.onPointerLeave,
32
+ contextmenu: this.onPointerLeave,
33
+ drag: this.onPointerLeave,
34
+ };
35
+ }
36
+ return {
37
+ 'node:pointerenter': this.onPointerEnter,
38
+ 'node:pointermove': this.onPointerMove,
39
+ 'canvas:pointermove': this.onCanvasMove,
40
+ 'edge:pointerenter': this.onPointerEnter,
41
+ 'edge:pointermove': this.onPointerMove,
42
+ 'combo:pointerenter': this.onPointerEnter,
43
+ 'combo:pointermove': this.onPointerMove,
44
+ contextmenu: this.onPointerLeave,
45
+ 'node:drag': this.onPointerLeave,
46
+ };
47
+ }
48
+ update(options) {
49
+ this.unbundEvents();
50
+ super.update(options);
51
+ if (this.tooltipElement) {
52
+ this.container?.removeChild(this.tooltipElement.HTMLTooltipElement);
53
+ }
54
+ this.tooltipElement = this.initTooltip();
55
+ this.bindEvents();
56
+ }
57
+ render() {
58
+ const { canvas } = this.context;
59
+ const $container = canvas.getContainer();
60
+ if (!$container)
61
+ return;
62
+ this.container = $container;
63
+ this.tooltipElement = this.initTooltip();
64
+ }
65
+ unbundEvents() {
66
+ const { graph } = this.context;
67
+ /** The previous event binding needs to be removed when updating the trigger. */
68
+ const events = this.getEvents();
69
+ Object.keys(events).forEach((eventName) => {
70
+ graph.off(eventName, events[eventName]);
71
+ });
72
+ }
73
+ bindEvents() {
74
+ const { graph } = this.context;
75
+ const events = this.getEvents();
76
+ Object.keys(events).forEach((eventName) => {
77
+ graph.on(eventName, events[eventName]);
78
+ });
79
+ }
80
+ isEnable = (e) => {
81
+ const { enable } = this.options;
82
+ if (typeof enable === 'function') {
83
+ return enable(e);
84
+ }
85
+ return enable;
86
+ };
87
+ onClick = (e) => {
88
+ const { target: { id }, } = e;
89
+ // click the same item twice, tooltip will be hidden
90
+ if (this.currentTarget === id) {
91
+ this.currentTarget = null;
92
+ this.hideTooltip(e);
93
+ }
94
+ else {
95
+ this.currentTarget = id;
96
+ this.showTooltip(e);
97
+ }
98
+ };
99
+ onPointerMove = (e) => {
100
+ const { target } = e;
101
+ if (!this.currentTarget || target.id === this.currentTarget) {
102
+ return;
103
+ }
104
+ this.showTooltip(e);
105
+ };
106
+ onPointerLeave = (e) => {
107
+ this.hideTooltip(e);
108
+ this.currentTarget = null;
109
+ };
110
+ onCanvasMove = (e) => {
111
+ this.hideTooltip(e);
112
+ this.currentTarget = null;
113
+ };
114
+ onPointerEnter = (e) => {
115
+ this.showTooltip(e);
116
+ };
117
+ showTooltipById = (id, elementType = 'node') => {
118
+ const e = {
119
+ targetType: elementType,
120
+ target: { id },
121
+ };
122
+ this.showTooltip(e);
123
+ };
124
+ getItems = (id, targetType) => {
125
+ const { model } = this.context;
126
+ switch (targetType) {
127
+ case 'node':
128
+ return model.getNodeData([id]);
129
+ case 'edge':
130
+ return model.getEdgeData([id]);
131
+ case 'combo':
132
+ return model.getComboData([id]);
133
+ default:
134
+ return [];
135
+ }
136
+ };
137
+ showTooltip = (e) => {
138
+ const { targetType, client, target: { id, attributes = { color: '#1883FF' } }, } = e;
139
+ if (!this.tooltipElement || !this.isEnable(e))
140
+ return;
141
+ const { getContent } = this.options;
142
+ const { color, stroke } = attributes;
143
+ this.currentTarget = id;
144
+ const items = this.getItems(id, targetType);
145
+ let x;
146
+ let y;
147
+ if (client) {
148
+ x = client.x;
149
+ y = client.y;
150
+ }
151
+ else {
152
+ const style = get(items, '0.style', { x: 0, y: 0 });
153
+ x = style.x;
154
+ y = style.y;
155
+ }
156
+ let tooltipContent = {};
157
+ if (getContent) {
158
+ tooltipContent.content = getContent(e, items);
159
+ }
160
+ else {
161
+ tooltipContent = {
162
+ title: targetType,
163
+ data: items.map((item) => {
164
+ return {
165
+ name: 'ID',
166
+ value: item.id || `${item.source} -> ${item.target}`,
167
+ color: color || stroke,
168
+ };
169
+ }),
170
+ };
171
+ }
172
+ this.tooltipElement.update({
173
+ x,
174
+ y,
175
+ style: {
176
+ '.tooltip': {
177
+ visibility: 'visible',
178
+ },
179
+ },
180
+ ...tooltipContent,
181
+ });
182
+ };
183
+ hideTooltip = (e) => {
184
+ // if e is undefined, hide the tooltip, external call
185
+ if (!e) {
186
+ this.tooltipElement?.hide();
187
+ return;
188
+ }
189
+ if (!this.tooltipElement || !this.isEnable(e))
190
+ return;
191
+ const { client: { x, y }, } = e;
192
+ this.tooltipElement.hide(x, y);
193
+ };
194
+ initTooltip = () => {
195
+ const { canvas } = this.context;
196
+ const { center } = canvas.getBounds();
197
+ const $container = canvas.getContainer();
198
+ const { top, left } = $container.getBoundingClientRect();
199
+ const { style, position, enterable, container = { x: -left, y: -top } } = this.options;
200
+ const [x, y] = center;
201
+ const [width, height] = canvas.getSize();
202
+ const tooltipElement = new TooltipComponent({
203
+ className: 'tooltip',
204
+ style: {
205
+ x,
206
+ y,
207
+ container,
208
+ bounding: {
209
+ x: 0,
210
+ y: 0,
211
+ width,
212
+ height,
213
+ },
214
+ position,
215
+ enterable,
216
+ title: '',
217
+ offset: [10, 10],
218
+ style,
219
+ },
220
+ });
221
+ this.container?.appendChild(tooltipElement.HTMLTooltipElement);
222
+ return tooltipElement;
223
+ };
224
+ destroy() {
225
+ this.unbundEvents();
226
+ if (this.tooltipElement) {
227
+ this.container?.removeChild(this.tooltipElement.HTMLTooltipElement);
228
+ }
229
+ super.destroy();
230
+ }
231
+ }
232
+ //# sourceMappingURL=tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.js","sourceRoot":"src/","sources":["plugins/tooltip.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAIjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAa3C,MAAM,OAAO,OAAQ,SAAQ,UAA0B;IACrD,MAAM,CAAC,cAAc,GAA4B;QAC/C,OAAO,EAAE,OAAO;QAChB,QAAQ,EAAE,WAAW;QACrB,SAAS,EAAE,KAAK;QAChB,MAAM,EAAE,IAAI;QACZ,KAAK,EAAE;YACL,UAAU,EAAE;gBACV,UAAU,EAAE,QAAQ;aACrB;SACF;KACF,CAAC;IACM,aAAa,GAAkB,IAAI,CAAC;IACpC,cAAc,GAA4B,IAAI,CAAC;IAC/C,SAAS,GAAuB,IAAI,CAAC;IAE7C,YAAY,OAAuB,EAAE,OAAuB;QAC1D,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;QACnE,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IA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D,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC"}
@@ -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
+ }
@@ -0,0 +1,53 @@
1
+ import { createPluginContainer } from '../utils/dom';
2
+ import { getImageWatermark, getTextWateramrk } from '../utils/watermark';
3
+ import { BasePlugin } from './base-plugin';
4
+ /**
5
+ * <zh/> 支持使用文本和图片作为水印,实现原理是在 Graph 容器的 div 上加上 background-image 属性,然后就可以通过 css 来控制水印的位置和样式。
6
+ * 对于文本,会使用隐藏 canvas 转成图片的方式来实现。
7
+ * <en/> Support using text and images as watermarks.
8
+ * The principle is to add the background-image property to the div of the Graph container,
9
+ * and then you can control the position and style of the watermark through css. For text,
10
+ * it will be converted to an image using a hidden canvas.
11
+ */
12
+ export class Watermark extends BasePlugin {
13
+ static defaultOptions = {
14
+ width: 200,
15
+ height: 100,
16
+ opacity: 0.2,
17
+ rotate: Math.PI / 12,
18
+ textFill: '#000',
19
+ textFontSize: 16,
20
+ textAlign: 'center',
21
+ textBaseline: 'middle',
22
+ backgroundRepeat: 'repeat',
23
+ };
24
+ $element = createPluginContainer('watermark');
25
+ constructor(context, options) {
26
+ super(context, Object.assign({}, Watermark.defaultOptions, options));
27
+ const $container = this.context.canvas.getContainer();
28
+ $container.appendChild(this.$element);
29
+ this.update(options);
30
+ }
31
+ async update(options) {
32
+ super.update(options);
33
+ const { width, height, text, imageURL, ...rest } = this.options;
34
+ // Set the background style.
35
+ Object.keys(rest).forEach((key) => {
36
+ if (key.startsWith('background')) {
37
+ // @ts-expect-error ignore
38
+ this.$element.style[key] = options[key];
39
+ }
40
+ });
41
+ // Set the background image.
42
+ const base64 = imageURL
43
+ ? await getImageWatermark(width, height, imageURL, rest)
44
+ : await getTextWateramrk(width, height, text, rest);
45
+ this.$element.style.backgroundImage = `url(${base64})`;
46
+ }
47
+ destroy() {
48
+ super.destroy();
49
+ // Remove the background dom.
50
+ this.$element.remove();
51
+ }
52
+ }
53
+ //# sourceMappingURL=watermark.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watermark.js","sourceRoot":"src/","sources":["plugins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,EAAE,EAAE;YAChC,IAAI,GAAG,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;gBACjC,0BAA0B;gBAC1B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,4BAA4B;QAC5B,MAAM,MAAM,GAAG,QAAQ;YACrB,CAAC,CAAC,MAAM,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC;YACxD,CAAC,CAAC,MAAM,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,GAAG,OAAO,MAAM,GAAG,CAAC;IACzD,CAAC;IAEM,OAAO;QACZ,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,6BAA6B;QAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import { comboCollapseExpand, fade, translate } from '../animations';
2
2
  import { CollapseExpand, DragCanvas, DragElement, ZoomCanvas } from '../behaviors';
3
3
  import { Circle, CircleCombo, Cubic, CubicHorizontal, CubicVertical, Diamond, Ellipse, Image, Line, Polyline, Quadratic, Rect, RectCombo, Star, Triangle, } from '../elements';
4
- import { CircularLayout, ComboCombinedLayout, ConcentricLayout, D3ForceLayout, DagreLayout, ForceAtlas2Layout, ForceLayout, FruchtermanLayout, GridLayout, MDSLayout, RadialLayout, RandomLayout, compactBox, dendrogram, indented, mindmap, } from '../layouts';
4
+ import { AntVDagreLayout, CircularLayout, ComboCombinedLayout, ConcentricLayout, D3ForceLayout, DagreLayout, ForceAtlas2Layout, ForceLayout, FruchtermanLayout, GridLayout, MDSLayout, RadialLayout, RandomLayout, compactBox, dendrogram, indented, mindmap, } from '../layouts';
5
5
  import { blues, greens, oranges, spectral } from '../palettes';
6
- import { GridLine } from '../plugins';
6
+ import { Contextmenu, GridLine, Tooltip, Watermark } from '../plugins';
7
7
  import { dark, light } from '../themes';
8
8
  /**
9
9
  * <zh/> 内置插件统一在这里注册。
@@ -34,6 +34,7 @@ export const BUILT_IN_EXTENSIONS = {
34
34
  'cubic-vertical': CubicVertical,
35
35
  },
36
36
  layout: {
37
+ 'antv-dagre': AntVDagreLayout,
37
38
  'combo-combined': ComboCombinedLayout,
38
39
  'compact-box': compactBox,
39
40
  'force-atlas2': ForceAtlas2Layout,
@@ -72,6 +73,9 @@ export const BUILT_IN_EXTENSIONS = {
72
73
  },
73
74
  plugin: {
74
75
  'grid-line': GridLine,
76
+ watermark: Watermark,
77
+ tooltip: Tooltip,
78
+ contextmenu: Contextmenu,
75
79
  },
76
80
  };
77
81
  //# sourceMappingURL=build-in.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-in.js","sourceRoot":"src/","sources":["registry/build-in.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EACL,MAAM,EACN,WAAW,EACX,KAAK,EACL,eAAe,EACf,aAAa,EACb,OAAO,EACP,OAAO,EACP,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,QAAQ,EACR,OAAO,GACR,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAA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AAO;KACjB;IACD,OAAO,EAAE;QACP,QAAQ;QACR,OAAO;QACP,MAAM;QACN,KAAK;KACN;IACD,KAAK,EAAE;QACL,IAAI;QACJ,KAAK;KACN;IACD,MAAM,EAAE;QACN,WAAW,EAAE,QAAQ;KACtB;CACF,CAAC"}
1
+ {"version":3,"file":"build-in.js","sourceRoot":"src/","sources":["registry/build-in.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EACL,MAAM,EACN,WAAW,EACX,KAAK,EACL,eAAe,EACf,aAAa,EACb,OAAO,EACP,OAAO,EACP,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,QAAQ,EACR,OAAO,GACR,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGxC;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACpD,SAAS,EAAE;QACT,IAAI;QACJ,SAAS;QACT,uBAAuB,EAAE,mBAAmB;KAC7C;IACD,QAAQ,EAAE;QAC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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
  *
@@ -75,7 +75,7 @@ export class BehaviorController extends ExtensionController {
75
75
  graph.emit(`${targetType}:${CanvasEvent.DBLCLICK}`, stdEvent);
76
76
  graph.emit(CanvasEvent.DBLCLICK, stdEvent);
77
77
  }
78
- // 右键菜单 / ContextMenu
78
+ // 右键菜单 / Contextmenu
79
79
  if (type === CanvasEvent.POINTER_DOWN && button === 2) {
80
80
  const contextMenuEvent = {
81
81
  ...stdEvent,
@@ -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[];
@@ -134,17 +134,69 @@ export class Graph extends EventEmitter {
134
134
  getLayout() {
135
135
  return this.options.layout;
136
136
  }
137
+ /**
138
+ * <zh/> 设置交互
139
+ *
140
+ * <en/> Set behaviors
141
+ * @param behaviors - <zh/> 交互配置 | <en/> behavior configuration
142
+ */
137
143
  setBehaviors(behaviors) {
138
144
  this.options.behaviors = isFunction(behaviors) ? behaviors(this.getBehaviors()) : behaviors;
139
145
  this.context.behavior?.setBehaviors(this.options.behaviors);
140
146
  }
147
+ /**
148
+ * <zh/> 更新交互
149
+ *
150
+ * <en/> Update behavior
151
+ * @param behavior - <zh/> 交互配置 | <en/> behavior configuration
152
+ */
153
+ updateBehavior(behavior) {
154
+ this.setBehaviors((behaviors) => behaviors.map((_behavior) => {
155
+ if (isObject(_behavior) && _behavior.key === behavior.key) {
156
+ return { ..._behavior, ...behavior };
157
+ }
158
+ return _behavior;
159
+ }));
160
+ }
161
+ /**
162
+ * <zh/> 获取交互
163
+ *
164
+ * <en/> Get behaviors
165
+ * @returns <zh/> 交互配置 | <en/> behavior configuration
166
+ */
141
167
  getBehaviors() {
142
168
  return this.options.behaviors || [];
143
169
  }
170
+ /**
171
+ * <zh/> 设置插件
172
+ *
173
+ * <en/> Set plugins
174
+ * @param plugins - <zh/> 插件配置 | <en/> plugin configuration
175
+ */
144
176
  setPlugins(plugins) {
145
177
  this.options.plugins = isFunction(plugins) ? plugins(this.getPlugins()) : plugins;
146
178
  this.context.plugin?.setPlugins(this.options.plugins);
147
179
  }
180
+ /**
181
+ * <zh/> 更新插件
182
+ *
183
+ * <en/> Update plugin
184
+ * @param plugin - <zh/> 插件配置 | <en/> plugin configuration
185
+ */
186
+ updatePlugin(plugin) {
187
+ this.setPlugins((plugins) => plugins.map((_plugin) => {
188
+ if (isObject(_plugin) && _plugin.key === plugin.key) {
189
+ return { ..._plugin, ...plugin };
190
+ }
191
+ return _plugin;
192
+ }));
193
+ }
194
+ /**
195
+ * <zh/> 获取插件
196
+ *
197
+ * <en/> Get plugins
198
+ * @returns <zh/> 插件配置 | <en/> plugin configuration
199
+ */
148
200
  getPlugins() {
149
201
  return this.options.plugins || [];
150
202
  }