@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
@@ -21,6 +21,8 @@ import { ifHorizontal } from '../utils';
21
21
  import type { CategoryItemStyleProps } from './item';
22
22
  import { CategoryItem } from './item';
23
23
  import type { PoptipStyleProps } from '../../poptip/types';
24
+ import { getLegendClassName } from '../utils/classname';
25
+ import { CLASSNAME_SUFFIX_MAP } from '../constant';
24
26
 
25
27
  interface CategoryItemsDatum {
26
28
  [keys: string]: any;
@@ -32,7 +34,12 @@ type CallableItemStyle = CallableStyleProps<
32
34
  >;
33
35
 
34
36
  export type PoptipRender = {
35
- render?: (params: { label: string | number; value: string | number; color?: string }) => string;
37
+ render?: (params: {
38
+ label: string | number;
39
+ value: string | number;
40
+ color?: string;
41
+ [key: string]: unknown;
42
+ }) => string;
36
43
  };
37
44
 
38
45
  export type CategoryItemsStyleProps = GroupStyleProps &
@@ -57,6 +64,7 @@ export type CategoryItemsStyleProps = GroupStyleProps &
57
64
  poptip?: PoptipStyleProps & PoptipRender;
58
65
  focus?: boolean;
59
66
  focusMarkerSize?: number;
67
+ classNamePrefix?: string;
60
68
  };
61
69
 
62
70
  export type CategoryItemsOptions = ComponentOptions<CategoryItemsStyleProps>;
@@ -131,7 +139,7 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
131
139
  }
132
140
 
