@antv/g2 5.0.10 → 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 (365) 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/chart.d.ts +1 -0
  5. package/esm/api/chart.js +5 -1
  6. package/esm/api/chart.js.map +1 -1
  7. package/esm/api/composition/geoPath.d.ts +1 -0
  8. package/esm/api/composition/geoPath.js +1 -0
  9. package/esm/api/composition/geoPath.js.map +1 -1
  10. package/esm/api/mark/index.d.ts +5 -1
  11. package/esm/api/mark/index.js +3 -1
  12. package/esm/api/mark/index.js.map +1 -1
  13. package/esm/api/mark/mark.d.ts +13 -1
  14. package/esm/api/mark/mark.js +18 -0
  15. package/esm/api/mark/mark.js.map +1 -1
  16. package/esm/api/node.d.ts +1 -0
  17. package/esm/api/node.js +5 -1
  18. package/esm/api/node.js.map +1 -1
  19. package/esm/api/utils.d.ts +1 -1
  20. package/esm/api/utils.js +11 -6
  21. package/esm/api/utils.js.map +1 -1
  22. package/esm/component/axis.js +2 -1
  23. package/esm/component/axis.js.map +1 -1
  24. package/esm/component/scrollbar.js +8 -5
  25. package/esm/component/scrollbar.js.map +1 -1
  26. package/esm/composition/facetRect.js +13 -17
  27. package/esm/composition/facetRect.js.map +1 -1
  28. package/esm/data/index.d.ts +2 -0
  29. package/esm/data/index.js +1 -0
  30. package/esm/data/index.js.map +1 -1
  31. package/esm/data/utils/venn/circleintersection.d.ts +33 -0
  32. package/esm/data/utils/venn/circleintersection.js +192 -0
  33. package/esm/data/utils/venn/circleintersection.js.map +1 -0
  34. package/esm/data/utils/venn/diagram.d.ts +2 -0
  35. package/esm/data/utils/venn/diagram.js +44 -0
  36. package/esm/data/utils/venn/diagram.js.map +1 -0
  37. package/esm/data/utils/venn/index.d.ts +5 -0
  38. package/esm/data/utils/venn/index.js +6 -0
  39. package/esm/data/utils/venn/index.js.map +1 -0
  40. package/esm/data/utils/venn/layout.d.ts +27 -0
  41. package/esm/data/utils/venn/layout.js +607 -0
  42. package/esm/data/utils/venn/layout.js.map +1 -0
  43. package/esm/data/venn.d.ts +7 -0
  44. package/esm/data/venn.js +34 -0
  45. package/esm/data/venn.js.map +1 -0
  46. package/esm/geo/geoPath.js +2 -1
  47. package/esm/geo/geoPath.js.map +1 -1
  48. package/esm/interaction/brushAxisHighlight.d.ts +5 -3
  49. package/esm/interaction/brushAxisHighlight.js +126 -12
  50. package/esm/interaction/brushAxisHighlight.js.map +1 -1
  51. package/esm/interaction/brushHighlight.js +6 -5
  52. package/esm/interaction/brushHighlight.js.map +1 -1
  53. package/esm/interaction/elementHighlight.d.ts +2 -2
  54. package/esm/interaction/elementHighlight.js +40 -6
  55. package/esm/interaction/elementHighlight.js.map +1 -1
  56. package/esm/interaction/elementHighlightByColor.d.ts +1 -1
  57. package/esm/interaction/elementHighlightByX.d.ts +1 -1
  58. package/esm/interaction/elementSelect.d.ts +2 -2
  59. package/esm/interaction/elementSelect.js +42 -13
  60. package/esm/interaction/elementSelect.js.map +1 -1
  61. package/esm/interaction/elementSelectByColor.d.ts +1 -1
  62. package/esm/interaction/elementSelectByX.d.ts +1 -1
  63. package/esm/interaction/event.js +5 -2
  64. package/esm/interaction/event.js.map +1 -1
  65. package/esm/interaction/index.d.ts +1 -0
  66. package/esm/interaction/index.js +1 -0
  67. package/esm/interaction/index.js.map +1 -1
  68. package/esm/interaction/legendFilter.js +42 -13
  69. package/esm/interaction/legendFilter.js.map +1 -1
  70. package/esm/interaction/legendHighlight.d.ts +1 -1
  71. package/esm/interaction/legendHighlight.js +53 -15
  72. package/esm/interaction/legendHighlight.js.map +1 -1
  73. package/esm/interaction/scrollbarFilter.d.ts +2 -0
  74. package/esm/interaction/scrollbarFilter.js +25 -0
  75. package/esm/interaction/scrollbarFilter.js.map +1 -0
  76. package/esm/interaction/sliderFilter.d.ts +1 -1
  77. package/esm/interaction/sliderFilter.js +75 -19
  78. package/esm/interaction/sliderFilter.js.map +1 -1
  79. package/esm/interaction/tooltip.js +2 -2
  80. package/esm/interaction/tooltip.js.map +1 -1
  81. package/esm/interaction/utils.d.ts +1 -0
  82. package/esm/interaction/utils.js +3 -0
  83. package/esm/interaction/utils.js.map +1 -1
  84. package/esm/mark/area.js +7 -3
  85. package/esm/mark/area.js.map +1 -1
  86. package/esm/mark/heatmap.d.ts +7 -0
  87. package/esm/mark/heatmap.js +36 -0
  88. package/esm/mark/heatmap.js.map +1 -0
  89. package/esm/mark/index.d.ts +2 -0
  90. package/esm/mark/index.js +1 -0
  91. package/esm/mark/index.js.map +1 -1
  92. package/esm/mark/line.js +1 -1
  93. package/esm/mark/line.js.map +1 -1
  94. package/esm/mark/text.js +0 -2
  95. package/esm/mark/text.js.map +1 -1
  96. package/esm/mark/utils.d.ts +1 -0
  97. package/esm/mark/utils.js +1 -1
  98. package/esm/mark/utils.js.map +1 -1
  99. package/esm/runtime/plot.js +13 -10
  100. package/esm/runtime/plot.js.map +1 -1
  101. package/esm/runtime/render.d.ts +2 -2
  102. package/esm/runtime/render.js +7 -3
  103. package/esm/runtime/render.js.map +1 -1
  104. package/esm/runtime/scale.js +41 -12
  105. package/esm/runtime/scale.js.map +1 -1
  106. package/esm/runtime/transform.js +12 -9
  107. package/esm/runtime/transform.js.map +1 -1
  108. package/esm/runtime/types/component.d.ts +2 -2
  109. package/esm/runtime/types/options.d.ts +6 -0
  110. package/esm/shape/heatmap/heatmap.d.ts +4 -0
  111. package/esm/shape/heatmap/heatmap.js +70 -0
  112. package/esm/shape/heatmap/heatmap.js.map +1 -0
  113. package/esm/shape/heatmap/renderer/gradient.d.ts +5 -0
  114. package/esm/shape/heatmap/renderer/gradient.js +13 -0
  115. package/esm/shape/heatmap/renderer/gradient.js.map +1 -0
  116. package/esm/shape/heatmap/renderer/index.d.ts +6 -0
  117. package/esm/shape/heatmap/renderer/index.js +122 -0
  118. package/esm/shape/heatmap/renderer/index.js.map +1 -0
  119. package/esm/shape/heatmap/renderer/types.d.ts +36 -0
  120. package/esm/shape/heatmap/renderer/types.js +2 -0
  121. package/esm/shape/heatmap/renderer/types.js.map +1 -0
  122. package/esm/shape/image/image.js +8 -3
  123. package/esm/shape/image/image.js.map +1 -1
  124. package/esm/shape/index.d.ts +4 -0
  125. package/esm/shape/index.js +2 -0
  126. package/esm/shape/index.js.map +1 -1
  127. package/esm/shape/interval/color.d.ts +8 -0
  128. package/esm/shape/interval/color.js +19 -8
  129. package/esm/shape/interval/color.js.map +1 -1
  130. package/esm/shape/interval/rect.d.ts +10 -1
  131. package/esm/shape/interval/rect.js.map +1 -1
  132. package/esm/shape/line/trail.d.ts +3 -0
  133. package/esm/shape/line/trail.js +74 -0
  134. package/esm/shape/line/trail.js.map +1 -0
  135. package/esm/shape/path/color.js +5 -3
  136. package/esm/shape/path/color.js.map +1 -1
  137. package/esm/spec/component.d.ts +1 -1
  138. package/esm/spec/composition.d.ts +9 -6
  139. package/esm/spec/dataTransform.d.ts +24 -2
  140. package/esm/spec/mark.d.ts +2 -1
  141. package/esm/stdlib/index.js +6 -6
  142. package/esm/stdlib/index.js.map +1 -1
  143. package/esm/utils/lru.d.ts +4 -0
  144. package/esm/utils/lru.js +18 -0
  145. package/esm/utils/lru.js.map +1 -0
  146. package/esm/utils/number.d.ts +4 -0
  147. package/esm/utils/number.js +7 -0
  148. package/esm/utils/number.js.map +1 -0
  149. package/esm/utils/scale.d.ts +2 -1
  150. package/esm/utils/scale.js +30 -11
  151. package/esm/utils/scale.js.map +1 -1
  152. package/esm/utils/vector.d.ts +1 -0
  153. package/esm/utils/vector.js +3 -0
  154. package/esm/utils/vector.js.map +1 -1
  155. package/lib/api/chart.d.ts +1 -0
  156. package/lib/api/chart.js +5 -1
  157. package/lib/api/chart.js.map +1 -1
  158. package/lib/api/composition/geoPath.d.ts +1 -0
  159. package/lib/api/composition/geoPath.js +1 -0
  160. package/lib/api/composition/geoPath.js.map +1 -1
  161. package/lib/api/mark/index.d.ts +5 -1
  162. package/lib/api/mark/index.js +2 -0
  163. package/lib/api/mark/index.js.map +1 -1
  164. package/lib/api/mark/mark.d.ts +13 -1
  165. package/lib/api/mark/mark.js +19 -1
  166. package/lib/api/mark/mark.js.map +1 -1
  167. package/lib/api/node.d.ts +1 -0
  168. package/lib/api/node.js +5 -1
  169. package/lib/api/node.js.map +1 -1
  170. package/lib/api/utils.d.ts +1 -1
  171. package/lib/api/utils.js +11 -6
  172. package/lib/api/utils.js.map +1 -1
  173. package/lib/component/axis.js +2 -1
  174. package/lib/component/axis.js.map +1 -1
  175. package/lib/component/scrollbar.js +8 -5
  176. package/lib/component/scrollbar.js.map +1 -1
  177. package/lib/composition/facetRect.js +12 -16
  178. package/lib/composition/facetRect.js.map +1 -1
  179. package/lib/data/index.d.ts +2 -0
  180. package/lib/data/index.js +3 -1
  181. package/lib/data/index.js.map +1 -1
  182. package/lib/data/utils/venn/circleintersection.d.ts +33 -0
  183. package/lib/data/utils/venn/circleintersection.js +202 -0
  184. package/lib/data/utils/venn/circleintersection.js.map +1 -0
  185. package/lib/data/utils/venn/diagram.d.ts +2 -0
  186. package/lib/data/utils/venn/diagram.js +48 -0
  187. package/lib/data/utils/venn/diagram.js.map +1 -0
  188. package/lib/data/utils/venn/index.d.ts +5 -0
  189. package/lib/data/utils/venn/index.js +12 -0
  190. package/lib/data/utils/venn/index.js.map +1 -0
  191. package/lib/data/utils/venn/layout.d.ts +27 -0
  192. package/lib/data/utils/venn/layout.js +620 -0
  193. package/lib/data/utils/venn/layout.js.map +1 -0
  194. package/lib/data/venn.d.ts +7 -0
  195. package/lib/data/venn.js +38 -0
  196. package/lib/data/venn.js.map +1 -0
  197. package/lib/geo/geoPath.js +2 -1
  198. package/lib/geo/geoPath.js.map +1 -1
  199. package/lib/interaction/brushAxisHighlight.d.ts +5 -3
  200. package/lib/interaction/brushAxisHighlight.js +126 -12
  201. package/lib/interaction/brushAxisHighlight.js.map +1 -1
  202. package/lib/interaction/brushHighlight.js +6 -5
  203. package/lib/interaction/brushHighlight.js.map +1 -1
  204. package/lib/interaction/elementHighlight.d.ts +2 -2
  205. package/lib/interaction/elementHighlight.js +39 -5
  206. package/lib/interaction/elementHighlight.js.map +1 -1
  207. package/lib/interaction/elementHighlightByColor.d.ts +1 -1
  208. package/lib/interaction/elementHighlightByX.d.ts +1 -1
  209. package/lib/interaction/elementSelect.d.ts +2 -2
  210. package/lib/interaction/elementSelect.js +41 -12
  211. package/lib/interaction/elementSelect.js.map +1 -1
  212. package/lib/interaction/elementSelectByColor.d.ts +1 -1
  213. package/lib/interaction/elementSelectByX.d.ts +1 -1
  214. package/lib/interaction/event.js +5 -2
  215. package/lib/interaction/event.js.map +1 -1
  216. package/lib/interaction/index.d.ts +1 -0
  217. package/lib/interaction/index.js +3 -1
  218. package/lib/interaction/index.js.map +1 -1
  219. package/lib/interaction/legendFilter.js +42 -13
  220. package/lib/interaction/legendFilter.js.map +1 -1
  221. package/lib/interaction/legendHighlight.d.ts +1 -1
  222. package/lib/interaction/legendHighlight.js +53 -15
  223. package/lib/interaction/legendHighlight.js.map +1 -1
  224. package/lib/interaction/scrollbarFilter.d.ts +2 -0
  225. package/lib/interaction/scrollbarFilter.js +29 -0
  226. package/lib/interaction/scrollbarFilter.js.map +1 -0
  227. package/lib/interaction/sliderFilter.d.ts +1 -1
  228. package/lib/interaction/sliderFilter.js +73 -17
  229. package/lib/interaction/sliderFilter.js.map +1 -1
  230. package/lib/interaction/tooltip.js +1 -1
  231. package/lib/interaction/tooltip.js.map +1 -1
  232. package/lib/interaction/utils.d.ts +1 -0
  233. package/lib/interaction/utils.js +5 -1
  234. package/lib/interaction/utils.js.map +1 -1
  235. package/lib/mark/area.js +7 -3
  236. package/lib/mark/area.js.map +1 -1
  237. package/lib/mark/heatmap.d.ts +7 -0
  238. package/lib/mark/heatmap.js +40 -0
  239. package/lib/mark/heatmap.js.map +1 -0
  240. package/lib/mark/index.d.ts +2 -0
  241. package/lib/mark/index.js +3 -1
  242. package/lib/mark/index.js.map +1 -1
  243. package/lib/mark/line.js +1 -1
  244. package/lib/mark/line.js.map +1 -1
  245. package/lib/mark/text.js +0 -2
  246. package/lib/mark/text.js.map +1 -1
  247. package/lib/mark/utils.d.ts +1 -0
  248. package/lib/mark/utils.js +2 -1
  249. package/lib/mark/utils.js.map +1 -1
  250. package/lib/runtime/plot.js +13 -10
  251. package/lib/runtime/plot.js.map +1 -1
  252. package/lib/runtime/render.d.ts +2 -2
  253. package/lib/runtime/render.js +7 -3
  254. package/lib/runtime/render.js.map +1 -1
  255. package/lib/runtime/scale.js +40 -11
  256. package/lib/runtime/scale.js.map +1 -1
  257. package/lib/runtime/transform.js +12 -9
  258. package/lib/runtime/transform.js.map +1 -1
  259. package/lib/runtime/types/component.d.ts +2 -2
  260. package/lib/runtime/types/options.d.ts +6 -0
  261. package/lib/shape/heatmap/heatmap.d.ts +4 -0
  262. package/lib/shape/heatmap/heatmap.js +74 -0
  263. package/lib/shape/heatmap/heatmap.js.map +1 -0
  264. package/lib/shape/heatmap/renderer/gradient.d.ts +5 -0
  265. package/lib/shape/heatmap/renderer/gradient.js +17 -0
  266. package/lib/shape/heatmap/renderer/gradient.js.map +1 -0
  267. package/lib/shape/heatmap/renderer/index.d.ts +6 -0
  268. package/lib/shape/heatmap/renderer/index.js +126 -0
  269. package/lib/shape/heatmap/renderer/index.js.map +1 -0
  270. package/lib/shape/heatmap/renderer/types.d.ts +36 -0
  271. package/lib/shape/heatmap/renderer/types.js +3 -0
  272. package/lib/shape/heatmap/renderer/types.js.map +1 -0
  273. package/lib/shape/image/image.js +8 -3
  274. package/lib/shape/image/image.js.map +1 -1
  275. package/lib/shape/index.d.ts +4 -0
  276. package/lib/shape/index.js +6 -2
  277. package/lib/shape/index.js.map +1 -1
  278. package/lib/shape/interval/color.d.ts +8 -0
  279. package/lib/shape/interval/color.js +19 -8
  280. package/lib/shape/interval/color.js.map +1 -1
  281. package/lib/shape/interval/rect.d.ts +10 -1
  282. package/lib/shape/interval/rect.js.map +1 -1
  283. package/lib/shape/line/trail.d.ts +3 -0
  284. package/lib/shape/line/trail.js +78 -0
  285. package/lib/shape/line/trail.js.map +1 -0
  286. package/lib/shape/path/color.js +5 -3
  287. package/lib/shape/path/color.js.map +1 -1
  288. package/lib/spec/component.d.ts +1 -1
  289. package/lib/spec/composition.d.ts +9 -6
  290. package/lib/spec/dataTransform.d.ts +24 -2
  291. package/lib/spec/mark.d.ts +2 -1
  292. package/lib/stdlib/index.js +2 -2
  293. package/lib/stdlib/index.js.map +1 -1
  294. package/lib/utils/lru.d.ts +4 -0
  295. package/lib/utils/lru.js +25 -0
  296. package/lib/utils/lru.js.map +1 -0
  297. package/lib/utils/number.d.ts +4 -0
  298. package/lib/utils/number.js +11 -0
  299. package/lib/utils/number.js.map +1 -0
  300. package/lib/utils/scale.d.ts +2 -1
  301. package/lib/utils/scale.js +32 -12
  302. package/lib/utils/scale.js.map +1 -1
  303. package/lib/utils/vector.d.ts +1 -0
  304. package/lib/utils/vector.js +5 -1
  305. package/lib/utils/vector.js.map +1 -1
  306. package/package.json +5 -1
  307. package/src/api/chart.ts +4 -1
  308. package/src/api/composition/geoPath.ts +2 -0
  309. package/src/api/mark/index.ts +6 -0
  310. package/src/api/mark/mark.ts +24 -0
  311. package/src/api/node.ts +6 -1
  312. package/src/api/utils.ts +18 -6
  313. package/src/component/axis.ts +1 -0
  314. package/src/component/scrollbar.ts +11 -8
  315. package/src/composition/facetRect.ts +14 -17
  316. package/src/data/index.ts +2 -0
  317. package/src/data/utils/venn/circleintersection.ts +235 -0
  318. package/src/data/utils/venn/diagram.ts +47 -0
  319. package/src/data/utils/venn/index.ts +5 -0
  320. package/src/data/utils/venn/layout.ts +769 -0
  321. package/src/data/venn.ts +58 -0
  322. package/src/geo/geoPath.ts +3 -1
  323. package/src/interaction/brushAxisHighlight.ts +130 -11
  324. package/src/interaction/brushHighlight.ts +6 -4
  325. package/src/interaction/elementHighlight.ts +39 -3
  326. package/src/interaction/elementSelect.ts +48 -10
  327. package/src/interaction/event.ts +7 -2
  328. package/src/interaction/index.ts +1 -0
  329. package/src/interaction/legendFilter.ts +46 -13
  330. package/src/interaction/legendHighlight.ts +55 -14
  331. package/src/interaction/scrollbarFilter.ts +32 -0
  332. package/src/interaction/sliderFilter.ts +108 -28
  333. package/src/interaction/tooltip.ts +2 -5
  334. package/src/interaction/utils.ts +6 -0
  335. package/src/mark/area.ts +6 -3
  336. package/src/mark/heatmap.ts +48 -0
  337. package/src/mark/index.ts +2 -0
  338. package/src/mark/line.ts +1 -1
  339. package/src/mark/text.ts +0 -1
  340. package/src/mark/utils.ts +1 -1
  341. package/src/runtime/plot.ts +31 -13
  342. package/src/runtime/render.ts +9 -7
  343. package/src/runtime/scale.ts +58 -14
  344. package/src/runtime/transform.ts +18 -9
  345. package/src/runtime/types/component.ts +2 -1
  346. package/src/runtime/types/options.ts +6 -0
  347. package/src/shape/heatmap/heatmap.ts +85 -0
  348. package/src/shape/heatmap/renderer/gradient.ts +16 -0
  349. package/src/shape/heatmap/renderer/index.ts +193 -0
  350. package/src/shape/heatmap/renderer/types.ts +38 -0
  351. package/src/shape/image/image.ts +9 -3
  352. package/src/shape/index.ts +6 -0
  353. package/src/shape/interval/color.ts +29 -5
  354. package/src/shape/interval/rect.ts +10 -1
  355. package/src/shape/line/trail.ts +80 -0
  356. package/src/shape/path/color.ts +10 -6
  357. package/src/spec/component.ts +2 -1
  358. package/src/spec/composition.ts +24 -8
  359. package/src/spec/dataTransform.ts +25 -0
  360. package/src/spec/mark.ts +2 -0
  361. package/src/stdlib/index.ts +10 -0
  362. package/src/utils/lru.ts +25 -0
  363. package/src/utils/number.ts +6 -0
  364. package/src/utils/scale.ts +29 -10
  365. 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
