@antv/component 2.0.0 → 2.0.2

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 (216) 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/core/component.d.ts +1 -0
  6. package/esm/core/component.js +5 -1
  7. package/esm/core/component.js.map +1 -1
  8. package/esm/ui/axis/axis.d.ts +1 -1
  9. package/esm/ui/axis/guides/grid.d.ts +1 -1
  10. package/esm/ui/axis/guides/labels.d.ts +2 -1
  11. package/esm/ui/axis/guides/ticks.d.ts +1 -1
  12. package/esm/ui/axis/guides/title.d.ts +1 -1
  13. package/esm/ui/checkbox/constant.d.ts +4 -3
  14. package/esm/ui/grid/index.d.ts +1 -1
  15. package/esm/ui/legend/base.d.ts +1 -1
  16. package/esm/ui/legend/category/item.js +14 -5
  17. package/esm/ui/legend/category/item.js.map +1 -1
  18. package/esm/ui/legend/continuous/utils.js.map +1 -1
  19. package/esm/ui/legend/continuous.d.ts +2 -1
  20. package/esm/ui/legend/continuous.js +30 -8
  21. package/esm/ui/legend/continuous.js.map +1 -1
  22. package/esm/ui/marker/index.js +2 -1
  23. package/esm/ui/marker/index.js.map +1 -1
  24. package/esm/ui/tag/index.js +0 -4
  25. package/esm/ui/tag/index.js.map +1 -1
  26. package/esm/ui/timebar/controller.js.map +1 -1
  27. package/esm/ui/timebar/icons.d.ts +2 -2
  28. package/esm/ui/title/index.js.map +1 -1
  29. package/esm/ui/tooltip/index.js +6 -1
  30. package/esm/ui/tooltip/index.js.map +1 -1
  31. package/esm/util/group-by.js.map +1 -1
  32. package/esm/util/keyframe-interpolate.d.ts +1 -1
  33. package/esm/util/number.d.ts +2 -2
  34. package/esm/util/selection.d.ts +1 -2
  35. package/esm/util/text.d.ts +1 -1
  36. package/lib/animation/fadeIn.d.ts +1 -1
  37. package/lib/animation/fadeIn.js +1 -1
  38. package/lib/animation/fadeIn.js.map +1 -1
  39. package/lib/animation/fadeOut.d.ts +1 -1
  40. package/lib/animation/fadeOut.js +1 -1
  41. package/lib/animation/fadeOut.js.map +1 -1
  42. package/lib/animation/utils.d.ts +3 -3
  43. package/lib/animation/utils.js +6 -7
  44. package/lib/animation/utils.js.map +1 -1
  45. package/lib/core/component.d.ts +1 -0
  46. package/lib/core/component.js +4 -0
  47. package/lib/core/component.js.map +1 -1
  48. package/lib/ui/axis/axis.d.ts +1 -1
  49. package/lib/ui/axis/guides/grid.d.ts +1 -1
  50. package/lib/ui/axis/guides/grid.js +1 -2
  51. package/lib/ui/axis/guides/grid.js.map +1 -1
  52. package/lib/ui/axis/guides/labels.d.ts +2 -1
  53. package/lib/ui/axis/guides/labels.js +1 -2
  54. package/lib/ui/axis/guides/labels.js.map +1 -1
  55. package/lib/ui/axis/guides/line.js +6 -7
  56. package/lib/ui/axis/guides/line.js.map +1 -1
  57. package/lib/ui/axis/guides/ticks.d.ts +1 -1
  58. package/lib/ui/axis/guides/ticks.js +3 -4
  59. package/lib/ui/axis/guides/ticks.js.map +1 -1
  60. package/lib/ui/axis/guides/title.d.ts +1 -1
  61. package/lib/ui/axis/guides/title.js +1 -2
  62. package/lib/ui/axis/guides/title.js.map +1 -1
  63. package/lib/ui/axis/guides/utils.js +7 -8
  64. package/lib/ui/axis/guides/utils.js.map +1 -1
  65. package/lib/ui/axis/overlap/autoEllipsis.js +1 -1
  66. package/lib/ui/axis/overlap/autoEllipsis.js.map +1 -1
  67. package/lib/ui/axis/overlap/autoHide.js +1 -1
  68. package/lib/ui/axis/overlap/autoHide.js.map +1 -1
  69. package/lib/ui/axis/overlap/autoRotate.js +1 -1
  70. package/lib/ui/axis/overlap/autoRotate.js.map +1 -1
  71. package/lib/ui/axis/overlap/autoWrap.js +1 -1
  72. package/lib/ui/axis/overlap/autoWrap.js.map +1 -1
  73. package/lib/ui/axis/overlap/index.js +3 -3
  74. package/lib/ui/axis/overlap/index.js.map +1 -1
  75. package/lib/ui/axis/utils/bounds.js +2 -2
  76. package/lib/ui/axis/utils/bounds.js.map +1 -1
  77. package/lib/ui/axis/utils/contain.js +3 -4
  78. package/lib/ui/axis/utils/contain.js.map +1 -1
  79. package/lib/ui/axis/utils/index.js +1 -2
  80. package/lib/ui/axis/utils/index.js.map +1 -1
  81. package/lib/ui/axis/utils/intersect.js +2 -2
  82. package/lib/ui/axis/utils/intersect.js.map +1 -1
  83. package/lib/ui/axis/utils/test.js +1 -2
  84. package/lib/ui/axis/utils/test.js.map +1 -1
  85. package/lib/ui/checkbox/constant.d.ts +4 -3
  86. package/lib/ui/grid/index.d.ts +1 -1
  87. package/lib/ui/legend/base.d.ts +1 -1
  88. package/lib/ui/legend/base.js +4 -5
  89. package/lib/ui/legend/base.js.map +1 -1
  90. package/lib/ui/legend/category/item.js +14 -5
  91. package/lib/ui/legend/category/item.js.map +1 -1
  92. package/lib/ui/legend/continuous/utils.js +2 -3
  93. package/lib/ui/legend/continuous/utils.js.map +1 -1
  94. package/lib/ui/legend/continuous.d.ts +2 -1
  95. package/lib/ui/legend/continuous.js +30 -8
  96. package/lib/ui/legend/continuous.js.map +1 -1
  97. package/lib/ui/legend/utils.js +7 -7
  98. package/lib/ui/legend/utils.js.map +1 -1
  99. package/lib/ui/marker/index.js +2 -1
  100. package/lib/ui/marker/index.js.map +1 -1
  101. package/lib/ui/marker/symbol.js +2 -2
  102. package/lib/ui/marker/symbol.js.map +1 -1
  103. package/lib/ui/marker/utils.js +1 -2
  104. package/lib/ui/marker/utils.js.map +1 -1
  105. package/lib/ui/poptip/utils.js +2 -3
  106. package/lib/ui/poptip/utils.js.map +1 -1
  107. package/lib/ui/sparkline/path.js +7 -8
  108. package/lib/ui/sparkline/path.js.map +1 -1
  109. package/lib/ui/sparkline/utils.js +2 -3
  110. package/lib/ui/sparkline/utils.js.map +1 -1
  111. package/lib/ui/tag/index.js +0 -4
  112. package/lib/ui/tag/index.js.map +1 -1
  113. package/lib/ui/timebar/controller.js.map +1 -1
  114. package/lib/ui/timebar/icons.d.ts +2 -2
  115. package/lib/ui/timebar/utils.js +3 -4
  116. package/lib/ui/timebar/utils.js.map +1 -1
  117. package/lib/ui/title/index.js +3 -3
  118. package/lib/ui/title/index.js.map +1 -1
  119. package/lib/ui/tooltip/constant.js +2 -3
  120. package/lib/ui/tooltip/constant.js.map +1 -1
  121. package/lib/ui/tooltip/index.js +6 -1
  122. package/lib/ui/tooltip/index.js.map +1 -1
  123. package/lib/util/angle-converter.js +2 -3
  124. package/lib/util/angle-converter.js.map +1 -1
  125. package/lib/util/bbox.js +2 -2
  126. package/lib/util/bbox.js.map +1 -1
  127. package/lib/util/callback.js +1 -2
  128. package/lib/util/callback.js.map +1 -1
  129. package/lib/util/ellipsis.js +1 -2
  130. package/lib/util/ellipsis.js.map +1 -1
  131. package/lib/util/event.js +1 -2
  132. package/lib/util/event.js.map +1 -1
  133. package/lib/util/extend-display-object.js +1 -2
  134. package/lib/util/extend-display-object.js.map +1 -1
  135. package/lib/util/geometry/line-length.js +1 -2
  136. package/lib/util/geometry/line-length.js.map +1 -1
  137. package/lib/util/geometry/lines-intersection.js +1 -2
  138. package/lib/util/geometry/lines-intersection.js.map +1 -1
  139. package/lib/util/group-by.js +1 -2
  140. package/lib/util/group-by.js.map +1 -1
  141. package/lib/util/group.js +1 -2
  142. package/lib/util/group.js.map +1 -1
  143. package/lib/util/html.js +2 -3
  144. package/lib/util/html.js.map +1 -1
  145. package/lib/util/if-show.js +1 -2
  146. package/lib/util/if-show.js.map +1 -1
  147. package/lib/util/in-range.js +1 -2
  148. package/lib/util/in-range.js.map +1 -1
  149. package/lib/util/interpolate.js +4 -4
  150. package/lib/util/interpolate.js.map +1 -1
  151. package/lib/util/keyframe-interpolate.d.ts +1 -1
  152. package/lib/util/keyframe-interpolate.js +1 -2
  153. package/lib/util/keyframe-interpolate.js.map +1 -1
  154. package/lib/util/layout/utils/helper.js +1 -2
  155. package/lib/util/layout/utils/helper.js.map +1 -1
  156. package/lib/util/matrix.js +9 -10
  157. package/lib/util/matrix.js.map +1 -1
  158. package/lib/util/number.d.ts +2 -2
  159. package/lib/util/number.js +5 -5
  160. package/lib/util/number.js.map +1 -1
  161. package/lib/util/offscreen.js +2 -3
  162. package/lib/util/offscreen.js.map +1 -1
  163. package/lib/util/omit.js +1 -2
  164. package/lib/util/omit.js.map +1 -1
  165. package/lib/util/path.js +1 -2
  166. package/lib/util/path.js.map +1 -1
  167. package/lib/util/primitive.js +3 -3
  168. package/lib/util/primitive.js.map +1 -1
  169. package/lib/util/sampling.js +1 -2
  170. package/lib/util/sampling.js.map +1 -1
  171. package/lib/util/scale-to-pixel.js +1 -2
  172. package/lib/util/scale-to-pixel.js.map +1 -1
  173. package/lib/util/selection.d.ts +1 -2
  174. package/lib/util/selection.js +3 -3
  175. package/lib/util/selection.js.map +1 -1
  176. package/lib/util/series.js +1 -2
  177. package/lib/util/series.js.map +1 -1
  178. package/lib/util/shape.js +6 -7
  179. package/lib/util/shape.js.map +1 -1
  180. package/lib/util/string.js +4 -5
  181. package/lib/util/string.js.map +1 -1
  182. package/lib/util/style.js +4 -5
  183. package/lib/util/style.js.map +1 -1
  184. package/lib/util/svg2marker.js +2 -3
  185. package/lib/util/svg2marker.js.map +1 -1
  186. package/lib/util/text.d.ts +1 -1
  187. package/lib/util/text.js +4 -4
  188. package/lib/util/text.js.map +1 -1
  189. package/lib/util/throttle.js +1 -2
  190. package/lib/util/throttle.js.map +1 -1
  191. package/lib/util/time.js +6 -7
  192. package/lib/util/time.js.map +1 -1
  193. package/lib/util/timer.js +1 -2
  194. package/lib/util/timer.js.map +1 -1
  195. package/lib/util/transform.js +2 -3
  196. package/lib/util/transform.js.map +1 -1
  197. package/lib/util/transpose.js +1 -2
  198. package/lib/util/transpose.js.map +1 -1
  199. package/lib/util/traverse.js +1 -2
  200. package/lib/util/traverse.js.map +1 -1
  201. package/lib/util/visibility.js +3 -4
  202. package/lib/util/visibility.js.map +1 -1
  203. package/lib/util/wrap.js +1 -2
  204. package/lib/util/wrap.js.map +1 -1
  205. package/package.json +9 -8
  206. package/src/core/component.ts +5 -0
  207. package/src/core/types.ts +2 -2
  208. package/src/ui/legend/category/item.ts +12 -5
  209. package/src/ui/legend/continuous/utils.ts +4 -7
  210. package/src/ui/legend/continuous.ts +43 -9
  211. package/src/ui/marker/index.ts +2 -1
  212. package/src/ui/tag/index.ts +0 -5
  213. package/src/ui/timebar/controller.ts +6 -9
  214. package/src/ui/title/index.ts +5 -8
  215. package/src/ui/tooltip/index.ts +5 -1
  216. package/src/util/group-by.ts +4 -7
