@antv/component 2.1.7 → 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 (155) hide show
  1. package/dist/component.min.js +1 -1
  2. package/esm/ui/axis/axis.js +18 -2
  3. package/esm/ui/axis/axis.js.map +1 -1
  4. package/esm/ui/axis/classname-map.d.ts +18 -0
  5. package/esm/ui/axis/classname-map.js +20 -0
  6. package/esm/ui/axis/classname-map.js.map +1 -0
  7. package/esm/ui/axis/constant.js +16 -15
  8. package/esm/ui/axis/constant.js.map +1 -1
  9. package/esm/ui/axis/guides/grid.js +8 -1
  10. package/esm/ui/axis/guides/grid.js.map +1 -1
  11. package/esm/ui/axis/guides/labels.js +11 -4
  12. package/esm/ui/axis/guides/labels.js.map +1 -1
  13. package/esm/ui/axis/guides/line.js +31 -8
  14. package/esm/ui/axis/guides/line.js.map +1 -1
  15. package/esm/ui/axis/guides/ticks.js +10 -3
  16. package/esm/ui/axis/guides/ticks.js.map +1 -1
  17. package/esm/ui/axis/guides/title.js +6 -2
  18. package/esm/ui/axis/guides/title.js.map +1 -1
  19. package/esm/ui/axis/types.d.ts +1 -0
  20. package/esm/ui/axis/utils/classname.d.ts +46 -0
  21. package/esm/ui/axis/utils/classname.js +53 -0
  22. package/esm/ui/axis/utils/classname.js.map +1 -0
  23. package/esm/ui/axis/utils/index.d.ts +1 -0
  24. package/esm/ui/axis/utils/index.js +1 -0
  25. package/esm/ui/axis/utils/index.js.map +1 -1
  26. package/esm/ui/legend/category/item.d.ts +3 -1
  27. package/esm/ui/legend/category/item.js +42 -14
  28. package/esm/ui/legend/category/item.js.map +1 -1
  29. package/esm/ui/legend/category/items.d.ts +2 -0
  30. package/esm/ui/legend/category/items.js +12 -9
  31. package/esm/ui/legend/category/items.js.map +1 -1
  32. package/esm/ui/legend/category.js +11 -3
  33. package/esm/ui/legend/category.js.map +1 -1
  34. package/esm/ui/legend/classname-map.d.ts +37 -0
  35. package/esm/ui/legend/classname-map.js +38 -0
  36. package/esm/ui/legend/classname-map.js.map +1 -0
  37. package/esm/ui/legend/constant.d.ts +1 -0
  38. package/esm/ui/legend/constant.js +1 -0
  39. package/esm/ui/legend/constant.js.map +1 -1
  40. package/esm/ui/legend/continuous/handle.d.ts +1 -0
  41. package/esm/ui/legend/continuous/handle.js +23 -3
  42. package/esm/ui/legend/continuous/handle.js.map +1 -1
  43. package/esm/ui/legend/continuous/ribbon.d.ts +1 -0
  44. package/esm/ui/legend/continuous/ribbon.js +11 -1
  45. package/esm/ui/legend/continuous/ribbon.js.map +1 -1
  46. package/esm/ui/legend/continuous.d.ts +6 -0
  47. package/esm/ui/legend/continuous.js +77 -10
  48. package/esm/ui/legend/continuous.js.map +1 -1
  49. package/esm/ui/legend/title/index.js +5 -1
  50. package/esm/ui/legend/title/index.js.map +1 -1
  51. package/esm/ui/legend/title/types.d.ts +1 -0
  52. package/esm/ui/legend/types.d.ts +1 -0
  53. package/esm/ui/legend/utils/classname.d.ts +31 -0
  54. package/esm/ui/legend/utils/classname.js +35 -0
  55. package/esm/ui/legend/utils/classname.js.map +1 -0
  56. package/esm/ui/legend/utils/index.d.ts +1 -0
  57. package/esm/ui/legend/utils/index.js +2 -0
  58. package/esm/ui/legend/utils/index.js.map +1 -0
  59. package/esm/ui/navigator/index.js +19 -4
  60. package/esm/ui/navigator/index.js.map +1 -1
  61. package/esm/ui/navigator/types.d.ts +1 -0
  62. package/esm/ui/slider/handle.d.ts +2 -0
  63. package/esm/ui/slider/handle.js +21 -6
  64. package/esm/ui/slider/handle.js.map +1 -1
  65. package/lib/ui/axis/axis.js +18 -2
  66. package/lib/ui/axis/axis.js.map +1 -1
  67. package/lib/ui/axis/classname-map.d.ts +18 -0
  68. package/lib/ui/axis/classname-map.js +23 -0
  69. package/lib/ui/axis/classname-map.js.map +1 -0
  70. package/lib/ui/axis/constant.js +16 -15
  71. package/lib/ui/axis/constant.js.map +1 -1
  72. package/lib/ui/axis/guides/grid.js +8 -1
  73. package/lib/ui/axis/guides/grid.js.map +1 -1
  74. package/lib/ui/axis/guides/labels.js +11 -4
  75. package/lib/ui/axis/guides/labels.js.map +1 -1
  76. package/lib/ui/axis/guides/line.js +31 -8
  77. package/lib/ui/axis/guides/line.js.map +1 -1
  78. package/lib/ui/axis/guides/ticks.js +10 -3
  79. package/lib/ui/axis/guides/ticks.js.map +1 -1
  80. package/lib/ui/axis/guides/title.js +6 -2
  81. package/lib/ui/axis/guides/title.js.map +1 -1
  82. package/lib/ui/axis/types.d.ts +1 -0
  83. package/lib/ui/axis/utils/classname.d.ts +46 -0
  84. package/lib/ui/axis/utils/classname.js +58 -0
  85. package/lib/ui/axis/utils/classname.js.map +1 -0
  86. package/lib/ui/axis/utils/index.d.ts +1 -0
  87. package/lib/ui/axis/utils/index.js +1 -0
  88. package/lib/ui/axis/utils/index.js.map +1 -1
  89. package/lib/ui/legend/category/item.d.ts +3 -1
  90. package/lib/ui/legend/category/item.js +42 -14
  91. package/lib/ui/legend/category/item.js.map +1 -1
  92. package/lib/ui/legend/category/items.d.ts +2 -0
  93. package/lib/ui/legend/category/items.js +11 -8
  94. package/lib/ui/legend/category/items.js.map +1 -1
  95. package/lib/ui/legend/category.js +11 -3
  96. package/lib/ui/legend/category.js.map +1 -1
  97. package/lib/ui/legend/classname-map.d.ts +37 -0
  98. package/lib/ui/legend/classname-map.js +41 -0
  99. package/lib/ui/legend/classname-map.js.map +1 -0
  100. package/lib/ui/legend/constant.d.ts +1 -0
  101. package/lib/ui/legend/constant.js +3 -1
  102. package/lib/ui/legend/constant.js.map +1 -1
  103. package/lib/ui/legend/continuous/handle.d.ts +1 -0
  104. package/lib/ui/legend/continuous/handle.js +23 -3
  105. package/lib/ui/legend/continuous/handle.js.map +1 -1
  106. package/lib/ui/legend/continuous/ribbon.d.ts +1 -0
  107. package/lib/ui/legend/continuous/ribbon.js +11 -1
  108. package/lib/ui/legend/continuous/ribbon.js.map +1 -1
  109. package/lib/ui/legend/continuous.d.ts +6 -0
  110. package/lib/ui/legend/continuous.js +76 -9
  111. package/lib/ui/legend/continuous.js.map +1 -1
  112. package/lib/ui/legend/title/index.js +5 -1
  113. package/lib/ui/legend/title/index.js.map +1 -1
  114. package/lib/ui/legend/title/types.d.ts +1 -0
  115. package/lib/ui/legend/types.d.ts +1 -0
  116. package/lib/ui/legend/utils/classname.d.ts +31 -0
  117. package/lib/ui/legend/utils/classname.js +39 -0
  118. package/lib/ui/legend/utils/classname.js.map +1 -0
  119. package/lib/ui/legend/utils/index.d.ts +1 -0
  120. package/lib/ui/legend/utils/index.js +5 -0
  121. package/lib/ui/legend/utils/index.js.map +1 -0
  122. package/lib/ui/navigator/index.js +19 -4
  123. package/lib/ui/navigator/index.js.map +1 -1
  124. package/lib/ui/navigator/types.d.ts +1 -0
  125. package/lib/ui/slider/handle.d.ts +2 -0
  126. package/lib/ui/slider/handle.js +21 -6
  127. package/lib/ui/slider/handle.js.map +1 -1
  128. package/package.json +2 -2
  129. package/src/ui/axis/axis.ts +19 -2
  130. package/src/ui/axis/classname-map.ts +22 -0
  131. package/src/ui/axis/constant.ts +17 -15
  132. package/src/ui/axis/guides/grid.ts +8 -1
  133. package/src/ui/axis/guides/labels.ts +16 -6
  134. package/src/ui/axis/guides/line.ts +50 -12
  135. package/src/ui/axis/guides/ticks.ts +15 -5
  136. package/src/ui/axis/guides/title.ts +10 -4
  137. package/src/ui/axis/types.ts +1 -0
  138. package/src/ui/axis/utils/classname.ts +62 -0
  139. package/src/ui/axis/utils/index.ts +1 -0
  140. package/src/ui/legend/category/item.ts +59 -12
  141. package/src/ui/legend/category/items.ts +17 -7
  142. package/src/ui/legend/category.ts +12 -3
  143. package/src/ui/legend/classname-map.ts +45 -0
  144. package/src/ui/legend/constant.ts +2 -0
  145. package/src/ui/legend/continuous/handle.ts +41 -4
  146. package/src/ui/legend/continuous/ribbon.ts +17 -1
  147. package/src/ui/legend/continuous.ts +96 -10
  148. package/src/ui/legend/title/index.ts +5 -1
  149. package/src/ui/legend/title/types.ts +1 -0
  150. package/src/ui/legend/types.ts +1 -0
  151. package/src/ui/legend/utils/classname.ts +39 -0
  152. package/src/ui/legend/utils/index.ts +1 -0
  153. package/src/ui/navigator/index.ts +32 -2
  154. package/src/ui/navigator/types.ts +1 -0
  155. package/src/ui/slider/handle.ts +44 -6
@@ -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