@antv/g2 5.1.1 → 5.1.3

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.
Files changed (133) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +6 -6
  3. package/README.zh-CN.md +6 -6
  4. package/dist/g2-lite.min.js +1 -1
  5. package/dist/g2.min.js +1 -1
  6. package/esm/api/chart.d.ts +7 -1
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/api/extend.d.ts +2 -1
  9. package/esm/api/index.d.ts +1 -3
  10. package/esm/api/index.js +1 -3
  11. package/esm/api/index.js.map +1 -1
  12. package/esm/api/library.d.ts +1 -0
  13. package/esm/api/runtime.js +1 -0
  14. package/esm/api/runtime.js.map +1 -1
  15. package/esm/index.d.ts +1 -1
  16. package/esm/index.js +1 -1
  17. package/esm/index.js.map +1 -1
  18. package/esm/interaction/tooltip.d.ts +1 -1
  19. package/esm/interaction/tooltip.js +14 -8
  20. package/esm/interaction/tooltip.js.map +1 -1
  21. package/esm/interaction/utils.js +4 -2
  22. package/esm/interaction/utils.js.map +1 -1
  23. package/esm/lib/plot.d.ts +1 -0
  24. package/esm/lib/plot.js +2 -1
  25. package/esm/lib/plot.js.map +1 -1
  26. package/esm/lib/std.d.ts +1 -0
  27. package/esm/mark/area.js +1 -1
  28. package/esm/mark/area.js.map +1 -1
  29. package/esm/mark/gauge.d.ts +1 -1
  30. package/esm/mark/gauge.js +14 -2
  31. package/esm/mark/gauge.js.map +1 -1
  32. package/esm/mark/index.d.ts +2 -0
  33. package/esm/mark/index.js +1 -0
  34. package/esm/mark/index.js.map +1 -1
  35. package/esm/mark/line.js +1 -1
  36. package/esm/mark/line.js.map +1 -1
  37. package/esm/mark/liquid.d.ts +7 -0
  38. package/esm/mark/liquid.js +83 -0
  39. package/esm/mark/liquid.js.map +1 -0
  40. package/esm/runtime/plot.js +2 -0
  41. package/esm/runtime/plot.js.map +1 -1
  42. package/esm/runtime/transform.js +4 -1
  43. package/esm/runtime/transform.js.map +1 -1
  44. package/esm/shape/index.d.ts +2 -0
  45. package/esm/shape/index.js +1 -0
  46. package/esm/shape/index.js.map +1 -1
  47. package/esm/shape/liquid/liquid.d.ts +3 -0
  48. package/esm/shape/liquid/liquid.js +79 -0
  49. package/esm/shape/liquid/liquid.js.map +1 -0
  50. package/esm/shape/liquid/shapes.d.ts +38 -0
  51. package/esm/shape/liquid/shapes.js +93 -0
  52. package/esm/shape/liquid/shapes.js.map +1 -0
  53. package/esm/shape/liquid/wave.d.ts +16 -0
  54. package/esm/shape/liquid/wave.js +192 -0
  55. package/esm/shape/liquid/wave.js.map +1 -0
  56. package/esm/spec/mark.d.ts +2 -1
  57. package/esm/utils/helper.js +10 -2
  58. package/esm/utils/helper.js.map +1 -1
  59. package/lib/api/chart.d.ts +7 -1
  60. package/lib/api/chart.js.map +1 -1
  61. package/lib/api/extend.d.ts +2 -1
  62. package/lib/api/index.d.ts +1 -3
  63. package/lib/api/index.js +1 -5
  64. package/lib/api/index.js.map +1 -1
  65. package/lib/api/library.d.ts +1 -0
  66. package/lib/api/runtime.js +1 -0
  67. package/lib/api/runtime.js.map +1 -1
  68. package/lib/index.d.ts +1 -1
  69. package/lib/index.js +1 -3
  70. package/lib/index.js.map +1 -1
  71. package/lib/interaction/tooltip.d.ts +1 -1
  72. package/lib/interaction/tooltip.js +13 -7
  73. package/lib/interaction/tooltip.js.map +1 -1
  74. package/lib/interaction/utils.js +4 -2
  75. package/lib/interaction/utils.js.map +1 -1
  76. package/lib/lib/plot.d.ts +1 -0
  77. package/lib/lib/plot.js +1 -0
  78. package/lib/lib/plot.js.map +1 -1
  79. package/lib/lib/std.d.ts +1 -0
  80. package/lib/mark/area.js +1 -1
  81. package/lib/mark/area.js.map +1 -1
  82. package/lib/mark/gauge.d.ts +1 -1
  83. package/lib/mark/gauge.js +13 -1
  84. package/lib/mark/gauge.js.map +1 -1
  85. package/lib/mark/index.d.ts +2 -0
  86. package/lib/mark/index.js +3 -1
  87. package/lib/mark/index.js.map +1 -1
  88. package/lib/mark/line.js +1 -1
  89. package/lib/mark/line.js.map +1 -1
  90. package/lib/mark/liquid.d.ts +7 -0
  91. package/lib/mark/liquid.js +87 -0
  92. package/lib/mark/liquid.js.map +1 -0
  93. package/lib/runtime/plot.js +2 -0
  94. package/lib/runtime/plot.js.map +1 -1
  95. package/lib/runtime/transform.js +3 -0
  96. package/lib/runtime/transform.js.map +1 -1
  97. package/lib/shape/index.d.ts +2 -0
  98. package/lib/shape/index.js +3 -1
  99. package/lib/shape/index.js.map +1 -1
  100. package/lib/shape/liquid/liquid.d.ts +3 -0
  101. package/lib/shape/liquid/liquid.js +83 -0
  102. package/lib/shape/liquid/liquid.js.map +1 -0
  103. package/lib/shape/liquid/shapes.d.ts +38 -0
  104. package/lib/shape/liquid/shapes.js +96 -0
  105. package/lib/shape/liquid/shapes.js.map +1 -0
  106. package/lib/shape/liquid/wave.d.ts +16 -0
  107. package/lib/shape/liquid/wave.js +196 -0
  108. package/lib/shape/liquid/wave.js.map +1 -0
  109. package/lib/spec/mark.d.ts +2 -1
  110. package/lib/utils/helper.js +10 -2
  111. package/lib/utils/helper.js.map +1 -1
  112. package/package.json +1 -1
  113. package/src/api/chart.ts +6 -1
  114. package/src/api/extend.ts +11 -11
  115. package/src/api/index.ts +6 -3
  116. package/src/api/runtime.ts +1 -0
  117. package/src/index.ts +2 -2
  118. package/src/interaction/tooltip.ts +15 -5
  119. package/src/interaction/utils.ts +5 -2
  120. package/src/lib/plot.ts +2 -1
  121. package/src/mark/area.ts +1 -1
  122. package/src/mark/gauge.ts +30 -9
  123. package/src/mark/index.ts +2 -0
  124. package/src/mark/line.ts +1 -1
  125. package/src/mark/liquid.ts +100 -0
  126. package/src/runtime/plot.ts +3 -0
  127. package/src/runtime/transform.ts +3 -1
  128. package/src/shape/index.ts +2 -0
  129. package/src/shape/liquid/liquid.ts +116 -0
  130. package/src/shape/liquid/shapes.ts +101 -0
  131. package/src/shape/liquid/wave.ts +245 -0
  132. package/src/spec/mark.ts +2 -0
  133. package/src/utils/helper.ts +9 -1
package/src/mark/line.ts CHANGED
@@ -108,7 +108,7 @@ Line.props = {
108
108
  { name: 'y' },
109
109
  { name: 'position', independent: true },
110
110
  { name: 'size' },
111
- { name: 'series', scale: 'identity' },
111
+ { name: 'series', scale: 'band' },
112
112
  ],
113
113
  preInference: [
114
114
  ...basePreInference(),
@@ -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 = {};
@@ -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);
@@ -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 };
@@ -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>;
@@ -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)) target.attr(key, value);
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