- const I = series.map((group) => group[0]);
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;
@@ -0,0 +1,48 @@
1
+ import { MarkComponent as MC, Vector2 } from '../runtime';
2
+ import { HeatmapMark } from '../spec';
3
+ import {
4
+ baseGeometryChannels,
5
+ basePostInference,
6
+ basePreInference,
7
+ tooltip2d,
8
+ } from './utils';
9
+
10
+ export type HeatmapOptions = Omit<HeatmapMark, 'type'>;
11
+
12
+ /**
13
+ * Draw heatmap with gradient.
14
+ */
15
+ export const Heatmap: MC<HeatmapOptions> = (options) => {
16
+ return (index, scale, value, coordinate) => {
17
+ const { x: X, y: Y, size: S, color: C } = value;
18
+ const P = Array.from(index, (i) => {
19
+ // Default size = 40.
20
+ const r = S ? +S[i] : 40;
21
+ // Warning: x, y, value, radius.
22
+ return [...coordinate.map([+X[i], +Y[i]]), C[i], r] as unknown as Vector2;
23
+ });
24
+
25
+ return [[0], [P]];
26
+ };
27
+ };
28
+
29
+ const shapes = ['heatmap'];
30
+
31
+ Heatmap.props = {
32
+ defaultShape: 'heatmap',
33
+ defaultLabelShape: 'label',
34
+ composite: false,
35
+ channels: [
36
+ ...baseGeometryChannels({ shapes }),
37
+ { name: 'x', required: true },
38
+ { name: 'y', required: true },
39
+ { name: 'color', scale: 'identity', required: true },
40
+ { name: 'size' },
41
+ ],
42
+ preInference: [
43
+ ...basePreInference(),
44
+ { type: 'maybeZeroY' },
45
+ { type: 'maybeZeroX' },
46
+ ],
47
+ postInference: [...basePostInference(), ...tooltip2d()],
48
+ };
package/src/mark/index.ts CHANGED
@@ -27,6 +27,7 @@ export { Tree } from './tree';
27
27
  export { WordCloud } from './wordCloud';