133
141
  private get renderData() {
134
- const { data, layout, poptip, focus, focusMarkerSize } = this.attributes;
142
+ const { data, layout, poptip, focus, focusMarkerSize, classNamePrefix } = this.attributes;
135
143
  const style = subStyleProps<CategoryItemStyleProps>(this.attributes, 'item');
136
144
 
137
145
  const d = data.map((datum, index) => {
@@ -146,6 +154,7 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
146
154
  poptip,
147
155
  focus,
148
156
  focusMarkerSize,
157
+ classNamePrefix,
149
158
  ...Object.fromEntries(
150
159
  Object.entries(style).map(([key, val]) => [key, getCallbackValue(val, [datum, index, data])])
151
160
  ),
@@ -250,17 +259,18 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
250
259
  }
251
260
 
252
261
  private renderItems(container: Group) {
253
- const { click, mouseenter, mouseleave } = this.attributes;
262
+ const { click, mouseenter, mouseleave, classNamePrefix } = this.attributes;
254
263
  this.flattenPage(container);
255
264
  const dispatchCustomEvent = this.dispatchCustomEvent.bind(this);
265
+ const itemClassName = getLegendClassName(CLASS_NAMES.item.name, CLASSNAME_SUFFIX_MAP.item, classNamePrefix);
256
266
  select(container)
257
267
  .selectAll(CLASS_NAMES.item.class)
258
268
  .data(this.renderData, (d) => d.id)
259
269
  .join(
260
270
  (enter) =>
261
271
  enter
262
- .append(({ style }) => new CategoryItem({ style }))
263
- .attr('className', CLASS_NAMES.item.name)
272
+ .append(({ style, ...rest }) => new CategoryItem({ style }, rest))
273
+ .attr('className', itemClassName)
264
274
  .on('click', function () {
265
275
  click?.(this);
266
276
  dispatchCustomEvent('itemClick', { item: this });
@@ -311,9 +321,9 @@ export class CategoryItems extends Component<CategoryItemsStyleProps> {
311
321
  }
312
322
 
313
323
  private renderNavigator(container: Selection) {
314
- const { orientation } = this.attributes;
324
+ const { orientation, classNamePrefix } = this.attributes;
315
325
  const navStyle = subStyleProps(this.attributes, 'nav');
316
- const style = deepAssign({ orientation }, navStyle);
326
+ const style = deepAssign({ orientation, classNamePrefix }, navStyle);
317
327
  const that = this;
318
328
  container
319
329
  .selectAll(CLASS_NAMES.navigator.class)
@@ -23,13 +23,13 @@ export class Category extends Component<CategoryStyleProps> {
23
23
  private items!: Selection<CategoryItems>;
24
24
 
25
25
  private renderTitle(container: Selection, width: number, height: number) {
26
- const { showTitle, titleText } = this.attributes;
26
+ const { showTitle, titleText, classNamePrefix } = this.attributes;
27
27
  const style = subStyleProps<TitleStyleProps>(this.attributes, 'title');
28
28
  const [titleStyle, groupStyle] = splitStyle(style);
29
29
 
30
30
  this.titleGroup = container.maybeAppendByClassName<Group>(CLASS_NAMES.titleGroup, 'g').styles(groupStyle);
31
31
 
32
- const finalTitleStyle = { width, height, ...titleStyle, text: showTitle ? titleText : '' };
32
+ const finalTitleStyle = { width, height, ...titleStyle, text: showTitle ? titleText : '', classNamePrefix };
33
33
  this.title = this.titleGroup
34
34
  .maybeAppendByClassName(CLASS_NAMES.title, () => new Title({ style: finalTitleStyle as TitleStyleProps }))
35
35
  .update(finalTitleStyle) as Selection<Title>;
@@ -84,8 +84,17 @@ export class Category extends Component<CategoryStyleProps> {
84
84
  }
85
85
 
86
86
  render(attributes: Required<CategoryStyleProps>, container: Group) {
87
- const { width, height, x = 0, y = 0 } = this.attributes;
87
+ const { width, height, x = 0, y = 0, classNamePrefix } = this.attributes;
88
88
  const ctn = select(container);
89
+
90
+ // Set root container className
91
+ const baseClassName = container.className || 'legend-category';
92
+ if (classNamePrefix) {
93
+ container.attr('className', `${baseClassName} ${classNamePrefix}legend`);
94
+ } else if (!container.className) {
95
+ container.attr('className', 'legend-category');
96
+ }
97
+
89
98
  container.style.transform = `translate(${x}, ${y})`;
90
99
 
91
100
  this.renderTitle(ctn, width!, height!);
@@ -0,0 +1,45 @@
1
+ /**
2
+ * className suffix mapping for legend elements
3
+ * Used to generate prefixed classNames, e.g., classNamePrefix='g2-' generates 'g2-legend-{suffix}'
4
+ *
5
+ * @example
6
+ * import { CLASSNAME_SUFFIX_MAP, getLegendClassName } from './utils';
7
+ *
8
+ * const titleClassName = getLegendClassName(
9
+ * CLASS_NAMES.text.name,
10
+ * CLASSNAME_SUFFIX_MAP.title,
11
+ * 'g2-'
12
+ * );
13
+ * // Returns: 'title-text g2-legend-title'
14
+ */
15
+ export const CLASSNAME_SUFFIX_MAP = {
16
+ // Common elements
17
+ title: 'title',
18
+
19
+ // Category legend elements
20
+ item: 'item',
21
+ marker: 'marker',
22
+ label: 'label',
23
+ value: 'value',
24
+ focusIcon: 'focus-icon',
25
+ background: 'background',
26
+
27
+ // Continuous legend elements
28
+ ribbon: 'ribbon',
29
+ track: 'track',
30
+ selection: 'selection',
31
+ handle: 'handle',
32
+ handleMarker: 'handle-marker',
33
+ handleLabel: 'handle-label',
34
+ indicator: 'indicator',
35
+
36
+ // Navigator elements (reserved)
37
+ prevBtn: 'prev-btn',
38
+ nextBtn: 'next-btn',
39
+ pageInfo: 'page-info',
40
+ } as const;
41
+
42
+ /**
43
+ * className suffix type
44
+ */
45
+ export type ClassNameSuffix = keyof typeof CLASSNAME_SUFFIX_MAP;
@@ -2,6 +2,8 @@ import { classNames, deepAssign, superStyleProps } from '../../util';
2
2
  import { DEFAULT_HANDLE_CFG } from './continuous/handle';
3
3
  import type { LegendBaseStyleProps } from './types';
4
4
 
5
+ export { CLASSNAME_SUFFIX_MAP, type ClassNameSuffix } from './classname-map';
6
+
5
7
  export const LEGEND_BASE_DEFAULT_OPTIONS: Partial<LegendBaseStyleProps> = {
6
8
  showTitle: true,
7
9
  padding: 0,
@@ -7,6 +7,8 @@ import type { Selection } from '../../../util';
7
7
  import { classNames, ifShow, select, subStyleProps } from '../../../util';
8
8
  import { Marker, MarkerStyleProps } from '../../marker';
9
9
  import { ifHorizontal } from '../utils';
10
+ import { getLegendClassName } from '../utils/classname';
11
+ import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
10
12
 
11
13
  export type HandleStyleProps<T = any> = GroupStyleProps &
12
14
  PrefixObject<TextStyleProps, 'label'> &
@@ -17,6 +19,7 @@ export type HandleStyleProps<T = any> = GroupStyleProps &
17
19
  /** spacing between marker and label */
18
20
  spacing?: number;
19
21
  shape?: 'basic' | 'slider';
22
+ classNamePrefix?: string;
20
23
  };
21
24
 
22
25
  export type HandleOptions = ComponentOptions<HandleStyleProps>;
@@ -64,20 +67,47 @@ export class Handle extends Component<HandleStyleProps> {
64
67
  }
65
68
 
66
69
  private renderMarker(container: Selection) {
67
- const { orientation, markerSymbol = ifHorizontal(orientation, 'horizontalHandle', 'verticalHandle') } =
68
- this.attributes;
70
+ const {
71
+ orientation,
72
+ classNamePrefix,
73
+ markerSymbol = ifHorizontal(orientation, 'horizontalHandle', 'verticalHandle'),
74
+ } = this.attributes;
69
75
 
70
76
  ifShow(!!markerSymbol, container, (group) => {
71
77
  const handleStyle = subStyleProps(this.attributes, 'marker');
72
78
  const markerStyle = { symbol: markerSymbol, ...handleStyle };
79
+ const markerClassName = getLegendClassName(
80
+ CLASS_NAMES.marker.name,
81
+ CLASSNAME_SUFFIX_MAP.handleMarker,
82
+ classNamePrefix
83
+ );
84
+
73
85
  this.marker = group
74
- .maybeAppendByClassName(CLASS_NAMES.marker, () => new Marker({ style: markerStyle }))
86
+ .maybeAppendByClassName(
87
+ CLASS_NAMES.marker,
88
+ () =>
89
+ new Marker({
90
+ style: markerStyle,
91
+ className: markerClassName,
92
+ })
93
+ )
75
94
  .update(markerStyle);
95
+
96
+ // Update Marker's child element className (Marker component overrides className internally)
97
+ if (classNamePrefix) {
98
+ const markerElement = this.marker.node().querySelector('.marker');
99
+ if (markerElement) {
100
+ const currentClass = markerElement.getAttribute('class') || '';
101
+ const baseClass = currentClass.split(' ')[0]; // e.g., 'marker'
102
+ const legendClassName = getLegendClassName(baseClass, CLASSNAME_SUFFIX_MAP.handleMarker, classNamePrefix);
103
+ markerElement.setAttribute('class', legendClassName);
104
+ }
105
+ }
76
106
  });
77
107
  }
78
108
 
79
109
  private renderLabel(container: Selection) {
80
- const { showLabel, orientation, spacing = 0, formatter } = this.attributes;
110
+ const { showLabel, orientation, spacing = 0, formatter, classNamePrefix } = this.attributes;
81
111
 
82
112
  ifShow(showLabel, container, (group) => {
83
113
  const { text, ...labelStyle } = subStyleProps(this.attributes, 'label');
@@ -90,8 +120,15 @@ export class Handle extends Component<HandleStyleProps> {
90
120
  [width + spacing, 0, 'start', 'middle']
91
121
  );
92
122
 
123
+ const labelClassName = getLegendClassName(
124
+ CLASS_NAMES.label.name,
125
+ CLASSNAME_SUFFIX_MAP.handleLabel,
126
+ classNamePrefix
127
+ );
128
+
93
129
  group
94
130
  .maybeAppendByClassName(CLASS_NAMES.label, 'text')
131
+ .attr('className', labelClassName)
95
132
  .styles({ ...labelStyle, x, y, text: formatter(text).toString(), textAlign, textBaseline });
96
133
  });
97
134
  }
@@ -5,6 +5,8 @@ import { Component } from '../../../core';
5
5
  import type { GroupStyleProps, PathStyleProps, RectStyleProps } from '../../../shapes';
6
6
  import { Group } from '../../../shapes';
7
7
  import { classNames, select, Selection, subStyleProps } from '../../../util';
8
+ import { CLASSNAME_SUFFIX_MAP } from '../constant';
9
+ import { getLegendClassName } from '../utils/classname';
8
10
  import { ifHorizontal } from '../utils';
9
11
  import { getBlockColor } from './utils';
10
12
 
@@ -23,6 +25,7 @@ export type RibbonStyleProps = GroupStyleProps &
23
25
  range?: [number, number];
24
26
  size: number;
25
27
  type?: 'size' | 'color';
28
+ classNamePrefix?: string;
26
29
  };
27
30
 
28
31
  export type RibbonOptions = ComponentOptions<RibbonStyleProps>;
@@ -93,15 +96,28 @@ function getClipPath(attr: RequiredRibbonStyleProps): any[] {
93
96
 
94
97
  function renderTrack(container: Selection, attr: RequiredRibbonStyleProps) {
95
98
  const style = subStyleProps(attr, 'track');
96
- container.maybeAppendByClassName(CLASS_NAMES.track, 'path').styles({ d: getTrackPath(attr), ...style });
99
+ const { classNamePrefix } = attr;
100
+ const trackClassName = getLegendClassName(CLASS_NAMES.track.name, CLASSNAME_SUFFIX_MAP.track, classNamePrefix);
101
+
102
+ container
103
+ .maybeAppendByClassName(CLASS_NAMES.track, 'path')
104
+ .attr('className', trackClassName)
105
+ .styles({ d: getTrackPath(attr), ...style });
97
106
  }
98
107
 
99
108
  function renderSelection(container: Selection, attr: RequiredRibbonStyleProps) {
100
109
  const style = subStyleProps(attr, 'selection');
101
110
  const fill = getColor(attr);
111
+ const { classNamePrefix } = attr;
112
+ const selectionClassName = getLegendClassName(
113
+ CLASS_NAMES.selection.name,
114
+ CLASSNAME_SUFFIX_MAP.selection,
115
+ classNamePrefix
116
+ );
102
117
 
103
118
  const ribbon = container
104
119
  .maybeAppendByClassName(CLASS_NAMES.selection, 'path')
120
+ .attr('className', selectionClassName)
105
121
  .styles({ d: getSelectionPath(attr), fill, ...style });
106
122
  const clipPath = ribbon
107
123
  .maybeAppendByClassName(CLASS_NAMES.clipPath, 'path')
@@ -25,7 +25,8 @@ import type { IndicatorStyleProps } from '../indicator';
25
25
  import { Indicator } from '../indicator';
26
26
  import { Handle as SliderHandle } from '../slider/handle';
27
27
  import { Title } from './title';
28
- import { CLASS_NAMES, CONTINUOUS_DEFAULT_OPTIONS, STEP_RATIO } from './constant';
28
+ import { CLASS_NAMES, CLASSNAME_SUFFIX_MAP, CONTINUOUS_DEFAULT_OPTIONS, STEP_RATIO } from './constant';
29
+ import { getLegendClassName } from './utils/classname';
29
30
  import type { HandleStyleProps, HandleType } from './continuous/handle';
30
31
  import { Handle } from './continuous/handle';
31
32
  import type { RibbonStyleProps } from './continuous/ribbon';
@@ -76,6 +77,15 @@ export class Continuous extends Component<ContinuousStyleProps> {
76
77
  }
77
78
 
78
79
  public render(attributes: Required<ContinuousStyleProps>, container: Group) {
80
+ // Set root container className
81
+ const { classNamePrefix } = attributes;
82
+ const baseClassName = container.className || 'legend-continuous';
83
+ if (classNamePrefix) {
84
+ container.attr('className', `${baseClassName} ${classNamePrefix}legend`);
85
+ } else if (!container.className) {
86
+ container.attr('className', 'legend-continuous');
87
+ }
88
+
79
89
  // 渲染顺序
80
90
  // 1. 绘制 title, 获得可用空间
81
91
  // 2. 绘制 label, handle
@@ -153,9 +163,9 @@ export class Continuous extends Component<ContinuousStyleProps> {
153
163
  }
154
164
 
155
165
  private renderTitle(container: Selection) {
156
- const { showTitle, titleText, width, height } = this.attributes;
166
+ const { showTitle, titleText, width, height, classNamePrefix } = this.attributes;
157
167
  const style = subStyleProps<TextStyleProps>(this.attributes, 'title');
158
- const finalTitleStyle = { ...style, width, height, text: titleText };
168
+ const finalTitleStyle = { ...style, width, height, text: titleText, classNamePrefix };
159
169
  const that = this;
160
170
  container
161
171
  .selectAll(CLASS_NAMES.title.class)
@@ -263,7 +273,7 @@ export class Continuous extends Component<ContinuousStyleProps> {
263
273
  }
264
274
 
265
275
  private renderRibbon(container: Selection) {
266
- const { data, type, orientation, color, block } = this.attributes;
276
+ const { data, type, orientation, color, block, classNamePrefix } = this.attributes;
267
277
  const ribbonStyle = subStyleProps(this.attributes, 'ribbon');
268
278
  const { min, max } = this.range;
269
279
  const { x, y } = this.ribbonBBox;
@@ -279,11 +289,22 @@ export class Continuous extends Component<ContinuousStyleProps> {
279
289
  block,
280
290
  partition: data.map((d) => (d.value - min) / (max - min)),
281
291
  range: this.ribbonRange,
292
+ classNamePrefix,
282
293
  },
283
294
  ribbonStyle
284
295
  );
285
296
 
286
- this.ribbon = container.maybeAppendByClassName(CLASS_NAMES.ribbon, () => new Ribbon({ style })).update(style);
297
+ const ribbonClassName = getLegendClassName(CLASS_NAMES.ribbon.name, CLASSNAME_SUFFIX_MAP.ribbon, classNamePrefix);
298
+ this.ribbon = container
299
+ .maybeAppendByClassName(
300
+ CLASS_NAMES.ribbon,
301
+ () =>
302
+ new Ribbon({
303
+ style,
304
+ className: ribbonClassName,
305
+ })
306
+ )
307
+ .update(style);
287
308
  }
288
309
 
289
310
  private getHandleClassName(type: HandleType) {
@@ -292,14 +313,19 @@ export class Continuous extends Component<ContinuousStyleProps> {
292
313
  }
293
314
 
294
315
  private renderHandles() {
295
- const { showHandle, orientation } = this.attributes;
316
+ const { showHandle, orientation, classNamePrefix } = this.attributes;
296
317
  const handleStyle = subStyleProps<HandleStyleProps>(this.attributes, 'handle');
297
318
  const [min, max] = this.selection;
298
- const style = { ...handleStyle, orientation };
319
+ const style = { ...handleStyle, orientation, classNamePrefix };
299
320
  const { shape = 'slider' } = handleStyle;
300
321
  const HandleCtor = shape === 'basic' ? Handle : SliderHandle;
301
322
 
302
323
  const that = this;
324
+ const baseHandleClassName = getLegendClassName(
325
+ CLASS_NAMES.handle.name,
326
+ CLASSNAME_SUFFIX_MAP.handle,
327
+ classNamePrefix
328
+ );
303
329
  this.handlesGroup
304
330
  .selectAll(CLASS_NAMES.handle.class)
305
331
  .data(
@@ -314,10 +340,10 @@ export class Continuous extends Component<ContinuousStyleProps> {
314
340
  .join(
315
341
  (enter) =>
316
342
  enter
317
- .append(() => new HandleCtor({ style }))
343
+ .append(() => new HandleCtor({ style, className: baseHandleClassName }))
318
344
  .attr(
319
345
  'className',
320
- ({ type }: any) => `${CLASS_NAMES.handle} ${that.getHandleClassName(type as HandleType)}`
346
+ ({ type }: any) => `${baseHandleClassName} ${that.getHandleClassName(type as HandleType)}`
321
347
  )
322
348
  .each(function ({ type, value: labelText }) {
323
349
  this.update({ labelText });
@@ -343,6 +369,51 @@ export class Continuous extends Component<ContinuousStyleProps> {
343
369
  const [min, max] = this.selection;
344
370
  this.setHandlePosition('start', min);
345
371
  this.setHandlePosition('end', max);
372
+
373
+ // Update SliderHandle sub-elements className after rendering
374
+ const { classNamePrefix, showHandle } = this.attributes;
375
+ const { shape = 'slider' } = subStyleProps<HandleStyleProps>(this.attributes, 'handle');
376
+ if (showHandle && shape === 'slider' && classNamePrefix) {
377
+ if (this.startHandle) this.updateSliderHandleClassNames(this.startHandle, classNamePrefix);
378
+ if (this.endHandle) this.updateSliderHandleClassNames(this.endHandle, classNamePrefix);
379
+ }
380
+ }
381
+
382
+ /**
383
+ * Update SliderHandle sub-elements className to use legend prefix
384
+ * SliderHandle generates: handle-icon-rect, handle-icon-line, handle-label
385
+ * Should add legend className: g2-legend-handle-marker, g2-legend-handle-label
386
+ */
387
+ private updateSliderHandleClassNames(handle: any, classNamePrefix: string) {
388
+ // Get the actual DOM node from the component
389
+ const container = handle.container || handle;
390
+
391
+ // Update icon elements (rect and lines) to use handleMarker suffix
392
+ const iconRect = container.querySelector('.handle-icon-rect');
393
+ if (iconRect) {
394
+ const markerClassName = getLegendClassName(
395
+ 'handle-icon-rect',
396
+ CLASSNAME_SUFFIX_MAP.handleMarker,
397
+ classNamePrefix
398
+ );
399
+ iconRect.setAttribute('class', markerClassName);
400
+
401
+ // Line elements are children of rect element
402
+ const iconLines = iconRect.querySelectorAll('line');
403
+ iconLines.forEach((line: any) => {
404
+ const currentClass = line.getAttribute('class') || '';
405
+ const baseClass = currentClass.split(' ')[0]; // e.g., 'handle-icon-line-1'
406
+ const markerClassName = getLegendClassName(baseClass, CLASSNAME_SUFFIX_MAP.handleMarker, classNamePrefix);
407
+ line.setAttribute('class', markerClassName);
408
+ });
409
+ }
410
+
411
+ // Update label element to use handleLabel suffix
412
+ const label = container.querySelector('.handle-label');
413
+ if (label) {
414
+ const labelClassName = getLegendClassName('handle-label', CLASSNAME_SUFFIX_MAP.handleLabel, classNamePrefix);
415
+ label.setAttribute('class', labelClassName);
416
+ }
346
417
  }
347
418
 
348
419
  private cacheHandleBBox: DOMRect | null = null;
@@ -380,8 +451,23 @@ export class Continuous extends Component<ContinuousStyleProps> {
380
451
  }
381
452
 
382
453
  private renderIndicator(container: Selection) {
454
+ const { classNamePrefix } = this.attributes;
383
455
  const style = subStyleProps<IndicatorStyleProps>(this.attributes, 'indicator');
384
- this.indicator = container.maybeAppendByClassName(CLASS_NAMES.indicator, () => new Indicator({})).update(style);
456
+ const indicatorClassName = getLegendClassName(
457
+ CLASS_NAMES.indicator.name,
458
+ CLASSNAME_SUFFIX_MAP.indicator,
459
+ classNamePrefix
460
+ );
461
+ this.indicator = container
462
+ .maybeAppendByClassName(
463
+ CLASS_NAMES.indicator,
464
+ () =>
465
+ new Indicator({
466
+ style,
467
+ className: indicatorClassName,
468
+ })
469
+ )
470
+ .update(style);
385
471
  // this.hideIndicator();
386
472
  }
387
473
 
@@ -2,6 +2,8 @@ import { Component } from '../../../core';
2
2
  import type { Group } from '../../../shapes';
3
3
  import { DisplayObject, Text } from '../../../shapes';
4
4
  import { BBox, Selection, classNames, ifShow, parsePosition, parseSeriesAttr, select, splitStyle } from '../../../util';
5
+ import { getLegendClassName } from '../utils/classname';
6
+ import { CLASSNAME_SUFFIX_MAP } from '../constant';
5
7
  import type { TitleOptions, TitleStyleProps } from './types';
6
8
 
7
9
  export type { TitleOptions, TitleStyleProps };
@@ -144,14 +146,16 @@ export class Title extends Component<TitleStyleProps> {
144
146
  }
145
147
 
146
148
  public render(attributes: Required<TitleStyleProps>, container: Group) {
147
- const { width, height, position, spacing, ...restStyle } = attributes;
149
+ const { width, height, position, spacing, classNamePrefix, ...restStyle } = attributes;
148
150
 
149
151
  const [titleStyle] = splitStyle(restStyle);
150
152
  const { x, y, textAlign, textBaseline } = getTitleLayout(attributes);
151
153
 
152
154
  ifShow(!!restStyle.text, select(container), (group) => {
155
+ const titleClassName = getLegendClassName(CLASS_NAMES.text.name, CLASSNAME_SUFFIX_MAP.title, classNamePrefix);
153
156
  this.title = group
154
157
  .maybeAppendByClassName(CLASS_NAMES.text, 'text')
158
+ .attr('className', titleClassName)
155
159
  .styles(titleStyle)
156
160
  .call(mayApplyStyle, { x, y, textAlign, textBaseline })
157
161
  .node();
@@ -25,6 +25,7 @@ export type TitleStyleProps = GroupStyleProps &
25
25
  | 'right-bottom'
26
26
  | 'bottom-right'
27
27
  | 'inner';
28
+ classNamePrefix?: string;
28
29
  };
29
30
 
30
31
  export type TitleOptions = ComponentOptions<TitleStyleProps>;
@@ -41,6 +41,7 @@ export type LegendBaseStyleProps = GroupStyleProps &
41
41
  padding?: SeriesAttr;
42
42
  showTitle?: boolean;
43
43
  // type?: 'category' | 'continuous';
44
+ classNamePrefix?: string;
44
45
  };
45
46
 
46
47
  export type LegendBaseOptions = ComponentOptions<LegendBaseStyleProps>;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Legend className utility functions
3
+ */
4
+
5
+ /**
6
+ * Generate legend className with optional prefix
7
+ * @param baseClassName - Base className, e.g., 'title-text'
8
+ * @param suffix - Suffix for prefixed className, e.g., 'title' -> '{prefix}legend-title'
9
+ * @param classNamePrefix - Optional className prefix, e.g., 'g2-'
10
+ * @returns Complete className, e.g., 'title-text g2-legend-title'
11
+ *
12
+ * @example
13
+ * getLegendClassName('title-text', 'title', 'g2-')
14
+ * // Returns: 'title-text g2-legend-title'
15
+ */
16
+ export function getLegendClassName(baseClassName: string, suffix: string, classNamePrefix?: string): string {
17
+ if (!classNamePrefix) return baseClassName;
18
+ return `${baseClassName} ${classNamePrefix}legend-${suffix}`;
19
+ }
20
+
21
+ /**
22
+ * Generate className from component attributes
23
+ * @param attributes - Component attributes with classNamePrefix
24
+ * @param baseClassName - CLASS_NAMES object, e.g., CLASS_NAMES.text
25
+ * @param suffix - Suffix key from CLASSNAME_SUFFIX_MAP
26
+ * @returns Complete className
27
+ *
28
+ * @example
29
+ * getClassNameFromAttrs(this.attributes, CLASS_NAMES.text, 'title')
30
+ * // Returns: 'title-text g2-legend-title' (if classNamePrefix = 'g2-')
31
+ */
32
+ export function getClassNameFromAttrs(
33
+ attributes: { classNamePrefix?: string },
34
+ baseClassName: { name: string },
35
+ suffix: string
36
+ ): string {
37
+ const { classNamePrefix = '' } = attributes;
38
+ return getLegendClassName(baseClassName.name, suffix, classNamePrefix);
39
+ }
@@ -0,0 +1 @@
1
+ export * from './classname';
@@ -19,6 +19,8 @@ import {
19
19
  } from '../../util';
20
20
  import { button } from '../marker/symbol';
21
21
  import type { NavigatorOptions, NavigatorStyleProps } from './types';
22
+ import { CLASSNAME_SUFFIX_MAP } from '../legend/classname-map';
23
+ import { getLegendClassName } from '../legend/utils/classname';
22
24
 
23
25
  export type { NavigatorOptions, NavigatorStyleProps };
24
26
 
@@ -272,7 +274,7 @@ export class Navigator extends Component<NavigatorStyleProps> {
272
274
  }
273
275
 
274
276
  private renderController(container: Selection) {
275
- const { controllerSpacing: spacing } = this.attributes;
277
+ const { controllerSpacing: spacing, classNamePrefix = '' } = this.attributes;
276
278
  const { pageWidth, pageHeight } = this.pageShape;
277
279
  const visible = this.pageViews.length >= 2;
278
280
 
@@ -291,10 +293,28 @@ export class Navigator extends Component<NavigatorStyleProps> {
291
293
  this.prevBtnGroup = prevBtnGroup.node();
292
294
  const prevBtn = prevBtnGroup.maybeAppendByClassName(CLASS_NAMES.prevBtn, 'path');
293
295
 
296
+ if (classNamePrefix) {
297
+ const prevBtnClassName = getLegendClassName(
298
+ CLASS_NAMES.prevBtn.name,
299
+ CLASSNAME_SUFFIX_MAP.prevBtn,
300
+ classNamePrefix
301
+ );
302
+ prevBtn.node().setAttribute('class', prevBtnClassName);
303
+ }
304
+
294
305
  const nextBtnGroup = group.maybeAppendByClassName(CLASS_NAMES.nextBtnGroup, 'g').styles(groupStyle);
295
306
  this.nextBtnGroup = nextBtnGroup.node();
296
307
  const nextBtn = nextBtnGroup.maybeAppendByClassName(CLASS_NAMES.nextBtn, 'path');
297
308
 
309
+ if (classNamePrefix) {
310
+ const nextBtnClassName = getLegendClassName(
311
+ CLASS_NAMES.nextBtn.name,
312
+ CLASSNAME_SUFFIX_MAP.nextBtn,
313
+ classNamePrefix
314
+ );
315
+ nextBtn.node().setAttribute('class', nextBtnClassName);
316
+ }
317
+
298
318
  [prevBtn, nextBtn].forEach((btn) => {
299
319
  btn.styles({ ...pathStyle, transformOrigin: 'center' });
300
320
  scaleToPixel(btn.node(), size, true);
@@ -303,7 +323,17 @@ export class Navigator extends Component<NavigatorStyleProps> {
303
323
  const pageInfoGroup = group.maybeAppendByClassName(CLASS_NAMES.pageInfoGroup, 'g');
304
324
  this.pageInfoGroup = pageInfoGroup.node();
305
325
 
306
- pageInfoGroup.maybeAppendByClassName(CLASS_NAMES.pageInfo, 'text').styles(textStyle);
326
+ const pageInfoElement = pageInfoGroup.maybeAppendByClassName(CLASS_NAMES.pageInfo, 'text');
327
+ pageInfoElement.styles(textStyle);
328
+
329
+ if (classNamePrefix) {
330
+ const pageInfoClassName = getLegendClassName(
331
+ CLASS_NAMES.pageInfo.name,
332
+ CLASSNAME_SUFFIX_MAP.pageInfo,
333
+ classNamePrefix
334
+ );
335
+ pageInfoElement.node().setAttribute('class', pageInfoClassName);
336
+ }
307
337
 
308
338
  this.updatePageInfo();
309
339
 
@@ -21,6 +21,7 @@ export type NavigatorStyleProps = Omit<RectStyleProps, 'width' | 'height'> &
21
21
  pageWidth?: number;
22
22
  /** infer to pageWidth */
23
23
  pageHeight?: number;
24
+ classNamePrefix?: string;
24
25
  };
25
26
 
26
27
  export type NavigatorOptions = ComponentOptions<NavigatorStyleProps>;