@antv/component 2.1.7 → 2.1.9

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 (177) 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 -1
  17. package/esm/ui/axis/guides/labels.js +11 -4
  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 +1 -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 +3 -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.d.ts +2 -1
  42. package/esm/ui/legend/category.js +45 -6
  43. package/esm/ui/legend/category.js.map +1 -1
  44. package/esm/ui/legend/classname-map.d.ts +37 -0
  45. package/esm/ui/legend/classname-map.js +38 -0
  46. package/esm/ui/legend/classname-map.js.map +1 -0
  47. package/esm/ui/legend/constant.d.ts +6 -0
  48. package/esm/ui/legend/constant.js +2 -0
  49. package/esm/ui/legend/constant.js.map +1 -1
  50. package/esm/ui/legend/continuous/handle.d.ts +1 -0
  51. package/esm/ui/legend/continuous/handle.js +23 -3
  52. package/esm/ui/legend/continuous/handle.js.map +1 -1
  53. package/esm/ui/legend/continuous/ribbon.d.ts +1 -0
  54. package/esm/ui/legend/continuous/ribbon.js +11 -1
  55. package/esm/ui/legend/continuous/ribbon.js.map +1 -1
  56. package/esm/ui/legend/continuous.d.ts +6 -0
  57. package/esm/ui/legend/continuous.js +77 -10
  58. package/esm/ui/legend/continuous.js.map +1 -1
  59. package/esm/ui/legend/title/index.js +5 -1
  60. package/esm/ui/legend/title/index.js.map +1 -1
  61. package/esm/ui/legend/title/types.d.ts +1 -0
  62. package/esm/ui/legend/types.d.ts +1 -0
  63. package/esm/ui/legend/utils/classname.d.ts +31 -0
  64. package/esm/ui/legend/utils/classname.js +35 -0
  65. package/esm/ui/legend/utils/classname.js.map +1 -0
  66. package/esm/ui/legend/utils/index.d.ts +1 -0
  67. package/esm/ui/legend/utils/index.js +2 -0
  68. package/esm/ui/legend/utils/index.js.map +1 -0
  69. package/esm/ui/navigator/index.js +19 -4
  70. package/esm/ui/navigator/index.js.map +1 -1
  71. package/esm/ui/navigator/types.d.ts +1 -0
  72. package/esm/ui/slider/handle.d.ts +2 -0
  73. package/esm/ui/slider/handle.js +21 -6
  74. package/esm/ui/slider/handle.js.map +1 -1
  75. package/esm/util/keyframe-interpolate.d.ts +1 -1
  76. package/lib/animation/fadeIn.d.ts +1 -1
  77. package/lib/animation/fadeOut.d.ts +1 -1
  78. package/lib/animation/utils.d.ts +3 -3
  79. package/lib/ui/axis/axis.d.ts +1 -1
  80. package/lib/ui/axis/axis.js +18 -2
  81. package/lib/ui/axis/axis.js.map +1 -1
  82. package/lib/ui/axis/classname-map.d.ts +18 -0
  83. package/lib/ui/axis/classname-map.js +23 -0
  84. package/lib/ui/axis/classname-map.js.map +1 -0
  85. package/lib/ui/axis/constant.js +16 -15
  86. package/lib/ui/axis/constant.js.map +1 -1
  87. package/lib/ui/axis/guides/grid.d.ts +1 -1
  88. package/lib/ui/axis/guides/grid.js +8 -1
  89. package/lib/ui/axis/guides/grid.js.map +1 -1
  90. package/lib/ui/axis/guides/labels.d.ts +1 -1
  91. package/lib/ui/axis/guides/labels.js +11 -4
  92. package/lib/ui/axis/guides/labels.js.map +1 -1
  93. package/lib/ui/axis/guides/line.js +31 -8
  94. package/lib/ui/axis/guides/line.js.map +1 -1
  95. package/lib/ui/axis/guides/ticks.d.ts +1 -1
  96. package/lib/ui/axis/guides/ticks.js +10 -3
  97. package/lib/ui/axis/guides/ticks.js.map +1 -1
  98. package/lib/ui/axis/guides/title.d.ts +1 -1
  99. package/lib/ui/axis/guides/title.js +6 -2
  100. package/lib/ui/axis/guides/title.js.map +1 -1
  101. package/lib/ui/axis/types.d.ts +1 -0
  102. package/lib/ui/axis/utils/classname.d.ts +46 -0
  103. package/lib/ui/axis/utils/classname.js +58 -0
  104. package/lib/ui/axis/utils/classname.js.map +1 -0
  105. package/lib/ui/axis/utils/index.d.ts +1 -0
  106. package/lib/ui/axis/utils/index.js +1 -0
  107. package/lib/ui/axis/utils/index.js.map +1 -1
  108. package/lib/ui/grid/index.d.ts +1 -1
  109. package/lib/ui/legend/category/item.d.ts +3 -1
  110. package/lib/ui/legend/category/item.js +42 -14
  111. package/lib/ui/legend/category/item.js.map +1 -1
  112. package/lib/ui/legend/category/items.d.ts +3 -0
  113. package/lib/ui/legend/category/items.js +11 -8
  114. package/lib/ui/legend/category/items.js.map +1 -1
  115. package/lib/ui/legend/category.d.ts +2 -1
  116. package/lib/ui/legend/category.js +45 -6
  117. package/lib/ui/legend/category.js.map +1 -1
  118. package/lib/ui/legend/classname-map.d.ts +37 -0
  119. package/lib/ui/legend/classname-map.js +41 -0
  120. package/lib/ui/legend/classname-map.js.map +1 -0
  121. package/lib/ui/legend/constant.d.ts +6 -0
  122. package/lib/ui/legend/constant.js +4 -1
  123. package/lib/ui/legend/constant.js.map +1 -1
  124. package/lib/ui/legend/continuous/handle.d.ts +1 -0
  125. package/lib/ui/legend/continuous/handle.js +23 -3
  126. package/lib/ui/legend/continuous/handle.js.map +1 -1
  127. package/lib/ui/legend/continuous/ribbon.d.ts +1 -0
  128. package/lib/ui/legend/continuous/ribbon.js +11 -1
  129. package/lib/ui/legend/continuous/ribbon.js.map +1 -1
  130. package/lib/ui/legend/continuous.d.ts +6 -0
  131. package/lib/ui/legend/continuous.js +76 -9
  132. package/lib/ui/legend/continuous.js.map +1 -1
  133. package/lib/ui/legend/title/index.js +5 -1
  134. package/lib/ui/legend/title/index.js.map +1 -1
  135. package/lib/ui/legend/title/types.d.ts +1 -0
  136. package/lib/ui/legend/types.d.ts +1 -0
  137. package/lib/ui/legend/utils/classname.d.ts +31 -0
  138. package/lib/ui/legend/utils/classname.js +39 -0
  139. package/lib/ui/legend/utils/classname.js.map +1 -0
  140. package/lib/ui/legend/utils/index.d.ts +1 -0
  141. package/lib/ui/legend/utils/index.js +5 -0
  142. package/lib/ui/legend/utils/index.js.map +1 -0
  143. package/lib/ui/navigator/index.js +19 -4
  144. package/lib/ui/navigator/index.js.map +1 -1
  145. package/lib/ui/navigator/types.d.ts +1 -0
  146. package/lib/ui/slider/handle.d.ts +2 -0
  147. package/lib/ui/slider/handle.js +21 -6
  148. package/lib/ui/slider/handle.js.map +1 -1
  149. package/lib/util/keyframe-interpolate.d.ts +1 -1
  150. package/package.json +3 -2
  151. package/src/ui/axis/axis.ts +19 -2
  152. package/src/ui/axis/classname-map.ts +22 -0
  153. package/src/ui/axis/constant.ts +17 -15
  154. package/src/ui/axis/guides/grid.ts +8 -1
  155. package/src/ui/axis/guides/labels.ts +16 -6
  156. package/src/ui/axis/guides/line.ts +50 -12
  157. package/src/ui/axis/guides/ticks.ts +15 -5
  158. package/src/ui/axis/guides/title.ts +10 -4
  159. package/src/ui/axis/types.ts +1 -0
  160. package/src/ui/axis/utils/classname.ts +62 -0
  161. package/src/ui/axis/utils/index.ts +1 -0
  162. package/src/ui/legend/category/item.ts +59 -12
  163. package/src/ui/legend/category/items.ts +18 -7
  164. package/src/ui/legend/category.ts +46 -7
  165. package/src/ui/legend/classname-map.ts +45 -0
  166. package/src/ui/legend/constant.ts +3 -0
  167. package/src/ui/legend/continuous/handle.ts +41 -4
  168. package/src/ui/legend/continuous/ribbon.ts +17 -1
  169. package/src/ui/legend/continuous.ts +96 -10
  170. package/src/ui/legend/title/index.ts +5 -1
  171. package/src/ui/legend/title/types.ts +1 -0
  172. package/src/ui/legend/types.ts +1 -0
  173. package/src/ui/legend/utils/classname.ts +39 -0
  174. package/src/ui/legend/utils/index.ts +1 -0
  175. package/src/ui/navigator/index.ts +32 -2
  176. package/src/ui/navigator/types.ts +1 -0
  177. package/src/ui/slider/handle.ts +44 -6
