@antv/g2 5.0.0-beta.6 → 5.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (387) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +3 -3
  3. package/esm/api/chart.d.ts +8 -4
  4. package/esm/api/chart.js +33 -17
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/composition/base.d.ts +21 -0
  7. package/esm/api/composition/base.js +59 -0
  8. package/esm/api/composition/base.js.map +1 -0
  9. package/esm/api/composition/facetCircle.d.ts +2 -3
  10. package/esm/api/composition/facetCircle.js +2 -2
  11. package/esm/api/composition/facetCircle.js.map +1 -1
  12. package/esm/api/composition/facetRect.d.ts +2 -3
  13. package/esm/api/composition/facetRect.js +2 -2
  14. package/esm/api/composition/facetRect.js.map +1 -1
  15. package/esm/api/composition/geoPath.d.ts +2 -3
  16. package/esm/api/composition/geoPath.js +2 -2
  17. package/esm/api/composition/geoPath.js.map +1 -1
  18. package/esm/api/composition/geoView.d.ts +2 -3
  19. package/esm/api/composition/geoView.js +2 -2
  20. package/esm/api/composition/geoView.js.map +1 -1
  21. package/esm/api/composition/index.d.ts +2 -1
  22. package/esm/api/composition/index.js +2 -1
  23. package/esm/api/composition/index.js.map +1 -1
  24. package/esm/api/composition/repeatMatrix.d.ts +2 -3
  25. package/esm/api/composition/repeatMatrix.js +2 -2
  26. package/esm/api/composition/repeatMatrix.js.map +1 -1
  27. package/esm/api/composition/spaceFlex.d.ts +2 -3
  28. package/esm/api/composition/spaceFlex.js +2 -2
  29. package/esm/api/composition/spaceFlex.js.map +1 -1
  30. package/esm/api/composition/spaceLayer.d.ts +2 -3
  31. package/esm/api/composition/spaceLayer.js +2 -2
  32. package/esm/api/composition/spaceLayer.js.map +1 -1
  33. package/esm/api/composition/timingKeyframe.d.ts +2 -3
  34. package/esm/api/composition/timingKeyframe.js +2 -2
  35. package/esm/api/composition/timingKeyframe.js.map +1 -1
  36. package/esm/api/composition/view.d.ts +3 -3
  37. package/esm/api/composition/view.js +4 -4
  38. package/esm/api/composition/view.js.map +1 -1
  39. package/esm/api/mark/base.d.ts +22 -0
  40. package/esm/api/mark/base.js +54 -0
  41. package/esm/api/mark/base.js.map +1 -0
  42. package/esm/api/mark/mark.d.ts +29 -29
  43. package/esm/api/mark/mark.js +27 -27
  44. package/esm/api/mark/mark.js.map +1 -1
  45. package/esm/api/node.d.ts +2 -1
  46. package/esm/api/node.js +8 -9
  47. package/esm/api/node.js.map +1 -1
  48. package/esm/api/props.js +0 -20
  49. package/esm/api/props.js.map +1 -1
  50. package/esm/component/axis.js +4 -0
  51. package/esm/component/axis.js.map +1 -1
  52. package/esm/component/legendContinuous.d.ts +1 -0
  53. package/esm/component/legendContinuous.js +14 -16
  54. package/esm/component/legendContinuous.js.map +1 -1
  55. package/esm/component/slider.js +3 -13
  56. package/esm/component/slider.js.map +1 -1
  57. package/esm/geo/{d3-projection.d.ts → d3Projection.d.ts} +0 -0
  58. package/esm/geo/{d3-projection.js → d3Projection.js} +1 -1
  59. package/esm/geo/d3Projection.js.map +1 -0
  60. package/esm/geo/geoView.js +1 -1
  61. package/esm/geo/geoView.js.map +1 -1
  62. package/esm/interaction/builtin/elementHighlight.d.ts +2 -0
  63. package/esm/interaction/builtin/elementHighlightByColor.d.ts +2 -0
  64. package/esm/interaction/builtin/elementHighlightByX.d.ts +2 -0
  65. package/esm/interaction/index.d.ts +2 -0
  66. package/esm/interaction/index.js +2 -0
  67. package/esm/interaction/index.js.map +1 -1
  68. package/esm/interaction/native/brushFilter.d.ts +3 -1
  69. package/esm/interaction/native/brushFilter.js +7 -32
  70. package/esm/interaction/native/brushFilter.js.map +1 -1
  71. package/esm/interaction/native/brushXFilter.js +1 -1
  72. package/esm/interaction/native/brushXFilter.js.map +1 -1
  73. package/esm/interaction/native/brushYFilter.js +1 -1
  74. package/esm/interaction/native/brushYFilter.js.map +1 -1
  75. package/esm/interaction/native/elementHighlight.d.ts +7 -2
  76. package/esm/interaction/native/elementHighlight.js +72 -18
  77. package/esm/interaction/native/elementHighlight.js.map +1 -1
  78. package/esm/interaction/native/elementHighlightByColor.d.ts +4 -1
  79. package/esm/interaction/native/elementHighlightByColor.js +19 -3
  80. package/esm/interaction/native/elementHighlightByColor.js.map +1 -1
  81. package/esm/interaction/native/elementHighlightByX.d.ts +3 -3
  82. package/esm/interaction/native/elementHighlightByX.js +19 -3
  83. package/esm/interaction/native/elementHighlightByX.js.map +1 -1
  84. package/esm/interaction/native/elementSelect.d.ts +1 -1
  85. package/esm/interaction/native/elementSelect.js +42 -20
  86. package/esm/interaction/native/elementSelect.js.map +1 -1
  87. package/esm/interaction/native/elementSelectByColor.js +3 -2
  88. package/esm/interaction/native/elementSelectByColor.js.map +1 -1
  89. package/esm/interaction/native/elementSelectByX.js +3 -2
  90. package/esm/interaction/native/elementSelectByX.js.map +1 -1
  91. package/esm/interaction/native/legendFilter.d.ts +4 -0
  92. package/esm/interaction/native/legendFilter.js +7 -4
  93. package/esm/interaction/native/legendFilter.js.map +1 -1
  94. package/esm/interaction/native/legendHighlight.d.ts +4 -0
  95. package/esm/interaction/native/legendHighlight.js +94 -0
  96. package/esm/interaction/native/legendHighlight.js.map +1 -0
  97. package/esm/interaction/native/sliderFilter.d.ts +5 -0
  98. package/esm/interaction/native/sliderFilter.js +87 -0
  99. package/esm/interaction/native/sliderFilter.js.map +1 -0
  100. package/esm/interaction/native/tooltip.js +11 -0
  101. package/esm/interaction/native/tooltip.js.map +1 -1
  102. package/esm/interaction/native/utils.d.ts +13 -2
  103. package/esm/interaction/native/utils.js +151 -26
  104. package/esm/interaction/native/utils.js.map +1 -1
  105. package/esm/label-transform/overlapDodgeY.js.map +1 -1
  106. package/esm/mark/area.js +1 -1
  107. package/esm/mark/area.js.map +1 -1
  108. package/esm/runtime/component.d.ts +1 -1
  109. package/esm/runtime/component.js +5 -3
  110. package/esm/runtime/component.js.map +1 -1
  111. package/esm/runtime/plot.d.ts +1 -1
  112. package/esm/runtime/plot.js +68 -29
  113. package/esm/runtime/plot.js.map +1 -1
  114. package/esm/runtime/render.js +18 -13
  115. package/esm/runtime/render.js.map +1 -1
  116. package/esm/runtime/scale.d.ts +2 -1
  117. package/esm/runtime/scale.js +7 -0
  118. package/esm/runtime/scale.js.map +1 -1
  119. package/esm/runtime/types/options.d.ts +4 -2
  120. package/esm/shape/area/hv.d.ts +3 -0
  121. package/esm/shape/area/hv.js +9 -0
  122. package/esm/shape/area/hv.js.map +1 -0
  123. package/esm/shape/area/hvh.d.ts +3 -0
  124. package/esm/shape/area/{step.js → hvh.js} +3 -3
  125. package/esm/shape/area/hvh.js.map +1 -0
  126. package/esm/shape/area/vh.d.ts +3 -0
  127. package/esm/shape/area/vh.js +9 -0
  128. package/esm/shape/area/vh.js.map +1 -0
  129. package/esm/shape/index.d.ts +6 -2
  130. package/esm/shape/index.js +3 -1
  131. package/esm/shape/index.js.map +1 -1
  132. package/esm/shape/interval/color.d.ts +1 -0
  133. package/esm/shape/interval/color.js +65 -53
  134. package/esm/shape/interval/color.js.map +1 -1
  135. package/esm/spec/composition.d.ts +0 -3
  136. package/esm/spec/geometry.d.ts +1 -0
  137. package/esm/spec/interaction.d.ts +30 -11
  138. package/esm/spec/transform.d.ts +15 -5
  139. package/esm/stdlib/index.js +3 -8
  140. package/esm/stdlib/index.js.map +1 -1
  141. package/esm/transform/sample.js +42 -26
  142. package/esm/transform/sample.js.map +1 -1
  143. package/esm/transform/select.js +1 -13
  144. package/esm/transform/select.js.map +1 -1
  145. package/esm/transform/selectX.js +1 -1
  146. package/esm/transform/selectX.js.map +1 -1
  147. package/esm/transform/selectY.js +1 -1
  148. package/esm/transform/selectY.js.map +1 -1
  149. package/esm/transform/utils/lttb.d.ts +5 -0
  150. package/esm/transform/utils/lttb.js +56 -0
  151. package/esm/transform/utils/lttb.js.map +1 -0
  152. package/esm/utils/event.d.ts +0 -2
  153. package/esm/utils/event.js +0 -18
  154. package/esm/utils/event.js.map +1 -1
  155. package/esm/utils/scale.d.ts +3 -0
  156. package/esm/utils/scale.js +30 -0
  157. package/esm/utils/scale.js.map +1 -0
  158. package/esm/utils/vector.d.ts +1 -1
  159. package/esm/utils/vector.js +1 -1
  160. package/lib/api/chart.d.ts +8 -4
  161. package/lib/api/chart.js +34 -15
  162. package/lib/api/chart.js.map +1 -1
  163. package/lib/api/composition/base.d.ts +21 -0
  164. package/lib/api/composition/base.js +62 -0
  165. package/lib/api/composition/base.js.map +1 -0
  166. package/lib/api/composition/facetCircle.d.ts +2 -3
  167. package/lib/api/composition/facetCircle.js +2 -2
  168. package/lib/api/composition/facetCircle.js.map +1 -1
  169. package/lib/api/composition/facetRect.d.ts +2 -3
  170. package/lib/api/composition/facetRect.js +2 -2
  171. package/lib/api/composition/facetRect.js.map +1 -1
  172. package/lib/api/composition/geoPath.d.ts +2 -3
  173. package/lib/api/composition/geoPath.js +2 -2
  174. package/lib/api/composition/geoPath.js.map +1 -1
  175. package/lib/api/composition/geoView.d.ts +2 -3
  176. package/lib/api/composition/geoView.js +2 -2
  177. package/lib/api/composition/geoView.js.map +1 -1
  178. package/lib/api/composition/index.d.ts +2 -1
  179. package/lib/api/composition/index.js +3 -1
  180. package/lib/api/composition/index.js.map +1 -1
  181. package/lib/api/composition/repeatMatrix.d.ts +2 -3
  182. package/lib/api/composition/repeatMatrix.js +2 -2
  183. package/lib/api/composition/repeatMatrix.js.map +1 -1
  184. package/lib/api/composition/spaceFlex.d.ts +2 -3
  185. package/lib/api/composition/spaceFlex.js +2 -2
  186. package/lib/api/composition/spaceFlex.js.map +1 -1
  187. package/lib/api/composition/spaceLayer.d.ts +2 -3
  188. package/lib/api/composition/spaceLayer.js +2 -2
  189. package/lib/api/composition/spaceLayer.js.map +1 -1
  190. package/lib/api/composition/timingKeyframe.d.ts +2 -3
  191. package/lib/api/composition/timingKeyframe.js +2 -2
  192. package/lib/api/composition/timingKeyframe.js.map +1 -1
  193. package/lib/api/composition/view.d.ts +3 -3
  194. package/lib/api/composition/view.js +4 -4
  195. package/lib/api/composition/view.js.map +1 -1
  196. package/lib/api/mark/base.d.ts +22 -0
  197. package/lib/api/mark/base.js +58 -0
  198. package/lib/api/mark/base.js.map +1 -0
  199. package/lib/api/mark/mark.d.ts +29 -29
  200. package/lib/api/mark/mark.js +27 -27
  201. package/lib/api/mark/mark.js.map +1 -1
  202. package/lib/api/node.d.ts +2 -1
  203. package/lib/api/node.js +8 -9
  204. package/lib/api/node.js.map +1 -1
  205. package/lib/api/props.js +0 -20
  206. package/lib/api/props.js.map +1 -1
  207. package/lib/component/axis.js +4 -0
  208. package/lib/component/axis.js.map +1 -1
  209. package/lib/component/legendContinuous.d.ts +1 -0
  210. package/lib/component/legendContinuous.js +14 -16
  211. package/lib/component/legendContinuous.js.map +1 -1
  212. package/lib/component/slider.js +3 -13
  213. package/lib/component/slider.js.map +1 -1
  214. package/lib/geo/{d3-projection.d.ts → d3Projection.d.ts} +0 -0
  215. package/lib/geo/{d3-projection.js → d3Projection.js} +1 -1
  216. package/lib/geo/d3Projection.js.map +1 -0
  217. package/lib/geo/geoView.js +1 -1
  218. package/lib/geo/geoView.js.map +1 -1
  219. package/lib/interaction/builtin/elementHighlight.d.ts +2 -0
  220. package/lib/interaction/builtin/elementHighlightByColor.d.ts +2 -0
  221. package/lib/interaction/builtin/elementHighlightByX.d.ts +2 -0
  222. package/lib/interaction/index.d.ts +2 -0
  223. package/lib/interaction/index.js +5 -1
  224. package/lib/interaction/index.js.map +1 -1
  225. package/lib/interaction/native/brushFilter.d.ts +3 -1
  226. package/lib/interaction/native/brushFilter.js +10 -35
  227. package/lib/interaction/native/brushFilter.js.map +1 -1
  228. package/lib/interaction/native/brushXFilter.js +1 -1
  229. package/lib/interaction/native/brushXFilter.js.map +1 -1
  230. package/lib/interaction/native/brushYFilter.js +1 -1
  231. package/lib/interaction/native/brushYFilter.js.map +1 -1
  232. package/lib/interaction/native/elementHighlight.d.ts +7 -2
  233. package/lib/interaction/native/elementHighlight.js +71 -17
  234. package/lib/interaction/native/elementHighlight.js.map +1 -1
  235. package/lib/interaction/native/elementHighlightByColor.d.ts +4 -1
  236. package/lib/interaction/native/elementHighlightByColor.js +18 -2
  237. package/lib/interaction/native/elementHighlightByColor.js.map +1 -1
  238. package/lib/interaction/native/elementHighlightByX.d.ts +3 -3
  239. package/lib/interaction/native/elementHighlightByX.js +18 -2
  240. package/lib/interaction/native/elementHighlightByX.js.map +1 -1
  241. package/lib/interaction/native/elementSelect.d.ts +1 -1
  242. package/lib/interaction/native/elementSelect.js +41 -19
  243. package/lib/interaction/native/elementSelect.js.map +1 -1
  244. package/lib/interaction/native/elementSelectByColor.js +2 -1
  245. package/lib/interaction/native/elementSelectByColor.js.map +1 -1
  246. package/lib/interaction/native/elementSelectByX.js +2 -1
  247. package/lib/interaction/native/elementSelectByX.js.map +1 -1
  248. package/lib/interaction/native/legendFilter.d.ts +4 -0
  249. package/lib/interaction/native/legendFilter.js +10 -3
  250. package/lib/interaction/native/legendFilter.js.map +1 -1
  251. package/lib/interaction/native/legendHighlight.d.ts +4 -0
  252. package/lib/interaction/native/legendHighlight.js +98 -0
  253. package/lib/interaction/native/legendHighlight.js.map +1 -0
  254. package/lib/interaction/native/sliderFilter.d.ts +5 -0
  255. package/lib/interaction/native/sliderFilter.js +91 -0
  256. package/lib/interaction/native/sliderFilter.js.map +1 -0
  257. package/lib/interaction/native/tooltip.js +11 -0
  258. package/lib/interaction/native/tooltip.js.map +1 -1
  259. package/lib/interaction/native/utils.d.ts +13 -2
  260. package/lib/interaction/native/utils.js +154 -27
  261. package/lib/interaction/native/utils.js.map +1 -1
  262. package/lib/label-transform/overlapDodgeY.js.map +1 -1
  263. package/lib/mark/area.js +1 -1
  264. package/lib/mark/area.js.map +1 -1
  265. package/lib/runtime/component.d.ts +1 -1
  266. package/lib/runtime/component.js +4 -2
  267. package/lib/runtime/component.js.map +1 -1
  268. package/lib/runtime/plot.d.ts +1 -1
  269. package/lib/runtime/plot.js +65 -26
  270. package/lib/runtime/plot.js.map +1 -1
  271. package/lib/runtime/render.js +20 -12
  272. package/lib/runtime/render.js.map +1 -1
  273. package/lib/runtime/scale.d.ts +2 -1
  274. package/lib/runtime/scale.js +9 -1
  275. package/lib/runtime/scale.js.map +1 -1
  276. package/lib/runtime/types/options.d.ts +4 -2
  277. package/lib/shape/area/hv.d.ts +3 -0
  278. package/lib/shape/area/hv.js +13 -0
  279. package/lib/shape/area/hv.js.map +1 -0
  280. package/lib/shape/area/hvh.d.ts +3 -0
  281. package/lib/shape/area/{step.js → hvh.js} +5 -5
  282. package/lib/shape/area/hvh.js.map +1 -0
  283. package/lib/shape/area/vh.d.ts +3 -0
  284. package/lib/shape/area/vh.js +13 -0
  285. package/lib/shape/area/vh.js.map +1 -0
  286. package/lib/shape/index.d.ts +6 -2
  287. package/lib/shape/index.js +7 -3
  288. package/lib/shape/index.js.map +1 -1
  289. package/lib/shape/interval/color.d.ts +1 -0
  290. package/lib/shape/interval/color.js +67 -54
  291. package/lib/shape/interval/color.js.map +1 -1
  292. package/lib/spec/composition.d.ts +0 -3
  293. package/lib/spec/geometry.d.ts +1 -0
  294. package/lib/spec/interaction.d.ts +30 -11
  295. package/lib/spec/transform.d.ts +15 -5
  296. package/lib/stdlib/index.js +1 -1
  297. package/lib/stdlib/index.js.map +1 -1
  298. package/lib/transform/sample.js +42 -26
  299. package/lib/transform/sample.js.map +1 -1
  300. package/lib/transform/select.js +1 -13
  301. package/lib/transform/select.js.map +1 -1
  302. package/lib/transform/selectX.js +1 -1
  303. package/lib/transform/selectX.js.map +1 -1
  304. package/lib/transform/selectY.js +1 -1
  305. package/lib/transform/selectY.js.map +1 -1
  306. package/lib/transform/utils/lttb.d.ts +5 -0
  307. package/lib/transform/utils/lttb.js +60 -0
  308. package/lib/transform/utils/lttb.js.map +1 -0
  309. package/lib/utils/event.d.ts +0 -2
  310. package/lib/utils/event.js +1 -21
  311. package/lib/utils/event.js.map +1 -1
  312. package/lib/utils/scale.d.ts +3 -0
  313. package/lib/utils/scale.js +36 -0
  314. package/lib/utils/scale.js.map +1 -0
  315. package/lib/utils/vector.d.ts +1 -1
  316. package/lib/utils/vector.js +1 -1
  317. package/package.json +4 -3
  318. package/src/.DS_Store +0 -0
  319. package/src/api/chart.ts +39 -18
  320. package/src/api/composition/base.ts +56 -0
  321. package/src/api/composition/facetCircle.ts +2 -3
  322. package/src/api/composition/facetRect.ts +2 -3
  323. package/src/api/composition/geoPath.ts +2 -3
  324. package/src/api/composition/geoView.ts +2 -3
  325. package/src/api/composition/index.ts +2 -0
  326. package/src/api/composition/repeatMatrix.ts +2 -3
  327. package/src/api/composition/spaceFlex.ts +2 -3
  328. package/src/api/composition/spaceLayer.ts +2 -3
  329. package/src/api/composition/timingKeyframe.ts +2 -3
  330. package/src/api/composition/view.ts +6 -4
  331. package/src/api/mark/base.ts +58 -0
  332. package/src/api/mark/mark.ts +29 -28
  333. package/src/api/node.ts +9 -11
  334. package/src/api/props.ts +0 -23
  335. package/src/component/axis.ts +7 -0
  336. package/src/component/legendContinuous.ts +15 -5
  337. package/src/component/slider.ts +3 -12
  338. package/src/data/.DS_Store +0 -0
  339. package/src/geo/{d3-projection.ts → d3Projection.ts} +0 -0
  340. package/src/geo/geoView.ts +1 -1
  341. package/src/interaction/index.ts +2 -0
  342. package/src/interaction/native/brushFilter.ts +18 -38
  343. package/src/interaction/native/brushXFilter.ts +1 -0
  344. package/src/interaction/native/brushYFilter.ts +1 -0
  345. package/src/interaction/native/elementHighlight.ts +78 -11
  346. package/src/interaction/native/elementHighlightByColor.ts +9 -4
  347. package/src/interaction/native/elementHighlightByX.ts +9 -5
  348. package/src/interaction/native/elementSelect.ts +58 -14
  349. package/src/interaction/native/elementSelectByColor.ts +4 -1
  350. package/src/interaction/native/elementSelectByX.ts +4 -1
  351. package/src/interaction/native/legendFilter.ts +8 -4
  352. package/src/interaction/native/legendHighlight.ts +87 -0
  353. package/src/interaction/native/sliderFilter.ts +112 -0
  354. package/src/interaction/native/tooltip.ts +11 -0
  355. package/src/interaction/native/utils.ts +183 -26
  356. package/src/label-transform/overlapDodgeY.ts +1 -1
  357. package/src/mark/area.ts +1 -1
  358. package/src/runtime/component.ts +18 -25
  359. package/src/runtime/plot.ts +123 -75
  360. package/src/runtime/render.ts +26 -13
  361. package/src/runtime/scale.ts +14 -0
  362. package/src/runtime/types/options.ts +10 -2
  363. package/src/shape/.DS_Store +0 -0
  364. package/src/shape/area/hv.ts +20 -0
  365. package/src/shape/area/{step.ts → hvh.ts} +3 -3
  366. package/src/shape/area/vh.ts +20 -0
  367. package/src/shape/index.ts +7 -2
  368. package/src/shape/interval/color.ts +86 -54
  369. package/src/spec/composition.ts +0 -1
  370. package/src/spec/geometry.ts +1 -0
  371. package/src/spec/interaction.ts +45 -12
  372. package/src/spec/transform.ts +30 -3
  373. package/src/stdlib/index.ts +10 -6
  374. package/src/transform/sample.ts +54 -18
  375. package/src/transform/select.ts +1 -2
  376. package/src/transform/selectX.ts +1 -1
  377. package/src/transform/selectY.ts +1 -1
  378. package/src/transform/utils/lttb.ts +73 -0
  379. package/src/utils/event.ts +0 -26
  380. package/src/utils/scale.ts +31 -0
  381. package/src/utils/vector.ts +1 -1
  382. package/esm/geo/d3-projection.js.map +0 -1
  383. package/esm/shape/area/step.d.ts +0 -3
  384. package/esm/shape/area/step.js.map +0 -1
  385. package/lib/geo/d3-projection.js.map +0 -1
  386. package/lib/shape/area/step.d.ts +0 -3
  387. package/lib/shape/area/step.js.map +0 -1
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lttb = void 0;
4
+ /**
5
+ * Sample data with lttb(Largest-Triangle-Three-Buckets) algo (https://github.com/pingec/downsample-lttb).
6
+ * Return the sampled index array.
7
+ */
8
+ function lttb(I, X, Y, thresholds) {
9
+ const length = I.length;
10
+ if (thresholds >= length || thresholds === 0) {
11
+ return I;
12
+ }
13
+ const x = (i) => X[I[i]] * 1;
14
+ const y = (i) => Y[I[i]] * 1;
15
+ const sampled = [];
16
+ // Bucket size. Leave room for start and end data points.
17
+ const every = (length - 2) / (thresholds - 2);
18
+ let a = 0; // Initially a is the first point in the triangle.
19
+ let maxArea;
20
+ let area;
21
+ let nextA;
22
+ sampled.push(a); // Always add the first point.
23
+ for (let i = 0; i < thresholds - 2; i++) {
24
+ // Calculate point average for next bucket (containing c).
25
+ let avgX = 0;
26
+ let avgY = 0;
27
+ let start = Math.floor((i + 1) * every) + 1;
28
+ let end = Math.floor((i + 2) * every) + 1;
29
+ end = Math.min(end, length);
30
+ const size = end - start;
31
+ for (; start < end; start++) {
32
+ avgX += x(start);
33
+ avgY += y(start);
34
+ }
35
+ avgX /= size;
36
+ avgY /= size;
37
+ // Get the range for this bucket.
38
+ let frameStart = Math.floor((i + 0) * every) + 1;
39
+ const frameEnd = Math.floor((i + 1) * every) + 1;
40
+ // Point a.
41
+ const pointA = [x(a), y(a)];
42
+ maxArea = area = -1;
43
+ for (; frameStart < frameEnd; frameStart++) {
44
+ // Calculate triangle area over three buckets.
45
+ area =
46
+ Math.abs((pointA[0] - avgX) * (x(frameStart) - pointA[1]) -
47
+ (pointA[0] - y(frameStart)) * (avgY - pointA[0])) * 0.5;
48
+ if (area > maxArea) {
49
+ maxArea = area;
50
+ nextA = frameStart; // Next a is this b.
51
+ }
52
+ }
53
+ sampled.push(nextA); // Pick this point from the bucket.
54
+ a = nextA; // This a is the next a (chosen b).
55
+ }
56
+ sampled.push(length - 1); // Always add last.
57
+ return sampled.map((a) => I[a]);
58
+ }
59
+ exports.lttb = lttb;
60
+ //# sourceMappingURL=lttb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lttb.js","sourceRoot":"src/","sources":["transform/utils/lttb.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,IAAI,CAClB,CAAW,EACX,CAAW,EACX,CAAW,EACX,UAAkB;IAElB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACxB,IAAI,UAAU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AAC,CAAC,mBAAmB;IAE7C,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClC,CAAC;AApED,oBAoEC"}
@@ -12,5 +12,3 @@ export declare enum CHART_LIFE_CIRCLE {
12
12
  BEFORE_CHANGE_SIZE = "beforechangesize",
13
13
  AFTER_CHANGE_SIZE = "afterchangesize"
14
14
  }
