@antv/g2 5.1.0 → 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.
Files changed (152) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +3 -3
  3. package/README.zh-CN.md +2 -2
  4. package/dist/g2-lite.min.js +1 -10
  5. package/dist/g2.min.js +1 -10
  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/component/axis.js +1 -1
  16. package/esm/component/axis.js.map +1 -1
  17. package/esm/index.d.ts +2 -2
  18. package/esm/index.js +2 -2
  19. package/esm/index.js.map +1 -1
  20. package/esm/interaction/brushHighlight.d.ts +1 -1
  21. package/esm/interaction/brushHighlight.js +15 -5
  22. package/esm/interaction/brushHighlight.js.map +1 -1
  23. package/esm/interaction/tooltip.d.ts +1 -1
  24. package/esm/interaction/tooltip.js +88 -42
  25. package/esm/interaction/tooltip.js.map +1 -1
  26. package/esm/lib/plot.d.ts +1 -0
  27. package/esm/lib/plot.js +2 -1
  28. package/esm/lib/plot.js.map +1 -1
  29. package/esm/lib/std.d.ts +1 -0
  30. package/esm/mark/area.js +1 -1
  31. package/esm/mark/area.js.map +1 -1
  32. package/esm/mark/gauge.d.ts +1 -1
  33. package/esm/mark/gauge.js +14 -2
  34. package/esm/mark/gauge.js.map +1 -1
  35. package/esm/mark/index.d.ts +2 -0
  36. package/esm/mark/index.js +1 -0
  37. package/esm/mark/index.js.map +1 -1
  38. package/esm/mark/line.js +1 -1
  39. package/esm/mark/line.js.map +1 -1
  40. package/esm/mark/liquid.d.ts +7 -0
  41. package/esm/mark/liquid.js +83 -0
  42. package/esm/mark/liquid.js.map +1 -0
  43. package/esm/runtime/constant.d.ts +1 -0
  44. package/esm/runtime/constant.js +1 -0
  45. package/esm/runtime/constant.js.map +1 -1
  46. package/esm/runtime/plot.js +7 -1
  47. package/esm/runtime/plot.js.map +1 -1
  48. package/esm/runtime/transform.js +4 -1
  49. package/esm/runtime/transform.js.map +1 -1
  50. package/esm/shape/index.d.ts +2 -0
  51. package/esm/shape/index.js +1 -0
  52. package/esm/shape/index.js.map +1 -1
  53. package/esm/shape/liquid/liquid.d.ts +3 -0
  54. package/esm/shape/liquid/liquid.js +79 -0
  55. package/esm/shape/liquid/liquid.js.map +1 -0
  56. package/esm/shape/liquid/shapes.d.ts +38 -0
  57. package/esm/shape/liquid/shapes.js +93 -0
  58. package/esm/shape/liquid/shapes.js.map +1 -0
  59. package/esm/shape/liquid/wave.d.ts +16 -0
  60. package/esm/shape/liquid/wave.js +192 -0
  61. package/esm/shape/liquid/wave.js.map +1 -0
  62. package/esm/spec/mark.d.ts +2 -1
  63. package/esm/theme/light.js +2 -1
  64. package/esm/theme/light.js.map +1 -1
  65. package/esm/utils/helper.js +10 -2
  66. package/esm/utils/helper.js.map +1 -1
  67. package/lib/api/chart.d.ts +7 -1
  68. package/lib/api/chart.js.map +1 -1
  69. package/lib/api/extend.d.ts +2 -1
  70. package/lib/api/index.d.ts +1 -3
  71. package/lib/api/index.js +1 -5
  72. package/lib/api/index.js.map +1 -1
  73. package/lib/api/library.d.ts +1 -0
  74. package/lib/api/runtime.js +1 -0
  75. package/lib/api/runtime.js.map +1 -1
  76. package/lib/component/axis.js +1 -1
  77. package/lib/component/axis.js.map +1 -1
  78. package/lib/index.d.ts +2 -2
  79. package/lib/index.js +2 -3
  80. package/lib/index.js.map +1 -1
  81. package/lib/interaction/brushHighlight.d.ts +1 -1
  82. package/lib/interaction/brushHighlight.js +15 -5
  83. package/lib/interaction/brushHighlight.js.map +1 -1
  84. package/lib/interaction/tooltip.d.ts +1 -1
  85. package/lib/interaction/tooltip.js +87 -41
  86. package/lib/interaction/tooltip.js.map +1 -1
  87. package/lib/lib/plot.d.ts +1 -0
  88. package/lib/lib/plot.js +1 -0
  89. package/lib/lib/plot.js.map +1 -1
  90. package/lib/lib/std.d.ts +1 -0
  91. package/lib/mark/area.js +1 -1
  92. package/lib/mark/area.js.map +1 -1
  93. package/lib/mark/gauge.d.ts +1 -1
  94. package/lib/mark/gauge.js +13 -1
  95. package/lib/mark/gauge.js.map +1 -1
  96. package/lib/mark/index.d.ts +2 -0
  97. package/lib/mark/index.js +3 -1
  98. package/lib/mark/index.js.map +1 -1
  99. package/lib/mark/line.js +1 -1
  100. package/lib/mark/line.js.map +1 -1
  101. package/lib/mark/liquid.d.ts +7 -0
  102. package/lib/mark/liquid.js +87 -0
  103. package/lib/mark/liquid.js.map +1 -0
  104. package/lib/runtime/constant.d.ts +1 -0
  105. package/lib/runtime/constant.js +2 -1
  106. package/lib/runtime/constant.js.map +1 -1
  107. package/lib/runtime/plot.js +7 -1
  108. package/lib/runtime/plot.js.map +1 -1
  109. package/lib/runtime/transform.js +3 -0
  110. package/lib/runtime/transform.js.map +1 -1
  111. package/lib/shape/index.d.ts +2 -0
  112. package/lib/shape/index.js +3 -1
  113. package/lib/shape/index.js.map +1 -1
  114. package/lib/shape/liquid/liquid.d.ts +3 -0
  115. package/lib/shape/liquid/liquid.js +83 -0
  116. package/lib/shape/liquid/liquid.js.map +1 -0
  117. package/lib/shape/liquid/shapes.d.ts +38 -0
  118. package/lib/shape/liquid/shapes.js +96 -0
  119. package/lib/shape/liquid/shapes.js.map +1 -0
  120. package/lib/shape/liquid/wave.d.ts +16 -0
  121. package/lib/shape/liquid/wave.js +196 -0
  122. package/lib/shape/liquid/wave.js.map +1 -0
  123. package/lib/spec/mark.d.ts +2 -1
  124. package/lib/theme/light.js +2 -1
  125. package/lib/theme/light.js.map +1 -1
  126. package/lib/utils/helper.js +10 -2
  127. package/lib/utils/helper.js.map +1 -1
  128. package/package.json +5 -5
  129. package/src/api/chart.ts +6 -1
  130. package/src/api/extend.ts +11 -11
  131. package/src/api/index.ts +6 -3
  132. package/src/api/runtime.ts +1 -0
  133. package/src/component/axis.ts +1 -1
  134. package/src/index.ts +3 -2
  135. package/src/interaction/brushHighlight.ts +26 -3
  136. package/src/interaction/tooltip.ts +95 -38
  137. package/src/lib/plot.ts +2 -1
  138. package/src/mark/area.ts +1 -1
  139. package/src/mark/gauge.ts +30 -9
  140. package/src/mark/index.ts +2 -0
  141. package/src/mark/line.ts +1 -1
  142. package/src/mark/liquid.ts +100 -0
  143. package/src/runtime/constant.ts +1 -0
  144. package/src/runtime/plot.ts +10 -2
  145. package/src/runtime/transform.ts +3 -1
  146. package/src/shape/index.ts +2 -0
  147. package/src/shape/liquid/liquid.ts +116 -0
  148. package/src/shape/liquid/shapes.ts +101 -0
  149. package/src/shape/liquid/wave.ts +245 -0
  150. package/src/spec/mark.ts +2 -0
  151. package/src/theme/light.ts +2 -1
  152. package/src/utils/helper.ts +9 -1
@@ -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>;
@@ -278,6 +278,7 @@ export const Light: TC<LightOptions> = (options) => {
278
278
  labelDirection: 'negative',
279
279
  tickDirection: 'negative',
280
280
  titlePosition: 'top',
281
+ labelAutoRotate: false,
281
282
  titleSpacing: 12,
282
283
  labelSpacing: 4,
283
284
  titleTextBaseline: 'middle',
@@ -285,7 +286,7 @@ export const Light: TC<LightOptions> = (options) => {
285
286
  axisBottom: {
286
287
  gridDirection: 'negative',
287
288
  labelDirection: 'positive',
288
- labelAutoRotate: true,
289
+ labelAutoRotate: false,
289
290
  tickDirection: 'positive',
290
291
  titlePosition: 'bottom',
291
292
  titleSpacing: 12,
@@ -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