@@ -2,7 +2,7 @@ import { CustomEvent } from '@antv/g';
2
2
  import { Linear } from '@antv/scale';
3
3
  import { clamp, isUndefined } from '@antv/util';
4
4
  import { Component } from '../../core';
5
- import type { BaseStyleProps, DisplayObject, TextStyleProps } from '../../shapes';
5
+ import type { DisplayObject, TextStyleProps } from '../../shapes';
6
6
  import { Group } from '../../shapes';
7
7
  import { Point } from '../../types';
8
8
  import {
@@ -517,7 +517,7 @@ export class Continuous extends Component<ContinuousStyleProps> {
517
517
  else if (labelPosition === 'top') spacing = labelSpacing;
518
518
  }
519
519
 
520
- return { offset, spacing: labelSpacing, tickLength };
520
+ return { offset, spacing, tickLength };
521
521
  }
522
522
 
523
523
  private adjustLabel() {
@@ -570,11 +570,13 @@ export class Continuous extends Component<ContinuousStyleProps> {
570
570
  data.map(({ value }) => value),
571
571
  value
572
572
  );
573
- this.showIndicator((range[0] + range[1]) / 2, `${range[0]}-${range[1]}`);
573
+
574
+ const selection = this.getRealSelection(range);
575
+ this.showIndicator((range[0] + range[1]) / 2, `${selection[0]}-${selection[1]}`);
574
576
  this.dispatchIndicated(value, range);
575
577
  } else {
576
578
  const safetyValue = this.getTickValue(value);
577
- this.showIndicator(safetyValue);
579
+ this.showIndicator(safetyValue, `${this.getRealValue(safetyValue)}`);
578
580
  this.dispatchIndicated(safetyValue);
579
581
  }
