@antv/component 2.1.6 → 2.1.8

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 (201) 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/ui/axis/axis.d.ts +1 -1
  6. package/esm/ui/axis/axis.js +18 -2
  7. package/esm/ui/axis/axis.js.map +1 -1
  8. package/esm/ui/axis/classname-map.d.ts +18 -0
  9. package/esm/ui/axis/classname-map.js +20 -0
  10. package/esm/ui/axis/classname-map.js.map +1 -0
  11. package/esm/ui/axis/constant.js +16 -15
  12. package/esm/ui/axis/constant.js.map +1 -1
  13. package/esm/ui/axis/guides/grid.d.ts +1 -1
  14. package/esm/ui/axis/guides/grid.js +8 -1
  15. package/esm/ui/axis/guides/grid.js.map +1 -1
  16. package/esm/ui/axis/guides/labels.d.ts +1 -2
  17. package/esm/ui/axis/guides/labels.js +29 -7
  18. package/esm/ui/axis/guides/labels.js.map +1 -1
  19. package/esm/ui/axis/guides/line.js +31 -8
  20. package/esm/ui/axis/guides/line.js.map +1 -1
  21. package/esm/ui/axis/guides/ticks.d.ts +1 -1
  22. package/esm/ui/axis/guides/ticks.js +10 -3
  23. package/esm/ui/axis/guides/ticks.js.map +1 -1
  24. package/esm/ui/axis/guides/title.d.ts +1 -1
  25. package/esm/ui/axis/guides/title.js +6 -2
  26. package/esm/ui/axis/guides/title.js.map +1 -1
  27. package/esm/ui/axis/types.d.ts +6 -0
  28. package/esm/ui/axis/utils/classname.d.ts +46 -0
  29. package/esm/ui/axis/utils/classname.js +53 -0
  30. package/esm/ui/axis/utils/classname.js.map +1 -0
  31. package/esm/ui/axis/utils/index.d.ts +1 -0
  32. package/esm/ui/axis/utils/index.js +1 -0
  33. package/esm/ui/axis/utils/index.js.map +1 -1
  34. package/esm/ui/grid/index.d.ts +1 -1
  35. package/esm/ui/legend/category/item.d.ts +3 -1
  36. package/esm/ui/legend/category/item.js +42 -14
  37. package/esm/ui/legend/category/item.js.map +1 -1
  38. package/esm/ui/legend/category/items.d.ts +2 -0
  39. package/esm/ui/legend/category/items.js +12 -9
  40. package/esm/ui/legend/category/items.js.map +1 -1
  41. package/esm/ui/legend/category.js +11 -3
  42. package/esm/ui/legend/category.js.map +1 -1
  43. package/esm/ui/legend/classname-map.d.ts +37 -0
  44. package/esm/ui/legend/classname-map.js +38 -0
  45. package/esm/ui/legend/classname-map.js.map +1 -0
  46. package/esm/ui/legend/constant.d.ts +1 -0
  47. package/esm/ui/legend/constant.js +1 -0
  48. package/esm/ui/legend/constant.js.map +1 -1
  49. package/esm/ui/legend/continuous/handle.d.ts +1 -0
  50. package/esm/ui/legend/continuous/handle.js +23 -3
  51. package/esm/ui/legend/continuous/handle.js.map +1 -1
  52. package/esm/ui/legend/continuous/ribbon.d.ts +1 -0
  53. package/esm/ui/legend/continuous/ribbon.js +11 -1
  54. package/esm/ui/legend/continuous/ribbon.js.map +1 -1
  55. package/esm/ui/legend/continuous.d.ts +6 -0
  56. package/esm/ui/legend/continuous.js +77 -10
  57. package/esm/ui/legend/continuous.js.map +1 -1
  58. package/esm/ui/legend/title/index.js +5 -1
  59. package/esm/ui/legend/title/index.js.map +1 -1
  60. package/esm/ui/legend/title/types.d.ts +1 -0
  61. package/esm/ui/legend/types.d.ts +1 -0
  62. package/esm/ui/legend/utils/classname.d.ts +31 -0
  63. package/esm/ui/legend/utils/classname.js +35 -0
  64. package/esm/ui/legend/utils/classname.js.map +1 -0
  65. package/esm/ui/legend/utils/index.d.ts +1 -0
  66. package/esm/ui/legend/utils/index.js +2 -0
  67. package/esm/ui/legend/utils/index.js.map +1 -0
  68. package/esm/ui/navigator/index.js +19 -4
  69. package/esm/ui/navigator/index.js.map +1 -1
  70. package/esm/ui/navigator/types.d.ts +1 -0
  71. package/esm/ui/slider/handle.d.ts +2 -0
  72. package/esm/ui/slider/handle.js +21 -6
  73. package/esm/ui/slider/handle.js.map +1 -1
  74. package/esm/ui/slider/index.js +3 -7
  75. package/esm/ui/slider/index.js.map +1 -1
  76. package/esm/util/extend-display-object.d.ts +2 -0
  77. package/esm/util/extend-display-object.js +7 -1
  78. package/esm/util/extend-display-object.js.map +1 -1
  79. package/esm/util/index.d.ts +1 -0
  80. package/esm/util/index.js +1 -0
  81. package/esm/util/index.js.map +1 -1
  82. package/esm/util/keyframe-interpolate.d.ts +1 -1
  83. package/esm/util/parse-height-from-html.d.ts +1 -0
  84. package/esm/util/parse-height-from-html.js +95 -0
  85. package/esm/util/parse-height-from-html.js.map +1 -0
  86. package/lib/animation/fadeIn.d.ts +1 -1
  87. package/lib/animation/fadeOut.d.ts +1 -1
  88. package/lib/animation/utils.d.ts +3 -3
  89. package/lib/ui/axis/axis.d.ts +1 -1
  90. package/lib/ui/axis/axis.js +18 -2
  91. package/lib/ui/axis/axis.js.map +1 -1
  92. package/lib/ui/axis/classname-map.d.ts +18 -0
  93. package/lib/ui/axis/classname-map.js +23 -0
  94. package/lib/ui/axis/classname-map.js.map +1 -0
  95. package/lib/ui/axis/constant.js +16 -15
  96. package/lib/ui/axis/constant.js.map +1 -1
  97. package/lib/ui/axis/guides/grid.d.ts +1 -1
  98. package/lib/ui/axis/guides/grid.js +8 -1
  99. package/lib/ui/axis/guides/grid.js.map +1 -1
  100. package/lib/ui/axis/guides/labels.d.ts +1 -2
  101. package/lib/ui/axis/guides/labels.js +27 -5
  102. package/lib/ui/axis/guides/labels.js.map +1 -1
  103. package/lib/ui/axis/guides/line.js +31 -8
  104. package/lib/ui/axis/guides/line.js.map +1 -1
  105. package/lib/ui/axis/guides/ticks.d.ts +1 -1
  106. package/lib/ui/axis/guides/ticks.js +10 -3
  107. package/lib/ui/axis/guides/ticks.js.map +1 -1
  108. package/lib/ui/axis/guides/title.d.ts +1 -1
  109. package/lib/ui/axis/guides/title.js +6 -2
  110. package/lib/ui/axis/guides/title.js.map +1 -1
  111. package/lib/ui/axis/types.d.ts +6 -0
  112. package/lib/ui/axis/utils/classname.d.ts +46 -0
  113. package/lib/ui/axis/utils/classname.js +58 -0
  114. package/lib/ui/axis/utils/classname.js.map +1 -0
  115. package/lib/ui/axis/utils/index.d.ts +1 -0
  116. package/lib/ui/axis/utils/index.js +1 -0
  117. package/lib/ui/axis/utils/index.js.map +1 -1
  118. package/lib/ui/grid/index.d.ts +1 -1
  119. package/lib/ui/legend/category/item.d.ts +3 -1
  120. package/lib/ui/legend/category/item.js +42 -14
  121. package/lib/ui/legend/category/item.js.map +1 -1
  122. package/lib/ui/legend/category/items.d.ts +2 -0
  123. package/lib/ui/legend/category/items.js +11 -8
  124. package/lib/ui/legend/category/items.js.map +1 -1
  125. package/lib/ui/legend/category.js +11 -3
  126. package/lib/ui/legend/category.js.map +1 -1
  127. package/lib/ui/legend/classname-map.d.ts +37 -0
  128. package/lib/ui/legend/classname-map.js +41 -0
  129. package/lib/ui/legend/classname-map.js.map +1 -0
  130. package/lib/ui/legend/constant.d.ts +1 -0
  131. package/lib/ui/legend/constant.js +3 -1
  132. package/lib/ui/legend/constant.js.map +1 -1
  133. package/lib/ui/legend/continuous/handle.d.ts +1 -0
  134. package/lib/ui/legend/continuous/handle.js +23 -3
  135. package/lib/ui/legend/continuous/handle.js.map +1 -1
  136. package/lib/ui/legend/continuous/ribbon.d.ts +1 -0
  137. package/lib/ui/legend/continuous/ribbon.js +11 -1
  138. package/lib/ui/legend/continuous/ribbon.js.map +1 -1
  139. package/lib/ui/legend/continuous.d.ts +6 -0
  140. package/lib/ui/legend/continuous.js +76 -9
  141. package/lib/ui/legend/continuous.js.map +1 -1
  142. package/lib/ui/legend/title/index.js +5 -1
  143. package/lib/ui/legend/title/index.js.map +1 -1
  144. package/lib/ui/legend/title/types.d.ts +1 -0
  145. package/lib/ui/legend/types.d.ts +1 -0
  146. package/lib/ui/legend/utils/classname.d.ts +31 -0
  147. package/lib/ui/legend/utils/classname.js +39 -0
  148. package/lib/ui/legend/utils/classname.js.map +1 -0
  149. package/lib/ui/legend/utils/index.d.ts +1 -0
  150. package/lib/ui/legend/utils/index.js +5 -0
  151. package/lib/ui/legend/utils/index.js.map +1 -0
  152. package/lib/ui/navigator/index.js +19 -4
  153. package/lib/ui/navigator/index.js.map +1 -1
  154. package/lib/ui/navigator/types.d.ts +1 -0
  155. package/lib/ui/slider/handle.d.ts +2 -0
  156. package/lib/ui/slider/handle.js +21 -6
  157. package/lib/ui/slider/handle.js.map +1 -1
  158. package/lib/ui/slider/index.js +3 -7
  159. package/lib/ui/slider/index.js.map +1 -1
  160. package/lib/util/extend-display-object.d.ts +2 -0
  161. package/lib/util/extend-display-object.js +7 -0
  162. package/lib/util/extend-display-object.js.map +1 -1
  163. package/lib/util/index.d.ts +1 -0
  164. package/lib/util/index.js +1 -0
  165. package/lib/util/index.js.map +1 -1
  166. package/lib/util/keyframe-interpolate.d.ts +1 -1
  167. package/lib/util/parse-height-from-html.d.ts +1 -0
  168. package/lib/util/parse-height-from-html.js +99 -0
  169. package/lib/util/parse-height-from-html.js.map +1 -0
  170. package/package.json +2 -3
  171. package/src/ui/axis/axis.ts +19 -2
  172. package/src/ui/axis/classname-map.ts +22 -0
  173. package/src/ui/axis/constant.ts +17 -15
  174. package/src/ui/axis/guides/grid.ts +8 -1
  175. package/src/ui/axis/guides/labels.ts +35 -9
  176. package/src/ui/axis/guides/line.ts +50 -12
  177. package/src/ui/axis/guides/ticks.ts +15 -5
  178. package/src/ui/axis/guides/title.ts +10 -4
  179. package/src/ui/axis/types.ts +6 -0
  180. package/src/ui/axis/utils/classname.ts +62 -0
  181. package/src/ui/axis/utils/index.ts +1 -0
  182. package/src/ui/legend/category/item.ts +59 -12
  183. package/src/ui/legend/category/items.ts +17 -7
  184. package/src/ui/legend/category.ts +12 -3
  185. package/src/ui/legend/classname-map.ts +45 -0
  186. package/src/ui/legend/constant.ts +2 -0
  187. package/src/ui/legend/continuous/handle.ts +41 -4
  188. package/src/ui/legend/continuous/ribbon.ts +17 -1
  189. package/src/ui/legend/continuous.ts +96 -10
  190. package/src/ui/legend/title/index.ts +5 -1
  191. package/src/ui/legend/title/types.ts +1 -0
  192. package/src/ui/legend/types.ts +1 -0
  193. package/src/ui/legend/utils/classname.ts +39 -0
  194. package/src/ui/legend/utils/index.ts +1 -0
  195. package/src/ui/navigator/index.ts +32 -2
  196. package/src/ui/navigator/types.ts +1 -0
  197. package/src/ui/slider/handle.ts +44 -6
  198. package/src/ui/slider/index.ts +3 -4
  199. package/src/util/extend-display-object.ts +7 -1
  200. package/src/util/index.ts +1 -0
  201. package/src/util/parse-height-from-html.ts +94 -0
