@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
@@ -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
@@ -511,13 +511,12 @@ export class Slider extends Component<SliderStyleProps> {
511
511
  return orientation === 'horizontal' ? x : y;
512
512
  }
513
513
 
514
- private setValuesOffset(stOffset: number, endOffset: number = 0, animate: boolean = false) {
514
+ private setValuesOffset(stOffset: number, endOffset: number = 0) {
515
515
  const { type } = this.attributes;
516
516
  const [oldStartVal, oldEndVal] = this.getValues();
517
517
  const internalStartOffset = type === 'range' ? stOffset : 0;
518
518
  const values = [oldStartVal + internalStartOffset, oldEndVal + endOffset].sort() as [number, number];
519
- if (animate) this.setValues(values);
520
- else this.innerSetValues(values, true);
519
+ this.innerSetValues(values, true);
521
520
  }
522
521
 
523
522
  private getRatio(val: number) {
@@ -550,7 +549,7 @@ export class Slider extends Component<SliderStyleProps> {
550
549
  const offset = deltaY || deltaX;
551
550
  const deltaVal = this.getRatio(offset);
552
551
 
553
- this.setValuesOffset(deltaVal, deltaVal, true);
552
+ this.setValuesOffset(deltaVal, deltaVal);
554
553
  }
555
554
  }
556
555
 
@@ -1,9 +1,15 @@
1
1
  import { isNumber, isString } from '@antv/util';
2
+ import type { HTMLStyleProps } from '@antv/g';
2
3
  import type { DisplayObject } from '../shapes';
3
- import { Text } from '../shapes';
4
+ import { Text, HTML } from '../shapes';
4
5
  import type { ExtendDisplayObject } from '../types';
5
6
 
6
7
  export function renderExtDo(el: ExtendDisplayObject): DisplayObject {
7
8
  if (typeof el === 'function') return el();
8
9
  return isString(el) || isNumber(el) ? new Text({ style: { text: String(el) } }) : el;
9
10
  }
11
+
12
+ export function renderHtmlExtDo(el: ExtendDisplayObject, style: Partial<HTMLStyleProps>): DisplayObject {
13
+ if (typeof el === 'function') return el();
14
+ return isString(el) || isNumber(el) ? new HTML({ style: { ...style, innerHTML: String(el) } }) : el;
15
+ }
package/src/util/index.ts CHANGED
@@ -40,3 +40,4 @@ export * from './traverse';
40
40
  export * from './visibility';
41
41
  export * from './replace-children';
42
42
  export * from './pase-position';
43
+ export * from './parse-height-from-html';
@@ -0,0 +1,94 @@
1
+ // Utility to parse height from an HTML string, limited: `box-sizing: border-box`
2
+ export const parseHeightFromHTML = (html: string): number => {
3
+ const parser = new DOMParser();
4
+ const doc = parser.parseFromString(html, 'text/html');
5
+ const el = doc.body.firstElementChild;
6
+ console.log(el?.getClientRects(), 11);
7
+
8
+ if (!el) return 0;
9
+
10
+ const style = el.getAttribute('style') || '';
11
+ const rules = Object.fromEntries(
12
+ style
13
+ .split(';')
14
+ .map((r) => r.trim())
15
+ .filter((r) => r.includes(':'))
16
+ .map((r) => {
17
+ const [key, value] = r.split(':').map((s) => s.trim());
18
+ return [key.toLowerCase(), value];
19
+ })
20
+ );
21
+
22
+ const parsePx = (v: string): number => {
23
+ if (!v) return 0;
24
+ const match = v.match(/([\d.]+)px/);
25
+ return match ? parseFloat(match[1]) : 0;
26
+ };
27
+
28
+ if (rules.height) {
29
+ return parsePx(rules.height);
30
+ }
31
+
32
+ const fontSize = parsePx(rules['font-size']) || 16;
33
+
34
+ // line-height
35
+ const lineHeight = rules['line-height'];
36
+ let baseHeight;
37
+ if (!lineHeight || lineHeight === 'normal') {
38
+ baseHeight = 1.2 * fontSize; // 默认 normal ≈ 1.2
39
+ } else if (lineHeight.endsWith('px')) {
40
+ baseHeight = parsePx(lineHeight);
41
+ } else if (/^[\d.]+$/.test(lineHeight)) {
42
+ baseHeight = parseFloat(lineHeight) * fontSize;
43
+ } else {
44
+ baseHeight = fontSize; // fallback
45
+ }
46
+
47
+ let paddingTop = parsePx(rules['padding-top']);
48
+ let paddingBottom = parsePx(rules['padding-bottom']);
49
+
50
+ if (rules.padding) {
51
+ const parts = rules.padding.split(/\s+/).map(parsePx);
52
+ if (parts.length === 1) {
53
+ paddingTop = parts[0];
54
+ paddingBottom = parts[0];
55
+ } else if (parts.length === 2) {
56
+ paddingTop = parts[0];
57
+ paddingBottom = parts[0];
58
+ } else if (parts.length === 3) {
59
+ paddingTop = parts[0];
60
+ paddingBottom = parts[2];
61
+ } else if (parts.length === 4) {
62
+ paddingTop = parts[0];
63
+ paddingBottom = parts[2];
64
+ }
65
+ }
66
+
67
+ let borderTop = parsePx(rules['border-top-width']);
68
+ let borderBottom = parsePx(rules['border-bottom-width']);
69
+ if (rules.border) {
70
+ const match = rules.border.match(/([\d.]+)px/);
71
+ if (match) {
72
+ borderTop = parseFloat(match[1]);
73
+ borderBottom = parseFloat(match[1]);
74
+ }
75
+ }
76
+ if (rules['border-width']) {
77
+ const parts = rules['border-width'].split(/\s+/).map(parsePx);
78
+ if (parts.length === 1) {
79
+ borderTop = parts[0];
80
+ borderBottom = parts[0];
81
+ } else if (parts.length === 2) {
82
+ borderTop = parts[0];
83
+ borderBottom = parts[0];
84
+ } else if (parts.length === 3) {
85
+ borderTop = parts[0];
86
+ borderBottom = parts[2];
87
+ } else if (parts.length === 4) {
88
+ borderTop = parts[0];
89
+ borderBottom = parts[2];
90
+ }
91
+ }
92
+
93
+ return baseHeight + paddingTop + paddingBottom + borderTop + borderBottom;
94
+ };