@antv/g2 5.1.1 → 5.1.2
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 +20 -0
- package/dist/g2-lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/api/chart.d.ts +7 -1
- package/esm/api/chart.js.map +1 -1
- package/esm/api/extend.d.ts +2 -1
- package/esm/api/index.d.ts +1 -3
- package/esm/api/index.js +1 -3
- package/esm/api/index.js.map +1 -1
- package/esm/api/library.d.ts +1 -0
- package/esm/api/runtime.js +1 -0
- package/esm/api/runtime.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +1 -1
- package/esm/interaction/tooltip.js +14 -8
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/lib/plot.d.ts +1 -0
- package/esm/lib/plot.js +2 -1
- package/esm/lib/plot.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/gauge.d.ts +1 -1
- package/esm/mark/gauge.js +14 -2
- package/esm/mark/gauge.js.map +1 -1
- package/esm/mark/index.d.ts +2 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/line.js +1 -1
- package/esm/mark/line.js.map +1 -1
- package/esm/mark/liquid.d.ts +7 -0
- package/esm/mark/liquid.js +83 -0
- package/esm/mark/liquid.js.map +1 -0
- package/esm/runtime/plot.js +2 -0
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/transform.js +4 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/shape/index.d.ts +2 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/liquid/liquid.d.ts +3 -0
- package/esm/shape/liquid/liquid.js +79 -0
- package/esm/shape/liquid/liquid.js.map +1 -0
- package/esm/shape/liquid/shapes.d.ts +38 -0
- package/esm/shape/liquid/shapes.js +93 -0
- package/esm/shape/liquid/shapes.js.map +1 -0
- package/esm/shape/liquid/wave.d.ts +16 -0
- package/esm/shape/liquid/wave.js +192 -0
- package/esm/shape/liquid/wave.js.map +1 -0
- package/esm/spec/mark.d.ts +2 -1
- package/esm/utils/helper.js +10 -2
- package/esm/utils/helper.js.map +1 -1
- package/lib/api/chart.d.ts +7 -1
- package/lib/api/chart.js.map +1 -1
- package/lib/api/extend.d.ts +2 -1
- package/lib/api/index.d.ts +1 -3
- package/lib/api/index.js +1 -5
- package/lib/api/index.js.map +1 -1
- package/lib/api/library.d.ts +1 -0
- package/lib/api/runtime.js +1 -0
- package/lib/api/runtime.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -3
- package/lib/index.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +1 -1
- package/lib/interaction/tooltip.js +13 -7
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/lib/plot.d.ts +1 -0
- package/lib/lib/plot.js +1 -0
- package/lib/lib/plot.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/gauge.d.ts +1 -1
- package/lib/mark/gauge.js +13 -1
- package/lib/mark/gauge.js.map +1 -1
- package/lib/mark/index.d.ts +2 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/line.js +1 -1
- package/lib/mark/line.js.map +1 -1
- package/lib/mark/liquid.d.ts +7 -0
- package/lib/mark/liquid.js +87 -0
- package/lib/mark/liquid.js.map +1 -0
- package/lib/runtime/plot.js +2 -0
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/transform.js +3 -0
- package/lib/runtime/transform.js.map +1 -1
- package/lib/shape/index.d.ts +2 -0
- package/lib/shape/index.js +3 -1
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/liquid/liquid.d.ts +3 -0
- package/lib/shape/liquid/liquid.js +83 -0
- package/lib/shape/liquid/liquid.js.map +1 -0
- package/lib/shape/liquid/shapes.d.ts +38 -0
- package/lib/shape/liquid/shapes.js +96 -0
- package/lib/shape/liquid/shapes.js.map +1 -0
- package/lib/shape/liquid/wave.d.ts +16 -0
- package/lib/shape/liquid/wave.js +196 -0
- package/lib/shape/liquid/wave.js.map +1 -0
- package/lib/spec/mark.d.ts +2 -1
- package/lib/utils/helper.js +10 -2
- package/lib/utils/helper.js.map +1 -1
- package/package.json +1 -1
- package/src/api/chart.ts +6 -1
- package/src/api/extend.ts +11 -11
- package/src/api/index.ts +6 -3
- package/src/api/runtime.ts +1 -0
- package/src/index.ts +2 -2
- package/src/interaction/tooltip.ts +15 -5
- package/src/lib/plot.ts +2 -1
- package/src/mark/area.ts +1 -1
- package/src/mark/gauge.ts +30 -9
- package/src/mark/index.ts +2 -0
- package/src/mark/line.ts +1 -1
- package/src/mark/liquid.ts +100 -0
- package/src/runtime/plot.ts +3 -0
- package/src/runtime/transform.ts +3 -1
- package/src/shape/index.ts +2 -0
- package/src/shape/liquid/liquid.ts +116 -0
- package/src/shape/liquid/shapes.ts +101 -0
- package/src/shape/liquid/wave.ts +245 -0
- package/src/spec/mark.ts +2 -0
- package/src/utils/helper.ts +9 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addWave = void 0;
|
|
4
|
+
const DURATION = 5000;
|
|
5
|
+
/**
|
|
6
|
+
* A function of linear mapping.
|
|
7
|
+
* @param min
|
|
8
|
+
* @param max
|
|
9
|
+
* @param factor
|
|
10
|
+
*/
|
|
11
|
+
function lerp(min, max, factor) {
|
|
12
|
+
return min + (max - min) * factor;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Using Bessel curve to simulate sine wave.
|
|
16
|
+
* Using Bezier curves to fit sine wave.
|
|
17
|
+
* There is 4 control points for each curve of wave,
|
|
18
|
+
* which is at 1/4 wave length of the sine wave.
|
|
19
|
+
*
|
|
20
|
+
* The control points for a wave from (a) to (d) are a-b-c-d:
|
|
21
|
+
* c *----* d
|
|
22
|
+
* b *
|
|
23
|
+
* |
|
|
24
|
+
* ... a * ..................
|
|
25
|
+
*
|
|
26
|
+
* Whose positions are a: (0, 0), b: (0.5, 0.5), c: (1, 1), d: (PI / 2, 1).
|
|
27
|
+
*
|
|
28
|
+
* @param x x position of the left-most point (a).
|
|
29
|
+
* @param stage 0-3, stating which part of the wave it is.
|
|
30
|
+
* @param waveLength wave length of the sine wave.
|
|
31
|
+
* @param amplitude wave amplitude.
|
|
32
|
+
* @return Sinusoidal segment curve.
|
|
33
|
+
*/
|
|
34
|
+
function getWaterWavePositions(x, stage, waveLength, amplitude) {
|
|
35
|
+
if (stage === 0) {
|
|
36
|
+
return [
|
|
37
|
+
[x + ((1 / 2) * waveLength) / Math.PI / 2, amplitude / 2],
|
|
38
|
+
[x + ((1 / 2) * waveLength) / Math.PI, amplitude],
|
|
39
|
+
[x + waveLength / 4, amplitude],
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
if (stage === 1) {
|
|
43
|
+
return [
|
|
44
|
+
[x + (((1 / 2) * waveLength) / Math.PI / 2) * (Math.PI - 2), amplitude],
|
|
45
|
+
[
|
|
46
|
+
x + (((1 / 2) * waveLength) / Math.PI / 2) * (Math.PI - 1),
|
|
47
|
+
amplitude / 2,
|
|
48
|
+
],
|
|
49
|
+
[x + waveLength / 4, 0],
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
if (stage === 2) {
|
|
53
|
+
return [
|
|
54
|
+
[x + ((1 / 2) * waveLength) / Math.PI / 2, -amplitude / 2],
|
|
55
|
+
[x + ((1 / 2) * waveLength) / Math.PI, -amplitude],
|
|
56
|
+
[x + waveLength / 4, -amplitude],
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
return [
|
|
60
|
+
[x + (((1 / 2) * waveLength) / Math.PI / 2) * (Math.PI - 2), -amplitude],
|
|
61
|
+
[
|
|
62
|
+
x + (((1 / 2) * waveLength) / Math.PI / 2) * (Math.PI - 1),
|
|
63
|
+
-amplitude / 2,
|
|
64
|
+
],
|
|
65
|
+
[x + waveLength / 4, 0],
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get wave path.
|
|
70
|
+
* @param radius
|
|
71
|
+
* @param waterLevel water level
|
|
72
|
+
* @param waveLength wave length
|
|
73
|
+
* @param phase
|
|
74
|
+
* @param amplitude
|
|
75
|
+
* @param cx center x
|
|
76
|
+
* @param cy center y
|
|
77
|
+
* @return path path
|
|
78
|
+
*/
|
|
79
|
+
function getWaterWavePath(radius, waterLevel, waveLength, phase, amplitude, cx, cy) {
|
|
80
|
+
const curves = Math.ceil(((2 * radius) / waveLength) * 4) * 4;
|
|
81
|
+
const path = [];
|
|
82
|
+
let _phase = phase;
|
|
83
|
+
// Map phase to [-Math.PI * 2, 0].
|
|
84
|
+
while (_phase < -Math.PI * 2) {
|
|
85
|
+
_phase += Math.PI * 2;
|
|
86
|
+
}
|
|
87
|
+
while (_phase > 0) {
|
|
88
|
+
_phase -= Math.PI * 2;
|
|
89
|
+
}
|
|
90
|
+
_phase = (_phase / Math.PI / 2) * waveLength;
|
|
91
|
+
const left = cx - radius + _phase - radius * 2;
|
|
92
|
+
/**
|
|
93
|
+
* Top-left corner as start point.
|
|
94
|
+
*
|
|
95
|
+
* Draws this point.
|
|
96
|
+
* |
|
|
97
|
+
* \|/
|
|
98
|
+
* ~~~~~~~~
|
|
99
|
+
* | |
|
|
100
|
+
* +------+
|
|
101
|
+
*/
|
|
102
|
+
path.push(['M', left, waterLevel]);
|
|
103
|
+
/**
|
|
104
|
+
* Top wave.
|
|
105
|
+
*
|
|
106
|
+
* ~~~~~~~~ <- Draws this sine wave.
|
|
107
|
+
* | |
|
|
108
|
+
* +------+
|
|
109
|
+
*/
|
|
110
|
+
let waveRight = 0;
|
|
111
|
+
for (let c = 0; c < curves; ++c) {
|
|
112
|
+
const stage = c % 4;
|
|
113
|
+
const pos = getWaterWavePositions((c * waveLength) / 4, stage, waveLength, amplitude);
|
|
114
|
+
path.push([
|
|
115
|
+
'C',
|
|
116
|
+
pos[0][0] + left,
|
|
117
|
+
-pos[0][1] + waterLevel,
|
|
118
|
+
pos[1][0] + left,
|
|
119
|
+
-pos[1][1] + waterLevel,
|
|
120
|
+
pos[2][0] + left,
|
|
121
|
+
-pos[2][1] + waterLevel,
|
|
122
|
+
]);
|
|
123
|
+
if (c === curves - 1) {
|
|
124
|
+
waveRight = pos[2][0];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Top-right corner.
|
|
129
|
+
*
|
|
130
|
+
* ~~~~~~~~
|
|
131
|
+
* 3. Draws this line. -> | | <- 1. Draws this line.
|
|
132
|
+
* +------+
|
|
133
|
+
* ^
|
|
134
|
+
* |
|
|
135
|
+
* 2. Draws this line.
|
|
136
|
+
*/
|
|
137
|
+
path.push(['L', waveRight + left, cy + radius]);
|
|
138
|
+
path.push(['L', left, cy + radius]);
|
|
139
|
+
path.push(['Z']);
|
|
140
|
+
return path;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Add wave.
|
|
144
|
+
* @param x center x
|
|
145
|
+
* @param y center y
|
|
146
|
+
* @param level wave level 0~1
|
|
147
|
+
* @param waveCount wave count
|
|
148
|
+
* @param waveAttrs style
|
|
149
|
+
* @param group g
|
|
150
|
+
* @param minY Minimum height
|
|
151
|
+
* @param radius radius
|
|
152
|
+
* @param waveLength wave length
|
|
153
|
+
* @param animation animation config
|
|
154
|
+
* @param document
|
|
155
|
+
*/
|
|
156
|
+
function addWave(x, y, level, waveCount, waveAttrs, group, minY, radius, waveLength, animation, document) {
|
|
157
|
+
// Box property Color width height.
|
|
158
|
+
const { fill, fillOpacity, opacity } = waveAttrs;
|
|
159
|
+
// Number of cyclic waveCount.
|
|
160
|
+
for (let idx = 0; idx < waveCount; idx++) {
|
|
161
|
+
const factor = waveCount <= 1 ? 1 : idx / (waveCount - 1);
|
|
162
|
+
const path = getWaterWavePath(radius, minY + radius * level, waveLength, 0,
|
|
163
|
+
// Amplitude height.
|
|
164
|
+
radius / 40, x, y);
|
|
165
|
+
// Create wave path.
|
|
166
|
+
const wave = document.createElement('path', {
|
|
167
|
+
style: {
|
|
168
|
+
path,
|
|
169
|
+
fill,
|
|
170
|
+
opacity: lerp(0.2, 0.9, factor) * Number(opacity || fillOpacity),
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
group.appendChild(wave);
|
|
174
|
+
try {
|
|
175
|
+
if (animation === false)
|
|
176
|
+
return;
|
|
177
|
+
const keyframes = [
|
|
178
|
+
{
|
|
179
|
+
transform: 'translate(0, 0)',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
transform: `translate(${waveLength * 2}px, 0)`,
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
wave.animate(keyframes, {
|
|
186
|
+
duration: lerp(0.5 * DURATION, DURATION, factor) * 2,
|
|
187
|
+
iterations: Infinity,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
console.warn('off-screen group animate error!');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.addWave = addWave;
|
|
196
|
+
//# sourceMappingURL=wave.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wave.js","sourceRoot":"src/","sources":["shape/liquid/wave.ts"],"names":[],"mappings":";;;AAEA,MAAM,QAAQ,GAAG,IAAI,CAAC;AAEtB;;;;;GAKG;AACH,SAAS,IAAI,CAAC,GAAW,EAAE,GAAW,EAAE,MAAc;IACpD,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,qBAAqB,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,OAAO;YAEhC,MAAM,SAAS,GAAG;gBAChB;oBACE,SAAS,EAAE,iBAAiB;iBAC7B;gBACD;oBACE,SAAS,EAAE,aAAa,UAAU,GAAG,CAAC,QAAQ;iBAC/C;aACF,CAAC;YAEF,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;gBACtB,QAAQ,EAAE,IAAI,CAAC,GAAG,GAAG,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC;gBACpD,UAAU,EAAE,QAAQ;aACrB,CAAC,CAAC;SACJ;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;SACjD;KACF;AACH,CAAC;AA9DD,0BA8DC"}
|
package/lib/spec/mark.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { Data } from './data';
|
|
|
10
10
|
import { AxisComponent, LegendComponent, ScrollbarComponent, SliderComponent, TitleComponent, TooltipComponent } from './component';
|
|
11
11
|
import { Closeable, Literal2Object, Padding } from './utils';
|
|
12
12
|
export type Mark = IntervalMark | RectMark | LineMark | PointMark | TextMark | CellMark | AreaMark | NodeMark | EdgeMark | ImageMark | PolygonMark | BoxMark | VectorMark | LineXMark | LineYMark | RangeMark | RangeXMark | RangeYMark | ConnectorMark | SankeyMark | PathMark | TreemapMark | PackMark | BoxPlotMark | ShapeMark | ForceGraphMark | TreeMark | WordCloudMark | DensityMark | CustomMark | CompositeMark;
|
|
13
|
-
export type MarkTypes = 'interval' | 'rect' | 'line' | 'point' | 'text' | 'cell' | 'area' | 'node' | 'edge' | 'link' | 'image' | 'polygon' | 'box' | 'vector' | 'lineX' | 'lineY' | 'connector' | 'range' | 'rangeX' | 'rangeY' | 'sankey' | 'path' | 'treemap' | 'pack' | 'boxplot' | 'shape' | 'forceGraph' | 'tree' | 'wordCloud' | 'gauge' | 'density' | 'heatmap' | MarkComponent | CompositeMarkType;
|
|
13
|
+
export type MarkTypes = 'interval' | 'rect' | 'line' | 'point' | 'text' | 'cell' | 'area' | 'node' | 'edge' | 'link' | 'image' | 'polygon' | 'box' | 'vector' | 'lineX' | 'lineY' | 'connector' | 'range' | 'rangeX' | 'rangeY' | 'sankey' | 'path' | 'treemap' | 'pack' | 'boxplot' | 'shape' | 'forceGraph' | 'tree' | 'wordCloud' | 'gauge' | 'density' | 'heatmap' | 'liquid' | MarkComponent | CompositeMarkType;
|
|
14
14
|
export type ChannelTypes = 'x' | 'y' | 'z' | 'x1' | 'y1' | 'series' | 'color' | 'opacity' | 'shape' | 'size' | 'key' | 'groupKey' | 'position' | 'series' | 'enterType' | 'enterEasing' | 'enterDuration' | 'enterDelay' | 'updateType' | 'updateEasing' | 'updateDuration' | 'updateDelay' | 'exitType' | 'exitEasing' | 'exitDuration' | 'exitDelay' | `position${number}`;
|
|
15
15
|
export type PositionChannelTypes = 'x' | 'y' | 'z' | 'position' | `position${number}`;
|
|
16
16
|
export type AtheisticChanelTypes = 'size' | 'color' | 'shape' | 'opacity';
|
|
@@ -190,4 +190,5 @@ export type WordCloudMark = BaseMark<'wordCloud', 'value' | ChannelTypes | 'text
|
|
|
190
190
|
export type GaugeMark = BaseMark<'gauge', `arc${Capitalize<ChannelTypes>}` | `indicator${Capitalize<ChannelTypes>}` | `pointer${Capitalize<ChannelTypes>}` | `pin${Capitalize<ChannelTypes>}` | ChannelTypes>;
|
|
191
191
|
export type DensityMark = BaseMark<'density', ChannelTypes | 'series'>;
|
|
192
192
|
export type HeatmapMark = BaseMark<'heatmap'>;
|
|
193
|
+
export type LiquidMark = BaseMark<'liquid'>;
|
|
193
194
|
export type CustomMark = BaseMark<MarkComponent, ChannelTypes>;
|
package/lib/utils/helper.js
CHANGED
|
@@ -44,8 +44,16 @@ function copyAttributes(target, source) {
|
|
|
44
44
|
const { attributes } = source;
|
|
45
45
|
const exclude = new Set(['id', 'className']);
|
|
46
46
|
for (const [key, value] of Object.entries(attributes)) {
|
|
47
|
-
if (!exclude.has(key))
|
|
48
|
-
|
|
47
|
+
if (!exclude.has(key)) {
|
|
48
|
+
// @todo Fix in @antv/g
|
|
49
|
+
if (key === 'transform') {
|
|
50
|
+
target.attr(key, '');
|
|
51
|
+
target.attr(key, value);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
target.attr(key, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
exports.copyAttributes = copyAttributes;
|
package/lib/utils/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"src/","sources":["utils/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qCAAmE;AAEnE,SAAgB,QAAQ,CAAI,CAAI;IAC9B,OAAO,CAAC,CAAC;AACX,CAAC;AAFD,4BAEC;AAGD;;GAEG;AACH,SAAgB,OAAO,CAAI,GAAc;IACvC,OAAO,GAAG,CAAC,MAAM,CACf,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,CACf,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,CACb,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EACrC,QAAQ,CACT,CAAC;AACJ,CAAC;AAPD,0BAOC;AAED;;GAEG;AACH,SAAgB,YAAY,CAC1B,GAAiC;IAEjC,OAAO,GAAG,CAAC,MAAM,CACf,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC,CAAO,CAAC,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC;QAChC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAA,EACD,QAAQ,CACT,CAAC;AACJ,CAAC;AAVD,oCAUC;AAED,SAAgB,eAAe,CAAC,GAAW;IACzC,OAAO,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAA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AC,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
package/src/api/chart.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { G2Spec } from '../spec';
|
|
2
|
-
import { extend, API } from './extend';
|
|
2
|
+
import { extend, API, CompositionAPI } from './extend';
|
|
3
3
|
import { library } from './library';
|
|
4
4
|
import { Runtime } from './runtime';
|
|
5
|
+
import { MarkNode as Node } from './mark';
|
|
5
6
|
import type { RuntimeOptions } from './runtime';
|
|
6
7
|
|
|
7
8
|
export interface Chart extends API<G2Spec, typeof library> {}
|
|
8
9
|
|
|
10
|
+
export interface CompositionNode extends CompositionAPI<typeof library> {}
|
|
11
|
+
|
|
12
|
+
export interface MarkNode extends Node {}
|
|
13
|
+
|
|
9
14
|
export const Chart = extend(Runtime, library);
|
|
10
15
|
|
|
11
16
|
export type ChartOptions = Omit<RuntimeOptions, 'lib'>;
|
package/src/api/extend.ts
CHANGED
|
@@ -5,22 +5,22 @@ import { MarkOf, CompositionOf as Of } from './types';
|
|
|
5
5
|
import { MarkNode } from './mark';
|
|
6
6
|
import { CompositionNode } from './composition';
|
|
7
7
|
|
|
8
|
-
type CompositionOf<Library> = Of<
|
|
9
|
-
Library,
|
|
10
|
-
(
|
|
11
|
-
composite?,
|
|
12
|
-
) => CompositionNode<
|
|
13
|
-
CompositionOf<Library> & MarkOf<Library, (composite?) => MarkNode>
|
|
14
|
-
> &
|
|
15
|
-
MarkOf<Library, (composite?) => MarkNode> &
|
|
16
|
-
CompositionOf<Library>
|
|
17
|
-
>;
|
|
18
|
-
|
|
19
8
|
type BuiltinComposition = {
|
|
20
9
|
'composition.mark': any;
|
|
21
10
|
'composition.view': any;
|
|
22
11
|
};
|
|
23
12
|
|
|
13
|
+
export type CompositionOf<Library> = Of<
|
|
14
|
+
Library,
|
|
15
|
+
(composite?) => CompositionAPI<Library>
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export type CompositionAPI<Library> = CompositionNode<
|
|
19
|
+
CompositionOf<Library> & MarkOf<Library, (composite?) => MarkNode>
|
|
20
|
+
> &
|
|
21
|
+
MarkOf<Library, (composite?) => MarkNode> &
|
|
22
|
+
CompositionOf<Library>;
|
|
23
|
+
|
|
24
24
|
export type API<Spec, Library> = Runtime<Spec> &
|
|
25
25
|
MarkOf<Library, (composite?) => MarkNode> &
|
|
26
26
|
CompositionOf<Library & BuiltinComposition>;
|
package/src/api/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export {
|
|
2
|
+
Chart,
|
|
3
|
+
type ChartOptions,
|
|
4
|
+
type MarkNode,
|
|
5
|
+
type CompositionNode,
|
|
6
|
+
} from './chart';
|
|
4
7
|
export { register } from './library';
|
|
5
8
|
export { Runtime } from './runtime';
|
|
6
9
|
export { extend } from './extend';
|
package/src/api/runtime.ts
CHANGED
|
@@ -64,6 +64,7 @@ export class Runtime<Spec extends G2Spec = G2Spec> extends CompositionNode {
|
|
|
64
64
|
render(): Promise<Runtime<Spec>> {
|
|
65
65
|
if (this._rendering) return this._addToTrailing();
|
|
66
66
|
if (!this._context.canvas) this._createCanvas();
|
|
67
|
+
this._context.canvas.getConfig().supportsCSSTransform = true;
|
|
67
68
|
this._bindAutoFit();
|
|
68
69
|
this._rendering = true;
|
|
69
70
|
const finished = new Promise<Runtime<Spec>>((resolve, reject) =>
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Circle, DisplayObject, IElement, Line } from '@antv/g';
|
|
|
2
2
|
import { sort, group, mean, bisector, minIndex } from 'd3-array';
|
|
3
3
|
import { deepMix, lowerFirst, throttle } from '@antv/util';
|
|
4
4
|
import { Tooltip as TooltipComponent } from '@antv/gui';
|
|
5
|
-
import { Constant, Identity } from '@antv/scale';
|
|
5
|
+
import { Constant, Identity, Band } from '@antv/scale';
|
|
6
6
|
import { defined, subObject } from '../utils/helper';
|
|
7
7
|
import { isTranspose, isPolar } from '../utils/coordinate';
|
|
8
8
|
import { angle, sub } from '../utils/vector';
|
|
@@ -185,19 +185,26 @@ function singleItem(element) {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
function groupNameOf(scale, datum) {
|
|
188
|
-
const { color: scaleColor, series: scaleSeries } = scale;
|
|
188
|
+
const { color: scaleColor, series: scaleSeries, facet = false } = scale;
|
|
189
189
|
const { color, series } = datum;
|
|
190
190
|
const invertAble = (scale) => {
|
|
191
191
|
return (
|
|
192
192
|
scale &&
|
|
193
193
|
scale.invert &&
|
|
194
|
-
!(scale instanceof
|
|
194
|
+
!(scale instanceof Band) &&
|
|
195
195
|
!(scale instanceof Constant)
|
|
196
196
|
);
|
|
197
197
|
};
|
|
198
198
|
// For non constant color channel.
|
|
199
199
|
if (invertAble(scaleSeries)) return scaleSeries.invert(series);
|
|
200
|
-
if (
|
|
200
|
+
if (
|
|
201
|
+
series &&
|
|
202
|
+
scaleSeries instanceof Band &&
|
|
203
|
+
scaleSeries.invert(series) !== color &&
|
|
204
|
+
!facet
|
|
205
|
+
) {
|
|
206
|
+
return scaleSeries.invert(series);
|
|
207
|
+
}
|
|
201
208
|
if (invertAble(scaleColor)) {
|
|
202
209
|
const name = scaleColor.invert(color);
|
|
203
210
|
// For threshold scale.
|
|
@@ -723,6 +730,7 @@ export function tooltip(
|
|
|
723
730
|
view,
|
|
724
731
|
mount,
|
|
725
732
|
bounding,
|
|
733
|
+
shared = false,
|
|
726
734
|
body = true,
|
|
727
735
|
disableNative = false,
|
|
728
736
|
}: Record<string, any>,
|
|
@@ -741,7 +749,7 @@ export function tooltip(
|
|
|
741
749
|
const k = groupKey(element);
|
|
742
750
|
const group = keyGroup.get(k);
|
|
743
751
|
const data =
|
|
744
|
-
group.length === 1
|
|
752
|
+
group.length === 1 && !shared
|
|
745
753
|
? singleItem(group[0])
|
|
746
754
|
: groupItems(group, scale, groupName);
|
|
747
755
|
|
|
@@ -896,6 +904,7 @@ export function Tooltip(options) {
|
|
|
896
904
|
const bbox = plotArea.getBounds();
|
|
897
905
|
const startX = bbox.min[0];
|
|
898
906
|
const startY = bbox.min[1];
|
|
907
|
+
Object.assign(scale, { facet: true });
|
|
899
908
|
|
|
900
909
|
// @todo Nested structure rather than flat structure for facet?
|
|
901
910
|
// Add listener to the root area.
|
|
@@ -923,6 +932,7 @@ export function Tooltip(options) {
|
|
|
923
932
|
item,
|
|
924
933
|
emitter,
|
|
925
934
|
view,
|
|
935
|
+
shared,
|
|
926
936
|
});
|
|
927
937
|
};
|
|
928
938
|
}
|
package/src/lib/plot.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Boxplot, WordCloud, Gauge } from '../mark';
|
|
1
|
+
import { Boxplot, WordCloud, Gauge, Liquid } from '../mark';
|
|
2
2
|
import { Venn } from '../data';
|
|
3
3
|
|
|
4
4
|
export function plotlib() {
|
|
@@ -7,5 +7,6 @@ export function plotlib() {
|
|
|
7
7
|
'mark.boxplot': Boxplot,
|
|
8
8
|
'mark.gauge': Gauge,
|
|
9
9
|
'mark.wordCloud': WordCloud,
|
|
10
|
+
'mark.liquid': Liquid,
|
|
10
11
|
} as const;
|
|
11
12
|
}
|
package/src/mark/area.ts
CHANGED
package/src/mark/gauge.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deepMix } from '@antv/util';
|
|
1
|
+
import { deepMix, isNumber } from '@antv/util';
|
|
2
2
|
import { Vector2 } from '@antv/coord';
|
|
3
3
|
import { Group } from '@antv/g';
|
|
4
4
|
import { filterPrefixObject, isUnset, subObject } from '../utils/helper';
|
|
@@ -124,16 +124,37 @@ const DEFAULT_TEXT_OPTIONS = {
|
|
|
124
124
|
},
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
export type GaugeData =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
export type GaugeData =
|
|
128
|
+
| {
|
|
129
|
+
target?: number;
|
|
130
|
+
total?: number;
|
|
131
|
+
percent?: number;
|
|
132
|
+
name?: string;
|
|
133
|
+
thresholds?: number[];
|
|
134
|
+
}
|
|
135
|
+
| number;
|
|
136
|
+
|
|
137
|
+
function getGaugeData(data: GaugeData) {
|
|
138
|
+
if (isNumber(data)) {
|
|
139
|
+
// Percent range [0, 1].
|
|
140
|
+
const percent = Math.max(0, Math.min(data, 1));
|
|
141
|
+
return {
|
|
142
|
+
percent,
|
|
143
|
+
target: percent,
|
|
144
|
+
total: 1,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
134
149
|
|
|
135
150
|
function dataTransform(data: GaugeData, scale) {
|
|
136
|
-
const {
|
|
151
|
+
const {
|
|
152
|
+
name = 'score',
|
|
153
|
+
target,
|
|
154
|
+
total,
|
|
155
|
+
percent,
|
|
156
|
+
thresholds = [],
|
|
157
|
+
} = getGaugeData(data);
|
|
137
158
|
const _target = percent || target;
|
|
138
159
|
const _total = percent ? 1 : total;
|
|
139
160
|
const newScale = {
|
package/src/mark/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export { WordCloud } from './wordCloud';
|
|
|
30
30
|
export { Gauge } from './gauge';
|
|
31
31
|
export { Density } from './density';
|
|
32
32
|
export { Heatmap } from './heatmap';
|
|
33
|
+
export { Liquid } from './liquid';
|
|
33
34
|
|
|
34
35
|
export type { IntervalOptions } from './interval';
|
|
35
36
|
export type { RectOptions } from './rect';
|
|
@@ -59,3 +60,4 @@ export type { WordCloudOptions } from './wordCloud';
|
|
|
59
60
|
export type { GaugeOptions } from './gauge';
|
|
60
61
|
export type { DensityOptions } from './density';
|
|
61
62
|
export type { HeatmapOptions } from './heatmap';
|
|
63
|
+
export type { LiquidOptions } from './liquid';
|
package/src/mark/line.ts
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { deepMix, isNumber } from '@antv/util';
|
|
2
|
+
import { subObject } from '../utils/helper';
|
|
3
|
+
import { CompositeMarkComponent as CC } from '../runtime';
|
|
4
|
+
import { LiquidMark } from '../spec';
|
|
5
|
+
import { LiquidShape } from '../shape';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_OPTIONS = {
|
|
8
|
+
axis: {
|
|
9
|
+
x: false,
|
|
10
|
+
y: false,
|
|
11
|
+
},
|
|
12
|
+
legend: false,
|
|
13
|
+
tooltip: false,
|
|
14
|
+
encode: {
|
|
15
|
+
x: 'type',
|
|
16
|
+
y: 'percent',
|
|
17
|
+
},
|
|
18
|
+
scale: {
|
|
19
|
+
y: {
|
|
20
|
+
domain: [0, 1],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
style: {
|
|
24
|
+
shape: LiquidShape,
|
|
25
|
+
},
|
|
26
|
+
animate: {
|
|
27
|
+
enter: {
|
|
28
|
+
type: 'fadeIn',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const DEFAULT_TEXT_OPTIONS = {
|
|
34
|
+
type: 'text',
|
|
35
|
+
style: {
|
|
36
|
+
x: '50%',
|
|
37
|
+
y: '50%',
|
|
38
|
+
textAlign: 'center',
|
|
39
|
+
textBaseline: 'middle',
|
|
40
|
+
fontSize: 20,
|
|
41
|
+
fontWeight: 800,
|
|
42
|
+
fill: '#888',
|
|
43
|
+
},
|
|
44
|
+
animate: {
|
|
45
|
+
enter: {
|
|
46
|
+
type: 'fadeIn',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type LiquidData =
|
|
52
|
+
| {
|
|
53
|
+
percent?: number;
|
|
54
|
+
}
|
|
55
|
+
| number;
|
|
56
|
+
|
|
57
|
+
export type LiquidOptions = Omit<LiquidMark, 'type'>;
|
|
58
|
+
|
|
59
|
+
export const Liquid: CC<LiquidOptions> = (options) => {
|
|
60
|
+
const { data = {}, style = {}, animate, ...resOptions } = options;
|
|
61
|
+
// Compatible with old data structures: { percent: number } and percent >= 0.
|
|
62
|
+
const percent = Math.max(0, isNumber(data) ? data : data?.percent);
|
|
63
|
+
|
|
64
|
+
const newData = [{ percent, type: 'liquid' }];
|
|
65
|
+
|
|
66
|
+
const textStyle = subObject(style, 'text');
|
|
67
|
+
const outline = subObject(style, 'outline');
|
|
68
|
+
const wave = subObject(style, 'wave');
|
|
69
|
+
const background = subObject(style, 'background');
|
|
70
|
+
|
|
71
|
+
return [
|
|
72
|
+
deepMix({}, DEFAULT_OPTIONS, {
|
|
73
|
+
type: 'interval',
|
|
74
|
+
data: newData,
|
|
75
|
+
style: {
|
|
76
|
+
liquidOptions: {
|
|
77
|
+
percent,
|
|
78
|
+
liquidShape: style?.shape,
|
|
79
|
+
},
|
|
80
|
+
styleOptions: {
|
|
81
|
+
...style,
|
|
82
|
+
outline,
|
|
83
|
+
wave,
|
|
84
|
+
background,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
animate,
|
|
88
|
+
...resOptions,
|
|
89
|
+
}),
|
|
90
|
+
deepMix({}, DEFAULT_TEXT_OPTIONS, {
|
|
91
|
+
style: {
|
|
92
|
+
text: `${percent * 100} %`,
|
|
93
|
+
...textStyle,
|
|
94
|
+
},
|
|
95
|
+
animate,
|
|
96
|
+
}),
|
|
97
|
+
];
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Liquid.props = {};
|
package/src/runtime/plot.ts
CHANGED
|
@@ -422,11 +422,14 @@ async function initializeView(
|
|
|
422
422
|
const flattenOptions = await transformMarks(options, library);
|
|
423
423
|
|
|
424
424
|
const mergedOptions = bubbleOptions(flattenOptions);
|
|
425
|
+
|
|
425
426
|
// @todo Remove this.
|
|
426
427
|
// !!! NOTE: Mute original view options.
|
|
427
428
|
// Update interaction and coordinate for this view.
|
|
428
429
|
options.interaction = mergedOptions.interaction;
|
|
429
430
|
options.coordinate = mergedOptions.coordinate;
|
|
431
|
+
// @ts-ignore
|
|
432
|
+
options.marks = [...mergedOptions.marks, ...mergedOptions.components];
|
|
430
433
|
|
|
431
434
|
const transformedOptions = coordinate2Transform(mergedOptions, library);
|
|
432
435
|
const state = await initializeMarks(transformedOptions, library);
|
package/src/runtime/transform.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Primitive } from 'd3-array';
|
|
2
|
-
import { deepMix } from '@antv/util';
|
|
2
|
+
import { deepMix, isNumber } from '@antv/util';
|
|
3
3
|
import { format } from 'd3-format';
|
|
4
4
|
import { indexOf, mapObject } from '../utils/array';
|
|
5
5
|
import {
|
|
@@ -336,6 +336,8 @@ function isField(data: Record<string, Primitive>[], value: string): boolean {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
function normalizedDataSource(data) {
|
|
339
|
+
// Liquid、Gauge need number data.
|
|
340
|
+
if (isNumber(data)) return { type: 'inline', value: data };
|
|
339
341
|
// Return null as a placeholder.
|
|
340
342
|
if (!data) return { type: 'inline', value: null };
|
|
341
343
|
if (Array.isArray(data)) return { type: 'inline', value: data };
|