@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
package/src/shape/index.ts
CHANGED
|
@@ -60,6 +60,7 @@ export { Rect as RangeShape } from './interval/rect';
|
|
|
60
60
|
export { Rect as RectShape } from './interval/rect';
|
|
61
61
|
export { Hollow as RectHollow } from './interval/hollow';
|
|
62
62
|
export { Shape as ShapeShape } from './shape/shape';
|
|
63
|
+
export { Liquid as LiquidShape } from './liquid/liquid';
|
|
63
64
|
|
|
64
65
|
export type { RectOptions as IntervalShapeOptions } from './interval/rect';
|
|
65
66
|
export type { HollowOptions as IntervalHollowOptions } from './interval/hollow';
|
|
@@ -109,3 +110,4 @@ export type { ConnectorOptions as ConnectorShapeOptions } from './connector/conn
|
|
|
109
110
|
export type { LabelOptions as LabelShapeOptions } from './label/label';
|
|
110
111
|
export type { DensityOptions as DensityShapeOptions } from './density/density';
|
|
111
112
|
export type { ShapeOptions as ShapeShapeOptions } from './shape/shape';
|
|
113
|
+
export type { LiquidOptions } from './liquid/liquid';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { isFunction } from '@antv/util';
|
|
2
|
+
import type { PathStyleProps } from '@antv/g';
|
|
3
|
+
import type { ShapeComponent as SC } from '../../runtime';
|
|
4
|
+
import { addWave } from './wave';
|
|
5
|
+
import { LiquidShapesPath } from './shapes';
|
|
6
|
+
|
|
7
|
+
const getLiquidShape = (shape = 'circle') =>
|
|
8
|
+
LiquidShapesPath[shape] || LiquidShapesPath.circle;
|
|
9
|
+
|
|
10
|
+
export type LiquidOptions = Record<string, any>;
|
|
11
|
+
|
|
12
|
+
export const Liquid: SC<LiquidOptions> = (options, context) => {
|
|
13
|
+
if (!context) return;
|
|
14
|
+
const { coordinate } = context;
|
|
15
|
+
const { liquidOptions, styleOptions } = options;
|
|
16
|
+
const { liquidShape, percent } = liquidOptions;
|
|
17
|
+
const {
|
|
18
|
+
background: backgroundStyle,
|
|
19
|
+
outline = {},
|
|
20
|
+
wave = {},
|
|
21
|
+
...attr
|
|
22
|
+
} = styleOptions;
|
|
23
|
+
const { border = 2, distance = 0, ...outlineStyle } = outline;
|
|
24
|
+
const { length = 192, count = 3 } = wave;
|
|
25
|
+
|
|
26
|
+
return (points, cfg, defaultAttr) => {
|
|
27
|
+
const { document } = context.canvas;
|
|
28
|
+
const { color, fillOpacity } = defaultAttr;
|
|
29
|
+
const attrs = { fill: color, ...defaultAttr, ...attr } as PathStyleProps;
|
|
30
|
+
|
|
31
|
+
const g = document.createElement('g', {});
|
|
32
|
+
|
|
33
|
+
// Center x/y.
|
|
34
|
+
const [centerX, centerY] = coordinate.getCenter();
|
|
35
|
+
// [width,height].
|
|
36
|
+
const size = coordinate.getSize();
|
|
37
|
+
const radius = Math.min(...size) / 2;
|
|
38
|
+
|
|
39
|
+
// 1、Gets the path of the overall shape.
|
|
40
|
+
const buildPath = isFunction(liquidShape)
|
|
41
|
+
? liquidShape
|
|
42
|
+
: getLiquidShape(liquidShape);
|
|
43
|
+
const shapePath = buildPath(centerX, centerY, radius, ...size);
|
|
44
|
+
|
|
45
|
+
// 2、Background create.
|
|
46
|
+
if (Object.keys(backgroundStyle).length) {
|
|
47
|
+
const backgroundShape = document.createElement('path', {
|
|
48
|
+
style: {
|
|
49
|
+
path: shapePath,
|
|
50
|
+
fill: '#fff',
|
|
51
|
+
...backgroundStyle,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
g.appendChild(backgroundShape);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Percent > 0 Mapping water waves.
|
|
59
|
+
if (percent > 0) {
|
|
60
|
+
// 3. Clip create.
|
|
61
|
+
const clipShape = document.createElement('path', {
|
|
62
|
+
style: {
|
|
63
|
+
path: shapePath,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
g.appendChild(clipShape);
|
|
68
|
+
g.style.clipPath = clipShape;
|
|
69
|
+
|
|
70
|
+
// 4. Wave create.
|
|
71
|
+
addWave(
|
|
72
|
+
centerX,
|
|
73
|
+
centerY,
|
|
74
|
+
1 - percent,
|
|
75
|
+
count,
|
|
76
|
+
attrs,
|
|
77
|
+
g,
|
|
78
|
+
clipShape.getBBox().y,
|
|
79
|
+
radius * 2,
|
|
80
|
+
length,
|
|
81
|
+
true,
|
|
82
|
+
document,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 5. Draw distance.
|
|
87
|
+
const distanceShape = document.createElement('path', {
|
|
88
|
+
style: {
|
|
89
|
+
path: shapePath,
|
|
90
|
+
fill: 'transparent',
|
|
91
|
+
lineWidth: border + 2 * distance,
|
|
92
|
+
stroke: '#fff',
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// 6. Draw border.
|
|
97
|
+
const borderShape = document.createElement('path', {
|
|
98
|
+
style: {
|
|
99
|
+
path: shapePath,
|
|
100
|
+
stroke: color,
|
|
101
|
+
strokeOpacity: fillOpacity,
|
|
102
|
+
lineWidth: border,
|
|
103
|
+
...attrs,
|
|
104
|
+
...outlineStyle,
|
|
105
|
+
fill: 'transparent',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
g.appendChild(distanceShape);
|
|
110
|
+
g.appendChild(borderShape);
|
|
111
|
+
|
|
112
|
+
return g;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Liquid.props = {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param x center x
|
|
3
|
+
* @param y center y
|
|
4
|
+
* @param radius
|
|
5
|
+
*/
|
|
6
|
+
function circle(x: number, y: number, r: number) {
|
|
7
|
+
return `
|
|
8
|
+
M ${x} ${y - r}
|
|
9
|
+
a ${r} ${r} 0 1 0 0 ${r * 2}
|
|
10
|
+
a ${r} ${r} 0 1 0 0 ${-r * 2}
|
|
11
|
+
Z
|
|
12
|
+
`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param x center x
|
|
17
|
+
* @param y center y
|
|
18
|
+
* @param radius
|
|
19
|
+
*/
|
|
20
|
+
function rect(x: number, y: number, r: number) {
|
|
21
|
+
const GOLDEN_SECTION_RATIO = 0.618;
|
|
22
|
+
const w = r * GOLDEN_SECTION_RATIO;
|
|
23
|
+
return `
|
|
24
|
+
M ${x - w} ${y - r}
|
|
25
|
+
L ${x + w} ${y - r}
|
|
26
|
+
L ${x + w} ${y + r}
|
|
27
|
+
L ${x - w} ${y + r}
|
|
28
|
+
Z
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param x center x
|
|
34
|
+
* @param y center y
|
|
35
|
+
* @param radius
|
|
36
|
+
*/
|
|
37
|
+
function diamond(x: number, y: number, r: number) {
|
|
38
|
+
return `
|
|
39
|
+
M ${x} ${y - r}
|
|
40
|
+
L ${x + r} ${y}
|
|
41
|
+
L ${x} ${y + r}
|
|
42
|
+
L ${x - r} ${y}
|
|
43
|
+
Z
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param x center x
|
|
49
|
+
* @param y center y
|
|
50
|
+
* @param radius
|
|
51
|
+
*/
|
|
52
|
+
function triangle(x: number, y: number, r: number) {
|
|
53
|
+
return `
|
|
54
|
+
M ${x} ${y - r}
|
|
55
|
+
L ${x + r} ${y + r}
|
|
56
|
+
L ${x - r} ${y + r}
|
|
57
|
+
Z
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param x center x
|
|
63
|
+
* @param y center y
|
|
64
|
+
* @param radius
|
|
65
|
+
*/
|
|
66
|
+
function pin(x: number, y: number, radius: number) {
|
|
67
|
+
const w = (radius * 4) / 3;
|
|
68
|
+
const h = Math.max(w, radius * 2);
|
|
69
|
+
const r = w / 2;
|
|
70
|
+
|
|
71
|
+
// Attrs of the upper circle.
|
|
72
|
+
const cx = x;
|
|
73
|
+
const cy = r + y - h / 2;
|
|
74
|
+
const theta = Math.asin(r / ((h - r) * 0.85));
|
|
75
|
+
const dy = Math.sin(theta) * r;
|
|
76
|
+
const dx = Math.cos(theta) * r;
|
|
77
|
+
|
|
78
|
+
// The start point of the path.
|
|
79
|
+
const x0 = cx - dx;
|
|
80
|
+
const y0 = cy + dy;
|
|
81
|
+
|
|
82
|
+
// Control point.
|
|
83
|
+
const cpX = x;
|
|
84
|
+
const cpY = cy + r / Math.sin(theta);
|
|
85
|
+
|
|
86
|
+
return `
|
|
87
|
+
M ${x0} ${y0}
|
|
88
|
+
A ${r} ${r} 0 1 1 ${x0 + dx * 2} ${y0}
|
|
89
|
+
Q ${cpX} ${cpY} ${x} ${y + h / 2}
|
|
90
|
+
Q ${cpX} ${cpY} ${x0} ${y0}
|
|
91
|
+
Z
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const LiquidShapesPath = {
|
|
96
|
+
pin,
|
|
97
|
+
rect,
|
|
98
|
+
circle,
|
|
99
|
+
diamond,
|
|
100
|
+
triangle,
|
|
101
|
+
};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { PathStyleProps, IAnimation } from '@antv/g';
|
|
2
|
+
|
|
3
|
+
const DURATION = 5000;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A function of linear mapping.
|
|
7
|
+
* @param min
|
|
8
|
+
* @param max
|
|
9
|
+
* @param factor
|
|
10
|
+
*/
|
|
11
|
+
function lerp(min: number, max: number, factor: number) {
|
|
12
|
+
return min + (max - min) * factor;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Using Bessel curve to simulate sine wave.
|
|
17
|
+
* Using Bezier curves to fit sine wave.
|
|
18
|
+
* There is 4 control points for each curve of wave,
|
|
19
|
+
* which is at 1/4 wave length of the sine wave.
|
|
20
|
+
*
|
|
21
|
+
* The control points for a wave from (a) to (d) are a-b-c-d:
|
|
22
|
+
* c *----* d
|
|
23
|
+
* b *
|
|
24
|
+
* |
|
|
25
|
+
* ... a * ..................
|
|
26
|
+
*
|
|
27
|
+
* Whose positions are a: (0, 0), b: (0.5, 0.5), c: (1, 1), d: (PI / 2, 1).
|
|
28
|
+
*
|
|
29
|
+
* @param x x position of the left-most point (a).
|
|
30
|
+
* @param stage 0-3, stating which part of the wave it is.
|
|
31
|
+
* @param waveLength wave length of the sine wave.
|
|
32
|
+
* @param amplitude wave amplitude.
|
|
33
|
+
* @return Sinusoidal segment curve.
|
|
34
|
+
*/
|
|
35
|
+
function getWaterWavePositions(
|
|
36
|
+
x: number,
|
|
37
|
+
stage: number,
|
|
38
|
+
waveLength: number,
|
|
39
|
+
amplitude: number,
|
|
40
|
+
) {
|
|
41
|
+
if (stage === 0) {
|
|
42
|
+
return [
|
|
43
|
+
[x + ((1 / 2) * waveLength) / Math.PI / 2, amplitude / 2],
|
|
44
|
+
[x + ((1 / 2) * waveLength) / Math.PI, amplitude],
|
|
45
|
+
[x + waveLength / 4, amplitude],
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
if (stage === 1) {
|
|
49
|
+
return [
|
|
50
|
+
[x + (((1 / 2) * waveLength) / Math.PI / 2) * (Math.PI - 2), amplitude],
|
|
51
|
+
[
|
|
52
|
+
x + (((1 / 2) * waveLength) / Math.PI / 2) * (Math.PI - 1),
|
|
53
|
+
amplitude / 2,
|
|
54
|
+
],
|
|
55
|
+
[x + waveLength / 4, 0],
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
if (stage === 2) {
|
|
59
|
+
return [
|
|
60
|
+
[x + ((1 / 2) * waveLength) / Math.PI / 2, -amplitude / 2],
|
|
61
|
+
[x + ((1 / 2) * waveLength) / Math.PI, -amplitude],
|
|
62
|
+
[x + waveLength / 4, -amplitude],
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
return [
|
|
66
|
+
[x + (((1 / 2) * waveLength) / Math.PI / 2) * (Math.PI - 2), -amplitude],
|
|
67
|
+
[
|
|
68
|
+
x + (((1 / 2) * waveLength) / Math.PI / 2) * (Math.PI - 1),
|
|
69
|
+
-amplitude / 2,
|
|
70
|
+
],
|
|
71
|
+
[x + waveLength / 4, 0],
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get wave path.
|
|
77
|
+
* @param radius
|
|
78
|
+
* @param waterLevel water level
|
|
79
|
+
* @param waveLength wave length
|
|
80
|
+
* @param phase
|
|
81
|
+
* @param amplitude
|
|
82
|
+
* @param cx center x
|
|
83
|
+
* @param cy center y
|
|
84
|
+
* @return path path
|
|
85
|
+
*/
|
|
86
|
+
function getWaterWavePath(
|
|
87
|
+
radius: number,
|
|
88
|
+
waterLevel: number,
|
|
89
|
+
waveLength: number,
|
|
90
|
+
phase: number,
|
|
91
|
+
amplitude: number,
|
|
92
|
+
cx: number,
|
|
93
|
+
cy: number,
|
|
94
|
+
) {
|
|
95
|
+
const curves = Math.ceil(((2 * radius) / waveLength) * 4) * 4;
|
|
96
|
+
const path = [];
|
|
97
|
+
let _phase = phase;
|
|
98
|
+
|
|
99
|
+
// Map phase to [-Math.PI * 2, 0].
|
|
100
|
+
while (_phase < -Math.PI * 2) {
|
|
101
|
+
_phase += Math.PI * 2;
|
|
102
|
+
}
|
|
103
|
+
while (_phase > 0) {
|
|
104
|
+
_phase -= Math.PI * 2;
|
|
105
|
+
}
|
|
106
|
+
_phase = (_phase / Math.PI / 2) * waveLength;
|
|
107
|
+
|
|
108
|
+
const left = cx - radius + _phase - radius * 2;
|
|
109
|
+
/**
|
|
110
|
+
* Top-left corner as start point.
|
|
111
|
+
*
|
|
112
|
+
* Draws this point.
|
|
113
|
+
* |
|
|
114
|
+
* \|/
|
|
115
|
+
* ~~~~~~~~
|
|
116
|
+
* | |
|
|
117
|
+
* +------+
|
|
118
|
+
*/
|
|
119
|
+
path.push(['M', left, waterLevel]);
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Top wave.
|
|
123
|
+
*
|
|
124
|
+
* ~~~~~~~~ <- Draws this sine wave.
|
|
125
|
+
* | |
|
|
126
|
+
* +------+
|
|
127
|
+
*/
|
|
128
|
+
let waveRight = 0;
|
|
129
|
+
for (let c = 0; c < curves; ++c) {
|
|
130
|
+
const stage = c % 4;
|
|
131
|
+
const pos = getWaterWavePositions(
|
|
132
|
+
(c * waveLength) / 4,
|
|
133
|
+
stage,
|
|
134
|
+
waveLength,
|
|
135
|
+
amplitude,
|
|
136
|
+
);
|
|
137
|
+
path.push([
|
|
138
|
+
'C',
|
|
139
|
+
pos[0][0] + left,
|
|
140
|
+
-pos[0][1] + waterLevel,
|
|
141
|
+
pos[1][0] + left,
|
|
142
|
+
-pos[1][1] + waterLevel,
|
|
143
|
+
pos[2][0] + left,
|
|
144
|
+
-pos[2][1] + waterLevel,
|
|
145
|
+
]);
|
|
146
|
+
|
|
147
|
+
if (c === curves - 1) {
|
|
148
|
+
waveRight = pos[2][0];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Top-right corner.
|
|
154
|
+
*
|
|
155
|
+
* ~~~~~~~~
|
|
156
|
+
* 3. Draws this line. -> | | <- 1. Draws this line.
|
|
157
|
+
* +------+
|
|
158
|
+
* ^
|
|
159
|
+
* |
|
|
160
|
+
* 2. Draws this line.
|
|
161
|
+
*/
|
|
162
|
+
path.push(['L', waveRight + left, cy + radius]);
|
|
163
|
+
path.push(['L', left, cy + radius]);
|
|
164
|
+
path.push(['Z']);
|
|
165
|
+
|
|
166
|
+
return path;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Add wave.
|
|
171
|
+
* @param x center x
|
|
172
|
+
* @param y center y
|
|
173
|
+
* @param level wave level 0~1
|
|
174
|
+
* @param waveCount wave count
|
|
175
|
+
* @param waveAttrs style
|
|
176
|
+
* @param group g
|
|
177
|
+
* @param minY Minimum height
|
|
178
|
+
* @param radius radius
|
|
179
|
+
* @param waveLength wave length
|
|
180
|
+
* @param animation animation config
|
|
181
|
+
* @param document
|
|
182
|
+
*/
|
|
183
|
+
export function addWave(
|
|
184
|
+
x: number,
|
|
185
|
+
y: number,
|
|
186
|
+
level: number,
|
|
187
|
+
waveCount: number,
|
|
188
|
+
waveAttrs: PathStyleProps,
|
|
189
|
+
group: any,
|
|
190
|
+
minY: number,
|
|
191
|
+
radius: number,
|
|
192
|
+
waveLength: number,
|
|
193
|
+
animation: IAnimation | boolean,
|
|
194
|
+
document: any,
|
|
195
|
+
) {
|
|
196
|
+
// Box property Color width height.
|
|
197
|
+
const { fill, fillOpacity, opacity } = waveAttrs;
|
|
198
|
+
|
|
199
|
+
// Number of cyclic waveCount.
|
|
200
|
+
for (let idx = 0; idx < waveCount; idx++) {
|
|
201
|
+
const factor = waveCount <= 1 ? 1 : idx / (waveCount - 1);
|
|
202
|
+
|
|
203
|
+
const path = getWaterWavePath(
|
|
204
|
+
radius,
|
|
205
|
+
minY + radius * level,
|
|
206
|
+
waveLength,
|
|
207
|
+
0,
|
|
208
|
+
// Amplitude height.
|
|
209
|
+
radius / 40,
|
|
210
|
+
x,
|
|
211
|
+
y,
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
// Create wave path.
|
|
215
|
+
const wave = document.createElement('path', {
|
|
216
|
+
style: {
|
|
217
|
+
path,
|
|
218
|
+
fill,
|
|
219
|
+
opacity: lerp(0.2, 0.9, factor) * Number(opacity || fillOpacity),
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
group.appendChild(wave);
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
if (animation === false) return;
|
|
227
|
+
|
|
228
|
+
const keyframes = [
|
|
229
|
+
{
|
|
230
|
+
transform: 'translate(0, 0)',
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
transform: `translate(${waveLength * 2}px, 0)`,
|
|
234
|
+
},
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
wave.animate(keyframes, {
|
|
238
|
+
duration: lerp(0.5 * DURATION, DURATION, factor) * 2,
|
|
239
|
+
iterations: Infinity,
|
|
240
|
+
});
|
|
241
|
+
} catch (e) {
|
|
242
|
+
console.warn('off-screen group animate error!');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
package/src/spec/mark.ts
CHANGED
|
@@ -83,6 +83,7 @@ export type MarkTypes =
|
|
|
83
83
|
| 'gauge'
|
|
84
84
|
| 'density'
|
|
85
85
|
| 'heatmap'
|
|
86
|
+
| 'liquid'
|
|
86
87
|
| MarkComponent
|
|
87
88
|
| CompositeMarkType;
|
|
88
89
|
|
|
@@ -387,5 +388,6 @@ export type GaugeMark = BaseMark<
|
|
|
387
388
|
|
|
388
389
|
export type DensityMark = BaseMark<'density', ChannelTypes | 'series'>;
|
|
389
390
|
export type HeatmapMark = BaseMark<'heatmap'>;
|
|
391
|
+
export type LiquidMark = BaseMark<'liquid'>;
|
|
390
392
|
|
|
391
393
|
export type CustomMark = BaseMark<MarkComponent, ChannelTypes>;
|
package/src/utils/helper.ts
CHANGED
|
@@ -45,7 +45,15 @@ export function copyAttributes(target: DisplayObject, source: DisplayObject) {
|
|
|
45
45
|
const { attributes } = source;
|
|
46
46
|
const exclude = new Set(['id', 'className']);
|
|
47
47
|
for (const [key, value] of Object.entries(attributes)) {
|
|
48
|
-
if (!exclude.has(key))
|
|
48
|
+
if (!exclude.has(key)) {
|
|
49
|
+
// @todo Fix in @antv/g
|
|
50
|
+
if (key === 'transform') {
|
|
51
|
+
target.attr(key, '');
|
|
52
|
+
target.attr(key, value);
|
|
53
|
+
} else {
|
|
54
|
+
target.attr(key, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
|