@antv/g2 5.1.17 → 5.1.19

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 (230) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/animation/growInX.js +4 -2
  4. package/esm/animation/growInX.js.map +1 -1
  5. package/esm/animation/growInY.js +4 -2
  6. package/esm/animation/growInY.js.map +1 -1
  7. package/esm/animation/morphing.js +35 -18
  8. package/esm/animation/morphing.js.map +1 -1
  9. package/esm/animation/scaleInY.js +2 -5
  10. package/esm/animation/scaleInY.js.map +1 -1
  11. package/esm/animation/utils.d.ts +10 -1
  12. package/esm/animation/utils.js +29 -3
  13. package/esm/animation/utils.js.map +1 -1
  14. package/esm/animation/waveIn.js +3 -14
  15. package/esm/animation/waveIn.js.map +1 -1
  16. package/esm/component/title.js +2 -1
  17. package/esm/component/title.js.map +1 -1
  18. package/esm/data/utils/d3-cloud/index.js +1 -0
  19. package/esm/data/utils/d3-cloud/index.js.map +1 -1
  20. package/esm/data/wordCloud.d.ts +100 -2
  21. package/esm/data/wordCloud.js +20 -5
  22. package/esm/data/wordCloud.js.map +1 -1
  23. package/esm/exports.js +0 -2
  24. package/esm/exports.js.map +1 -1
  25. package/esm/index.d.ts +4 -2
  26. package/esm/interaction/brushAxisHighlight.js +3 -3
  27. package/esm/interaction/brushAxisHighlight.js.map +1 -1
  28. package/esm/interaction/brushHighlight.js +4 -5
  29. package/esm/interaction/brushHighlight.js.map +1 -1
  30. package/esm/interaction/elementPointMove.js +6 -6
  31. package/esm/interaction/elementPointMove.js.map +1 -1
  32. package/esm/interaction/tooltip.js +4 -1
  33. package/esm/interaction/tooltip.js.map +1 -1
  34. package/esm/interaction/utils.js +2 -2
  35. package/esm/interaction/utils.js.map +1 -1
  36. package/esm/lib/core.d.ts +2 -0
  37. package/esm/lib/core.js +4 -2
  38. package/esm/lib/core.js.map +1 -1
  39. package/esm/lib/std.d.ts +2 -1
  40. package/esm/mark/chord.js +0 -1
  41. package/esm/mark/chord.js.map +1 -1
  42. package/esm/mark/point.js +3 -1
  43. package/esm/mark/point.js.map +1 -1
  44. package/esm/mark/sankey.js +1 -1
  45. package/esm/mark/sankey.js.map +1 -1
  46. package/esm/mark/text.js +4 -3
  47. package/esm/mark/text.js.map +1 -1
  48. package/esm/mark/wordCloud.js +11 -12
  49. package/esm/mark/wordCloud.js.map +1 -1
  50. package/esm/runtime/plot.js +4 -7
  51. package/esm/runtime/plot.js.map +1 -1
  52. package/esm/shape/connector/connector.js +1 -1
  53. package/esm/shape/connector/connector.js.map +1 -1
  54. package/esm/shape/gauge/round.js +1 -1
  55. package/esm/shape/gauge/round.js.map +1 -1
  56. package/esm/shape/image/image.js +1 -1
  57. package/esm/shape/index.d.ts +4 -0
  58. package/esm/shape/index.js +3 -0
  59. package/esm/shape/index.js.map +1 -1
  60. package/esm/shape/interval/color.js +1 -1
  61. package/esm/shape/interval/color.js.map +1 -1
  62. package/esm/shape/interval/funnel.js +1 -1
  63. package/esm/shape/interval/funnel.js.map +1 -1
  64. package/esm/shape/label/position/default.js +9 -9
  65. package/esm/shape/label/position/default.js.map +1 -1
  66. package/esm/shape/lineXY/line.js +1 -1
  67. package/esm/shape/lineXY/line.js.map +1 -1
  68. package/esm/shape/liquid/liquid.js +4 -4
  69. package/esm/shape/liquid/liquid.js.map +1 -1
  70. package/esm/shape/liquid/wave.js +2 -2
  71. package/esm/shape/liquid/wave.js.map +1 -1
  72. package/esm/shape/point/circle.d.ts +16 -0
  73. package/esm/shape/point/circle.js +56 -0
  74. package/esm/shape/point/circle.js.map +1 -0
  75. package/esm/shape/point/color.d.ts +2 -0
  76. package/esm/shape/point/color.js +2 -1
  77. package/esm/shape/point/color.js.map +1 -1
  78. package/esm/shape/point/hollowCircle.d.ts +6 -0
  79. package/esm/shape/point/hollowCircle.js +9 -0
  80. package/esm/shape/point/hollowCircle.js.map +1 -0
  81. package/esm/shape/text/advance.js +2 -1
  82. package/esm/shape/text/advance.js.map +1 -1
  83. package/esm/shape/text/badge.js +2 -3
  84. package/esm/shape/text/badge.js.map +1 -1
  85. package/esm/shape/text/tag.d.ts +7 -0
  86. package/esm/shape/text/tag.js +40 -0
  87. package/esm/shape/text/tag.js.map +1 -0
  88. package/esm/theme/create.d.ts +4 -2
  89. package/esm/theme/create.js +4 -2
  90. package/esm/theme/create.js.map +1 -1
  91. package/esm/utils/helper.js +1 -8
  92. package/esm/utils/helper.js.map +1 -1
  93. package/esm/utils/marker.d.ts +1 -1
  94. package/esm/utils/marker.js +2 -2
  95. package/esm/utils/marker.js.map +1 -1
  96. package/lib/animation/growInX.js +4 -2
  97. package/lib/animation/growInX.js.map +1 -1
  98. package/lib/animation/growInY.js +4 -2
  99. package/lib/animation/growInY.js.map +1 -1
  100. package/lib/animation/morphing.js +33 -16
  101. package/lib/animation/morphing.js.map +1 -1
  102. package/lib/animation/scaleInY.js +2 -5
  103. package/lib/animation/scaleInY.js.map +1 -1
  104. package/lib/animation/utils.d.ts +10 -1
  105. package/lib/animation/utils.js +30 -4
  106. package/lib/animation/utils.js.map +1 -1
  107. package/lib/animation/waveIn.js +2 -13
  108. package/lib/animation/waveIn.js.map +1 -1
  109. package/lib/component/title.js +2 -1
  110. package/lib/component/title.js.map +1 -1
  111. package/lib/data/utils/d3-cloud/index.js +1 -0
  112. package/lib/data/utils/d3-cloud/index.js.map +1 -1
  113. package/lib/data/wordCloud.d.ts +100 -2
  114. package/lib/data/wordCloud.js +20 -5
  115. package/lib/data/wordCloud.js.map +1 -1
  116. package/lib/exports.js +0 -2
  117. package/lib/exports.js.map +1 -1
  118. package/lib/index.d.ts +4 -2
  119. package/lib/interaction/brushAxisHighlight.js +3 -3
  120. package/lib/interaction/brushAxisHighlight.js.map +1 -1
  121. package/lib/interaction/brushHighlight.js +4 -5
  122. package/lib/interaction/brushHighlight.js.map +1 -1
  123. package/lib/interaction/elementPointMove.js +6 -6
  124. package/lib/interaction/elementPointMove.js.map +1 -1
  125. package/lib/interaction/tooltip.js +4 -1
  126. package/lib/interaction/tooltip.js.map +1 -1
  127. package/lib/interaction/utils.js +2 -2
  128. package/lib/interaction/utils.js.map +1 -1
  129. package/lib/lib/core.d.ts +2 -0
  130. package/lib/lib/core.js +2 -0
  131. package/lib/lib/core.js.map +1 -1
  132. package/lib/lib/std.d.ts +2 -1
  133. package/lib/mark/chord.js +0 -1
  134. package/lib/mark/chord.js.map +1 -1
  135. package/lib/mark/point.js +2 -0
  136. package/lib/mark/point.js.map +1 -1
  137. package/lib/mark/sankey.js +1 -1
  138. package/lib/mark/sankey.js.map +1 -1
  139. package/lib/mark/text.js +3 -2
  140. package/lib/mark/text.js.map +1 -1
  141. package/lib/mark/wordCloud.js +11 -12
  142. package/lib/mark/wordCloud.js.map +1 -1
  143. package/lib/runtime/plot.js +4 -7
  144. package/lib/runtime/plot.js.map +1 -1
  145. package/lib/shape/connector/connector.js +1 -1
  146. package/lib/shape/connector/connector.js.map +1 -1
  147. package/lib/shape/gauge/round.js +1 -1
  148. package/lib/shape/gauge/round.js.map +1 -1
  149. package/lib/shape/image/image.js +1 -1
  150. package/lib/shape/index.d.ts +4 -0
  151. package/lib/shape/index.js +8 -2
  152. package/lib/shape/index.js.map +1 -1
  153. package/lib/shape/interval/color.js +1 -1
  154. package/lib/shape/interval/color.js.map +1 -1
  155. package/lib/shape/interval/funnel.js +1 -1
  156. package/lib/shape/interval/funnel.js.map +1 -1
  157. package/lib/shape/label/position/default.js +9 -9
  158. package/lib/shape/label/position/default.js.map +1 -1
  159. package/lib/shape/lineXY/line.js +1 -1
  160. package/lib/shape/lineXY/line.js.map +1 -1
  161. package/lib/shape/liquid/liquid.js +4 -4
  162. package/lib/shape/liquid/liquid.js.map +1 -1
  163. package/lib/shape/liquid/wave.js +2 -2
  164. package/lib/shape/liquid/wave.js.map +1 -1
  165. package/lib/shape/point/circle.d.ts +16 -0
  166. package/lib/shape/point/circle.js +61 -0
  167. package/lib/shape/point/circle.js.map +1 -0
  168. package/lib/shape/point/color.d.ts +2 -0
  169. package/lib/shape/point/color.js +3 -1
  170. package/lib/shape/point/color.js.map +1 -1
  171. package/lib/shape/point/hollowCircle.d.ts +6 -0
  172. package/lib/shape/point/hollowCircle.js +13 -0
  173. package/lib/shape/point/hollowCircle.js.map +1 -0
  174. package/lib/shape/text/advance.js +2 -1
  175. package/lib/shape/text/advance.js.map +1 -1
  176. package/lib/shape/text/badge.js +2 -3
  177. package/lib/shape/text/badge.js.map +1 -1
  178. package/lib/shape/text/tag.d.ts +7 -0
  179. package/lib/shape/text/tag.js +44 -0
  180. package/lib/shape/text/tag.js.map +1 -0
  181. package/lib/theme/create.d.ts +4 -2
  182. package/lib/theme/create.js +4 -2
  183. package/lib/theme/create.js.map +1 -1
  184. package/lib/utils/helper.js +1 -8
  185. package/lib/utils/helper.js.map +1 -1
  186. package/lib/utils/marker.d.ts +1 -1
  187. package/lib/utils/marker.js +2 -2
  188. package/lib/utils/marker.js.map +1 -1
  189. package/package.json +13 -13
  190. package/src/animation/growInX.ts +9 -2
  191. package/src/animation/growInY.ts +9 -2
  192. package/src/animation/morphing.ts +36 -24
  193. package/src/animation/scaleInY.ts +2 -5
  194. package/src/animation/utils.ts +34 -4
  195. package/src/animation/waveIn.ts +3 -20
  196. package/src/component/title.ts +4 -0
  197. package/src/data/utils/d3-cloud/index.ts +1 -0
  198. package/src/data/wordCloud.ts +112 -7
  199. package/src/exports.ts +0 -4
  200. package/src/interaction/brushAxisHighlight.ts +5 -4
  201. package/src/interaction/brushHighlight.ts +8 -5
  202. package/src/interaction/elementPointMove.ts +6 -6
  203. package/src/interaction/tooltip.ts +4 -1
  204. package/src/interaction/utils.ts +2 -2
  205. package/src/lib/core.ts +4 -0
  206. package/src/mark/chord.ts +0 -1
  207. package/src/mark/point.ts +4 -0
  208. package/src/mark/sankey.ts +1 -1
  209. package/src/mark/text.ts +4 -3
  210. package/src/mark/wordCloud.ts +16 -18
  211. package/src/runtime/plot.ts +12 -7
  212. package/src/shape/connector/connector.ts +1 -1
  213. package/src/shape/gauge/round.ts +1 -1
  214. package/src/shape/image/image.ts +1 -1
  215. package/src/shape/index.ts +4 -0
  216. package/src/shape/interval/color.ts +1 -1
  217. package/src/shape/interval/funnel.ts +1 -1
  218. package/src/shape/label/position/default.ts +9 -9
  219. package/src/shape/lineXY/line.ts +1 -2
  220. package/src/shape/liquid/liquid.ts +4 -4
  221. package/src/shape/liquid/wave.ts +2 -2
  222. package/src/shape/point/circle.ts +57 -0
  223. package/src/shape/point/color.ts +2 -1
  224. package/src/shape/point/hollowCircle.ts +16 -0
  225. package/src/shape/text/advance.ts +3 -1
  226. package/src/shape/text/badge.ts +2 -3
  227. package/src/shape/text/tag.ts +44 -0
  228. package/src/theme/create.ts +4 -2
  229. package/src/utils/helper.ts +1 -7
  230. package/src/utils/marker.ts +2 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g2",