15
- export declare function emitEvent(event: Record<string, EventListener[]>, eventName: string, ...args: any[]): void;
16
- export declare function offEvent(event: Record<string, EventListener[]>, eventName?: string): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.offEvent = exports.emitEvent = exports.CHART_LIFE_CIRCLE = void 0;
3
+ exports.CHART_LIFE_CIRCLE = void 0;
4
4
  // Life cycle stage.
5
5
  var CHART_LIFE_CIRCLE;
6
6
  (function (CHART_LIFE_CIRCLE) {
@@ -17,24 +17,4 @@ var CHART_LIFE_CIRCLE;
17
17
  CHART_LIFE_CIRCLE["BEFORE_CHANGE_SIZE"] = "beforechangesize";
18
18
  CHART_LIFE_CIRCLE["AFTER_CHANGE_SIZE"] = "afterchangesize";
19
19
  })(CHART_LIFE_CIRCLE = exports.CHART_LIFE_CIRCLE || (exports.CHART_LIFE_CIRCLE = {}));
20
- function emitEvent(event, eventName, ...args) {
21
- if (!event)
22
- return;
23
- const listeners = event[eventName] || [];
24
- listeners.forEach((listener) => {
25
- listener.apply(this, args);
26
- });
27
- }
28
- exports.emitEvent = emitEvent;
29
- function offEvent(event, eventName) {
30
- if (!event)
31
- return;
32
- // Unbind all event.
33
- if (!eventName) {
34
- event = {};
35
- return;
36
- }
37
- delete event[eventName];
38
- }
39
- exports.offEvent = offEvent;
40
20
  //# sourceMappingURL=event.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"event.js","sourceRoot":"src/","sources":["utils/event.ts"],"names":[],"mappings":";;;AAAA,oBAAo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;IAE1B,qDAAgC,CAAA;IAChC,mDAA8B,CAAA;IAE9B,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;AACvC,CAAC,EAlBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAkB5B"}
