@antv/g6 5.0.49 → 5.0.51
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/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/dist/g6.min.js +38 -59
- package/dist/lib/behaviors/brush-select.d.ts +2 -3
- package/dist/lib/behaviors/click-select.d.ts +2 -2
- package/dist/lib/behaviors/drag-element.d.ts +21 -2
- package/dist/lib/behaviors/focus-element.d.ts +18 -0
- package/dist/lib/exports.d.ts +1 -1
- package/dist/lib/layouts/types.d.ts +9 -1
- package/dist/lib/plugins/bubble-sets.d.ts +1 -1
- package/dist/lib/plugins/index.d.ts +2 -0
- package/dist/lib/plugins/legend.d.ts +10 -2
- package/dist/lib/plugins/minimap/index.d.ts +7 -4
- package/dist/lib/plugins/title/index.d.ts +85 -0
- package/dist/lib/runtime/element.d.ts +8 -0
- package/dist/lib/runtime/graph.d.ts +27 -0
- package/dist/lib/runtime/layout.d.ts +2 -1
- package/dist/lib/utils/data.d.ts +9 -0
- package/dist/lib/utils/element.d.ts +1 -1
- package/dist/lib/utils/vector.d.ts +9 -0
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/brush-select.d.ts +2 -3
- package/esm/behaviors/brush-select.js +14 -5
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/click-select.d.ts +2 -2
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/create-edge.js +5 -1
- package/esm/behaviors/create-edge.js.map +1 -1
- package/esm/behaviors/drag-canvas.js +2 -7
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/behaviors/drag-element-force.js +1 -1
- package/esm/behaviors/drag-element-force.js.map +1 -1
- package/esm/behaviors/drag-element.d.ts +21 -2
- package/esm/behaviors/drag-element.js +24 -3
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/focus-element.d.ts +18 -0
- package/esm/behaviors/focus-element.js +18 -1
- package/esm/behaviors/focus-element.js.map +1 -1
- package/esm/behaviors/lasso-select.js +3 -3
- package/esm/behaviors/lasso-select.js.map +1 -1
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/exports.d.ts +1 -1
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/layouts/types.d.ts +9 -1
- package/esm/plugins/bubble-sets.d.ts +1 -1
- package/esm/plugins/bubble-sets.js +30 -7
- package/esm/plugins/bubble-sets.js.map +1 -1
- package/esm/plugins/grid-line.js +1 -1
- package/esm/plugins/grid-line.js.map +1 -1
- package/esm/plugins/index.d.ts +2 -0
- package/esm/plugins/index.js +1 -0
- package/esm/plugins/index.js.map +1 -1
- package/esm/plugins/legend.d.ts +10 -2
- package/esm/plugins/legend.js.map +1 -1
- package/esm/plugins/minimap/index.d.ts +7 -4
- package/esm/plugins/minimap/index.js +41 -52
- package/esm/plugins/minimap/index.js.map +1 -1
- package/esm/plugins/title/index.d.ts +85 -0
- package/esm/plugins/title/index.js +172 -0
- package/esm/plugins/title/index.js.map +1 -0
- package/esm/plugins/tooltip.js +6 -1
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/registry/build-in.js +5 -4
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/element.d.ts +8 -0
- package/esm/runtime/element.js +53 -8
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +27 -0
- package/esm/runtime/graph.js +35 -2
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +2 -1
- package/esm/runtime/layout.js +8 -6
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/viewport.js +3 -0
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/themes/base.js +1 -0
- package/esm/themes/base.js.map +1 -1
- package/esm/transforms/process-parallel-edges.js +16 -3
- package/esm/transforms/process-parallel-edges.js.map +1 -1
- package/esm/utils/data.d.ts +9 -0
- package/esm/utils/data.js +11 -0
- package/esm/utils/data.js.map +1 -1
- package/esm/utils/element.d.ts +1 -1
- package/esm/utils/element.js.map +1 -1
- package/esm/utils/shortcut.js +1 -1
- package/esm/utils/shortcut.js.map +1 -1
- package/esm/utils/vector.d.ts +9 -0
- package/esm/utils/vector.js +17 -0
- package/esm/utils/vector.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/brush-select.d.ts +2 -3
- package/lib/behaviors/brush-select.js +14 -5
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/click-select.d.ts +2 -2
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/create-edge.js +5 -1
- package/lib/behaviors/create-edge.js.map +1 -1
- package/lib/behaviors/drag-canvas.js +1 -6
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/behaviors/drag-element-force.js +1 -1
- package/lib/behaviors/drag-element-force.js.map +1 -1
- package/lib/behaviors/drag-element.d.ts +21 -2
- package/lib/behaviors/drag-element.js +23 -2
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/focus-element.d.ts +18 -0
- package/lib/behaviors/focus-element.js +18 -1
- package/lib/behaviors/focus-element.js.map +1 -1
- package/lib/behaviors/lasso-select.js +3 -3
- package/lib/behaviors/lasso-select.js.map +1 -1
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/exports.d.ts +1 -1
- package/lib/exports.js +3 -2
- package/lib/exports.js.map +1 -1
- package/lib/layouts/types.d.ts +9 -1
- package/lib/plugins/bubble-sets.d.ts +1 -1
- package/lib/plugins/bubble-sets.js +30 -7
- package/lib/plugins/bubble-sets.js.map +1 -1
- package/lib/plugins/grid-line.js +1 -1
- package/lib/plugins/grid-line.js.map +1 -1
- package/lib/plugins/index.d.ts +2 -0
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/legend.d.ts +10 -2
- package/lib/plugins/legend.js.map +1 -1
- package/lib/plugins/minimap/index.d.ts +7 -4
- package/lib/plugins/minimap/index.js +41 -52
- package/lib/plugins/minimap/index.js.map +1 -1
- package/lib/plugins/title/index.d.ts +85 -0
- package/lib/plugins/title/index.js +176 -0
- package/lib/plugins/title/index.js.map +1 -0
- package/lib/plugins/tooltip.js +6 -1
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/registry/build-in.js +1 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/element.d.ts +8 -0
- package/lib/runtime/element.js +53 -8
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +27 -0
- package/lib/runtime/graph.js +35 -2
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +2 -1
- package/lib/runtime/layout.js +8 -6
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/viewport.js +3 -0
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/themes/base.js +1 -0
- package/lib/themes/base.js.map +1 -1
- package/lib/transforms/process-parallel-edges.js +16 -3
- package/lib/transforms/process-parallel-edges.js.map +1 -1
- package/lib/utils/data.d.ts +9 -0
- package/lib/utils/data.js +13 -0
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/element.d.ts +1 -1
- package/lib/utils/element.js.map +1 -1
- package/lib/utils/shortcut.js +1 -1
- package/lib/utils/shortcut.js.map +1 -1
- package/lib/utils/vector.d.ts +9 -0
- package/lib/utils/vector.js +18 -0
- package/lib/utils/vector.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +11 -11
- package/src/behaviors/brush-select.ts +17 -7
- package/src/behaviors/click-select.ts +1 -1
- package/src/behaviors/create-edge.ts +5 -3
- package/src/behaviors/drag-canvas.ts +2 -6
- package/src/behaviors/drag-element-force.ts +2 -1
- package/src/behaviors/drag-element.ts +37 -4
- package/src/behaviors/focus-element.ts +28 -1
- package/src/behaviors/lasso-select.ts +3 -3
- package/src/elements/combos/base-combo.ts +2 -1
- package/src/elements/edges/base-edge.ts +2 -1
- package/src/elements/nodes/base-node.ts +2 -1
- package/src/exports.ts +1 -0
- package/src/layouts/types.ts +9 -1
- package/src/plugins/bubble-sets.ts +37 -9
- package/src/plugins/grid-line.ts +1 -1
- package/src/plugins/index.ts +2 -0
- package/src/plugins/legend.ts +1 -1
- package/src/plugins/minimap/index.ts +50 -63
- package/src/plugins/title/index.ts +300 -0
- package/src/plugins/tooltip.ts +8 -2
- package/src/registry/build-in.ts +6 -4
- package/src/runtime/canvas.ts +4 -2
- package/src/runtime/element.ts +54 -9
- package/src/runtime/graph.ts +36 -2
- package/src/runtime/layout.ts +13 -6
- package/src/runtime/viewport.ts +14 -3
- package/src/themes/base.ts +1 -0
- package/src/transforms/process-parallel-edges.ts +17 -3
- package/src/types/edge.ts +1 -3
- package/src/utils/data.ts +12 -0
- package/src/utils/element.ts +5 -5
- package/src/utils/shortcut.ts +1 -1
- package/src/utils/vector.ts +17 -0
- package/src/version.ts +1 -1
- package/src/layouts/hierarchy.d.ts +0 -10
|
@@ -51,11 +51,11 @@ export interface BubbleSetsOptions extends BasePluginOptions, IBubbleSetOptions,
|
|
|
51
51
|
* <en/> The principle is to represent sets by creating a shape similar to a bubble. Each set is represented by a unique "bubble", and the elements in the set are contained within this bubble. If two sets have an intersection, then the two bubbles will have an overlapping part, which represents the intersection of the two sets.
|
|
52
52
|
*/
|
|
53
53
|
export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
|
|
54
|
-
private shape
|
|
54
|
+
private shape?: Contour;
|
|
55
55
|
|
|
56
56
|
private bubbleSets!: BubbleSetsJS;
|
|
57
57
|
|
|
58
|
-
private path
|
|
58
|
+
private path: PathArray | null = null;
|
|
59
59
|
|
|
60
60
|
private members: Map<ID, IRectangle | ILine> = new Map();
|
|
61
61
|
|
|
@@ -90,8 +90,9 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
|
|
|
90
90
|
|
|
91
91
|
private init() {
|
|
92
92
|
this.bubbleSets = new BubbleSetsJS(this.options);
|
|
93
|
-
this.members
|
|
94
|
-
this.avoidMembers
|
|
93
|
+
this.members.clear();
|
|
94
|
+
this.avoidMembers.clear();
|
|
95
|
+
this.path = null;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
private parseOptions() {
|
|
@@ -139,8 +140,21 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
|
|
|
139
140
|
const currAvoidMembers = this.options.avoidMembers;
|
|
140
141
|
const prevAvoidMembers = [...this.avoidMembers.keys()];
|
|
141
142
|
|
|
142
|
-
if (
|
|
143
|
+
if (currMembers.length === 0 && currAvoidMembers.length === 0) {
|
|
144
|
+
this.members.clear();
|
|
145
|
+
this.avoidMembers.clear();
|
|
146
|
+
this.path = [] as unknown as PathArray;
|
|
143
147
|
return this.path;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
!forceUpdateId &&
|
|
152
|
+
this.path &&
|
|
153
|
+
isEqual(currMembers, prevMembers) &&
|
|
154
|
+
isEqual(currAvoidMembers, prevAvoidMembers)
|
|
155
|
+
) {
|
|
156
|
+
return this.path;
|
|
157
|
+
}
|
|
144
158
|
|
|
145
159
|
const { enter: membersToEnter = [], exit: membersToExit = [] } = arrayDiff(prevMembers, currMembers, (d) => d);
|
|
146
160
|
const { enter: avoidMembersToEnter = [], exit: avoidMembersToExit = [] } = arrayDiff(
|
|
@@ -150,8 +164,17 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
|
|
|
150
164
|
);
|
|
151
165
|
|
|
152
166
|
if (forceUpdateId) {
|
|
153
|
-
|
|
154
|
-
|
|
167
|
+
const isMemberNow = currMembers.includes(forceUpdateId);
|
|
168
|
+
const isAvoidNow = currAvoidMembers.includes(forceUpdateId);
|
|
169
|
+
|
|
170
|
+
if (isMemberNow) {
|
|
171
|
+
membersToExit.push(forceUpdateId);
|
|
172
|
+
membersToEnter.push(forceUpdateId);
|
|
173
|
+
}
|
|
174
|
+
if (isAvoidNow) {
|
|
175
|
+
avoidMembersToExit.push(forceUpdateId);
|
|
176
|
+
avoidMembersToEnter.push(forceUpdateId);
|
|
177
|
+
}
|
|
155
178
|
}
|
|
156
179
|
|
|
157
180
|
const updateBubbleSets = (ids: ID[], isEntering: boolean, isMember: boolean) => {
|
|
@@ -247,7 +270,7 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
|
|
|
247
270
|
*/
|
|
248
271
|
public addAvoidMember(avoidMembers: ID | ID[]) {
|
|
249
272
|
const avoidMembersToAdd = Array.isArray(avoidMembers) ? avoidMembers : [avoidMembers];
|
|
250
|
-
if (avoidMembersToAdd.some((
|
|
273
|
+
if (avoidMembersToAdd.some((avoidMember) => this.options.members.includes(avoidMember))) {
|
|
251
274
|
this.options.members = this.options.members.filter((id) => !avoidMembersToAdd.includes(id));
|
|
252
275
|
}
|
|
253
276
|
this.options.avoidMembers = [...new Set([...this.options.avoidMembers, ...avoidMembersToAdd])];
|
|
@@ -294,7 +317,12 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
|
|
|
294
317
|
public destroy(): void {
|
|
295
318
|
this.context.graph.off(GraphEvent.AFTER_RENDER, this.drawBubbleSets);
|
|
296
319
|
this.context.graph.off(GraphEvent.AFTER_ELEMENT_UPDATE, this.updateBubbleSetsPath);
|
|
297
|
-
|
|
320
|
+
|
|
321
|
+
if (this.shape) {
|
|
322
|
+
this.shape.destroy();
|
|
323
|
+
this.shape = undefined;
|
|
324
|
+
}
|
|
325
|
+
|
|
298
326
|
super.destroy();
|
|
299
327
|
}
|
|
300
328
|
}
|
package/src/plugins/grid-line.ts
CHANGED
|
@@ -177,7 +177,7 @@ export class GridLine extends BasePlugin<GridLineOptions> {
|
|
|
177
177
|
data: { scale, origin },
|
|
178
178
|
} = event;
|
|
179
179
|
|
|
180
|
-
if (!scale) return;
|
|
180
|
+
if (!scale || (origin === undefined && this.context.viewport === undefined)) return;
|
|
181
181
|
|
|
182
182
|
const prevScale = this.currentScale;
|
|
183
183
|
this.currentScale = scale;
|
package/src/plugins/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { Legend } from './legend';
|
|
|
14
14
|
export { Minimap } from './minimap';
|
|
15
15
|
export { Snapline } from './snapline';
|
|
16
16
|
export { Timebar } from './timebar';
|
|
17
|
+
export { Title } from './title';
|
|
17
18
|
export { Toolbar } from './toolbar';
|
|
18
19
|
export { Tooltip } from './tooltip';
|
|
19
20
|
export { Watermark } from './watermark';
|
|
@@ -34,6 +35,7 @@ export type { LegendOptions } from './legend';
|
|
|
34
35
|
export type { MinimapOptions } from './minimap';
|
|
35
36
|
export type { SnaplineOptions } from './snapline';
|
|
36
37
|
export type { TimebarOptions } from './timebar';
|
|
38
|
+
export type { SubTitleStyle, TitleOptions, TitleStyle } from './title';
|
|
37
39
|
export type { ToolbarOptions } from './toolbar';
|
|
38
40
|
export type { TooltipOptions } from './tooltip';
|
|
39
41
|
export type { WatermarkOptions } from './watermark';
|
package/src/plugins/legend.ts
CHANGED
|
@@ -248,7 +248,7 @@ export class Legend extends BasePlugin<LegendOptions> {
|
|
|
248
248
|
};
|
|
249
249
|
};
|
|
250
250
|
|
|
251
|
-
|
|
251
|
+
protected getMarkerData = (field: string | ((item: ElementDatum) => string), elementType: ElementType) => {
|
|
252
252
|
if (!field) return [];
|
|
253
253
|
const { model, element } = this.context;
|
|
254
254
|
const { nodes, edges, combos } = model.getData();
|
|
@@ -3,7 +3,7 @@ import { debounce, throttle } from '@antv/util';
|
|
|
3
3
|
import { GraphEvent } from '../../constants';
|
|
4
4
|
import type { RuntimeContext } from '../../runtime/types';
|
|
5
5
|
import { GraphData } from '../../spec';
|
|
6
|
-
import type { ElementDatum, ElementType,
|
|
6
|
+
import type { ElementDatum, ElementType, IGraphLifeCycleEvent, Padding, Placement, Vector3 } from '../../types';
|
|
7
7
|
import { isVisible } from '../../utils/element';
|
|
8
8
|
import { idOf } from '../../utils/id';
|
|
9
9
|
import { parsePadding } from '../../utils/padding';
|
|
@@ -56,13 +56,17 @@ export interface MinimapOptions extends BasePluginOptions {
|
|
|
56
56
|
* @remarks
|
|
57
57
|
* <zh/>
|
|
58
58
|
* - 'key' 使用元素的主图形作为缩略图形
|
|
59
|
-
* -
|
|
59
|
+
* - 'icon' 使用元素中心的 icon 作为缩略图形
|
|
60
|
+
* - 更多图形名称可查阅 https://g6.antv.antgroup.com/manual/element/node/base-node#style
|
|
61
|
+
* - 也可以传入一个函数,接收元素的 [id, 类型, 元素节点],返回一个自定义样式的图形
|
|
60
62
|
*
|
|
61
63
|
* <en/>
|
|
62
64
|
* - 'key' uses the key shape of the element as the thumbnail shape
|
|
63
|
-
* -
|
|
65
|
+
* - 'icon' uses the icon shape of the element as the thumbnail shape
|
|
66
|
+
* - more shape name see https://g6.antv.antgroup.com/manual/element/node/base-node#style
|
|
67
|
+
* - You can also pass in a function that receives the [id, type of the element, element] and returns a custom shape
|
|
64
68
|
*/
|
|
65
|
-
shape?: 'key' | ((id: string, elementType: ElementType) => DisplayObject);
|
|
69
|
+
shape?: string | 'key' | 'icon' | ((id: string, elementType: ElementType, element: DisplayObject) => DisplayObject);
|
|
66
70
|
/**
|
|
67
71
|
* <zh/> 缩略图画布类名,传入外置容器时不生效
|
|
68
72
|
*
|
|
@@ -169,8 +173,6 @@ export class Minimap extends BasePlugin<MinimapOptions> {
|
|
|
169
173
|
|
|
170
174
|
private onRender!: () => void;
|
|
171
175
|
|
|
172
|
-
private shapes = new Map<ID, DisplayObject>();
|
|
173
|
-
|
|
174
176
|
/**
|
|
175
177
|
* <zh/> 创建或更新缩略图
|
|
176
178
|
*
|
|
@@ -214,65 +216,46 @@ export class Minimap extends BasePlugin<MinimapOptions> {
|
|
|
214
216
|
const { shape } = this.options;
|
|
215
217
|
const { element } = this.context;
|
|
216
218
|
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
cloneShape.id = target.id;
|
|
234
|
-
|
|
235
|
-
if (!this.shapes.has(id)) {
|
|
236
|
-
canvas.appendChild(cloneShape);
|
|
237
|
-
this.shapes.set(id, cloneShape);
|
|
219
|
+
const iterate = (datum: ElementDatum, elType: ElementType) => {
|
|
220
|
+
const id = idOf(datum);
|
|
221
|
+
const target = element?.getElement(id);
|
|
222
|
+
if (!target) return;
|
|
223
|
+
|
|
224
|
+
const keyShape = target.getShape('key');
|
|
225
|
+
let cloneShape: DisplayObject;
|
|
226
|
+
|
|
227
|
+
if (typeof shape === 'string') {
|
|
228
|
+
const shapeName = shape;
|
|
229
|
+
const miniShape = target.getShape(shapeName);
|
|
230
|
+
cloneShape = miniShape.cloneNode();
|
|
231
|
+
} else {
|
|
232
|
+
const miniShape = shape(id, elType, target);
|
|
233
|
+
if (miniShape === target) {
|
|
234
|
+
cloneShape = miniShape.cloneNode(true);
|
|
238
235
|
} else {
|
|
239
|
-
|
|
240
|
-
if (cloneShape.style[key] !== value) cloneShape.style[key] = value;
|
|
241
|
-
});
|
|
236
|
+
cloneShape = miniShape;
|
|
242
237
|
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const setPosition = (id: ID, shape: DisplayObject) => {
|
|
261
|
-
const target = element!.getElement(id)!;
|
|
262
|
-
const position = target.getPosition();
|
|
263
|
-
shape.setPosition(position);
|
|
264
|
-
return shape;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 这里使用的是 keyShape 的位置
|
|
242
|
+
* 对于整个元素的位置而言,使用 keyShape 位置会比较准确
|
|
243
|
+
* 也比较合理
|
|
244
|
+
*/
|
|
245
|
+
cloneShape.setPosition(keyShape.getPosition());
|
|
246
|
+
// keep zIndex / id
|
|
247
|
+
if (target.style.zIndex) cloneShape.style.zIndex = target.style.zIndex;
|
|
248
|
+
cloneShape.id = target.id;
|
|
249
|
+
|
|
250
|
+
canvas.appendChild(cloneShape);
|
|
265
251
|
};
|
|
266
252
|
|
|
267
253
|
canvas.removeChildren();
|
|
268
254
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
nodes.forEach((datum) => {
|
|
274
|
-
canvas.appendChild(setPosition(idOf(datum), shape(idOf(datum), 'node')));
|
|
275
|
-
});
|
|
255
|
+
// 注意执行顺序 / Note the execution order
|
|
256
|
+
edges.forEach((datum) => iterate(datum, 'edge'));
|
|
257
|
+
combos.forEach((datum) => iterate(datum, 'combo'));
|
|
258
|
+
nodes.forEach((datum) => iterate(datum, 'node'));
|
|
276
259
|
}
|
|
277
260
|
|
|
278
261
|
private container!: HTMLElement;
|
|
@@ -463,12 +446,16 @@ export class Minimap extends BasePlugin<MinimapOptions> {
|
|
|
463
446
|
// 当拖拽画布导致 mask 缩小时,拖拽 mask 时,能够恢复到实际大小
|
|
464
447
|
// When dragging the canvas causes the mask to shrink, dragging the mask will restore it to its actual size
|
|
465
448
|
if (width < fullWidth) {
|
|
466
|
-
if (movementX > 0)
|
|
467
|
-
|
|
449
|
+
if (movementX > 0) {
|
|
450
|
+
x = lower(x - movementX, 0);
|
|
451
|
+
width = upper(width + movementX, minimapWidth);
|
|
452
|
+
} else if (movementX < 0) width = upper(width - movementX, minimapWidth);
|
|
468
453
|
}
|
|
469
454
|
if (height < fullHeight) {
|
|
470
|
-
if (movementY > 0)
|
|
471
|
-
|
|
455
|
+
if (movementY > 0) {
|
|
456
|
+
y = lower(y - movementY, 0);
|
|
457
|
+
height = upper(height + movementY, minimapHeight);
|
|
458
|
+
} else if (movementY < 0) height = upper(height - movementY, minimapHeight);
|
|
472
459
|
}
|
|
473
460
|
|
|
474
461
|
Object.assign(this.mask.style, {
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { Canvas } from '@antv/g';
|
|
2
|
+
import { GraphEvent } from '../../constants';
|
|
3
|
+
import type { LabelStyleProps } from '../../elements/shapes/label';
|
|
4
|
+
import { Label } from '../../elements/shapes/label';
|
|
5
|
+
import type { RuntimeContext } from '../../runtime/types';
|
|
6
|
+
import type { Prefix } from '../../types';
|
|
7
|
+
import { parsePadding } from '../../utils/padding';
|
|
8
|
+
import { subStyleProps } from '../../utils/prefix';
|
|
9
|
+
import type { BasePluginOptions } from '../base-plugin';
|
|
10
|
+
import { BasePlugin } from '../base-plugin';
|
|
11
|
+
import { createPluginCanvas } from '../utils/canvas';
|
|
12
|
+
|
|
13
|
+
const commonStyle: Partial<LabelStyleProps> = {
|
|
14
|
+
fill: '#1D2129',
|
|
15
|
+
wordWrap: true, // 自动换行
|
|
16
|
+
maxLines: 1, // 最大行数
|
|
17
|
+
textOverflow: 'ellipsis', // 溢出隐藏省略号
|
|
18
|
+
textBaseline: 'top',
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* textAlign 需要和 x 结合使用
|
|
22
|
+
* 举例: 前提条件: 画布 width = 600
|
|
23
|
+
* - textAlign: 'start' | 'left
|
|
24
|
+
* 需要设 x = 0
|
|
25
|
+
* - textAlign: 'end' | 'right'
|
|
26
|
+
* 需要设 x = 600 (即画布的宽度)
|
|
27
|
+
* - textAlign: 'center'
|
|
28
|
+
* 需要设 x = 300 (即画布的宽度 / 2)
|
|
29
|
+
*/
|
|
30
|
+
textAlign: 'start',
|
|
31
|
+
x: 0,
|
|
32
|
+
};
|
|
33
|
+
const defaultTitleStyle: Partial<LabelStyleProps> = {
|
|
34
|
+
...commonStyle,
|
|
35
|
+
fillOpacity: 0.9,
|
|
36
|
+
fontSize: 16,
|
|
37
|
+
fontWeight: 'bold',
|
|
38
|
+
};
|
|
39
|
+
const defaultSubTitleStyle: Partial<LabelStyleProps> = {
|
|
40
|
+
...commonStyle,
|
|
41
|
+
fillOpacity: 0.65,
|
|
42
|
+
fontSize: 12,
|
|
43
|
+
fontWeight: 'normal',
|
|
44
|
+
};
|
|
45
|
+
const defaultOptions: Partial<TitleOptions> = {
|
|
46
|
+
align: 'left',
|
|
47
|
+
spacing: 8,
|
|
48
|
+
size: 44,
|
|
49
|
+
padding: [16, 24, 0, 24],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const titleKey = 'title';
|
|
53
|
+
const subtitleKey = 'subtitle';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* <zh/> 标题的样式
|
|
57
|
+
*
|
|
58
|
+
* <en/> Title styles
|
|
59
|
+
*/
|
|
60
|
+
export type TitleStyle = Prefix<typeof titleKey, Omit<LabelStyleProps, 'x' | 'y' | 'text'>>;
|
|
61
|
+
/**
|
|
62
|
+
* <zh/> 副标题的样式
|
|
63
|
+
*
|
|
64
|
+
* <en/> Subtitle styles
|
|
65
|
+
*/
|
|
66
|
+
export type SubTitleStyle = Prefix<typeof subtitleKey, Omit<LabelStyleProps, 'x' | 'y' | 'text'>>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* <zh/> 标题插件配置项
|
|
70
|
+
*
|
|
71
|
+
* <en/> Title plugin options
|
|
72
|
+
*/
|
|
73
|
+
export interface TitleOptions extends BasePluginOptions, TitleStyle, SubTitleStyle {
|
|
74
|
+
/**
|
|
75
|
+
* <zh/> 整个标题的高度
|
|
76
|
+
*
|
|
77
|
+
* <en/> whole title height
|
|
78
|
+
* @defaultValue 44
|
|
79
|
+
*/
|
|
80
|
+
size?: number;
|
|
81
|
+
/**
|
|
82
|
+
* <zh/> 整个标题位于图的位置
|
|
83
|
+
*
|
|
84
|
+
* <en/> The entire title is located at the position of the graph
|
|
85
|
+
* @defaultValue 'left'
|
|
86
|
+
*/
|
|
87
|
+
align?: 'left' | 'center' | 'right';
|
|
88
|
+
/**
|
|
89
|
+
* <zh/> 主标题、副标题之间的上下间距
|
|
90
|
+
*
|
|
91
|
+
* <en/> The y spacing between the title and subtitle
|
|
92
|
+
* @defaultValue 8
|
|
93
|
+
*/
|
|
94
|
+
spacing?: number;
|
|
95
|
+
/**
|
|
96
|
+
* <zh/> 标题内边距
|
|
97
|
+
*
|
|
98
|
+
* <en/> whole title padding
|
|
99
|
+
* @defaultValue [16, 24, 0, 24]
|
|
100
|
+
*/
|
|
101
|
+
padding?: number | number[];
|
|
102
|
+
/**
|
|
103
|
+
* <zh/> 标题内容
|
|
104
|
+
*
|
|
105
|
+
* <en/> title text
|
|
106
|
+
*/
|
|
107
|
+
[titleKey]: string;
|
|
108
|
+
/**
|
|
109
|
+
* <zh/> 副标题内容
|
|
110
|
+
*
|
|
111
|
+
* <en/> subtitle text
|
|
112
|
+
*/
|
|
113
|
+
[subtitleKey]?: string | null;
|
|
114
|
+
/**
|
|
115
|
+
* <zh/> 标题画布类名,传入外置容器时不生效
|
|
116
|
+
*
|
|
117
|
+
* <en/> The class name of the title canvas, which does not take effect when an external container is passed in
|
|
118
|
+
*/
|
|
119
|
+
className?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export class Title extends BasePlugin<TitleOptions> {
|
|
123
|
+
private canvas!: Canvas;
|
|
124
|
+
private container!: HTMLElement;
|
|
125
|
+
|
|
126
|
+
private get padding() {
|
|
127
|
+
return parsePadding(this.options.padding);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
constructor(context: RuntimeContext, options: TitleOptions) {
|
|
131
|
+
const combineOption = Object.assign({}, defaultOptions, options);
|
|
132
|
+
super(context, combineOption);
|
|
133
|
+
|
|
134
|
+
this.bindEvents();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private onRender = () => {
|
|
138
|
+
const canvas = this.updateCanvas();
|
|
139
|
+
this.renderTitle(canvas);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
private bindEvents() {
|
|
143
|
+
const { graph } = this.context;
|
|
144
|
+
graph.on(GraphEvent.AFTER_RENDER, this.onRender);
|
|
145
|
+
graph.on(GraphEvent.AFTER_ANIMATE, this.onRender);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private unbindEvents() {
|
|
149
|
+
const { graph } = this.context;
|
|
150
|
+
graph.off(GraphEvent.AFTER_RENDER, this.onRender);
|
|
151
|
+
graph.off(GraphEvent.AFTER_ANIMATE, this.onRender);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public destroy(): void {
|
|
155
|
+
this.unbindEvents();
|
|
156
|
+
this.canvas?.destroy();
|
|
157
|
+
this.container?.remove();
|
|
158
|
+
super.destroy();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private updateCanvas() {
|
|
162
|
+
const { size, className, align } = this.options;
|
|
163
|
+
const [width] = this.context.canvas.getSize();
|
|
164
|
+
const [pt = 0, , pb = 0] = this.padding;
|
|
165
|
+
const height = size + pt + pb;
|
|
166
|
+
|
|
167
|
+
if (this.canvas) {
|
|
168
|
+
const { width: w, height: h } = this.canvas.getConfig();
|
|
169
|
+
if (width !== w || height !== h) this.canvas.resize(width, height);
|
|
170
|
+
} else {
|
|
171
|
+
const positions = {
|
|
172
|
+
left: 'left-top',
|
|
173
|
+
center: 'top',
|
|
174
|
+
right: 'right-top',
|
|
175
|
+
} as const;
|
|
176
|
+
|
|
177
|
+
const [$container, canvas] = createPluginCanvas({
|
|
178
|
+
width,
|
|
179
|
+
height,
|
|
180
|
+
placement: positions[align] || positions.left,
|
|
181
|
+
className: 'title-canvas',
|
|
182
|
+
graphCanvas: this.context.canvas,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
if (className) $container.classList.add(className);
|
|
186
|
+
|
|
187
|
+
this.container = $container;
|
|
188
|
+
this.canvas = canvas;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return this.canvas;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private renderTitle(canvas: Canvas) {
|
|
195
|
+
const titles = new TitleComponent({
|
|
196
|
+
options: this.options,
|
|
197
|
+
ctx: this.context,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
canvas.removeChildren();
|
|
201
|
+
titles.getTitle().forEach((label) => {
|
|
202
|
+
if (label) canvas.appendChild(label);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
class TitleComponent {
|
|
208
|
+
private options: TitleOptions;
|
|
209
|
+
|
|
210
|
+
private context: RuntimeContext;
|
|
211
|
+
private get padding() {
|
|
212
|
+
return parsePadding(this.options.padding);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
constructor(props: { ctx: RuntimeContext; options: TitleOptions }) {
|
|
216
|
+
const { options, ctx } = props;
|
|
217
|
+
|
|
218
|
+
this.options = options;
|
|
219
|
+
|
|
220
|
+
this.context = ctx;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public getTitle() {
|
|
224
|
+
const {
|
|
225
|
+
[titleKey]: propsTitle,
|
|
226
|
+
[subtitleKey]: propsSubtitle,
|
|
227
|
+
spacing = 44,
|
|
228
|
+
padding,
|
|
229
|
+
align,
|
|
230
|
+
...style
|
|
231
|
+
} = this.options;
|
|
232
|
+
|
|
233
|
+
const titleText = propsTitle;
|
|
234
|
+
const subTitleText = propsSubtitle;
|
|
235
|
+
|
|
236
|
+
const titleStyle = subStyleProps(style, titleKey) as LabelStyleProps;
|
|
237
|
+
const subtitleStyle = subStyleProps(style, subtitleKey) as LabelStyleProps;
|
|
238
|
+
|
|
239
|
+
const [topGraphWidth] = this.context.graph.getSize();
|
|
240
|
+
const [pt = 0, pr = 0, , pl = 0] = this.padding;
|
|
241
|
+
const canvasWidth = topGraphWidth;
|
|
242
|
+
const textWidth = canvasWidth - pl - pr;
|
|
243
|
+
|
|
244
|
+
let subTitle: Label | null = null;
|
|
245
|
+
|
|
246
|
+
let alignX = pl;
|
|
247
|
+
let textAlign = 'left' as 'left' | 'center' | 'right';
|
|
248
|
+
|
|
249
|
+
switch (align) {
|
|
250
|
+
case 'left':
|
|
251
|
+
alignX = pl;
|
|
252
|
+
textAlign = 'left';
|
|
253
|
+
break;
|
|
254
|
+
case 'center':
|
|
255
|
+
alignX = canvasWidth / 2;
|
|
256
|
+
textAlign = 'center';
|
|
257
|
+
break;
|
|
258
|
+
|
|
259
|
+
case 'right':
|
|
260
|
+
alignX = canvasWidth - pr;
|
|
261
|
+
textAlign = 'right';
|
|
262
|
+
break;
|
|
263
|
+
default:
|
|
264
|
+
alignX = pl;
|
|
265
|
+
textAlign = 'left';
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const title = new Label({
|
|
269
|
+
className: titleKey,
|
|
270
|
+
style: {
|
|
271
|
+
...defaultTitleStyle,
|
|
272
|
+
wordWrapWidth: textWidth - 5,
|
|
273
|
+
x: alignX,
|
|
274
|
+
y: pt,
|
|
275
|
+
textAlign,
|
|
276
|
+
...titleStyle,
|
|
277
|
+
text: titleText,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const titleBBox = title.getBBox();
|
|
282
|
+
|
|
283
|
+
if (subTitleText) {
|
|
284
|
+
subTitle = new Label({
|
|
285
|
+
className: 'subTitle',
|
|
286
|
+
style: {
|
|
287
|
+
...defaultSubTitleStyle,
|
|
288
|
+
wordWrapWidth: textWidth - 5,
|
|
289
|
+
x: alignX,
|
|
290
|
+
y: titleBBox.height + spacing + pt,
|
|
291
|
+
textAlign,
|
|
292
|
+
...subtitleStyle,
|
|
293
|
+
text: subTitleText,
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return [title, subTitle];
|
|
299
|
+
}
|
|
300
|
+
}
|
package/src/plugins/tooltip.ts
CHANGED
|
@@ -13,7 +13,8 @@ import { BasePlugin } from './base-plugin';
|
|
|
13
13
|
* <en/> Tooltip plugin options
|
|
14
14
|
*/
|
|
15
15
|
export interface TooltipOptions
|
|
16
|
-
extends
|
|
16
|
+
extends
|
|
17
|
+
BasePluginOptions,
|
|
17
18
|
Pick<TooltipStyleProps, 'position' | 'offset' | 'enterable' | 'style' | 'container' | 'title'> {
|
|
18
19
|
/**
|
|
19
20
|
* <zh/> 触发行为,可选 hover | click
|
|
@@ -254,7 +255,12 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
254
255
|
const { getContent, title } = this.options;
|
|
255
256
|
const items: ElementDatum[] = this.getElementData(id, targetType as ElementType);
|
|
256
257
|
|
|
257
|
-
if (!this.tooltipElement
|
|
258
|
+
if (!this.tooltipElement) return;
|
|
259
|
+
// if shown, when is not enable, hide
|
|
260
|
+
if (!this.isEnable(event, items)) {
|
|
261
|
+
this.hide(event);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
258
264
|
|
|
259
265
|
let tooltipContent: { [key: string]: unknown } = {};
|
|
260
266
|
if (getContent) {
|
package/src/registry/build-in.ts
CHANGED
|
@@ -87,6 +87,7 @@ import {
|
|
|
87
87
|
Minimap,
|
|
88
88
|
Snapline,
|
|
89
89
|
Timebar,
|
|
90
|
+
Title,
|
|
90
91
|
Toolbar,
|
|
91
92
|
Tooltip,
|
|
92
93
|
Watermark,
|
|
@@ -152,20 +153,20 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
|
|
|
152
153
|
layout: {
|
|
153
154
|
'antv-dagre': AntVDagreLayout,
|
|
154
155
|
'combo-combined': ComboCombinedLayout,
|
|
155
|
-
'compact-box': compactBox,
|
|
156
|
+
'compact-box': compactBox as any,
|
|
156
157
|
'd3-force': D3ForceLayout,
|
|
157
158
|
'force-atlas2': ForceAtlas2Layout,
|
|
158
159
|
circular: CircularLayout,
|
|
159
160
|
concentric: ConcentricLayout,
|
|
160
161
|
dagre: DagreLayout,
|
|
161
|
-
dendrogram,
|
|
162
|
+
dendrogram: dendrogram as any,
|
|
162
163
|
fishbone: FishboneLayout,
|
|
163
164
|
force: ForceLayout,
|
|
164
165
|
fruchterman: FruchtermanLayout,
|
|
165
166
|
grid: GridLayout,
|
|
166
|
-
indented,
|
|
167
|
+
indented: indented as any,
|
|
167
168
|
mds: MDSLayout,
|
|
168
|
-
mindmap,
|
|
169
|
+
mindmap: mindmap as any,
|
|
169
170
|
radial: RadialLayout,
|
|
170
171
|
random: RandomLayout,
|
|
171
172
|
snake: SnakeLayout,
|
|
@@ -208,6 +209,7 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
|
|
|
208
209
|
minimap: Minimap,
|
|
209
210
|
snapline: Snapline,
|
|
210
211
|
timebar: Timebar,
|
|
212
|
+
title: Title,
|
|
211
213
|
toolbar: Toolbar,
|
|
212
214
|
tooltip: Tooltip,
|
|
213
215
|
watermark: Watermark,
|
package/src/runtime/canvas.ts
CHANGED
|
@@ -8,8 +8,10 @@ import type { CanvasLayer, Point } from '../types';
|
|
|
8
8
|
import { getBBoxSize, getCombinedBBox } from '../utils/bbox';
|
|
9
9
|
import { parsePoint, toPointObject } from '../utils/point';
|
|
10
10
|
|
|
11
|
-
export interface CanvasConfig
|
|
12
|
-
|
|
11
|
+
export interface CanvasConfig extends Pick<
|
|
12
|
+
GCanvasConfig,
|
|
13
|
+
'container' | 'devicePixelRatio' | 'width' | 'height' | 'cursor' | 'background'
|
|
14
|
+
> {
|
|
13
15
|
/**
|
|
14
16
|
* <zh/> 渲染器
|
|
15
17
|
*
|