@antv/g2 5.2.8 → 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/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 +6 -3
- 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/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/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 +6 -3
- 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/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 -42
- 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/lib/core.ts +2 -0
- package/src/mark/gauge.ts +3 -1
- package/src/runtime/plot.ts +12 -3
- package/src/runtime/render.ts +5 -2
- package/src/spec/dataTransform.ts +10 -1
- package/src/transform/stackY.ts +16 -3
- package/src/utils/color.ts +1 -1
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);
|
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;
|
|
@@ -1364,11 +1366,18 @@ function createLabelShapeFunction(
|
|
|
1364
1366
|
transform,
|
|
1365
1367
|
style: abstractStyle,
|
|
1366
1368
|
render,
|
|
1369
|
+
selector,
|
|
1370
|
+
element,
|
|
1367
1371
|
...abstractOptions
|
|
1368
1372
|
} = options;
|
|
1373
|
+
|
|
1369
1374
|
const visualOptions = mapObject(
|
|
1370
1375
|
{ ...abstractOptions, ...abstractStyle } as Record<string, any>,
|
|
1371
|
-
(d) =>
|
|
1376
|
+
(d) =>
|
|
1377
|
+
valueOf(d, datum, index, abstractData, {
|
|
1378
|
+
channel,
|
|
1379
|
+
element,
|
|
1380
|
+
}),
|
|
1372
1381
|
);
|
|
1373
1382
|
const { shape = defaultLabelShape, text, ...style } = visualOptions;
|
|
1374
1383
|
const f = typeof formatter === 'string' ? format(formatter) : formatter;
|
|
@@ -1392,7 +1401,7 @@ function valueOf(
|
|
|
1392
1401
|
datum: Record<string, any>,
|
|
1393
1402
|
i: number,
|
|
1394
1403
|
data: Record<string, any>,
|
|
1395
|
-
options: { channel: Record<string, any
|
|
1404
|
+
options: { channel: Record<string, any>; element?: G2Element },
|
|
1396
1405
|
) {
|
|
1397
1406
|
if (typeof value === 'function') return value(datum, i, data, options);
|
|
1398
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) => {
|
|
@@ -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