@antv/g6 5.0.12 → 5.0.13
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/dist/lib/elements/shapes/icon.d.ts +1 -1
- package/dist/lib/exports.d.ts +1 -1
- package/dist/lib/runtime/layout.d.ts +1 -0
- package/dist/lib/utils/tree.d.ts +1 -1
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/drag-canvas.js +8 -7
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/elements/shapes/base-shape.js +2 -1
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/elements/shapes/icon.d.ts +1 -1
- package/esm/elements/shapes/icon.js +5 -4
- package/esm/elements/shapes/icon.js.map +1 -1
- package/esm/exports.d.ts +1 -1
- package/esm/plugins/tooltip.js +4 -1
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/runtime/graph.js +1 -0
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +1 -0
- package/esm/runtime/layout.js +48 -0
- package/esm/runtime/layout.js.map +1 -1
- package/esm/utils/tree.d.ts +1 -1
- package/esm/utils/tree.js +2 -2
- package/esm/utils/tree.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/drag-canvas.js +8 -7
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/elements/shapes/base-shape.js +2 -1
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/elements/shapes/icon.d.ts +1 -1
- package/lib/elements/shapes/icon.js +5 -4
- package/lib/elements/shapes/icon.js.map +1 -1
- package/lib/exports.d.ts +1 -1
- package/lib/plugins/tooltip.js +4 -1
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/runtime/graph.js +1 -0
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +1 -0
- package/lib/runtime/layout.js +48 -0
- package/lib/runtime/layout.js.map +1 -1
- package/lib/utils/tree.d.ts +1 -1
- package/lib/utils/tree.js +2 -2
- package/lib/utils/tree.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/behaviors/drag-canvas.ts +8 -7
- package/src/elements/shapes/base-shape.ts +3 -1
- package/src/elements/shapes/icon.ts +5 -4
- package/src/exports.ts +1 -0
- package/src/plugins/tooltip.ts +4 -1
- package/src/runtime/graph.ts +1 -0
- package/src/runtime/layout.ts +55 -0
- package/src/utils/tree.ts +3 -3
- package/src/version.ts +1 -1
|
@@ -25,14 +25,15 @@ export class Icon extends BaseShape<IconStyleProps> {
|
|
|
25
25
|
super(options);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
private
|
|
29
|
-
|
|
28
|
+
private isImage() {
|
|
29
|
+
const { src } = this.attributes;
|
|
30
|
+
return !!src;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
protected getIconStyle(attributes: IconStyleProps = this.attributes): IconStyleProps {
|
|
33
34
|
const { width = 0, height = 0 } = attributes;
|
|
34
35
|
const style = this.getGraphicStyle(attributes);
|
|
35
|
-
if (this.
|
|
36
|
+
if (this.isImage()) {
|
|
36
37
|
return {
|
|
37
38
|
x: -width / 2,
|
|
38
39
|
y: -height / 2,
|
|
@@ -47,6 +48,6 @@ export class Icon extends BaseShape<IconStyleProps> {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
public render(attributes = this.attributes, container: Group = this): void {
|
|
50
|
-
this.upsert('icon', (this.
|
|
51
|
+
this.upsert('icon', (this.isImage() ? GImage : GText) as any, this.getIconStyle(attributes), container);
|
|
51
52
|
}
|
|
52
53
|
}
|
package/src/exports.ts
CHANGED
package/src/plugins/tooltip.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Tooltip as TooltipComponent } from '@antv/component';
|
|
|
3
3
|
import { get } from '@antv/util';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
5
|
import type { ElementDatum, ElementType, ID, IElementEvent } from '../types';
|
|
6
|
+
import { isToBeDestroyed } from '../utils/element';
|
|
6
7
|
import type { BasePluginOptions } from './base-plugin';
|
|
7
8
|
import { BasePlugin } from './base-plugin';
|
|
8
9
|
|
|
@@ -235,8 +236,10 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
235
236
|
client,
|
|
236
237
|
target: { id },
|
|
237
238
|
} = event;
|
|
238
|
-
|
|
239
|
+
if (isToBeDestroyed(event.target)) return;
|
|
239
240
|
if (!this.tooltipElement || !this.isEnable(event)) return;
|
|
241
|
+
|
|
242
|
+
const targetType = this.context.graph.getElementType(id);
|
|
240
243
|
const { getContent, title } = this.options;
|
|
241
244
|
this.currentTarget = id;
|
|
242
245
|
const items: ElementDatum[] = this.getElementData(id, targetType as ElementType);
|
package/src/runtime/graph.ts
CHANGED
|
@@ -1733,6 +1733,7 @@ export class Graph extends EventEmitter {
|
|
|
1733
1733
|
|
|
1734
1734
|
const elementType = model.getElementType(id);
|
|
1735
1735
|
|
|
1736
|
+
await this.frontElement(id);
|
|
1736
1737
|
this.isCollapsingExpanding = true;
|
|
1737
1738
|
this.setElementCollapsibility(id, true);
|
|
1738
1739
|
if (elementType === 'node') await element!.collapseNode(id, animation);
|
package/src/runtime/layout.ts
CHANGED
|
@@ -156,6 +156,7 @@ export class LayoutController {
|
|
|
156
156
|
|
|
157
157
|
createTreeStructure(model);
|
|
158
158
|
|
|
159
|
+
const layoutPreset: GraphData = { nodes: [], edges: [] };
|
|
159
160
|
const layoutResult: GraphData = { nodes: [], edges: [] };
|
|
160
161
|
|
|
161
162
|
const roots = model.getRoots(TREE_KEY) as unknown as TreeData[];
|
|
@@ -170,11 +171,13 @@ export class LayoutController {
|
|
|
170
171
|
);
|
|
171
172
|
|
|
172
173
|
const result = layout(root, options);
|
|
174
|
+
const { x: rx, y: ry, z: rz = 0 } = result;
|
|
173
175
|
// 将布局结果转化为 LayoutMapping 格式 / Convert the layout result to LayoutMapping format
|
|
174
176
|
dfs(
|
|
175
177
|
result,
|
|
176
178
|
(node) => {
|
|
177
179
|
const { id, x, y, z = 0 } = node;
|
|
180
|
+
layoutPreset.nodes!.push({ id, style: { x: rx, y: ry, z: rz } });
|
|
178
181
|
layoutResult.nodes!.push({ id, style: { x, y, z } });
|
|
179
182
|
},
|
|
180
183
|
(node) => node.children,
|
|
@@ -182,13 +185,45 @@ export class LayoutController {
|
|
|
182
185
|
);
|
|
183
186
|
});
|
|
184
187
|
|
|
188
|
+
const offset = this.inferTreeLayoutOffset(layoutResult);
|
|
189
|
+
applyTreeLayoutOffset(layoutResult, offset);
|
|
190
|
+
|
|
185
191
|
if (animation) {
|
|
192
|
+
// 先将所有节点移动到根节点位置 / Move all nodes to the root node position first
|
|
193
|
+
applyTreeLayoutOffset(layoutPreset, offset);
|
|
194
|
+
this.updateElementPosition(layoutPreset, false);
|
|
195
|
+
|
|
186
196
|
this.updateElementPosition(layoutResult, animation);
|
|
187
197
|
}
|
|
188
198
|
|
|
189
199
|
return layoutResult;
|
|
190
200
|
}
|
|
191
201
|
|
|
202
|
+
private inferTreeLayoutOffset(data: GraphData) {
|
|
203
|
+
let [minX, maxX] = [Infinity, -Infinity];
|
|
204
|
+
let [minY, maxY] = [Infinity, -Infinity];
|
|
205
|
+
|
|
206
|
+
data.nodes?.forEach((node) => {
|
|
207
|
+
const { x = 0, y = 0 } = node.style || {};
|
|
208
|
+
minX = Math.min(minX, x);
|
|
209
|
+
maxX = Math.max(maxX, x);
|
|
210
|
+
minY = Math.min(minY, y);
|
|
211
|
+
maxY = Math.max(maxY, y);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const { canvas } = this.context;
|
|
215
|
+
const canvasSize = canvas.getSize();
|
|
216
|
+
const [x1, y1] = canvas.getCanvasByViewport([0, 0]);
|
|
217
|
+
const [x2, y2] = canvas.getCanvasByViewport(canvasSize);
|
|
218
|
+
|
|
219
|
+
if (minX >= x1 && maxX <= x2 && minY >= y1 && maxY <= y2) return [0, 0] as [number, number];
|
|
220
|
+
|
|
221
|
+
const cx = (x1 + x2) / 2;
|
|
222
|
+
const cy = (y1 + y2) / 2;
|
|
223
|
+
|
|
224
|
+
return [cx - (minX + maxX) / 2, cy - (minY + maxY) / 2] as [number, number];
|
|
225
|
+
}
|
|
226
|
+
|
|
192
227
|
public stopLayout() {
|
|
193
228
|
if (this.instance && isLayoutWithIterations(this.instance)) {
|
|
194
229
|
this.instance.stop();
|
|
@@ -303,3 +338,23 @@ export class LayoutController {
|
|
|
303
338
|
this.animationResult = undefined;
|
|
304
339
|
}
|
|
305
340
|
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* <zh/> 对树形布局结果应用偏移
|
|
344
|
+
*
|
|
345
|
+
* <en/> Apply offset to tree layout result
|
|
346
|
+
* @param data - <zh/> 布局数据 | <en/> Layout data
|
|
347
|
+
* @param offset - <zh/> 偏移量 | <en/> Offset
|
|
348
|
+
*/
|
|
349
|
+
const applyTreeLayoutOffset = (data: GraphData, offset: [number, number]) => {
|
|
350
|
+
const [ox, oy] = offset;
|
|
351
|
+
data.nodes?.forEach((node) => {
|
|
352
|
+
if (node.style) {
|
|
353
|
+
const { x = 0, y = 0 } = node.style;
|
|
354
|
+
node.style.x = x + ox;
|
|
355
|
+
node.style.y = y + oy;
|
|
356
|
+
} else {
|
|
357
|
+
node.style = { x: ox, y: oy };
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
};
|
package/src/utils/tree.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { TreeData } from '../types';
|
|
|
3
3
|
import { dfs } from './traverse';
|
|
4
4
|
|
|
5
5
|
type TreeDataGetter = {
|
|
6
|
-
getNodeData?: (datum: TreeData) => NodeData;
|
|
6
|
+
getNodeData?: (datum: TreeData, depth: number) => NodeData;
|
|
7
7
|
getEdgeData?: (source: TreeData, target: TreeData) => EdgeData;
|
|
8
8
|
getChildren?: (datum: TreeData) => TreeData[];
|
|
9
9
|
};
|
|
@@ -32,8 +32,8 @@ export function treeToGraphData(treeData: TreeData, getter?: TreeDataGetter): Gr
|
|
|
32
32
|
|
|
33
33
|
dfs(
|
|
34
34
|
treeData,
|
|
35
|
-
(node) => {
|
|
36
|
-
nodes.push(getNodeData(node));
|
|
35
|
+
(node, depth) => {
|
|
36
|
+
nodes.push(getNodeData(node, depth));
|
|
37
37
|
const children = getChildren(node);
|
|
38
38
|
for (const child of children) {
|
|
39
39
|
edges.push(getEdgeData(node, child));
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.13';
|