3
- "version": "5.1.17",
3
+ "version": "5.1.19",
4
4
  "description": "the Grammar of Graphics in Javascript",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -59,12 +59,12 @@
59
59
  "animation"
60
60
  ],
61
61
  "dependencies": {
62
- "@antv/component": "^1.0.1-beta.0",
62
+ "@antv/component": "^2.0.0",
63
63
  "@antv/coord": "^0.4.6",
64
64
  "@antv/event-emitter": "^0.1.3",
65
- "@antv/g": "^5.18.19",
66
- "@antv/g-canvas": "^1.11.22",
67
- "@antv/g-plugin-dragndrop": "^1.8.17",
65
+ "@antv/g": "^6.0.0",
66
+ "@antv/g-canvas": "^2.0.0",
67
+ "@antv/g-plugin-dragndrop": "^2.0.0",
68
68
  "@antv/path-util": "^3.0.1",
69
69
  "@antv/scale": "^0.4.12",
70
70
  "@antv/util": "^3.3.5",
@@ -84,13 +84,13 @@
84
84
  },
85
85
  "devDependencies": {
86
86
  "@antv/data-set": "^0.11.8",
87
- "@antv/g-pattern": "^1.2.19",
88
- "@antv/g-plugin-3d": "^1.9.26",
89
- "@antv/g-plugin-control": "^1.9.17",
90
- "@antv/g-plugin-rough-canvas-renderer": "^1.9.22",
91
- "@antv/g-plugin-rough-svg-renderer": "^1.9.22",
92
- "@antv/g-svg": "^1.10.21",
93
- "@antv/g-webgl": "^1.9.29",
87
+ "@antv/g-pattern": "^2.0.0",
88
+ "@antv/g-plugin-3d": "^2.0.0",
89
+ "@antv/g-plugin-control": "^2.0.0",
90
+ "@antv/g-plugin-rough-canvas-renderer": "^2.0.0",
91
+ "@antv/g-plugin-rough-svg-renderer": "^2.0.0",
92
+ "@antv/g-svg": "^2.0.0",
93
+ "@antv/g-webgl": "^2.0.0",
94
94
  "@antv/g2-extension-3d": "^0.1.3",
95
95
  "@antv/g2-extension-ava": "^0.1.1",
96
96
  "@antv/g2-extension-plot": "^0.1.0",
@@ -154,7 +154,7 @@
154
154
  "limit-size": [
155
155
  {
156
156
  "path": "dist/g2.min.js",
157
- "limit": "280 Kb",
157
+ "limit": "285 Kb",
158
158
  "gzip": true
159
159
  },
160
160
  {
@@ -11,10 +11,17 @@ export type GrowInXOptions = Animation;
11
11
  export const GrowInX: AC<GrowInXOptions> = (options, context) => {
12
12
  return (from, to, defaults) => {
13
13
  const [shape] = from;
14
- const { height, width } = shape.getBoundingClientRect();
14
+ const {
15
+ min: [x, y],
16
+ halfExtents,
17
+ } = shape.getLocalBounds();
18
+ const width = halfExtents[0] * 2;
19
+ const height = halfExtents[1] * 2;
15
20
  const clipPath = new Path({
16
21
  style: {
17
- path: `M0,0L${width},0L${width},${height}L0,${height}Z`,
22
+ d: `M${x},${y}L${x + width},${y}L${x + width},${y + height}L${x},${
23
+ y + height
24
+ }Z`,
18
25
  },
19
26
  });
20
27
  shape.appendChild(clipPath);
@@ -11,10 +11,17 @@ export type GrowInYOptions = Animation;
11
11
  export const GrowInY: AC<GrowInYOptions> = (options, context) => {
12
12
  return (from, to, defaults) => {
13
13
  const [shape] = from;
14
- const { height, width } = shape.getBoundingClientRect();
14
+ const {
15
+ min: [x, y],
16
+ halfExtents,
17
+ } = shape.getLocalBounds();
18
+ const width = halfExtents[0] * 2;
19
+ const height = halfExtents[1] * 2;
15
20
  const clipPath = new Path({
16
21
  style: {
17
- path: `M0,0L${width},0L${width},${height}L0,${height}Z`,
22
+ d: `M${x},${y}L${x + width},${y}L${x + width},${y + height}L${x},${
23
+ y + height
24
+ }Z`,
18
25
  },
19
26
  });
20
27
  shape.appendChild(clipPath);
@@ -3,11 +3,12 @@ import {
3
3
  DisplayObject,
4
4
  IAnimation as GAnimation,
5
5
  Path,
6
+ Shape,
6
7
  } from '@antv/g';
7
8
  import { AnimationComponent as AC } from '../runtime';
8
9
  import { copyAttributes } from '../utils/helper';
9
10
  import { Animation } from './types';
10
- import { attributeKeys, attributeOf } from './utils';
11
+ import { attributeKeys, attributeOf, GEOMETRY_ATTRIBUTES } from './utils';
11
12
 
12
13
  export type MorphingOptions = Animation & { split: 'pack' | SplitFunction };
13
14
 
@@ -66,38 +67,44 @@ function normalizeSplit(
66
67
  }
67
68
 
68
69
  /**
69
- * Translate and scale.
70
+ * Use attributes relative to geometry to do shape to shape animation.
71
+ *
72
+ * For example, the x, y, width, height of `Rect`, the cx, cy, r of `Circle`.
73
+ * And for `Group`, it will use the bbox of the group.
70
74
  */
71
75
  function shapeToShape(
72
76
  from: DisplayObject,
73
77
  to: DisplayObject,
74
78
  timeEffect: Record<string, any>,
75
79
  ): GAnimation {
76
- const [x0, y0, w0, h0] = localBBoxOf(from);
77
- const { transform: fromTransform } = from.style;
80
+ let { transform: fromTransform } = from.style;
78
81
  const { transform: toTransform } = to.style;
79
82
 
80
83
  // Replace first to get right bbox after mounting.
81
84
  replaceChild(to, from);
82
85
 
83
- // Apply translate and scale transform.
84
- const [x1, y1, w1, h1] = localBBoxOf(to);
85
- const dx = x0 - x1;
86
- const dy = y0 - y1;
87
- const sx = w0 / w1;
88
- const sy = h0 / h1;
86
+ let keys = attributeKeys;
87
+ if (from.nodeName === Shape.GROUP) {
88
+ // Apply translate and scale transform.
89
+ const [x0, y0, w0, h0] = localBBoxOf(from);
90
+ const [x1, y1, w1, h1] = localBBoxOf(to);
91
+ const dx = x0 - x1;
92
+ const dy = y0 - y1;
93
+ const sx = w0 / w1;
94
+ const sy = h0 / h1;
95
+ fromTransform = `translate(${dx}, ${dy}) scale(${sx}, ${sy})`;
96
+ } else {
97
+ keys = keys.concat(GEOMETRY_ATTRIBUTES[from.nodeName] || []);
98
+ }
99
+
89
100
  const keyframes = [
90
101
  {
91
- transform: `${
92
- fromTransform ? fromTransform + ' ' : ''
93
- }translate(${dx}, ${dy}) scale(${sx}, ${sy})`,
94
- ...attributeOf(from, attributeKeys),
102
+ transform: fromTransform ?? 'none',
103
+ ...attributeOf(from, keys, true),
95
104
  },
96
105
  {
97
- transform: `${
98
- toTransform ? toTransform + ' ' : ''
99
- }translate(0, 0) scale(1, 1)`,
100
- ...attributeOf(to, attributeKeys),
106
+ transform: toTransform ?? 'none',
107
+ ...attributeOf(to, keys, true),
101
108
  },
102
109
  ];
103
110
  const animation = to.animate(keyframes, timeEffect);
@@ -172,21 +179,26 @@ function oneToOne(
172
179
  const pathShape = maybePath(shape, fromPath);
173
180
  // Convert Path will take transform, anchor, etc into account,
174
181
  // so there is no need to specify these attributes in keyframes.
175
- const keyframes = [
182
+ const keyframes: Keyframe[] = [
176
183
  {
177
- path: fromPath,
178
184
  ...attributeOf(from, attributeKeys),
179
185
  },
180
186
  {
181
- path: toPath,
182
187
  ...attributeOf(to, attributeKeys),
183
188
  },
184
189
  ];
190
+ if (fromPath !== toPath) {
191
+ keyframes[0].d = fromPath;
192
+ keyframes[1].d = toPath;
193
+ }
185
194
  const animation = pathShape.animate(keyframes, timeEffect);
186
195
 
187
196
  animation.onfinish = () => {
188
- pathShape.style.transform = 'none';
197
+ // Should keep the original path definition.
198
+ const d = pathShape.style.d;
189
199
  copyAttributes(pathShape, to);
200
+ pathShape.style.d = d;
201
+ pathShape.style.transform = 'none';
190
202
  };
191
203
 
192
204
  // Remove transform because it already applied in path
@@ -207,7 +219,7 @@ function oneToMultiple(
207
219
  return to.map((shape, i) => {
208
220
  const path = new Path({
209
221
  style: {
210
- path: D[i],
222
+ d: D[i],
211
223
  ...attributeOf(from, attributeKeys),
212
224
  },
213
225
  });
@@ -236,7 +248,7 @@ function multipleToOne(
236
248
  const animations = from.map((shape, i) => {
237
249
  const path = new Path({
238
250
  style: {
239
- path: D[i],
251
+ d: D[i],
240
252
  fill: to.style.fill,
241
253
  },
242
254
  });
@@ -51,7 +51,6 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
51
51
  .cornerRadius(radius as number)
52
52
  .padAngle((inset * Math.PI) / 180);
53
53
  const pathForConversion = new Path({});
54
- const center = coordinate.getCenter();
55
54
  const createArcPath = (arcParams: {
56
55
  startAngle: number;
57
56
  endAngle: number;
@@ -60,10 +59,8 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
60
59
  }) => {
61
60
  pathForConversion.attr({
62
61
  d: path(arcParams),
63
- transform: `translate(${center[0]}, ${center[1]})`,
64
62
  });
65
63
  const convertedPathDefinition = convertToPath(pathForConversion);
66
- pathForConversion.style.transform = '';
67
64
  return convertedPathDefinition;
68
65
  };
69
66
 
@@ -91,14 +88,14 @@ export const ScaleInY: AC<ScaleInYOptions> = (options, context) => {
91
88
 
92
89
  const animation = shape.animate(keyframes, { ...defaults, ...options });
93
90
  animation.onframe = function () {
94
- shape.style.path = createArcPath({
91
+ shape.style.d = createArcPath({
95
92
  ...arcObject,
96
93
  outerRadius: Number(shape.style.scaleInYRadius),
97
94
  });
98
95
  };
99
96
 
100
97
  animation.onfinish = function () {
101
- shape.style.path = createArcPath({
98
+ shape.style.d = createArcPath({
102
99
  ...arcObject,
103
100
  outerRadius: outerRadius,
104
101
  });
@@ -1,13 +1,43 @@
1
- import { DisplayObject } from '@antv/g';
1
+ import { DisplayObject, Shape } from '@antv/g';
2
2
 
3
- // TODO: Add more attributes need to be transform.
4
- // TODO: Opacity transform unexpectedly.
5
- export function attributeOf(shape: DisplayObject, keys: string[]) {
3
+ const DEFAULT_ATTRIBUTE_VALUE = {
4
+ opacity: 1,
5
+ strokeOpacity: 1,
6
+ fillOpacity: 1,
7
+ lineWidth: 0,
8
+ x: 0,
9
+ y: 0,
10
+ cx: 0,
11
+ cy: 0,
12
+ r: 0,
13
+ rx: 0,
14
+ ry: 0,
15
+ width: 0,
16
+ height: 0,
17
+ };
18
+
19
+ export const GEOMETRY_ATTRIBUTES = {
20
+ [Shape.CIRCLE]: ['cx', 'cy', 'r'],
21
+ [Shape.ELLIPSE]: ['cx', 'cy', 'rx', 'ry'],
22
+ [Shape.RECT]: ['x', 'y', 'width', 'height'],
23
+ [Shape.IMAGE]: ['x', 'y', 'width', 'height'],
24
+ [Shape.LINE]: ['x1', 'y1', 'x2', 'y2'],
25
+ [Shape.POLYLINE]: ['points'],
26
+ [Shape.POLYGON]: ['points'],
27
+ };
28
+
29
+ export function attributeOf(
30
+ shape: DisplayObject,
31
+ keys: string[],
32
+ useDefaultValue = false,
33
+ ) {
6
34
  const attribute = {};
7
35
  for (const key of keys) {
8
36
  const value = shape.style[key];
9
37
  if (value) {
10
38
  attribute[key] = value;
39
+ } else if (useDefaultValue) {
40
+ attribute[key] = DEFAULT_ATTRIBUTE_VALUE[key];
11
41
  }
12
42
  }
13
43
  return attribute;
@@ -1,5 +1,5 @@
1
1
  import { arc } from 'd3-shape';
2
- import { Path, CSS, PropertySyntax, convertToPath } from '@antv/g';
2
+ import { CSS, PropertySyntax } from '@antv/g';
3
3
  import { G2Element } from '../utils/selection';
4
4
  import { AnimationComponent as AC } from '../runtime';
5
5
  import { getArcObject } from '../shape/utils';
@@ -33,7 +33,6 @@ export const WaveIn: AC<WaveInOptions> = (options, context) => {
33
33
  return ScaleInX(options, context)(from, to, defaults);
34
34
  }
35
35
 
36
- const center = coordinate.getCenter();
37
36
  const { __data__, style } = shape as G2Element;
38
37
  const {
39
38
  radius = 0,
@@ -50,22 +49,6 @@ export const WaveIn: AC<WaveInOptions> = (options, context) => {
50
49
  .padAngle((inset * Math.PI) / 180);
51
50
  const arcObject = getArcObject(coordinate, points, [y, y1]);
52
51
  const { startAngle, endAngle } = arcObject;
53
- const pathForConversion = new Path({});
54
-
55
- const createArcPath = (arcParams: {
56
- startAngle: number;
57
- endAngle: number;
58
- innerRadius: number;
59
- outerRadius: number;
60
- }) => {
61
- pathForConversion.attr({
62
- d: path(arcParams),
63
- transform: `translate(${center[0]}, ${center[1]})`,
64
- });
65
- const convertedPathDefinition = convertToPath(pathForConversion);
66
- pathForConversion.style.transform = '';
67
- return convertedPathDefinition;
68
- };
69
52
 
70
53
  const keyframes = [
71
54
  // Use custom interpolable CSS property.
@@ -92,13 +75,13 @@ export const WaveIn: AC<WaveInOptions> = (options, context) => {
92
75
  const animation = shape.animate(keyframes, { ...defaults, ...options });
93
76
 
94
77
  animation.onframe = function () {
95
- shape.style.path = createArcPath({
78
+ shape.style.d = path({
96
79
  ...arcObject,
97
80
  endAngle: Number(shape.style.waveInArcAngle),
98
81
  });
99
82
  };
100
83
  animation.onfinish = function () {
101
- shape.style.path = createArcPath({
84
+ shape.style.d = path({
102
85
  ...arcObject,
103
86
  endAngle: endAngle,
104
87
  });
@@ -49,9 +49,13 @@ const Title = createComponent<TitleStyleProps>({
49
49
  subtitle,
50
50
  spacing = 2,
51
51
  align = 'left',
52
+ x,
53
+ y,
52
54
  ...style
53
55
  } = attributes;
54
56
 
57
+ container.style.transform = `translate(${x}, ${y})`;
58
+
55
59
  const titleStyle = subObject(style, 'title');
56
60
  const subtitleStyle = subObject(style, 'subtitle');
57
61
 
@@ -357,6 +357,7 @@ export function tagCloud() {
357
357
  const context = canvas.getContext('2d') as CanvasRenderingContext2D;
358
358
  context.fillStyle = context.strokeStyle = 'red';
359
359
  context.textAlign = 'center';
360
+ context.textBaseline = 'middle';
360
361
  return { context, ratio };
361
362
  }
362
363
 
@@ -1,15 +1,112 @@
1
1
  import { min, max } from 'd3-array';
2
2
  import { DataComponent as DC } from '../runtime';
3
- import { tagCloud } from './utils/d3-cloud';
4
3
  import { flow } from './utils/flow';
4
+ import { tagCloud } from './utils/d3-cloud';
5
5
 
6
- export type WordCloudOptions = Omit<Record<string, any>, 'type'>;
6
+ type Callable<T> = T | ((datum: any, i: number) => T);
7
+
8
+ /**
9
+ * See the document here: https://github.com/jasondavies/d3-cloud.
10
+ */
11
+ export type WordCloudOptions = {
12
+ /**
13
+ * Internally, the layout uses setInterval to avoid locking up the browser’s event loop.
14
+ * If specified, time is the maximum amount of time that can be spent during the current timestep.
15
+ * If not specified, returns the current maximum time interval, which defaults to Infinity.
16
+ */
17
+ timeInterval: number;
18
+ /**
19
+ * If specified, sets the words array. If not specified, returns the current words array, which defaults to [].
20
+ */
21
+ words: any[];
22
+ /**
23
+ * If specified, sets the rectangular [width, height] of the layout.
24
+ * If not specified, returns the current size, which defaults to [1, 1].
25
+ */
26
+ size: [number, number];
27
+ /**
28
+ * If specified, sets the font accessor function, which indicates the font face for each word.
29
+ * If not specified, returns the current font accessor function, which defaults to "serif".
30
+ * A constant may be specified instead of a function.
31
+ */
32
+ font: Callable<CSSStyleDeclaration['fontFamily']>;
33
+ /**
34
+ * TODO: Cname of font.
35
+ */
36
+ fontFamily: Callable<CSSStyleDeclaration['fontFamily']>;
37
+ /**
38
+ * If specified, sets the fontStyle accessor function, which indicates the font style for each word.
39
+ * If not specified, returns the current fontStyle accessor function, which defaults to "normal".
40
+ * A constant may be specified instead of a function.
41
+ */
42
+ fontStyle: Callable<CSSStyleDeclaration['fontFamily']>;
43
+ /**
44
+ * If specified, sets the fontWeight accessor function, which indicates the font weight for each word.
45
+ * If not specified, returns the current fontWeight accessor function, which defaults to "normal".
46
+ * A constant may be specified instead of a function.
47
+ */
48
+ fontWeight: Callable<CSSStyleDeclaration['fontFamily']>;
49
+ /**
50
+ * If specified, sets the fontSize accessor function, which indicates the numerical font size for each word.
51
+ * If not specified, returns the current fontSize accessor function, which defaults to:
52
+ *
53
+ * > function(d) { return Math.sqrt(d.value); }
54
+ *
55
+ * A constant may be specified instead of a function.
56
+ *
57
+ * If the fontSize is an array, it will be normalized to the range of [min, max] of the data value.
58
+ * If the fontSize is a function, it will be called with the data value.
59
+ * If the fontSize is a number, it will be used as the constant value.
60
+ */
61
+ fontSize: number | [number, number] | ((d: any) => number);
62
+ /**
63
+ * If specified, sets the rotate accessor function, which indicates the rotation angle (in degrees) for each word.
64
+ * If not specified, returns the current rotate accessor function, which defaults to:
65
+ *
66
+ * function() { return (~~(Math.random() * 6) - 3) * 30; }
67
+ *
68
+ * A constant may be specified instead of a function.
69
+ */
70
+ rotate: Callable<number>;
71
+ /**
72
+ * If specified, sets the text accessor function, which indicates the text for each word.
73
+ * If not specified, returns the current text accessor function, which defaults to:
74
+ *
75
+ * function(d) { return d.text; }
76
+ *
77
+ * A constant may be specified instead of a function.
78
+ */
79
+ text: Callable<string>;
80
+ /**
81
+ * If specified, sets the padding accessor function, which indicates the numerical padding for each word.
82
+ * If not specified, returns the current padding, which defaults to 1.
83
+ */
84
+ padding: Callable<number>;
85
+
86
+ /**
87
+ * If specified, sets the internal random number generator, used for selecting the initial position of each word,
88
+ * and the clockwise/counterclockwise direction of the spiral for each word.
89
+ * This should return a number in the range [0, 1).
90
+ * If not specified, returns the current random number generator, which defaults to Math.random.
91
+ */
92
+ random: () => number;
93
+ spiral: any;
94
+ };
7
95
 
8
- const DEFAULT_OPTIONS: Partial<WordCloudOptions> = {
9
- size: [500, 500],
10
- fontSize: [14, 28],
96
+ const DEFAULT_OPTIONS = {
97
+ fontSize: [20, 60],
98
+ font: 'Impact',
99
+ padding: 2,
100
+ rotate: function () {
101
+ return (~~(Math.random() * 6) - 3) * 30;
102
+ },
11
103
  };
12
104
 
105
+ /**
106
+ * Process the image mask of wordCloud.
107
+ * @param img
108
+ * @returns
109
+ */
13
110
  export function processImageMask(
14
111
  img: HTMLImageElement | string,
15
112
  ): Promise<HTMLImageElement> {
@@ -33,6 +130,12 @@ export function processImageMask(
33
130
  });
34
131
  }
35
132
 
133
+ /**
134
+ * normalize fontSize range to d3-cloud fontSize function.
135
+ * @param fontSize
136
+ * @param range
137
+ * @returns
138
+ */
36
139
  export function normalizeFontSize(fontSize: any, range?: [number, number]) {
37
140
  if (typeof fontSize === 'function') return fontSize;
38
141
 
@@ -48,7 +151,7 @@ export function normalizeFontSize(fontSize: any, range?: [number, number]) {
48
151
  return () => fontSize;
49
152
  }
50
153
 
51
- export const WordCloud: DC<WordCloudOptions> = (options) => {
154
+ export const WordCloud: DC<Partial<WordCloudOptions>> = (options) => {
52
155
  return async (data) => {
53
156
  const cloudOptions = Object.assign({}, DEFAULT_OPTIONS, options);
54
157
  const layout = tagCloud();
@@ -80,12 +183,14 @@ export const WordCloud: DC<WordCloudOptions> = (options) => {
80
183
  { x: 0, y: 0 },
81
184
  { x: cw, y: ch },
82
185
  ];
186
+
83
187
  const { _bounds: bounds = defaultBounds, _tags, hasImage } = result;
84
188
 
85
- const tags = _tags.map(({ x, y, ...rest }) => ({
189
+ const tags = _tags.map(({ x, y, font, ...rest }) => ({
86
190
  ...rest,
87
191
  x: x + cw / 2,
88
192
  y: y + ch / 2,
193
+ fontFamily: font,
89
194
  }));
90
195
 
91
196
  // Append two data to replace the corner of top-left and bottom-right, avoid calculate the actual bounds will occur some error.
package/src/exports.ts CHANGED
@@ -1,7 +1,3 @@
1
- import { runtime } from '@antv/g';
2
-
3
- runtime.enableCSSParsing = false;
4
-
5
1
  export {
6
2
  render,
7
3
  renderToMountedElement,
@@ -54,9 +54,10 @@ function verticalBrush(axis, { cross, offsetX, offsetY, ...style }) {
54
54
  style: {
55
55
  // If it is not cross, draw brush in both side of axisLine,
56
56
  // otherwise the draw brush within bounds area.
57
- x: cross ? minX : lineX - size / 2,
58
57
  width: cross ? size / 2 : size,
59
- y: minY,
58
+ transform: `translate(${(cross ? minX : lineX - size / 2).toFixed(
59
+ 2,
60
+ )}, ${minY})`,
60
61
  height: maxY - minY,
61
62
  ...style,
62
63
  },
@@ -86,12 +87,11 @@ function horizontalBrush(axis, { offsetY, offsetX, cross = false, ...style }) {
86
87
  hotZone: new Rect({
87
88
  className: AXIS_HOT_AREA_CLASS_NAME,
88
89
  style: {
89
- x: minX,
90
90
  width: maxX - minX,
91
91
  // If it is not cross, draw brush in both side of axisLine,
92
92
  // otherwise the draw brush within bounds area.
93
- y: cross ? minY : lineY - size,
94
93
  height: cross ? size : size * 2,
94
+ transform: `translate(${minX}, ${cross ? minY : lineY - size})`,
95
95
  ...style,
96
96
  },
97
97
  }),
@@ -222,6 +222,7 @@ export function brushAxisHighlight(
222
222
  fill: 'transparent', // Make it interactive.
223
223
  });
224
224
  axis.parentNode.appendChild(hotZone);
225
+
225
226
  const brushHandler = brush(hotZone, {
226
227
  ...brushStyle,
227
228
  reverse,
@@ -113,8 +113,7 @@ const ResizableMask = createElement((g) => {
113
113
 
114
114
  const renderHandle = (g, renderNode) => {
115
115
  const { id } = g;
116
- const { x, y, ...style } = g.attributes;
117
- const handle = renderNode(g, { x: 0, y: 0, ...style }, document);
116
+ const handle = renderNode(g, g.attributes, document);
118
117
  handle.id = id;
119
118
  handle.style.draggable = true;
120
119
  };
@@ -128,15 +127,19 @@ const ResizableMask = createElement((g) => {
128
127
 
129
128
  const container = select(g)
130
129
  .attr('className', className)
131
- .style('x', x)
132
- .style('y', y)
130
+ .style('transform', `translate(${x}, ${y})`)
133
131
  .style('draggable', true);
134
132
 
135
133
  container
136
134
  .maybeAppend('selection', 'rect')
137
135
  .style('draggable', true)
138
136
  .style('fill', 'transparent')
139
- .call(applyStyle, { width, height, ...omitPrefixObject(style, 'handle') });
137
+ .call(applyStyle, {
138
+ width,
139
+ height,
140
+ ...omitPrefixObject(style, 'handle'),
141
+ transform: undefined,
142
+ });
140
143
 
141
144
  container
142
145
  .maybeAppend('handle-n', appendHandle(handleNRender))
@@ -395,7 +395,7 @@ export function ElementPointMove(
395
395
  'text',
396
396
  ratioTransform(scaleY.invert(y)).toFixed(precision),
397
397
  );
398
- pathShape.attr('path', newPath);
398
+ pathShape.attr('d', newPath);
399
399
  circle.attr('cx', newX);
400
400
  circle.attr('cy', newY);
401
401
  } else {
@@ -414,7 +414,7 @@ export function ElementPointMove(
414
414
  'text',
415
415
  ratioTransform(scaleY.invert(y)).toFixed(precision),
416
416
  );
417
- pathShape.attr('path', newPath);
417
+ pathShape.attr('d', newPath);
418
418
  circle.attr('cy', newCy);
419
419
  }
420
420
  } else {
@@ -426,7 +426,7 @@ export function ElementPointMove(
426
426
  points[index + 1],
427
427
  ]);
428
428
  labelShape.attr('text', scaleY.invert(y).toFixed(precision));
429
- pathShape.attr('path', newPath);
429
+ pathShape.attr('d', newPath);
430
430
  circle.attr('cy', newCy);
431
431
  }
432
432
  };
@@ -528,7 +528,7 @@ export function ElementPointMove(
528
528
  'text',
529
529
  ratioTransform(scaleY.invert(x)).toFixed(precision),
530
530
  );
531
- pathShape.attr('path', newPath);
531
+ pathShape.attr('d', newPath);
532
532
  circle.attr('cx', newCx);
533
533
  } else if (isTheta) {
534
534
  // Pie chart.
@@ -559,7 +559,7 @@ export function ElementPointMove(
559
559
  'text',
560
560
  ratioTransform(percent, true).toFixed(precision),
561
561
  );
562
- pathShape.attr('path', newPath);
562
+ pathShape.attr('d', newPath);
563
563
  circle.attr('cx', newXOut);
564
564
  circle.attr('cy', newYOut);
565
565
  } else {
@@ -585,7 +585,7 @@ export function ElementPointMove(
585
585
  'text',
586
586
  ratioTransform(scaleY.invert(y)).toFixed(precision),
587
587
  );
588
- pathShape.attr('path', newPath);
588
+ pathShape.attr('d', newPath);
589
589
  circle.attr('cy', newCy);
590
590
  }
591
591
  };