@antv/g2 5.0.11 → 5.0.12

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 (239) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/g2-lite.min.js +3 -3
  3. package/dist/g2.min.js +3 -3
  4. package/esm/api/mark/index.d.ts +3 -1
  5. package/esm/api/mark/index.js +2 -1
  6. package/esm/api/mark/index.js.map +1 -1
  7. package/esm/api/mark/mark.d.ts +7 -1
  8. package/esm/api/mark/mark.js +9 -0
  9. package/esm/api/mark/mark.js.map +1 -1
  10. package/esm/api/utils.js +1 -0
  11. package/esm/api/utils.js.map +1 -1
  12. package/esm/component/axis.js +2 -1
  13. package/esm/component/axis.js.map +1 -1
  14. package/esm/component/scrollbar.js +8 -5
  15. package/esm/component/scrollbar.js.map +1 -1
  16. package/esm/composition/facetRect.js +13 -17
  17. package/esm/composition/facetRect.js.map +1 -1
  18. package/esm/data/index.d.ts +2 -0
  19. package/esm/data/index.js +1 -0
  20. package/esm/data/index.js.map +1 -1
  21. package/esm/data/utils/venn/circleintersection.d.ts +33 -0
  22. package/esm/data/utils/venn/circleintersection.js +192 -0
  23. package/esm/data/utils/venn/circleintersection.js.map +1 -0
  24. package/esm/data/utils/venn/diagram.d.ts +2 -0
  25. package/esm/data/utils/venn/diagram.js +44 -0
  26. package/esm/data/utils/venn/diagram.js.map +1 -0
  27. package/esm/data/utils/venn/index.d.ts +5 -0
  28. package/esm/data/utils/venn/index.js +6 -0
  29. package/esm/data/utils/venn/index.js.map +1 -0
  30. package/esm/data/utils/venn/layout.d.ts +27 -0
  31. package/esm/data/utils/venn/layout.js +607 -0
  32. package/esm/data/utils/venn/layout.js.map +1 -0
  33. package/esm/data/venn.d.ts +7 -0
  34. package/esm/data/venn.js +34 -0
  35. package/esm/data/venn.js.map +1 -0
  36. package/esm/interaction/brushAxisHighlight.d.ts +5 -3
  37. package/esm/interaction/brushAxisHighlight.js +126 -12
  38. package/esm/interaction/brushAxisHighlight.js.map +1 -1
  39. package/esm/interaction/brushHighlight.js +6 -5
  40. package/esm/interaction/brushHighlight.js.map +1 -1
  41. package/esm/interaction/elementHighlight.d.ts +2 -2
  42. package/esm/interaction/elementHighlight.js +40 -6
  43. package/esm/interaction/elementHighlight.js.map +1 -1
  44. package/esm/interaction/elementHighlightByColor.d.ts +1 -1
  45. package/esm/interaction/elementHighlightByX.d.ts +1 -1
  46. package/esm/interaction/elementSelect.d.ts +2 -2
  47. package/esm/interaction/elementSelect.js +42 -13
  48. package/esm/interaction/elementSelect.js.map +1 -1
  49. package/esm/interaction/elementSelectByColor.d.ts +1 -1
  50. package/esm/interaction/elementSelectByX.d.ts +1 -1
  51. package/esm/interaction/index.d.ts +1 -0
  52. package/esm/interaction/index.js +1 -0
  53. package/esm/interaction/index.js.map +1 -1
  54. package/esm/interaction/legendFilter.js +42 -13
  55. package/esm/interaction/legendFilter.js.map +1 -1
  56. package/esm/interaction/legendHighlight.d.ts +1 -1
  57. package/esm/interaction/legendHighlight.js +53 -15
  58. package/esm/interaction/legendHighlight.js.map +1 -1
  59. package/esm/interaction/scrollbarFilter.d.ts +2 -0
  60. package/esm/interaction/scrollbarFilter.js +25 -0
  61. package/esm/interaction/scrollbarFilter.js.map +1 -0
  62. package/esm/interaction/sliderFilter.d.ts +1 -1
  63. package/esm/interaction/sliderFilter.js +75 -19
  64. package/esm/interaction/sliderFilter.js.map +1 -1
  65. package/esm/interaction/tooltip.js +2 -2
  66. package/esm/interaction/tooltip.js.map +1 -1
  67. package/esm/interaction/utils.d.ts +1 -0
  68. package/esm/interaction/utils.js +3 -0
  69. package/esm/interaction/utils.js.map +1 -1
  70. package/esm/mark/area.js +6 -2
  71. package/esm/mark/area.js.map +1 -1
  72. package/esm/runtime/plot.js +1 -0
  73. package/esm/runtime/plot.js.map +1 -1
  74. package/esm/runtime/scale.js +30 -3
  75. package/esm/runtime/scale.js.map +1 -1
  76. package/esm/runtime/transform.js +12 -9
  77. package/esm/runtime/transform.js.map +1 -1
  78. package/esm/shape/index.d.ts +2 -0
  79. package/esm/shape/index.js +1 -0
  80. package/esm/shape/index.js.map +1 -1
  81. package/esm/shape/interval/color.d.ts +8 -0
  82. package/esm/shape/interval/color.js +19 -8
  83. package/esm/shape/interval/color.js.map +1 -1
  84. package/esm/shape/interval/rect.d.ts +10 -1
  85. package/esm/shape/interval/rect.js.map +1 -1
  86. package/esm/shape/line/trail.d.ts +3 -0
  87. package/esm/shape/line/trail.js +74 -0
  88. package/esm/shape/line/trail.js.map +1 -0
  89. package/esm/shape/path/color.js +5 -3
  90. package/esm/shape/path/color.js.map +1 -1
  91. package/esm/spec/dataTransform.d.ts +24 -2
  92. package/esm/stdlib/index.js +5 -5
  93. package/esm/stdlib/index.js.map +1 -1
  94. package/esm/utils/number.d.ts +4 -0
  95. package/esm/utils/number.js +7 -0
  96. package/esm/utils/number.js.map +1 -0
  97. package/esm/utils/scale.d.ts +2 -1
  98. package/esm/utils/scale.js +30 -11
  99. package/esm/utils/scale.js.map +1 -1
  100. package/esm/utils/vector.d.ts +1 -0
  101. package/esm/utils/vector.js +3 -0
  102. package/esm/utils/vector.js.map +1 -1
  103. package/lib/api/mark/index.d.ts +3 -1
  104. package/lib/api/mark/index.js +1 -0
  105. package/lib/api/mark/index.js.map +1 -1
  106. package/lib/api/mark/mark.d.ts +7 -1
  107. package/lib/api/mark/mark.js +10 -1
  108. package/lib/api/mark/mark.js.map +1 -1
  109. package/lib/api/utils.js +1 -0
  110. package/lib/api/utils.js.map +1 -1
  111. package/lib/component/axis.js +2 -1
  112. package/lib/component/axis.js.map +1 -1
  113. package/lib/component/scrollbar.js +8 -5
  114. package/lib/component/scrollbar.js.map +1 -1
  115. package/lib/composition/facetRect.js +12 -16
  116. package/lib/composition/facetRect.js.map +1 -1
  117. package/lib/data/index.d.ts +2 -0
  118. package/lib/data/index.js +3 -1
  119. package/lib/data/index.js.map +1 -1
  120. package/lib/data/utils/venn/circleintersection.d.ts +33 -0
  121. package/lib/data/utils/venn/circleintersection.js +202 -0
  122. package/lib/data/utils/venn/circleintersection.js.map +1 -0
  123. package/lib/data/utils/venn/diagram.d.ts +2 -0
  124. package/lib/data/utils/venn/diagram.js +48 -0
  125. package/lib/data/utils/venn/diagram.js.map +1 -0
  126. package/lib/data/utils/venn/index.d.ts +5 -0
  127. package/lib/data/utils/venn/index.js +12 -0
  128. package/lib/data/utils/venn/index.js.map +1 -0
  129. package/lib/data/utils/venn/layout.d.ts +27 -0
  130. package/lib/data/utils/venn/layout.js +620 -0
  131. package/lib/data/utils/venn/layout.js.map +1 -0
  132. package/lib/data/venn.d.ts +7 -0
  133. package/lib/data/venn.js +38 -0
  134. package/lib/data/venn.js.map +1 -0
  135. package/lib/interaction/brushAxisHighlight.d.ts +5 -3
  136. package/lib/interaction/brushAxisHighlight.js +126 -12
  137. package/lib/interaction/brushAxisHighlight.js.map +1 -1
  138. package/lib/interaction/brushHighlight.js +6 -5
  139. package/lib/interaction/brushHighlight.js.map +1 -1
  140. package/lib/interaction/elementHighlight.d.ts +2 -2
  141. package/lib/interaction/elementHighlight.js +39 -5
  142. package/lib/interaction/elementHighlight.js.map +1 -1
  143. package/lib/interaction/elementHighlightByColor.d.ts +1 -1
  144. package/lib/interaction/elementHighlightByX.d.ts +1 -1
  145. package/lib/interaction/elementSelect.d.ts +2 -2
  146. package/lib/interaction/elementSelect.js +41 -12
  147. package/lib/interaction/elementSelect.js.map +1 -1
  148. package/lib/interaction/elementSelectByColor.d.ts +1 -1
  149. package/lib/interaction/elementSelectByX.d.ts +1 -1
  150. package/lib/interaction/index.d.ts +1 -0
  151. package/lib/interaction/index.js +3 -1
  152. package/lib/interaction/index.js.map +1 -1
  153. package/lib/interaction/legendFilter.js +42 -13
  154. package/lib/interaction/legendFilter.js.map +1 -1
  155. package/lib/interaction/legendHighlight.d.ts +1 -1
  156. package/lib/interaction/legendHighlight.js +53 -15
  157. package/lib/interaction/legendHighlight.js.map +1 -1
  158. package/lib/interaction/scrollbarFilter.d.ts +2 -0
  159. package/lib/interaction/scrollbarFilter.js +29 -0
  160. package/lib/interaction/scrollbarFilter.js.map +1 -0
  161. package/lib/interaction/sliderFilter.d.ts +1 -1
  162. package/lib/interaction/sliderFilter.js +73 -17
  163. package/lib/interaction/sliderFilter.js.map +1 -1
  164. package/lib/interaction/tooltip.js +1 -1
  165. package/lib/interaction/tooltip.js.map +1 -1
  166. package/lib/interaction/utils.d.ts +1 -0
  167. package/lib/interaction/utils.js +5 -1
  168. package/lib/interaction/utils.js.map +1 -1
  169. package/lib/mark/area.js +6 -2
  170. package/lib/mark/area.js.map +1 -1
  171. package/lib/runtime/plot.js +1 -0
  172. package/lib/runtime/plot.js.map +1 -1
  173. package/lib/runtime/scale.js +29 -2
  174. package/lib/runtime/scale.js.map +1 -1
  175. package/lib/runtime/transform.js +12 -9
  176. package/lib/runtime/transform.js.map +1 -1
  177. package/lib/shape/index.d.ts +2 -0
  178. package/lib/shape/index.js +4 -2
  179. package/lib/shape/index.js.map +1 -1
  180. package/lib/shape/interval/color.d.ts +8 -0
  181. package/lib/shape/interval/color.js +19 -8
  182. package/lib/shape/interval/color.js.map +1 -1
  183. package/lib/shape/interval/rect.d.ts +10 -1
  184. package/lib/shape/interval/rect.js.map +1 -1
  185. package/lib/shape/line/trail.d.ts +3 -0
  186. package/lib/shape/line/trail.js +78 -0
  187. package/lib/shape/line/trail.js.map +1 -0
  188. package/lib/shape/path/color.js +5 -3
  189. package/lib/shape/path/color.js.map +1 -1
  190. package/lib/spec/dataTransform.d.ts +24 -2
  191. package/lib/stdlib/index.js +2 -2
  192. package/lib/stdlib/index.js.map +1 -1
  193. package/lib/utils/number.d.ts +4 -0
  194. package/lib/utils/number.js +11 -0
  195. package/lib/utils/number.js.map +1 -0
  196. package/lib/utils/scale.d.ts +2 -1
  197. package/lib/utils/scale.js +32 -12
  198. package/lib/utils/scale.js.map +1 -1
  199. package/lib/utils/vector.d.ts +1 -0
  200. package/lib/utils/vector.js +5 -1
  201. package/lib/utils/vector.js.map +1 -1
  202. package/package.json +2 -1
  203. package/src/api/mark/index.ts +3 -0
  204. package/src/api/mark/mark.ts +12 -0
  205. package/src/api/utils.ts +1 -0
  206. package/src/component/axis.ts +1 -0
  207. package/src/component/scrollbar.ts +11 -8
  208. package/src/composition/facetRect.ts +14 -17
  209. package/src/data/index.ts +2 -0
  210. package/src/data/utils/venn/circleintersection.ts +235 -0
  211. package/src/data/utils/venn/diagram.ts +47 -0
  212. package/src/data/utils/venn/index.ts +5 -0
  213. package/src/data/utils/venn/layout.ts +769 -0
  214. package/src/data/venn.ts +58 -0
  215. package/src/interaction/brushAxisHighlight.ts +130 -11
  216. package/src/interaction/brushHighlight.ts +6 -4
  217. package/src/interaction/elementHighlight.ts +39 -3
  218. package/src/interaction/elementSelect.ts +48 -10
  219. package/src/interaction/index.ts +1 -0
  220. package/src/interaction/legendFilter.ts +46 -13
  221. package/src/interaction/legendHighlight.ts +55 -14
  222. package/src/interaction/scrollbarFilter.ts +32 -0
  223. package/src/interaction/sliderFilter.ts +108 -28
  224. package/src/interaction/tooltip.ts +2 -5
  225. package/src/interaction/utils.ts +6 -0
  226. package/src/mark/area.ts +5 -2
  227. package/src/runtime/plot.ts +1 -0
  228. package/src/runtime/scale.ts +44 -5
  229. package/src/runtime/transform.ts +18 -9
  230. package/src/shape/index.ts +4 -0
  231. package/src/shape/interval/color.ts +29 -5
  232. package/src/shape/interval/rect.ts +10 -1
  233. package/src/shape/line/trail.ts +80 -0
  234. package/src/shape/path/color.ts +10 -6
  235. package/src/spec/dataTransform.ts +25 -0
  236. package/src/stdlib/index.ts +6 -0
  237. package/src/utils/number.ts +6 -0
  238. package/src/utils/scale.ts +29 -10
  239. package/src/utils/vector.ts +4 -0
