@antv/g2 5.3.4 → 5.3.5-beta.0
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 +11 -11
- package/dist/g2.min.js +11 -11
- package/esm/api/runtime.js +3 -0
- package/esm/api/runtime.js.map +1 -1
- package/esm/composition/geoView.js +6 -1
- package/esm/composition/geoView.js.map +1 -1
- package/esm/data/cluster.d.ts +1 -1
- package/esm/interaction/tooltip.d.ts +1 -1
- package/esm/interaction/tooltip.js +44 -5
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/shape/liquid/liquid.js +2 -1
- package/esm/shape/liquid/liquid.js.map +1 -1
- package/esm/utils/helper.d.ts +6 -0
- package/esm/utils/helper.js +13 -2
- package/esm/utils/helper.js.map +1 -1
- package/lib/api/runtime.js +3 -0
- package/lib/api/runtime.js.map +1 -1
- package/lib/composition/geoView.js +6 -1
- package/lib/composition/geoView.js.map +1 -1
- package/lib/data/cluster.d.ts +1 -1
- package/lib/interaction/tooltip.d.ts +1 -1
- package/lib/interaction/tooltip.js +42 -3
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/shape/liquid/liquid.js +2 -1
- package/lib/shape/liquid/liquid.js.map +1 -1
- package/lib/utils/helper.d.ts +6 -0
- package/lib/utils/helper.js +15 -3
- package/lib/utils/helper.js.map +1 -1
- package/package.json +26 -5
- package/src/api/runtime.ts +2 -0
- package/src/composition/geoView.ts +6 -1
- package/src/interaction/tooltip.ts +65 -6
- package/src/shape/liquid/liquid.ts +7 -1
- package/src/utils/helper.ts +14 -2
|
@@ -6,6 +6,7 @@ import { CompositionComponent as CC } from '../runtime';
|
|
|
6
6
|
import { GeoViewComposition } from '../spec';
|
|
7
7
|
|
|
8
8
|
import * as d3Projection from './d3Projection';
|
|
9
|
+
import { mergeData } from './utils';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Get projection factory from d3-projection.
|
|
@@ -154,7 +155,11 @@ export const GeoView: CC<GeoViewOptions> = () => {
|
|
|
154
155
|
// Get projection factory.
|
|
155
156
|
const { type = 'equalEarth', ...projectionOptions } = projection;
|
|
156
157
|
const createProjection = normalizeProjection(type);
|
|
157
|
-
const nodes = children
|
|
158
|
+
const nodes = children
|
|
159
|
+
.map((c) => {
|
|
160
|
+
return { ...c, data: mergeData(c.data, options.data) };
|
|
161
|
+
})
|
|
162
|
+
.map(normalizeDataSource);
|
|
158
163
|
|
|
159
164
|
// Set path generator lazily.
|
|
160
165
|
let path;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Circle, DisplayObject, IElement, Line } from '@antv/g';
|
|
2
2
|
import { sort, group, mean, bisector, minIndex } from '@antv/vendor/d3-array';
|
|
3
|
-
import { deepMix, lowerFirst, throttle } from '@antv/util';
|
|
3
|
+
import { deepMix, lowerFirst, set, throttle, last } from '@antv/util';
|
|
4
4
|
import { Tooltip as TooltipComponent } from '@antv/component';
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
defined,
|
|
7
|
+
groupNameOf,
|
|
8
|
+
subObject,
|
|
9
|
+
dataOf,
|
|
10
|
+
isHeatmap,
|
|
11
|
+
} from '../utils/helper';
|
|
7
12
|
import { isTranspose, isPolar } from '../utils/coordinate';
|
|
8
13
|
import { angle, sub, dist } from '../utils/vector';
|
|
9
14
|
import { invert } from '../utils/scale';
|
|
@@ -192,8 +197,33 @@ function showUndefined(item) {
|
|
|
192
197
|
return { ...item, value: value === undefined ? 'undefined' : value };
|
|
193
198
|
}
|
|
194
199
|
|
|
200
|
+
function heatmapItem(element) {
|
|
201
|
+
const datum = element.__data__;
|
|
202
|
+
const normalizedX = datum?.normalized?.x ?? 0;
|
|
203
|
+
|
|
204
|
+
const originalDatum = element.parentNode?.__data__;
|
|
205
|
+
const encode = originalDatum?.encode ?? {};
|
|
206
|
+
const { x = {}, y = {}, color = {} } = encode;
|
|
207
|
+
const { value: vx = [] } = x;
|
|
208
|
+
const { value: vy = [] } = y;
|
|
209
|
+
const { value: vc = [] } = color;
|
|
210
|
+
const index = Math.min(Math.round(vx.length * normalizedX), vx.length - 1);
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
title: `${vx[index]}, ${vy[index]}`,
|
|
214
|
+
items: [
|
|
215
|
+
{
|
|
216
|
+
name: color.field ?? 'value',
|
|
217
|
+
value: vc[index],
|
|
218
|
+
color: element.style?.fill || element.getAttribute?.('color') || '#000',
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
195
224
|
function singleItem(element) {
|
|
196
225
|
const { __data__: datum } = element;
|
|
226
|
+
if (isHeatmap(element)) return heatmapItem(element);
|
|
197
227
|
const { title, items = [] } = datum;
|
|
198
228
|
const newItems = items
|
|
199
229
|
.filter(defined)
|
|
@@ -235,7 +265,9 @@ function groupItems(
|
|
|
235
265
|
).filter(defined);
|
|
236
266
|
const newItems = data
|
|
237
267
|
.flatMap((datum, i) => {
|
|
238
|
-
|
|
268
|
+
// Fix: Get the corresponding element from datum instead of using index i
|
|
269
|
+
// When data and elements don't correspond one-to-one, using index will cause color errors
|
|
270
|
+
const element = datum.element || elements[i];
|
|
239
271
|
const { items = [], title } = datum;
|
|
240
272
|
const definedItems = items.filter(defined);
|
|
241
273
|
|
|
@@ -522,6 +554,23 @@ function hasSeries(markState): boolean {
|
|
|
522
554
|
);
|
|
523
555
|
}
|
|
524
556
|
|
|
557
|
+
function normalizedPosition(coordinate, position) {
|
|
558
|
+
const {
|
|
559
|
+
innerWidth,
|
|
560
|
+
innerHeight,
|
|
561
|
+
marginLeft,
|
|
562
|
+
paddingLeft,
|
|
563
|
+
insetLeft,
|
|
564
|
+
marginTop,
|
|
565
|
+
paddingTop,
|
|
566
|
+
insetTop,
|
|
567
|
+
} = coordinate.getOptions();
|
|
568
|
+
return {
|
|
569
|
+
x: (position.x - marginLeft - paddingLeft - insetLeft) / innerWidth,
|
|
570
|
+
y: (position.y - marginTop - paddingTop - insetTop) / innerHeight,
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
|
|
525
574
|
/**
|
|
526
575
|
* Finds a single element based on the mouse event in a non-series context (e.g., single item tooltip).
|
|
527
576
|
* @param root - The root display object of the chart.
|
|
@@ -539,7 +588,7 @@ function hasSeries(markState): boolean {
|
|
|
539
588
|
export function findSingleElement({
|
|
540
589
|
root,
|
|
541
590
|
event,
|
|
542
|
-
elements,
|
|
591
|
+
elements = [],
|
|
543
592
|
coordinate,
|
|
544
593
|
scale,
|
|
545
594
|
shared,
|
|
@@ -563,9 +612,19 @@ export function findSingleElement({
|
|
|
563
612
|
// Sort for bisector search.
|
|
564
613
|
if (isBar) elements.sort((a, b) => xof(a) - xof(b));
|
|
565
614
|
const findElementByTarget = (event) => {
|
|
566
|
-
const { target } = event;
|
|
615
|
+
const { target = last(elements) } = event;
|
|
567
616
|
return maybeRoot(target, (node) => {
|
|
568
617
|
if (!node.classList) return false;
|
|
618
|
+
if (isHeatmap(node)) {
|
|
619
|
+
set(
|
|
620
|
+
node,
|
|
621
|
+
'__data__.normalized',
|
|
622
|
+
normalizedPosition(coordinate, {
|
|
623
|
+
x: event.offsetX,
|
|
624
|
+
y: event.offsetY,
|
|
625
|
+
}),
|
|
626
|
+
);
|
|
627
|
+
}
|
|
569
628
|
return node.classList.includes('element');
|
|
570
629
|
});
|
|
571
630
|
};
|
|
@@ -41,6 +41,12 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
|
|
|
41
41
|
? liquidShape
|
|
42
42
|
: getLiquidShape(liquidShape);
|
|
43
43
|
const shapePath = buildPath(centerX, centerY, radius, ...size);
|
|
44
|
+
const shapeClipPath = buildPath(
|
|
45
|
+
centerX,
|
|
46
|
+
centerY,
|
|
47
|
+
radius + border / 2,
|
|
48
|
+
...size,
|
|
49
|
+
);
|
|
44
50
|
|
|
45
51
|
// 2、Background create.
|
|
46
52
|
if (Object.keys(backgroundStyle).length) {
|
|
@@ -60,7 +66,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
|
|
|
60
66
|
// 3. Clip create.
|
|
61
67
|
const clipShape = document.createElement('path', {
|
|
62
68
|
style: {
|
|
63
|
-
d:
|
|
69
|
+
d: shapeClipPath,
|
|
64
70
|
},
|
|
65
71
|
});
|
|
66
72
|
|
package/src/utils/helper.ts
CHANGED
|
@@ -17,6 +17,16 @@ export function getViewFromElement(element: G2Element) {
|
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @description Check if the element is a heatmap.
|
|
22
|
+
* @param element G2 element.
|
|
23
|
+
* @returns True if the element is a heatmap, otherwise false.
|
|
24
|
+
*/
|
|
25
|
+
export function isHeatmap(element) {
|
|
26
|
+
const { markType, nodeName } = element;
|
|
27
|
+
return markType === 'heatmap' && nodeName === 'image';
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
31
|
* @description Get element's original data.
|
|
22
32
|
* @param elemenet G2 element.
|
|
@@ -26,7 +36,7 @@ export function getViewFromElement(element: G2Element) {
|
|
|
26
36
|
export function dataOf(element: G2Element, viewData?: any) {
|
|
27
37
|
const view = viewData ?? getViewFromElement(element).__data__;
|
|
28
38
|
const datum = element.__data__;
|
|
29
|
-
const { markKey, index, seriesIndex } = datum;
|
|
39
|
+
const { markKey, index, seriesIndex, normalized = { x: 0 } } = datum;
|
|
30
40
|
const { markState } = view;
|
|
31
41
|
const selectedMark: any = Array.from(markState.keys()).find(
|
|
32
42
|
(mark) => (mark as any).key === markKey,
|
|
@@ -35,7 +45,9 @@ export function dataOf(element: G2Element, viewData?: any) {
|
|
|
35
45
|
if (seriesIndex) {
|
|
36
46
|
return seriesIndex.map((i) => selectedMark.data[i]);
|
|
37
47
|
}
|
|
38
|
-
return
|
|
48
|
+
return isHeatmap(element)
|
|
49
|
+
? selectedMark.data[Math.round(selectedMark.data.length * normalized.x)]
|
|
50
|
+
: selectedMark.data[index];
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
/**
|