@antv/component 1.0.0 → 1.0.1-beta.1

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 (263) hide show
  1. package/dist/component.min.js +1 -1
  2. package/esm/animation/fadeIn.d.ts +1 -1
  3. package/esm/animation/fadeOut.d.ts +1 -1
  4. package/esm/animation/utils.d.ts +3 -3
  5. package/esm/animation/utils.js +10 -14
  6. package/esm/animation/utils.js.map +1 -1
  7. package/esm/ui/axis/constant.js +0 -1
  8. package/esm/ui/axis/constant.js.map +1 -1
  9. package/esm/ui/axis/guides/labels.js +11 -9
  10. package/esm/ui/axis/guides/labels.js.map +1 -1
  11. package/esm/ui/axis/guides/ticks.js +1 -1
  12. package/esm/ui/axis/guides/ticks.js.map +1 -1
  13. package/esm/ui/axis/guides/title.js +6 -9
  14. package/esm/ui/axis/guides/title.js.map +1 -1
  15. package/esm/ui/axis/overlap/autoEllipsis.js +1 -2
  16. package/esm/ui/axis/overlap/autoEllipsis.js.map +1 -1
  17. package/esm/ui/axis/overlap/autoHide.js +1 -2
  18. package/esm/ui/axis/overlap/autoHide.js.map +1 -1
  19. package/esm/ui/axis/utils/bounds.d.ts +3 -1
  20. package/esm/ui/axis/utils/bounds.js +4 -7
  21. package/esm/ui/axis/utils/bounds.js.map +1 -1
  22. package/esm/ui/breadcrumb/index.js +2 -2
  23. package/esm/ui/breadcrumb/index.js.map +1 -1
  24. package/esm/ui/button/index.js +8 -6
  25. package/esm/ui/button/index.js.map +1 -1
  26. package/esm/ui/button/types.d.ts +2 -0
  27. package/esm/ui/checkbox/constant.d.ts +2 -2
  28. package/esm/ui/checkbox/index.js +1 -1
  29. package/esm/ui/checkbox/index.js.map +1 -1
  30. package/esm/ui/indicator/indicator.js +2 -1
  31. package/esm/ui/indicator/indicator.js.map +1 -1
  32. package/esm/ui/indicator/types.d.ts +2 -0
  33. package/esm/ui/layout/layout.js +3 -1
  34. package/esm/ui/layout/layout.js.map +1 -1
  35. package/esm/ui/layout/types.d.ts +2 -0
  36. package/esm/ui/legend/category/item.d.ts +2 -0
  37. package/esm/ui/legend/category/item.js +10 -4
  38. package/esm/ui/legend/category/item.js.map +1 -1
  39. package/esm/ui/legend/category/items.d.ts +2 -0
  40. package/esm/ui/legend/category/items.js.map +1 -1
  41. package/esm/ui/legend/category.js +4 -2
  42. package/esm/ui/legend/category.js.map +1 -1
  43. package/esm/ui/legend/continuous.d.ts +0 -1
  44. package/esm/ui/legend/continuous.js +5 -17
  45. package/esm/ui/legend/continuous.js.map +1 -1
  46. package/esm/ui/marker/index.js +4 -4
  47. package/esm/ui/marker/index.js.map +1 -1
  48. package/esm/ui/marker/types.d.ts +2 -0
  49. package/esm/ui/navigator/index.js +5 -0
  50. package/esm/ui/navigator/index.js.map +1 -1
  51. package/esm/ui/navigator/types.d.ts +2 -0
  52. package/esm/ui/scrollbar/index.js +4 -2
  53. package/esm/ui/scrollbar/index.js.map +1 -1
  54. package/esm/ui/scrollbar/types.d.ts +2 -0
  55. package/esm/ui/select/option.js +1 -1
  56. package/esm/ui/select/option.js.map +1 -1
  57. package/esm/ui/select/select.js +11 -9
  58. package/esm/ui/select/select.js.map +1 -1
  59. package/esm/ui/select/types.d.ts +4 -0
  60. package/esm/ui/slider/constant.d.ts +2 -0
  61. package/esm/ui/slider/constant.js +2 -0
  62. package/esm/ui/slider/constant.js.map +1 -1
  63. package/esm/ui/slider/handle.d.ts +4 -0
  64. package/esm/ui/slider/handle.js +14 -17
  65. package/esm/ui/slider/handle.js.map +1 -1
  66. package/esm/ui/slider/index.js +17 -16
  67. package/esm/ui/slider/index.js.map +1 -1
  68. package/esm/ui/slider/types.d.ts +2 -0
  69. package/esm/ui/sparkline/columns.d.ts +2 -0
  70. package/esm/ui/sparkline/columns.js +2 -1
  71. package/esm/ui/sparkline/columns.js.map +1 -1
  72. package/esm/ui/sparkline/index.js +4 -2
  73. package/esm/ui/sparkline/index.js.map +1 -1
  74. package/esm/ui/sparkline/lines.d.ts +2 -0
  75. package/esm/ui/sparkline/lines.js +2 -1
  76. package/esm/ui/sparkline/lines.js.map +1 -1
  77. package/esm/ui/sparkline/types.d.ts +2 -0
  78. package/esm/ui/switch/index.js +1 -0
  79. package/esm/ui/switch/index.js.map +1 -1
  80. package/esm/ui/switch/types.d.ts +2 -0
  81. package/esm/ui/tag/index.js +1 -0
  82. package/esm/ui/tag/index.js.map +1 -1
  83. package/esm/ui/tag/types.d.ts +2 -0
  84. package/esm/ui/timebar/controller.js +8 -8
  85. package/esm/ui/timebar/controller.js.map +1 -1
  86. package/esm/ui/timebar/handle.d.ts +4 -0
  87. package/esm/ui/timebar/handle.js +9 -7
  88. package/esm/ui/timebar/handle.js.map +1 -1
  89. package/esm/ui/timebar/icons.js +103 -90
  90. package/esm/ui/timebar/icons.js.map +1 -1
  91. package/esm/ui/timebar/timebar.js +14 -6
  92. package/esm/ui/timebar/timebar.js.map +1 -1
  93. package/esm/ui/timebar/types.d.ts +4 -0
  94. package/esm/ui/tooltip/index.d.ts +11 -2
  95. package/esm/ui/tooltip/index.js +53 -26
  96. package/esm/ui/tooltip/index.js.map +1 -1
  97. package/esm/ui/tooltip/types.d.ts +4 -0
  98. package/esm/util/bbox.d.ts +5 -0
  99. package/esm/util/bbox.js +7 -0
  100. package/esm/util/bbox.js.map +1 -1
  101. package/esm/util/keyframe-interpolate.d.ts +1 -1
  102. package/esm/util/primitive.js +0 -3
  103. package/esm/util/primitive.js.map +1 -1
  104. package/esm/util/scale-to-pixel.js +3 -2
  105. package/esm/util/scale-to-pixel.js.map +1 -1
  106. package/esm/util/text.d.ts +6 -1
  107. package/lib/animation/fadeIn.d.ts +1 -1
  108. package/lib/animation/fadeOut.d.ts +1 -1
  109. package/lib/animation/utils.d.ts +3 -3
  110. package/lib/animation/utils.js +10 -14
  111. package/lib/animation/utils.js.map +1 -1
  112. package/lib/ui/axis/constant.js +0 -1
  113. package/lib/ui/axis/constant.js.map +1 -1
  114. package/lib/ui/axis/guides/labels.js +11 -9
  115. package/lib/ui/axis/guides/labels.js.map +1 -1
  116. package/lib/ui/axis/guides/ticks.js +1 -1
  117. package/lib/ui/axis/guides/ticks.js.map +1 -1
  118. package/lib/ui/axis/guides/title.js +5 -8
  119. package/lib/ui/axis/guides/title.js.map +1 -1
  120. package/lib/ui/axis/overlap/autoEllipsis.js +1 -2
  121. package/lib/ui/axis/overlap/autoEllipsis.js.map +1 -1
  122. package/lib/ui/axis/overlap/autoHide.js +1 -2
  123. package/lib/ui/axis/overlap/autoHide.js.map +1 -1
  124. package/lib/ui/axis/utils/bounds.d.ts +3 -1
  125. package/lib/ui/axis/utils/bounds.js +5 -9
  126. package/lib/ui/axis/utils/bounds.js.map +1 -1
  127. package/lib/ui/breadcrumb/index.js +2 -2
  128. package/lib/ui/breadcrumb/index.js.map +1 -1
  129. package/lib/ui/button/index.js +8 -6
  130. package/lib/ui/button/index.js.map +1 -1
  131. package/lib/ui/button/types.d.ts +2 -0
  132. package/lib/ui/checkbox/constant.d.ts +2 -2
  133. package/lib/ui/checkbox/index.js +1 -1
  134. package/lib/ui/checkbox/index.js.map +1 -1
  135. package/lib/ui/indicator/indicator.js +2 -1
  136. package/lib/ui/indicator/indicator.js.map +1 -1
  137. package/lib/ui/indicator/types.d.ts +2 -0
  138. package/lib/ui/layout/layout.js +3 -1
  139. package/lib/ui/layout/layout.js.map +1 -1
  140. package/lib/ui/layout/types.d.ts +2 -0
  141. package/lib/ui/legend/category/item.d.ts +2 -0
  142. package/lib/ui/legend/category/item.js +10 -4
  143. package/lib/ui/legend/category/item.js.map +1 -1
  144. package/lib/ui/legend/category/items.d.ts +2 -0
  145. package/lib/ui/legend/category/items.js.map +1 -1
  146. package/lib/ui/legend/category.js +4 -2
  147. package/lib/ui/legend/category.js.map +1 -1
  148. package/lib/ui/legend/continuous.d.ts +0 -1
  149. package/lib/ui/legend/continuous.js +5 -17
  150. package/lib/ui/legend/continuous.js.map +1 -1
  151. package/lib/ui/marker/index.js +4 -4
  152. package/lib/ui/marker/index.js.map +1 -1
  153. package/lib/ui/marker/types.d.ts +2 -0
  154. package/lib/ui/navigator/index.js +5 -0
  155. package/lib/ui/navigator/index.js.map +1 -1
  156. package/lib/ui/navigator/types.d.ts +2 -0
  157. package/lib/ui/scrollbar/index.js +4 -2
  158. package/lib/ui/scrollbar/index.js.map +1 -1
  159. package/lib/ui/scrollbar/types.d.ts +2 -0
  160. package/lib/ui/select/option.js +1 -1
  161. package/lib/ui/select/option.js.map +1 -1
  162. package/lib/ui/select/select.js +11 -9
  163. package/lib/ui/select/select.js.map +1 -1
  164. package/lib/ui/select/types.d.ts +4 -0
  165. package/lib/ui/slider/constant.d.ts +2 -0
  166. package/lib/ui/slider/constant.js +2 -0
  167. package/lib/ui/slider/constant.js.map +1 -1
  168. package/lib/ui/slider/handle.d.ts +4 -0
  169. package/lib/ui/slider/handle.js +14 -17
  170. package/lib/ui/slider/handle.js.map +1 -1
  171. package/lib/ui/slider/index.js +17 -16
  172. package/lib/ui/slider/index.js.map +1 -1
  173. package/lib/ui/slider/types.d.ts +2 -0
  174. package/lib/ui/sparkline/columns.d.ts +2 -0
  175. package/lib/ui/sparkline/columns.js +2 -1
  176. package/lib/ui/sparkline/columns.js.map +1 -1
  177. package/lib/ui/sparkline/index.js +4 -2
  178. package/lib/ui/sparkline/index.js.map +1 -1
  179. package/lib/ui/sparkline/lines.d.ts +2 -0
  180. package/lib/ui/sparkline/lines.js +2 -1
  181. package/lib/ui/sparkline/lines.js.map +1 -1
  182. package/lib/ui/sparkline/types.d.ts +2 -0
  183. package/lib/ui/switch/index.js +1 -0
  184. package/lib/ui/switch/index.js.map +1 -1
  185. package/lib/ui/switch/types.d.ts +2 -0
  186. package/lib/ui/tag/index.js +1 -0
  187. package/lib/ui/tag/index.js.map +1 -1
  188. package/lib/ui/tag/types.d.ts +2 -0
  189. package/lib/ui/timebar/controller.js +8 -8
  190. package/lib/ui/timebar/controller.js.map +1 -1
  191. package/lib/ui/timebar/handle.d.ts +4 -0
  192. package/lib/ui/timebar/handle.js +9 -7
  193. package/lib/ui/timebar/handle.js.map +1 -1
  194. package/lib/ui/timebar/icons.js +103 -90
  195. package/lib/ui/timebar/icons.js.map +1 -1
  196. package/lib/ui/timebar/timebar.js +14 -6
  197. package/lib/ui/timebar/timebar.js.map +1 -1
  198. package/lib/ui/timebar/types.d.ts +4 -0
  199. package/lib/ui/tooltip/index.d.ts +11 -2
  200. package/lib/ui/tooltip/index.js +51 -24
  201. package/lib/ui/tooltip/index.js.map +1 -1
  202. package/lib/ui/tooltip/types.d.ts +4 -0
  203. package/lib/util/bbox.d.ts +5 -0
  204. package/lib/util/bbox.js +7 -0
  205. package/lib/util/bbox.js.map +1 -1
  206. package/lib/util/keyframe-interpolate.d.ts +1 -1
  207. package/lib/util/primitive.js +0 -3
  208. package/lib/util/primitive.js.map +1 -1
  209. package/lib/util/scale-to-pixel.js +3 -2
  210. package/lib/util/scale-to-pixel.js.map +1 -1
  211. package/lib/util/text.d.ts +6 -1
  212. package/package.json +6 -6
  213. package/src/animation/utils.ts +16 -15
  214. package/src/ui/axis/constant.ts +0 -1
  215. package/src/ui/axis/guides/labels.ts +18 -10
  216. package/src/ui/axis/guides/ticks.ts +1 -1
  217. package/src/ui/axis/guides/title.ts +9 -9
  218. package/src/ui/axis/overlap/autoEllipsis.ts +1 -2
  219. package/src/ui/axis/overlap/autoHide.ts +1 -2
  220. package/src/ui/axis/utils/bounds.ts +4 -7
  221. package/src/ui/breadcrumb/index.ts +2 -3
  222. package/src/ui/button/index.ts +10 -6
  223. package/src/ui/button/types.ts +2 -0
  224. package/src/ui/checkbox/index.ts +0 -2
  225. package/src/ui/indicator/indicator.ts +2 -1
  226. package/src/ui/indicator/types.ts +2 -0
  227. package/src/ui/layout/layout.ts +4 -1
  228. package/src/ui/layout/types.ts +2 -0
  229. package/src/ui/legend/category/item.ts +14 -4
  230. package/src/ui/legend/category/items.ts +2 -0
  231. package/src/ui/legend/category.ts +4 -2
  232. package/src/ui/legend/continuous.ts +5 -20
  233. package/src/ui/marker/index.ts +5 -4
  234. package/src/ui/marker/types.ts +2 -0
  235. package/src/ui/navigator/index.ts +7 -0
  236. package/src/ui/navigator/types.ts +2 -0
  237. package/src/ui/scrollbar/index.ts +5 -1
  238. package/src/ui/scrollbar/types.ts +2 -0
  239. package/src/ui/select/option.ts +1 -1
  240. package/src/ui/select/select.ts +11 -9
  241. package/src/ui/select/types.ts +4 -0
  242. package/src/ui/slider/constant.ts +2 -0
  243. package/src/ui/slider/handle.ts +26 -14
  244. package/src/ui/slider/index.ts +20 -12
  245. package/src/ui/slider/types.ts +2 -0
  246. package/src/ui/sparkline/columns.ts +4 -1
  247. package/src/ui/sparkline/index.ts +8 -2
  248. package/src/ui/sparkline/lines.ts +4 -1
  249. package/src/ui/sparkline/types.ts +2 -0
  250. package/src/ui/switch/index.ts +1 -0
  251. package/src/ui/switch/types.ts +2 -0
  252. package/src/ui/tag/index.ts +1 -0
  253. package/src/ui/tag/types.ts +2 -0
  254. package/src/ui/timebar/controller.ts +8 -8
  255. package/src/ui/timebar/handle.ts +16 -10
  256. package/src/ui/timebar/icons.ts +93 -86
  257. package/src/ui/timebar/timebar.ts +13 -9
  258. package/src/ui/timebar/types.ts +4 -0
  259. package/src/ui/tooltip/index.ts +58 -19
  260. package/src/ui/tooltip/types.ts +4 -0
  261. package/src/util/bbox.ts +8 -0
  262. package/src/util/primitive.ts +0 -3
  263. package/src/util/scale-to-pixel.ts +3 -1
