@antv/g2 5.1.19 → 5.1.21
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/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/animation/morphing.js +14 -12
- package/esm/animation/morphing.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/interaction/brushHighlight.js +11 -8
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +1 -1
- package/esm/interaction/tooltip.js +120 -19
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/label-transform/exceedAdjust.d.ts +7 -0
- package/esm/label-transform/exceedAdjust.js +45 -0
- package/esm/label-transform/exceedAdjust.js.map +1 -0
- package/esm/label-transform/index.d.ts +2 -0
- package/esm/label-transform/index.js +1 -0
- package/esm/label-transform/index.js.map +1 -1
- package/esm/lib/core.d.ts +1 -0
- package/esm/lib/core.js +2 -1
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/runtime/component.js +2 -0
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/layout.js +3 -3
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/plot.js +16 -10
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/transform.js +2 -2
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/component.d.ts +5 -2
- package/esm/shape/vector/vector.js +2 -3
- package/esm/shape/vector/vector.js.map +1 -1
- package/esm/spec/labelTransform.d.ts +3 -0
- package/esm/theme/dark.js +1 -1
- package/esm/theme/dark.js.map +1 -1
- package/lib/animation/morphing.js +14 -12
- package/lib/animation/morphing.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/interaction/brushHighlight.js +11 -8
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +1 -1
- package/lib/interaction/tooltip.js +119 -18
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/label-transform/exceedAdjust.d.ts +7 -0
- package/lib/label-transform/exceedAdjust.js +49 -0
- package/lib/label-transform/exceedAdjust.js.map +1 -0
- package/lib/label-transform/index.d.ts +2 -0
- package/lib/label-transform/index.js +3 -1
- package/lib/label-transform/index.js.map +1 -1
- package/lib/lib/core.d.ts +1 -0
- package/lib/lib/core.js +1 -0
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/runtime/component.js +2 -0
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/layout.js +3 -3
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/plot.js +15 -9
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/transform.js +2 -2
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/component.d.ts +5 -2
- package/lib/shape/vector/vector.js +2 -3
- package/lib/shape/vector/vector.js.map +1 -1
- package/lib/spec/labelTransform.d.ts +3 -0
- package/lib/theme/dark.js +1 -1
- package/lib/theme/dark.js.map +1 -1
- package/package.json +1 -1
- package/src/animation/morphing.ts +15 -12
- package/src/interaction/brushHighlight.ts +13 -8
- package/src/interaction/tooltip.ts +178 -18
- package/src/label-transform/exceedAdjust.ts +61 -0
- package/src/label-transform/index.ts +2 -0
- package/src/lib/core.ts +2 -0
- package/src/runtime/component.ts +1 -0
- package/src/runtime/layout.ts +3 -3
- package/src/runtime/plot.ts +18 -9
- package/src/runtime/transform.ts +2 -2
- package/src/runtime/types/component.ts +10 -2
- package/src/shape/vector/vector.ts +2 -3
- package/src/spec/labelTransform.ts +4 -0
- package/src/theme/dark.ts +1 -1
|
@@ -5,7 +5,7 @@ import { Tooltip as TooltipComponent } from '@antv/component';
|
|
|
5
5
|
import { Constant, Band } from '@antv/scale';
|
|
6
6
|
import { defined, subObject } from '../utils/helper';
|
|
7
7
|
import { isTranspose, isPolar } from '../utils/coordinate';
|
|
8
|
-
import { angle, sub } from '../utils/vector';
|
|
8
|
+
import { angle, sub, dist } from '../utils/vector';
|
|
9
9
|
import { invert } from '../utils/scale';
|
|
10
10
|
import { BBox } from '../runtime';
|
|
11
11
|
import {
|
|
@@ -288,6 +288,106 @@ function groupItems(
|
|
|
288
288
|
};
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
function updateRuleX(
|
|
292
|
+
root,
|
|
293
|
+
points,
|
|
294
|
+
mouse,
|
|
295
|
+
{
|
|
296
|
+
plotWidth,
|
|
297
|
+
plotHeight,
|
|
298
|
+
mainWidth,
|
|
299
|
+
mainHeight,
|
|
300
|
+
startX,
|
|
301
|
+
startY,
|
|
302
|
+
transposed,
|
|
303
|
+
polar,
|
|
304
|
+
insetLeft,
|
|
305
|
+
insetTop,
|
|
306
|
+
...rest
|
|
307
|
+
},
|
|
308
|
+
) {
|
|
309
|
+
const defaults = {
|
|
310
|
+
lineWidth: 1,
|
|
311
|
+
stroke: '#1b1e23',
|
|
312
|
+
strokeOpacity: 0.5,
|
|
313
|
+
...rest,
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const createCircle = (cx, cy, r) => {
|
|
317
|
+
const circle = new Circle({
|
|
318
|
+
style: {
|
|
319
|
+
cx,
|
|
320
|
+
cy,
|
|
321
|
+
r,
|
|
322
|
+
...defaults,
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
root.appendChild(circle);
|
|
326
|
+
return circle;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const createLine = (x1, x2, y1, y2) => {
|
|
330
|
+
const line = new Line({
|
|
331
|
+
style: {
|
|
332
|
+
x1,
|
|
333
|
+
x2,
|
|
334
|
+
y1,
|
|
335
|
+
y2,
|
|
336
|
+
...defaults,
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
root.appendChild(line);
|
|
340
|
+
return line;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const minDistPoint = (mouse, points) => {
|
|
344
|
+
// only one point do not need compute
|
|
345
|
+
if (points.length === 1) {
|
|
346
|
+
return points[0];
|
|
347
|
+
}
|
|
348
|
+
const dists = points.map((p) => dist(p, mouse));
|
|
349
|
+
const minDistIndex = minIndex(dists, (d) => d);
|
|
350
|
+
return points[minDistIndex];
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const target = minDistPoint(mouse, points);
|
|
354
|
+
|
|
355
|
+
const pointsOf = () => {
|
|
356
|
+
if (transposed)
|
|
357
|
+
return [
|
|
358
|
+
startX + target[0],
|
|
359
|
+
startX + target[0],
|
|
360
|
+
startY,
|
|
361
|
+
startY + plotHeight,
|
|
362
|
+
];
|
|
363
|
+
return [startX, startX + plotWidth, target[1] + startY, target[1] + startY];
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const pointsOfPolar = () => {
|
|
367
|
+
const cx = startX + insetLeft + mainWidth / 2;
|
|
368
|
+
const cy = startY + insetTop + mainHeight / 2;
|
|
369
|
+
const cdist = dist([cx, cy], target);
|
|
370
|
+
return [cx, cy, cdist];
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
if (polar) {
|
|
374
|
+
const [cx, cy, r] = pointsOfPolar();
|
|
375
|
+
const ruleX = root.ruleX || createCircle(cx, cy, r);
|
|
376
|
+
ruleX.style.cx = cx;
|
|
377
|
+
ruleX.style.cy = cy;
|
|
378
|
+
ruleX.style.r = r;
|
|
379
|
+
root.ruleX = ruleX;
|
|
380
|
+
} else {
|
|
381
|
+
const [x1, x2, y1, y2] = pointsOf();
|
|
382
|
+
const ruleX = root.ruleX || createLine(x1, x2, y1, y2);
|
|
383
|
+
ruleX.style.x1 = x1;
|
|
384
|
+
ruleX.style.x2 = x2;
|
|
385
|
+
ruleX.style.y1 = y1;
|
|
386
|
+
ruleX.style.y2 = y2;
|
|
387
|
+
root.ruleX = ruleX;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
291
391
|
function updateRuleY(
|
|
292
392
|
root,
|
|
293
393
|
points,
|
|
@@ -311,10 +411,12 @@ function updateRuleY(
|
|
|
311
411
|
strokeOpacity: 0.5,
|
|
312
412
|
...rest,
|
|
313
413
|
};
|
|
414
|
+
|
|
314
415
|
const Y = points.map((p) => p[1]);
|
|
315
416
|
const X = points.map((p) => p[0]);
|
|
316
417
|
const y = mean(Y);
|
|
317
418
|
const x = mean(X);
|
|
419
|
+
|
|
318
420
|
const pointsOf = () => {
|
|
319
421
|
if (polar) {
|
|
320
422
|
const r = Math.min(mainWidth, mainHeight) / 2;
|
|
@@ -328,6 +430,7 @@ function updateRuleY(
|
|
|
328
430
|
if (transposed) return [startX, startX + plotWidth, y + startY, y + startY];
|
|
329
431
|
return [x + startX, x + startX, startY, startY + plotHeight];
|
|
330
432
|
};
|
|
433
|
+
|
|
331
434
|
const [x1, x2, y1, y2] = pointsOf();
|
|
332
435
|
const createLine = () => {
|
|
333
436
|
const line = new Line({
|
|
@@ -360,6 +463,13 @@ function hideRuleY(root) {
|
|
|
360
463
|
}
|
|
361
464
|
}
|
|
362
465
|
|
|
466
|
+
function hideRuleX(root) {
|
|
467
|
+
if (root.ruleX) {
|
|
468
|
+
root.ruleX.remove();
|
|
469
|
+
root.ruleX = undefined;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
363
473
|
function updateMarker(root, { data, style, theme }) {
|
|
364
474
|
if (root.markers) root.markers.forEach((d) => d.remove());
|
|
365
475
|
const markers = data
|
|
@@ -442,6 +552,8 @@ export function seriesTooltip(
|
|
|
442
552
|
scale,
|
|
443
553
|
coordinate,
|
|
444
554
|
crosshairs,
|
|
555
|
+
crosshairsX,
|
|
556
|
+
crosshairsY,
|
|
445
557
|
render,
|
|
446
558
|
groupName,
|
|
447
559
|
emitter,
|
|
@@ -469,6 +581,7 @@ export function seriesTooltip(
|
|
|
469
581
|
const transposed = isTranspose(coordinate);
|
|
470
582
|
const polar = isPolar(coordinate);
|
|
471
583
|
const style = deepMix(_style, rest);
|
|
584
|
+
|
|
472
585
|
const {
|
|
473
586
|
innerWidth: plotWidth,
|
|
474
587
|
innerHeight: plotHeight,
|
|
@@ -662,22 +775,50 @@ export function seriesTooltip(
|
|
|
662
775
|
});
|
|
663
776
|
}
|
|
664
777
|
|
|
665
|
-
if (crosshairs) {
|
|
666
|
-
const points = filteredSeriesData.map((d) => d[1]);
|
|
778
|
+
if (crosshairs || crosshairsX || crosshairsY) {
|
|
667
779
|
const ruleStyle = subObject(style, 'crosshairs');
|
|
668
|
-
|
|
780
|
+
|
|
781
|
+
const ruleStyleX = {
|
|
669
782
|
...ruleStyle,
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
783
|
+
...subObject(style, 'crosshairsX'),
|
|
784
|
+
};
|
|
785
|
+
const ruleStyleY = {
|
|
786
|
+
...ruleStyle,
|
|
787
|
+
...subObject(style, 'crosshairsY'),
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
const points = filteredSeriesData.map((d) => d[1]);
|
|
791
|
+
if (crosshairsX) {
|
|
792
|
+
updateRuleX(root, points, mouse, {
|
|
793
|
+
...ruleStyleX,
|
|
794
|
+
plotWidth,
|
|
795
|
+
plotHeight,
|
|
796
|
+
mainWidth,
|
|
797
|
+
mainHeight,
|
|
798
|
+
insetLeft,
|
|
799
|
+
insetTop,
|
|
800
|
+
startX,
|
|
801
|
+
startY,
|
|
802
|
+
transposed,
|
|
803
|
+
polar,
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
if (crosshairsY) {
|
|
808
|
+
updateRuleY(root, points, {
|
|
809
|
+
...ruleStyleY,
|
|
810
|
+
plotWidth,
|
|
811
|
+
plotHeight,
|
|
812
|
+
mainWidth,
|
|
813
|
+
mainHeight,
|
|
814
|
+
insetLeft,
|
|
815
|
+
insetTop,
|
|
816
|
+
startX,
|
|
817
|
+
startY,
|
|
818
|
+
transposed,
|
|
819
|
+
polar,
|
|
820
|
+
});
|
|
821
|
+
}
|
|
681
822
|
}
|
|
682
823
|
|
|
683
824
|
if (marker) {
|
|
@@ -701,13 +842,19 @@ export function seriesTooltip(
|
|
|
701
842
|
|
|
702
843
|
const hide = (event: MouseEvent) => {
|
|
703
844
|
hideTooltip({ root, single, emitter, event });
|
|
704
|
-
if (crosshairs)
|
|
845
|
+
if (crosshairs) {
|
|
846
|
+
hideRuleY(root);
|
|
847
|
+
hideRuleX(root);
|
|
848
|
+
}
|
|
705
849
|
if (marker) hideMarker(root);
|
|
706
850
|
};
|
|
707
851
|
|
|
708
852
|
const destroy = () => {
|
|
709
853
|
destroyTooltip({ root, single });
|
|
710
|
-
if (crosshairs)
|
|
854
|
+
if (crosshairs) {
|
|
855
|
+
hideRuleY(root);
|
|
856
|
+
hideRuleX(root);
|
|
857
|
+
}
|
|
711
858
|
if (marker) hideMarker(root);
|
|
712
859
|
};
|
|
713
860
|
|
|
@@ -939,12 +1086,15 @@ export function Tooltip(options) {
|
|
|
939
1086
|
const {
|
|
940
1087
|
shared,
|
|
941
1088
|
crosshairs,
|
|
1089
|
+
crosshairsX,
|
|
1090
|
+
crosshairsY,
|
|
942
1091
|
series,
|
|
943
1092
|
name,
|
|
944
1093
|
item = () => ({}),
|
|
945
1094
|
facet = false,
|
|
946
1095
|
...rest
|
|
947
1096
|
} = options;
|
|
1097
|
+
|
|
948
1098
|
return (target, viewInstances, emitter) => {
|
|
949
1099
|
const { container, view } = target;
|
|
950
1100
|
const { scale, markState, coordinate, theme } = view;
|
|
@@ -953,6 +1103,7 @@ export function Tooltip(options) {
|
|
|
953
1103
|
const defaultShowCrosshairs = interactionKeyof(markState, 'crosshairs');
|
|
954
1104
|
const plotArea = selectPlotArea(container);
|
|
955
1105
|
const isSeries = maybeValue(series, defaultSeries);
|
|
1106
|
+
const crosshairsSetting = maybeValue(crosshairs, defaultShowCrosshairs);
|
|
956
1107
|
|
|
957
1108
|
// For non-facet and series tooltip.
|
|
958
1109
|
if (isSeries && hasSeries(markState) && !facet) {
|
|
@@ -962,7 +1113,12 @@ export function Tooltip(options) {
|
|
|
962
1113
|
elements: selectG2Elements,
|
|
963
1114
|
scale,
|
|
964
1115
|
coordinate,
|
|
965
|
-
crosshairs:
|
|
1116
|
+
crosshairs: crosshairsSetting,
|
|
1117
|
+
// the crosshairsX settings level: crosshairsX > crosshairs > false
|
|
1118
|
+
// it means crosshairsX default is false
|
|
1119
|
+
crosshairsX: maybeValue(maybeValue(crosshairsX, crosshairs), false),
|
|
1120
|
+
// crosshairsY default depend on the crossharisSettings
|
|
1121
|
+
crosshairsY: maybeValue(crosshairsY, crosshairsSetting),
|
|
966
1122
|
item,
|
|
967
1123
|
emitter,
|
|
968
1124
|
});
|
|
@@ -992,6 +1148,10 @@ export function Tooltip(options) {
|
|
|
992
1148
|
scale,
|
|
993
1149
|
coordinate,
|
|
994
1150
|
crosshairs: maybeValue(crosshairs, defaultShowCrosshairs),
|
|
1151
|
+
// the crosshairsX settings level: crosshairsX > crosshairs > false
|
|
1152
|
+
// it means crosshairsX default is false
|
|
1153
|
+
crosshairsX: maybeValue(maybeValue(crosshairsX, crosshairs), false),
|
|
1154
|
+
crosshairsY: maybeValue(crosshairsY, crosshairsSetting),
|
|
995
1155
|
item,
|
|
996
1156
|
startX,
|
|
997
1157
|
startY,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { LabelTransformComponent as LLC } from '../runtime';
|
|
3
|
+
import { ExceedAdjustLabel } from '../spec';
|
|
4
|
+
import { Bounds } from '../utils/bounds';
|
|
5
|
+
import { show } from '../utils/style';
|
|
6
|
+
|
|
7
|
+
const adjustPosition = (target: Bounds, edge: Bounds) => {
|
|
8
|
+
const [[minEdgeX, minEdgeY], [maxEdgeX, maxEdgeY]] = edge;
|
|
9
|
+
const [[minX, minY], [maxX, maxY]] = target;
|
|
10
|
+
|
|
11
|
+
let changeX = 0,
|
|
12
|
+
changeY = 0;
|
|
13
|
+
|
|
14
|
+
// x-axis
|
|
15
|
+
if (minX < minEdgeX) {
|
|
16
|
+
changeX = minEdgeX - minX;
|
|
17
|
+
} else if (maxX > maxEdgeX) {
|
|
18
|
+
changeX = maxEdgeX - maxX;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// y-axis
|
|
22
|
+
if (minY < minEdgeY) {
|
|
23
|
+
changeY = minEdgeY - minY;
|
|
24
|
+
} else if (maxY > maxEdgeY) {
|
|
25
|
+
changeY = maxEdgeY - maxY;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return [changeX, changeY];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ExceedAdjustOptions = Omit<ExceedAdjustLabel, 'type'>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* adjust the label when exceed the plot
|
|
35
|
+
*/
|
|
36
|
+
export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
|
|
37
|
+
return (labels: DisplayObject[], { canvas }) => {
|
|
38
|
+
const { width, height } = canvas.getConfig();
|
|
39
|
+
|
|
40
|
+
labels.forEach((l) => {
|
|
41
|
+
show(l);
|
|
42
|
+
const { max, min } = l.getRenderBounds();
|
|
43
|
+
const [xMax, yMax] = max,
|
|
44
|
+
[xMin, yMin] = min;
|
|
45
|
+
const changeValue = adjustPosition(
|
|
46
|
+
[
|
|
47
|
+
[xMin, yMin],
|
|
48
|
+
[xMax, yMax],
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
[0, 0],
|
|
52
|
+
[width, height],
|
|
53
|
+
],
|
|
54
|
+
);
|
|
55
|
+
l.style.x += changeValue[0];
|
|
56
|
+
l.style.y += changeValue[1];
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return labels;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
@@ -2,8 +2,10 @@ export { OverlapHide } from './overlapHide';
|
|
|
2
2
|
export { OverlapDodgeY } from './overlapDodgeY';
|
|
3
3
|
export { ContrastReverse } from './contrastReverse';
|
|
4
4
|
export { OverflowHide } from './overflowHide';
|
|
5
|
+
export { ExceedAdjust } from './exceedAdjust';
|
|
5
6
|
|
|
6
7
|
export type { OverlapHideOptions } from './overlapHide';
|
|
7
8
|
export type { OverlapDodgeYOptions } from './overlapDodgeY';
|
|
8
9
|
export type { ContrastReverseOptions } from './contrastReverse';
|
|
9
10
|
export type { OverflowHideOptions } from './overflowHide';
|
|
11
|
+
export type { ExceedAdjustOptions } from './exceedAdjust';
|
package/src/lib/core.ts
CHANGED
|
@@ -161,6 +161,7 @@ import {
|
|
|
161
161
|
OverflowHide,
|
|
162
162
|
ContrastReverse,
|
|
163
163
|
OverlapHide,
|
|
164
|
+
ExceedAdjust,
|
|
164
165
|
} from '../label-transform';
|
|
165
166
|
|
|
166
167
|
export function corelib() {
|
|
@@ -317,5 +318,6 @@ export function corelib() {
|
|
|
317
318
|
'labelTransform.overlapDodgeY': OverlapDodgeY,
|
|
318
319
|
'labelTransform.overflowHide': OverflowHide,
|
|
319
320
|
'labelTransform.contrastReverse': ContrastReverse,
|
|
321
|
+
'labelTransform.exceedAdjust': ExceedAdjust,
|
|
320
322
|
} as const;
|
|
321
323
|
}
|
package/src/runtime/component.ts
CHANGED
|
@@ -741,6 +741,7 @@ function computeAxisSize(
|
|
|
741
741
|
component.labelTransform = 'rotate(90)';
|
|
742
742
|
component.size = maxLabelWidth + paddingTick;
|
|
743
743
|
} else {
|
|
744
|
+
component.labelTransform = component.labelTransform ?? 'rotate(0)';
|
|
744
745
|
component.size = maxLabelHeight + paddingTick;
|
|
745
746
|
}
|
|
746
747
|
}
|
package/src/runtime/layout.ts
CHANGED
|
@@ -29,11 +29,11 @@ import {
|
|
|
29
29
|
} from './coordinate';
|
|
30
30
|
|
|
31
31
|
export function processAxisZ(components: G2GuideComponentOptions[]) {
|
|
32
|
+
const axisX = components.find(({ type }) => type === 'axisX');
|
|
33
|
+
const axisY = components.find(({ type }) => type === 'axisY');
|
|
32
34
|
const axisZ = components.find(({ type }) => type === 'axisZ');
|
|
33
|
-
if (axisZ) {
|
|
34
|
-
const axisX = components.find(({ type }) => type === 'axisX');
|
|
35
|
+
if (axisX && axisY && axisZ) {
|
|
35
36
|
axisX.plane = 'xy';
|
|
36
|
-
const axisY = components.find(({ type }) => type === 'axisY');
|
|
37
37
|
axisY.plane = 'xy';
|
|
38
38
|
axisZ.plane = 'yz';
|
|
39
39
|
axisZ.origin = [axisX.bbox.x, axisX.bbox.y, 0];
|
package/src/runtime/plot.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { format } from 'd3-format';
|
|
|
6
6
|
import { mapObject } from '../utils/array';
|
|
7
7
|
import { ChartEvent } from '../utils/event';
|
|
8
8
|
import {
|
|
9
|
+
isStrictObject,
|
|
9
10
|
appendTransform,
|
|
10
11
|
compose,
|
|
11
12
|
copyAttributes,
|
|
@@ -1220,15 +1221,20 @@ function plotLabel(
|
|
|
1220
1221
|
labelDescriptor.get(d.__data__),
|
|
1221
1222
|
);
|
|
1222
1223
|
const { coordinate } = view;
|
|
1224
|
+
|
|
1225
|
+
const labelTransformContext = {
|
|
1226
|
+
canvas: context.canvas,
|
|
1227
|
+
coordinate,
|
|
1228
|
+
};
|
|
1223
1229
|
for (const [label, shapes] of labelGroups) {
|
|
1224
1230
|
const { transform = [] } = label;
|
|
1225
1231
|
const transformFunction = compose(transform.map(useLabelTransform));
|
|
1226
|
-
transformFunction(shapes,
|
|
1232
|
+
transformFunction(shapes, labelTransformContext);
|
|
1227
1233
|
}
|
|
1228
1234
|
|
|
1229
1235
|
// Apply view-level transform.
|
|
1230
1236
|
if (labelTransform) {
|
|
1231
|
-
labelTransform(labelShapes,
|
|
1237
|
+
labelTransform(labelShapes, labelTransformContext);
|
|
1232
1238
|
}
|
|
1233
1239
|
}
|
|
1234
1240
|
|
|
@@ -1325,9 +1331,10 @@ function createLabelShapeFunction(
|
|
|
1325
1331
|
'shape',
|
|
1326
1332
|
library,
|
|
1327
1333
|
);
|
|
1328
|
-
const { data: abstractData } = mark;
|
|
1334
|
+
const { data: abstractData, encode } = mark;
|
|
1329
1335
|
const { data: visualData, defaultLabelShape } = state;
|
|
1330
1336
|
const point2d = visualData.map((d) => d.points);
|
|
1337
|
+
const channel = mapObject(encode, (d) => d.value);
|
|
1331
1338
|
|
|
1332
1339
|
// Assemble Context.
|
|
1333
1340
|
const { theme, coordinate } = view;
|
|
@@ -1351,7 +1358,7 @@ function createLabelShapeFunction(
|
|
|
1351
1358
|
} = options;
|
|
1352
1359
|
const visualOptions = mapObject(
|
|
1353
1360
|
{ ...abstractOptions, ...abstractStyle } as Record<string, any>,
|
|
1354
|
-
(d) => valueOf(d, datum, index, abstractData),
|
|
1361
|
+
(d) => valueOf(d, datum, index, abstractData, { channel }),
|
|
1355
1362
|
);
|
|
1356
1363
|
const { shape = defaultLabelShape, text, ...style } = visualOptions;
|
|
1357
1364
|
const f = typeof formatter === 'string' ? format(formatter) : formatter;
|
|
@@ -1371,14 +1378,15 @@ function createLabelShapeFunction(
|
|
|
1371
1378
|
}
|
|
1372
1379
|
|
|
1373
1380
|
function valueOf(
|
|
1374
|
-
value: Primitive | ((d: any, i: number, array: any) => any),
|
|
1381
|
+
value: Primitive | ((d: any, i: number, array: any, channel: any) => any),
|
|
1375
1382
|
datum: Record<string, any>,
|
|
1376
1383
|
i: number,
|
|
1377
1384
|
data: Record<string, any>,
|
|
1385
|
+
options: { channel: Record<string, any> },
|
|
1378
1386
|
) {
|
|
1379
|
-
if (typeof value === 'function') return value(datum, i, data);
|
|
1387
|
+
if (typeof value === 'function') return value(datum, i, data, options);
|
|
1380
1388
|
if (typeof value !== 'string') return value;
|
|
1381
|
-
if (datum[value] !== undefined) return datum[value];
|
|
1389
|
+
if (isStrictObject(datum) && datum[value] !== undefined) return datum[value];
|
|
1382
1390
|
return value;
|
|
1383
1391
|
}
|
|
1384
1392
|
|
|
@@ -1491,8 +1499,9 @@ function createMarkShapeFunction(
|
|
|
1491
1499
|
'shape',
|
|
1492
1500
|
library,
|
|
1493
1501
|
);
|
|
1494
|
-
const { data: abstractData } = mark;
|
|
1502
|
+
const { data: abstractData, encode } = mark;
|
|
1495
1503
|
const { defaultShape, data, shape: shapeLibrary } = state;
|
|
1504
|
+
const channel = mapObject(encode, (d) => d.value);
|
|
1496
1505
|
const point2d = data.map((d) => d.points);
|
|
1497
1506
|
const { theme, coordinate } = view;
|
|
1498
1507
|
const { type: markType, style = {} } = mark;
|
|
@@ -1518,7 +1527,7 @@ function createMarkShapeFunction(
|
|
|
1518
1527
|
|
|
1519
1528
|
const I = seriesIndex ? seriesIndex : i;
|
|
1520
1529
|
const visualStyle = mapObject(style, (d) =>
|
|
1521
|
-
valueOf(d, abstractDatum, I, abstractData),
|
|
1530
|
+
valueOf(d, abstractDatum, I, abstractData, { channel }),
|
|
1522
1531
|
);
|
|
1523
1532
|
|
|
1524
1533
|
// Try get shape from mark first, then from library.
|
package/src/runtime/transform.ts
CHANGED
|
@@ -260,8 +260,8 @@ export function addGuideToScale(
|
|
|
260
260
|
};
|
|
261
261
|
const axisChannels =
|
|
262
262
|
typeof axis === 'object'
|
|
263
|
-
? Array.from(new Set(['x', 'y', ...Object.keys(axis)]))
|
|
264
|
-
: ['x', 'y'];
|
|
263
|
+
? Array.from(new Set(['x', 'y', 'z', ...Object.keys(axis)]))
|
|
264
|
+
: ['x', 'y', 'z'];
|
|
265
265
|
|
|
266
266
|
deepMix(mark, {
|
|
267
267
|
scale: {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Coordinate, Transformation } from '@antv/coord';
|
|
2
2
|
import EventEmitter from '@antv/event-emitter';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
DisplayObject,
|
|
5
|
+
IAnimation as GAnimation,
|
|
6
|
+
IDocument,
|
|
7
|
+
Canvas,
|
|
8
|
+
} from '@antv/g';
|
|
4
9
|
import {
|
|
5
10
|
G2Theme,
|
|
6
11
|
G2ViewInstance,
|
|
@@ -225,7 +230,10 @@ export type CompositionComponent<O = Record<string, unknown>> = G2BaseComponent<
|
|
|
225
230
|
|
|
226
231
|
export type LabelTransform = (
|
|
227
232
|
labels: DisplayObject[],
|
|
228
|
-
|
|
233
|
+
context: {
|
|
234
|
+
coordinate: Coordinate;
|
|
235
|
+
canvas: Canvas;
|
|
236
|
+
},
|
|
229
237
|
) => DisplayObject[];
|
|
230
238
|
export type LabelTransformComponent<O = Record<string, unknown>> =
|
|
231
239
|
G2BaseComponent<LabelTransform, O>;
|
|
@@ -26,9 +26,8 @@ export const Vector: SC<VectorOptions> = (options, context) => {
|
|
|
26
26
|
if (arrow) {
|
|
27
27
|
// Calculate arrow end point.
|
|
28
28
|
const [arrow1, arrow2] = arrowPoints(from, to, { arrowSize });
|
|
29
|
-
path.moveTo(...
|
|
30
|
-
path.lineTo(...
|
|
31
|
-
path.moveTo(...to);
|
|
29
|
+
path.moveTo(...arrow1);
|
|
30
|
+
path.lineTo(...to);
|
|
32
31
|
path.lineTo(...arrow2);
|
|
33
32
|
}
|
|
34
33
|
|