@antv/g6 5.0.0-beta.10 → 5.0.0-beta.12
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.
- package/dist/g6.min.js +2 -2
- package/esm/api-doc/graph.d.ts +3 -3
- package/esm/api-doc/graph.js +3 -3
- package/esm/api-doc/graph.js.map +1 -1
- package/esm/constant/shape.d.ts +1 -1
- package/esm/index.d.ts +12 -62
- package/esm/index.js +4 -5
- package/esm/index.js.map +1 -1
- package/esm/item/node.js +0 -1
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/item.js +15 -6
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/controller/layout.js +1 -3
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/graph.d.ts +1 -1
- package/esm/runtime/graph.js +11 -5
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
- package/esm/stdlib/behavior/shortcuts-call.d.ts +2 -2
- package/esm/stdlib/behavior/shortcuts-call.js +12 -5
- package/esm/stdlib/behavior/shortcuts-call.js.map +1 -1
- package/esm/stdlib/behavior/zoom-canvas-3d.js +4 -1
- package/esm/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
- package/esm/stdlib/index.d.ts +6 -1
- package/esm/stdlib/index.js +8 -3
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/edge/base.js +5 -1
- package/esm/stdlib/item/edge/base.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-horizontal.js.map +1 -1
- package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -1
- package/esm/stdlib/item/edge/cubic.js +1 -1
- package/esm/stdlib/item/edge/cubic.js.map +1 -1
- package/esm/stdlib/item/edge/loop.js +1 -1
- package/esm/stdlib/item/edge/loop.js.map +1 -1
- package/esm/stdlib/item/node/cube.d.ts +35 -0
- package/esm/stdlib/item/node/cube.js +54 -0
- package/esm/stdlib/item/node/cube.js.map +1 -0
- package/esm/stdlib/item/node/index.d.ts +3 -0
- package/esm/stdlib/item/node/index.js +3 -0
- package/esm/stdlib/item/node/index.js.map +1 -1
- package/esm/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
- package/esm/stdlib/plugin/edgeFilterLens/index.js +309 -0
- package/esm/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
- package/esm/stdlib/plugin/grid/index.d.ts +1 -1
- package/esm/stdlib/plugin/grid/index.js +3 -4
- package/esm/stdlib/plugin/grid/index.js.map +1 -1
- package/esm/stdlib/plugin/hull/convexHull.d.ts +1 -1
- package/esm/stdlib/plugin/hull/hullComponent.js +2 -3
- package/esm/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/esm/stdlib/plugin/hull/util.d.ts +2 -2
- package/esm/stdlib/plugin/hull/util.js +6 -2
- package/esm/stdlib/plugin/hull/util.js.map +1 -1
- package/esm/stdlib/plugin/index.d.ts +1 -0
- package/esm/stdlib/plugin/index.js +1 -0
- package/esm/stdlib/plugin/index.js.map +1 -1
- package/esm/stdlib/plugin/legend/index.d.ts +2 -2
- package/esm/stdlib/plugin/legend/index.js +3 -3
- package/esm/stdlib/plugin/legend/index.js.map +1 -1
- package/esm/stdlib/plugin/map/index.d.ts +1 -1
- package/esm/stdlib/plugin/map/index.js +4 -4
- package/esm/stdlib/plugin/map/index.js.map +1 -1
- package/esm/stdlib/plugin/menu/index.d.ts +4 -4
- package/esm/stdlib/plugin/menu/index.js +3 -3
- package/esm/stdlib/plugin/menu/index.js.map +1 -1
- package/esm/stdlib/plugin/minimap/index.d.ts +1 -1
- package/esm/stdlib/plugin/minimap/index.js +3 -3
- package/esm/stdlib/plugin/minimap/index.js.map +1 -1
- package/esm/stdlib/plugin/timebar/index.js +2 -2
- package/esm/stdlib/plugin/timebar/index.js.map +1 -1
- package/esm/stdlib/plugin/toolbar/index.d.ts +3 -3
- package/esm/stdlib/plugin/toolbar/index.js +4 -4
- package/esm/stdlib/plugin/toolbar/index.js.map +1 -1
- package/esm/stdlib/plugin/tooltip/index.d.ts +4 -4
- package/esm/stdlib/plugin/tooltip/index.js +3 -4
- package/esm/stdlib/plugin/tooltip/index.js.map +1 -1
- package/esm/stdlib/plugin/types.d.ts +1 -0
- package/esm/stdlib/plugin/watermaker/index.d.ts +78 -0
- package/esm/stdlib/plugin/watermaker/index.js +243 -0
- package/esm/stdlib/plugin/watermaker/index.js.map +1 -0
- package/esm/types/plugin.d.ts +1 -1
- package/esm/util/bbox.js +4 -5
- package/esm/util/bbox.js.map +1 -1
- package/esm/util/behavior.d.ts +2 -2
- package/esm/util/behavior.js +2 -2
- package/esm/util/behavior.js.map +1 -1
- package/esm/util/data.d.ts +2 -2
- package/esm/util/data.js.map +1 -1
- package/esm/util/dom.d.ts +15 -0
- package/esm/util/dom.js +29 -0
- package/esm/util/dom.js.map +1 -0
- package/esm/util/extend.d.ts +1 -1
- package/esm/util/extend.js +0 -1
- package/esm/util/extend.js.map +1 -1
- package/esm/util/index.d.ts +7 -52
- package/esm/util/index.js +7 -23
- package/esm/util/index.js.map +1 -1
- package/esm/util/layout.d.ts +1 -1
- package/esm/util/layout.js.map +1 -1
- package/esm/util/loop.d.ts +1 -1
- package/esm/util/math.d.ts +1 -1
- package/esm/util/matrix.d.ts +6 -0
- package/esm/util/matrix.js +48 -0
- package/esm/util/matrix.js.map +1 -0
- package/esm/util/path.js +1 -1
- package/esm/util/path.js.map +1 -1
- package/esm/util/point.d.ts +1 -1
- package/esm/util/polyline.d.ts +2 -1
- package/esm/util/polyline.js +2 -1
- package/esm/util/polyline.js.map +1 -1
- package/esm/util/router.d.ts +1 -1
- package/esm/util/shape.js.map +1 -1
- package/esm/util/shape3d.js +1 -1
- package/esm/util/shape3d.js.map +1 -1
- package/lib/api-doc/graph.d.ts +3 -3
- package/lib/api-doc/graph.js +27 -7
- package/lib/api-doc/graph.js.map +1 -1
- package/lib/constant/shape.d.ts +1 -1
- package/lib/index.d.ts +12 -62
- package/lib/index.js +18 -10
- package/lib/index.js.map +1 -1
- package/lib/item/node.js +0 -1
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/item.js +15 -6
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/controller/layout.js +1 -3
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/graph.d.ts +1 -1
- package/lib/runtime/graph.js +12 -5
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/drag-canvas.d.ts +1 -1
- package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
- package/lib/stdlib/behavior/shortcuts-call.d.ts +2 -2
- package/lib/stdlib/behavior/shortcuts-call.js +12 -5
- package/lib/stdlib/behavior/shortcuts-call.js.map +1 -1
- package/lib/stdlib/behavior/zoom-canvas-3d.js +4 -1
- package/lib/stdlib/behavior/zoom-canvas-3d.js.map +1 -1
- package/lib/stdlib/index.d.ts +6 -1
- package/lib/stdlib/index.js +8 -3
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/edge/base.js +5 -1
- package/lib/stdlib/item/edge/base.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-horizontal.js.map +1 -1
- package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -1
- package/lib/stdlib/item/edge/cubic.js +2 -2
- package/lib/stdlib/item/edge/cubic.js.map +1 -1
- package/lib/stdlib/item/edge/loop.js +3 -3
- package/lib/stdlib/item/edge/loop.js.map +1 -1
- package/lib/stdlib/item/node/cube.d.ts +35 -0
- package/lib/stdlib/item/node/cube.js +58 -0
- package/lib/stdlib/item/node/cube.js.map +1 -0
- package/lib/stdlib/item/node/index.d.ts +3 -0
- package/lib/stdlib/item/node/index.js +3 -0
- package/lib/stdlib/item/node/index.js.map +1 -1
- package/lib/stdlib/plugin/edgeFilterLens/index.d.ts +66 -0
- package/lib/stdlib/plugin/edgeFilterLens/index.js +313 -0
- package/lib/stdlib/plugin/edgeFilterLens/index.js.map +1 -0
- package/lib/stdlib/plugin/grid/index.d.ts +1 -1
- package/lib/stdlib/plugin/grid/index.js +6 -7
- package/lib/stdlib/plugin/grid/index.js.map +1 -1
- package/lib/stdlib/plugin/hull/convexHull.d.ts +1 -1
- package/lib/stdlib/plugin/hull/hullComponent.js +2 -3
- package/lib/stdlib/plugin/hull/hullComponent.js.map +1 -1
- package/lib/stdlib/plugin/hull/util.d.ts +2 -2
- package/lib/stdlib/plugin/hull/util.js +26 -22
- package/lib/stdlib/plugin/hull/util.js.map +1 -1
- package/lib/stdlib/plugin/index.d.ts +1 -0
- package/lib/stdlib/plugin/index.js +1 -0
- package/lib/stdlib/plugin/index.js.map +1 -1
- package/lib/stdlib/plugin/legend/index.d.ts +2 -2
- package/lib/stdlib/plugin/legend/index.js +3 -3
- package/lib/stdlib/plugin/legend/index.js.map +1 -1
- package/lib/stdlib/plugin/map/index.d.ts +1 -1
- package/lib/stdlib/plugin/map/index.js +6 -6
- package/lib/stdlib/plugin/map/index.js.map +1 -1
- package/lib/stdlib/plugin/menu/index.d.ts +4 -4
- package/lib/stdlib/plugin/menu/index.js +6 -6
- package/lib/stdlib/plugin/menu/index.js.map +1 -1
- package/lib/stdlib/plugin/minimap/index.d.ts +1 -1
- package/lib/stdlib/plugin/minimap/index.js +6 -6
- package/lib/stdlib/plugin/minimap/index.js.map +1 -1
- package/lib/stdlib/plugin/timebar/index.js +2 -2
- package/lib/stdlib/plugin/timebar/index.js.map +1 -1
- package/lib/stdlib/plugin/toolbar/index.d.ts +3 -3
- package/lib/stdlib/plugin/toolbar/index.js +5 -5
- package/lib/stdlib/plugin/toolbar/index.js.map +1 -1
- package/lib/stdlib/plugin/tooltip/index.d.ts +4 -4
- package/lib/stdlib/plugin/tooltip/index.js +10 -11
- package/lib/stdlib/plugin/tooltip/index.js.map +1 -1
- package/lib/stdlib/plugin/types.d.ts +1 -0
- package/lib/stdlib/plugin/watermaker/index.d.ts +78 -0
- package/lib/stdlib/plugin/watermaker/index.js +247 -0
- package/lib/stdlib/plugin/watermaker/index.js.map +1 -0
- package/lib/types/plugin.d.ts +1 -1
- package/lib/util/bbox.js +4 -5
- package/lib/util/bbox.js.map +1 -1
- package/lib/util/behavior.d.ts +2 -2
- package/lib/util/behavior.js +2 -2
- package/lib/util/behavior.js.map +1 -1
- package/lib/util/data.d.ts +2 -2
- package/lib/util/data.js.map +1 -1
- package/lib/util/dom.d.ts +15 -0
- package/lib/util/dom.js +34 -0
- package/lib/util/dom.js.map +1 -0
- package/lib/util/extend.d.ts +1 -1
- package/lib/util/extend.js +0 -1
- package/lib/util/extend.js.map +1 -1
- package/lib/util/index.d.ts +7 -52
- package/lib/util/index.js +23 -23
- package/lib/util/index.js.map +1 -1
- package/lib/util/layout.d.ts +1 -1
- package/lib/util/layout.js.map +1 -1
- package/lib/util/loop.d.ts +1 -1
- package/lib/util/math.d.ts +1 -1
- package/lib/util/matrix.d.ts +6 -0
- package/lib/util/matrix.js +52 -0
- package/lib/util/matrix.js.map +1 -0
- package/lib/util/path.js +2 -2
- package/lib/util/path.js.map +1 -1
- package/lib/util/point.d.ts +1 -1
- package/lib/util/polyline.d.ts +2 -1
- package/lib/util/polyline.js +2 -1
- package/lib/util/polyline.js.map +1 -1
- package/lib/util/router.d.ts +1 -1
- package/lib/util/shape.js.map +1 -1
- package/lib/util/shape3d.js +1 -1
- package/lib/util/shape3d.js.map +1 -1
- package/package.json +32 -40
- package/src/api-doc/graph.ts +4 -3
- package/src/constant/shape.ts +1 -1
- package/src/index.ts +5 -6
- package/src/item/node.ts +0 -1
- package/src/runtime/controller/item.ts +15 -6
- package/src/runtime/controller/layout.ts +1 -5
- package/src/runtime/graph.ts +12 -6
- package/src/stdlib/behavior/drag-canvas.ts +1 -1
- package/src/stdlib/behavior/shortcuts-call.ts +13 -4
- package/src/stdlib/behavior/zoom-canvas-3d.ts +4 -1
- package/src/stdlib/index.ts +10 -1
- package/src/stdlib/item/edge/base.ts +5 -2
- package/src/stdlib/item/edge/cubic-horizontal.ts +0 -1
- package/src/stdlib/item/edge/cubic-vertical.ts +0 -1
- package/src/stdlib/item/edge/cubic.ts +1 -1
- package/src/stdlib/item/edge/loop.ts +1 -1
- package/src/stdlib/item/node/cube.ts +102 -0
- package/src/stdlib/item/node/index.ts +3 -0
- package/src/stdlib/plugin/edgeFilterLens/index.ts +387 -0
- package/src/stdlib/plugin/grid/index.ts +6 -6
- package/src/stdlib/plugin/hull/convexHull.ts +1 -1
- package/src/stdlib/plugin/hull/hullComponent.ts +2 -3
- package/src/stdlib/plugin/hull/util.ts +6 -2
- package/src/stdlib/plugin/index.ts +1 -0
- package/src/stdlib/plugin/legend/index.ts +6 -6
- package/src/stdlib/plugin/map/index.ts +7 -7
- package/src/stdlib/plugin/menu/index.ts +13 -13
- package/src/stdlib/plugin/minimap/index.ts +6 -6
- package/src/stdlib/plugin/timebar/index.ts +4 -4
- package/src/stdlib/plugin/toolbar/index.ts +8 -8
- package/src/stdlib/plugin/tooltip/index.ts +10 -10
- package/src/stdlib/plugin/types.ts +1 -0
- package/src/stdlib/plugin/watermaker/index.ts +302 -0
- package/src/types/plugin.ts +1 -1
- package/src/util/bbox.ts +4 -5
- package/src/util/behavior.ts +4 -4
- package/src/util/data.ts +2 -3
- package/src/util/dom.ts +33 -0
- package/src/util/extend.ts +2 -3
- package/src/util/index.ts +7 -24
- package/src/util/layout.ts +3 -2
- package/src/util/loop.ts +1 -1
- package/src/util/math.ts +1 -1
- package/src/util/matrix.ts +66 -0
- package/src/util/path.ts +1 -1
- package/src/util/point.ts +1 -1
- package/src/util/polyline.ts +2 -1
- package/src/util/router.ts +1 -1
- package/src/util/shape.ts +0 -1
- package/src/util/shape3d.ts +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createDom, modifyCSS } from '@antv/dom-util';
|
|
2
|
-
import { AABB } from '@antv/g';
|
|
3
1
|
import { isString, uniqueId } from '@antv/util';
|
|
4
2
|
import insertCss from 'insert-css';
|
|
5
3
|
import Item from '../../../item/item';
|
|
4
|
+
import { createDOM, modifyCSS } from '../../../util/dom';
|
|
6
5
|
import { IGraph } from '../../../types';
|
|
7
6
|
import { IG6GraphEvent } from '../../../types/event';
|
|
8
7
|
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
8
|
+
|
|
9
9
|
typeof document !== 'undefined' &&
|
|
10
10
|
insertCss(`
|
|
11
11
|
.g6-component-contextmenu {
|
|
@@ -39,14 +39,14 @@ typeof document !== 'undefined' &&
|
|
|
39
39
|
* The `MenuConfig` interface contains the following properties:
|
|
40
40
|
|
|
41
41
|
- `handleMenuClick`: An optional function for handling menu click events. It takes two arguments: `target` (of type HTMLElement) and `item` (of type Item), and has no return value.
|
|
42
|
-
- `getContent`: An optional function for getting the content of the menu. It takes an optional argument of type `IG6GraphEvent`, and returns a value of type
|
|
42
|
+
- `getContent`: An optional function for getting the content of the menu. It takes an optional argument of type `IG6GraphEvent`, and returns a value of type HTMLElement, string, or Promise (resolving to HTMLElement or string).
|
|
43
43
|
- `offsetX`: An optional number representing the offset of the menu in the X direction.
|
|
44
44
|
- `offsetY`: An optional number representing the offset of the menu in the Y direction.
|
|
45
45
|
- `shouldBegin`: An optional function for determining whether the menu should be displayed. It takes an optional argument of type `IG6GraphEvent`, and returns a boolean value.
|
|
46
46
|
- `itemTypes`: An optional array of strings representing the types of items for which the menu is allowed to be displayed.
|
|
47
47
|
- `trigger`: An optional string, either 'click' or 'contextmenu', representing the event type that triggers the display of the menu.
|
|
48
48
|
- `onHide`: An optional function to be executed when the menu is hidden. It takes no arguments and returns a boolean value.
|
|
49
|
-
- `loadingContent`: An optional
|
|
49
|
+
- `loadingContent`: An optional HTMLElement or string representing the loading DOM.
|
|
50
50
|
- `liHoverStyle`: An optional object representing the style of li elements when hovered over. It can contain any number of key-value pairs, where the key is a style name and the value is a string.
|
|
51
51
|
*/
|
|
52
52
|
export interface MenuConfig extends IPluginBaseConfig {
|
|
@@ -54,7 +54,7 @@ export interface MenuConfig extends IPluginBaseConfig {
|
|
|
54
54
|
// return the content of menu, support the `Promise` type return value.
|
|
55
55
|
getContent?: (
|
|
56
56
|
evt?: IG6GraphEvent,
|
|
57
|
-
) =>
|
|
57
|
+
) => HTMLElement | string | Promise<HTMLElement | string>;
|
|
58
58
|
offsetX?: number;
|
|
59
59
|
offsetY?: number;
|
|
60
60
|
shouldBegin?: (evt?: IG6GraphEvent) => boolean;
|
|
@@ -62,7 +62,7 @@ export interface MenuConfig extends IPluginBaseConfig {
|
|
|
62
62
|
trigger?: 'click' | 'contextmenu';
|
|
63
63
|
onHide?: () => boolean;
|
|
64
64
|
//loading Dom
|
|
65
|
-
loadingContent?:
|
|
65
|
+
loadingContent?: HTMLElement | string;
|
|
66
66
|
liHoverStyle?: { [key: string]: string };
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -126,16 +126,16 @@ export class Menu extends Base {
|
|
|
126
126
|
.join('')}
|
|
127
127
|
}
|
|
128
128
|
`);
|
|
129
|
-
const menu =
|
|
129
|
+
const menu = createDOM(
|
|
130
130
|
`<div class=${className || 'g6-component-contextmenu'}></div>`,
|
|
131
131
|
);
|
|
132
132
|
modifyCSS(menu, { top: '0px', position: 'absolute', visibility: 'hidden' });
|
|
133
|
-
let container:
|
|
133
|
+
let container: HTMLElement | null | string = this.options.container;
|
|
134
134
|
if (!container) {
|
|
135
|
-
container = this.graph.container as
|
|
135
|
+
container = this.graph.container as HTMLElement;
|
|
136
136
|
}
|
|
137
137
|
if (isString(container)) {
|
|
138
|
-
container = document.getElementById(container) as
|
|
138
|
+
container = document.getElementById(container) as HTMLElement;
|
|
139
139
|
}
|
|
140
140
|
container.appendChild(menu);
|
|
141
141
|
this.menu = menu;
|
|
@@ -189,7 +189,7 @@ export class Menu extends Base {
|
|
|
189
189
|
if (isString(menu)) {
|
|
190
190
|
//the type is string
|
|
191
191
|
menuDom.innerHTML = menu;
|
|
192
|
-
} else if (menu instanceof
|
|
192
|
+
} else if (menu instanceof HTMLElement) {
|
|
193
193
|
//the type is htmldom
|
|
194
194
|
menuDom.innerHTML = menu.outerHTML;
|
|
195
195
|
} else {
|
|
@@ -264,10 +264,10 @@ export class Menu extends Base {
|
|
|
264
264
|
if (menu) {
|
|
265
265
|
let container = this.options.container;
|
|
266
266
|
if (!container) {
|
|
267
|
-
container = this.graph.container as
|
|
267
|
+
container = this.graph.container as HTMLElement;
|
|
268
268
|
}
|
|
269
269
|
if (isString(container)) {
|
|
270
|
-
container = document.getElementById(container) as
|
|
270
|
+
container = document.getElementById(container) as HTMLElement;
|
|
271
271
|
}
|
|
272
272
|
container.removeChild(menu);
|
|
273
273
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// TODO: update type define.
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
import { createDom, modifyCSS } from '@antv/dom-util';
|
|
4
3
|
import { Canvas, DisplayObject, Group, Rect } from '@antv/g';
|
|
5
4
|
import { debounce, each, isNil, isString, uniqueId } from '@antv/util';
|
|
6
5
|
import { IGraph } from '../../../types';
|
|
@@ -8,6 +7,7 @@ import { IG6GraphEvent } from '../../../types/event';
|
|
|
8
7
|
import { ShapeStyle } from '../../../types/item';
|
|
9
8
|
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
10
9
|
import { createCanvas } from '../../../util/canvas';
|
|
10
|
+
import { createDOM, modifyCSS } from '../../../util/dom';
|
|
11
11
|
|
|
12
12
|
const DEFAULT_MODE = 'default';
|
|
13
13
|
const KEYSHAPE_MODE = 'keyShape';
|
|
@@ -32,7 +32,7 @@ export interface MiniMapConfig extends IPluginBaseConfig {
|
|
|
32
32
|
/** Whether to hide edges on minimap to enhance performance */
|
|
33
33
|
hideEdge?: boolean;
|
|
34
34
|
/** Container for minimap */
|
|
35
|
-
container?:
|
|
35
|
+
container?: HTMLElement | null;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export class Minimap extends Base {
|
|
@@ -47,7 +47,7 @@ export class Minimap extends Base {
|
|
|
47
47
|
graphItem: DisplayObject;
|
|
48
48
|
}
|
|
49
49
|
> = new Map();
|
|
50
|
-
private container:
|
|
50
|
+
private container: HTMLElement;
|
|
51
51
|
/** Ratio of (minimap graph size / main graph size). */
|
|
52
52
|
private ratio: number;
|
|
53
53
|
/** Distance from top of minimap graph to the top of minimap container. */
|
|
@@ -111,7 +111,7 @@ export class Minimap extends Base {
|
|
|
111
111
|
const containerDOM = canvas.context.config.container as HTMLElement;
|
|
112
112
|
const isFireFox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
113
113
|
const isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
|
|
114
|
-
const viewport =
|
|
114
|
+
const viewport = createDOM(`
|
|
115
115
|
<div
|
|
116
116
|
class=${viewportClassName}
|
|
117
117
|
style='position:absolute;
|
|
@@ -631,12 +631,12 @@ export class Minimap extends Base {
|
|
|
631
631
|
const { graph, options } = this;
|
|
632
632
|
const { size, className } = options;
|
|
633
633
|
let parentNode = options.container;
|
|
634
|
-
const container:
|
|
634
|
+
const container: HTMLElement = createDOM(
|
|
635
635
|
`<div class='${className}' style='width: ${size[0]}px; height: ${size[1]}px; overflow: hidden;'></div>`,
|
|
636
636
|
);
|
|
637
637
|
|
|
638
638
|
if (isString(parentNode)) {
|
|
639
|
-
parentNode = document.getElementById(parentNode) as
|
|
639
|
+
parentNode = document.getElementById(parentNode) as HTMLElement;
|
|
640
640
|
}
|
|
641
641
|
|
|
642
642
|
if (parentNode) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createDom } from '@antv/dom-util';
|
|
2
1
|
import { Canvas } from '@antv/g';
|
|
3
2
|
import type { TimebarStyleProps } from '@antv/gui';
|
|
4
3
|
import { Timebar as GUITimebar } from '@antv/gui';
|
|
@@ -10,6 +9,7 @@ import type { ITEM_TYPE } from '../../../types/item';
|
|
|
10
9
|
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
11
10
|
import { createCanvas } from '../../../util/canvas';
|
|
12
11
|
import { formatPadding } from '../../../util/shape';
|
|
12
|
+
import { createDOM } from '../../../util/dom';
|
|
13
13
|
|
|
14
14
|
// -- start -- Adapt to GUI -- start --
|
|
15
15
|
type SubStyleProps<T, Prefix extends string> = {
|
|
@@ -123,7 +123,7 @@ const tryToGet = <T = any>(
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
export class Timebar extends Base {
|
|
126
|
-
private wrapper:
|
|
126
|
+
private wrapper: HTMLElement;
|
|
127
127
|
private canvas: Canvas;
|
|
128
128
|
private timebar: GUITimebar;
|
|
129
129
|
private graphDataCache: GraphData;
|
|
@@ -235,9 +235,9 @@ export class Timebar extends Base {
|
|
|
235
235
|
const { className } = options;
|
|
236
236
|
const { width, height } = this.containerShape;
|
|
237
237
|
|
|
238
|
-
const wrapper = (
|
|
238
|
+
const wrapper = createDOM(
|
|
239
239
|
`<div class="${className}" style="width: ${width}px;height: ${height}"></div>`,
|
|
240
|
-
)
|
|
240
|
+
);
|
|
241
241
|
this.container.appendChild(wrapper);
|
|
242
242
|
return wrapper;
|
|
243
243
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createDom, modifyCSS } from '@antv/dom-util';
|
|
2
1
|
import insertCss from 'insert-css';
|
|
3
2
|
import { IGraph } from '../../../types';
|
|
4
3
|
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
4
|
+
import { createDOM, modifyCSS } from '../../../util/dom';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The `ToolbarConfig` interface contains the following properties:
|
|
8
8
|
|
|
9
9
|
- `handleClick`: An optional function for handling clicks on the toolbar. It takes two arguments: `code` (of type string) and `graph` (of type IGraph), and has no return value.
|
|
10
|
-
- `getContent`: A required function for getting the content of the toolbar. It takes an optional argument of type `IGraph`, and returns a value of type
|
|
10
|
+
- `getContent`: A required function for getting the content of the toolbar. It takes an optional argument of type `IGraph`, and returns a value of type HTMLElement or string.
|
|
11
11
|
- `zoomSensitivity`: An optional number representing the zoom sensitivity of the toolbar. The default value is 10.
|
|
12
12
|
- `minZoom`: An optional number representing the minimum zoom ratio of the toolbar. The default value is 0.00001.
|
|
13
13
|
- `maxZoom`: An optional number representing the maximum zoom ratio of the toolbar. The default value is 1000.
|
|
@@ -17,7 +17,7 @@ export interface ToolbarConfig extends IPluginBaseConfig {
|
|
|
17
17
|
/** Function for handling clicks on toolbar */
|
|
18
18
|
handleClick?: (code: string, graph: IGraph) => void;
|
|
19
19
|
/** Function for getting content of toolbar */
|
|
20
|
-
getContent: (graph?: IGraph) =>
|
|
20
|
+
getContent: (graph?: IGraph) => HTMLElement | string;
|
|
21
21
|
/** Zoom sensitivity of toolbar */
|
|
22
22
|
zoomSensitivity: number;
|
|
23
23
|
/** Minimum zoom ratio of toolbar */
|
|
@@ -51,12 +51,12 @@ const getEventPath = (evt: MouseEvent) => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export class Toolbar extends Base {
|
|
54
|
-
public ToolbarDOM:
|
|
54
|
+
public ToolbarDOM: HTMLElement;
|
|
55
55
|
public ContainerDOM: HTMLElement;
|
|
56
56
|
constructor(config: Partial<ToolbarConfig>) {
|
|
57
57
|
super(config);
|
|
58
|
-
this.ToolbarDOM =
|
|
59
|
-
this.ContainerDOM =
|
|
58
|
+
this.ToolbarDOM = createDOM('<div></div>');
|
|
59
|
+
this.ContainerDOM = createDOM('<div></div>');
|
|
60
60
|
}
|
|
61
61
|
public getDefaultCfgs(): ToolbarConfig {
|
|
62
62
|
return {
|
|
@@ -95,7 +95,7 @@ export class Toolbar extends Base {
|
|
|
95
95
|
public getContainer() {
|
|
96
96
|
const { container } = this.options;
|
|
97
97
|
if (typeof container === 'string') {
|
|
98
|
-
this.ContainerDOM = document.getElementById(container) as
|
|
98
|
+
this.ContainerDOM = document.getElementById(container) as HTMLElement;
|
|
99
99
|
} else {
|
|
100
100
|
this.ContainerDOM = this.graph.container;
|
|
101
101
|
}
|
|
@@ -109,7 +109,7 @@ export class Toolbar extends Base {
|
|
|
109
109
|
const { getContent, className, handleClick, position } = this.options;
|
|
110
110
|
const ToolBarContent = getContent(graph);
|
|
111
111
|
if (typeof ToolBarContent === 'string') {
|
|
112
|
-
this.ToolbarDOM =
|
|
112
|
+
this.ToolbarDOM = createDOM(ToolBarContent);
|
|
113
113
|
} else {
|
|
114
114
|
this.ToolbarDOM = ToolBarContent;
|
|
115
115
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// TODO: update type define.
|
|
2
|
-
import { createDom, modifyCSS } from '@antv/dom-util';
|
|
3
2
|
import { AABB } from '@antv/g';
|
|
4
3
|
import { isArray, isString, uniqueId } from '@antv/util';
|
|
5
4
|
import insertCss from 'insert-css';
|
|
6
5
|
import { IGraph } from '../../../types';
|
|
7
6
|
import { IG6GraphEvent } from '../../../types/event';
|
|
8
7
|
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
8
|
+
import { createDOM, modifyCSS } from '../../../util/dom';
|
|
9
9
|
|
|
10
10
|
typeof document !== 'undefined' &&
|
|
11
11
|
insertCss(`
|
|
@@ -56,21 +56,21 @@ type Placement =
|
|
|
56
56
|
/**
|
|
57
57
|
* The `TooltipConfig` interface contains the following properties:
|
|
58
58
|
|
|
59
|
-
- `getContent`: An optional function for getting the content of the tooltip. It takes an optional argument of type `IG6GraphEvent`, and returns a value of type
|
|
59
|
+
- `getContent`: An optional function for getting the content of the tooltip. It takes an optional argument of type `IG6GraphEvent`, and returns a value of type HTMLElement, string, or Promise (resolving to HTMLElement or string).
|
|
60
60
|
- `offsetX`: An optional number representing the offset of the tooltip in the X direction.
|
|
61
61
|
- `offsetY`: An optional number representing the offset of the tooltip in the Y direction.
|
|
62
62
|
- `shouldBegin`: An optional function for determining whether the tooltip should be displayed. It takes an optional argument of type `IG6GraphEvent`, and returns a boolean value.
|
|
63
63
|
- `itemTypes`: An optional array of strings representing the types of items for which the tooltip is allowed to be displayed. The possible values are 'node', 'edge', 'combo', and 'canvas'.
|
|
64
64
|
- `trigger`: An optional string, either 'pointerenter' or 'click', representing the event type that triggers the display of the tooltip.
|
|
65
65
|
- `fixToNode`: An optional array of two numbers, a string representing a placement, or undefined, representing how to fix the tooltip to a node.
|
|
66
|
-
- `loadingContent`: An optional
|
|
66
|
+
- `loadingContent`: An optional HTMLElement or string representing the loading DOM.
|
|
67
67
|
|
|
68
68
|
*/
|
|
69
69
|
export interface TooltipConfig extends IPluginBaseConfig {
|
|
70
70
|
/** Function for getting tooltip content */
|
|
71
71
|
getContent?: (
|
|
72
72
|
evt?: IG6GraphEvent,
|
|
73
|
-
) =>
|
|
73
|
+
) => HTMLElement | string | Promise<HTMLElement | string>;
|
|
74
74
|
/** Offset of tooltip in X direction */
|
|
75
75
|
offsetX?: number;
|
|
76
76
|
/** Offset of tooltip in Y direction */
|
|
@@ -84,7 +84,7 @@ export interface TooltipConfig extends IPluginBaseConfig {
|
|
|
84
84
|
/** How to fix tooltip to node */
|
|
85
85
|
fixToNode?: [number, number] | Placement | undefined;
|
|
86
86
|
/** Loading DOM */
|
|
87
|
-
loadingContent?:
|
|
87
|
+
loadingContent?: HTMLElement | string;
|
|
88
88
|
}
|
|
89
89
|
export class Tooltip extends Base {
|
|
90
90
|
private tooltip;
|
|
@@ -153,7 +153,7 @@ export class Tooltip extends Base {
|
|
|
153
153
|
public init(graph: IGraph) {
|
|
154
154
|
super.init(graph);
|
|
155
155
|
const className = this.options.className;
|
|
156
|
-
const tooltip =
|
|
156
|
+
const tooltip = createDOM(
|
|
157
157
|
`<div class='${className || 'g6-component-tooltip'}'></div>`,
|
|
158
158
|
);
|
|
159
159
|
modifyCSS(tooltip, {
|
|
@@ -173,12 +173,12 @@ export class Tooltip extends Base {
|
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
175
|
//`container` string type in v5
|
|
176
|
-
let container:
|
|
176
|
+
let container: HTMLElement | null | string = this.options.container;
|
|
177
177
|
if (!container) {
|
|
178
|
-
container = this.graph.container as
|
|
178
|
+
container = this.graph.container as HTMLElement;
|
|
179
179
|
}
|
|
180
180
|
if (isString(container)) {
|
|
181
|
-
container = document.getElementById(container) as
|
|
181
|
+
container = document.getElementById(container) as HTMLElement;
|
|
182
182
|
}
|
|
183
183
|
container.appendChild(tooltip);
|
|
184
184
|
this.tooltip = tooltip;
|
|
@@ -264,7 +264,7 @@ export class Tooltip extends Base {
|
|
|
264
264
|
});
|
|
265
265
|
if (isString(tooltip)) {
|
|
266
266
|
tooltipDom.innerHTML = tooltip;
|
|
267
|
-
} else if (tooltip instanceof
|
|
267
|
+
} else if (tooltip instanceof HTMLElement) {
|
|
268
268
|
this.clearContainer();
|
|
269
269
|
this.container.appendChild(tooltip);
|
|
270
270
|
} else {
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { uniqueId, isString } from '@antv/util';
|
|
2
|
+
import { Canvas, Group, Image, Text, TextStyleProps } from '@antv/g';
|
|
3
|
+
import { Plugin as Base, IPluginBaseConfig } from '../../../types/plugin';
|
|
4
|
+
import { createCanvas } from '../../../util/canvas';
|
|
5
|
+
import { IGraph } from '../../../types';
|
|
6
|
+
|
|
7
|
+
/** Define configuration types for image and text watermarks */
|
|
8
|
+
type ImageWaterMarkerConfig = {
|
|
9
|
+
/** URL of the image used as the watermark. */
|
|
10
|
+
imgURL: string;
|
|
11
|
+
/** Width of the image watermark in pixels. */
|
|
12
|
+
width: number;
|
|
13
|
+
/** Height of the image watermark in pixels. */
|
|
14
|
+
height: number;
|
|
15
|
+
/** Rotation angle of the image watermark in degrees (0 to 360). */
|
|
16
|
+
rotate: number;
|
|
17
|
+
};
|
|
18
|
+
interface TextWaterMarkerConfig extends TextStyleProps {
|
|
19
|
+
/** Text or an array of texts to be used as the watermark content. */
|
|
20
|
+
texts: string | string[];
|
|
21
|
+
/** Rotation angle of the text watermark in degrees (0 to 360). */
|
|
22
|
+
rotate: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Define configuration types for watermarks */
|
|
26
|
+
export interface WaterMarkerConfig extends IPluginBaseConfig {
|
|
27
|
+
/** The watermarker canvas. undefined by default means create a new canvas to draw the markers. */
|
|
28
|
+
canvas?: Canvas;
|
|
29
|
+
/** (Optional) The width of the watermark canvas in pixels. undefined by default, means equal to graph's width. */
|
|
30
|
+
width?: number;
|
|
31
|
+
/** (Optional) The height of the watermark canvas in pixels. undefined by default, means equal to graph's height. */
|
|
32
|
+
height?: number;
|
|
33
|
+
/** (Optional) The mode of the watermark, either 'image' or 'text'. */
|
|
34
|
+
mode?: 'image' | 'text';
|
|
35
|
+
/** (Optional) The position of the watermark, default: under the main canvas*/
|
|
36
|
+
position?: 'top' | 'middle' | 'bottom';
|
|
37
|
+
/** (Optional) Configuration for an image watermark (See ImageWaterMarkerConfig). */
|
|
38
|
+
image?: Partial<ImageWaterMarkerConfig>;
|
|
39
|
+
/** (Optional) Configuration for a text watermark (See TextWaterMarkerConfig). */
|
|
40
|
+
text?: Partial<TextWaterMarkerConfig>;
|
|
41
|
+
/** The first marker's position. [0, 0] by default. */
|
|
42
|
+
begin?: [number, number];
|
|
43
|
+
/** The gap of x and y between neighbor markers. [100, 100] by default. */
|
|
44
|
+
seperation?: [number, number];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class WaterMarker extends Base {
|
|
48
|
+
private container: HTMLElement;
|
|
49
|
+
private canvas: Canvas;
|
|
50
|
+
private canvasSize: [number, number];
|
|
51
|
+
private followGraphSize: boolean;
|
|
52
|
+
|
|
53
|
+
constructor(options?: WaterMarkerConfig) {
|
|
54
|
+
super(options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public getDefaultCfgs(): WaterMarkerConfig {
|
|
58
|
+
return {
|
|
59
|
+
key: `watermarker-${uniqueId()}`,
|
|
60
|
+
container: null,
|
|
61
|
+
canvas: undefined,
|
|
62
|
+
mode: 'image',
|
|
63
|
+
width: undefined,
|
|
64
|
+
height: undefined,
|
|
65
|
+
position: 'bottom',
|
|
66
|
+
begin: [0, 0],
|
|
67
|
+
seperation: [100, 100],
|
|
68
|
+
image: {
|
|
69
|
+
imgURL:
|
|
70
|
+
'https://gw.alipayobjects.com/os/s/prod/antv/assets/image/logo-with-text-73b8a.svg',
|
|
71
|
+
width: 94,
|
|
72
|
+
height: 28,
|
|
73
|
+
rotate: 0,
|
|
74
|
+
},
|
|
75
|
+
text: {
|
|
76
|
+
texts: 'AntV',
|
|
77
|
+
rotate: 20,
|
|
78
|
+
fontSize: 14,
|
|
79
|
+
fontFamily: 'Microsoft YaHei',
|
|
80
|
+
fill: 'rgba(0, 0, 0, 0.1)',
|
|
81
|
+
textBaseline: 'top',
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Initialize the WaterMarker plugin.
|
|
88
|
+
*/
|
|
89
|
+
public init(graph: IGraph) {
|
|
90
|
+
super.init(graph);
|
|
91
|
+
const promise = this.initCanvas();
|
|
92
|
+
promise.then(() => {
|
|
93
|
+
this.updateWaterMarker();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public getEvents() {
|
|
98
|
+
return {
|
|
99
|
+
aftersetsize: this.onGraphSetSize,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Initialize the canvas for watermark rendering.
|
|
105
|
+
*/
|
|
106
|
+
public initCanvas() {
|
|
107
|
+
const { graph, options } = this;
|
|
108
|
+
const { width, height, position, canvas } = options;
|
|
109
|
+
let parentNode = options.container;
|
|
110
|
+
let container: HTMLElement;
|
|
111
|
+
|
|
112
|
+
const graphSize = graph.getSize();
|
|
113
|
+
if (canvas) {
|
|
114
|
+
this.canvas = canvas;
|
|
115
|
+
this.canvasSize = [graphSize[0], graphSize[1]];
|
|
116
|
+
this.followGraphSize = true;
|
|
117
|
+
this.container = graph.container as HTMLDivElement;
|
|
118
|
+
return canvas.ready;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (isString(parentNode)) {
|
|
122
|
+
parentNode = document.getElementById(parentNode) as HTMLElement;
|
|
123
|
+
}
|
|
124
|
+
if (parentNode) {
|
|
125
|
+
container = parentNode;
|
|
126
|
+
} else {
|
|
127
|
+
container = graph.container as HTMLElement;
|
|
128
|
+
}
|
|
129
|
+
if (!container.style.position) {
|
|
130
|
+
container.style.position = 'relative';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.canvasSize = [
|
|
134
|
+
width === undefined ? graphSize[0] : width,
|
|
135
|
+
height === undefined ? graphSize[1] : height,
|
|
136
|
+
];
|
|
137
|
+
this.followGraphSize = width === undefined || height === undefined;
|
|
138
|
+
|
|
139
|
+
this.canvas = createCanvas(
|
|
140
|
+
'canvas',
|
|
141
|
+
container,
|
|
142
|
+
this.canvasSize[0],
|
|
143
|
+
this.canvasSize[1],
|
|
144
|
+
);
|
|
145
|
+
const $domElement = this.canvas
|
|
146
|
+
.getContextService()
|
|
147
|
+
.getDomElement() as unknown as HTMLElement;
|
|
148
|
+
$domElement.style.position = 'fixed';
|
|
149
|
+
$domElement.style.outline = 'none';
|
|
150
|
+
$domElement.style.pointerEvents = 'none';
|
|
151
|
+
$domElement.style.userSelect = 'none';
|
|
152
|
+
this.container = container;
|
|
153
|
+
|
|
154
|
+
const canvasEl = this.canvas.getContextService().getDomElement() as any;
|
|
155
|
+
this.container.removeChild(canvasEl);
|
|
156
|
+
const graphCanvasDOM = graph.canvas
|
|
157
|
+
.getContextService()
|
|
158
|
+
.getDomElement() as any;
|
|
159
|
+
const graphTransientCanvasDOM = graph.transientCanvas
|
|
160
|
+
.getContextService()
|
|
161
|
+
.getDomElement() as any;
|
|
162
|
+
switch (position) {
|
|
163
|
+
case 'top':
|
|
164
|
+
this.container.appendChild(canvasEl);
|
|
165
|
+
break;
|
|
166
|
+
case 'middle':
|
|
167
|
+
this.container.insertBefore(canvasEl, graphTransientCanvasDOM);
|
|
168
|
+
break;
|
|
169
|
+
case 'bottom':
|
|
170
|
+
default:
|
|
171
|
+
this.container.insertBefore(canvasEl, graphCanvasDOM);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return this.canvas.ready;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private onGraphSetSize(e) {
|
|
178
|
+
const { size } = e;
|
|
179
|
+
if (!this.followGraphSize) return;
|
|
180
|
+
this.canvas.resize(size[0], size[1]);
|
|
181
|
+
this.updateWaterMarker();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Update the watermark based on the chosen mode (image or text).
|
|
186
|
+
*/
|
|
187
|
+
public updateWaterMarker() {
|
|
188
|
+
switch (this.options.mode) {
|
|
189
|
+
case 'text':
|
|
190
|
+
this.setTextWaterMarker();
|
|
191
|
+
break;
|
|
192
|
+
case 'image':
|
|
193
|
+
default:
|
|
194
|
+
this.setImageWaterMarker();
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Render an image watermark on the canvas.
|
|
201
|
+
*/
|
|
202
|
+
public setImageWaterMarker() {
|
|
203
|
+
const { canvas, options, canvasSize } = this;
|
|
204
|
+
const { image, begin, seperation } = options;
|
|
205
|
+
const { imgURL, rotate = 0, ...imageStyles } = image;
|
|
206
|
+
|
|
207
|
+
const currentPosition = [...begin];
|
|
208
|
+
let imageBounds;
|
|
209
|
+
const getRowGroup = () => {
|
|
210
|
+
const rowGroup = new Group();
|
|
211
|
+
while (currentPosition[0] < canvasSize[0]) {
|
|
212
|
+
const imageShape = new Image({
|
|
213
|
+
style: {
|
|
214
|
+
...imageStyles,
|
|
215
|
+
img: imgURL,
|
|
216
|
+
x: currentPosition[0],
|
|
217
|
+
y: currentPosition[1],
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
if (rotate) {
|
|
221
|
+
imageShape.style.transformOrigin = 'center';
|
|
222
|
+
imageShape.style.transform = `rotate(${rotate}deg)`;
|
|
223
|
+
}
|
|
224
|
+
if (!imageBounds) {
|
|
225
|
+
imageBounds = imageShape.getLocalBounds();
|
|
226
|
+
}
|
|
227
|
+
rowGroup.appendChild(imageShape);
|
|
228
|
+
currentPosition[0] += imageBounds.halfExtents[0] * 2 + seperation[0];
|
|
229
|
+
}
|
|
230
|
+
return rowGroup;
|
|
231
|
+
};
|
|
232
|
+
while (currentPosition[1] < canvasSize[1]) {
|
|
233
|
+
canvas.appendChild(getRowGroup());
|
|
234
|
+
currentPosition[0] = begin[0];
|
|
235
|
+
currentPosition[1] += imageBounds.halfExtents[1] * 2 + seperation[1];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Render a text watermark on the canvas.
|
|
241
|
+
*/
|
|
242
|
+
public async setTextWaterMarker() {
|
|
243
|
+
const { canvas, options, canvasSize } = this;
|
|
244
|
+
const { text, seperation, begin } = options;
|
|
245
|
+
const { texts, rotate, ...textStyles } = text;
|
|
246
|
+
|
|
247
|
+
const currentPosition = [...begin];
|
|
248
|
+
const displayTexts = isString(texts) ? [texts] : texts;
|
|
249
|
+
const textContent = displayTexts.join('\n');
|
|
250
|
+
let textBounds;
|
|
251
|
+
const getRowGroup = () => {
|
|
252
|
+
const rowGroup = new Group();
|
|
253
|
+
while (currentPosition[0] < canvasSize[0]) {
|
|
254
|
+
const textShape = new Text({
|
|
255
|
+
style: {
|
|
256
|
+
...textStyles,
|
|
257
|
+
text: textContent,
|
|
258
|
+
x: currentPosition[0],
|
|
259
|
+
y: currentPosition[1],
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
if (rotate) {
|
|
263
|
+
textShape.style.transform = `rotate(${rotate}deg)`;
|
|
264
|
+
}
|
|
265
|
+
if (!textBounds) {
|
|
266
|
+
textBounds = textShape.getLocalBounds();
|
|
267
|
+
}
|
|
268
|
+
rowGroup.appendChild(textShape);
|
|
269
|
+
currentPosition[0] += textBounds.halfExtents[0] * 2 + seperation[0];
|
|
270
|
+
}
|
|
271
|
+
return rowGroup;
|
|
272
|
+
};
|
|
273
|
+
while (currentPosition[1] < canvasSize[1]) {
|
|
274
|
+
canvas.appendChild(getRowGroup());
|
|
275
|
+
currentPosition[0] = begin[0];
|
|
276
|
+
currentPosition[1] += textBounds.halfExtents[1] * 2 + seperation[1];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Destroy the WaterMarker and remove it from the container.
|
|
282
|
+
*/
|
|
283
|
+
public destroy() {
|
|
284
|
+
const { canvas, options } = this;
|
|
285
|
+
|
|
286
|
+
const parentNode = options.container;
|
|
287
|
+
let container: HTMLElement;
|
|
288
|
+
|
|
289
|
+
if (!parentNode) {
|
|
290
|
+
container = this.graph.container as HTMLElement;
|
|
291
|
+
}
|
|
292
|
+
if (isString(container)) {
|
|
293
|
+
container = document.getElementById(container) as HTMLElement;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (container !== this.graph.container) {
|
|
297
|
+
container.remove();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
canvas.destroy();
|
|
301
|
+
}
|
|
302
|
+
}
|
package/src/types/plugin.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { deepMix, each } from '@antv/util';
|
|
|
2
2
|
import { IGraph } from './graph';
|
|
3
3
|
|
|
4
4
|
export interface IPluginBaseConfig {
|
|
5
|
-
container?:
|
|
5
|
+
container?: HTMLElement | string | null;
|
|
6
6
|
className?: string;
|
|
7
7
|
graph?: IGraph;
|
|
8
8
|
[key: string]: any;
|
package/src/util/bbox.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable prefer-spread */
|
|
2
1
|
import { AABB } from '@antv/g';
|
|
3
2
|
import { Point, PolyPoint } from 'types/common';
|
|
4
3
|
|
|
@@ -40,10 +39,10 @@ export const getBBoxFromPoints = (points: PolyPoint[] = []): AABB => {
|
|
|
40
39
|
xs.push(p.x);
|
|
41
40
|
ys.push(p.y);
|
|
42
41
|
});
|
|
43
|
-
const minX = Math.min
|
|
44
|
-
const maxX = Math.max
|
|
45
|
-
const minY = Math.min
|
|
46
|
-
const maxY = Math.max
|
|
42
|
+
const minX = Math.min(...xs);
|
|
43
|
+
const maxX = Math.max(...xs);
|
|
44
|
+
const minY = Math.min(...ys);
|
|
45
|
+
const maxY = Math.max(...ys);
|
|
47
46
|
const bbox = new AABB();
|
|
48
47
|
bbox.setMinMax([minX, minY, 0], [maxX, maxY, 0]);
|
|
49
48
|
return bbox;
|
package/src/util/behavior.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { BehaviorOptionsOf, BehaviorRegistry } from 'types/behavior';
|
|
2
1
|
import { isString } from '@antv/util';
|
|
2
|
+
import { BehaviorOptionsOf, BehaviorRegistry } from '../types/behavior';
|
|
3
3
|
import { isArrayOverlap } from './array';
|
|
4
4
|
|
|
5
5
|
const TREE_BEHAVIORS = ['collapse-expand-tree'];
|
|
6
|
-
export
|
|
6
|
+
export function hasTreeBehaviors(
|
|
7
7
|
behaviors: BehaviorOptionsOf<BehaviorRegistry>[],
|
|
8
|
-
)
|
|
8
|
+
) {
|
|
9
9
|
if (!behaviors?.length) return false;
|
|
10
10
|
const behaviorTypes = behaviors
|
|
11
11
|
.map((behavior) => (isString(behavior) ? behavior : behavior.type))
|
|
12
12
|
.filter(Boolean);
|
|
13
13
|
return isArrayOverlap(TREE_BEHAVIORS, behaviorTypes);
|
|
14
|
-
}
|
|
14
|
+
}
|