@antv/g6 5.0.31 → 5.0.33
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 +33 -34
- package/README.zh-CN.md +117 -0
- package/dist/g6.min.js +29 -29
- package/dist/lib/behaviors/collapse-expand.d.ts +6 -0
- package/dist/lib/behaviors/drag-element.d.ts +1 -1
- package/dist/lib/elements/nodes/html.d.ts +4 -0
- package/dist/lib/exports.d.ts +1 -0
- package/dist/lib/plugins/snapline/index.d.ts +1 -1
- package/dist/lib/runtime/data.d.ts +1 -1
- package/dist/lib/runtime/element.d.ts +29 -2
- package/dist/lib/runtime/graph.d.ts +11 -9
- package/dist/lib/runtime/viewport.d.ts +22 -2
- package/dist/lib/spec/data.d.ts +2 -2
- package/dist/lib/utils/event/events.d.ts +4 -4
- package/dist/lib/utils/id.d.ts +1 -1
- package/dist/lib/utils/visibility.d.ts +1 -2
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/collapse-expand.d.ts +6 -0
- package/esm/behaviors/collapse-expand.js +4 -3
- package/esm/behaviors/collapse-expand.js.map +1 -1
- package/esm/behaviors/drag-element.d.ts +1 -1
- package/esm/behaviors/optimize-viewport-transform.js +1 -1
- package/esm/behaviors/optimize-viewport-transform.js.map +1 -1
- package/esm/elements/nodes/html.d.ts +4 -0
- package/esm/elements/nodes/html.js +7 -0
- package/esm/elements/nodes/html.js.map +1 -1
- package/esm/elements/shapes/base-shape.js +1 -1
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/exports.d.ts +1 -0
- package/esm/plugins/background/index.js +0 -1
- package/esm/plugins/background/index.js.map +1 -1
- package/esm/plugins/grid-line.js +1 -3
- package/esm/plugins/grid-line.js.map +1 -1
- package/esm/plugins/hull/util.js +6 -1
- package/esm/plugins/hull/util.js.map +1 -1
- package/esm/plugins/snapline/index.d.ts +1 -1
- package/esm/plugins/utils/dom.js +2 -0
- package/esm/plugins/utils/dom.js.map +1 -1
- package/esm/preset.js +0 -2
- package/esm/preset.js.map +1 -1
- package/esm/runtime/data.d.ts +1 -1
- package/esm/runtime/data.js +8 -3
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +29 -2
- package/esm/runtime/element.js +34 -4
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +11 -9
- package/esm/runtime/graph.js +20 -15
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/viewport.d.ts +22 -2
- package/esm/runtime/viewport.js +12 -11
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/spec/data.d.ts +2 -2
- package/esm/transforms/place-radial-labels.js +6 -1
- package/esm/transforms/place-radial-labels.js.map +1 -1
- package/esm/utils/event/events.d.ts +4 -4
- package/esm/utils/id.d.ts +1 -1
- package/esm/utils/visibility.d.ts +1 -2
- package/esm/utils/visibility.js +8 -34
- package/esm/utils/visibility.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/collapse-expand.d.ts +6 -0
- package/lib/behaviors/collapse-expand.js +4 -3
- package/lib/behaviors/collapse-expand.js.map +1 -1
- package/lib/behaviors/drag-element.d.ts +1 -1
- package/lib/behaviors/optimize-viewport-transform.js +1 -1
- package/lib/behaviors/optimize-viewport-transform.js.map +1 -1
- package/lib/elements/edges/base-edge.js +17 -7
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/html.d.ts +4 -0
- package/lib/elements/nodes/html.js +7 -0
- package/lib/elements/nodes/html.js.map +1 -1
- package/lib/elements/shapes/base-shape.js +1 -1
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/exports.d.ts +1 -0
- package/lib/plugins/background/index.js +0 -1
- package/lib/plugins/background/index.js.map +1 -1
- package/lib/plugins/grid-line.js +1 -3
- package/lib/plugins/grid-line.js.map +1 -1
- package/lib/plugins/hull/util.js +5 -0
- package/lib/plugins/hull/util.js.map +1 -1
- package/lib/plugins/snapline/index.d.ts +1 -1
- package/lib/plugins/utils/dom.js +2 -0
- package/lib/plugins/utils/dom.js.map +1 -1
- package/lib/preset.js +0 -2
- package/lib/preset.js.map +1 -1
- package/lib/runtime/data.d.ts +1 -1
- package/lib/runtime/data.js +7 -2
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +29 -2
- package/lib/runtime/element.js +34 -4
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +11 -9
- package/lib/runtime/graph.js +20 -15
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/viewport.d.ts +22 -2
- package/lib/runtime/viewport.js +12 -11
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/spec/data.d.ts +2 -2
- package/lib/transforms/place-radial-labels.js +6 -1
- package/lib/transforms/place-radial-labels.js.map +1 -1
- package/lib/utils/event/events.d.ts +4 -4
- package/lib/utils/id.d.ts +1 -1
- package/lib/utils/visibility.d.ts +1 -2
- package/lib/utils/visibility.js +8 -34
- package/lib/utils/visibility.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -8
- package/src/behaviors/collapse-expand.ts +10 -3
- package/src/behaviors/optimize-viewport-transform.ts +1 -1
- package/src/elements/nodes/html.ts +9 -0
- package/src/elements/shapes/base-shape.ts +1 -1
- package/src/exports.ts +1 -0
- package/src/plugins/background/index.ts +0 -1
- package/src/plugins/grid-line.ts +1 -3
- package/src/plugins/hull/util.ts +7 -1
- package/src/plugins/utils/dom.ts +2 -0
- package/src/preset.ts +0 -3
- package/src/runtime/data.ts +11 -4
- package/src/runtime/element.ts +51 -4
- package/src/runtime/graph.ts +21 -17
- package/src/runtime/viewport.ts +36 -10
- package/src/spec/data.ts +2 -2
- package/src/transforms/place-radial-labels.ts +5 -1
- package/src/utils/visibility.ts +6 -35
- package/src/version.ts +1 -1
- package/README.en-US.md +0 -118
package/src/runtime/graph.ts
CHANGED
|
@@ -53,6 +53,7 @@ import { BehaviorController } from './behavior';
|
|
|
53
53
|
import type { DataURLOptions } from './canvas';
|
|
54
54
|
import { Canvas } from './canvas';
|
|
55
55
|
import { DataController } from './data';
|
|
56
|
+
import type { CollapseExpandNodeOptions } from './element';
|
|
56
57
|
import { ElementController } from './element';
|
|
57
58
|
import { LayoutController } from './layout';
|
|
58
59
|
import { PluginController } from './plugin';
|
|
@@ -424,7 +425,7 @@ export class Graph extends EventEmitter {
|
|
|
424
425
|
* <zh/> 获取插件实例
|
|
425
426
|
*
|
|
426
427
|
* <en/> Get plugin instance
|
|
427
|
-
* @param key - <zh/> 插件 key | <en/> plugin key
|
|
428
|
+
* @param key - <zh/> 插件 key(在配置 plugin 时需要手动传入指定) | <en/> plugin key(need to be specified manually when configuring plugin)
|
|
428
429
|
* @returns <zh/> 插件实例 | <en/> plugin instance
|
|
429
430
|
* @remarks
|
|
430
431
|
* <zh/> 一些插件提供了 API 方法可供调用,例如全屏插件可以调用 `request` 和 `exit` 方法来请求和退出全屏
|
|
@@ -1286,7 +1287,7 @@ export class Graph extends EventEmitter {
|
|
|
1286
1287
|
* @apiCategory viewport
|
|
1287
1288
|
*/
|
|
1288
1289
|
public async fitCenter(animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
1289
|
-
await this.context.viewport?.fitCenter(animation);
|
|
1290
|
+
await this.context.viewport?.fitCenter({ animation });
|
|
1290
1291
|
}
|
|
1291
1292
|
|
|
1292
1293
|
private async autoFit(): Promise<void> {
|
|
@@ -1316,7 +1317,7 @@ export class Graph extends EventEmitter {
|
|
|
1316
1317
|
* @apiCategory viewport
|
|
1317
1318
|
*/
|
|
1318
1319
|
public async focusElement(id: ID | ID[], animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
1319
|
-
await this.context.viewport?.focusElements(Array.isArray(id) ? id : [id], animation);
|
|
1320
|
+
await this.context.viewport?.focusElements(Array.isArray(id) ? id : [id], { animation });
|
|
1320
1321
|
}
|
|
1321
1322
|
|
|
1322
1323
|
/**
|
|
@@ -1782,50 +1783,53 @@ export class Graph extends EventEmitter {
|
|
|
1782
1783
|
private isCollapsingExpanding = false;
|
|
1783
1784
|
|
|
1784
1785
|
/**
|
|
1785
|
-
* <zh/>
|
|
1786
|
+
* <zh/> 收起元素
|
|
1786
1787
|
*
|
|
1787
|
-
* <en/> Collapse
|
|
1788
|
+
* <en/> Collapse element
|
|
1788
1789
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1789
|
-
* @param
|
|
1790
|
+
* @param options - <zh/> 是否启用动画或者配置收起节点的配置项 | <en/> whether to enable animation or the options of collapsing node
|
|
1790
1791
|
* @apiCategory element
|
|
1791
1792
|
*/
|
|
1792
|
-
public async collapseElement(id: ID,
|
|
1793
|
+
public async collapseElement(id: ID, options: boolean | CollapseExpandNodeOptions = true): Promise<void> {
|
|
1793
1794
|
const { model, element } = this.context;
|
|
1794
1795
|
if (isCollapsed(model.getNodeLikeData([id])[0])) return;
|
|
1795
|
-
|
|
1796
1796
|
if (this.isCollapsingExpanding) return;
|
|
1797
1797
|
|
|
1798
|
+
if (typeof options === 'boolean') options = { animation: options, align: true };
|
|
1799
|
+
|
|
1798
1800
|
const elementType = model.getElementType(id);
|
|
1799
1801
|
|
|
1800
1802
|
await this.frontElement(id);
|
|
1801
1803
|
this.isCollapsingExpanding = true;
|
|
1802
1804
|
this.setElementCollapsibility(id, true);
|
|
1803
|
-
if (elementType === 'node') await element!.collapseNode(id,
|
|
1804
|
-
else if (elementType === 'combo') await element!.collapseCombo(id, animation);
|
|
1805
|
+
if (elementType === 'node') await element!.collapseNode(id, options);
|
|
1806
|
+
else if (elementType === 'combo') await element!.collapseCombo(id, !!options.animation);
|
|
1805
1807
|
|
|
1806
1808
|
this.isCollapsingExpanding = false;
|
|
1807
1809
|
}
|
|
1808
1810
|
|
|
1809
1811
|
/**
|
|
1810
|
-
* <zh/>
|
|
1812
|
+
* <zh/> 展开元素
|
|
1811
1813
|
*
|
|
1812
|
-
* <en/> Expand
|
|
1814
|
+
* <en/> Expand Element
|
|
1813
1815
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1814
|
-
* @param animation - <zh/>
|
|
1816
|
+
* @param animation - <zh/> 是否启用动画或者配置收起节点的配置项 | <en/> whether to enable animation or the options of collapsing node
|
|
1817
|
+
* @param options
|
|
1815
1818
|
* @apiCategory element
|
|
1816
1819
|
*/
|
|
1817
|
-
public async expandElement(id: ID,
|
|
1820
|
+
public async expandElement(id: ID, options: boolean | CollapseExpandNodeOptions = true): Promise<void> {
|
|
1818
1821
|
const { model, element } = this.context;
|
|
1819
1822
|
if (!isCollapsed(model.getNodeLikeData([id])[0])) return;
|
|
1820
|
-
|
|
1821
1823
|
if (this.isCollapsingExpanding) return;
|
|
1822
1824
|
|
|
1825
|
+
if (typeof options === 'boolean') options = { animation: options, align: true };
|
|
1826
|
+
|
|
1823
1827
|
const elementType = model.getElementType(id);
|
|
1824
1828
|
|
|
1825
1829
|
this.isCollapsingExpanding = true;
|
|
1826
1830
|
this.setElementCollapsibility(id, false);
|
|
1827
|
-
if (elementType === 'node') await element!.expandNode(id,
|
|
1828
|
-
else if (elementType === 'combo') await element!.expandCombo(id, animation);
|
|
1831
|
+
if (elementType === 'node') await element!.expandNode(id, options);
|
|
1832
|
+
else if (elementType === 'combo') await element!.expandCombo(id, !!options.animation);
|
|
1829
1833
|
|
|
1830
1834
|
this.isCollapsingExpanding = false;
|
|
1831
1835
|
}
|
package/src/runtime/viewport.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AABB, ICamera } from '@antv/g';
|
|
|
2
2
|
import { clamp, isNumber, pick } from '@antv/util';
|
|
3
3
|
import { AnimationType, GraphEvent } from '../constants';
|
|
4
4
|
import type { FitViewOptions, ID, Point, TransformOptions, Vector2, ViewportAnimationEffectTiming } from '../types';
|
|
5
|
+
import type { Element } from '../types/element';
|
|
5
6
|
import { getAnimationOptions } from '../utils/animation';
|
|
6
7
|
import { getBBoxSize, getCombinedBBox, getExpandedBBox, isBBoxInside, isPointInBBox } from '../utils/bbox';
|
|
7
8
|
import { AnimateEvent, ViewportEvent, emit } from '../utils/event';
|
|
@@ -217,7 +218,7 @@ export class ViewportController {
|
|
|
217
218
|
(direction === 'y' && contentHeight >= innerHeight) ||
|
|
218
219
|
(direction === 'both' && contentWidth >= innerWidth && contentHeight >= innerHeight);
|
|
219
220
|
|
|
220
|
-
if (when === 'overflow' && !isOverflow) return await this.fitCenter(animation);
|
|
221
|
+
if (when === 'overflow' && !isOverflow) return await this.fitCenter({ animation });
|
|
221
222
|
|
|
222
223
|
const scaleX = innerWidth / contentWidth;
|
|
223
224
|
const scaleY = innerHeight / contentHeight;
|
|
@@ -237,23 +238,27 @@ export class ViewportController {
|
|
|
237
238
|
);
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
public async fitCenter(
|
|
241
|
+
public async fitCenter(options: FocusOptions): Promise<void> {
|
|
241
242
|
const canvasBounds = this.context.canvas.getBounds();
|
|
242
|
-
await this.focus(canvasBounds,
|
|
243
|
+
await this.focus(canvasBounds, options);
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
public async focusElements(ids: ID[],
|
|
246
|
+
public async focusElements(ids: ID[], options: FocusOptions = {}): Promise<void> {
|
|
246
247
|
const { element } = this.context;
|
|
247
248
|
if (!element) return;
|
|
248
|
-
|
|
249
|
-
|
|
249
|
+
|
|
250
|
+
const getBoundsOf = (el: Element) =>
|
|
251
|
+
options.shapes ? el.getShape(options.shapes).getRenderBounds() : el.getRenderBounds();
|
|
252
|
+
|
|
253
|
+
const elementsBounds = getCombinedBBox(ids.map((id) => getBoundsOf(element.getElement(id)!)));
|
|
254
|
+
await this.focus(elementsBounds, options);
|
|
250
255
|
}
|
|
251
256
|
|
|
252
|
-
private async focus(bbox: AABB,
|
|
257
|
+
private async focus(bbox: AABB, options: FocusOptions) {
|
|
253
258
|
const center = this.context.graph.getViewportByCanvas(bbox.center);
|
|
254
|
-
const
|
|
255
|
-
const delta = subtract(
|
|
256
|
-
await this.transform({ mode: 'relative', translate: add(delta, this.paddingOffset) }, animation);
|
|
259
|
+
const position = options.position || this.getCanvasCenter();
|
|
260
|
+
const delta = subtract(position, center);
|
|
261
|
+
await this.transform({ mode: 'relative', translate: add(delta, this.paddingOffset) }, options.animation);
|
|
257
262
|
}
|
|
258
263
|
|
|
259
264
|
/**
|
|
@@ -312,3 +317,24 @@ export class ViewportController {
|
|
|
312
317
|
this.transformResolver?.();
|
|
313
318
|
}
|
|
314
319
|
}
|
|
320
|
+
|
|
321
|
+
export interface FocusOptions {
|
|
322
|
+
/**
|
|
323
|
+
* <zh/> 动画配置
|
|
324
|
+
*
|
|
325
|
+
* <en/> Animation configuration
|
|
326
|
+
*/
|
|
327
|
+
animation?: ViewportAnimationEffectTiming;
|
|
328
|
+
/**
|
|
329
|
+
* <zh/> 使用子图形计算包围盒
|
|
330
|
+
*
|
|
331
|
+
* <en/> Calculate the bounding box by using sub-shapes
|
|
332
|
+
*/
|
|
333
|
+
shapes?: string;
|
|
334
|
+
/**
|
|
335
|
+
* <zh/> 对齐位置,默认为画布中心
|
|
336
|
+
*
|
|
337
|
+
* <en/> Alignment position, default is the center of the canvas
|
|
338
|
+
*/
|
|
339
|
+
position?: Point;
|
|
340
|
+
}
|
package/src/spec/data.ts
CHANGED
|
@@ -92,7 +92,7 @@ export interface NodeData {
|
|
|
92
92
|
*
|
|
93
93
|
* <en/> ID of the combo to which the node belongs
|
|
94
94
|
*/
|
|
95
|
-
combo?: ID;
|
|
95
|
+
combo?: ID | null;
|
|
96
96
|
/**
|
|
97
97
|
* <zh/> 子节点 ID
|
|
98
98
|
*
|
|
@@ -161,7 +161,7 @@ export interface ComboData {
|
|
|
161
161
|
*
|
|
162
162
|
* <en/> ID of the combo to which the combo belongs
|
|
163
163
|
*/
|
|
164
|
-
combo?: ID;
|
|
164
|
+
combo?: ID | null;
|
|
165
165
|
[key: string]: unknown;
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -54,7 +54,11 @@ export class PlaceRadialLabels extends BaseTransform<PlaceRadialLabelsOptions> {
|
|
|
54
54
|
const isLeft = Math.abs(radian) > Math.PI / 2;
|
|
55
55
|
|
|
56
56
|
const isLeaf = !datum.children || datum.children.length === 0;
|
|
57
|
-
const
|
|
57
|
+
const nodeId = idOf(datum);
|
|
58
|
+
const node = this.context.element?.getElement(nodeId);
|
|
59
|
+
if (!node || !node.isVisible()) return;
|
|
60
|
+
|
|
61
|
+
const nodeHalfWidth = parseSize(graph.getElementRenderStyle(nodeId).size)[0] / 2;
|
|
58
62
|
const offset = (isLeaf ? 1 : -1) * (nodeHalfWidth + this.options.offset);
|
|
59
63
|
|
|
60
64
|
const labelTransform: TransformArray = [
|
package/src/utils/visibility.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import type { BaseStyleProps, DisplayObject } from '@antv/g';
|
|
2
2
|
|
|
3
|
-
const ORIGINAL_MAP = new WeakMap<DisplayObject, BaseStyleProps['visibility']>();
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* <zh/> 设置图形实例的可见性
|
|
7
5
|
*
|
|
8
6
|
* <en/> Set the visibility of the shape instance
|
|
9
7
|
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
10
8
|
* @param value - <zh/> 可见性 | <en/> visibility
|
|
11
|
-
* @param inherited - <zh/> 是否是来自继承样式 | <en/> Whether it is from inherited styles
|
|
12
9
|
* @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
|
|
13
10
|
* @remarks
|
|
14
11
|
* <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
|
|
@@ -18,40 +15,14 @@ const ORIGINAL_MAP = new WeakMap<DisplayObject, BaseStyleProps['visibility']>();
|
|
|
18
15
|
export function setVisibility(
|
|
19
16
|
shape: DisplayObject,
|
|
20
17
|
value: BaseStyleProps['visibility'],
|
|
21
|
-
inherited = false,
|
|
22
18
|
filter?: (shape: DisplayObject) => boolean,
|
|
23
19
|
) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const walk = (val = scope): void => (current.childNodes as DisplayObject[]).forEach((node) => traverse(node, val));
|
|
28
|
-
|
|
29
|
-
if (filter && !filter(current)) return walk();
|
|
30
|
-
|
|
31
|
-
if (!inherited && current === shape) {
|
|
32
|
-
shape.style.visibility = value;
|
|
33
|
-
ORIGINAL_MAP.delete(shape);
|
|
34
|
-
walk(value);
|
|
35
|
-
} else {
|
|
36
|
-
if (!ORIGINAL_MAP.has(current)) ORIGINAL_MAP.set(current, current.style.visibility);
|
|
37
|
-
|
|
38
|
-
const computedValue = scope === 'hidden' || getOriginalValue(current) === 'hidden' ? 'hidden' : 'visible';
|
|
39
|
-
current.style.visibility = computedValue;
|
|
40
|
-
walk(computedValue);
|
|
41
|
-
}
|
|
20
|
+
const callback = (node: DisplayObject) => {
|
|
21
|
+
if (filter && !filter(node)) return;
|
|
22
|
+
node.style.visibility = value;
|
|
42
23
|
};
|
|
43
24
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* <zh/> 获取图形原本的可见性
|
|
49
|
-
*
|
|
50
|
-
* <en/> Get the original visibility of the shape
|
|
51
|
-
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
52
|
-
* @returns <zh/> 可见性 | <en/> visibility
|
|
53
|
-
*/
|
|
54
|
-
function getOriginalValue(shape: DisplayObject) {
|
|
55
|
-
if (ORIGINAL_MAP.has(shape)) return ORIGINAL_MAP.get(shape);
|
|
56
|
-
return shape.style.visibility;
|
|
25
|
+
shape.forEach((node) => {
|
|
26
|
+
callback(node as DisplayObject);
|
|
27
|
+
});
|
|
57
28
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.33';
|
package/README.en-US.md
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
<img src="https://gw.alipayobjects.com/zos/antfincdn/R8sN%24GNdh6/language.svg" width="18"> English | [简体中文](./README.md)
|
|
2
|
-
|
|
3
|
-
<h1 align="center">
|
|
4
|
-
<b>G6: A Graph Visualization Framework in TypeScript</b>
|
|
5
|
-
</h1>
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
[](https://www.npmjs.com/package/@antv/g6)
|
|
10
|
-
[](https://github.com/antvis/g6/actions)
|
|
11
|
-
[](https://coveralls.io/github/antvis/G6)
|
|
12
|
-
[](https://www.npmjs.com/package/@antv/g6)
|
|
13
|
-

|
|
14
|
-
[](https://www.npmjs.com/package/@antv/g6)
|
|
15
|
-
|
|
16
|
-
<p align="center">
|
|
17
|
-
<a href="https://g6.antv.antgroup.com/">Introduction</a> •
|
|
18
|
-
<a href="https://g6.antv.antgroup.com/examples">Examples</a> •
|
|
19
|
-
<a href="https://g6.antv.antgroup.com/">Tutorial</a> •
|
|
20
|
-
<a href="https://g6.antv.antgroup.com/">API</a>
|
|
21
|
-
</p>
|
|
22
|
-
|
|
23
|
-
[G6](https://github.com/antvis/g6) is a graph visualization engine. It provides basic capabilities for graph visualization and analysis such as drawing, layout, analysis, interaction, animation, themes, and plugins. With G6, users can quickly build their own graph visualization and analysis applications, making relational data simple, transparent, and meaningful.
|
|
24
|
-
|
|
25
|
-
<img src='https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*_PJ5SZELwq0AAAAAAAAAAAAADmJ7AQ/original' width=550 alt='' />
|
|
26
|
-
|
|
27
|
-
<img src='https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*zTjwQaXokeQAAAAAAAAAAABkARQnAQ' width=550 alt='' />
|
|
28
|
-
|
|
29
|
-
<img src='https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*zau8QJcVpDQAAAAAAAAAAABkARQnAQ' height=200 alt='' /><img src='https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*RIlETY_S6IoAAAAAAAAAAABkARQnAQ' height=200 alt='' />
|
|
30
|
-
|
|
31
|
-
<img src='https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*cDzXR4jIWr8AAAAAAAAAAABkARQnAQ' height=150 alt='' /><img src='https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*HTasSJGC4koAAAAAAAAAAABkARQnAQ' height=150 alt='' />
|
|
32
|
-
|
|
33
|
-
<img src="https://user-images.githubusercontent.com/6113694/44995293-02858600-afd5-11e8-840c-349e4730d63d.gif" height=150 alt='' /><img src="https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*I9OdTbXJIi0AAAAAAAAAAABkARQnAQ" height=150 alt='' /><img src="https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*xoufSYcjK2AAAAAAAAAAAABkARQnAQ" height=150 alt='' />
|
|
34
|
-
|
|
35
|
-
## ✨ Features
|
|
36
|
-
|
|
37
|
-
G6, as a professional graph visualization engine, boasts the following features:
|
|
38
|
-
|
|
39
|
-
- **Rich Elements**: It comes with a variety of built-in node, edge, and Combo UI elements with extensive style configurations, supports data callbacks, and has a flexible mechanism for extending custom elements.
|
|
40
|
-
- **Controllable Interactions**: It includes more than 10 built-in interaction behaviors and offers a rich array of events, facilitating the expansion of custom interactive behaviors.
|
|
41
|
-
- **High-Performance Layout**: The engine features more than 10 common graph layouts, some of which leverage GPU and Rust parallel computing for enhanced performance, and it supports custom layout development.
|
|
42
|
-
- **Convenient Plugins**: Optimized built-in plugin functionality and performance, with flexible extensibility, making it easier to implement customized business capabilities.
|
|
43
|
-
- **Multiple Theme and Palettes**: Provides two sets of built-in themes, light and dark, that integrate over 20 popular community color palettes based on the AntV new color scheme.
|
|
44
|
-
- **Multi-Environment Rendering**: Harnessing the power of [G](https://github.com/antvis/g), it supports rendering in Canvas, SVG, and WebGL, as well as server-side rendering with Node.js; it also offers plugin packages that provide powerful 3D rendering and spatial interactions based on WebGL.
|
|
45
|
-
- **React Ecosystem**: By utilizing the React front-end ecosystem, it supports React nodes, significantly enriching the presentational styles of G6 nodes.
|
|
46
|
-
|
|
47
|
-
## 🔨 Getting Started
|
|
48
|
-
|
|
49
|
-
G6 is usually installed via a package manager such as npm or Yarn.
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
$ npm install @antv/g6
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
The `Graph` object then can be imported from G6.
|
|
56
|
-
|
|
57
|
-
```html
|
|
58
|
-
<div id="container"></div>
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
import { Graph } from '@antv/g6';
|
|
63
|
-
|
|
64
|
-
// Get the Data.
|
|
65
|
-
const data = {
|
|
66
|
-
nodes: [
|
|
67
|
-
/* your nodes data */
|
|
68
|
-
],
|
|
69
|
-
edges: [
|
|
70
|
-
/* your edges data */
|
|
71
|
-
],
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Create the Graph instance.
|
|
75
|
-
const graph = new Graph({
|
|
76
|
-
container: 'container',
|
|
77
|
-
data,
|
|
78
|
-
node: {
|
|
79
|
-
palette: {
|
|
80
|
-
type: 'group',
|
|
81
|
-
field: 'cluster',
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
layout: {
|
|
85
|
-
type: 'force',
|
|
86
|
-
},
|
|
87
|
-
behaviors: ['drag-canvas', 'drag-node'],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Render the Graph.
|
|
91
|
-
graph.render();
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
All goes well, you can get the following lovely graph!
|
|
95
|
-
|
|
96
|
-
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*ue4iTYurc6sAAAAAAAAAAAAADmJ7AQ/fmt.webp" height="300" />
|
|
97
|
-
|
|
98
|
-
## 🌍 Ecosystem
|
|
99
|
-
|
|
100
|
-
- **Ant Design Charts**: A React chart library based on G2, G6, X6, L7.
|
|
101
|
-
- **Graphin**: A simple React wrapper based on G6, as well as an SDK for developing graph visualization applications.
|
|
102
|
-
|
|
103
|
-
For more ecosystem open-source projects, contributions are welcome. Please feel free to submit a PR for inclusion.
|
|
104
|
-
|
|
105
|
-
## 📮 Contributing
|
|
106
|
-
|
|
107
|
-
- **Issue Reporting**: If you encounter any issues with G6 during use, please feel free to submit an issue, along with the minimal sample code that can reproduce the problem.
|
|
108
|
-
- **Contribution Guide**: Information on how to get involved in the [development and contribution](https://g6.antv.antgroup.com/en/manual/contribute) to G6.
|
|
109
|
-
- **Ideas Discussion**: Discuss your ideas on GitHub Discussions or in the DingTalk group.
|
|
110
|
-
|
|
111
|
-
<div align="center">
|
|
112
|
-
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*CQoGSoFBzaUAAAAAAAAAAAAADmJ7AQ/fmt.webp" height="256" />
|
|
113
|
-
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*yXJGSY8RC68AAAAAAAAAAAAADmJ7AQ/fmt.webp" height="256" />
|
|
114
|
-
</div>
|
|
115
|
-
|
|
116
|
-
## 📄 License
|
|
117
|
-
|
|
118
|
-
[MIT](./LICENSE).
|