@antv/g2 5.2.7 → 5.2.9
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 +59 -1
- package/dist/g2.min.js +59 -1
- package/esm/component/slider.d.ts +4 -0
- package/esm/component/slider.js.map +1 -1
- package/esm/data/ema.d.ts +10 -0
- package/esm/data/ema.js +44 -0
- package/esm/data/ema.js.map +1 -0
- package/esm/data/index.d.ts +2 -0
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/label-transform/contrastReverse.js +2 -0
- package/esm/label-transform/contrastReverse.js.map +1 -1
- package/esm/label-transform/exceedAdjust.js +6 -5
- package/esm/label-transform/exceedAdjust.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/mark/gauge.js +3 -1
- package/esm/mark/gauge.js.map +1 -1
- package/esm/runtime/plot.js +8 -4
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +5 -2
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/types/component.d.ts +2 -1
- package/esm/spec/dataTransform.d.ts +8 -2
- package/esm/transform/stackY.js +16 -5
- package/esm/transform/stackY.js.map +1 -1
- package/esm/utils/color.js.map +1 -1
- package/lib/component/slider.d.ts +4 -0
- package/lib/component/slider.js.map +1 -1
- package/lib/data/ema.d.ts +10 -0
- package/lib/data/ema.js +49 -0
- package/lib/data/ema.js.map +1 -0
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/label-transform/contrastReverse.js +2 -0
- package/lib/label-transform/contrastReverse.js.map +1 -1
- package/lib/label-transform/exceedAdjust.js +6 -5
- package/lib/label-transform/exceedAdjust.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/mark/gauge.js +3 -1
- package/lib/mark/gauge.js.map +1 -1
- package/lib/runtime/plot.js +8 -4
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +5 -2
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/types/component.d.ts +2 -1
- package/lib/spec/dataTransform.d.ts +8 -2
- package/lib/transform/stackY.js +16 -5
- package/lib/transform/stackY.js.map +1 -1
- package/lib/utils/color.js.map +1 -1
- package/package.json +46 -43
- package/src/component/slider.ts +4 -0
- package/src/data/ema.ts +62 -0
- package/src/data/index.ts +2 -0
- package/src/label-transform/contrastReverse.ts +1 -0
- package/src/label-transform/exceedAdjust.ts +4 -5
- package/src/lib/core.ts +2 -0
- package/src/mark/gauge.ts +3 -1
- package/src/runtime/plot.ts +14 -4
- package/src/runtime/render.ts +5 -2
- package/src/runtime/types/component.ts +2 -0
- package/src/spec/dataTransform.ts +10 -1
- package/src/transform/stackY.ts +16 -3
- package/src/utils/color.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.9",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -12,7 +12,16 @@
|
|
|
12
12
|
"types": "./lib/index.d.ts",
|
|
13
13
|
"import": "./esm/index.js",
|
|
14
14
|
"require": "./lib/index.js"
|
|
15
|
-
}
|
|
15
|
+
},
|
|
16
|
+
"./lib/*": {
|
|
17
|
+
"types": "./lib/*.d.ts",
|
|
18
|
+
"require": "./lib/*.js"
|
|
19
|
+
},
|
|
20
|
+
"./esm/*": {
|
|
21
|
+
"types": "./lib/*.d.ts",
|
|
22
|
+
"import": "./esm/*.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
16
25
|
},
|
|
17
26
|
"sideEffects": [
|
|
18
27
|
"./esm/exports.js"
|
|
@@ -32,17 +41,16 @@
|
|
|
32
41
|
"size": "limit-size",
|
|
33
42
|
"lint": "eslint ./src ./__tests__ && prettier ./src ./__tests__ --check ",
|
|
34
43
|
"fix": "eslint ./src ./__tests__ --fix && prettier ./src ./__tests__ --write ",
|
|
35
|
-
"test": "cross-env TZ=Asia/Shanghai
|
|
36
|
-
"test:unit": "cross-env TZ=Asia/Shanghai
|
|
37
|
-
"test:integration": "cross-env TZ=Asia/Shanghai
|
|
44
|
+
"test": "cross-env TZ=Asia/Shanghai jest __tests__ --coverage",
|
|
45
|
+
"test:unit": "cross-env TZ=Asia/Shanghai jest __tests__/unit/",
|
|
46
|
+
"test:integration": "cross-env TZ=Asia/Shanghai jest __tests__/integration/",
|
|
38
47
|
"preview": "vite preview",
|
|
39
|
-
"build:umd": "rimraf ./dist && node
|
|
48
|
+
"build:umd": "rimraf ./dist && node node_modules/rollup/dist/bin/rollup -c && npm run size",
|
|
40
49
|
"build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
|
|
41
50
|
"build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm",
|
|
42
51
|
"build": "run-p build:*",
|
|
43
52
|
"bundle-vis": "cross-env BUNDLE_VIS=1 run-p build:umd",
|
|
44
53
|
"ci": "run-s lint test build",
|
|
45
|
-
"prepublishOnly": "npm run ci",
|
|
46
54
|
"prepare": "husky install",
|
|
47
55
|
"upload": "node scripts/upload/snapshot.js",
|
|
48
56
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
|
@@ -59,67 +67,64 @@
|
|
|
59
67
|
"animation"
|
|
60
68
|
],
|
|
61
69
|
"dependencies": {
|
|
62
|
-
"@antv/component": "^2.
|
|
63
|
-
"@antv/coord": "^0.4.
|
|
70
|
+
"@antv/component": "^2.1.2",
|
|
71
|
+
"@antv/coord": "^0.4.7",
|
|
64
72
|
"@antv/event-emitter": "^0.1.3",
|
|
65
|
-
"@antv/g": "^6.
|
|
66
|
-
"@antv/g-canvas": "^2.0.
|
|
67
|
-
"@antv/g-plugin-dragndrop": "^2.0.
|
|
68
|
-
"@antv/scale": "^0.4.
|
|
69
|
-
"@antv/util": "^3.3.
|
|
73
|
+
"@antv/g": "^6.1.11",
|
|
74
|
+
"@antv/g-canvas": "^2.0.29",
|
|
75
|
+
"@antv/g-plugin-dragndrop": "^2.0.22",
|
|
76
|
+
"@antv/scale": "^0.4.16",
|
|
77
|
+
"@antv/util": "^3.3.10",
|
|
70
78
|
"d3-array": "^3.2.4",
|
|
71
79
|
"d3-dsv": "^3.0.1",
|
|
72
80
|
"d3-force": "^3.0.0",
|
|
73
81
|
"d3-format": "^3.1.0",
|
|
74
|
-
"d3-geo": "^3.1.
|
|
82
|
+
"d3-geo": "^3.1.1",
|
|
75
83
|
"d3-hierarchy": "^3.1.2",
|
|
76
84
|
"d3-path": "^3.1.0",
|
|
77
|
-
"d3-scale-chromatic": "^3.
|
|
85
|
+
"d3-scale-chromatic": "^3.1.0",
|
|
78
86
|
"d3-shape": "^3.2.0",
|
|
79
87
|
"flru": "^1.0.2",
|
|
80
|
-
"fmin": "^0.0.
|
|
88
|
+
"fmin": "^0.0.4",
|
|
81
89
|
"pdfast": "^0.2.0"
|
|
82
90
|
},
|
|
83
91
|
"devDependencies": {
|
|
84
92
|
"@antv/data-set": "^0.11.8",
|
|
85
|
-
"@antv/g-pattern": "^2.0.
|
|
86
|
-
"@antv/g-plugin-3d": "^2.0.
|
|
87
|
-
"@antv/g-plugin-control": "^2.0.
|
|
88
|
-
"@antv/g-plugin-rough-canvas-renderer": "^2.0.
|
|
89
|
-
"@antv/g-plugin-rough-svg-renderer": "^2.0.
|
|
90
|
-
"@antv/g-svg": "^2.0.
|
|
91
|
-
"@antv/g-webgl": "^2.0.
|
|
92
|
-
"@antv/g2-extension-3d": "^0.1.
|
|
93
|
+
"@antv/g-pattern": "^2.0.22",
|
|
94
|
+
"@antv/g-plugin-3d": "^2.0.31",
|
|
95
|
+
"@antv/g-plugin-control": "^2.0.22",
|
|
96
|
+
"@antv/g-plugin-rough-canvas-renderer": "^2.0.29",
|
|
97
|
+
"@antv/g-plugin-rough-svg-renderer": "^2.0.25",
|
|
98
|
+
"@antv/g-svg": "^2.0.24",
|
|
99
|
+
"@antv/g-webgl": "^2.0.33",
|
|
100
|
+
"@antv/g2-extension-3d": "^0.1.6",
|
|
93
101
|
"@antv/g2-extension-ava": "^0.1.1",
|
|
94
|
-
"@antv/g2-extension-plot": "^0.1.
|
|
102
|
+
"@antv/g2-extension-plot": "^0.1.2",
|
|
95
103
|
"@antv/translator": "^1.0.1",
|
|
96
104
|
"@commitlint/cli": "^11.0.0",
|
|
97
105
|
"@commitlint/config-conventional": "^17.8.1",
|
|
98
106
|
"@optimize-lodash/rollup-plugin": "^4.0.4",
|
|
99
107
|
"@rollup/plugin-commonjs": "^21.1.0",
|
|
100
|
-
"@rollup/plugin-json": "^6.0
|
|
101
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
108
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
109
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
102
110
|
"@rollup/plugin-terser": "^0.4.4",
|
|
103
111
|
"@types/d3-array": "3.0.5",
|
|
104
|
-
"@types/d3-path": "^3.0
|
|
105
|
-
"@types/d3-shape": "^3.1.
|
|
106
|
-
"@types/diff": "^5.
|
|
112
|
+
"@types/d3-path": "^3.1.0",
|
|
113
|
+
"@types/d3-shape": "^3.1.6",
|
|
114
|
+
"@types/diff": "^5.2.3",
|
|
107
115
|
"@types/jest": "^26.0.24",
|
|
108
116
|
"@types/pixelmatch": "^5.2.6",
|
|
109
|
-
"@types/pngjs": "^6.0.4",
|
|
110
117
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
111
118
|
"@typescript-eslint/parser": "^4.33.0",
|
|
112
119
|
"conventional-changelog-cli": "^2.2.2",
|
|
113
120
|
"cross-env": "^7.0.3",
|
|
114
|
-
"d3-dsv": "^3.0.1",
|
|
115
121
|
"d3-fetch": "^3.0.1",
|
|
116
122
|
"d3-geo-projection": "^4.0.0",
|
|
117
|
-
"d3-hierarchy": "^3.1.2",
|
|
118
123
|
"d3-interpolate": "^3.0.1",
|
|
119
124
|
"d3-random": "^3.0.1",
|
|
120
125
|
"d3-regression": "^1.3.10",
|
|
121
126
|
"eslint": "^7.32.0",
|
|
122
|
-
"eslint-plugin-import": "^2.
|
|
127
|
+
"eslint-plugin-import": "^2.31.0",
|
|
123
128
|
"fecha": "^4.2.3",
|
|
124
129
|
"husky": "^7.0.4",
|
|
125
130
|
"jest": "^26.6.3",
|
|
@@ -128,18 +133,16 @@
|
|
|
128
133
|
"lint-staged": "^10.5.4",
|
|
129
134
|
"npm-run-all": "^4.1.5",
|
|
130
135
|
"pixelmatch": "5.3.0",
|
|
131
|
-
"pngjs": "^6.0.0",
|
|
132
136
|
"prettier": "^2.8.8",
|
|
133
|
-
"reflect-metadata": "^0.1.13",
|
|
134
137
|
"rimraf": "^3.0.2",
|
|
135
|
-
"rollup": "^2.79.
|
|
138
|
+
"rollup": "^2.79.2",
|
|
136
139
|
"rollup-plugin-polyfill-node": "^0.8.0",
|
|
137
140
|
"rollup-plugin-typescript2": "^0.35.0",
|
|
138
|
-
"rollup-plugin-visualizer": "^5.
|
|
141
|
+
"rollup-plugin-visualizer": "^5.12.0",
|
|
139
142
|
"topojson": "^3.0.2",
|
|
140
143
|
"ts-jest": "^26.5.6",
|
|
141
144
|
"typescript": "^4.9.5",
|
|
142
|
-
"vite": "^3.2.
|
|
145
|
+
"vite": "^3.2.11",
|
|
143
146
|
"xmlserializer": "^0.6.1"
|
|
144
147
|
},
|
|
145
148
|
"lint-staged": {
|
|
@@ -152,17 +155,17 @@
|
|
|
152
155
|
"limit-size": [
|
|
153
156
|
{
|
|
154
157
|
"path": "dist/g2.min.js",
|
|
155
|
-
"limit": "
|
|
158
|
+
"limit": "290 Kb",
|
|
156
159
|
"gzip": true
|
|
157
160
|
},
|
|
158
161
|
{
|
|
159
162
|
"path": "dist/g2.min.js",
|
|
160
|
-
"limit": "
|
|
163
|
+
"limit": "970 Kb",
|
|
161
164
|
"gzip": false
|
|
162
165
|
},
|
|
163
166
|
{
|
|
164
167
|
"path": "dist/g2.lite.min.js",
|
|
165
|
-
"limit": "
|
|
168
|
+
"limit": "260 Kb",
|
|
166
169
|
"gzip": true
|
|
167
170
|
}
|
|
168
171
|
],
|
package/src/component/slider.ts
CHANGED
|
@@ -11,6 +11,10 @@ import { invert } from '../utils/scale';
|
|
|
11
11
|
|
|
12
12
|
export type SliderOptions = {
|
|
13
13
|
orientation: 'horizontal' | 'vertical';
|
|
14
|
+
showHandle?: boolean;
|
|
15
|
+
showLabel?: boolean;
|
|
16
|
+
showLabelOnInteraction?: boolean;
|
|
17
|
+
autoFitLabel?: boolean;
|
|
14
18
|
[key: string]: any;
|
|
15
19
|
};
|
|
16
20
|
|
package/src/data/ema.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { DataComponent as DC } from '../runtime';
|
|
2
|
+
import { EMADataTransform } from '../spec';
|
|
3
|
+
|
|
4
|
+
export function ema(values: number[], alpha: number): number[] {
|
|
5
|
+
if (alpha < 0 || alpha > 1) {
|
|
6
|
+
throw new Error('alpha must be between 0 and 1.');
|
|
7
|
+
}
|
|
8
|
+
if (values.length === 0) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let last = values[0];
|
|
13
|
+
const smoothed: number[] = [];
|
|
14
|
+
|
|
15
|
+
for (const point of values) {
|
|
16
|
+
if (point === null || point === undefined) {
|
|
17
|
+
// 如果没有数据的话,使用最近的值
|
|
18
|
+
smoothed.push(point);
|
|
19
|
+
console.warn('EMA:The value is null or undefined', values);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (last === null || last === undefined) {
|
|
24
|
+
last = point;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const smoothedVal = last * alpha + (1 - alpha) * point;
|
|
28
|
+
smoothed.push(smoothedVal);
|
|
29
|
+
last = smoothedVal;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return smoothed;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type EMAOptions = Omit<EMADataTransform, 'type'>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* https://en.wikipedia.org/wiki/Exponential_smoothing
|
|
39
|
+
* @param options
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
export const EMA: DC<EMAOptions> = (options) => {
|
|
44
|
+
const { field = 'y', alpha = 0.6, as = field } = options;
|
|
45
|
+
|
|
46
|
+
return (data) => {
|
|
47
|
+
const values = data.map((d) => {
|
|
48
|
+
return d[field];
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const out = ema(values, alpha);
|
|
52
|
+
|
|
53
|
+
return data.map((d, i) => {
|
|
54
|
+
return {
|
|
55
|
+
...d,
|
|
56
|
+
[as]: out[i],
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
EMA.props = {};
|
package/src/data/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ export { Slice } from './slice';
|
|
|
18
18
|
export { KDE } from './kde';
|
|
19
19
|
export { Venn } from './venn';
|
|
20
20
|
export { Log } from './log';
|
|
21
|
+
export { EMA } from './ema';
|
|
21
22
|
|
|
22
23
|
export type { FetchOptions } from './fetch';
|
|
23
24
|
export type { FoldOptions } from './fold';
|
|
@@ -39,3 +40,4 @@ export type { SliceOptions } from './slice';
|
|
|
39
40
|
export type { KDEOptions } from './kde';
|
|
40
41
|
export type { VennOptions } from './venn';
|
|
41
42
|
export type { LogDataOptions } from './log';
|
|
43
|
+
export type { EMAOptions } from './ema';
|
|
@@ -25,6 +25,7 @@ function getL(r: number, g: number, b: number) {
|
|
|
25
25
|
* @param background
|
|
26
26
|
*/
|
|
27
27
|
function contrast(foreground, background): number {
|
|
28
|
+
if (!foreground || !background || foreground === background) return 1;
|
|
28
29
|
const { r, g, b } = foreground;
|
|
29
30
|
const { r: rb, g: gb, b: bb } = background;
|
|
30
31
|
const L1 = getL(r, g, b);
|
|
@@ -34,9 +34,7 @@ export type ExceedAdjustOptions = Omit<ExceedAdjustLabel, 'type'>;
|
|
|
34
34
|
* adjust the label when exceed the plot
|
|
35
35
|
*/
|
|
36
36
|
export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
|
|
37
|
-
return (labels: DisplayObject[], { canvas }) => {
|
|
38
|
-
const { width, height } = canvas.getConfig();
|
|
39
|
-
|
|
37
|
+
return (labels: DisplayObject[], { canvas, layout }) => {
|
|
40
38
|
labels.forEach((l) => {
|
|
41
39
|
show(l);
|
|
42
40
|
const { max, min } = l.getRenderBounds();
|
|
@@ -47,9 +45,10 @@ export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
|
|
|
47
45
|
[xMin, yMin],
|
|
48
46
|
[xMax, yMax],
|
|
49
47
|
],
|
|
48
|
+
// Prevent label overlap in multiple charts by calculating layouts separately to avoid collisions.
|
|
50
49
|
[
|
|
51
|
-
[
|
|
52
|
-
[width, height],
|
|
50
|
+
[layout.x, layout.y],
|
|
51
|
+
[layout.x + layout.width, layout.y + layout.height],
|
|
53
52
|
],
|
|
54
53
|
);
|
|
55
54
|
// For label with connectorPoints
|
package/src/lib/core.ts
CHANGED
|
@@ -154,6 +154,7 @@ import {
|
|
|
154
154
|
Sort as DataSort,
|
|
155
155
|
KDE as DataKDE,
|
|
156
156
|
Log as DataLog,
|
|
157
|
+
EMA as DataEMA,
|
|
157
158
|
WordCloud,
|
|
158
159
|
} from '../data';
|
|
159
160
|
import {
|
|
@@ -181,6 +182,7 @@ export function corelib() {
|
|
|
181
182
|
'data.kde': DataKDE,
|
|
182
183
|
'data.log': DataLog,
|
|
183
184
|
'data.wordCloud': WordCloud,
|
|
185
|
+
'data.ema': DataEMA,
|
|
184
186
|
'transform.stackY': StackY,
|
|
185
187
|
'transform.binX': BinX,
|
|
186
188
|
'transform.bin': Bin,
|
package/src/mark/gauge.ts
CHANGED
|
@@ -123,6 +123,7 @@ const DEFAULT_TEXT_OPTIONS = {
|
|
|
123
123
|
fontWeight: 800,
|
|
124
124
|
fill: '#888',
|
|
125
125
|
},
|
|
126
|
+
tooltip: false,
|
|
126
127
|
};
|
|
127
128
|
|
|
128
129
|
export type GaugeData =
|
|
@@ -212,7 +213,7 @@ export const Gauge: CC<GaugeOptions> = (options) => {
|
|
|
212
213
|
total,
|
|
213
214
|
scale: newScale,
|
|
214
215
|
} = dataTransform(data, scale);
|
|
215
|
-
const textStyle = subObject(style, 'text');
|
|
216
|
+
const { tooltip, ...textStyle } = subObject(style, 'text');
|
|
216
217
|
// pointer + pin
|
|
217
218
|
const indicatorStyle = filterPrefixObject(style, ['pointer', 'pin']);
|
|
218
219
|
|
|
@@ -244,6 +245,7 @@ export const Gauge: CC<GaugeOptions> = (options) => {
|
|
|
244
245
|
text: getTextContent(textStyle, { target, total }),
|
|
245
246
|
...textStyle,
|
|
246
247
|
},
|
|
248
|
+
tooltip,
|
|
247
249
|
animate:
|
|
248
250
|
typeof animate === 'object' ? subObject(animate, 'text') : animate,
|
|
249
251
|
}),
|
package/src/runtime/plot.ts
CHANGED
|
@@ -1197,7 +1197,9 @@ function plotLabel(
|
|
|
1197
1197
|
return elements.flatMap((e) => {
|
|
1198
1198
|
const L = getLabels(options, i, e);
|
|
1199
1199
|
L.forEach((l) => {
|
|
1200
|
-
labelShapeFunction.set(l,
|
|
1200
|
+
labelShapeFunction.set(l, (data) =>
|
|
1201
|
+
shapeFunction({ ...data, element: e }),
|
|
1202
|
+
);
|
|
1201
1203
|
labelDescriptor.set(l, labelOption);
|
|
1202
1204
|
});
|
|
1203
1205
|
return L;
|
|
@@ -1229,11 +1231,12 @@ function plotLabel(
|
|
|
1229
1231
|
const labelGroups = group(labelShapes, (d) =>
|
|
1230
1232
|
labelDescriptor.get(d.__data__),
|
|
1231
1233
|
);
|
|
1232
|
-
const { coordinate } = view;
|
|
1234
|
+
const { coordinate, layout } = view;
|
|
1233
1235
|
|
|
1234
1236
|
const labelTransformContext = {
|
|
1235
1237
|
canvas: context.canvas,
|
|
1236
1238
|
coordinate,
|
|
1239
|
+
layout,
|
|
1237
1240
|
};
|
|
1238
1241
|
for (const [label, shapes] of labelGroups) {
|
|
1239
1242
|
const { transform = [] } = label;
|
|
@@ -1363,11 +1366,18 @@ function createLabelShapeFunction(
|
|
|
1363
1366
|
transform,
|
|
1364
1367
|
style: abstractStyle,
|
|
1365
1368
|
render,
|
|
1369
|
+
selector,
|
|
1370
|
+
element,
|
|
1366
1371
|
...abstractOptions
|
|
1367
1372
|
} = options;
|
|
1373
|
+
|
|
1368
1374
|
const visualOptions = mapObject(
|
|
1369
1375
|
{ ...abstractOptions, ...abstractStyle } as Record<string, any>,
|
|
1370
|
-
(d) =>
|
|
1376
|
+
(d) =>
|
|
1377
|
+
valueOf(d, datum, index, abstractData, {
|
|
1378
|
+
channel,
|
|
1379
|
+
element,
|
|
1380
|
+
}),
|
|
1371
1381
|
);
|
|
1372
1382
|
const { shape = defaultLabelShape, text, ...style } = visualOptions;
|
|
1373
1383
|
const f = typeof formatter === 'string' ? format(formatter) : formatter;
|
|
@@ -1391,7 +1401,7 @@ function valueOf(
|
|
|
1391
1401
|
datum: Record<string, any>,
|
|
1392
1402
|
i: number,
|
|
1393
1403
|
data: Record<string, any>,
|
|
1394
|
-
options: { channel: Record<string, any
|
|
1404
|
+
options: { channel: Record<string, any>; element?: G2Element },
|
|
1395
1405
|
) {
|
|
1396
1406
|
if (typeof value === 'function') return value(datum, i, data, options);
|
|
1397
1407
|
if (typeof value !== 'string') return value;
|
package/src/runtime/render.ts
CHANGED
|
@@ -105,9 +105,12 @@ export function render<T extends G2ViewTree = G2ViewTree>(
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// Wait for the next tick.
|
|
108
|
+
// FIXME: Use `rendered?` event instead of `requestAnimationFrame`.
|
|
108
109
|
canvas.requestAnimationFrame(() => {
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
canvas.requestAnimationFrame(() => {
|
|
111
|
+
emitter.emit(ChartEvent.AFTER_RENDER);
|
|
112
|
+
resolve?.();
|
|
113
|
+
});
|
|
111
114
|
});
|
|
112
115
|
})
|
|
113
116
|
.catch((e) => {
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
Vector2,
|
|
16
16
|
G2MarkState,
|
|
17
17
|
GuideComponentPlane,
|
|
18
|
+
Layout,
|
|
18
19
|
} from './common';
|
|
19
20
|
import { DataComponent } from './data';
|
|
20
21
|
import { Encode, EncodeComponent } from './encode';
|
|
@@ -233,6 +234,7 @@ export type LabelTransform = (
|
|
|
233
234
|
context: {
|
|
234
235
|
coordinate: Coordinate;
|
|
235
236
|
canvas: Canvas;
|
|
237
|
+
layout: Layout;
|
|
236
238
|
},
|
|
237
239
|
) => DisplayObject[];
|
|
238
240
|
export type LabelTransformComponent<O = Record<string, unknown>> =
|
|
@@ -13,7 +13,8 @@ export type DataTransform =
|
|
|
13
13
|
| KDEDataTransform
|
|
14
14
|
| VennDataTransform
|
|
15
15
|
| LogDataTransform
|
|
16
|
-
| CustomTransform
|
|
16
|
+
| CustomTransform
|
|
17
|
+
| EMADataTransform;
|
|
17
18
|
|
|
18
19
|
export type DataTransformTypes =
|
|
19
20
|
| 'sortBy'
|
|
@@ -29,6 +30,7 @@ export type DataTransformTypes =
|
|
|
29
30
|
| 'venn'
|
|
30
31
|
| 'log'
|
|
31
32
|
| 'custom'
|
|
33
|
+
| 'ema'
|
|
32
34
|
| DataComponent;
|
|
33
35
|
|
|
34
36
|
export type SortByTransform = {
|
|
@@ -188,3 +190,10 @@ export type CustomTransform = {
|
|
|
188
190
|
type?: DataComponent;
|
|
189
191
|
[key: string]: any;
|
|
190
192
|
};
|
|
193
|
+
|
|
194
|
+
export type EMADataTransform = {
|
|
195
|
+
type?: 'ema';
|
|
196
|
+
field?: string; // The field to be smoothed, default: 'y'
|
|
197
|
+
alpha?: number; // smooth factor, default: 0.6
|
|
198
|
+
as?: string; // Set the generated field, default: 'y'
|
|
199
|
+
};
|
package/src/transform/stackY.ts
CHANGED
|
@@ -95,13 +95,26 @@ export const StackY: TC<StackYOptions> = (options = {}) => {
|
|
|
95
95
|
// Choose new y or y1 channel as the new y channel.
|
|
96
96
|
const V = fromY === 'y' ? newY : newY1;
|
|
97
97
|
const V1 = fromY1 === 'y' ? newY : newY1;
|
|
98
|
+
let newEncode: Record<string, any>;
|
|
99
|
+
// mark point will compute the actural Y = (y + y1) / 2 if y1 exists
|
|
100
|
+
if (mark.type === 'point') {
|
|
101
|
+
newEncode = {
|
|
102
|
+
y0: inferredColumn(Y, fy), // Store original Y.
|
|
103
|
+
y: column(V, fy),
|
|
104
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
newEncode = {
|
|
107
|
+
y0: inferredColumn(Y, fy), // Store original Y.
|
|
108
|
+
y: column(V, fy),
|
|
109
|
+
y1: column(V1, fy1),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
98
113
|
return [
|
|
99
114
|
I,
|
|
100
115
|
deepMix({}, mark, {
|
|
101
116
|
encode: {
|
|
102
|
-
|
|
103
|
-
y: column(V, fy),
|
|
104
|
-
y1: column(V1, fy1),
|
|
117
|
+
...newEncode,
|
|
105
118
|
},
|
|
106
119
|
style: {
|
|
107
120
|
first: (_, i) => FS.has(i),
|
package/src/utils/color.ts
CHANGED