@antv/g2 5.1.11 → 5.1.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/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/component/utils.js +2 -2
- package/esm/component/utils.js.map +1 -1
- package/esm/interaction/tooltip.js +21 -21
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/utils.js +1 -1
- package/esm/interaction/utils.js.map +1 -1
- package/esm/mark/liquid.js +2 -2
- package/esm/mark/liquid.js.map +1 -1
- package/esm/mark/rangeX.js +2 -1
- package/esm/mark/rangeX.js.map +1 -1
- package/esm/mark/rangeY.js +2 -1
- package/esm/mark/rangeY.js.map +1 -1
- package/esm/runtime/component.js +1 -1
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.js +1 -1
- package/esm/runtime/plot.js.map +1 -1
- package/esm/spec/interaction.d.ts +1 -0
- package/esm/spec/transform.d.ts +2 -0
- package/esm/transform/index.d.ts +2 -0
- package/esm/transform/index.js +2 -0
- package/esm/transform/index.js.map +1 -1
- package/esm/transform/maybeDefaultX.d.ts +7 -0
- package/esm/transform/maybeDefaultX.js +29 -0
- package/esm/transform/maybeDefaultX.js.map +1 -0
- package/esm/transform/maybeDefaultY.d.ts +7 -0
- package/esm/transform/maybeDefaultY.js +29 -0
- package/esm/transform/maybeDefaultY.js.map +1 -0
- package/esm/transform/pack.d.ts +2 -1
- package/esm/transform/pack.js +49 -43
- package/esm/transform/pack.js.map +1 -1
- package/lib/component/utils.js +2 -2
- package/lib/component/utils.js.map +1 -1
- package/lib/interaction/tooltip.js +21 -21
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/utils.js +1 -1
- package/lib/interaction/utils.js.map +1 -1
- package/lib/mark/liquid.js +2 -2
- package/lib/mark/liquid.js.map +1 -1
- package/lib/mark/rangeX.js +2 -1
- package/lib/mark/rangeX.js.map +1 -1
- package/lib/mark/rangeY.js +2 -1
- package/lib/mark/rangeY.js.map +1 -1
- package/lib/runtime/component.js +1 -1
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.js +1 -1
- package/lib/runtime/plot.js.map +1 -1
- package/lib/spec/interaction.d.ts +1 -0
- package/lib/spec/transform.d.ts +2 -0
- package/lib/transform/index.d.ts +2 -0
- package/lib/transform/index.js +5 -1
- package/lib/transform/index.js.map +1 -1
- package/lib/transform/maybeDefaultX.d.ts +7 -0
- package/lib/transform/maybeDefaultX.js +33 -0
- package/lib/transform/maybeDefaultX.js.map +1 -0
- package/lib/transform/maybeDefaultY.d.ts +7 -0
- package/lib/transform/maybeDefaultY.js +33 -0
- package/lib/transform/maybeDefaultY.js.map +1 -0
- package/lib/transform/pack.d.ts +2 -1
- package/lib/transform/pack.js +49 -43
- package/lib/transform/pack.js.map +1 -1
- package/package.json +6 -6
- package/src/component/utils.ts +2 -2
- package/src/interaction/tooltip.ts +29 -20
- package/src/interaction/utils.ts +1 -1
- package/src/mark/liquid.ts +6 -2
- package/src/mark/rangeX.ts +2 -1
- package/src/mark/rangeY.ts +2 -1
- package/src/runtime/component.ts +1 -1
- package/src/runtime/plot.ts +1 -1
- package/src/spec/interaction.ts +1 -1
- package/src/spec/transform.ts +2 -0
- package/src/transform/index.ts +2 -0
- package/src/transform/maybeDefaultX.ts +36 -0
- package/src/transform/maybeDefaultY.ts +36 -0
- package/src/transform/pack.ts +51 -45
package/lib/transform/pack.js
CHANGED
|
@@ -3,56 +3,62 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Pack = void 0;
|
|
4
4
|
const util_1 = require("@antv/util");
|
|
5
5
|
const vector_1 = require("../utils/vector");
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
6
|
+
function pack(options) {
|
|
7
|
+
const { padding = 0, direction = 'col' } = options;
|
|
8
|
+
return (P, count, layout) => {
|
|
9
|
+
const pcount = P.length;
|
|
10
|
+
if (pcount === 0)
|
|
11
|
+
return [];
|
|
12
|
+
// col * row >= count
|
|
13
|
+
// row is close to col * aspect, so
|
|
14
|
+
// col * (col * aspect) >= count
|
|
15
|
+
const { innerWidth, innerHeight } = layout;
|
|
16
|
+
const aspect = innerHeight / innerWidth;
|
|
17
|
+
let col = Math.ceil(Math.sqrt(count / aspect));
|
|
18
|
+
// Increase col to avoid total height of packed shape
|
|
19
|
+
// being large than height of bbox.
|
|
20
|
+
let size = innerWidth / col;
|
|
21
|
+
let row = Math.ceil(count / col);
|
|
22
|
+
let h0 = row * size;
|
|
23
|
+
while (h0 > innerHeight) {
|
|
24
|
+
col = col + 1;
|
|
25
|
+
size = innerWidth / col;
|
|
26
|
+
row = Math.ceil(count / col);
|
|
27
|
+
h0 = row * size;
|
|
28
|
+
}
|
|
29
|
+
// Some offset to increase the space usage.
|
|
30
|
+
const space = innerHeight - row * size;
|
|
31
|
+
const intervalY = row <= 1 ? 0 : space / (row - 1);
|
|
32
|
+
const [offsetX, offsetY] = row <= 1
|
|
33
|
+
? [
|
|
34
|
+
(innerWidth - pcount * size) / (pcount - 1),
|
|
35
|
+
(innerHeight - size) / 2,
|
|
36
|
+
]
|
|
37
|
+
: [0, 0];
|
|
38
|
+
return P.map((points, m) => {
|
|
39
|
+
const [x, y, width, height] = (0, vector_1.calcBBox)(points);
|
|
40
|
+
const i = direction === 'col' ? m % col : Math.floor(m / row);
|
|
41
|
+
const j = direction === 'col' ? Math.floor(m / col) : m % row;
|
|
42
|
+
const newX = i * size;
|
|
43
|
+
const newY = (row - j - 1) * size + space;
|
|
44
|
+
const sx = (size - padding) / width;
|
|
45
|
+
const sy = (size - padding) / height;
|
|
46
|
+
// Translate the shape and mark to make sure the center of
|
|
47
|
+
// shape is overlap before and after scale transformation.
|
|
48
|
+
const tx = newX - x + offsetX * i + (1 / 2) * padding;
|
|
49
|
+
const ty = newY - y - intervalY * j - offsetY + (1 / 2) * padding;
|
|
50
|
+
return `translate(${tx}, ${ty}) scale(${sx}, ${sy})`;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
49
55
|
* Uniform pack to avid overlap.
|
|
50
56
|
* @todo Improve or change algorithm to increase space usage.
|
|
51
57
|
* @todo Take some special case into account.
|
|
52
58
|
*/
|
|
53
|
-
const Pack = () => {
|
|
59
|
+
const Pack = (options) => {
|
|
54
60
|
return (I, mark) => {
|
|
55
|
-
return [I, (0, util_1.deepMix)({}, mark, { modifier, axis: false })];
|
|
61
|
+
return [I, (0, util_1.deepMix)({}, mark, { modifier: pack(options), axis: false })];
|
|
56
62
|
};
|
|
57
63
|
};
|
|
58
64
|
exports.Pack = Pack;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.js","sourceRoot":"src/","sources":["transform/pack.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AAErC,4CAA2C;
|
|
1
|
+
{"version":3,"file":"pack.js","sourceRoot":"src/","sources":["transform/pack.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AAErC,4CAA2C;AAK3C,SAAS,IAAI,CAAC,OAAoB;IAChC,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,SAAS,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IACnD,OAAO,CAAC,CAAC,EA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ACvD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACI,MAAM,IAAI,GAAoB,CAAC,OAAO,EAAE,EAAE;IAC/C,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;QACjB,OAAO,CAAC,CAAC,EAAE,IAAA,cAAO,EAAC,EAAE,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IAC1E,CAAC,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,IAAI,QAIf;AAEF,YAAI,CAAC,KAAK,GAAG,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.13",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
|
-
"dev": "TZ=Asia/Shanghai vite",
|
|
27
|
+
"dev": "cross-env TZ=Asia/Shanghai vite",
|
|
28
28
|
"dev:link": "cross-env LINK=1 vite",
|
|
29
29
|
"clean": "rimraf lib esm dist",
|
|
30
30
|
"lint-staged": "lint-staged",
|
|
31
31
|
"size": "limit-size",
|
|
32
32
|
"lint": "eslint ./src ./__tests__ && prettier ./src ./__tests__ --check ",
|
|
33
33
|
"fix": "eslint ./src ./__tests__ --fix && prettier ./src ./__tests__ --write ",
|
|
34
|
-
"test": "TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__ --logHeapUsage",
|
|
35
|
-
"test:unit": "TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/unit/ --coverage --logHeapUsage",
|
|
36
|
-
"test:integration": "TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/integration/ --coverage --logHeapUsage",
|
|
34
|
+
"test": "cross-env TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__ --logHeapUsage",
|
|
35
|
+
"test:unit": "cross-env TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/unit/ --coverage --logHeapUsage",
|
|
36
|
+
"test:integration": "cross-env TZ=Asia/Shanghai node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/integration/ --coverage --logHeapUsage",
|
|
37
37
|
"preview": "vite preview",
|
|
38
38
|
"build:umd": "rimraf ./dist && node --expose-gc --max-old-space-size=4096 node_modules/rollup/dist/bin/rollup -c && npm run size",
|
|
39
39
|
"build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"animation"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@antv/component": "^1.0.0",
|
|
61
|
+
"@antv/component": "^1.0.1-beta.0",
|
|
62
62
|
"@antv/coord": "^0.4.6",
|
|
63
63
|
"@antv/event-emitter": "^0.1.3",
|
|
64
64
|
"@antv/g": "^5.18.19",
|
package/src/component/utils.ts
CHANGED
|
@@ -65,8 +65,8 @@ export function inferComponentLayout(
|
|
|
65
65
|
const layout = {
|
|
66
66
|
top: ['row', 'flex-start', 'center'],
|
|
67
67
|
bottom: ['row', 'flex-start', 'center'],
|
|
68
|
-
left: ['column', '
|
|
69
|
-
right: ['column', '
|
|
68
|
+
left: ['column', 'flex-start', 'center'],
|
|
69
|
+
right: ['column', 'flex-start', 'center'],
|
|
70
70
|
center: ['column', 'center', 'center'],
|
|
71
71
|
};
|
|
72
72
|
|
|
@@ -146,7 +146,13 @@ function showTooltip({
|
|
|
146
146
|
parent.tooltipElement = tooltipElement;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
function hideTooltip({
|
|
149
|
+
function hideTooltip({
|
|
150
|
+
root,
|
|
151
|
+
single,
|
|
152
|
+
emitter,
|
|
153
|
+
nativeEvent = true,
|
|
154
|
+
event = null,
|
|
155
|
+
}) {
|
|
150
156
|
if (nativeEvent) {
|
|
151
157
|
emitter.emit('tooltip:hide', { nativeEvent });
|
|
152
158
|
}
|
|
@@ -154,7 +160,8 @@ function hideTooltip({ root, single, emitter, nativeEvent = true }) {
|
|
|
154
160
|
const parent = single ? container : root;
|
|
155
161
|
const { tooltipElement } = parent;
|
|
156
162
|
if (tooltipElement) {
|
|
157
|
-
|
|
163
|
+
// Must be clientX, clientY.
|
|
164
|
+
tooltipElement.hide(event?.clientX, event?.clientY);
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
167
|
|
|
@@ -523,9 +530,13 @@ export function seriesTooltip(
|
|
|
523
530
|
const finalX = abstractX(focus);
|
|
524
531
|
const DX = X.filter(defined);
|
|
525
532
|
const [minX, maxX] = sort([DX[0], DX[DX.length - 1]]);
|
|
533
|
+
// If only has one element(minX == maxX), show tooltip when hover whole chart
|
|
534
|
+
const isOnlyOneElement = minX === maxX;
|
|
535
|
+
|
|
526
536
|
// If closest is true, always find at least one element.
|
|
527
537
|
// Otherwise, skip element out of plot area.
|
|
528
|
-
if (!closest && (finalX < minX || finalX > maxX)
|
|
538
|
+
if (!closest && (finalX < minX || finalX > maxX) && !isOnlyOneElement)
|
|
539
|
+
return null;
|
|
529
540
|
const search = bisector((i) => X[+i]).center;
|
|
530
541
|
const i = search(I, finalX);
|
|
531
542
|
return I[i];
|
|
@@ -622,7 +633,7 @@ export function seriesTooltip(
|
|
|
622
633
|
|
|
623
634
|
// Hide tooltip with no selected tooltip.
|
|
624
635
|
if (selectedElements.length === 0 || isEmptyTooltipData(tooltipData)) {
|
|
625
|
-
hide();
|
|
636
|
+
hide(event);
|
|
626
637
|
return;
|
|
627
638
|
}
|
|
628
639
|
|
|
@@ -680,8 +691,8 @@ export function seriesTooltip(
|
|
|
680
691
|
{ leading, trailing },
|
|
681
692
|
) as (...args: any[]) => void;
|
|
682
693
|
|
|
683
|
-
const hide = () => {
|
|
684
|
-
hideTooltip({ root, single, emitter });
|
|
694
|
+
const hide = (event: MouseEvent) => {
|
|
695
|
+
hideTooltip({ root, single, emitter, event });
|
|
685
696
|
if (crosshairs) hideRuleY(root);
|
|
686
697
|
if (marker) hideMarker(root);
|
|
687
698
|
};
|
|
@@ -790,11 +801,11 @@ export function tooltip(
|
|
|
790
801
|
const elementSet = new Set(elements);
|
|
791
802
|
const keyGroup = group(elements, groupKey);
|
|
792
803
|
|
|
793
|
-
const
|
|
804
|
+
const pointermove = throttle(
|
|
794
805
|
(event) => {
|
|
795
806
|
const { target: element } = event;
|
|
796
807
|
if (!elementSet.has(element)) {
|
|
797
|
-
hideTooltip({ root, single, emitter });
|
|
808
|
+
hideTooltip({ root, single, emitter, event });
|
|
798
809
|
return;
|
|
799
810
|
}
|
|
800
811
|
const k = groupKey(element);
|
|
@@ -813,7 +824,7 @@ export function tooltip(
|
|
|
813
824
|
}
|
|
814
825
|
|
|
815
826
|
if (isEmptyTooltipData(data)) {
|
|
816
|
-
hideTooltip({ root, single, emitter });
|
|
827
|
+
hideTooltip({ root, single, emitter, event });
|
|
817
828
|
return;
|
|
818
829
|
}
|
|
819
830
|
|
|
@@ -847,25 +858,23 @@ export function tooltip(
|
|
|
847
858
|
{ leading, trailing },
|
|
848
859
|
) as (...args: any[]) => void;
|
|
849
860
|
|
|
850
|
-
const
|
|
851
|
-
|
|
852
|
-
if (!elementSet.has(element)) return;
|
|
853
|
-
hideTooltip({ root, single, emitter });
|
|
861
|
+
const pointerleave = (event) => {
|
|
862
|
+
hideTooltip({ root, single, emitter, event });
|
|
854
863
|
};
|
|
855
864
|
|
|
856
865
|
const addEventListeners = () => {
|
|
857
866
|
if (!disableNative) {
|
|
858
|
-
root.addEventListener('
|
|
859
|
-
root.
|
|
860
|
-
|
|
867
|
+
root.addEventListener('pointermove', pointermove);
|
|
868
|
+
// Only emit pointerleave event when the pointer is not in the root area.
|
|
869
|
+
// !!!DO NOT USE pointerout event, it will emit when the pointer is in the child area.
|
|
870
|
+
root.addEventListener('pointerleave', pointerleave);
|
|
861
871
|
}
|
|
862
872
|
};
|
|
863
873
|
|
|
864
874
|
const removeEventListeners = () => {
|
|
865
875
|
if (!disableNative) {
|
|
866
|
-
root.removeEventListener('
|
|
867
|
-
root.removeEventListener('
|
|
868
|
-
root.removeEventListener('pointerout', pointerout);
|
|
876
|
+
root.removeEventListener('pointermove', pointermove);
|
|
877
|
+
root.removeEventListener('pointerleave', pointerleave);
|
|
869
878
|
}
|
|
870
879
|
};
|
|
871
880
|
|
|
@@ -875,7 +884,7 @@ export function tooltip(
|
|
|
875
884
|
if (!element) return;
|
|
876
885
|
const bbox = element.getBBox();
|
|
877
886
|
const { x, y, width, height } = bbox;
|
|
878
|
-
|
|
887
|
+
pointermove({
|
|
879
888
|
target: element,
|
|
880
889
|
offsetX: x + width / 2,
|
|
881
890
|
offsetY: y + height / 2,
|
package/src/interaction/utils.ts
CHANGED
|
@@ -433,7 +433,7 @@ export function renderBackground({
|
|
|
433
433
|
const shapeOf = isOrdinalShape() ? bandShapeOf : cloneShapeOf;
|
|
434
434
|
const shape = shapeOf(element, finalStyle);
|
|
435
435
|
shape.className = BACKGROUND_CLASS_NAME;
|
|
436
|
-
element.parentNode.appendChild(shape);
|
|
436
|
+
element.parentNode.parentNode.appendChild(shape);
|
|
437
437
|
element.background = shape;
|
|
438
438
|
};
|
|
439
439
|
|
package/src/mark/liquid.ts
CHANGED
|
@@ -64,7 +64,11 @@ export const Liquid: CC<LiquidOptions> = (options) => {
|
|
|
64
64
|
|
|
65
65
|
const newData = [{ percent, type: 'liquid' }];
|
|
66
66
|
|
|
67
|
-
const
|
|
67
|
+
const contentStyle = {
|
|
68
|
+
...subObject(style, 'text'),
|
|
69
|
+
...subObject(style, 'content'),
|
|
70
|
+
};
|
|
71
|
+
|
|
68
72
|
const outline = subObject(style, 'outline');
|
|
69
73
|
const wave = subObject(style, 'wave');
|
|
70
74
|
const background = subObject(style, 'background');
|
|
@@ -91,7 +95,7 @@ export const Liquid: CC<LiquidOptions> = (options) => {
|
|
|
91
95
|
deepMix({}, DEFAULT_TEXT_OPTIONS, {
|
|
92
96
|
style: {
|
|
93
97
|
text: `${prettyNumber(percent * 100)} %`,
|
|
94
|
-
...
|
|
98
|
+
...contentStyle,
|
|
95
99
|
},
|
|
96
100
|
animate,
|
|
97
101
|
}),
|
package/src/mark/rangeX.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MarkComponent as MC } from '../runtime';
|
|
2
2
|
import { RangeXMark } from '../spec';
|
|
3
3
|
import { RangeShape } from '../shape';
|
|
4
|
+
import { MaybeDefaultX } from '../transform';
|
|
4
5
|
import {
|
|
5
6
|
baseAnnotationChannels,
|
|
6
7
|
basePostInference,
|
|
@@ -27,6 +28,6 @@ RangeX.props = {
|
|
|
27
28
|
...baseAnnotationChannels({ shapes: Object.keys(shape) }),
|
|
28
29
|
{ name: 'x', required: true },
|
|
29
30
|
],
|
|
30
|
-
preInference: [...basePreInference()],
|
|
31
|
+
preInference: [...basePreInference(), { type: MaybeDefaultX }],
|
|
31
32
|
postInference: [...basePostInference()],
|
|
32
33
|
};
|
package/src/mark/rangeY.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MarkComponent as MC } from '../runtime';
|
|
2
2
|
import { RangeYMark } from '../spec';
|
|
3
3
|
import { RangeShape } from '../shape';
|
|
4
|
+
import { MaybeDefaultY } from '../transform';
|
|
4
5
|
import {
|
|
5
6
|
baseAnnotationChannels,
|
|
6
7
|
basePostInference,
|
|
@@ -27,6 +28,6 @@ RangeY.props = {
|
|
|
27
28
|
...baseAnnotationChannels({ shapes: Object.keys(shape) }),
|
|
28
29
|
{ name: 'y', required: true },
|
|
29
30
|
],
|
|
30
|
-
preInference: [...basePreInference()],
|
|
31
|
+
preInference: [...basePreInference(), { type: MaybeDefaultY }],
|
|
31
32
|
postInference: [...basePostInference()],
|
|
32
33
|
};
|
package/src/runtime/component.ts
CHANGED
|
@@ -876,7 +876,7 @@ function computeCategoryLegendSize(
|
|
|
876
876
|
const titleHeight = titleBBox ? titleBBox.height : 0;
|
|
877
877
|
const maxHeight = crossSize - titleHeight;
|
|
878
878
|
for (const { width } of labelBBoxes) {
|
|
879
|
-
const w = widthOf(width);
|
|
879
|
+
const w = widthOf(width, colPadding);
|
|
880
880
|
maxSize = Math.max(maxSize, w);
|
|
881
881
|
if (pos + height > maxHeight) {
|
|
882
882
|
cols++;
|
package/src/runtime/plot.ts
CHANGED
package/src/spec/interaction.ts
CHANGED
|
@@ -181,7 +181,7 @@ export type TooltipInteraction = {
|
|
|
181
181
|
bounding?: BBox;
|
|
182
182
|
mount?: string | HTMLElement;
|
|
183
183
|
css?: Record<string, any>; // @todo
|
|
184
|
-
|
|
184
|
+
enterable?: boolean;
|
|
185
185
|
sort?: (d: TooltipItemValue) => any;
|
|
186
186
|
filter?: (d: TooltipItemValue) => any;
|
|
187
187
|
render?: (
|
package/src/spec/transform.ts
CHANGED
package/src/transform/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ export { MaybeTupleY } from './maybeTupleY';
|
|
|
11
11
|
export { MaybeTupleX } from './maybeTupleX';
|
|
12
12
|
export { MaybeIdentityY } from './maybeIdentityY';
|
|
13
13
|
export { MaybeIdentityX } from './maybeIdentityX';
|
|
14
|
+
export { MaybeDefaultX } from './maybeDefaultX';
|
|
15
|
+
export { MaybeDefaultY } from './maybeDefaultY';
|
|
14
16
|
export { MaybeTooltip } from './maybeTooltip';
|
|
15
17
|
export { MaybeZeroPadding } from './maybeZeroPadding';
|
|
16
18
|
export { MaybeVisualPosition } from './maybeVisualPosition';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { deepMix } from '@antv/util';
|
|
2
|
+
import { TransformComponent as TC } from '../runtime';
|
|
3
|
+
import { column, isObject } from './utils/helper';
|
|
4
|
+
|
|
5
|
+
export type MaybeDefaultXOptions = Record<string, never>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add a default encode for rangeX
|
|
9
|
+
* when data is just an array
|
|
10
|
+
*/
|
|
11
|
+
export const MaybeDefaultX: TC<MaybeDefaultXOptions> = () => {
|
|
12
|
+
return (I, mark) => {
|
|
13
|
+
const { data } = mark;
|
|
14
|
+
if (
|
|
15
|
+
Array.isArray(data) &&
|
|
16
|
+
(data.every(Array.isArray) || !data.some(isObject))
|
|
17
|
+
) {
|
|
18
|
+
const extractX = (data, index: number) =>
|
|
19
|
+
Array.isArray(data[0])
|
|
20
|
+
? data.map((item) => item[index])
|
|
21
|
+
: [data[index]];
|
|
22
|
+
return [
|
|
23
|
+
I,
|
|
24
|
+
deepMix({}, mark, {
|
|
25
|
+
encode: {
|
|
26
|
+
x: column(extractX(data, 0)),
|
|
27
|
+
x1: column(extractX(data, 1)),
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
return [I, mark];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
MaybeDefaultX.props = {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { deepMix } from '@antv/util';
|
|
2
|
+
import { Primitive, TransformComponent as TC } from '../runtime';
|
|
3
|
+
import { column, isObject } from './utils/helper';
|
|
4
|
+
|
|
5
|
+
export type MaybeDefaultYOptions = Record<string, never>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Add a default encode for rangeY
|
|
9
|
+
* when data is just an array
|
|
10
|
+
*/
|
|
11
|
+
export const MaybeDefaultY: TC<MaybeDefaultYOptions> = () => {
|
|
12
|
+
return (I, mark) => {
|
|
13
|
+
const { data } = mark;
|
|
14
|
+
if (
|
|
15
|
+
Array.isArray(data) &&
|
|
16
|
+
(data.every(Array.isArray) || !data.some(isObject))
|
|
17
|
+
) {
|
|
18
|
+
const extractY = (data, index: number) =>
|
|
19
|
+
Array.isArray(data[0])
|
|
20
|
+
? data.map((item) => item[index])
|
|
21
|
+
: [data[index]];
|
|
22
|
+
return [
|
|
23
|
+
I,
|
|
24
|
+
deepMix({}, mark, {
|
|
25
|
+
encode: {
|
|
26
|
+
y: column(extractY(data, 0)),
|
|
27
|
+
y1: column(extractY(data, 1)),
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
return [I, mark];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
MaybeDefaultY.props = {};
|
package/src/transform/pack.ts
CHANGED
|
@@ -1,58 +1,64 @@
|
|
|
1
1
|
import { deepMix } from '@antv/util';
|
|
2
2
|
import { TransformComponent as TC } from '../runtime';
|
|
3
3
|
import { calcBBox } from '../utils/vector';
|
|
4
|
+
import { PackTransform } from '../spec';
|
|
4
5
|
|
|
5
|
-
export type PackOptions =
|
|
6
|
+
export type PackOptions = Omit<PackTransform, 'type'>;
|
|
6
7
|
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
function pack(options: PackOptions) {
|
|
9
|
+
const { padding = 0, direction = 'col' } = options;
|
|
10
|
+
return (P, count, layout) => {
|
|
11
|
+
const pcount = P.length;
|
|
12
|
+
if (pcount === 0) return [];
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// col * row >= count
|
|
15
|
+
// row is close to col * aspect, so
|
|
16
|
+
// col * (col * aspect) >= count
|
|
17
|
+
const { innerWidth, innerHeight } = layout;
|
|
18
|
+
const aspect = innerHeight / innerWidth;
|
|
19
|
+
let col = Math.ceil(Math.sqrt(count / aspect));
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
// Increase col to avoid total height of packed shape
|
|
22
|
+
// being large than height of bbox.
|
|
23
|
+
let size = innerWidth / col;
|
|
24
|
+
let row = Math.ceil(count / col);
|
|
25
|
+
let h0 = row * size;
|
|
26
|
+
while (h0 > innerHeight) {
|
|
27
|
+
col = col + 1;
|
|
28
|
+
size = innerWidth / col;
|
|
29
|
+
row = Math.ceil(count / col);
|
|
30
|
+
h0 = row * size;
|
|
31
|
+
}
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
// Some offset to increase the space usage.
|
|
34
|
+
const space = innerHeight - row * size;
|
|
35
|
+
const intervalY = row <= 1 ? 0 : space / (row - 1);
|
|
36
|
+
const [offsetX, offsetY] =
|
|
37
|
+
row <= 1
|
|
38
|
+
? [
|
|
39
|
+
(innerWidth - pcount * size) / (pcount - 1),
|
|
40
|
+
(innerHeight - size) / 2,
|
|
41
|
+
]
|
|
42
|
+
: [0, 0];
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
return P.map((points, m) => {
|
|
45
|
+
const [x, y, width, height] = calcBBox(points);
|
|
46
|
+
const i = direction === 'col' ? m % col : Math.floor(m / row);
|
|
47
|
+
const j = direction === 'col' ? Math.floor(m / col) : m % row;
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
const newX = i * size;
|
|
50
|
+
const newY = (row - j - 1) * size + space;
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
const sx = (size - padding) / width;
|
|
53
|
+
const sy = (size - padding) / height;
|
|
46
54
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return `translate(${tx}, ${ty}) scale(${sx}, ${sy})`;
|
|
55
|
-
});
|
|
55
|
+
// Translate the shape and mark to make sure the center of
|
|
56
|
+
// shape is overlap before and after scale transformation.
|
|
57
|
+
const tx = newX - x + offsetX * i + (1 / 2) * padding;
|
|
58
|
+
const ty = newY - y - intervalY * j - offsetY + (1 / 2) * padding;
|
|
59
|
+
return `translate(${tx}, ${ty}) scale(${sx}, ${sy})`;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
/**
|
|
@@ -60,9 +66,9 @@ function modifier(P, count, layout) {
|
|
|
60
66
|
* @todo Improve or change algorithm to increase space usage.
|
|
61
67
|
* @todo Take some special case into account.
|
|
62
68
|
*/
|
|
63
|
-
export const Pack: TC<PackOptions> = () => {
|
|
69
|
+
export const Pack: TC<PackOptions> = (options) => {
|
|
64
70
|
return (I, mark) => {
|
|
65
|
-
return [I, deepMix({}, mark, { modifier, axis: false })];
|
|
71
|
+
return [I, deepMix({}, mark, { modifier: pack(options), axis: false })];
|
|
66
72
|
};
|
|
67
73
|
};
|
|
68
74
|
|