@antv/g2 5.2.11 → 5.2.12
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 +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/g2.lite.min.js +22 -22
- package/dist/g2.min.js +22 -22
- package/esm/animation/scaleInY.js +2 -20
- package/esm/animation/scaleInY.js.map +1 -1
- package/esm/api/runtime.js +2 -0
- package/esm/api/runtime.js.map +1 -1
- package/esm/component/legendCategory.js +5 -1
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/data/utils/arc/arc.d.ts +25 -2
- package/esm/data/utils/arc/arc.js.map +1 -1
- package/esm/data/utils/arc/types.d.ts +27 -2
- package/esm/exports.d.ts +2 -0
- package/esm/exports.js +2 -0
- package/esm/exports.js.map +1 -1
- package/esm/interaction/elementSelect.d.ts +1 -0
- package/esm/interaction/elementSelect.js +31 -2
- package/esm/interaction/elementSelect.js.map +1 -1
- package/esm/interaction/event.d.ts +0 -1
- package/esm/interaction/event.js +2 -13
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/legendHighlight.js.map +1 -1
- package/esm/interaction/tooltip.js +7 -34
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/runtime/layout.js +1 -1
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/transform.d.ts +1 -0
- package/esm/runtime/transform.js +2 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/spec/interaction.d.ts +1 -0
- package/esm/transform/bin.js.map +1 -1
- package/esm/transform/sort.js +19 -51
- package/esm/transform/sort.js.map +1 -1
- package/esm/utils/helper.d.ts +24 -0
- package/esm/utils/helper.js +76 -0
- package/esm/utils/helper.js.map +1 -1
- package/lib/animation/scaleInY.js +1 -19
- package/lib/animation/scaleInY.js.map +1 -1
- package/lib/api/runtime.js +2 -0
- package/lib/api/runtime.js.map +1 -1
- package/lib/component/legendCategory.js +5 -1
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/data/utils/arc/arc.d.ts +25 -2
- package/lib/data/utils/arc/arc.js.map +1 -1
- package/lib/data/utils/arc/types.d.ts +27 -2
- package/lib/exports.d.ts +2 -0
- package/lib/exports.js +7 -1
- package/lib/exports.js.map +1 -1
- package/lib/interaction/elementSelect.d.ts +1 -0
- package/lib/interaction/elementSelect.js +31 -2
- package/lib/interaction/elementSelect.js.map +1 -1
- package/lib/interaction/event.d.ts +0 -1
- package/lib/interaction/event.js +3 -15
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/legendHighlight.js.map +1 -1
- package/lib/interaction/tooltip.js +9 -36
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/transform.d.ts +1 -0
- package/lib/runtime/transform.js +3 -2
- package/lib/runtime/transform.js.map +1 -1
- package/lib/spec/interaction.d.ts +1 -0
- package/lib/transform/bin.js.map +1 -1
- package/lib/transform/sort.js +19 -51
- package/lib/transform/sort.js.map +1 -1
- package/lib/utils/helper.d.ts +24 -0
- package/lib/utils/helper.js +81 -1
- package/lib/utils/helper.js.map +1 -1
- package/package.json +3 -3
- package/src/animation/scaleInY.ts +2 -45
- package/src/api/runtime.ts +3 -0
- package/src/component/legendCategory.ts +9 -1
- package/src/data/utils/arc/arc.ts +5 -5
- package/src/data/utils/arc/types.ts +28 -2
- package/src/exports.ts +3 -0
- package/src/interaction/elementSelect.ts +32 -2
- package/src/interaction/event.ts +2 -15
- package/src/interaction/legendHighlight.ts +4 -2
- package/src/interaction/tooltip.ts +9 -38
- package/src/runtime/layout.ts +15 -2
- package/src/runtime/transform.ts +4 -1
- package/src/spec/interaction.ts +1 -0
- package/src/transform/bin.ts +2 -2
- package/src/transform/sort.ts +20 -42
- package/src/utils/helper.ts +83 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.js","sourceRoot":"src/","sources":["transform/sort.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sort.js","sourceRoot":"src/","sources":["transform/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,CAAC,KAAK,GAAG,EAAE,CAAC"}
|
package/lib/utils/helper.d.ts
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { Base } from '@antv/scale';
|
|
3
|
+
import { G2Element } from './selection';
|
|
4
|
+
/**
|
|
5
|
+
* @description Get element's ancestor view node.
|
|
6
|
+
* @param elemenet G2 element.
|
|
7
|
+
* @returns Element's ancestor view node.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getViewFromElement(element: G2Element): G2Element;
|
|
10
|
+
/**
|
|
11
|
+
* @description Get element's original data.
|
|
12
|
+
* @param elemenet G2 element.
|
|
13
|
+
* @returns The original data of the element.
|
|
14
|
+
*/
|
|
15
|
+
export declare function dataOf(element: G2Element): any;
|
|
16
|
+
/**
|
|
17
|
+
* @description Get element's series name.
|
|
18
|
+
* @param elemenet G2 element.
|
|
19
|
+
* @returns The series name of the element.
|
|
20
|
+
*/
|
|
21
|
+
export declare function seriesOf(elemenet: G2Element): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get group name with view's scale and element's datum.
|
|
24
|
+
*/
|
|
25
|
+
export declare function groupNameOf(scale: Record<string, Base<any>>, datum: any): any;
|
|
2
26
|
export declare function identity<T>(x: T): T;
|
|
3
27
|
type Func<R> = (x: R, ...args: any[]) => R;
|
|
4
28
|
/**
|
package/lib/utils/helper.js
CHANGED
|
@@ -9,8 +9,88 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.deepAssign = exports.isUnset = exports.isStrictObject = exports.maybePercentage = exports.omitPrefixObject = exports.filterPrefixObject = exports.prefixObject = exports.maybeSubObject = exports.subObject = exports.appendTransform = exports.useMemo = exports.random = exports.defined = exports.copyAttributes = exports.error = exports.capitalizeFirst = exports.composeAsync = exports.compose = exports.identity = void 0;
|
|
12
|
+
exports.deepAssign = exports.isUnset = exports.isStrictObject = exports.maybePercentage = exports.omitPrefixObject = exports.filterPrefixObject = exports.prefixObject = exports.maybeSubObject = exports.subObject = exports.appendTransform = exports.useMemo = exports.random = exports.defined = exports.copyAttributes = exports.error = exports.capitalizeFirst = exports.composeAsync = exports.compose = exports.identity = exports.groupNameOf = exports.seriesOf = exports.dataOf = exports.getViewFromElement = void 0;
|
|
13
13
|
const util_1 = require("@antv/util");
|
|
14
|
+
const scale_1 = require("@antv/scale");
|
|
15
|
+
/**
|
|
16
|
+
* @description Get element's ancestor view node.
|
|
17
|
+
* @param elemenet G2 element.
|
|
18
|
+
* @returns Element's ancestor view node.
|
|
19
|
+
*/
|
|
20
|
+
function getViewFromElement(element) {
|
|
21
|
+
var _a;
|
|
22
|
+
let current = element;
|
|
23
|
+
while (current) {
|
|
24
|
+
if (((_a = current.attributes) === null || _a === void 0 ? void 0 : _a.class) === 'view')
|
|
25
|
+
return current;
|
|
26
|
+
current = current.parentNode;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
exports.getViewFromElement = getViewFromElement;
|
|
31
|
+
/**
|
|
32
|
+
* @description Get element's original data.
|
|
33
|
+
* @param elemenet G2 element.
|
|
34
|
+
* @returns The original data of the element.
|
|
35
|
+
*/
|
|
36
|
+
function dataOf(element) {
|
|
37
|
+
const view = getViewFromElement(element);
|
|
38
|
+
const datum = element.__data__;
|
|
39
|
+
const { markKey, index, seriesIndex } = datum;
|
|
40
|
+
const { markState } = view.__data__;
|
|
41
|
+
const selectedMark = Array.from(markState.keys()).find((mark) => mark.key === markKey);
|
|
42
|
+
if (!selectedMark)
|
|
43
|
+
return;
|
|
44
|
+
if (seriesIndex) {
|
|
45
|
+
return seriesIndex.map((i) => selectedMark.data[i]);
|
|
46
|
+
}
|
|
47
|
+
return selectedMark.data[index];
|
|
48
|
+
}
|
|
49
|
+
exports.dataOf = dataOf;
|
|
50
|
+
/**
|
|
51
|
+
* @description Get element's series name.
|
|
52
|
+
* @param elemenet G2 element.
|
|
53
|
+
* @returns The series name of the element.
|
|
54
|
+
*/
|
|
55
|
+
function seriesOf(elemenet) {
|
|
56
|
+
const viewData = getViewFromElement(elemenet).__data__;
|
|
57
|
+
const { scale } = viewData;
|
|
58
|
+
return groupNameOf(scale, elemenet.__data__);
|
|
59
|
+
}
|
|
60
|
+
exports.seriesOf = seriesOf;
|
|
61
|
+
/**
|
|
62
|
+
* Get group name with view's scale and element's datum.
|
|
63
|
+
*/
|
|
64
|
+
function groupNameOf(scale, datum) {
|
|
65
|
+
const { color: scaleColor, series: scaleSeries, facet = false } = scale;
|
|
66
|
+
const { color, series } = datum;
|
|
67
|
+
const invertAble = (scale) => {
|
|
68
|
+
return (scale &&
|
|
69
|
+
scale.invert &&
|
|
70
|
+
!(scale instanceof scale_1.Band) &&
|
|
71
|
+
!(scale instanceof scale_1.Constant));
|
|
72
|
+
};
|
|
73
|
+
// For non constant color channel.
|
|
74
|
+
if (invertAble(scaleSeries)) {
|
|
75
|
+
const cloned = scaleSeries.clone();
|
|
76
|
+
return cloned.invert(series);
|
|
77
|
+
}
|
|
78
|
+
if (series &&
|
|
79
|
+
scaleSeries instanceof scale_1.Band &&
|
|
80
|
+
scaleSeries.invert(series) !== color &&
|
|
81
|
+
!facet) {
|
|
82
|
+
return scaleSeries.invert(series);
|
|
83
|
+
}
|
|
84
|
+
if (invertAble(scaleColor)) {
|
|
85
|
+
const name = scaleColor.invert(color);
|
|
86
|
+
// For threshold scale.
|
|
87
|
+
if (Array.isArray(name))
|
|
88
|
+
return null;
|
|
89
|
+
return name;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
exports.groupNameOf = groupNameOf;
|
|
14
94
|
function identity(x) {
|
|
15
95
|
return x;
|
|
16
96
|
}
|
package/lib/utils/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"src/","sources":["utils/helper.ts"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V,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAClB,CAAC;AACJ,CAAC;AAPD,wCAOC;AAED,SAAgB,OAAO,CAAC,KAAK;IAC3B,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,CAAC;AAC3C,CAAC;AAFD,0BAEC;AAED,SAAgB,UAAU,CACxB,IAA6B,EAC7B,GAA4B,EAC5B,QAAQ,GAAG,CAAC,EACZ,KAAK,GAAG,CAAC;IAET,IAAI,KAAK,IAAI,QAAQ;QAAE,OAAO;IAC9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAClC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,IAAA,oBAAa,EAAC,KAAK,CAAC,IAAI,CAAC,IAAA,oBAAa,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;YACtD,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SACnB;aAAM;YACL,UAAU,CACR,IAAI,CAAC,GAAG,CAA4B,EACpC,KAAgC,EAChC,QAAQ,EACR,KAAK,GAAG,CAAC,CACV,CAAC;SACH;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AArBD,gCAqBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.12",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@antv/g-plugin-dragndrop": "^2.0.22",
|
|
77
77
|
"@antv/scale": "^0.4.16",
|
|
78
78
|
"@antv/util": "^3.3.10",
|
|
79
|
-
"@antv/vendor": "1.0.
|
|
79
|
+
"@antv/vendor": "^1.0.8",
|
|
80
80
|
"flru": "^1.0.2",
|
|
81
81
|
"fmin": "0.0.2",
|
|
82
82
|
"pdfast": "^0.2.0"
|
|
@@ -165,4 +165,4 @@
|
|
|
165
165
|
"bugs": {
|
|
166
166
|
"url": "https://github.com/antvis/g2/issues"
|
|
167
167
|
}
|
|
168
|
-
}
|
|
168
|
+
}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
Path,
|
|
4
|
-
convertToPath,
|
|
5
|
-
CSS,
|
|
6
|
-
PropertySyntax,
|
|
7
|
-
DisplayObject,
|
|
8
|
-
} from '@antv/g';
|
|
1
|
+
import { CSS, PropertySyntax, DisplayObject } from '@antv/g';
|
|
9
2
|
import { G2Element } from 'utils/selection';
|
|
10
3
|
import { AnimationComponent as AC } from '../runtime';
|
|
11
4
|
import { isTranspose, isPolar } from '../utils/coordinate';
|
|
@@ -37,32 +30,10 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
|
|
|
37
30
|
const [shape] = from;
|
|
38
31
|
const PolarScaleInY = (shape: DisplayObject) => {
|
|
39
32
|
const { __data__, style } = shape as G2Element;
|
|
40
|
-
const {
|
|
41
|
-
radius = 0,
|
|
42
|
-
inset = 0,
|
|
43
|
-
fillOpacity = 1,
|
|
44
|
-
strokeOpacity = 1,
|
|
45
|
-
opacity = 1,
|
|
46
|
-
} = style;
|
|
33
|
+
const { fillOpacity = 1, strokeOpacity = 1, opacity = 1 } = style;
|
|
47
34
|
const { points, y, y1 } = __data__;
|
|
48
35
|
const arcObject = getArcObject(coordinate, points, [y, y1]);
|
|
49
36
|
const { innerRadius, outerRadius } = arcObject;
|
|
50
|
-
const path = arc()
|
|
51
|
-
.cornerRadius(radius as number)
|
|
52
|
-
.padAngle((inset * Math.PI) / 180);
|
|
53
|
-
const pathForConversion = new Path({});
|
|
54
|
-
const createArcPath = (arcParams: {
|
|
55
|
-
startAngle: number;
|
|
56
|
-
endAngle: number;
|
|
57
|
-
innerRadius: number;
|
|
58
|
-
outerRadius: number;
|
|
59
|
-
}) => {
|
|
60
|
-
pathForConversion.attr({
|
|
61
|
-
d: path(arcParams),
|
|
62
|
-
});
|
|
63
|
-
const convertedPathDefinition = convertToPath(pathForConversion);
|
|
64
|
-
return convertedPathDefinition;
|
|
65
|
-
};
|
|
66
37
|
|
|
67
38
|
const keyframes = [
|
|
68
39
|
{
|
|
@@ -87,20 +58,6 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
|
|
|
87
58
|
];
|
|
88
59
|
|
|
89
60
|
const animation = shape.animate(keyframes, { ...defaults, ...options });
|
|
90
|
-
animation.onframe = function () {
|
|
91
|
-
shape.style.d = createArcPath({
|
|
92
|
-
...arcObject,
|
|
93
|
-
outerRadius: Number(shape.style.scaleInYRadius),
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
animation.onfinish = function () {
|
|
98
|
-
shape.style.d = createArcPath({
|
|
99
|
-
...arcObject,
|
|
100
|
-
outerRadius: outerRadius,
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
|
|
104
61
|
return animation;
|
|
105
62
|
};
|
|
106
63
|
|
package/src/api/runtime.ts
CHANGED
|
@@ -75,6 +75,9 @@ export class Runtime<Spec extends G2Spec = G2Spec> extends CompositionNode {
|
|
|
75
75
|
if (!this._context.canvas) this._createCanvas();
|
|
76
76
|
this._bindAutoFit();
|
|
77
77
|
this._rendering = true;
|
|
78
|
+
|
|
79
|
+
// @fixme The cancel render is not marked, which will cause additional rendered event.
|
|
80
|
+
// @ref src/runtime/render.ts
|
|
78
81
|
const finished = new Promise<Runtime<Spec>>((resolve, reject) =>
|
|
79
82
|
render(
|
|
80
83
|
this._computedOptions(),
|
|
@@ -170,6 +170,13 @@ function inferLegendShape(
|
|
|
170
170
|
return { width, height };
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
function filterEmptyIds(legendStyle) {
|
|
174
|
+
return {
|
|
175
|
+
...legendStyle,
|
|
176
|
+
data: legendStyle?.data.filter((item) => item.id !== '') || [],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
173
180
|
/**
|
|
174
181
|
* Guide Component for ordinal color scale.
|
|
175
182
|
*/
|
|
@@ -211,8 +218,9 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
|
|
|
211
218
|
|
|
212
219
|
const { legendCategory: legendTheme = {} } = theme;
|
|
213
220
|
|
|
221
|
+
// Filter out the data items with empty string IDs in the wordCloud's data before generating the legend.
|
|
214
222
|
const categoryStyle = adaptor(
|
|
215
|
-
Object.assign({}, legendTheme, legendStyle, style),
|
|
223
|
+
Object.assign({}, legendTheme, filterEmptyIds(legendStyle), style),
|
|
216
224
|
);
|
|
217
225
|
|
|
218
226
|
const layoutWrapper = new LegendCategoryLayout({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { group, sum } from '@antv/vendor/d3-array';
|
|
2
2
|
import { error } from '../../../utils/helper';
|
|
3
|
-
import { ArcData, ArcOptions } from './types';
|
|
3
|
+
import { ArcData, ArcOptions, ArcEdge, ArcNode } from './types';
|
|
4
4
|
import * as SortMethods from './sort';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_OPTIONS = {
|
|
@@ -53,7 +53,7 @@ export function Arc(options?: ArcOptions) {
|
|
|
53
53
|
/**
|
|
54
54
|
* Calculate id, value, frequency for node, and source,target for edge.
|
|
55
55
|
*/
|
|
56
|
-
function preprocess(nodes, edges) {
|
|
56
|
+
function preprocess(nodes: ArcNode[], edges: ArcEdge[]) {
|
|
57
57
|
edges.forEach((edge) => {
|
|
58
58
|
edge.source = source(edge);
|
|
59
59
|
edge.target = target(edge);
|
|
@@ -83,7 +83,7 @@ export function Arc(options?: ArcOptions) {
|
|
|
83
83
|
return { nodes, edges };
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
function sortNodes(nodes, edges) {
|
|
86
|
+
function sortNodes(nodes: ArcNode[], edges: ArcEdge[]) {
|
|
87
87
|
const method = typeof sortBy === 'function' ? sortBy : SortMethods[sortBy];
|
|
88
88
|
|
|
89
89
|
if (method) {
|
|
@@ -91,7 +91,7 @@ export function Arc(options?: ArcOptions) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
function layoutNodes(nodes, edges) {
|
|
94
|
+
function layoutNodes(nodes: ArcNode[], edges: ArcEdge[]) {
|
|
95
95
|
const size = nodes.length;
|
|
96
96
|
if (!size) {
|
|
97
97
|
throw error("Invalid nodes: it's empty!");
|
|
@@ -145,7 +145,7 @@ export function Arc(options?: ArcOptions) {
|
|
|
145
145
|
/**
|
|
146
146
|
* Get edge layout information from nodes, and save into edge object.
|
|
147
147
|
*/
|
|
148
|
-
function layoutEdges(nodes, edges) {
|
|
148
|
+
function layoutEdges(nodes: ArcNode[], edges: ArcEdge[]) {
|
|
149
149
|
const nodesMap = new Map(nodes.map((d) => [d.id, d]));
|
|
150
150
|
|
|
151
151
|
if (!weight) {
|
|
@@ -20,8 +20,34 @@ export type ArcOptions = {
|
|
|
20
20
|
/** Thickness of node, default: 0.05 */
|
|
21
21
|
thickness?: number;
|
|
22
22
|
};
|
|
23
|
+
export interface ArcEdge {
|
|
24
|
+
source: string;
|
|
25
|
+
target: string;
|
|
26
|
+
sourceWeight: number;
|
|
27
|
+
targetWeight: number;
|
|
28
|
+
x: number[] | number;
|
|
29
|
+
y: number[] | number;
|
|
30
|
+
value: number;
|
|
31
|
+
weight?: number;
|
|
32
|
+
width?: number;
|
|
33
|
+
height?: number;
|
|
34
|
+
frequency?: number;
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ArcNode {
|
|
39
|
+
id: string;
|
|
40
|
+
x: number[] | number;
|
|
41
|
+
y: number[] | number;
|
|
42
|
+
value: number;
|
|
43
|
+
frequency: number;
|
|
44
|
+
weight?: number;
|
|
45
|
+
width?: number;
|
|
46
|
+
height?: number;
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
}
|
|
23
49
|
|
|
24
50
|
export type ArcData = {
|
|
25
|
-
nodes:
|
|
26
|
-
edges:
|
|
51
|
+
nodes: ArcNode[];
|
|
52
|
+
edges: ArcEdge[];
|
|
27
53
|
};
|
package/src/exports.ts
CHANGED
|
@@ -37,6 +37,9 @@ export type {
|
|
|
37
37
|
Channel,
|
|
38
38
|
} from './runtime';
|
|
39
39
|
export { select, Selection } from './utils/selection';
|
|
40
|
+
export { dataOf, seriesOf } from './utils/helper';
|
|
41
|
+
export { selectG2Elements, selectPlotArea } from './interaction/utils';
|
|
42
|
+
|
|
40
43
|
export * from './transform';
|
|
41
44
|
export { LinearAxis } from './component/axis';
|
|
42
45
|
export type { AxisOptions } from './component/axis';
|
|
@@ -26,6 +26,7 @@ export function elementSelect(
|
|
|
26
26
|
groupKey = (d) => d, // group elements by specified key
|
|
27
27
|
link = false, // draw link or not
|
|
28
28
|
single = false, // single select or not
|
|
29
|
+
multipleSelectHotkey, // hotkey for multi-select mode
|
|
29
30
|
coordinate,
|
|
30
31
|
background = false,
|
|
31
32
|
scale,
|
|
@@ -68,6 +69,8 @@ export function elementSelect(
|
|
|
68
69
|
});
|
|
69
70
|
|
|
70
71
|
const { setState, removeState, hasState } = useState(elementStyle, valueof);
|
|
72
|
+
let isMultiSelectMode = !single; // "single" determines whether to multi-select by default
|
|
73
|
+
let activeHotkey = null; // Track the currently active hotkey
|
|
71
74
|
|
|
72
75
|
const clear = (nativeEvent = true) => {
|
|
73
76
|
for (const e of elements) {
|
|
@@ -151,16 +154,39 @@ export function elementSelect(
|
|
|
151
154
|
// Click non-element shape, reset.
|
|
152
155
|
// Such as the rest of content area(background).
|
|
153
156
|
if (!elementSet.has(element)) return clear();
|
|
154
|
-
if (
|
|
157
|
+
if (!isMultiSelectMode) return singleSelect(event, element, nativeEvent);
|
|
155
158
|
return multipleSelect(event, element, nativeEvent);
|
|
156
159
|
};
|
|
157
160
|
|
|
161
|
+
// Handle keyboard events for multi-select mode
|
|
162
|
+
const hotkeys = Array.isArray(multipleSelectHotkey)
|
|
163
|
+
? multipleSelectHotkey
|
|
164
|
+
: [multipleSelectHotkey];
|
|
165
|
+
const handleKeyDown = (event) => {
|
|
166
|
+
if (hotkeys.includes(event.code) && !activeHotkey) {
|
|
167
|
+
activeHotkey = event.code;
|
|
168
|
+
isMultiSelectMode = true;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const handleKeyUp = (event) => {
|
|
172
|
+
if (event.code === activeHotkey) {
|
|
173
|
+
activeHotkey = null;
|
|
174
|
+
isMultiSelectMode = false;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
158
178
|
root.addEventListener('click', click);
|
|
179
|
+
if (multipleSelectHotkey) {
|
|
180
|
+
// If a hotkey is set, the initial state should be single mode
|
|
181
|
+
isMultiSelectMode = false;
|
|
182
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
183
|
+
document.addEventListener('keyup', handleKeyUp);
|
|
184
|
+
}
|
|
159
185
|
|
|
160
186
|
const onSelect = (e) => {
|
|
161
187
|
const { nativeEvent, data } = e;
|
|
162
188
|
if (nativeEvent) return;
|
|
163
|
-
const selectedData =
|
|
189
|
+
const selectedData = !isMultiSelectMode ? data.data.slice(0, 1) : data.data;
|
|
164
190
|
for (const d of selectedData) {
|
|
165
191
|
const element = selectElementByData(elements, d, datum);
|
|
166
192
|
click({ target: element, nativeEvent: false });
|
|
@@ -177,6 +203,10 @@ export function elementSelect(
|
|
|
177
203
|
return () => {
|
|
178
204
|
for (const e of elements) removeLink(e);
|
|
179
205
|
root.removeEventListener('click', click);
|
|
206
|
+
if (multipleSelectHotkey) {
|
|
207
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
208
|
+
document.removeEventListener('keyup', handleKeyUp);
|
|
209
|
+
}
|
|
180
210
|
emitter.off('element:select', onSelect);
|
|
181
211
|
emitter.off('element:unselect', onUnSelect);
|
|
182
212
|
};
|
package/src/interaction/event.ts
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { ChartEvent } from '../utils/event';
|
|
2
|
+
import { dataOf } from '../utils/helper';
|
|
2
3
|
import { maybeRoot } from './utils';
|
|
3
4
|
|
|
4
|
-
export function dataOf(element, view) {
|
|
5
|
-
const { __data__: datum } = element;
|
|
6
|
-
const { markKey, index, seriesIndex } = datum;
|
|
7
|
-
const { markState } = view;
|
|
8
|
-
const selectedMark: any = Array.from(markState.keys()).find(
|
|
9
|
-
(mark) => (mark as any).key === markKey,
|
|
10
|
-
);
|
|
11
|
-
if (!selectedMark) return;
|
|
12
|
-
if (seriesIndex) {
|
|
13
|
-
return seriesIndex.map((i) => selectedMark.data[i]);
|
|
14
|
-
}
|
|
15
|
-
return selectedMark.data[index];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
5
|
// For extended component
|
|
19
6
|
function maybeComponentRoot(node) {
|
|
20
7
|
return maybeRoot(node, (node) => node.className === 'component');
|
|
@@ -63,7 +50,7 @@ function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
|
|
|
63
50
|
nativeEvent: true,
|
|
64
51
|
};
|
|
65
52
|
if (elementType === 'element') {
|
|
66
|
-
e1['data'] = { data: dataOf(root
|
|
53
|
+
e1['data'] = { data: dataOf(root) };
|
|
67
54
|
emitter.emit(`element:${eventType}`, e1);
|
|
68
55
|
emitter.emit(`${markType}:${eventType}`, e1);
|
|
69
56
|
} else if (elementType === 'label') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { group } from '@antv/vendor/d3-array';
|
|
1
|
+
import { InternMap, group } from '@antv/vendor/d3-array';
|
|
2
2
|
import { subObject } from '../utils/helper';
|
|
3
3
|
import {
|
|
4
4
|
mergeState,
|
|
@@ -66,7 +66,9 @@ export function LegendHighlight() {
|
|
|
66
66
|
const highlightItem = (event, item) => {
|
|
67
67
|
// Update UI.
|
|
68
68
|
const value = datumOf(item);
|
|
69
|
-
const elementSet = new Set(
|
|
69
|
+
const elementSet = new Set(
|
|
70
|
+
(elementGroup as InternMap<unknown, any[]>).get(value),
|
|
71
|
+
);
|
|
70
72
|
for (const e of elements) {
|
|
71
73
|
if (elementSet.has(e)) setState(e, 'active');
|
|
72
74
|
else setState(e, 'inactive');
|
|
@@ -2,12 +2,12 @@ import { Circle, DisplayObject, IElement, Line } from '@antv/g';
|
|
|
2
2
|
import { sort, group, mean, bisector, minIndex } from '@antv/vendor/d3-array';
|
|
3
3
|
import { deepMix, lowerFirst, throttle } from '@antv/util';
|
|
4
4
|
import { Tooltip as TooltipComponent } from '@antv/component';
|
|
5
|
-
import {
|
|
6
|
-
import { defined, subObject } from '../utils/helper';
|
|
5
|
+
import { defined, groupNameOf, subObject, dataOf } from '../utils/helper';
|
|
7
6
|
import { isTranspose, isPolar } from '../utils/coordinate';
|
|
8
7
|
import { angle, sub, dist } from '../utils/vector';
|
|
9
8
|
import { invert } from '../utils/scale';
|
|
10
9
|
import { BBox } from '../runtime';
|
|
10
|
+
import { CALLBACK_ITEM_SYMBOL } from '../runtime/transform';
|
|
11
11
|
import {
|
|
12
12
|
selectG2Elements,
|
|
13
13
|
createXKey,
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
bboxOf,
|
|
20
20
|
maybeRoot,
|
|
21
21
|
} from './utils';
|
|
22
|
-
import { dataOf } from './event';
|
|
23
22
|
|
|
24
23
|
function getContainer(
|
|
25
24
|
group: IElement,
|
|
@@ -208,39 +207,6 @@ function singleItem(element) {
|
|
|
208
207
|
};
|
|
209
208
|
}
|
|
210
209
|
|
|
211
|
-
function groupNameOf(scale, datum) {
|
|
212
|
-
const { color: scaleColor, series: scaleSeries, facet = false } = scale;
|
|
213
|
-
const { color, series } = datum;
|
|
214
|
-
const invertAble = (scale) => {
|
|
215
|
-
return (
|
|
216
|
-
scale &&
|
|
217
|
-
scale.invert &&
|
|
218
|
-
!(scale instanceof Band) &&
|
|
219
|
-
!(scale instanceof Constant)
|
|
220
|
-
);
|
|
221
|
-
};
|
|
222
|
-
// For non constant color channel.
|
|
223
|
-
if (invertAble(scaleSeries)) {
|
|
224
|
-
const cloned = scaleSeries.clone();
|
|
225
|
-
return cloned.invert(series);
|
|
226
|
-
}
|
|
227
|
-
if (
|
|
228
|
-
series &&
|
|
229
|
-
scaleSeries instanceof Band &&
|
|
230
|
-
scaleSeries.invert(series) !== color &&
|
|
231
|
-
!facet
|
|
232
|
-
) {
|
|
233
|
-
return scaleSeries.invert(series);
|
|
234
|
-
}
|
|
235
|
-
if (invertAble(scaleColor)) {
|
|
236
|
-
const name = scaleColor.invert(color);
|
|
237
|
-
// For threshold scale.
|
|
238
|
-
if (Array.isArray(name)) return null;
|
|
239
|
-
return name;
|
|
240
|
-
}
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
210
|
function itemColorOf(element) {
|
|
245
211
|
const fill = element.getAttribute('fill');
|
|
246
212
|
const stroke = element.getAttribute('stroke');
|
|
@@ -279,7 +245,12 @@ function groupItems(
|
|
|
279
245
|
return definedItems.map(
|
|
280
246
|
({ color = itemColorOf(element) || theme.color, name, ...item }) => {
|
|
281
247
|
const groupName = groupNameOf(scale, datum);
|
|
282
|
-
|
|
248
|
+
// callback's priority is higher than groupName.
|
|
249
|
+
const name1 =
|
|
250
|
+
useGroupName && !(CALLBACK_ITEM_SYMBOL in item)
|
|
251
|
+
? groupName || name
|
|
252
|
+
: name || groupName;
|
|
253
|
+
|
|
283
254
|
return {
|
|
284
255
|
...item,
|
|
285
256
|
color,
|
|
@@ -1097,7 +1068,7 @@ export function tooltip(
|
|
|
1097
1068
|
nativeEvent: true,
|
|
1098
1069
|
data: {
|
|
1099
1070
|
...data,
|
|
1100
|
-
data: dataOf(element
|
|
1071
|
+
data: dataOf(element),
|
|
1101
1072
|
},
|
|
1102
1073
|
});
|
|
1103
1074
|
},
|
package/src/runtime/layout.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { Coordinate } from '@antv/coord';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
NestedInternMap,
|
|
4
|
+
ascending,
|
|
5
|
+
group,
|
|
6
|
+
max,
|
|
7
|
+
min,
|
|
8
|
+
sum,
|
|
9
|
+
} from '@antv/vendor/d3-array';
|
|
3
10
|
import { deepMix } from '@antv/util';
|
|
4
11
|
import { isParallel, isPolar, isRadar, radiusOf } from '../utils/coordinate';
|
|
5
12
|
import { capitalizeFirst, defined } from '../utils/helper';
|
|
@@ -389,10 +396,16 @@ export function placeComponents(
|
|
|
389
396
|
layout: Layout,
|
|
390
397
|
): void {
|
|
391
398
|
// Group components by plane & position.
|
|
392
|
-
|
|
399
|
+
|
|
400
|
+
const positionComponents: NestedInternMap<
|
|
401
|
+
G2GuideComponentOptions,
|
|
402
|
+
G2GuideComponentOptions[],
|
|
403
|
+
[string]
|
|
404
|
+
> = group<G2GuideComponentOptions, [string]>(
|
|
393
405
|
components,
|
|
394
406
|
(d) => `${d.plane || 'xy'}-${d.position}`,
|
|
395
407
|
);
|
|
408
|
+
|
|
396
409
|
const {
|
|
397
410
|
paddingLeft,
|
|
398
411
|
paddingRight,
|
package/src/runtime/transform.ts
CHANGED
|
@@ -15,6 +15,8 @@ import { Data, DataComponent } from './types/data';
|
|
|
15
15
|
import { G2Mark, G2DataOptions, G2Context } from './types/options';
|
|
16
16
|
import { isPosition } from './scale';
|
|
17
17
|
|
|
18
|
+
export const CALLBACK_ITEM_SYMBOL = Symbol('CALLBACK_ITEM');
|
|
19
|
+
|
|
18
20
|
// @todo Add more defaults.
|
|
19
21
|
export function applyDefaults(
|
|
20
22
|
I: number[],
|
|
@@ -192,7 +194,8 @@ export function extractTooltip(
|
|
|
192
194
|
const values = [];
|
|
193
195
|
for (const i of I) {
|
|
194
196
|
const v = item(data[i], i, data, encode);
|
|
195
|
-
if (isStrictObject(v))
|
|
197
|
+
if (isStrictObject(v))
|
|
198
|
+
values[i] = { ...v, [CALLBACK_ITEM_SYMBOL]: true };
|
|
196
199
|
else values[i] = { value: v };
|
|
197
200
|
}
|
|
198
201
|
return values;
|
package/src/spec/interaction.ts
CHANGED
|
@@ -107,6 +107,7 @@ export type ElementSelectInteraction = {
|
|
|
107
107
|
single?: boolean;
|
|
108
108
|
background?: boolean;
|
|
109
109
|
offset?: number;
|
|
110
|
+
multipleSelectHotkey?: string;
|
|
110
111
|
} & Record<`${'link' | 'background'}${any}`, any>;
|
|
111
112
|
|
|
112
113
|
export type ElementSelectByColorInteraction = {
|