580
582
  };
@@ -590,6 +592,7 @@ export class Continuous extends Component<ContinuousStyleProps> {
590
592
  const safeValue = clamp(value, min, max);
591
593
  const offset = this.getOffset(safeValue);
592
594
  const pos: Point = this.ifHorizontal([offset + x, y], [x, offset + y]);
595
+
593
596
  this.indicator.update({
594
597
  x: pos[0],
595
598
  y: pos[1],
@@ -686,9 +689,8 @@ export class Continuous extends Component<ContinuousStyleProps> {
686
689
 
687
690
  /**
688
691
  * 事件触发的位置对应的value值
689
- * @param limit {boolean} 我也忘了要干啥了
690
692
  */
691
- private getValueByCanvasPoint(e: any, limit: boolean = false) {
693
+ private getValueByCanvasPoint(e: any) {
692
694
  const { min, max } = this.range;
693
695
  const [x, y] = this.ribbon.node().getPosition();
694
696
  const startPos = this.ifHorizontal(x, y);
@@ -708,18 +710,50 @@ export class Continuous extends Component<ContinuousStyleProps> {
708
710
  return scale.map(value);
709
711
  }
710
712
 
713
+ private getRealSelection(range: number[]) {
714
+ const { max } = this.range;
715
+ const [start, end] = range;
716
+
717
+ return this.ifHorizontal([start, end], [max - end, max - start]);
718
+ }
719
+
720
+ private getRealValue(value: number) {
721
+ const { max } = this.range;
722
+
723
+ return this.ifHorizontal(value, max - value);
724
+ }
725
+
711
726
  private dispatchSelection() {
727
+ const selection = this.getRealSelection(this.selection);
728
+
712
729
  const evt = new CustomEvent('valuechange', {
713
730
  detail: {
714
- value: this.selection,
731
+ value: selection,
715
732
  },
716
733
  });
717
734
  this.dispatchEvent(evt as any);
718
735
  }
719
736
 
720
- private dispatchIndicated(value: number, range?: unknown) {
737
+ private dispatchIndicated(value: number, range?: number[]) {
738
+ const { max } = this.range;
739
+
740
+ const detail = this.ifHorizontal(
741
+ () => {
742
+ return {
743
+ value,
744
+ range,
745
+ };
746
+ },
747
+ () => {
748
+ return {
749
+ value: max - value,
750
+ range: range ? this.getRealSelection(range) : undefined,
751
+ };
752
+ }
753
+ );
754
+
721
755
  const evt = new CustomEvent('indicate', {
722
- detail: { value, range },
756
+ detail,
723
757
  });
724
758
  this.dispatchEvent(evt as any);
725
759
  }
@@ -44,7 +44,8 @@ function getType(symbol: MarkerStyleProps['symbol']): string | null {
44
44
 
45
45
  export class Marker extends Component<MarkerStyleProps> {
46
46
  public render(attributes: Required<MarkerStyleProps>, container: Group) {
47
- const { symbol, size = 16, x = 0, y = 0, transform, transformOrigin, ...style } = attributes;
47
+ const { x = 0, y = 0 } = attributes;
48
+ const { symbol, size = 16, ...style } = this.getSubShapeStyle(attributes);
48
49
 
49
50
  const type = getType(symbol);
50
51
  ifShow(!!type, select(container), (group) => {
@@ -61,15 +61,10 @@ export class Tag extends Component<TagStyleProps> {
61
61
  .style('zIndex', 0)
62
62
  .node();
63
63
  const markerStyle = marker || { symbol: 'triangle', size: 0 };
64
- // @ts-ignore
65
64
  const markerShape = maybeAppend(group, '.tag-marker', () => new Marker({ style: markerStyle }))
66
65
  .attr('className', 'tag-marker')
67
- .call((selection) => {
68
- (selection.node() as Marker).clear();
69
- })
70
66
  .update(markerStyle)
71
67
  .node() as Marker;
72
-
73
68
  const { x, y } = getTextPosition(markerShape, spacing);
74
69
 
75
70
  select(group)
@@ -64,15 +64,12 @@ export class Controller extends Component<ControllerStyleProps> {
64
64
  padding: [, right, , left],
65
65
  } = this;
66
66
 
67
- const components = functions.reduce(
68
- (prev, curr) => {
69
- if (prev.length && curr.length) {
70
- return prev.concat('split', ...curr);
71
- }
72
- return prev.concat(...curr);
73
- },
74
- [] as (keyof typeof componentsMap)[]
75
- );
67
+ const components = functions.reduce((prev, curr) => {
68
+ if (prev.length && curr.length) {
69
+ return prev.concat('split', ...curr);
70
+ }
71
+ return prev.concat(...curr);
72
+ }, [] as (keyof typeof componentsMap)[]);
76
73
 
77
74
  const componentsWidth = components.length * (iconSize + iconSpacing) - iconSpacing;
78
75
  const xOffset =
@@ -73,14 +73,11 @@ export function getBBox(title: Title, content: DisplayObject): DOMRect {
73
73
  }
74
74
 
75
75
  function mayApplyStyle(el: Selection, style: any) {
76
- const finalStyle = Object.entries(style).reduce(
77
- (acc, [key, value]) => {
78
- const currAttr = el.node().attr(key);
79
- if (!currAttr) acc[key] = value;
80
- return acc;
81
- },
82
- {} as Record<string, any>
83
- );
76
+ const finalStyle = Object.entries(style).reduce((acc, [key, value]) => {
77
+ const currAttr = el.node().attr(key);
78
+ if (!currAttr) acc[key] = value;
79
+ return acc;
80
+ }, {} as Record<string, any>);
84
81
 
85
82
  el.styles(finalStyle);
86
83
  }
@@ -151,7 +151,11 @@ export class Tooltip extends Component<TooltipStyleProps> {
151
151
  const itemsElements = this.HTMLTooltipItemsElements;
152
152
  const ul = document.createElement('ul');
153
153
  ul.className = CLASS_NAME.LIST;
154
- ul.replaceChildren(...itemsElements);
154
+ if (ul.replaceChildren) ul.replaceChildren(...itemsElements);
155
+ else {
156
+ ul.innerHTML = '';
157
+ ul.append(...itemsElements);
158
+ }
155
159
  const list = this.element.querySelector(`.${CLASS_NAME.LIST}`);
156
160
  if (list) list.replaceWith(ul);
157
161
  else container.appendChild(ul);
@@ -1,9 +1,6 @@
1
1
  export function groupBy<T extends { [key: string]: any }>(source: T[], by: keyof T) {
2
- return source.reduce(
3
- (acc, curr) => {
4
- (acc[curr[by]] = acc[curr[by]] || []).push(curr);
5
- return acc;
6
- },
7
- {} as { [key in T[keyof T]]: T[] }
8
- );
2
+ return source.reduce((acc, curr) => {
3
+ (acc[curr[by]] = acc[curr[by]] || []).push(curr);
4
+ return acc;
5
+ }, {} as { [key in T[keyof T]]: T[] });
9
6
  }