@@ -187,24 +187,30 @@ function overlapHandler(attr: Required<AxisStyleProps>) {
187
187
  });
188
188
  }
189
189
 
190
- function renderLabel(container: DisplayObject, datum: any, data: any[], style: any, attr: Required<AxisStyleProps>) {
190
+ function renderLabel(
191
+ container: DisplayObject,
192
+ datum: any,
193
+ data: any[],
194
+ style: any,
195
+ attr: Required<AxisStyleProps>
196
+ ): DisplayObject {
191
197
  const index = data.indexOf(datum);
192
198
  const label = select(container)
193
199
  .append(formatter(datum, index, data, attr))
194
200
  .attr('className', CLASS_NAMES.labelItem.name)
195
201
  .node();
196
202
  const [labelStyle, { transform, ...groupStyle }] = splitStyle(getCallbackStyle(style, [datum, index, data]));
197
- percentTransform(container, transform);
198
203
 
199
- const rotate = getLabelRotation(datum, container, attr);
200
- container.setLocalEulerAngles(+rotate);
204
+ percentTransform(label, transform);
205
+ const rotate = getLabelRotation(datum, label, attr);
206
+ if (!label.getLocalEulerAngles()) {
207
+ label.setLocalEulerAngles(rotate);
208
+ }
201
209
 
202
210
  applyTextStyle(label, {
203
211
  ...getLabelStyle(datum.value, rotate, attr),
204
212
  ...labelStyle,
205
213
  });
206
- // todo G transform 存在问题,需要二次设置
207
- percentTransform(container, transform);
208
214
  container.attr(groupStyle);
209
215
  return label;
210
216
  }
@@ -227,8 +233,9 @@ export function renderLabels(
227
233
  .attr('className', CLASS_NAMES.label.name)
228
234
  .transition(function (datum) {
229
235
  renderLabel(this, datum, data, style, attr);
230
- this.attr(getLabelPos(datum, data, attr));
231
- this.__bbox__ = datum.bbox;
236
+ const { x, y } = getLabelPos(datum, data, attr);
237
+ // .axis-label
238
+ this.style.transform = `translate(${x}, ${y})`;
232
239
  return null;
233
240
  })
234
241
  .call(() => overlapHandler.call(container, attr)),
@@ -238,9 +245,10 @@ export function renderLabels(
238
245
  const prevLabel = this.querySelector(CLASS_NAMES.labelItem.class);
239
246
  const label = renderLabel(this, datum, data, style, attr);
240
247
  const shapeAnimation = transitionShape(prevLabel, label, animate.update);
241
- const animation = transition(this, getLabelPos(datum, data, attr), animate.update);
242
- this.__bbox__ = datum.bbox;
248
+ const { x, y } = getLabelPos(datum, data, attr);
249
+ const animation = transition(this, { transform: `translate(${x}, ${y})` }, animate.update);
243
250
  return [...shapeAnimation, animation];
251
+ // return [animation];
244
252
  })
245
253
  .call((selection) => {
246
254
  const transitions = get(selection, '_transitions').flat().filter(defined) as IAnimation[];
@@ -77,7 +77,7 @@ function createTick(
77
77
  const tick = createTickEl(select(this), datum, index, data, attr);
78
78
  applyTickStyle(datum, index, data, tick, this, attr, tickAttr);
79
79
  const [x, y] = getValuePos(datum.value, attr);
80
- return transition(this, { x, y }, animate);
80
+ return transition(this, { transform: `translate(${x}, ${y})` }, animate);
81
81
  }
82
82
 
83
83
  export function renderTicks(
@@ -32,7 +32,9 @@ function getTitlePosition(
32
32
  halfExtents: [mainHalfWidth, mainHalfHeight],
33
33
  } = mainGroup.node().getLocalBounds();
34
34
 
35
- const [titleHalfWidth, titleHalfHeight] = titleGroup.node().getLocalBounds().halfExtents;
35
+ const {
36
+ halfExtents: [titleHalfWidth, titleHalfHeight],
37
+ } = titleGroup.node().getLocalBounds();
36
38
 
37
39
  let [x, y] = [mainX + mainHalfWidth, mainY + mainHalfHeight];
38
40
 
@@ -49,17 +51,16 @@ function getTitlePosition(
49
51
 
50
52
  if (pos.includes('t')) y -= mainHalfHeight + titleHalfHeight + spacingTop;
51
53
  if (pos.includes('r')) x += mainHalfWidth + titleHalfWidth + spacingRight;
52
- if (pos.includes('l')) x -= mainHalfWidth + titleHalfWidth * 2 + spacingLeft;
53
- if (pos.includes('b')) y += mainHalfHeight + titleHalfHeight * 2 + spacingBottom;
54
+ if (pos.includes('l')) x -= mainHalfWidth + titleHalfWidth + spacingLeft;
55
+ if (pos.includes('b')) y += mainHalfHeight + titleHalfHeight + spacingBottom;
54
56
 
55
57
  return { x, y };
56
58
  }
57
59
 
58
60
  function inferTransform(n: DisplayObject, direction: string, position: string): string {
59
61
  const node = n.cloneNode(true);
60
- node.style.transform = 'scale(1, 1)';
61
- node.style.transform = 'none';
62
62
  const { height } = node.getBBox();
63
+
63
64
  if (direction === 'vertical') {
64
65
  if (position === 'left') return `rotate(-90) translate(0, ${height / 2})`;
65
66
  if (position === 'right') return `rotate(-90) translate(0, -${height / 2})`;
@@ -75,12 +76,12 @@ function applyTitleStyle(
75
76
  animate: GenericAnimation
76
77
  ) {
77
78
  const style = subStyleProps(attr, 'title');
78
- const [titleStyle, { transform: specified, ...groupStyle }] = splitStyle(style);
79
+ const [titleStyle, { transform: specified, transformOrigin, ...groupStyle }] = splitStyle(style);
79
80
 
80
- title.styles(titleStyle);
81
81
  group.styles(groupStyle);
82
82
 
83
83
  const transform = specified || inferTransform(title.node(), titleStyle.direction, titleStyle.position);
84
+ title.styles({ ...titleStyle, transformOrigin });
84
85
  percentTransform(title.node(), transform);
85
86
 
86
87
  const { x, y } = getTitlePosition(
@@ -90,8 +91,7 @@ function applyTitleStyle(
90
91
  attr
91
92
  );
92
93
 
93
- const animation = transition(group.node(), { x, y }, animate);
94
- percentTransform(title.node(), transform);
94
+ const animation = transition(group.node(), { transform: `translate(${x}, ${y})` }, animate);
95
95
  return animation;
96
96
  }
97
97
 
@@ -3,7 +3,6 @@ import type { DisplayObject } from '../../../shapes';
3
3
  import { Text } from '../../../shapes';
4
4
  import { getFont, measureTextWidth } from '../../../util';
5
5
  import { AxisStyleProps, EllipsisOverlapCfg } from '../types';
6
- import { getBBox } from '../utils/bounds';
7
6
  import { boundTest } from '../utils/test';
8
7
 
9
8
  export type Utils = {
@@ -40,7 +39,7 @@ export default function ellipseLabels(
40
39
  if (isNil(max) || max === Infinity) {
41
40
  max = Math.max.apply(
42
41
  null,
43
- labels.map((d) => getBBox(d).width)
42
+ labels.map((d) => d.getBBox().width)
44
43
  );
45
44
  }
46
45
  // Generally, 100 ticks cost less than 300ms. If cost time exceed, means ticks count is too large to see.
@@ -3,7 +3,6 @@ import { defined, getLocalBBox, hide } from '../../../util';
3
3
  import { isAxisHorizontal, isAxisVertical } from '../guides/line';
4
4
  import type { AxisStyleProps, HideOverlapCfg } from '../types';
5
5
  import { boundTest } from '../utils/test';
6
- import { getBBox } from '../utils/bounds';
7
6
 
8
7
  type Hide = (item: DisplayObject) => void;
9
8
  type Show = (item: DisplayObject) => void;
@@ -32,7 +31,7 @@ export default function hideLabels(
32
31
  const source = labels.slice();
33
32
  let target = labels.slice();
34
33
 
35
- const minLabelWidth = Math.min(1, ...labels.map((d) => getBBox(d).width));
34
+ const minLabelWidth = Math.min(1, ...labels.map((d) => d.getBBox().width));
36
35
 
37
36
  if (attr.type === 'linear' && (isAxisHorizontal(attr) || isAxisVertical(attr))) {
38
37
  const minX = getLocalBBox(labels[0]).left;
@@ -78,6 +78,9 @@ export class Bounds {
78
78
  }
79
79
  }
80
80
 
81
+ /**
82
+ * Can't use getBounds directly since we should not use AABB here.
83
+ */
81
84
  export function getBounds(item: DisplayObject<any>, margin?: SeriesAttr) {
82
85
  const angle = item.getEulerAngles() || 0;
83
86
  item.setEulerAngles(0);
@@ -86,7 +89,7 @@ export function getBounds(item: DisplayObject<any>, margin?: SeriesAttr) {
86
89
  min: [x, y],
87
90
  max: [right, bottom],
88
91
  } = item.getLocalBounds();
89
- const { width: w, height: h } = getBBox(item);
92
+ const { width: w, height: h } = item.getBBox();
90
93
 
91
94
  let height = h;
92
95
  let dx = 0;
@@ -124,9 +127,3 @@ export function getBounds(item: DisplayObject<any>, margin?: SeriesAttr) {
124
127
  item.setEulerAngles(angle);
125
128
  return bounds.rotatedPoints(degToRad(angle), anchorX, anchorY);
126
129
  }
127
-
128
- export function getBBox(shape: DisplayObject): DOMRect {
129
- // @ts-ignore
130
- if (shape.__bbox__) return shape.__bbox__;
131
- return shape.getBBox();
132
- }
@@ -69,8 +69,7 @@ export class Breadcrumb extends Component<BreadcrumbStyleProps> {
69
69
  const shape = new Tag({
70
70
  className: 'breadcrumb-item',
71
71
  style: {
72
- x: cursorX,
73
- y: cursorY,
72
+ transform: `translate(${cursorX}, ${cursorY})`,
74
73
  ...tagStyle,
75
74
  text: isNil(datum.text) ? datum.id : datum.text,
76
75
  ...pick(datum, ['marker']),
@@ -88,7 +87,7 @@ export class Breadcrumb extends Component<BreadcrumbStyleProps> {
88
87
  if (!isNil(width)) {
89
88
  const avaliableWidth = width! - right;
90
89
  if (cursorX > avaliableWidth) {
91
- shape.attr({ x: 0, y: cursorY + shapeH });
90
+ shape.attr({ transform: `translateY(${cursorY + shapeH})` });
92
91
  // 更新光标
93
92
  cursorX = shapeW;
94
93
  cursorY += shapeH;
@@ -95,8 +95,10 @@ export class Button extends Component<ButtonStyleProps> {
95
95
 
96
96
  // @todo 处理 markerAlign='right' 的场景. 方案: left marker & right marker 处理为两个 shape, 互相不干扰
97
97
  public render(attributes: Required<ButtonStyleProps>, container: Group) {
98
- const { text = '', padding = 0, markerSymbol, markerSpacing = 0 } = attributes;
99
- container.attr('cursor', this.state === 'disabled' ? 'not-allowed' : 'pointer');
98
+ const { text = '', padding = 0, markerSymbol, markerSpacing = 0, x = 0, y = 0 } = attributes;
99
+ container.attr({
100
+ cursor: this.state === 'disabled' ? 'not-allowed' : 'pointer',
101
+ });
100
102
  const [pt, pr, pb, pl] = parseSeriesAttr(padding);
101
103
  const height = this.buttonHeight;
102
104
 
@@ -106,8 +108,8 @@ export class Button extends Component<ButtonStyleProps> {
106
108
  const style = {
107
109
  ...markerStyle,
108
110
  symbol: markerSymbol,
109
- x: pl + markerSize / 2,
110
- y: height / 2,
111
+ x: x + pl + markerSize / 2,
112
+ y: y + height / 2,
111
113
  size: markerSize,
112
114
  };
113
115
  const markerShape = maybeAppend(container, '.marker', () => new Marker({ className: 'marker', style }))
@@ -120,8 +122,8 @@ export class Button extends Component<ButtonStyleProps> {
120
122
  this.textShape = maybeAppend(container, '.text', 'text')
121
123
  .attr('className', 'text')
122
124
  .styles({
123
- x: markerSize ? bounds.max[0] + markerSpacing : pl,
124
- y: height / 2,
125
+ x: x + (markerSize ? bounds.max[0] + markerSpacing : pl),
126
+ y: y + height / 2,
125
127
  ...textStyle,
126
128
  text,
127
129
  textAlign: 'left',
@@ -141,6 +143,8 @@ export class Button extends Component<ButtonStyleProps> {
141
143
  .styles({
142
144
  zIndex: -1,
143
145
  ...buttonStyle,
146
+ x,
147
+ y,
144
148
  height,
145
149
  width: pl + (markerSize ? markerSize + markerSpacing : 0) + textBounds.halfExtents[0] * 2 + pr,
146
150
  });
@@ -13,6 +13,8 @@ export type ButtonStyleProps = GroupStyleProps &
13
13
  Partial<PrefixStyleProps<RectStyleProps, 'button'>> &
14
14
  Partial<PrefixStyleProps<Omit<MarkerStyleProps, 'symbol'>, 'marker'>>
15
15
  > & {
16
+ x?: number;
17
+ y?: number;
16
18
  type?: 'primary' | 'dashed' | 'link' | 'text' | 'default';
17
19
  /**
18
20
  * @title 大小
@@ -30,8 +30,6 @@ export class Checkbox extends Component<CheckboxStyleProps> {
30
30
 
31
31
  constructor(options: CheckboxOptions) {
32
32
  super(options, {
33
- x: 0,
34
- y: 0,
35
33
  labelText: '',
36
34
  spacing: 4,
37
35
  checked: false,
@@ -78,7 +78,8 @@ export class Indicator extends Component<IndicatorStyleProps> {
78
78
 
79
79
  private adjustLayout() {
80
80
  const [dx, dy] = this.point;
81
- this.group.attr('x', -dx).attr('y', -dy);
81
+ const { x, y } = this.attributes;
82
+ this.group.attr('transform', `translate(${x - dx}, ${y - dy})`);
82
83
  }
83
84
 
84
85
  private getPath(position: Position, bbox: BBox) {
@@ -8,6 +8,8 @@ export type Position = 'top' | 'right' | 'bottom' | 'left';
8
8
  export type IndicatorStyleProps<T = any> = GroupStyleProps &
9
9
  PrefixObject<PathStyleProps, 'background'> &
10
10
  PrefixObject<Omit<TextStyleProps, 'text'>, 'label'> & {
11
+ x: number;
12
+ y: number;
11
13
  labelText?: T;
12
14
  /** position of indicator related to pointer */
13
15
  position?: Position;
@@ -71,6 +71,9 @@ export class Layout extends Group {
71
71
  if (!this.attributes.display || !this.isConnected) return;
72
72
  if (this.children.some((child) => !child.isConnected)) return;
73
73
  try {
74
+ const { x, y } = this.attributes;
75
+ this.style.transform = `translate(${x}, ${y})`;
76
+
74
77
  const bboxes = calcLayout(
75
78
  this.getAvailableSpace(),
76
79
  this.children.map((child) => (child as DisplayObject).getBBox()),
@@ -79,7 +82,7 @@ export class Layout extends Group {
79
82
 
80
83
  this.children.forEach((child, index) => {
81
84
  const { x, y } = bboxes[index];
82
- (child as DisplayObject).attr({ x, y });
85
+ child.style.transform = `translate(${x}, ${y})`;
83
86
  });
84
87
  } catch (e) {
85
88
  // do nothing
@@ -4,6 +4,8 @@ import type { SeriesAttr } from '../../util/series';
4
4
 
5
5
  export type LayoutStyleProps = GroupStyleProps &
6
6
  LayoutElementConfig & {
7
+ x?: number;
8
+ y?: number;
7
9
  width: number;
8
10
  height: number;
9
11
  margin?: SeriesAttr;
@@ -42,6 +42,8 @@ export type CategoryItemStyleProps = GroupStyleProps &
42
42
  valueText?: ExtendDisplayObject;
43
43
  // if width and height not specific, set it to actual space occurred
44
44
  width?: number;
45
+ x?: number;
46
+ y?: number;
45
47
  };
46
48
 
47
49
  export type CategoryItemOptions = ComponentOptions<CategoryItemStyleProps>;
@@ -196,7 +198,8 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
196
198
 
197
199
  // record the scale of marker
198
200
  this.markerGroup.node().scale(1 / this.markerGroup.node().getScale()[0]);
199
- scaleToPixel(this.markerGroup.node(), this.scaleSize, true);
201
+ const scale = scaleToPixel(this.markerGroup.node(), this.scaleSize, true);
202
+ this.markerGroup.node().style._transform = `scale(${scale})`;
200
203
  });
201
204
  }
202
205
 
@@ -231,18 +234,25 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
231
234
  },
232
235
  } = this;
233
236
  const halfHeight = height / 2;
234
- this.markerGroup.styles({ x: markerX, y: halfHeight });
235
- this.labelGroup.styles({ x: labelX, y: halfHeight });
237
+
238
+ // console.log(this.markerGroup.node().style._transform);
239
+
240
+ this.markerGroup.styles({
241
+ transform: `translate(${markerX}, ${halfHeight})${this.markerGroup.node().style._transform}`,
242
+ });
243
+ this.labelGroup.styles({ transform: `translate(${labelX}, ${halfHeight})` });
236
244
 
237
245
  ellipsisIt(this.labelGroup.select(CLASS_NAMES.label.class).node(), Math.ceil(labelWidth));
238
246
  if (this.showValue) {
239
- this.valueGroup.styles({ x: valueX, y: halfHeight });
247
+ this.valueGroup.styles({ transform: `translate(${valueX}, ${halfHeight})` });
240
248
  ellipsisIt(this.valueGroup.select(CLASS_NAMES.value.class).node(), Math.ceil(valueWidth));
241
249
  }
242
250
  }
243
251
 
244
252
  public render(attributes: CategoryItemStyleProps, container: Group) {
245
253
  const ctn = select(container);
254
+ const { x = 0, y = 0 } = attributes;
255
+ ctn.styles({ transform: `translate(${x}, ${y})` });
246
256
  this.renderMarker(ctn);
247
257
  this.renderLabel(ctn);
248
258
  this.renderValue(ctn);
@@ -36,6 +36,8 @@ export type CategoryItemsStyleProps = GroupStyleProps &
36
36
  data: CategoryItemsDatum[];
37
37
  orientation?: 'horizontal' | 'vertical';
38
38
  layout?: 'flex' | 'grid';
39
+ x?: number;
40
+ y?: number;
39
41
  width?: number;
40
42
  height?: number;
41
43
  gridRow?: number;
@@ -66,7 +66,8 @@ export class Category extends Component<CategoryStyleProps> {
66
66
  const { showTitle } = this.attributes;
67
67
  if (showTitle) {
68
68
  const { x, y } = this.title.node<Title>().getAvailableSpace();
69
- this.itemsGroup.node().setLocalPosition(x, y);
69
+ this.itemsGroup.node().style.transform = `translate(${x}, ${y})`;
70
+ // this.itemsGroup.node().setLocalPosition(x, y);
70
71
  }
71
72
  }
72
73
 
@@ -84,8 +85,9 @@ export class Category extends Component<CategoryStyleProps> {
84
85
  }
85
86
 
86
87
  render(attributes: Required<CategoryStyleProps>, container: Group) {
87
- const { width, height } = attributes;
88
+ const { width, height, x = 0, y = 0 } = this.attributes;
88
89
  const ctn = select(container);
90
+ container.style.transform = `translate(${x}, ${y})`;
89
91
 
90
92
  this.renderTitle(ctn, width!, height!);
91
93
 
@@ -92,7 +92,9 @@ export class Continuous extends Component<ContinuousStyleProps> {
92
92
  /** label */
93
93
 
94
94
  /** content */
95
- const contentGroup = select(container).maybeAppendByClassName(CLASS_NAMES.contentGroup, 'g').styles({ x, y });
95
+ const contentGroup = select(container)
96
+ .maybeAppendByClassName(CLASS_NAMES.contentGroup, 'g')
97
+ .styles({ transform: `translate(${x}, ${y})` });
96
98
 
97
99
  const labelGroup = contentGroup.maybeAppendByClassName(CLASS_NAMES.labelGroup, 'g').styles({ zIndex: 1 });
98
100
  ifShow(!!showLabel, labelGroup, (group) => {
@@ -268,8 +270,7 @@ export class Continuous extends Component<ContinuousStyleProps> {
268
270
  const { length, size } = this.ribbonShape;
269
271
  const style: Required<RibbonStyleProps> = deepAssign(
270
272
  {
271
- x,
272
- y,
273
+ transform: `translate(${x}, ${y})`,
273
274
  length,
274
275
  size,
275
276
  type,
@@ -344,22 +345,6 @@ export class Continuous extends Component<ContinuousStyleProps> {
344
345
  this.setHandlePosition('end', max);
345
346
  }
346
347
 
347
- private adjustTitle() {
348
- const { titlePosition, orientation } = this.attributes;
349
- const [title] = this.getElementsByClassName(CLASS_NAMES.title.name);
350
- const handle: Handle = this.handlesGroup.select(`.${this.getHandleClassName('start')}`).node();
351
- if (!title || !handle) return;
352
- if (titlePosition !== 'top-left' || orientation !== 'horizontal') return;
353
- const {
354
- min: [handleX],
355
- } = handle.getLocalBounds();
356
- const {
357
- min: [titleX],
358
- } = title.getLocalBounds();
359
- const diffX = handleX - titleX;
360
- title.style.x = +(this.style.x || 0) + diffX;
361
- }
362
-
363
348
  private cacheHandleBBox: DOMRect | null = null;
364
349
 
365
350
  private get handleBBox() {
@@ -391,7 +376,7 @@ export class Continuous extends Component<ContinuousStyleProps> {
391
376
  [ribbonX + ribbonSize * this.handleOffsetRatio, ribbonY + offset]
392
377
  );
393
378
  const handle: Handle = this.handlesGroup.select(`.${this.getHandleClassName(type)}`).node();
394
- handle?.update({ x, y, formatter: handleFormatter });
379
+ handle?.update({ transform: `translate(${x}, ${y})`, formatter: handleFormatter });
395
380
  }
396
381
 
397
382
  private renderIndicator(container: Selection) {
@@ -44,7 +44,8 @@ function getType(symbol: MarkerStyleProps['symbol']): string | null {
44
44
 
45
45
  export class Marker extends Component<MarkerStyleProps> {
46
46
  public render(attributes: Required<MarkerStyleProps>, container: Group) {
47
- const { symbol, size = 16, ...style } = attributes;
47
+ const { symbol, size = 16, x = 0, y = 0, transform, transformOrigin, ...style } = attributes;
48
+
48
49
  const type = getType(symbol);
49
50
  ifShow(!!type, select(container), (group) => {
50
51
  group
@@ -58,13 +59,13 @@ export class Marker extends Component<MarkerStyleProps> {
58
59
  img: symbol,
59
60
  width: r,
60
61
  height: r,
61
- x: -size,
62
- y: -size,
62
+ x: x - size,
63
+ y: y - size,
63
64
  });
64
65
  } else {
65
66
  const r = (size as number) / 2;
66
67
  const symbolFn = isFunction(symbol) ? symbol : Marker.getSymbol(symbol);
67
- selection.styles({ path: symbolFn?.(0, 0, r), ...style });
68
+ selection.styles({ path: symbolFn?.(x, y, r), ...style });
68
69
  }
69
70
  });
70
71
  });
@@ -4,6 +4,8 @@ import type { BaseCustomElementStyleProps } from '../../shapes';
4
4
  export type FunctionalSymbol = (x: number, y: number, r: number) => any;
5
5
 
6
6
  export type MarkerStyleProps = BaseCustomElementStyleProps & {
7
+ x?: number;
8
+ y?: number;
7
9
  size?: number;
8
10
  symbol: string | FunctionalSymbol;
9
11
  };
@@ -41,6 +41,8 @@ const CLASS_NAMES = classNames(
41
41
  export class Navigator extends Component<NavigatorStyleProps> {
42
42
  constructor(options: NavigatorOptions) {
43
43
  super(options, {
44
+ x: 0,
45
+ y: 0,
44
46
  animate: {
45
47
  easing: 'linear',
46
48
  duration: 200,
@@ -305,6 +307,8 @@ export class Navigator extends Component<NavigatorStyleProps> {
305
307
 
306
308
  this.updatePageInfo();
307
309
 
310
+ // group.node().style.transform = `translate(${pageWidth + spacing}, ${pageHeight / 2})`;
311
+
308
312
  // put it on the right side of the container
309
313
  group.node().setLocalPosition(pageWidth + spacing, pageHeight / 2);
310
314
  if (whetherToAddEventListener) {
@@ -318,6 +322,9 @@ export class Navigator extends Component<NavigatorStyleProps> {
318
322
  }
319
323
 
320
324
  render(attributes: NavigatorStyleProps, container: Group) {
325
+ const { x = 0, y = 0 } = attributes;
326
+ this.attr('transform', `translate(${x}, ${y})`);
327
+
321
328
  /**
322
329
  * container
323
330
  * |- contentGroup (with clip path)
@@ -6,6 +6,8 @@ import type { PrefixObject } from '../../types';
6
6
  export type NavigatorStyleProps = Omit<RectStyleProps, 'width' | 'height'> &
7
7
  PrefixObject<PathStyleProps & { size?: number }, 'button'> &
8
8
  PrefixObject<TextStyleProps, 'pageNum'> & {
9
+ x?: number;
10
+ y?: number;
9
11
  animate?: GenericAnimation;
10
12
  /** padding between buttons and page number */
11
13
  controllerPadding?: number;
@@ -23,6 +23,8 @@ export class Scrollbar extends Component<ScrollbarStyleProps> {
23
23
 
24
24
  constructor(options: ScrollbarOptions) {
25
25
  super(options, {
26
+ x: 0,
27
+ y: 0,
26
28
  isRound: true,
27
29
  orientation: 'vertical',
28
30
  padding: [2, 2, 2, 2],
@@ -90,11 +92,13 @@ export class Scrollbar extends Component<ScrollbarStyleProps> {
90
92
  }
91
93
 
92
94
  private renderSlider(container: Group) {
93
- const { orientation, trackSize, padding, slidable } = this.attributes;
95
+ const { x, y, orientation, trackSize, padding, slidable } = this.attributes;
94
96
  const trackStyle = subStyleProps<RectStyleProps>(this.attributes, 'track');
95
97
  const selectionStyle = subStyleProps<RectStyleProps>(this.attributes, 'thumb');
96
98
 
97
99
  const style: SliderStyleProps = {
100
+ x,
101
+ y,
98
102
  brushable: false,
99
103
  orientation,
100
104
  padding,
@@ -8,6 +8,8 @@ import type { SliderStyleProps } from '../slider';
8
8
  export type ScrollbarStyleProps = GroupStyleProps &
9
9
  PrefixObject<RectStyleProps, 'track'> &
10
10
  PrefixObject<RectStyleProps, 'thumb'> & {
11
+ x?: number;
12
+ y?: number;
11
13
  /** 滑条朝向 */
12
14
  orientation?: Required<SliderStyleProps>['orientation'];
13
15
 
@@ -52,7 +52,7 @@ export class Option extends Component<OptionStyleProps> {
52
52
  fill: selected ? this.selectedColor : '#fff',
53
53
  });
54
54
  // place label
55
- this.label.attr({ x: left, y: (backgroundHeight - labelHeight) / 2 });
55
+ this.label.attr({ transform: `translate(${left}, ${(backgroundHeight - labelHeight) / 2})` });
56
56
  }
57
57
 
58
58
  constructor(options: OptionOptions) {