@@ -0,0 +1,3 @@
1
+ export declare function isOrdinalScale(scale: any): any;
2
+ export declare function invert(scale: any, x: any, start: any): any;
3
+ export declare function domainOf(scale: any, values: any): any;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.domainOf = exports.invert = exports.isOrdinalScale = void 0;
4
+ const d3_array_1 = require("d3-array");
5
+ function constrain(x, lo, hi) {
6
+ return Math.min(hi, Math.max(lo, x));
7
+ }
8
+ function isOrdinalScale(scale) {
9
+ return scale.getBandWidth;
10
+ }
11
+ exports.isOrdinalScale = isOrdinalScale;
12
+ function invert(scale, x, start) {
13
+ if (!isOrdinalScale(scale))
14
+ return scale.invert(x);
15
+ const { adjustedRange } = scale;
16
+ const { domain } = scale.getOptions();
17
+ const offset = start ? -1 : 0;
18
+ const step = scale.getStep();
19
+ const range = start ? adjustedRange : adjustedRange.map((d) => d + step);
20
+ // R[i0 - 1] < x <= R[i0]
21
+ const i0 = (0, d3_array_1.bisectLeft)(range, x);
22
+ const i1 = constrain(i0 + offset, 0, domain.length - 1);
23
+ return domain[i1];
24
+ }
25
+ exports.invert = invert;
26
+ function domainOf(scale, values) {
27
+ if (!isOrdinalScale(scale))
28
+ return (0, d3_array_1.sort)(values);
29
+ const { domain } = scale.getOptions();
30
+ const [v1, v2] = values;
31
+ const start = domain.indexOf(v1);
32
+ const end = domain.indexOf(v2);
33
+ return domain.slice(start, end + 1);
34
+ }
35
+ exports.domainOf = domainOf;
36
+ //# sourceMappingURL=scale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale.js","sourceRoot":"src/","sources":["utils/scale.ts"],"names":[],"mappings":";;;AAAA,uCAA4C;AAE5C,SAAS,SAAS,CAAC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E,MAAM,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;IACtC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC;IACxB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC;AAPD,4BAOC"}
@@ -6,7 +6,7 @@ export declare function dist([x0, y0]: Vector2, [x1, y1]: Vector2): number;
6
6
  */
