@antv/g6 5.0.0-beta.24 → 5.0.0-beta.26
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/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/item/edge.js +1 -1
- package/esm/item/edge.js.map +1 -1
- package/esm/item/item.js +23 -3
- package/esm/item/item.js.map +1 -1
- package/esm/item/node.js +1 -1
- package/esm/item/node.js.map +1 -1
- package/esm/runtime/controller/layout.js +16 -4
- package/esm/runtime/controller/layout.js.map +1 -1
- package/esm/runtime/graph.js +25 -23
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/data/mapNodeSize.js +3 -3
- package/esm/stdlib/data/mapNodeSize.js.map +1 -1
- package/esm/stdlib/plugin/menu/index.js +2 -1
- package/esm/stdlib/plugin/menu/index.js.map +1 -1
- package/esm/types/view.d.ts +4 -2
- package/esm/util/animate.js +4 -1
- package/esm/util/animate.js.map +1 -1
- package/esm/util/shape.d.ts +2 -0
- package/esm/util/shape.js +7 -0
- package/esm/util/shape.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/item/edge.js +1 -1
- package/lib/item/edge.js.map +1 -1
- package/lib/item/item.js +23 -3
- package/lib/item/item.js.map +1 -1
- package/lib/item/node.js +1 -1
- package/lib/item/node.js.map +1 -1
- package/lib/runtime/controller/layout.js +16 -4
- package/lib/runtime/controller/layout.js.map +1 -1
- package/lib/runtime/graph.js +25 -23
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/data/mapNodeSize.js +3 -3
- package/lib/stdlib/data/mapNodeSize.js.map +1 -1
- package/lib/stdlib/plugin/menu/index.js +2 -1
- package/lib/stdlib/plugin/menu/index.js.map +1 -1
- package/lib/types/view.d.ts +4 -2
- package/lib/util/animate.js +4 -1
- package/lib/util/animate.js.map +1 -1
- package/lib/util/shape.d.ts +2 -0
- package/lib/util/shape.js +7 -0
- package/lib/util/shape.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/item/edge.ts +1 -1
- package/src/item/item.ts +28 -1
- package/src/item/node.ts +1 -1
- package/src/runtime/controller/layout.ts +22 -4
- package/src/runtime/graph.ts +31 -29
- package/src/stdlib/data/mapNodeSize.ts +3 -3
- package/src/stdlib/plugin/menu/index.ts +1 -1
- package/src/types/view.ts +4 -2
- package/src/util/animate.ts +4 -1
- package/src/util/shape.ts +11 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/item/edge.ts
CHANGED
|
@@ -128,7 +128,7 @@ export default class Edge extends Item {
|
|
|
128
128
|
this.shapeMap, // shapeMap
|
|
129
129
|
this.group,
|
|
130
130
|
firstRendering ? 'buildIn' : 'update',
|
|
131
|
-
diffState
|
|
131
|
+
diffState?.current.map((state) => state.name) || this.changedStates,
|
|
132
132
|
this.animateFrameListener,
|
|
133
133
|
(canceled) => onfinish(displayModel.id, canceled),
|
|
134
134
|
);
|
package/src/item/item.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from '../util/animate';
|
|
33
33
|
import { AnimateTiming, IAnimates } from '../types/animate';
|
|
34
34
|
import { formatLodStrategy } from '../util/zoom';
|
|
35
|
+
import { IStateAnimate } from '../types/animate';
|
|
35
36
|
|
|
36
37
|
export default abstract class Item implements IItem {
|
|
37
38
|
public destroyed = false;
|
|
@@ -473,6 +474,10 @@ export default abstract class Item implements IItem {
|
|
|
473
474
|
|
|
474
475
|
this.visible = true;
|
|
475
476
|
this.cacheHiddenByItem = {};
|
|
477
|
+
// restore the states
|
|
478
|
+
if (this.states?.length) {
|
|
479
|
+
this.drawWithStates([]);
|
|
480
|
+
}
|
|
476
481
|
});
|
|
477
482
|
}
|
|
478
483
|
|
|
@@ -707,13 +712,29 @@ export default abstract class Item implements IItem {
|
|
|
707
712
|
// merge the states' styles into drawing style
|
|
708
713
|
styles = mergeStyles([styles, mergedStateStyles]);
|
|
709
714
|
});
|
|
715
|
+
const mergedData = mergeStyles([displayModelData, styles]);
|
|
716
|
+
const { animates } = mergedData;
|
|
717
|
+
const displayUpdateAnimates = [];
|
|
718
|
+
const stateNames = this.states.map((state) => state.name);
|
|
719
|
+
animates?.update?.forEach((animateCfg) => {
|
|
720
|
+
const { states } = animateCfg as IStateAnimate;
|
|
721
|
+
if (states && isArrayOverlap(states, stateNames)) {
|
|
722
|
+
displayUpdateAnimates.push(animateCfg);
|
|
723
|
+
}
|
|
724
|
+
});
|
|
710
725
|
|
|
711
726
|
// apply the merged styles
|
|
712
727
|
this.draw(
|
|
713
728
|
// displayModel
|
|
714
729
|
{
|
|
715
730
|
...this.displayModel,
|
|
716
|
-
data:
|
|
731
|
+
data: {
|
|
732
|
+
...mergedData,
|
|
733
|
+
animates: {
|
|
734
|
+
...animates,
|
|
735
|
+
update: displayUpdateAnimates,
|
|
736
|
+
},
|
|
737
|
+
},
|
|
717
738
|
} as ItemDisplayModel,
|
|
718
739
|
// diffData
|
|
719
740
|
undefined,
|
|
@@ -766,6 +787,12 @@ export default abstract class Item implements IItem {
|
|
|
766
787
|
estimateBounds.min[i] += val;
|
|
767
788
|
estimateBounds.center[i] += val;
|
|
768
789
|
});
|
|
790
|
+
|
|
791
|
+
estimateBounds.halfExtents = [
|
|
792
|
+
(estimateBounds.max[0] - estimateBounds.min[0]) / 2,
|
|
793
|
+
(estimateBounds.max[1] - estimateBounds.min[1]) / 2,
|
|
794
|
+
(estimateBounds.max[2] - estimateBounds.min[2]) / 2,
|
|
795
|
+
];
|
|
769
796
|
return estimateBounds as AABB;
|
|
770
797
|
}
|
|
771
798
|
return this.group.getRenderBounds();
|
package/src/item/node.ts
CHANGED
|
@@ -107,7 +107,7 @@ export default class Node extends Item {
|
|
|
107
107
|
this.shapeMap, // shapeMap
|
|
108
108
|
group,
|
|
109
109
|
firstRendering ? 'buildIn' : 'update',
|
|
110
|
-
this.changedStates,
|
|
110
|
+
diffState?.current.map((state) => state.name) || this.changedStates,
|
|
111
111
|
this.animateFrameListener,
|
|
112
112
|
(canceled) => onfinish(model.id, canceled),
|
|
113
113
|
);
|
|
@@ -121,10 +121,19 @@ export class LayoutController {
|
|
|
121
121
|
preset: layoutNodes.map((node) => {
|
|
122
122
|
const { x, y, z } = node.data;
|
|
123
123
|
if (isNaN(x) || isNaN(y)) return;
|
|
124
|
-
const
|
|
124
|
+
const presetNode = { x, y, z };
|
|
125
|
+
const otherProps = this.previousNodes?.get(node.id) || {};
|
|
126
|
+
['_order', 'layer'].forEach((field) => {
|
|
127
|
+
presetNode[field] = node.data.hasOwnProperty(field)
|
|
128
|
+
? node.data[field]
|
|
129
|
+
: otherProps[field];
|
|
130
|
+
});
|
|
125
131
|
return {
|
|
126
132
|
id: node.id,
|
|
127
|
-
data: {
|
|
133
|
+
data: {
|
|
134
|
+
...otherProps,
|
|
135
|
+
...presetNode,
|
|
136
|
+
},
|
|
128
137
|
};
|
|
129
138
|
}),
|
|
130
139
|
...rest,
|
|
@@ -185,10 +194,19 @@ export class LayoutController {
|
|
|
185
194
|
.map((node) => {
|
|
186
195
|
const { x, y, z } = node.data;
|
|
187
196
|
if (isNaN(x) || isNaN(y)) return;
|
|
188
|
-
const
|
|
197
|
+
const presetNode = { x, y, z };
|
|
198
|
+
const otherProps = this.previousNodes?.get(node.id) || {};
|
|
199
|
+
['_order', 'layer'].forEach((field) => {
|
|
200
|
+
presetNode[field] = node.data.hasOwnProperty(field)
|
|
201
|
+
? node.data[field]
|
|
202
|
+
: otherProps[field];
|
|
203
|
+
});
|
|
189
204
|
return {
|
|
190
205
|
id: node.id,
|
|
191
|
-
data: {
|
|
206
|
+
data: {
|
|
207
|
+
...otherProps,
|
|
208
|
+
...presetNode,
|
|
209
|
+
},
|
|
192
210
|
};
|
|
193
211
|
})
|
|
194
212
|
.filter(Boolean)
|
package/src/runtime/graph.ts
CHANGED
|
@@ -482,34 +482,33 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
482
482
|
|
|
483
483
|
this.once('afterlayout', async () => {
|
|
484
484
|
const { autoFit } = this.specification;
|
|
485
|
-
if (autoFit)
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
},
|
|
485
|
+
if (!autoFit) return;
|
|
486
|
+
if (autoFit === 'view') {
|
|
487
|
+
await this.fitView({ rules: { boundsType: 'layout' } });
|
|
488
|
+
} else if (autoFit === 'center') {
|
|
489
|
+
await this.fitCenter('layout');
|
|
490
|
+
} else {
|
|
491
|
+
const { type, effectTiming, ...others } = autoFit;
|
|
492
|
+
if (type === 'view') {
|
|
493
|
+
const { padding, rules } = others as {
|
|
494
|
+
padding: Padding;
|
|
495
|
+
rules: FitViewRules;
|
|
496
|
+
};
|
|
497
|
+
await this.fitView(
|
|
498
|
+
{
|
|
499
|
+
padding,
|
|
500
|
+
rules: {
|
|
501
|
+
...rules,
|
|
502
|
+
boundsType: 'layout',
|
|
504
503
|
},
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
504
|
+
},
|
|
505
|
+
effectTiming,
|
|
506
|
+
);
|
|
507
|
+
} else if (type === 'center') {
|
|
508
|
+
await this.fitCenter('layout', effectTiming);
|
|
509
|
+
} else if (type === 'position') {
|
|
510
|
+
// TODO: align
|
|
511
|
+
await this.translateTo((others as any).position, effectTiming);
|
|
513
512
|
}
|
|
514
513
|
}
|
|
515
514
|
});
|
|
@@ -765,7 +764,8 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
765
764
|
direction = 'both',
|
|
766
765
|
ratioRule = 'min',
|
|
767
766
|
boundsType = 'render',
|
|
768
|
-
|
|
767
|
+
onlyOutOfViewport = false,
|
|
768
|
+
onlyZoomAtLargerThanViewport = false,
|
|
769
769
|
} = rules || {};
|
|
770
770
|
|
|
771
771
|
const {
|
|
@@ -799,7 +799,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
799
799
|
min[1] < tlInCanvas.y ||
|
|
800
800
|
max[0] > brInCanvas.x ||
|
|
801
801
|
max[1] > brInCanvas.y;
|
|
802
|
-
if (
|
|
802
|
+
if (onlyOutOfViewport && !isOutOfView) return;
|
|
803
803
|
|
|
804
804
|
const targetViewWidth = brInCanvas.x - tlInCanvas.x;
|
|
805
805
|
const targetViewHeight = brInCanvas.y - tlInCanvas.y;
|
|
@@ -819,6 +819,8 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
819
819
|
: Math.min(wRatio, hRatio);
|
|
820
820
|
}
|
|
821
821
|
|
|
822
|
+
if (onlyZoomAtLargerThanViewport && ratio > 1) ratio = 1;
|
|
823
|
+
|
|
822
824
|
await this.transform(
|
|
823
825
|
{
|
|
824
826
|
translate: {
|
|
@@ -23,9 +23,9 @@ export const MapNodeSize = (
|
|
|
23
23
|
): GraphDataChanges => {
|
|
24
24
|
const { dataAdded, dataUpdated, dataRemoved } = data;
|
|
25
25
|
return {
|
|
26
|
-
dataAdded: handler(dataAdded, options, graphCore),
|
|
27
|
-
dataUpdated: handler(dataUpdated, options, graphCore),
|
|
28
|
-
dataRemoved:
|
|
26
|
+
dataAdded: handler(dataAdded || {}, options, graphCore),
|
|
27
|
+
dataUpdated: handler(dataUpdated || {}, options, graphCore),
|
|
28
|
+
dataRemoved: dataRemoved,
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
|
package/src/types/view.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export interface FitViewRules {
|
|
2
|
-
/** Whehter fit it only when the graph is out of the
|
|
3
|
-
|
|
2
|
+
/** Whehter fit it only when the graph is out of the viewport. */
|
|
3
|
+
onlyOutOfViewport?: boolean;
|
|
4
|
+
/** Whether zoom the graph only when the graph is larger than the viewport. */
|
|
5
|
+
onlyZoomAtLargerThanViewport?: boolean;
|
|
4
6
|
/** Axis to fit. */
|
|
5
7
|
direction?: 'x' | 'y' | 'both';
|
|
6
8
|
/** Ratio rule to fit. */
|
package/src/util/animate.ts
CHANGED
|
@@ -169,7 +169,10 @@ const runAnimateGroupOnShapes = (
|
|
|
169
169
|
...DEFAULT_ANIMATE_CFG[timing],
|
|
170
170
|
...animateCfg,
|
|
171
171
|
};
|
|
172
|
-
const { duration } = animateConfig;
|
|
172
|
+
const { duration, iterations } = animateConfig;
|
|
173
|
+
if (iterations === Infinity && animateCfg.fill == undefined) {
|
|
174
|
+
animateConfig.fill = 'auto';
|
|
175
|
+
}
|
|
173
176
|
|
|
174
177
|
let animation;
|
|
175
178
|
if (!shapeId || shapeId === 'group') {
|
package/src/util/shape.ts
CHANGED
|
@@ -563,6 +563,7 @@ export const getShapeLocalBoundsByStyle = (
|
|
|
563
563
|
min: number[];
|
|
564
564
|
max: number[];
|
|
565
565
|
center: number[];
|
|
566
|
+
halfExtents: number[];
|
|
566
567
|
} => {
|
|
567
568
|
const {
|
|
568
569
|
r,
|
|
@@ -587,12 +588,14 @@ export const getShapeLocalBoundsByStyle = (
|
|
|
587
588
|
min: [-radius, -radius, 0],
|
|
588
589
|
max: [radius, radius, 0],
|
|
589
590
|
center: [0, 0, 0],
|
|
591
|
+
halfExtents: [radius, radius, 0],
|
|
590
592
|
};
|
|
591
593
|
case 'sphere':
|
|
592
594
|
return {
|
|
593
595
|
min: [-radius, -radius, -radius],
|
|
594
596
|
max: [radius, radius, radius],
|
|
595
597
|
center: [0, 0, 0],
|
|
598
|
+
halfExtents: [radius, radius, radius],
|
|
596
599
|
};
|
|
597
600
|
case 'image':
|
|
598
601
|
case 'rect':
|
|
@@ -602,18 +605,21 @@ export const getShapeLocalBoundsByStyle = (
|
|
|
602
605
|
min: [-width / 2, -height / 2, -depth / 2],
|
|
603
606
|
max: [width / 2, height / 2, depth / 2],
|
|
604
607
|
center: [0, 0, 0],
|
|
608
|
+
halfExtents: [width / 2, height / 2, depth / 2],
|
|
605
609
|
};
|
|
606
610
|
case 'ellipse':
|
|
607
611
|
return {
|
|
608
612
|
min: [-radiusX, -radiusY, 0],
|
|
609
613
|
max: [radiusX, radiusY, 0],
|
|
610
614
|
center: [0, 0, 0],
|
|
615
|
+
halfExtents: [radiusX, radiusY, 0],
|
|
611
616
|
};
|
|
612
617
|
case 'line':
|
|
613
618
|
return {
|
|
614
619
|
min: [x1, y1, z1],
|
|
615
620
|
max: [x2, y2, z2],
|
|
616
621
|
center: [(x1 + x2) / 2, (y1 + y2) / 2, (z1 + z2) / 2],
|
|
622
|
+
halfExtents: [(x2 - x1) / 2, (y2 - y1) / 2, (z2 - z1) / 2],
|
|
617
623
|
};
|
|
618
624
|
case 'text':
|
|
619
625
|
case 'polyline':
|
|
@@ -638,12 +644,14 @@ export const combineBounds = (
|
|
|
638
644
|
min: number[];
|
|
639
645
|
max: number[];
|
|
640
646
|
center: number[];
|
|
647
|
+
halfExtents: number[];
|
|
641
648
|
} => {
|
|
642
649
|
const res = {
|
|
643
650
|
center: [0, 0, 0],
|
|
644
651
|
min: [Infinity, Infinity, Infinity],
|
|
645
652
|
max: [-Infinity, -Infinity, -Infinity],
|
|
646
653
|
size: [0, 0, 0],
|
|
654
|
+
halfExtents: [0, 0, 0],
|
|
647
655
|
};
|
|
648
656
|
bounds.forEach((bound) => {
|
|
649
657
|
const { min, max } = bound;
|
|
@@ -655,6 +663,9 @@ export const combineBounds = (
|
|
|
655
663
|
});
|
|
656
664
|
});
|
|
657
665
|
res.center = res.center.map((val, i) => (res.max[i] + res.min[i]) / 2);
|
|
666
|
+
res.halfExtents = res.halfExtents.map(
|
|
667
|
+
(val, i) => (res.max[i] - res.min[i]) / 2,
|
|
668
|
+
);
|
|
658
669
|
return res;
|
|
659
670
|
};
|
|
660
671
|
|