@@ -10,7 +10,7 @@ import {
10
10
  import { markerOf, labelOf, itemsOf, legendsOf, dataOf } from './legendFilter';
11
11
 
12
12
  export function LegendHighlight() {
13
- return (context) => {
13
+ return (context, _, emitter) => {
14
14
  const { container, view, options } = context;
15
15
  const legends = legendsOf(container);
16
16
  const elements = selectG2Elements(container);
@@ -25,6 +25,7 @@ export function LegendHighlight() {
25
25
  };
26
26
  const markState = mergeState(options, ['active', 'inactive']);
27
27
  const valueof = createValueof(elements, createDatumof(view));
28
+ const destroys = [];
28
29
 
29
30
  // Bind events for each legend.
30
31
  for (const legend of legends) {
@@ -62,39 +63,79 @@ export function LegendHighlight() {
62
63
  }
63
64
  }
64
65
  };
66
+ const highlightItem = (event, item) => {
67
+ // Update UI.
68
+ const value = datumOf(item);
69
+ const elementSet = new Set(elementGroup.get(value));
70
+ for (const e of elements) {
71
+ if (elementSet.has(e)) setState(e, 'active');
72
+ else setState(e, 'inactive');
73
+ }
74
+ updateLegendState(item);
75
+
76
+ // Emit events.
77
+ const { nativeEvent = true } = event;
78
+ if (!nativeEvent) return;
79
+ emitter.emit('legend:highlight', {
80
+ ...event,
81
+ nativeEvent,
82
+ data: { channel, value },
83
+ });
84
+ };
65
85
 
66
86
  const itemPointerover = new Map();
67
87
 
68
88
  // Add listener for the legend items.
69
89
  for (const item of items) {
70
- const pointerover = () => {
71
- const value = datumOf(item);
72
- const elementSet = new Set(elementGroup.get(value));
73
- for (const e of elements) {
74
- if (elementSet.has(e)) setState(e, 'active');
75
- else setState(e, 'inactive');
76
- }
77
- updateLegendState(item);
90
+ const pointerover = (event) => {
91
+ highlightItem(event, item);
78
92
  };
79
93
  item.addEventListener('pointerover', pointerover);
80
94
  itemPointerover.set(item, pointerover);
81
95
  }
82
96
 
83
97
  // Add listener for the legend group.
84
- const pointerleave = () => {
85
- for (const e of elements) {
86
- removeState(e, 'inactive', 'active');
87
- }
98
+ const pointerleave = (event) => {
99
+ for (const e of elements) removeState(e, 'inactive', 'active');
88
100
  updateLegendState(null);
101
+
102
+ // Emit events.
103
+ const { nativeEvent = true } = event;
104
+ if (!nativeEvent) return;
105
+ emitter.emit('legend:unhighlight', { nativeEvent });
106
+ };
107
+
108
+ const onHighlight = (event) => {
109
+ const { nativeEvent, data } = event;
110
+ if (nativeEvent) return;
111
+ const { channel: specifiedChannel, value } = data;
112
+ if (specifiedChannel !== channel) return;
113
+ const item = items.find((d) => datumOf(d) === value);
114
+ if (!item) return;
115
+ highlightItem({ nativeEvent: false }, item);
89
116
  };
117
+
118
+ const onUnHighlight = (event) => {
119
+ const { nativeEvent } = event;
120
+ if (nativeEvent) return;
121
+ pointerleave({ nativeEvent: false });
122
+ };
123
+
90
124
  legend.addEventListener('pointerleave', pointerleave);
125
+ emitter.on('legend:highlight', onHighlight);
126
+ emitter.on('legend:unhighlight', onUnHighlight);
91
127
 
92
- return () => {
128
+ const destroy = () => {
93
129
  legend.removeEventListener(pointerleave);
130
+ emitter.off('legend:highlight', onHighlight);
131
+ emitter.off('legend:unhighlight', onUnHighlight);
94
132
  for (const [item, pointerover] of itemPointerover) {
95
133
  item.removeEventListener(pointerover);
96
134
  }
97
135
  };
136
+ destroys.push(destroy);
98
137
  }
138
+
139
+ return () => destroys.forEach((d) => d());
99
140
  };
100
141
  }
@@ -0,0 +1,32 @@
1
+ import { SliderFilter } from './sliderFilter';
2
+
3
+ export const SCROLLBAR_CLASS_NAME = 'g2-scrollbar';
4
+
5
+ export function ScrollbarFilter(options: any = {}) {
6
+ return (context, _, emitter) => {
7
+ const { view, container } = context;
8
+ const scrollbars = container.getElementsByClassName(SCROLLBAR_CLASS_NAME);
9
+ if (!scrollbars.length) return () => {};
10
+ const { scale } = view;
11
+ const { x: scaleX, y: scaleY } = scale;
12
+ const channelDomain = {
13
+ x: scaleX.getOptions().domain,
14
+ y: scaleY.getOptions().domain,
15
+ };
16
+ scaleX.update({
17
+ domain: scaleX.getOptions().expectedDomain,
18
+ });
19
+ scaleY.update({
20
+ domain: scaleY.getOptions().expectedDomain,
21
+ });
22
+ const interaction = SliderFilter({
23
+ ...options,
24
+ channelDomain,
25
+ className: SCROLLBAR_CLASS_NAME,
26
+ prefix: 'scrollbar',
27
+ hasState: true,
28
+ setValue: (component, values) => component.setValue(values[0]),
29
+ });
30
+ return interaction(context, _, emitter);
31
+ };
32
+ }
@@ -1,10 +1,11 @@
1
- import { deepMix, throttle } from '@antv/util';
1
+ import { deepMix, throttle, upperFirst } from '@antv/util';
2
+ import { CustomEvent } from '@antv/g';
2
3
  import { isTranspose } from '../utils/coordinate';
3
- import { invert, domainOf } from '../utils/scale';
4
+ import { invert, domainOf, abstractOf } from '../utils/scale';
4
5
 
5
6
  export const SLIDER_CLASS_NAME = 'slider';
6
7
 
7
- function filterDataByDomain(options, scaleOptions) {
8
+ function filterDataByDomain(options, scaleOptions, prefix, hasState = false) {
8
9
  const { marks } = options;
9
10
  const newMarks = marks.map((mark) =>
10
11
  deepMix(
@@ -19,9 +20,13 @@ function filterDataByDomain(options, scaleOptions) {
19
20
  {
20
21
  scale: scaleOptions,
21
22
  // Don't rerender sliders.
22
- slider: {
23
- ...(mark.slider.x && { x: { preserve: true } }),
24
- ...(mark.slider.y && { y: { preserve: true } }),
23
+ [prefix]: {
24
+ ...(mark[prefix].x && {
25
+ x: { preserve: true, ...(hasState && { ratio: null }) },
26
+ }),
27
+ ...(mark[prefix].y && {
28
+ y: { preserve: true, ...(hasState && { ratio: null }) },
29
+ }),
25
30
  },
26
31
  animate: false,
27
32
  },
@@ -45,17 +50,26 @@ function abstractValue(values, scale, reverse) {
45
50
  return domainOf(scale, [d0, d1]);
46
51
  }
47
52
 
53
+ function extentOf(domain) {
54
+ return [domain[0], domain[domain.length - 1]];
55
+ }
56
+
48
57
  /**
49
58
  * @todo Support click to reset after fix click and dragend conflict.
50
59
  */
51
60
  export function SliderFilter({
61
+ channelDomain,
62
+ className = SLIDER_CLASS_NAME,
63
+ prefix = 'slider',
64
+ setValue = (component, values) => component.setValues(values),
65
+ hasState = false,
52
66
  wait = 50,
53
67
  leading = true,
54
68
  trailing = false,
55
69
  }: any) {
56
- return (context) => {
70
+ return (context, _, emitter) => {
57
71
  const { container, view, options, update } = context;
58
- const sliders = container.getElementsByClassName(SLIDER_CLASS_NAME);
72
+ const sliders = container.getElementsByClassName(className);
59
73
  if (!sliders.length) return () => {};
60
74
 
61
75
  let filtering = false;
@@ -71,41 +85,80 @@ export function SliderFilter({
71
85
  };
72
86
 
73
87
  const sliderHandler = new Map();
88
+ const emitHandlers = new Set<[string, (event: any) => void]>();
74
89
 
75
90
  // Store current domain of x and y scale.
76
- const channelDomain = {
77
- x: scaleX.getOptions().domain,
78
- y: scaleY.getOptions().domain,
79
- };
91
+ if (!channelDomain) {
92
+ channelDomain = {
93
+ x: scaleX.getOptions().domain,
94
+ y: scaleY.getOptions().domain,
95
+ };
96
+ }
80
97
 
81
98
  for (const slider of sliders) {
82
99
  const { orientation } = slider.attributes;
100
+ const [channel0, channel1] = channelOf(orientation);
101
+ const eventName = `${prefix}${upperFirst(channel0)}:filter`;
102
+ const isX = channel0 === 'x';
103
+ const { ratio: ratioX } = scaleX.getOptions();
104
+ const { ratio: ratioY } = scaleY.getOptions();
105
+ const domainsOf = (event) => {
106
+ // From abstract values.
107
+ if (event.data) {
108
+ const { selection } = event.data;
109
+ const [X = extentOf(channelDomain.x), Y = extentOf(channelDomain.y)] =
110
+ selection;
111
+ return isX
112
+ ? [domainOf(scaleX, X, ratioX), domainOf(scaleY, Y, ratioY)]
113
+ : [domainOf(scaleY, Y, ratioY), domainOf(scaleX, X, ratioX)];
114
+ }
115
+
116
+ // From visual values.
117
+ const { value: values } = event.detail;
118
+ const scale0 = scale[channel0];
119
+ const domain0 = abstractValue(
120
+ values,
121
+ scale0,
122
+ transposed && orientation === 'horizontal',
123
+ );
124
+ const domain1 = channelDomain[channel1];
125
+ return [domain0, domain1];
126
+ };
83
127
 
84
128
  const onValueChange = throttle(
85
129
  async (event) => {
86
- const { value: values } = event.detail;
87
130
  if (filtering) return;
88
131
  filtering = true;
89
132
 
90
- const [channel0, channel1] = channelOf(orientation);
133
+ const { nativeEvent = true } = event;
91
134
 
92
- // Update domain of the current channel.
93
- const scale0 = scale[channel0];
94
- const domain0 = abstractValue(
95
- values,
96
- scale0,
97
- transposed && orientation === 'horizontal',
98
- );
135
+ // Get and update domain.
136
+ const [domain0, domain1] = domainsOf(event);
99
137
  channelDomain[channel0] = domain0;
100
-
101
- // Get domain of the other channel.
102
- const domain1 = channelDomain[channel1];
138
+ channelDomain[channel1] = domain1;
103
139
 
104
140
  // Filter data.
105
- const newOptions = filterDataByDomain(options, {
106
- [channel0]: { domain: domain0 },
107
- [channel1]: { domain: domain1 },
108
- });
141
+ const newOptions = filterDataByDomain(
142
+ options,
143
+ {
144
+ [channel0]: { domain: domain0 },
145
+ [channel1]: { domain: domain1 },
146
+ },
147
+ prefix,
148
+ hasState,
149
+ );
150
+
151
+ if (nativeEvent) {
152
+ // Emit events.
153
+ const X = isX ? domain0 : domain1;
154
+ const Y = isX ? domain1 : domain0;
155
+ emitter.emit(eventName, {
156
+ ...event,
157
+ nativeEvent,
158
+ data: { selection: [extentOf(X), extentOf(Y)] },
159
+ });
160
+ }
161
+
109
162
  await update(newOptions);
110
163
  filtering = false;
111
164
  },
@@ -113,14 +166,41 @@ export function SliderFilter({
113
166
  { leading, trailing },
114
167
  );
115
168
 
169
+ const emitHandler = (event) => {
170
+ const { nativeEvent } = event;
171
+ if (nativeEvent) return;
172
+
173
+ const { data } = event;
174
+ const { selection } = data;
175
+ const [X, Y] = selection;
176
+
177
+ // Update data.
178
+ slider.dispatchEvent(
179
+ new CustomEvent('valuechange', {
180
+ data,
181
+ nativeEvent: false,
182
+ }),
183
+ );
184
+
185
+ // Update slider.
186
+ const V = isX ? abstractOf(X, scaleX) : abstractOf(Y, scaleY);
187
+ setValue(slider, V);
188
+ };
189
+
190
+ emitter.on(eventName, emitHandler);
191
+
116
192
  slider.addEventListener('valuechange', onValueChange);
117
193
  sliderHandler.set(slider, onValueChange);
194
+ emitHandlers.add([eventName, emitHandler]);
118
195
  }
119
196
 
120
197
  return () => {
121
198
  for (const [slider, handler] of sliderHandler) {
122
199
  slider.removeEventListener('valuechange', handler);
123
200
  }
201
+ for (const [name, handler] of emitHandlers) {
202
+ emitter.off(name, handler);
203
+ }
124
204
  };
125
205
  };
126
206
  }
@@ -15,6 +15,7 @@ import {
15
15
  mousePosition,
16
16
  selectFacetG2Elements,
17
17
  createDatumof,
18
+ selectElementByData,
18
19
  } from './utils';
19
20
  import { dataOf } from './event';
20
21
 
@@ -683,11 +684,7 @@ export function tooltip(
683
684
 
684
685
  const onTooltipShow = ({ nativeEvent, data }) => {
685
686
  if (nativeEvent) return;
686
- const element = elements.find((d) =>
687
- Object.entries(data.data).every(
688
- ([key, value]) => datum(d)[key] === value,
689
- ),
690
- );
687
+ const element = selectElementByData(elements, data.data, datum);
691
688
  if (!element) return;
692
689
  const bbox = element.getBBox();
693
690
  const { x, y, width, height } = bbox;
@@ -456,3 +456,9 @@ export function setCursor(root, cursor) {
456
456
  export function restoreCursor(root) {
457
457
  setCursor(root, 'default');
458
458
  }
459
+
460
+ export function selectElementByData(elements, data, datum) {
461
+ return elements.find((d) =>
462
+ Object.entries(data).every(([key, value]) => datum(d)[key] === value),
463
+ );
464
+ }
package/src/mark/area.ts CHANGED
@@ -39,20 +39,23 @@ export type AreaOptions = Omit<AreaMark, 'type'>;
39
39
  export const Area: MC<AreaOptions> = () => {
40
40
  return (index, scale, value, coordinate) => {
41
41
  const { x: X, y: Y, y1: Y1, series: S } = value;
42
+ const { x, y } = scale;
42
43
 
43
44
  // Group data by series field.
44
45
  const series = S ? Array.from(group(index, (i) => S[i]).values()) : [index];
45
46
  const I = series.map((group) => group[0]).filter((i) => i !== undefined);
46
47
 
47
48
  // A group of data corresponds to one area.
49
+ const xoffset = (x?.getBandWidth?.() || 0) / 2;
50
+ const yoffset = (y?.getBandWidth?.() || 0) / 2;
48
51
  const P = Array.from(series, (SI) => {
49
52
  const l = SI.length;
50
53
  const points = new Array(l * 2);
51
54
 
52
55
  for (let idx = 0; idx < SI.length; idx++) {
53
56
  const i = SI[idx];
54
- points[idx] = coordinate.map([+X[i], +Y[i]]); // y1
55
- points[l + idx] = coordinate.map([+X[i], +Y1[i]]); // y0
57
+ points[idx] = coordinate.map([+X[i] + xoffset, +Y[i] + yoffset]); // y1
58
+ points[l + idx] = coordinate.map([+X[i] + xoffset, +Y1[i] + yoffset]); // y0
56
59
  }
57
60
 
58
61
  return points;
@@ -1403,6 +1403,7 @@ function inferInteraction(
1403
1403
  // @todo Inferred by slider self.
1404
1404
  sliderFilter: true,
1405
1405
  legendFilter: true,
1406
+ scrollbarFilter: true,
1406
1407
  };
1407
1408
  const { interaction = {} } = view;
1408
1409
  return Object.entries(deepMix(defaults, interaction));
@@ -1,7 +1,7 @@
1
- import { createInterpolateValue } from '@antv/scale';
1
+ import { Linear, createInterpolateValue } from '@antv/scale';
2
2
  import { extent } from 'd3-array';
3
3
  import * as d3ScaleChromatic from 'd3-scale-chromatic';
4
- import { upperFirst } from '@antv/util';
4
+ import { max, upperFirst } from '@antv/util';
5
5
  import { firstOf, lastOf, unique } from '../utils/array';
6
6
  import { defined, identity, isStrictObject } from '../utils/helper';
7
7
  import { Primitive, G2Theme, G2MarkState, ChannelGroups } from './types/common';
@@ -26,12 +26,22 @@ export function inferScale(name, values, options, coordinates, theme, library) {
26
26
  const { guide = {} } = options;
27
27
  const type = inferScaleType(name, values, options);
28
28
  if (typeof type !== 'string') return options;
29
- const domain = inferScaleDomain(type, name, values, options);
29
+ const expectedDomain = inferScaleDomain(type, name, values, options);
30
+ const actualDomain = maybeRatio(type, expectedDomain, options);
30
31
  return {
31
32
  ...options,
32
33
  ...inferScaleOptions(type, name, values, options, coordinates),
33
- domain,
34
- range: inferScaleRange(type, name, values, options, domain, theme, library),
34
+ domain: actualDomain,
35
+ range: inferScaleRange(
36
+ type,
37
+ name,
38
+ values,
39
+ options,
40
+ actualDomain,
41
+ theme,
42
+ library,
43
+ ),
44
+ expectedDomain,
35
45
  guide,
36
46
  name,
37
47
  type,
@@ -144,6 +154,35 @@ function syncFacetsScaleByChannel(
144
154
  }
145
155
  }
146
156
 
157
+ function maybeRatio(
158
+ type: string,
159
+ domain: Primitive[],
160
+ options: G2ScaleOptions,
161
+ ) {
162
+ const { ratio } = options;
163
+ if (ratio === undefined || ratio === null) return domain;
164
+ if (isQuantitativeScale({ type })) {
165
+ return clampQuantitativeScale(domain as number[], ratio, type);
166
+ }
167
+ if (isDiscreteScale({ type })) return clampDiscreteScale(domain, ratio);
168
+ return domain;
169
+ }
170
+
171
+ function clampQuantitativeScale(domain: number[], ratio: number, type: string) {
172
+ const D = domain.map(Number);
173
+ const scale = new Linear({
174
+ domain: D,
175
+ range: [D[0], D[0] + (D[D.length - 1] - D[0]) * ratio],
176
+ });
177
+ if (type === 'time') return domain.map((d) => new Date(scale.map(d)));
178
+ return domain.map((d) => scale.map(d));
179
+ }
180
+
181
+ function clampDiscreteScale(domain: Primitive[], ratio: number) {
182
+ const index = Math.round(domain.length * ratio);
183
+ return domain.slice(0, index);
184
+ }
185
+
147
186
  function isQuantitativeScale(scale: G2ScaleOptions) {
148
187
  const { type } = scale;
149
188
  if (typeof type !== 'string') return false;
@@ -255,20 +255,29 @@ export function addGuideToScale(
255
255
  deepMix(mark, {
256
256
  scale: {
257
257
  ...Object.fromEntries(
258
- axisChannels.map((channel) => [
259
- channel,
260
- {
261
- guide: normalize(axis, channel),
262
- slider: normalize(slider, channel),
263
- scrollbar: normalize(scrollbar, channel),
264
- },
265
- ]),
258
+ axisChannels.map((channel) => {
259
+ const scrollbarOptions = normalize(scrollbar, channel);
260
+ return [
261
+ channel,
262
+ {
263
+ guide: normalize(axis, channel),
264
+ slider: normalize(slider, channel),
265
+ scrollbar: scrollbarOptions,
266
+ ...(scrollbarOptions && {
267
+ ratio:
268
+ scrollbarOptions.ratio === undefined
269
+ ? 0.5
270
+ : scrollbarOptions.ratio,
271
+ }),
272
+ },
273
+ ];
274
+ }),
266
275
  ),
267
276
  color: { guide: normalize(legend, 'color') },
268
277
  size: { guide: normalize(legend, 'size') },
269
278
  shape: { guide: normalize(legend, 'shape') },
270
279
  // fixme: opacity is conflict with DisplayObject.opacity
271
- // to be comfirm.
280
+ // to be confirm.
272
281
  opacity: { guide: normalize(legend, 'opacity') },
273
282
  },
274
283
  });
@@ -2,11 +2,14 @@ export { Rect } from './interval/rect';
2
2
  export { Hollow as HollowRect } from './interval/hollow';
3
3
  export { Funnel } from './interval/funnel';
4
4
  export { Pyramid } from './interval/pyramid';
5
+
5
6
  export { Line } from './line/line';
6
7
  export { Smooth } from './line/smooth';
7
8
  export { HV } from './line/hv';
8
9
  export { VH } from './line/vh';
9
10
  export { HVH } from './line/hvh';
11
+ export { Trail } from './line/trail';
12
+
10
13
  export { Bowtie } from './point/bowtie';
11
14
  export { Cross } from './point/cross';
12
15
  export { Diamond } from './point/diamond';
@@ -61,6 +64,7 @@ export type { SmoothOptions } from './line/smooth';
61
64
  export type { HVOptions } from './line/hv';
62
65
  export type { VHOptions } from './line/vh';
63
66
  export type { HVHOptions } from './line/hvh';
67
+ export type { TrailOptions } from './line/trail';
64
68
 
65
69
  export type { BowtieOptions } from './point/bowtie';
66
70
  export type { CrossOptions } from './point/cross';
@@ -3,7 +3,8 @@ import { arc } from 'd3-shape';
3
3
  import { Vector2, ShapeComponent as SC } from '../../runtime';
4
4
  import { isPolar, isHelix, isTranspose } from '../../utils/coordinate';
5
5
  import { select } from '../../utils/selection';
6
- import { sub } from '../.././utils/vector';
6
+ import { sub } from '../../utils/vector';
7
+ import { clamp } from '../../utils/number';
7
8
  import {
8
9
  applyStyle,
9
10
  getArcObject,
@@ -14,6 +15,14 @@ import {
14
15
 
15
16
  export type ColorOptions = {
16
17
  colorAttribute: 'fill' | 'stroke';
18
+ /**
19
+ * Minimum width of each interval.
20
+ */
21
+ minWidth?: number;
22
+ /**
23
+ * Maximum width of each interval.
24
+ */
25
+ maxWidth?: number;
17
26
  [key: string]: any;
18
27
  };
19
28
 
@@ -35,6 +44,8 @@ export function rect(
35
44
  radiusBottomRight = radius,
36
45
  radiusTopLeft = radius,
37
46
  radiusTopRight = radius,
47
+ minWidth = -Infinity,
48
+ maxWidth = Infinity,
38
49
  ...rest
39
50
  } = style;
40
51
  if (!isPolar(coordinate) && !isHelix(coordinate)) {
@@ -53,11 +64,20 @@ export function rect(
53
64
  const finalWidth = absWidth - (insetLeft + insetRight);
54
65
  const finalHeight = absHeight - (insetTop + insetBottom);
55
66
 
67
+ const clampWidth = tpShape
68
+ ? finalWidth
69
+ : clamp(finalWidth, minWidth, maxWidth);
70
+ const clampHeight = tpShape
71
+ ? clamp(finalHeight, minWidth, maxWidth)
72
+ : finalHeight;
73
+ const clampX = finalX - (clampWidth - finalWidth) / 2;
74
+ const clampY = finalY - (clampHeight - finalHeight) / 2;
75
+
56
76
  return select(new Rect({}))
57
- .style('x', finalX)
58
- .style('y', finalY)
59
- .style('width', finalWidth)
60
- .style('height', finalHeight)
77
+ .style('x', clampX)
78
+ .style('y', clampY)
79
+ .style('width', clampWidth)
80
+ .style('height', clampHeight)
61
81
  .style('radius', [
62
82
  radiusTopLeft,
63
83
  radiusTopRight,
@@ -128,6 +148,8 @@ export const Color: SC<ColorOptions> = (options) => {
128
148
  insetRight = inset,
129
149
  insetBottom = inset,
130
150
  insetTop = inset,
151
+ minWidth,
152
+ maxWidth,
131
153
  ...rest
132
154
  } = style;
133
155
  const { color = defaultColor, opacity } = value;
@@ -160,6 +182,8 @@ export const Color: SC<ColorOptions> = (options) => {
160
182
  insetRight,
161
183
  insetBottom,
162
184
  insetTop,
185
+ minWidth,
186
+ maxWidth,
163
187
  };
164
188
 
165
189
  return (
@@ -1,7 +1,16 @@
1
1
  import { ShapeComponent as SC } from '../../runtime';
2
2
  import { Color } from './color';
3
3
 
4
- export type RectOptions = Record<string, any>;
4
+ export type RectOptions = {
5
+ /**
6
+ * Minimum width of each interval.
7
+ */
8
+ minWidth?: number;
9
+ /**
10
+ * Maximum width of each interval.
11
+ */
12
+ maxWidth?: number;
13
+ };
5
14
 
6
15
  /**
7
16
  * Render rect in different coordinate and using color channel for stroke and fill attribute.