@antv/g2 5.1.4 → 5.1.5
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/CHANGELOG.md +436 -0
- package/dist/g2.full.min.js +1 -0
- package/dist/g2.lite.min.js +1 -0
- package/dist/g2.min.js +1 -1
- package/esm/api/chart.d.ts +2 -163
- package/esm/api/library.d.ts +1 -162
- package/esm/api/library.js +1 -2
- package/esm/api/library.js.map +1 -1
- package/esm/api/runtime.d.ts +1 -1
- package/esm/api/runtime.js +6 -1
- package/esm/api/runtime.js.map +1 -1
- package/esm/api/utils.d.ts +1 -0
- package/esm/api/utils.js +25 -6
- package/esm/api/utils.js.map +1 -1
- package/esm/composition/repeatMatrix.js +4 -1
- package/esm/composition/repeatMatrix.js.map +1 -1
- package/esm/exports.d.ts +5 -0
- package/esm/exports.js +7 -0
- package/esm/exports.js.map +1 -0
- package/esm/index.d.ts +338 -7
- package/esm/index.js +9 -8
- package/esm/index.js.map +1 -1
- package/esm/interaction/fisheye.js +3 -1
- package/esm/interaction/fisheye.js.map +1 -1
- package/esm/interaction/legendFilter.d.ts +1 -1
- package/esm/interaction/legendFilter.js +72 -31
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +2 -2
- package/esm/interaction/tooltip.js +37 -21
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/lib/auto.d.ts +3 -0
- package/esm/lib/auto.js +7 -0
- package/esm/lib/auto.js.map +1 -0
- 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/index.d.ts +1 -0
- package/esm/lib/index.js +1 -0
- package/esm/lib/index.js.map +1 -1
- package/esm/lib/std.d.ts +30 -29
- package/esm/mark/auto.d.ts +1 -0
- package/esm/mark/auto.js +26 -0
- package/esm/mark/auto.js.map +1 -0
- package/esm/mark/index.d.ts +1 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/runtime/plot.js +11 -4
- package/esm/runtime/plot.js.map +1 -1
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/connector/connector.js.map +1 -1
- package/esm/shape/index.d.ts +1 -1
- package/esm/spec/index.d.ts +3 -3
- package/esm/spec/mark.d.ts +4 -2
- package/esm/theme/academy.js +30 -358
- package/esm/theme/academy.js.map +1 -1
- package/esm/theme/classic.js +4 -433
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +3 -404
- package/esm/theme/classicDark.js.map +1 -1
- package/esm/theme/create.d.ts +437 -0
- package/esm/theme/create.js +421 -0
- package/esm/theme/create.js.map +1 -0
- package/esm/theme/dark.d.ts +3 -0
- package/esm/theme/dark.js +76 -0
- package/esm/theme/dark.js.map +1 -0
- package/esm/theme/index.d.ts +1 -0
- package/esm/theme/index.js +1 -0
- package/esm/theme/index.js.map +1 -1
- package/esm/theme/light.js +52 -470
- package/esm/theme/light.js.map +1 -1
- package/esm/utils/event.d.ts +31 -32
- package/esm/utils/event.js +2 -12
- package/esm/utils/event.js.map +1 -1
- package/lib/api/chart.d.ts +2 -163
- package/lib/api/library.d.ts +1 -162
- package/lib/api/library.js +1 -2
- package/lib/api/library.js.map +1 -1
- package/lib/api/runtime.d.ts +1 -1
- package/lib/api/runtime.js +6 -1
- package/lib/api/runtime.js.map +1 -1
- package/lib/api/utils.d.ts +1 -0
- package/lib/api/utils.js +26 -7
- package/lib/api/utils.js.map +1 -1
- package/lib/composition/repeatMatrix.js +4 -1
- package/lib/composition/repeatMatrix.js.map +1 -1
- package/lib/exports.d.ts +5 -0
- package/lib/exports.js +39 -0
- package/lib/exports.js.map +1 -0
- package/lib/index.d.ts +338 -7
- package/lib/index.js +11 -28
- package/lib/index.js.map +1 -1
- package/lib/interaction/fisheye.js +3 -1
- package/lib/interaction/fisheye.js.map +1 -1
- package/lib/interaction/legendFilter.d.ts +1 -1
- package/lib/interaction/legendFilter.js +72 -31
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +2 -2
- package/lib/interaction/tooltip.js +37 -21
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/lib/auto.d.ts +3 -0
- package/lib/lib/auto.js +11 -0
- package/lib/lib/auto.js.map +1 -0
- 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/index.d.ts +1 -0
- package/lib/lib/index.js +3 -1
- package/lib/lib/index.js.map +1 -1
- package/lib/lib/std.d.ts +30 -29
- package/lib/mark/auto.d.ts +1 -0
- package/lib/mark/auto.js +30 -0
- package/lib/mark/auto.js.map +1 -0
- package/lib/mark/index.d.ts +1 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/runtime/plot.js +11 -4
- package/lib/runtime/plot.js.map +1 -1
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/connector/connector.js.map +1 -1
- package/lib/shape/index.d.ts +1 -1
- package/lib/spec/index.d.ts +3 -3
- package/lib/spec/mark.d.ts +4 -2
- package/lib/theme/academy.js +30 -358
- package/lib/theme/academy.js.map +1 -1
- package/lib/theme/classic.js +4 -433
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +3 -404
- package/lib/theme/classicDark.js.map +1 -1
- package/lib/theme/create.d.ts +437 -0
- package/lib/theme/create.js +425 -0
- package/lib/theme/create.js.map +1 -0
- package/lib/theme/dark.d.ts +3 -0
- package/lib/theme/dark.js +80 -0
- package/lib/theme/dark.js.map +1 -0
- package/lib/theme/index.d.ts +1 -0
- package/lib/theme/index.js +3 -1
- package/lib/theme/index.js.map +1 -1
- package/lib/theme/light.js +52 -470
- package/lib/theme/light.js.map +1 -1
- package/lib/utils/event.d.ts +31 -32
- package/lib/utils/event.js +2 -12
- package/lib/utils/event.js.map +1 -1
- package/package.json +23 -8
- package/src/api/chart.ts +1 -1
- package/src/api/library.ts +1 -2
- package/src/api/runtime.ts +7 -2
- package/src/api/utils.ts +22 -6
- package/src/composition/repeatMatrix.ts +11 -2
- package/src/exports.ts +32 -0
- package/src/index.ts +13 -41
- package/src/interaction/fisheye.ts +3 -1
- package/src/interaction/legendFilter.ts +81 -48
- package/src/interaction/tooltip.ts +56 -33
- package/src/lib/auto.ts +7 -0
- package/src/lib/core.ts +2 -1
- package/src/lib/index.ts +1 -0
- package/src/mark/auto.ts +22 -0
- package/src/mark/index.ts +1 -0
- package/src/runtime/plot.ts +34 -7
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/index.ts +1 -1
- package/src/spec/index.ts +3 -3
- package/src/spec/mark.ts +4 -0
- package/src/theme/academy.ts +74 -399
- package/src/theme/classic.ts +11 -438
- package/src/theme/classicDark.ts +10 -409
- package/src/theme/create.ts +439 -0
- package/src/theme/dark.ts +85 -0
- package/src/theme/index.ts +1 -0
- package/src/theme/light.ts +53 -473
- package/src/utils/event.ts +32 -45
- package/dist/g2-lite.min.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.5",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"require": "./lib/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"./esm/exports.js"
|
|
18
|
+
],
|
|
16
19
|
"files": [
|
|
17
20
|
"src",
|
|
18
21
|
"lib",
|
|
@@ -30,7 +33,8 @@
|
|
|
30
33
|
"test": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/ --coverage -i --logHeapUsage",
|
|
31
34
|
"test:unit": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/unit/ --coverage -i --logHeapUsage",
|
|
32
35
|
"test:integration": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict node_modules/jest/bin/jest __tests__/integration/ --coverage -i --logHeapUsage",
|
|
33
|
-
"
|
|
36
|
+
"preview": "vite preview",
|
|
37
|
+
"build:umd": "rimraf ./dist && node --expose-gc --max-old-space-size=4096 node_modules/rollup/dist/bin/rollup -c && npm run size",
|
|
34
38
|
"build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
|
|
35
39
|
"build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm",
|
|
36
40
|
"build": "run-p build:*",
|
|
@@ -41,9 +45,6 @@
|
|
|
41
45
|
"upload": "node scripts/upload/snapshot.js",
|
|
42
46
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
|
|
43
47
|
},
|
|
44
|
-
"sideEffects": [
|
|
45
|
-
"./esm/index.js"
|
|
46
|
-
],
|
|
47
48
|
"keywords": [
|
|
48
49
|
"antv",
|
|
49
50
|
"g2",
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"animation"
|
|
56
57
|
],
|
|
57
58
|
"dependencies": {
|
|
59
|
+
"@antv/ava": "^3.0.7",
|
|
58
60
|
"@antv/coord": "^0.4.1",
|
|
59
61
|
"@antv/event-emitter": "^0.1.3",
|
|
60
62
|
"@antv/g": "^5.18.6",
|
|
@@ -89,7 +91,9 @@
|
|
|
89
91
|
"@antv/g-webgl": "^1.9.8",
|
|
90
92
|
"@commitlint/cli": "^11.0.0",
|
|
91
93
|
"@commitlint/config-conventional": "^17.4.4",
|
|
94
|
+
"@optimize-lodash/rollup-plugin": "^4.0.3",
|
|
92
95
|
"@rollup/plugin-commonjs": "^21.0.2",
|
|
96
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
93
97
|
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
94
98
|
"@rollup/plugin-terser": "^0.4.3",
|
|
95
99
|
"@types/d3-array": "3.0.5",
|
|
@@ -146,17 +150,28 @@
|
|
|
146
150
|
"limit-size": [
|
|
147
151
|
{
|
|
148
152
|
"path": "dist/g2.min.js",
|
|
149
|
-
"limit": "
|
|
153
|
+
"limit": "280 Kb",
|
|
150
154
|
"gzip": true
|
|
151
155
|
},
|
|
152
156
|
{
|
|
153
157
|
"path": "dist/g2.min.js",
|
|
154
|
-
"limit": "
|
|
158
|
+
"limit": "950 Kb",
|
|
159
|
+
"gzip": false
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"path": "dist/g2.lite.min.js",
|
|
163
|
+
"limit": "240 Kb",
|
|
164
|
+
"gzip": true
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"path": "dist/g2.full.min.js",
|
|
168
|
+
"limit": "350 Kb",
|
|
169
|
+
"gzip": true
|
|
155
170
|
}
|
|
156
171
|
],
|
|
157
172
|
"author": {
|
|
158
173
|
"name": "AntV",
|
|
159
|
-
"url": "https://antv.
|
|
174
|
+
"url": "https://antv.antgroup.com/"
|
|
160
175
|
},
|
|
161
176
|
"repository": {
|
|
162
177
|
"type": "git",
|
package/src/api/chart.ts
CHANGED
package/src/api/library.ts
CHANGED
package/src/api/runtime.ts
CHANGED
|
@@ -6,7 +6,7 @@ import EventEmitter from '@antv/event-emitter';
|
|
|
6
6
|
import { G2Context, render, destroy } from '../runtime';
|
|
7
7
|
import { G2Spec, ViewComposition } from '../spec';
|
|
8
8
|
import { ChartEvent } from '../utils/event';
|
|
9
|
-
import { G2Library } from '../runtime/types/options';
|
|
9
|
+
import type { G2Library } from '../runtime/types/options';
|
|
10
10
|
import {
|
|
11
11
|
normalizeContainer,
|
|
12
12
|
removeContainer,
|
|
@@ -20,6 +20,7 @@ import { CompositionNode } from './composition';
|
|
|
20
20
|
import { Node } from './node';
|
|
21
21
|
import { defineProps, nodeProps } from './define';
|
|
22
22
|
import { MarkNode } from './mark';
|
|
23
|
+
import { library } from './library';
|
|
23
24
|
|
|
24
25
|
export const G2_CHART_KEY = 'G2_CHART_KEY';
|
|
25
26
|
|
|
@@ -58,7 +59,11 @@ export class Runtime<Spec extends G2Spec = G2Spec> extends CompositionNode {
|
|
|
58
59
|
this._plugins = plugins || [];
|
|
59
60
|
this._container = normalizeContainer(container);
|
|
60
61
|
this._emitter = new EventEmitter();
|
|
61
|
-
this._context = {
|
|
62
|
+
this._context = {
|
|
63
|
+
library: { ...lib, ...library },
|
|
64
|
+
emitter: this._emitter,
|
|
65
|
+
canvas,
|
|
66
|
+
};
|
|
62
67
|
this._create();
|
|
63
68
|
}
|
|
64
69
|
|
package/src/api/utils.ts
CHANGED
|
@@ -31,6 +31,8 @@ export const VIEW_KEYS = [
|
|
|
31
31
|
|
|
32
32
|
export const REMOVE_FLAG = '__remove__';
|
|
33
33
|
|
|
34
|
+
export const CALLBACK_NODE = '__callback__';
|
|
35
|
+
|
|
34
36
|
export function normalizeContainer(
|
|
35
37
|
container: string | HTMLElement,
|
|
36
38
|
): HTMLElement {
|
|
@@ -84,12 +86,16 @@ export function optionsOf(node: Node): Record<string, any> {
|
|
|
84
86
|
const value = nodeValue.get(node);
|
|
85
87
|
const { children = [] } = node;
|
|
86
88
|
for (const child of children) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
if (child.type === CALLBACK_NODE) {
|
|
90
|
+
value.children = child.value;
|
|
91
|
+
} else {
|
|
92
|
+
const childValue = valueOf(child);
|
|
93
|
+
const { children = [] } = value;
|
|
94
|
+
children.push(childValue);
|
|
95
|
+
discovered.push(child);
|
|
96
|
+
nodeValue.set(child, childValue);
|
|
97
|
+
value.children = children;
|
|
98
|
+
}
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
return nodeValue.get(root);
|
|
@@ -142,6 +148,12 @@ function createNode(
|
|
|
142
148
|
mark: Record<string, new () => Node>,
|
|
143
149
|
composition: Record<string, new () => Node>,
|
|
144
150
|
): Node {
|
|
151
|
+
if (typeof options === 'function') {
|
|
152
|
+
const node = new Node();
|
|
153
|
+
node.value = options;
|
|
154
|
+
node.type = CALLBACK_NODE;
|
|
155
|
+
return node;
|
|
156
|
+
}
|
|
145
157
|
const { type, children, ...value } = options;
|
|
146
158
|
const Ctor = typeCtor(type, mark, composition);
|
|
147
159
|
const node = new Ctor();
|
|
@@ -182,6 +194,8 @@ function appendNode(
|
|
|
182
194
|
for (const child of children) {
|
|
183
195
|
discovered.push([node, child]);
|
|
184
196
|
}
|
|
197
|
+
} else if (typeof children === 'function') {
|
|
198
|
+
discovered.push([node, children]);
|
|
185
199
|
}
|
|
186
200
|
}
|
|
187
201
|
}
|
|
@@ -216,6 +230,8 @@ export function updateRoot(
|
|
|
216
230
|
const oldChild = oldChildren[i];
|
|
217
231
|
discovered.push([oldNode, oldChild, newChild]);
|
|
218
232
|
}
|
|
233
|
+
} else if (typeof newChildren === 'function') {
|
|
234
|
+
discovered.push([oldNode, null, newChildren]);
|
|
219
235
|
}
|
|
220
236
|
}
|
|
221
237
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { deepMix } from '@antv/util';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CompositionComponent as CC,
|
|
4
|
+
G2View,
|
|
5
|
+
G2ViewTree,
|
|
6
|
+
Node,
|
|
7
|
+
} from '../runtime';
|
|
3
8
|
import { RepeatMatrixComposition } from '../spec';
|
|
4
9
|
import { Container } from '../utils/container';
|
|
5
10
|
import { calcBBox } from '../utils/vector';
|
|
@@ -63,7 +68,7 @@ const setChildren = useOverrideAdaptor<G2ViewTree>((options) => {
|
|
|
63
68
|
const facet = facets[i];
|
|
64
69
|
const children = normalizedChildren[i];
|
|
65
70
|
return children.map((d) => {
|
|
66
|
-
const { scale, key, encode, axis, ...rest } = d;
|
|
71
|
+
const { scale, key, encode, axis, interaction, ...rest } = d;
|
|
67
72
|
const guideY = scale?.y?.guide;
|
|
68
73
|
const guideX = scale?.x?.guide;
|
|
69
74
|
const defaultScale = {
|
|
@@ -103,6 +108,10 @@ const setChildren = useOverrideAdaptor<G2ViewTree>((options) => {
|
|
|
103
108
|
x: fx,
|
|
104
109
|
y: fy,
|
|
105
110
|
}),
|
|
111
|
+
interaction: deepMix({}, interaction, {
|
|
112
|
+
// Register this interaction in parent node.
|
|
113
|
+
legendFilter: false,
|
|
114
|
+
}),
|
|
106
115
|
...rest,
|
|
107
116
|
};
|
|
108
117
|
});
|
package/src/exports.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { runtime } from '@antv/g';
|
|
2
|
+
|
|
3
|
+
runtime.enableCSSParsing = false;
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
render,
|
|
7
|
+
renderToMountedElement,
|
|
8
|
+
MAIN_LAYER_CLASS_NAME,
|
|
9
|
+
LABEL_LAYER_CLASS_NAME,
|
|
10
|
+
ELEMENT_CLASS_NAME,
|
|
11
|
+
VIEW_CLASS_NAME,
|
|
12
|
+
PLOT_CLASS_NAME,
|
|
13
|
+
COMPONENT_CLASS_NAME,
|
|
14
|
+
LABEL_CLASS_NAME,
|
|
15
|
+
AREA_CLASS_NAME,
|
|
16
|
+
MASK_CLASS_NAME,
|
|
17
|
+
} from './runtime';
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
type MarkNode,
|
|
21
|
+
type CompositionNode,
|
|
22
|
+
register,
|
|
23
|
+
Runtime,
|
|
24
|
+
extend,
|
|
25
|
+
type ChartOptions,
|
|
26
|
+
} from './api';
|
|
27
|
+
|
|
28
|
+
export { ChartEvent } from './utils/event';
|
|
29
|
+
|
|
30
|
+
export type { G2Context } from './runtime';
|
|
31
|
+
|
|
32
|
+
export * from './spec';
|
package/src/index.ts
CHANGED
|
@@ -1,45 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { corelib, plotlib, graphlib, geolib, stdlib, threedlib } from './lib';
|
|
2
|
+
import { extend, Runtime } from './api';
|
|
3
|
+
import { API, CompositionAPI } from './api/extend';
|
|
4
|
+
import { G2Spec } from './spec';
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
export { corelib, plotlib, graphlib, geolib, stdlib, threedlib };
|
|
4
7
|
|
|
5
|
-
export
|
|
6
|
-
render,
|
|
7
|
-
renderToMountedElement,
|
|
8
|
-
MAIN_LAYER_CLASS_NAME,
|
|
9
|
-
LABEL_LAYER_CLASS_NAME,
|
|
10
|
-
ELEMENT_CLASS_NAME,
|
|
11
|
-
VIEW_CLASS_NAME,
|
|
12
|
-
PLOT_CLASS_NAME,
|
|
13
|
-
COMPONENT_CLASS_NAME,
|
|
14
|
-
LABEL_CLASS_NAME,
|
|
15
|
-
AREA_CLASS_NAME,
|
|
16
|
-
MASK_CLASS_NAME,
|
|
17
|
-
} from './runtime';
|
|
8
|
+
export * from './exports';
|
|
18
9
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
graphlib,
|
|
24
|
-
plotlib,
|
|
25
|
-
geolib,
|
|
26
|
-
threedlib,
|
|
27
|
-
} from './lib';
|
|
10
|
+
/**
|
|
11
|
+
* G2 standard library initial all the libs except 3D and auto.
|
|
12
|
+
*/
|
|
13
|
+
const library = { ...stdlib() };
|
|
28
14
|
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
Chart,
|
|
33
|
-
type MarkNode,
|
|
34
|
-
type CompositionNode,
|
|
35
|
-
register,
|
|
36
|
-
Runtime,
|
|
37
|
-
extend,
|
|
38
|
-
type ChartOptions,
|
|
39
|
-
} from './api';
|
|
40
|
-
|
|
41
|
-
export { ChartEvent } from './utils/event';
|
|
42
|
-
|
|
43
|
-
export type { G2Context } from './runtime';
|
|
44
|
-
|
|
45
|
-
export * from './spec';
|
|
15
|
+
export const Chart = extend(Runtime, library);
|
|
16
|
+
export interface Chart extends API<G2Spec, typeof library> {}
|
|
17
|
+
export interface CompositionNode extends CompositionAPI<typeof library> {}
|
|
@@ -36,7 +36,9 @@ export function Fisheye({
|
|
|
36
36
|
setState('fisheye', (options) => {
|
|
37
37
|
// Clone options and mutate it.
|
|
38
38
|
// Disable animation.
|
|
39
|
-
const clonedOptions = deepMix({}, options
|
|
39
|
+
const clonedOptions = deepMix({}, options, {
|
|
40
|
+
interaction: { tooltip: { preserve: true } },
|
|
41
|
+
});
|
|
40
42
|
for (const mark of clonedOptions.marks) mark.animate = false;
|
|
41
43
|
const [x, y] = focus;
|
|
42
44
|
const fisheye = maybeCoordinate(clonedOptions);
|
|
@@ -198,9 +198,69 @@ function legendFilterContinuous(_, { legend, filter, emitter, channel }) {
|
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
async function filterView(
|
|
202
|
+
context, // View instance,
|
|
203
|
+
{
|
|
204
|
+
legend, // Legend instance.
|
|
205
|
+
channel, // Filter Channel.
|
|
206
|
+
value, // Filtered Values.
|
|
207
|
+
ordinal, // Data type of the legend.
|
|
208
|
+
channels, // Channels for this legend.
|
|
209
|
+
allChannels, // Channels for all legends.
|
|
210
|
+
facet = false, // For facet.
|
|
211
|
+
},
|
|
212
|
+
) {
|
|
213
|
+
const { view, update, setState } = context;
|
|
214
|
+
setState(legend, (viewOptions) => {
|
|
215
|
+
const { marks } = viewOptions;
|
|
216
|
+
// Add filter transform for every marks,
|
|
217
|
+
// which will skip for mark without color channel.
|
|
218
|
+
const newMarks = marks.map((mark) => {
|
|
219
|
+
if (mark.type === 'legends') return mark;
|
|
220
|
+
|
|
221
|
+
// Inset after aggregate transform, such as group, and bin.
|
|
222
|
+
const { transform = [] } = mark;
|
|
223
|
+
const index = transform.findIndex(
|
|
224
|
+
({ type }) => type.startsWith('group') || type.startsWith('bin'),
|
|
225
|
+
);
|
|
226
|
+
const newTransform = [...transform];
|
|
227
|
+
newTransform.splice(index + 1, 0, {
|
|
228
|
+
type: 'filter',
|
|
229
|
+
[channel]: { value, ordinal },
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Set domain of scale to preserve encoding.
|
|
233
|
+
const newScale = Object.fromEntries(
|
|
234
|
+
channels.map((channel) => [
|
|
235
|
+
channel,
|
|
236
|
+
{ domain: view.scale[channel].getOptions().domain },
|
|
237
|
+
]),
|
|
238
|
+
);
|
|
239
|
+
return deepMix({}, mark, {
|
|
240
|
+
transform: newTransform,
|
|
241
|
+
scale: newScale,
|
|
242
|
+
...(!ordinal && { animate: false }),
|
|
243
|
+
legend: facet
|
|
244
|
+
? false
|
|
245
|
+
: Object.fromEntries(allChannels.map((d) => [d, { preserve: true }])),
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
return { ...viewOptions, marks: newMarks };
|
|
249
|
+
});
|
|
250
|
+
await update();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function filterFacets(facets, options) {
|
|
254
|
+
for (const facet of facets) {
|
|
255
|
+
filterView(facet, { ...options, facet: true });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
201
259
|
export function LegendFilter() {
|
|
202
|
-
return (context,
|
|
203
|
-
const { container
|
|
260
|
+
return (context, contexts, emitter) => {
|
|
261
|
+
const { container } = context;
|
|
262
|
+
const facets = contexts.filter((d) => d !== context);
|
|
263
|
+
const isFacet = facets.length > 0;
|
|
204
264
|
|
|
205
265
|
const channelsOf = (legend) => {
|
|
206
266
|
return dataOf(legend).scales.map((d) => d.name);
|
|
@@ -211,54 +271,19 @@ export function LegendFilter() {
|
|
|
211
271
|
];
|
|
212
272
|
const allChannels = legends.flatMap(channelsOf);
|
|
213
273
|
|
|
214
|
-
const filter =
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const { marks } = viewOptions;
|
|
218
|
-
// Add filter transform for every marks,
|
|
219
|
-
// which will skip for mark without color channel.
|
|
220
|
-
const newMarks = marks.map((mark) => {
|
|
221
|
-
if (mark.type === 'legends') return mark;
|
|
222
|
-
|
|
223
|
-
// Inset after aggregate transform, such as group, and bin.
|
|
224
|
-
const { transform = [] } = mark;
|
|
225
|
-
const index = transform.findIndex(
|
|
226
|
-
({ type }) => type.startsWith('group') || type.startsWith('bin'),
|
|
227
|
-
);
|
|
228
|
-
const newTransform = [...transform];
|
|
229
|
-
newTransform.splice(index + 1, 0, {
|
|
230
|
-
type: 'filter',
|
|
231
|
-
[channel]: { value, ordinal },
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
// Set domain of scale to preserve encoding.
|
|
235
|
-
const newScale = Object.fromEntries(
|
|
236
|
-
channels.map((channel) => [
|
|
237
|
-
channel,
|
|
238
|
-
{ domain: view.scale[channel].getOptions().domain },
|
|
239
|
-
]),
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
return deepMix({}, mark, {
|
|
243
|
-
transform: newTransform,
|
|
244
|
-
scale: newScale,
|
|
245
|
-
...(!ordinal && { animate: false }),
|
|
246
|
-
legend: Object.fromEntries(
|
|
247
|
-
allChannels.map((d) => [d, { preserve: true }]),
|
|
248
|
-
),
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
return { ...viewOptions, marks: newMarks };
|
|
252
|
-
});
|
|
253
|
-
await update();
|
|
254
|
-
},
|
|
255
|
-
50,
|
|
256
|
-
{ trailing: true },
|
|
257
|
-
);
|
|
274
|
+
const filter = isFacet
|
|
275
|
+
? throttle(filterFacets, 50, { trailing: true })
|
|
276
|
+
: throttle(filterView, 50, { trailing: true });
|
|
258
277
|
|
|
259
278
|
const removes = legends.map((legend) => {
|
|
260
279
|
const { name: channel, domain } = dataOf(legend).scales[0];
|
|
261
280
|
const channels = channelsOf(legend);
|
|
281
|
+
const common = {
|
|
282
|
+
legend,
|
|
283
|
+
channel,
|
|
284
|
+
channels,
|
|
285
|
+
allChannels,
|
|
286
|
+
};
|
|
262
287
|
if (legend.className === CATEGORY_LEGEND_CLASS_NAME) {
|
|
263
288
|
return legendFilterOrdinal(container, {
|
|
264
289
|
legends: itemsOf,
|
|
@@ -269,7 +294,11 @@ export function LegendFilter() {
|
|
|
269
294
|
const { index } = datum;
|
|
270
295
|
return domain[index];
|
|
271
296
|
},
|
|
272
|
-
filter: (value) =>
|
|
297
|
+
filter: (value) => {
|
|
298
|
+
const options = { ...common, value, ordinal: true };
|
|
299
|
+
if (isFacet) filter(facets, options);
|
|
300
|
+
else filter(context, options);
|
|
301
|
+
},
|
|
273
302
|
state: legend.attributes.state,
|
|
274
303
|
channel,
|
|
275
304
|
emitter,
|
|
@@ -277,7 +306,11 @@ export function LegendFilter() {
|
|
|
277
306
|
} else {
|
|
278
307
|
return legendFilterContinuous(container, {
|
|
279
308
|
legend,
|
|
280
|
-
filter: (value) =>
|
|
309
|
+
filter: (value) => {
|
|
310
|
+
const options = { ...common, value, ordinal: false };
|
|
311
|
+
if (isFacet) filter(facets, options);
|
|
312
|
+
else filter(context, options);
|
|
313
|
+
},
|
|
281
314
|
emitter,
|
|
282
315
|
channel,
|
|
283
316
|
});
|