7
7
  export declare function angle([x, y]: Vector2): number;
8
8
  /**
9
- * Calculate angle of [x, y]then + Math.PI / 2.
9
+ * Calculate angle of [x, y], then + Math.PI / 2.
10
10
  * Because of the difference between `Geometric coordinate system` and `Visualization coordinate system`.
11
11
  * @returns
12
12
  */
@@ -17,7 +17,7 @@ function angle([x, y]) {
17
17
  }
18
18
  exports.angle = angle;
19
19
  /**
20
- * Calculate angle of [x, y]then + Math.PI / 2.
20
+ * Calculate angle of [x, y], then + Math.PI / 2.
21
21
  * Because of the difference between `Geometric coordinate system` and `Visualization coordinate system`.
22
22
  * @returns
23
23
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g2",
3
- "version": "5.0.0-beta.6",
3
+ "version": "5.0.0-beta.8",
4
4
  "description": "the Grammar of Graphics in Javascript",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -121,14 +121,15 @@
121
121
  },
122
122
  "dependencies": {
123
123
  "@antv/coord": "^0.4.1",
124
+ "@antv/event-emitter": "^0.1.3",
124
125
  "@antv/g": "^5.7.4",
125
126
  "@antv/g-canvas": "^1.7.4",
126
127
  "@antv/g-plugin-dragndrop": "^1.6.1",
127
- "@antv/gui": "^0.4.3-alpha.53",
128
+ "@antv/gui": "^0.4.3-alpha.65",
128
129
  "@antv/path-util": "^3.0.1",
129
130
  "@antv/scale": "^0.4.7",
130
131
  "@antv/util": "^2.0.17",
131
- "d3-array": "^3.1.1",
132
+ "d3-array": "^3.2.2",
132
133
  "d3-dsv": "^3.0.1",
133
134
  "d3-force": "^3.0.0",
134
135
  "d3-format": "^3.1.0",
package/src/.DS_Store ADDED
Binary file
package/src/api/chart.ts CHANGED
@@ -2,10 +2,11 @@ import { RendererPlugin, Canvas as GCanvas } from '@antv/g';
2
2
  import { Renderer as CanvasRenderer } from '@antv/g-canvas';
3
3
  import { Plugin as DragAndDropPlugin } from '@antv/g-plugin-dragndrop';
4
4
  import { debounce } from '@antv/util';
5
+ import EventEmitter from '@antv/event-emitter';
5
6
  import { G2Context, render, destroy } from '../runtime';
6
7
  import { ViewComposition } from '../spec';
7
8
  import { getChartSize } from '../utils/size';
8
- import { CHART_LIFE_CIRCLE, emitEvent } from '../utils/event';
9
+ import { CHART_LIFE_CIRCLE } from '../utils/event';
9
10
  import { Node } from './node';
10
11
  import {
11
12
  defineProps,
@@ -20,7 +21,7 @@ import {
20
21
  ObjectAttribute,
21
22
  } from './types';
22
23
  import { mark, Mark } from './mark';
23
- import { composition, Composition } from './composition';
24
+ import { composition, Composition, View } from './composition';
24
25
  import { library } from './library';
25
26
 
26
27
  function normalizeContainer(container: string | HTMLElement): HTMLElement {
@@ -133,7 +134,6 @@ export interface Chart extends Composition, Mark {
133
134
  transform: ArrayAttribute<ChartProps['transform'], Chart>;
134
135
  theme: ObjectAttribute<ChartProps['theme'], Chart>;
135
136
  title: ObjectAttribute<ChartProps['title'], Chart>;
136
- on: ObjectAttribute<ChartProps['on'], Chart>;
137
137
  scale: ObjectAttribute<ChartOptions['scale'], Chart>;
138
138
  axis: ObjectAttribute<ChartOptions['axis'], Chart>;
139
139
  legend: ObjectAttribute<ChartOptions['legend'], Chart>;
@@ -151,7 +151,6 @@ export const props: NodePropertyDescriptor[] = [
151
151
  { name: 'key', type: 'value' },
152
152
  { name: 'transform', type: 'array' },
153
153
  { name: 'theme', type: 'object' },
154
- { name: 'on', type: 'event' },
155
154
  { name: 'scale', type: 'object' },
156
155
  { name: 'axis', type: 'object' },
157
156
  { name: 'legend', type: 'object' },
@@ -161,19 +160,21 @@ export const props: NodePropertyDescriptor[] = [
161
160
  ];
162
161
 
163
162
  @defineProps(props)
164
- export class Chart extends Node<ChartOptions> {
163
+ export class Chart extends View<ChartOptions> {
165
164
  private _container: HTMLElement;
166
165
  private _context: G2Context;
166
+ private _emitter: EventEmitter;
167
167
 
168
168
  constructor(options: ChartOptions = {}) {
169
169
  const { container, ...rest } = options;
170
170
  super(rest, 'view');
171
171
  this._container = normalizeContainer(container);
172
- this._context = { library };
172
+ this._emitter = new EventEmitter();
173
+ this._context = { library, emitter: this._emitter };
173
174
  this.bindAutoFit();
174
175
  }
175
176
 
176
- render(): Chart {
177
+ render(): Promise<Chart> {
177
178
  if (!this._context.canvas) {
178
179
  // Init width and height.
179
180
  const {
@@ -201,9 +202,10 @@ export class Chart extends Node<ChartOptions> {
201
202
  plugins,
202
203
  );
203
204
  }
204
- render(this.options(), this._context);
205
205
 
206
- return this;
206
+ return new Promise((resolve) => {
207
+ render(this.options(), this._context, () => resolve(this));
208
+ });
207
209
  }
208
210
 
209
211
  options() {
@@ -218,23 +220,41 @@ export class Chart extends Node<ChartOptions> {
218
220
  return this._context;
219
221
  }
220
222
 
223
+ on(event: string, callback: (...args: any[]) => any, once?: boolean): this {
224
+ this._emitter.on(event, callback, once);
225
+ return this;
226
+ }
227
+
228
+ once(event: string, callback: (...args: any[]) => any): this {
229
+ this._emitter.once(event, callback);
230
+ return this;
231
+ }
232
+
233
+ emit(event: string, ...args: any[]): this {
234
+ this._emitter.emit(event, ...args);
235
+ return this;
236
+ }
237
+
238
+ off(event?: string, callback?: (...args: any[]) => any) {
239
+ this._emitter.off(event, callback);
240
+ return this;
241
+ }
242
+
221
243
  destroy() {
222
244
  const options = this.options();
223
- const { on } = options;
224
- emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_DESTROY);
245
+ this.emit(CHART_LIFE_CIRCLE.BEFORE_DESTROY);
225
246
  this.unbindAutoFit();
226
247
  destroy(options, this._context);
227
248
  // Remove the container.
228
249
  removeContainer(this._container);
229
- emitEvent(on, CHART_LIFE_CIRCLE.AFTER_DESTROY);
250
+ this.emit(CHART_LIFE_CIRCLE.AFTER_DESTROY);
230
251
  }
231
252
 
232
253
  clear() {
233
254
  const options = this.options();
234
- const { on } = options;
235
- emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_CLEAR);
255
+ this.emit(CHART_LIFE_CIRCLE.BEFORE_CLEAR);
236
256
  destroy(options, this._context);
237
- emitEvent(on, CHART_LIFE_CIRCLE.AFTER_CLEAR);
257
+ this.emit(CHART_LIFE_CIRCLE.AFTER_CLEAR);
238
258
  }
239
259
 
240
260
  forceFit() {
@@ -256,11 +276,12 @@ export class Chart extends Node<ChartOptions> {
256
276
  return this;
257
277
  }
258
278
 
259
- emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_CHANGE_SIZE);
279
+ this.emit(CHART_LIFE_CIRCLE.BEFORE_CHANGE_SIZE);
260
280
  this.width(adjustedWidth);
261
281
  this.height(adjustedHeight);
262
- this.render();
263
- emitEvent(on, CHART_LIFE_CIRCLE.AFTER_CHANGE_SIZE);
282
+ return this.render().then(() => {
283
+ this.emit(CHART_LIFE_CIRCLE.AFTER_CHANGE_SIZE);
284
+ });
264
285
  }
265
286
 
266
287
  private onResize = debounce(() => {
@@ -0,0 +1,56 @@
1
+ import { DisplayObject } from '@antv/g';
2
+ import { Coordinate } from '@antv/coord';
3
+ import { defineProps } from '../props';
4
+ import { Node } from '../node';
5
+ import { G2Theme, G2ViewDescriptor } from '../../runtime';
6
+
7
+ @defineProps([{ name: 'on', type: 'event' }])
8
+ export class Base<
9
+ Value extends Record<string, any> = Record<string, any>,
10
+ ParentValue extends Record<string, any> = Record<string, any>,
11
+ ChildValue extends Record<string, any> = Record<string, any>,
12
+ > extends Node<Value, ParentValue, ChildValue> {
13
+ /**
14
+ * Get view instance by key.
15
+ */
16
+ getView(): G2ViewDescriptor {
17
+ const chart = this.root();
18
+ const { views } = chart.context();
19
+ if (!views?.length) return undefined;
20
+ return views.find((view) => view.key === this.attr('key'));
21
+ }
22
+
23
+ getCoordinate(): Coordinate {
24
+ return this.getView()?.coordinate;
25
+ }
26
+
27
+ getTheme(): G2Theme {
28
+ return this.getView()?.theme;
29
+ }
30
+
31
+ getGroup(): DisplayObject {
32
+ const key = this.attr('key');
33
+ if (!key) return undefined;
34
+ const chart = this.root();
35
+ const chartGroup = chart.context().canvas.getRoot();
36
+ return chartGroup.getElementById(key);
37
+ }
38
+
39
+ /**
40
+ * Show the view.
41
+ */
42
+ show() {
43
+ const group = this.getGroup();
44
+ if (!group) return;
45
+ !group.isVisible() && group.setAttribute('visibility', 'visible');
46
+ }
47
+
48
+ /**
49
+ * Hide the view.
50
+ */
51
+ hide() {
52
+ const group = this.getGroup();
53
+ if (!group) return;
54
+ group.isVisible() && group.setAttribute('visibility', 'hidden');
55
+ }
56
+ }
@@ -6,9 +6,8 @@ import {
6
6
  ArrayAttribute,
7
7
  ObjectAttribute,
8
8
  } from '../types';