28
28
  export { Gauge } from './gauge';
29
29
  export { Density } from './density';
30
+ export { Heatmap } from './heatmap';
30
31
 
31
32
  export type { IntervalOptions } from './interval';
32
33
  export type { RectOptions } from './rect';
@@ -55,3 +56,4 @@ export type { TreeOptions } from './tree';
55
56
  export type { WordCloudOptions } from './wordCloud';
56
57
  export type { GaugeOptions } from './gauge';
57
58
  export type { DensityOptions } from './density';
59
+ export type { HeatmapOptions } from './heatmap';
package/src/mark/line.ts CHANGED
@@ -26,7 +26,7 @@ const line: Mark = (index, scale, value, coordinate) => {
26
26
  // Group data into series.
27
27
  // There is only one series without specified series encode.
28
28
  const series = S ? Array.from(group(index, (i) => S[i]).values()) : [index];
29
- const I = series.map((group) => group[0]);
29
+ const I = series.map((group) => group[0]).filter((i) => i !== undefined);
30
30
 
31
31
  // A group of data corresponds to one line.
32
32
  const xoffset = (x?.getBandWidth?.() || 0) / 2;
package/src/mark/text.ts CHANGED
@@ -15,7 +15,6 @@ export const Text: MC<TextOptions> = (options) => {
15
15
  const { cartesian = false } = options;
16
16
  if (cartesian) return visualMark as Mark;
17
17
  return ((index, scale, value, coordinate) => {
18
- if (cartesian) return visualMark(index, scale, value, coordinate);
19
18
  const { x: X, y: Y } = value;
20
19
  const offset = createBandOffset(scale, value, options);
21
20
  const P = Array.from(index, (i) => {
package/src/mark/utils.ts CHANGED
@@ -96,7 +96,7 @@ export function createBandOffset(
96
96
  };
97
97
  }
98
98
 
99
- function p(d) {
99
+ export function p(d) {
100
100
  return parseFloat(d) / 100;
101
101
  }
102
102
 
@@ -188,12 +188,12 @@ export async function plot<T extends G2ViewTree>(
188
188
  .attr('id', (view) => view.key)
189
189
  .call(applyTranslate)
190
190
  .each(function (view) {
191
- plotView(view, select(this), transitions, library);
191
+ plotView(view, select(this), transitions, library, context);
192
192
  enterContainer.set(view, this);
193
193
  }),
194
194
  (update) =>
195
195
  update.call(applyTranslate).each(function (view) {
196
- plotView(view, select(this), transitions, library);
196
+ plotView(view, select(this), transitions, library, context);
197
197
  updateContainer.set(view, this);
198
198
  }),
199
199
  (exit) =>
@@ -320,7 +320,7 @@ function createUpdateView(
320
320
  return async (newOptions) => {
321
321
  const transitions = [];
322
322
  const [newView, newChildren] = await initializeView(newOptions, library);
323
- plotView(newView, selection, transitions, library);
323
+ plotView(newView, selection, transitions, library, context);
324
324
  updateTooltip(selection, newOptions, newView, library, context);
325
325
  for (const child of newChildren) {
326
326
  plot(child, selection, library, context);
@@ -392,11 +392,13 @@ function bubbleOptions(options: G2View): G2View {
392
392
  const {
393
393
  coordinate: viewCoordinate = {},
394
394
  interaction: viewInteraction = {},
395
+ style: viewStyle = {},
395
396
  marks,
396
397
  ...rest
397
398
  } = options;
398
399
  const markCoordinates = marks.map((d) => d.coordinate || {});
399
400
  const markInteractions = marks.map((d) => d.interaction || {});
401
+ const markViewStyles = marks.map((d) => d.viewStyle || {});
400
402
  const newCoordinate = [...markCoordinates, viewCoordinate].reduceRight(
401
403
  (prev, cur) => deepMix(prev, cur),
402
404
  {},
@@ -405,11 +407,16 @@ function bubbleOptions(options: G2View): G2View {
405
407
  (prev, cur) => deepMix(prev, cur),
406
408
  {},
407
409
  );
410
+ const newStyle = [...markViewStyles, viewStyle].reduce(
411
+ (prev, cur) => deepMix(prev, cur),
412
+ {},
413
+ );
408
414
  return {
409
415
  ...rest,
410
416
  marks,
411
417
  coordinate: newCoordinate,
412
418
  interaction: newInteraction,
419
+ style: newStyle,
413
420
  };
414
421
  }
415
422
 
@@ -671,6 +678,7 @@ async function plotView(
671
678
  selection: Selection,
672
679
  transitions: GAnimation[],
673
680
  library: G2Library,
681
+ context: G2Context,
674
682
  ): Promise<void> {
675
683
  const { components, theme, layout, markState, coordinate, key, style, clip } =
676
684
  view;
@@ -809,7 +817,13 @@ async function plotView(
809
817
  const { data } = state;
810
818
  const { key, class: cls, type } = mark;
811
819
  const viewNode = selection.select(`#${key}`);
812
- const shapeFunction = createMarkShapeFunction(mark, state, view, library);
820
+ const shapeFunction = createMarkShapeFunction(
821
+ mark,
822
+ state,
823
+ view,
824
+ library,
825
+ context,
826
+ );
813
827
  const enterFunction = createEnterFunction(mark, state, view, library);
814
828
  const updateFunction = createUpdateFunction(mark, state, view, library);
815
829
  const exitFunction = createExitFunction(mark, state, view, library);
@@ -1017,14 +1031,16 @@ function getLabels(
1017
1031
  ];
1018
1032
  }
1019
1033
  const selector = normalizeLabelSelector(label);
1020
- const F = SI.map((index: number, i: number) => ({
1021
- ...label,
1022
- key: `${seriesKey[i]}-${labelIndex}`,
1023
- bounds: [points[i]],
1024
- index,
1025
- points,
1026
- dependentElement: element,
1027
- }));
1034
+ const F = SI.filter((_, i) => points[i].every(defined)).map(
1035
+ (index: number, i: number) => ({
1036
+ ...label,
1037
+ key: `${seriesKey[i]}-${labelIndex}`,
1038
+ bounds: [points[i]],
1039
+ index,
1040
+ points,
1041
+ dependentElement: element,
1042
+ }),
1043
+ );
1028
1044
  return selector ? selector(F) : F;
1029
1045
  }
1030
1046
 
@@ -1225,6 +1241,7 @@ function createMarkShapeFunction(
1225
1241
  state: G2MarkState,
1226
1242
  view: G2ViewDescriptor,
1227
1243
  library: G2Library,
1244
+ context: G2Context,
1228
1245
  ): (
1229
1246
  data: Record<string, any>,
1230
1247
  index: number,
@@ -1262,7 +1279,7 @@ function createMarkShapeFunction(
1262
1279
  ...visualStyle,
1263
1280
  type: shapeName(mark, shape),
1264
1281
  });
1265
- return shapeFunction(points, value, coordinate, theme, point2d);
1282
+ return shapeFunction(points, value, coordinate, theme, point2d, context);
1266
1283
  };
1267
1284
  }
1268
1285
 
@@ -1386,6 +1403,7 @@ function inferInteraction(
1386
1403
  // @todo Inferred by slider self.
1387
1404
  sliderFilter: true,
1388
1405
  legendFilter: true,
1406
+ scrollbarFilter: true,
1389
1407
  };
1390
1408
  const { interaction = {} } = view;
1391
1409
  return Object.entries(deepMix(defaults, interaction));
@@ -65,8 +65,10 @@ function Canvas(width: number, height: number): GCanvas {
65
65
  export function render<T extends G2ViewTree = G2ViewTree>(
66
66
  options: T,
67
67
  context: G2Context = {},
68
- resolve?: () => void,
69
- reject?: (e: Error) => void,
68
+ resolve = (): void => {},
69
+ reject = (e?: any): void => {
70
+ throw e;
71
+ },
70
72
  ): HTMLElement {
71
73
  // Initialize the context if it is not provided.
72
74
  const { width = 640, height = 480, theme } = options;
@@ -113,8 +115,10 @@ export function render<T extends G2ViewTree = G2ViewTree>(
113
115
  export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
114
116
  options: T,
115
117
  context: G2Context = {},
116
- resolve?: () => void,
117
- reject?: (e: Error) => void,
118
+ resolve = () => {},
119
+ reject = (e?: any) => {
120
+ throw e;
121
+ },
118
122
  ): DisplayObject {
119
123
  // Initialize the context if it is not provided.
120
124
  const { width = 640, height = 480, on } = options;
@@ -126,9 +130,7 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
126
130
  } = context;
127
131
 
128
132
  if (!group?.parentElement) {
129
- throw new Error(
130
- `renderToMountedElement can't render chart to unmounted group.`,
131
- );
133
+ error(`renderToMountedElement can't render chart to unmounted group.`);
132
134
  }
133
135
 
134
136
  const selection = select(group);