@@ -3,6 +3,8 @@ import { Path } from '../../shapes';
3
3
  import { classNames } from '../../util';
4
4
  import type { AxisBaseStyleProps } from './types';
5
5
 
6
+ import { CLASSNAME_SUFFIX_MAP } from './classname-map';
7
+
6
8
  export const AXIS_BASE_DEFAULT_ATTR: Partial<AxisBaseStyleProps> = {
7
9
  data: [],
8
10
  animate: {
@@ -76,21 +78,21 @@ export const HELIX_DEFAULT_OPTIONS = deepMix({}, AXIS_BASE_DEFAULT_ATTR, {
76
78
 
77
79
  export const CLASS_NAMES = classNames(
78
80
  {
79
- mainGroup: 'main-group',
80
- gridGroup: 'grid-group',
81
- grid: 'grid',
82
- lineGroup: 'line-group',
83
- line: 'line',
84
- tickGroup: 'tick-group',
85
- tick: 'tick',
86
- tickItem: 'tick-item',
87
- labelGroup: 'label-group',
88
- label: 'label',
89
- labelItem: 'label-item',
90
- titleGroup: 'title-group',
91
- title: 'title',
92
- lineFirst: 'line-first',
93
- lineSecond: 'line-second',
81
+ mainGroup: CLASSNAME_SUFFIX_MAP.mainGroup,
82
+ gridGroup: CLASSNAME_SUFFIX_MAP.gridGroup,
83
+ grid: CLASSNAME_SUFFIX_MAP.grid,
84
+ lineGroup: CLASSNAME_SUFFIX_MAP.lineGroup,
85
+ line: CLASSNAME_SUFFIX_MAP.line,
86
+ tickGroup: CLASSNAME_SUFFIX_MAP.tickGroup,
87
+ tick: CLASSNAME_SUFFIX_MAP.tick,
88
+ tickItem: CLASSNAME_SUFFIX_MAP.tickItem,
89
+ labelGroup: CLASSNAME_SUFFIX_MAP.labelGroup,
90
+ label: CLASSNAME_SUFFIX_MAP.label,
91
+ labelItem: CLASSNAME_SUFFIX_MAP.labelItem,
92
+ titleGroup: CLASSNAME_SUFFIX_MAP.titleGroup,
93
+ title: CLASSNAME_SUFFIX_MAP.title,
94
+ lineFirst: CLASSNAME_SUFFIX_MAP.lineFirst,
95
+ lineSecond: CLASSNAME_SUFFIX_MAP.lineSecond,
94
96
  },
95
97
  'axis'
96
98
  );
@@ -7,6 +7,8 @@ import { CLASS_NAMES } from '../constant';
7
7
  import type { AxisDatum, AxisGridStyleProps, AxisStyleProps } from '../types';
8
8
  import { getValuePos } from './line';
9
9
  import { filterExec, getDirectionVector } from './utils';
10
+ import { applyClassName } from '../utils/classname';
11
+ import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
10
12
 
11
13
  function getGridVector(value: number, attr: Required<AxisStyleProps>) {
12
14
  return getDirectionVector(value, attr.gridDirection, attr);
@@ -63,6 +65,7 @@ export function renderGrid(
63
65
  attr: Required<AxisStyleProps>,
64
66
  animate: StandardAnimationOption
65
67
  ) {
68
+ const { classNamePrefix } = attr;
66
69
  const gridAttr = subStyleProps<Required<AxisGridStyleProps>>(attr, 'grid');
67
70
  const { type, areaFill } = gridAttr;
68
71
  const center = getGridCenter(attr);
@@ -83,7 +86,11 @@ export function renderGrid(
83
86
  .selectAll(CLASS_NAMES.grid.class)
84
87
  .data([1])
85
88
  .join(
86
- (enter) => enter.append(() => new Grid({ style })).attr('className', CLASS_NAMES.grid.name),
89
+ (enter) => {
90
+ const grid = enter.append(() => new Grid({ style })).attr('className', CLASS_NAMES.grid.name);
91
+ applyClassName(grid, CLASS_NAMES.grid, CLASSNAME_SUFFIX_MAP.grid, classNamePrefix);
92
+ return grid;
93
+ },
87
94
  (update) =>
88
95
  update.transition(function () {
89
96
  return this.update(style);
@@ -1,5 +1,4 @@
1
- import type { IAnimation } from '@antv/g';
2
- import { flatten, get, isFunction } from '@antv/util';
1
+ import { get, isFunction } from '@antv/util';
3
2
  import type { StandardAnimationOption } from '../../../animation';
4
3
  import { fadeOut, onAnimateFinished, onAnimatesFinished, transition, transitionShape } from '../../../animation';
5
4
  import type { DisplayObject, TextStyleProps } from '../../../shapes';
@@ -22,6 +21,8 @@ import {
22
21
  splitStyle,
23
22
  subStyleProps,
24
23
  wrapIt,
24
+ renderHtmlExtDo,
25
+ parseHeightFromHTML,
25
26
  } from '../../../util';
26
27
  import { CLASS_NAMES } from '../constant';
27
28
  import { processOverlap } from '../overlap';
@@ -29,6 +30,8 @@ import type { AxisDatum, AxisLabelStyleProps, AxisStyleProps } from '../types';
29
30
  import { getFactor } from '../utils';
30
31
  import { getValuePos } from './line';
31
32
  import { filterExec, getCallbackStyle, getLabelVector, getLineTangentVector } from './utils';
33
+ import { applyClassName } from '../utils/classname';
34
+ import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
32
35
 
33
36
  function angleNormalizer(angle: number) {
34
37
  let normalizedAngle = angle;
@@ -166,8 +169,22 @@ function formatter(datum: AxisDatum, index: number, data: AxisDatum[], attr: Req
166
169
  return element;
167
170
  }
168
171
 
172
+ function renderHTMLLabel(datum: AxisDatum, index: number, data: AxisDatum[], attr: Required<AxisStyleProps>) {
173
+ const { labelRender } = attr;
174
+ const elementWidth = (get(attr, 'endPos.0', 400) - get(attr, 'startPos.0', 0)) / data.length;
175
+ const elStr = isFunction(labelRender)
176
+ ? getCallbackValue(labelRender, [datum, index, data, getLabelVector(datum.value, attr)])
177
+ : datum.label || '';
178
+ const elementHeight = parseHeightFromHTML(elStr) || 30;
179
+ return () =>
180
+ renderHtmlExtDo(elStr, {
181
+ width: elementWidth,
182
+ height: elementHeight,
183
+ });
184
+ }
185
+
169
186
  function applyTextStyle(node: DisplayObject, style: Partial<TextStyleProps>) {
170
- if (node.nodeName === 'text') node.attr(style);
187
+ if (['text', 'html'].includes(node.nodeName)) node.attr(style);
171
188
  }
172
189
 
173
190
  function overlapHandler(attr: Required<AxisStyleProps>, main: DisplayObject) {
@@ -183,7 +200,9 @@ function overlapHandler(attr: Required<AxisStyleProps>, main: DisplayObject) {
183
200
  wrap: (label, width, lines) => {
184
201
  label && wrapIt(label, width, lines);
185
202
  },
186
- getTextShape: (label) => label.querySelector<DisplayObject>('text') as Text,
203
+ getTextShape: (label) => {
204
+ return label.querySelector<DisplayObject>(CLASS_NAMES.labelItem.class) as Text;
205
+ },
187
206
  });
188
207
  }
189
208
 
@@ -195,10 +214,13 @@ function renderLabel(
195
214
  attr: Required<AxisStyleProps>
196
215
  ): DisplayObject {
197
216
  const index = data.indexOf(datum);
217
+ const { labelRender, classNamePrefix } = attr;
218
+
198
219
  const label = select(container)
199
- .append(formatter(datum, index, data, attr))
220
+ .append(labelRender ? renderHTMLLabel(datum, index, data, attr) : formatter(datum, index, data, attr))
200
221
  .attr('className', CLASS_NAMES.labelItem.name)
201
222
  .node();
223
+ applyClassName(select(label), CLASS_NAMES.labelItem, CLASSNAME_SUFFIX_MAP.labelItem, classNamePrefix);
202
224
  const [labelStyle, { transform, ...groupStyle }] = splitStyle(getCallbackStyle(style, [datum, index, data]));
203
225
 
204
226
  percentTransform(label, transform);
@@ -222,24 +244,28 @@ export function renderLabels(
222
244
  animate: StandardAnimationOption,
223
245
  main: DisplayObject
224
246
  ) {
247
+ const { classNamePrefix } = attr;
225
248
  const finalData = filterExec(data, attr.labelFilter);
226
249
  const style = subStyleProps<AxisLabelStyleProps>(attr, 'label');
250
+
227
251
  let _exit!: Selection<AxisDatum>;
228
252
  const transitions = container
229
253
  .selectAll(CLASS_NAMES.label.class)
230
254
  .data(finalData, (d, i) => i)
231
255
  .join(
232
- (enter) =>
233
- enter
256
+ (enter) => {
257
+ const labels = enter
234
258
  .append('g')
235
259
  .attr('className', CLASS_NAMES.label.name)
236
260
  .transition(function (datum) {
237
261
  renderLabel(this, datum, data, style, attr);
238
262
  const { x, y } = getLabelPos(datum, data, attr);
239
- // .axis-label
240
263
  this.style.transform = `translate(${x}, ${y})`;
241
264
  return null;
242
- }),
265
+ });
266
+ applyClassName(labels, CLASS_NAMES.label, CLASSNAME_SUFFIX_MAP.label, classNamePrefix);
267
+ return labels;
268
+ },
243
269
  (update) =>
244
270
  update.transition(function (datum) {
245
271
  const prevLabel = this.querySelector(CLASS_NAMES.labelItem.class);
@@ -15,6 +15,8 @@ import {
15
15
  import { CLASS_NAMES } from '../constant';
16
16
  import type { RequiredArcAxisStyleProps, RequiredAxisStyleProps, RequiredLinearAxisStyleProps } from '../types';
17
17
  import { getLineAngle, getLineTangentVector } from './utils';
18
+ import { applyClassName, getAxisClassName } from '../utils/classname';
19
+ import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
18
20
 
19
21
  type LineDatum = {
20
22
  line: [Vector2, Vector2];
@@ -97,18 +99,21 @@ function renderArc(
97
99
  style: RequiredArcAxisStyleProps,
98
100
  animate: StandardAnimationOption
99
101
  ) {
100
- const { startAngle, endAngle, center, radius } = attr;
102
+ const { startAngle, endAngle, center, radius, classNamePrefix } = attr;
101
103
 
102
104
  return container
103
105
  .selectAll(CLASS_NAMES.line.class)
104
106
  .data([{ d: getArcPath(startAngle, endAngle, ...center, radius) }], (d, i) => i)
105
107
  .join(
106
- (enter) =>
107
- enter
108
+ (enter) => {
109
+ const line = enter
108
110
  .append('path')
109
111
  .attr('className', CLASS_NAMES.line.name)
110
112
  .styles(attr)
111
- .styles({ d: (d: any) => d.d }),
113
+ .styles({ d: (d: any) => d.d });
114
+ applyClassName(line, CLASS_NAMES.line, CLASSNAME_SUFFIX_MAP.line, classNamePrefix);
115
+ return line;
116
+ },
112
117
  (update) =>
113
118
  update
114
119
  .transition(function () {
@@ -158,7 +163,7 @@ function renderLinear(
158
163
  style: RequiredLinearAxisStyleProps,
159
164
  animate: StandardAnimationOption
160
165
  ) {
161
- const { showTrunc, startPos, endPos, truncRange, lineExtension } = attr;
166
+ const { showTrunc, startPos, endPos, truncRange, lineExtension, classNamePrefix } = attr;
162
167
  const [[x1, y1], [x2, y2]] = [startPos, endPos];
163
168
  const [ox1, oy1, ox2, oy2] = lineExtension ? extendLine(startPos, endPos, lineExtension) : new Array(4).fill(0);
164
169
  const renderLine = (data: LineDatum[]) => {
@@ -166,14 +171,43 @@ function renderLinear(
166
171
  .selectAll(CLASS_NAMES.line.class)
167
172
  .data(data, (d, i) => i)
168
173
  .join(
169
- (enter) =>
170
- enter
174
+ (enter) => {
175
+ const lines = enter
171
176
  .append('line')
172
- .attr('className', (d: LineDatum) => `${CLASS_NAMES.line.name} ${d.className}`)
173
177
  .styles(style)
174
178
  .transition(function (d: LineDatum) {
175
179
  return transition(this, getLinePath(d.line), false);
176
- }),
180
+ });
181
+ // Set className with appropriate logic for line elements
182
+ lines.attr('className', (d: LineDatum) => {
183
+ if (!classNamePrefix) {
184
+ return `${CLASS_NAMES.line.name} ${d.className}`;
185
+ }
186
+ const baseLineClassName = getAxisClassName(
187
+ CLASS_NAMES.line.name,
188
+ CLASSNAME_SUFFIX_MAP.line,
189
+ classNamePrefix
190
+ );
191
+ if (d.className === CLASS_NAMES.lineFirst.name) {
192
+ const specificClassName = getAxisClassName(
193
+ CLASS_NAMES.lineFirst.name,
194
+ CLASSNAME_SUFFIX_MAP.lineFirst,
195
+ classNamePrefix
196
+ );
197
+ return `${baseLineClassName} ${specificClassName}`;
198
+ }
199
+ if (d.className === CLASS_NAMES.lineSecond.name) {
200
+ const specificClassName = getAxisClassName(
201
+ CLASS_NAMES.lineSecond.name,
202
+ CLASSNAME_SUFFIX_MAP.lineSecond,
203
+ classNamePrefix
204
+ );
205
+ return `${baseLineClassName} ${specificClassName}`;
206
+ }
207
+ return baseLineClassName;
208
+ });
209
+ return lines;
210
+ },
177
211
  (update) =>
178
212
  update.styles(style).transition(function ({ line }: LineDatum) {
179
213
  return transition(this, getLinePath(line), animate.update);
@@ -228,9 +262,13 @@ function renderAxisArrow(
228
262
  const { showArrow, showTrunc, lineArrow, lineArrowOffset, lineArrowSize } = attr;
229
263
 
230
264
  let shapeToAddArrow: Selection;
231
- if (type === 'arc') shapeToAddArrow = container.select(CLASS_NAMES.line.class);
232
- else if (showTrunc) shapeToAddArrow = container.select(CLASS_NAMES.lineSecond.class);
233
- else shapeToAddArrow = container.select(CLASS_NAMES.line.class);
265
+ if (type === 'arc') {
266
+ shapeToAddArrow = container.select(CLASS_NAMES.line.class);
267
+ } else if (showTrunc) {
268
+ shapeToAddArrow = container.select(CLASS_NAMES.lineSecond.class);
269
+ } else {
270
+ shapeToAddArrow = container.select(CLASS_NAMES.line.class);
271
+ }
234
272
  if (!showArrow || !lineArrow || (attr.type === 'arc' && isCircle(attr.startAngle, attr.endAngle))) {
235
273
  const node = shapeToAddArrow.node<Line>();
236
274
  if (node) node.style.markerEnd = undefined;
@@ -8,6 +8,8 @@ import { CLASS_NAMES } from '../constant';
8
8
  import type { AxisDatum, AxisTickStyleProps, RequiredAxisStyleProps } from '../types';
9
9
  import { getValuePos } from './line';
10
10
  import { filterExec, getCallbackStyle, getDirectionVector } from './utils';
11
+ import { applyClassName } from '../utils/classname';
12
+ import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
11
13
 
12
14
  type RequiredAxisTickStyleProps = Required<AxisTickStyleProps>;
13
15
 
@@ -42,11 +44,14 @@ function createTickEl(
42
44
  data: AxisDatum[],
43
45
  attr: RequiredAxisStyleProps
44
46
  ) {
45
- const { tickFormatter: formatter } = attr;
47
+ const { tickFormatter: formatter, classNamePrefix } = attr;
46
48
  const tickVector = getTickVector(datum.value, attr);
47
49
  let el: any = 'line';
48
50
  if (isFunction(formatter)) el = () => getCallbackValue(formatter, [datum, index, data, tickVector]);
49
- return container.append(el).attr('className', CLASS_NAMES.tickItem.name);
51
+
52
+ const tick = container.append(el).attr('className', CLASS_NAMES.tickItem.name);
53
+ applyClassName(tick, CLASS_NAMES.tickItem, CLASSNAME_SUFFIX_MAP.tickItem, classNamePrefix);
54
+ return tick;
50
55
  }
51
56
 
52
57
  function applyTickStyle(
@@ -86,19 +91,24 @@ export function renderTicks(
86
91
  attr: RequiredAxisStyleProps,
87
92
  animate: StandardAnimationOption
88
93
  ) {
94
+ const { classNamePrefix } = attr;
89
95
  const finalData = filterExec(axisData, attr.tickFilter);
90
96
  const tickAttr = subStyleProps<RequiredAxisTickStyleProps>(attr, 'tick');
97
+
91
98
  return container
92
99
  .selectAll(CLASS_NAMES.tick.class)
93
100
  .data(finalData, (d) => d.id || d.label)
94
101
  .join(
95
- (enter) =>
96
- enter
102
+ (enter) => {
103
+ const ticks = enter
97
104
  .append('g')
98
105
  .attr('className', CLASS_NAMES.tick.name)
99
106
  .transition(function (datum: AxisDatum, index: number) {
100
107
  return createTick.call(this, datum, index, finalData, attr, tickAttr, false);
101
- }),
108
+ });
109
+ applyClassName(ticks, CLASS_NAMES.tick, CLASSNAME_SUFFIX_MAP.tick, classNamePrefix);
110
+ return ticks;
111
+ },
102
112
  (update) =>
103
113
  update.transition(function (datum: AxisDatum, index: number) {
104
114
  this.removeChildren();
@@ -15,6 +15,8 @@ import {
15
15
  } from '../../../util';
16
16
  import { CLASS_NAMES } from '../constant';
17
17
  import type { RequiredAxisStyleProps } from '../types';
18
+ import { applyClassName } from '../utils/classname';
19
+ import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
18
20
 
19
21
  function getTitlePosition(
20
22
  mainGroup: Selection,
@@ -101,7 +103,8 @@ export function renderTitle(
101
103
  attr: RequiredAxisStyleProps,
102
104
  animate: StandardAnimationOption
103
105
  ) {
104
- const { titleText } = attr;
106
+ const { titleText, classNamePrefix } = attr;
107
+
105
108
  return container
106
109
  .selectAll(CLASS_NAMES.title.class)
107
110
  .data(
@@ -109,13 +112,16 @@ export function renderTitle(
109
112
  (d, i) => d.title
110
113
  )
111
114
  .join(
112
- (enter) =>
113
- enter
115
+ (enter) => {
116
+ const titles = enter
114
117
  .append(() => renderExtDo(titleText))
115
118
  .attr('className', CLASS_NAMES.title.name)
116
119
  .transition(function () {
117
120
  return applyTitleStyle(select(this), container, axis, attr, animate.enter);
118
- }),
121
+ });
122
+ applyClassName(titles, CLASS_NAMES.title, CLASSNAME_SUFFIX_MAP.title, classNamePrefix);
123
+ return titles;
124
+ },
119
125
  (update) =>
120
126
  update.transition(function () {
121
127
  return applyTitleStyle(select(this), container, axis, attr, animate.update);
@@ -133,6 +133,11 @@ export type AxisLabelStyleProps = {
133
133
  * transform label by using ellipsis, hide and rotate to avoid overlap
134
134
  */
135
135
  overlap: LabelOverlapCfg[];
136
+ /**
137
+ * render label by HTML or g shape
138
+ * when using a callback form, the argument will additional returns the label vector
139
+ */
140
+ render?: Callable<ExtendDisplayObject, CallbackParameter<AxisDatum, [Vector2]>>;
136
141
  } & {
137
142
  [key in keyof TextStyleProps]?: Callable<TextStyleProps[key], AxisDatumCP>;
138
143
  };
@@ -178,6 +183,7 @@ export type AxisBaseStyleProps = PrefixStyleProps<Partial<AxisTitleStyleProps>,
178
183
  showTick?: boolean;
179
184
  showTitle?: boolean;
180
185
  showTrunc?: boolean;
186
+ classNamePrefix?: string;
181
187
  };
182
188
 
183
189
  export type LinearAxisStyleProps = AxisBaseStyleProps & { type: 'linear'; startPos: Vector2; endPos: Vector2 };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Generate axis className with optional prefix
3
+ * @param baseClassName Base className (e.g., 'axis-line')
4
+ * @param suffix Suffix (e.g., 'line')
5
+ * @param classNamePrefix User-defined prefix (e.g., 'g2-')
6
+ * @returns Concatenated className
7
+ *
8
+ * @example
9
+ * getAxisClassName('axis-line', 'line', 'g2-')
10
+ * // => 'axis-line g2-axis-line'
11
+ *
12
+ * getAxisClassName('axis-line', 'line', undefined)
13
+ * // => 'axis-line'
14
+ */
15
+ export function getAxisClassName(baseClassName: string, suffix: string, classNamePrefix?: string): string {
16
+ if (!classNamePrefix) return baseClassName;
17
+ return `${baseClassName} ${classNamePrefix}axis-${suffix}`;
18
+ }
19
+
20
+ /**
21
+ * Extract className from component attributes
22
+ * @param attributes Component attributes
23
+ * @param baseClassName Base className object
24
+ * @param suffix Suffix string
25
+ * @returns Concatenated className
26
+ */
27
+ export function getClassNameFromAttrs(
28
+ attributes: { classNamePrefix?: string },
29
+ baseClassName: { name: string },
30
+ suffix: string
31
+ ): string {
32
+ const { classNamePrefix = '' } = attributes;
33
+ return getAxisClassName(baseClassName.name, suffix, classNamePrefix);
34
+ }
35
+
36
+ /**
37
+ * Apply full className (with prefix) to a selection element
38
+ * This is a helper to implement the two-step pattern:
39
+ * 1. Create element with base className
40
+ * 2. Apply full className with prefix
41
+ *
42
+ * @param selection The selection to apply className to
43
+ * @param baseClassName Base className object from CLASS_NAMES
44
+ * @param suffix Suffix from CLASSNAME_SUFFIX_MAP
45
+ * @param classNamePrefix Optional user-defined prefix
46
+ * @returns The selection for chaining
47
+ *
48
+ * @example
49
+ * const element = container.maybeAppendByClassName(CLASS_NAMES.grid, 'g');
50
+ * applyClassName(element, CLASS_NAMES.grid, CLASSNAME_SUFFIX_MAP.grid, classNamePrefix);
51
+ */
52
+ export function applyClassName(
53
+ selection: any,
54
+ baseClassName: { name: string },
55
+ suffix: string,
56
+ classNamePrefix?: string
57
+ ): any {
58
+ if (classNamePrefix) {
59
+ selection.attr('className', getAxisClassName(baseClassName.name, suffix, classNamePrefix));
60
+ }
61
+ return selection;
62
+ }
@@ -1,6 +1,7 @@
1
1
  import type { VerticalFactor, Direction } from '../types';
2
2
 
3
3
  export * from './test';
4
+ export * from './classname';
4
5
 
5
6
  export function getFactor(...args: Direction[]): VerticalFactor {
6
7
  const fn = (str: (typeof args)[number]): VerticalFactor => (str === 'positive' ? -1 : 1);
@@ -30,6 +30,8 @@ import {
30
30
  import { Poptip } from '../../poptip';
31
31
  import type { PoptipStyleProps } from '../../poptip/types';
32
32
  import type { PoptipRender } from './items';
33
+ import { getLegendClassName } from '../utils/classname';
34
+ import { CLASSNAME_SUFFIX_MAP } from '../constant';
33
35
 
34
36
  type ItemMarkerStyle = { size?: number } & PathStyleProps;
35
37
  type ItemTextStyle = Omit<TextStyleProps, 'text'>;
@@ -53,6 +55,7 @@ export type CategoryItemStyleProps = GroupStyleProps &
53
55
  poptip?: PoptipStyleProps & PoptipRender;
54
56
  focus?: boolean;
55
57
  focusMarkerSize?: number;
58
+ classNamePrefix?: string;
56
59
  };
57
60
 
58
61
  export type CategoryItemOptions = ComponentOptions<CategoryItemStyleProps>;
@@ -100,7 +103,10 @@ function styleOfMarker(group: Group): BaseStyleProps {
100
103
  }
101
104
 
102
105
  export class CategoryItem extends Component<CategoryItemStyleProps> {
103
- constructor(options: CategoryItemOptions) {
106
+ // Key fields, used to pass extra info like id, index for poptip rendering
107
+ public keyFields: object = {};
108
+
109
+ constructor(options: CategoryItemOptions, keyFields?: Omit<CategoryItemOptions, 'style'>) {
104
110
  super(options, {
105
111
  span: [1, 1],
106
112
  marker: () => new Circle({ style: { r: 6 } }),
@@ -112,6 +118,7 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
112
118
  labelTextBaseline: 'middle',
113
119
  valueTextBaseline: 'middle',
114
120
  });
121
+ this.keyFields = keyFields || {};
115
122
  }
116
123
 
117
124
  private poptipGroup!: Poptip;
@@ -223,19 +230,26 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
223
230
  }
224
231
 
225
232
  private renderMarker(container: Selection) {
226
- const { marker } = this.attributes;
233
+ const { marker, classNamePrefix } = this.attributes;
227
234
  const style = subStyleProps(this.attributes, 'marker');
228
235
  this.markerGroup = container.maybeAppendByClassName(CLASS_NAMES.markerGroup, 'g').style('zIndex', 0);
229
236
  ifShow(!!marker, this.markerGroup, () => {
230
237
  const parent = this.markerGroup.node();
231
238
  const oldMarker = parent.childNodes?.[0] as DisplayObject | undefined;
239
+ const markerClassName = getLegendClassName(CLASS_NAMES.marker.name, CLASSNAME_SUFFIX_MAP.marker, classNamePrefix);
232
240
  const newMarker =
233
- typeof marker === 'string'
234
- ? new Marker({ style: { symbol: marker }, className: CLASS_NAMES.marker.name })
235
- : marker();
241
+ typeof marker === 'string' ? new Marker({ style: { symbol: marker }, className: markerClassName }) : marker();
236
242
 
237
243
  if (!oldMarker) {
238
- if (!(newMarker instanceof Marker)) select(newMarker).attr('className', CLASS_NAMES.marker.name).styles(style);
244
+ if (!(newMarker instanceof Marker)) {
245
+ const markerClassName = getLegendClassName(
246
+ CLASS_NAMES.marker.name,
247
+ CLASSNAME_SUFFIX_MAP.marker,
248
+ classNamePrefix
249
+ );
250
+ (newMarker as any).className = markerClassName;
251
+ select(newMarker).styles(style);
252
+ }
239
253
  parent.appendChild(newMarker);
240
254
  } else if (newMarker.nodeName === oldMarker.nodeName) {
241
255
  if (oldMarker instanceof Marker) oldMarker.update({ ...style, symbol: marker });
@@ -245,7 +259,15 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
245
259
  }
246
260
  } else {
247
261
  oldMarker.remove();
248
- select(newMarker).attr('className', CLASS_NAMES.marker.name).styles(style);
262
+ if (!(newMarker instanceof Marker)) {
263
+ const markerClassName = getLegendClassName(
264
+ CLASS_NAMES.marker.name,
265
+ CLASSNAME_SUFFIX_MAP.marker,
266
+ classNamePrefix
267
+ );
268
+ (newMarker as any).className = markerClassName;
269
+ }
270
+ select(newMarker).styles(style);
249
271
  parent.appendChild(newMarker);
250
272
  }
251
273
 
@@ -258,15 +280,23 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
258
280
 
259
281
  private renderLabel(container: Selection) {
260
282
  const { text: label, ...style } = subStyleProps(this.attributes, 'label');
283
+ const { classNamePrefix } = this.attributes;
261
284
  this.labelGroup = container.maybeAppendByClassName<Group>(CLASS_NAMES.labelGroup, 'g').style('zIndex', 0);
262
- this.labelGroup.maybeAppendByClassName(CLASS_NAMES.label, () => renderExtDo(label)).styles(style);
285
+ const labelClassName = getLegendClassName(CLASS_NAMES.label.name, CLASSNAME_SUFFIX_MAP.label, classNamePrefix);
286
+ const labelElement = this.labelGroup.maybeAppendByClassName(CLASS_NAMES.label, () => renderExtDo(label));
287
+ labelElement.node().setAttribute('class', labelClassName);
288
+ labelElement.styles(style);
263
289
  }
264
290
 
265
291
  private renderValue(container: Selection) {
266
292
  const { text: value, ...style } = subStyleProps(this.attributes, 'value');
293
+ const { classNamePrefix } = this.attributes;
267
294
  this.valueGroup = container.maybeAppendByClassName(CLASS_NAMES.valueGroup, 'g').style('zIndex', 0);
268
295
  ifShow(this.showValue, this.valueGroup, () => {
269
- this.valueGroup.maybeAppendByClassName(CLASS_NAMES.value, () => renderExtDo(value)).styles(style);
296
+ const valueClassName = getLegendClassName(CLASS_NAMES.value.name, CLASSNAME_SUFFIX_MAP.value, classNamePrefix);
297
+ const valueElement = this.valueGroup.maybeAppendByClassName(CLASS_NAMES.value, () => renderExtDo(value));
298
+ valueElement.node().setAttribute('class', valueClassName);
299
+ valueElement.styles(style);
270
300
  });
271
301
  }
272
302
 
@@ -287,7 +317,7 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
287
317
  const label = typeof labelText === 'string' ? labelText : (labelText as DisplayObject)?.attr('text');
288
318
  const value = typeof valueText === 'string' ? valueText : (valueText as DisplayObject)?.attr('text');
289
319
  if (typeof poptip.render === 'function') {
290
- return { html: poptip.render({ label, value, color: markerFill as string }) };
320
+ return { html: poptip.render({ ...this.keyFields, label, value, color: markerFill as string }) };
291
321
  }
292
322
  let html = '';
293
323
  if (typeof label === 'string' || typeof label === 'number') {
@@ -301,7 +331,7 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
301
331
  }
302
332
 
303
333
  private renderFocus(ctn: Selection) {
304
- const { focus, focusMarkerSize } = this.attributes;
334
+ const { focus, focusMarkerSize, classNamePrefix } = this.attributes;
305
335
  const defaultOptions = {
306
336
  x: 0,
307
337
  y: 0,
@@ -316,11 +346,17 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
316
346
 
317
347
  this.focusGroup = ctn.maybeAppendByClassName<Group>(CLASS_NAMES.focusGroup, 'g').style('zIndex', 0);
318
348
  ifShow(focus, this.focusGroup, () => {
349
+ const focusClassName = getLegendClassName(
350
+ CLASS_NAMES.focus.name,
351
+ CLASSNAME_SUFFIX_MAP.focusIcon,
352
+ classNamePrefix
353
+ );
319
354
  const marker = new Marker({
320
355
  style: {
321
356
  ...defaultOptions,
322
357
  symbol: 'focus',
323
358
  },
359
+ className: focusClassName,
324
360
  });
325
361
  const interactiveCircle = new Circle({
326
362
  style: {
@@ -359,7 +395,18 @@ export class CategoryItem extends Component<CategoryItemStyleProps> {
359
395
  const { width, height } = this.shape;
360
396
  const style = subStyleProps(this.attributes, 'background');
361
397
  this.background = container.maybeAppendByClassName(CLASS_NAMES.backgroundGroup, 'g').style('zIndex', -1);
362
- this.background.maybeAppendByClassName(CLASS_NAMES.background, 'rect').styles({ width, height, ...style });
398
+ const backgroundElement = this.background.maybeAppendByClassName(CLASS_NAMES.background, 'rect');
399
+ backgroundElement.styles({ width, height, ...style });
400
+
401
+ const { classNamePrefix = '' } = this.attributes;
402
+ if (classNamePrefix) {
403
+ const backgroundClassName = getLegendClassName(
404
+ CLASS_NAMES.background.name,
405
+ CLASSNAME_SUFFIX_MAP.background,
406
+ classNamePrefix
407
+ );
408
+ backgroundElement.node().setAttribute('class', backgroundClassName);
409
+ }
363
410
  }
364
411
 
365
412
  private adjustLayout() {