@@ -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>;
@@ -14,6 +14,7 @@ export type IconStyleProps = PathStyleProps & {
14
14
  radius?: number;
15
15
  shape?: string | ((type: HandleType) => DisplayObject);
16
16
  orientation?: 'horizontal' | 'vertical';
17
+ classNamePrefix?: string;
17
18
  };
18
19
 
19
20
  export type LabelStyleProps = Partial<TextStyleProps>;
@@ -27,6 +28,7 @@ export type HandleStyleProps = GroupStyleProps &
27
28
  showLabel?: boolean;
28
29
  spacing?: number;
29
30
  type?: HandleType;
31
+ classNamePrefix?: string;
30
32
  };
31
33
 
32
34
  export type HandleOptions = ComponentOptions<HandleStyleProps>;
@@ -45,13 +47,23 @@ const CLASS_NAMES = classNames(
45
47
 
46
48
  class HandleIcon extends Component<IconStyleProps> {
47
49
  render(attributes: Required<IconStyleProps>, container: DisplayObject) {
48
- const { x, y, size = 10, radius = size / 4, orientation, ...iconStyle } = attributes;
49
- // 默认手柄
50
+ const { x, y, size = 10, radius = size / 4, orientation, classNamePrefix, ...iconStyle } = attributes;
51
+ // default handle
50
52
  const width = size!;
51
53
  const height = width * 2.4;
52
54
 
55
+ const rectClassName = classNamePrefix
56
+ ? `${CLASS_NAMES.iconRect.name} ${classNamePrefix}handle-icon-rect`
57
+ : CLASS_NAMES.iconRect.name;
58
+
59
+ const lineClassName = (index: number) =>
60
+ classNamePrefix
61
+ ? `${CLASS_NAMES.iconLine}-${index} ${classNamePrefix}handle-icon-line`
62
+ : `${CLASS_NAMES.iconLine}-${index}`;
63
+
53
64
  const rect = select(container)
54
65
  .maybeAppendByClassName(CLASS_NAMES.iconRect, 'rect')
66
+ .attr('className', rectClassName)
55
67
  .styles({
56
68
  ...iconStyle,
57
69
  width,
@@ -67,8 +79,27 @@ class HandleIcon extends Component<IconStyleProps> {
67
79
  const y1 = y + (1 / 4) * height - height / 2;
68
80
  const y2 = y + (3 / 4) * height - height / 2;
69
81
 
70
- rect.maybeAppendByClassName(`${CLASS_NAMES.iconLine}-1`, 'line').styles({ x1, x2: x1, y1, y2, ...iconStyle });
71
- rect.maybeAppendByClassName(`${CLASS_NAMES.iconLine}-2`, 'line').styles({ x1: x2, x2, y1, y2, ...iconStyle });
82
+ rect
83
+ .maybeAppendByClassName(`${CLASS_NAMES.iconLine}-1`, 'line')
84
+ .attr('className', lineClassName(1))
85
+ .styles({
86
+ x1,
87
+ x2: x1,
88
+ y1,
89
+ y2,
90
+ ...iconStyle,
91
+ });
92
+
93
+ rect
94
+ .maybeAppendByClassName(`${CLASS_NAMES.iconLine}-2`, 'line')
95
+ .attr('className', lineClassName(2))
96
+ .styles({
97
+ x1: x2,
98
+ x2,
99
+ y1,
100
+ y2,
101
+ ...iconStyle,
102
+ });
72
103
 
73
104
  if (orientation === 'vertical') rect.node().style.transform = 'rotate(90)';
74
105
  }
@@ -119,8 +150,15 @@ export class Handle extends Component<HandleStyleProps> {
119
150
  }
120
151
 
121
152
  private renderIcon(container: Group) {
122
- const { x, y, orientation, type } = this.attributes;
123
- const iconStyle = { x, y, orientation, ...HANDLE_ICON_DEFAULT_CFG, ...subStyleProps(this.attributes, 'icon') };
153
+ const { x, y, orientation, type, classNamePrefix } = this.attributes;
154
+ const iconStyle = {
155
+ x,
156
+ y,
157
+ orientation,
158
+ classNamePrefix,
159
+ ...HANDLE_ICON_DEFAULT_CFG,
160
+ ...subStyleProps(this.attributes, 'icon'),
161
+ };
124
162
  const { iconShape = () => new HandleIcon({ style: iconStyle }) } = this.attributes;
125
163
  const iconGroup = select(container).maybeAppendByClassName(CLASS_NAMES.iconGroup, 'g');
126
164
  iconGroup