9
- import { Node } from '../node';
10
9
  import { mark, Mark } from '../mark';
11
- import { Composition } from './index';
10
+ import { Composition, Base } from './index';
12
11
 
13
12
  type FacetCircleSpec = Concrete<FacetCircleComposition>;
14
13
 
@@ -30,7 +29,7 @@ export interface FacetCircle extends Composition, Mark {
30
29
  { type: 'object', name: 'axis' },
31
30
  ...nodeProps(mark),
32
31
  ])
33
- export class FacetCircle extends Node<FacetCircleComposition> {
32
+ export class FacetCircle extends Base<FacetCircleComposition> {
34
33
  constructor() {
35
34
  super({}, 'facetCircle');
36
35
  }
@@ -6,9 +6,8 @@ import {
6
6
  ArrayAttribute,
7
7
  ObjectAttribute,
8
8
  } from '../types';
9
- import { Node } from '../node';
10
9
  import { mark, Mark } from '../mark';
11
- import { Composition } from './index';
10
+ import { Composition, Base } from './index';
12
11
 
13
12
  type FacetRectSpec = Concrete<FacetRectComposition>;
14
13
 
@@ -30,7 +29,7 @@ export interface FacetRect extends Composition, Mark {
30
29
  { type: 'object', name: 'axis' },
31
30
  ...nodeProps(mark),
32
31
  ])
33
- export class FacetRect extends Node<FacetRectComposition> {
32
+ export class FacetRect extends Base<FacetRectComposition> {
34
33
  constructor() {
35
34
  super({}, 'facetRect');
36
35
  }
@@ -6,9 +6,8 @@ import {
6
6
  ArrayAttribute,
7
7
  Concrete,
8
8
  } from '../types';
9
- import { Node } from '../node';
10
9
  import { mark, Mark } from '../mark';
11
- import { Composition } from './index';
10
+ import { Composition, Base } from './index';
12
11
 
13
12
  type GeoPathSpec = Concrete<GeoPathComposition>;
14
13
 
@@ -36,7 +35,7 @@ export interface GeoPath extends Mark, Composition {
36
35
  { type: 'object', name: 'legend' },
37
36
  ...nodeProps(mark),
38
37
  ])
39
- export class GeoPath extends Node<GeoPathComposition> {
38
+ export class GeoPath extends Base<GeoPathComposition> {
40
39
  constructor() {
41
40
  super({}, 'geoPath');
42
41
  }
@@ -6,9 +6,8 @@ import {
6
6
  ArrayAttribute,
7
7
  Concrete,
8
8
  } from '../types';
9
- import { Node } from '../node';
10
9
  import { mark, Mark } from '../mark';
11
- import { Composition } from './index';
10
+ import { Composition, Base } from './index';
12
11
 
13
12
  type GeoViewSpec = Concrete<GeoViewComposition>;
14
13
 
@@ -35,7 +34,7 @@ export interface GeoView extends Mark, Composition {
35
34
  { type: 'object', name: 'legend' },
36
35
  ...nodeProps(mark),
37
36
  ])
38
- export class GeoView extends Node<GeoViewComposition> {
37
+ export class GeoView extends Base<GeoViewComposition> {
39
38
  constructor() {
40
39
  super({}, 'geoView');
41
40
  }
@@ -1,4 +1,5 @@
1
1
  import { defineProps, nodeProps } from '../props';
2
+ import { Base } from './base';
2
3
  import { View } from './view';
3
4
  import { SpaceLayer } from './spaceLayer';
4
5
  import { SpaceFlex } from './spaceFlex';
@@ -34,6 +35,7 @@ export interface Composition {
34
35
  }
35
36
 
36
37
  export {
38
+ Base,
37
39
  View,
38
40
  SpaceLayer,
39
41
  SpaceFlex,
@@ -6,9 +6,8 @@ import {
6
6
  ArrayAttribute,
7
7
  ObjectAttribute,
8
8
  } from '../types';
9
- import { Node } from '../node';
10
9
  import { mark, Mark } from '../mark';
11
- import { Composition } from './index';
10
+ import { Composition, Base } from './index';
12
11
 
13
12
  type RepeatMatrixSpec = Concrete<RepeatMatrixComposition>;
14
13
 
@@ -30,7 +29,7 @@ export interface RepeatMatrix extends Composition, Mark {
30
29
  { type: 'object', name: 'legend' },
31
30
  ...nodeProps(mark),
32
31
  ])
33
- export class RepeatMatrix extends Node<RepeatMatrixComposition> {
32
+ export class RepeatMatrix extends Base<RepeatMatrixComposition> {
34
33
  constructor() {
35
34
  super({}, 'repeatMatrix');
36
35
  }
@@ -1,9 +1,8 @@
1
1
  import { SpaceFlexComposition } from '../../spec';
2
2
  import { defineProps, nodeProps } from '../props';
3
3
  import { ValueAttribute, Concrete } from '../types';
4
- import { Node } from '../node';
5
4
  import { mark, Mark } from '../mark';
6
- import { Composition } from './index';
5
+ import { Composition, Base } from './index';
7
6
 
8
7
  type SpaceFlexSpec = Concrete<SpaceFlexComposition>;
9
8
 
@@ -12,7 +11,7 @@ export interface SpaceFlex extends Composition, Mark {
12
11
  }
13
12
 
14
13
  @defineProps([{ type: 'value', name: 'data' }, ...nodeProps(mark)])
15
- export class SpaceFlex extends Node<SpaceFlexSpec> {
14
+ export class SpaceFlex extends Base<SpaceFlexSpec> {
16
15
  constructor() {
17
16
  super({}, 'spaceFlex');
18
17
  }
@@ -1,9 +1,8 @@
1
1
  import { SpaceLayerComposition } from '../../spec';
2
2
  import { defineProps, nodeProps } from '../props';
3
3
  import { ValueAttribute, Concrete } from '../types';
4
- import { Node } from '../node';
5
4
  import { mark, Mark } from '../mark';
6
- import { Composition } from './index';
5
+ import { Composition, Base } from './index';
7
6
 
8
7
  type SpaceLayerSpec = Concrete<SpaceLayerComposition>;
9
8
 
@@ -12,7 +11,7 @@ export interface SpaceLayer extends Composition, Mark {
12
11
  }
13
12
 
14
13
  @defineProps([{ type: 'value', name: 'data' }, ...nodeProps(mark)])
15
- export class SpaceLayer extends Node<SpaceLayerComposition> {
14
+ export class SpaceLayer extends Base<SpaceLayerComposition> {
16
15
  constructor() {
17
16
  super({}, 'spaceLayer');
18
17
  }
@@ -1,16 +1,15 @@
1
1
  import { TimingKeyframeComposition } from '../../spec';
2
2
  import { defineProps, nodeProps } from '../props';
3
3
  import { Concrete } from '../types';
4
- import { Node } from '../node';
5
4
  import { mark, Mark } from '../mark';
6
- import { Composition } from './index';
5
+ import { Composition, Base } from './index';
7
6
 
8
7
  type TimingKeyframeSpec = Concrete<TimingKeyframeComposition>;
9
8
 
10
9
  export interface TimingKeyframe extends Composition, Mark {}
11
10
 
12
11
  @defineProps([...nodeProps(mark)])
13
- export class TimingKeyframe extends Node<TimingKeyframeSpec> {
12
+ export class TimingKeyframe extends Base<TimingKeyframeSpec> {
14
13
  constructor() {
15
14
  super({}, 'timingKeyframe');
16
15
  }
@@ -6,8 +6,8 @@ import {
6
6
  ArrayAttribute,
7
7
  Concrete,
8
8
  } from '../types';
9
- import { Node } from '../node';
10
9
  import { mark, Mark } from '../mark';
10
+ import { Base } from './base';
11
11
 
12
12
  type ViewSpec = Concrete<ViewComposition>;
13
13
 
@@ -33,8 +33,10 @@ export interface View extends Mark {
33
33
  { type: 'object', name: 'legend' },
34
34
  ...nodeProps(mark),
35
35
  ])
36
- export class View extends Node<ViewComposition> {
37
- constructor() {
38
- super({}, 'view');
36
+ export class View<
37
+ ViewProps extends ViewComposition = ViewComposition,
38
+ > extends Base<ViewProps> {
39
+ constructor(options = {}, type = 'view') {
40
+ super(options, type);
39
41
  }
40
42
  }
@@ -0,0 +1,58 @@
1
+ import { DisplayObject } from '@antv/g';
2
+ import { Node } from '../node';
3
+ import { G2MarkState, Scale } from '../../runtime';
4
+
5
+ export class MarkBase<
6
+ Value extends Record<string, any> = Record<string, any>,
7
+ ParentValue extends Record<string, any> = Record<string, any>,
8
+ ChildValue extends Record<string, any> = Record<string, any>,
9
+ > extends Node<Value, ParentValue, ChildValue> {
10
+ changeData(data: any) {
11
+ const chart = this.root();
12
+ if (!chart) return;
13
+ this.attr('data', data);
14
+ chart?.render();
15
+ }
16
+
17
+ /**
18
+ * Get mark from chart views.
19
+ */
20
+ getMark(): G2MarkState {
21
+ const chartView = this.root()?.getView();
22
+ if (!chartView) return undefined;
23
+ const { markState } = chartView;
24
+ const markKey = Array.from(markState.keys()).find(
25
+ (item) => item.key === this.attr('key'),
26
+ );
27
+ return markState.get(markKey);
28
+ }
29
+
30
+ /**
31
+ * Get all scales instance.
32
+ */
33
+ getScale(): Record<string, Scale> {
34
+ const chartView = this.root()?.getView();
35
+ if (!chartView) return undefined;
36
+ return chartView?.scale;
37
+ }
38
+
39
+ /**
40
+ * Get the scale instance by channel.
41
+ */
42
+ getScaleByChannel(channel: string): Scale {
43
+ const chartView = this.root()?.getView();
44
+ if (!chartView) return undefined;
45
+ return chartView?.scale?.[channel];
46
+ }
47
+
48
+ /**
49
+ * Get canvas group.
50
+ */
51
+ getGroup(): DisplayObject {
52
+ const key = this.attr('key');
53
+ if (!key) return undefined;
54
+ const chart = this.root();
55
+ const chartGroup = chart.context().canvas.getRoot();
56
+ return chartGroup.getElementById(key);
57
+ }
58
+ }