@visactor/vgrammar-core 0.10.0-alpha.2 → 0.10.0-alpha.3

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 (306) hide show
  1. package/cjs/component/axis.js.map +1 -1
  2. package/cjs/component/datazoom.js.map +1 -1
  3. package/cjs/component/grid.js.map +1 -1
  4. package/cjs/component/label.js +1 -0
  5. package/cjs/component/label.js.map +1 -1
  6. package/cjs/component/legend.js.map +1 -1
  7. package/cjs/component/player.js.map +1 -1
  8. package/cjs/component/scrollbar.js.map +1 -1
  9. package/cjs/component/slider.js.map +1 -1
  10. package/cjs/component/title.d.ts +4 -3
  11. package/cjs/component/title.js.map +1 -1
  12. package/cjs/core/factory.d.ts +8 -4
  13. package/cjs/core/factory.js +9 -3
  14. package/cjs/core/factory.js.map +1 -1
  15. package/cjs/env.d.ts +1 -1
  16. package/cjs/env.js +6 -6
  17. package/cjs/env.js.map +1 -1
  18. package/cjs/glyph/boxplot.js +4 -2
  19. package/cjs/glyph/boxplot.js.map +1 -1
  20. package/cjs/glyph/link-path.js +3 -2
  21. package/cjs/glyph/link-path.js.map +1 -1
  22. package/cjs/glyph/ripple.js +2 -2
  23. package/cjs/glyph/ripple.js.map +1 -1
  24. package/cjs/glyph/tree-path.js +3 -2
  25. package/cjs/glyph/tree-path.js.map +1 -1
  26. package/cjs/glyph/violin.js +4 -2
  27. package/cjs/glyph/violin.js.map +1 -1
  28. package/cjs/glyph/wave.js +2 -2
  29. package/cjs/glyph/wave.js.map +1 -1
  30. package/cjs/graph/animation/animate.js +5 -3
  31. package/cjs/graph/animation/animate.js.map +1 -1
  32. package/cjs/graph/animation/animation/grow-cartesian.js.map +1 -1
  33. package/cjs/graph/animation/animator.js +6 -5
  34. package/cjs/graph/animation/animator.js.map +1 -1
  35. package/cjs/graph/animation/attribute.d.ts +2 -2
  36. package/cjs/graph/animation/attribute.js +6 -6
  37. package/cjs/graph/animation/attribute.js.map +1 -1
  38. package/cjs/graph/animation/config.js +9 -7
  39. package/cjs/graph/animation/config.js.map +1 -1
  40. package/cjs/graph/animation/morph.js +4 -4
  41. package/cjs/graph/animation/morph.js.map +1 -1
  42. package/cjs/graph/attributes/line.d.ts +1 -0
  43. package/cjs/graph/attributes/line.js +11 -3
  44. package/cjs/graph/attributes/line.js.map +1 -1
  45. package/cjs/graph/attributes/transform.js +0 -24
  46. package/cjs/graph/attributes/transform.js.map +1 -1
  47. package/cjs/graph/canvas-renderer.d.ts +1 -1
  48. package/cjs/graph/canvas-renderer.js +5 -5
  49. package/cjs/graph/canvas-renderer.js.map +1 -1
  50. package/cjs/graph/constants.d.ts +1 -0
  51. package/cjs/graph/constants.js +3 -3
  52. package/cjs/graph/constants.js.map +1 -1
  53. package/cjs/graph/element.d.ts +2 -2
  54. package/cjs/graph/element.js +9 -10
  55. package/cjs/graph/element.js.map +1 -1
  56. package/cjs/graph/glyph-element.d.ts +1 -1
  57. package/cjs/graph/glyph-element.js.map +1 -1
  58. package/cjs/graph/mark/graphic.d.ts +22 -0
  59. package/cjs/graph/mark/graphic.js +138 -0
  60. package/cjs/graph/mark/graphic.js.map +1 -0
  61. package/cjs/graph/mark/large-rects.d.ts +2 -2
  62. package/cjs/graph/mark/large-rects.js +3 -3
  63. package/cjs/graph/mark/large-rects.js.map +1 -1
  64. package/cjs/graph/mark/large-symbols.d.ts +2 -2
  65. package/cjs/graph/mark/large-symbols.js +3 -3
  66. package/cjs/graph/mark/large-symbols.js.map +1 -1
  67. package/cjs/graph/util/env.js +2 -2
  68. package/cjs/graph/util/env.js.map +1 -1
  69. package/cjs/graph/util/events-extend.d.ts +1 -1
  70. package/cjs/graph/util/events-extend.js.map +1 -1
  71. package/cjs/graph/util/graphic.d.ts +3 -5
  72. package/cjs/graph/util/graphic.js +12 -28
  73. package/cjs/graph/util/graphic.js.map +1 -1
  74. package/cjs/index.d.ts +5 -2
  75. package/cjs/index.js +34 -5
  76. package/cjs/index.js.map +1 -1
  77. package/cjs/interactions/brush-active.d.ts +1 -1
  78. package/cjs/interactions/brush-active.js.map +1 -1
  79. package/cjs/interactions/brush-base.d.ts +1 -1
  80. package/cjs/interactions/brush-base.js.map +1 -1
  81. package/cjs/interactions/brush-filter.d.ts +1 -1
  82. package/cjs/interactions/brush-filter.js.map +1 -1
  83. package/cjs/interactions/brush-highlight.d.ts +1 -1
  84. package/cjs/interactions/brush-highlight.js.map +1 -1
  85. package/cjs/interactions/crosshair.js.map +1 -1
  86. package/cjs/interactions/drill-down.d.ts +1 -1
  87. package/cjs/interactions/drill-down.js.map +1 -1
  88. package/cjs/parse/scale.js +1 -1
  89. package/cjs/parse/scale.js.map +1 -1
  90. package/cjs/semantic-marks/cell.d.ts +1 -1
  91. package/cjs/semantic-marks/interval.d.ts +1 -1
  92. package/cjs/semantic-marks/interval.js +4 -2
  93. package/cjs/semantic-marks/interval.js.map +1 -1
  94. package/cjs/transforms/data/contour.js +2 -1
  95. package/cjs/transforms/data/contour.js.map +1 -1
  96. package/cjs/transforms/data/sampling.js +3 -3
  97. package/cjs/transforms/data/sampling.js.map +1 -1
  98. package/cjs/transforms/data/unfold.js +2 -2
  99. package/cjs/transforms/data/unfold.js.map +1 -1
  100. package/cjs/transforms/mark/symmetry.js +2 -1
  101. package/cjs/transforms/mark/symmetry.js.map +1 -1
  102. package/cjs/transforms/util/util.d.ts +0 -2
  103. package/cjs/transforms/util/util.js +2 -11
  104. package/cjs/transforms/util/util.js.map +1 -1
  105. package/cjs/types/animate.d.ts +3 -1
  106. package/cjs/types/animate.js.map +1 -1
  107. package/cjs/types/component.d.ts +5 -5
  108. package/cjs/types/component.js.map +1 -1
  109. package/cjs/types/element.d.ts +1 -1
  110. package/cjs/types/element.js.map +1 -1
  111. package/cjs/types/event.d.ts +1 -1
  112. package/cjs/types/event.js.map +1 -1
  113. package/cjs/types/grammar.d.ts +5 -5
  114. package/cjs/types/grammar.js.map +1 -1
  115. package/cjs/types/interaction.d.ts +1 -1
  116. package/cjs/types/interaction.js.map +1 -1
  117. package/cjs/types/mark.d.ts +1 -1
  118. package/cjs/types/mark.js.map +1 -1
  119. package/cjs/types/morph.d.ts +1 -1
  120. package/cjs/types/morph.js.map +1 -1
  121. package/cjs/types/plot.d.ts +1 -1
  122. package/cjs/types/plot.js.map +1 -1
  123. package/cjs/types/renderer.d.ts +1 -1
  124. package/cjs/types/renderer.js.map +1 -1
  125. package/cjs/types/theme.d.ts +1 -1
  126. package/cjs/types/theme.js.map +1 -1
  127. package/cjs/types/view.d.ts +1 -1
  128. package/cjs/types/view.js.map +1 -1
  129. package/cjs/util/text.d.ts +1 -1
  130. package/cjs/util/text.js +3 -3
  131. package/cjs/util/text.js.map +1 -1
  132. package/cjs/view/View.d.ts +1 -1
  133. package/cjs/view/View.js +17 -14
  134. package/cjs/view/View.js.map +1 -1
  135. package/cjs/view/component.d.ts +1 -1
  136. package/cjs/view/coordinate.d.ts +1 -0
  137. package/cjs/view/coordinate.js +8 -2
  138. package/cjs/view/coordinate.js.map +1 -1
  139. package/cjs/view/mark.d.ts +4 -4
  140. package/cjs/view/mark.js +12 -8
  141. package/cjs/view/mark.js.map +1 -1
  142. package/cjs/view/scale.d.ts +1 -0
  143. package/cjs/view/scale.js +8 -2
  144. package/cjs/view/scale.js.map +1 -1
  145. package/es/component/axis.js.map +1 -1
  146. package/es/component/datazoom.js.map +1 -1
  147. package/es/component/grid.js.map +1 -1
  148. package/es/component/label.js +1 -0
  149. package/es/component/label.js.map +1 -1
  150. package/es/component/legend.js.map +1 -1
  151. package/es/component/player.js.map +1 -1
  152. package/es/component/scrollbar.js.map +1 -1
  153. package/es/component/slider.js.map +1 -1
  154. package/es/component/title.d.ts +4 -3
  155. package/es/component/title.js.map +1 -1
  156. package/es/core/factory.d.ts +8 -4
  157. package/es/core/factory.js +8 -3
  158. package/es/core/factory.js.map +1 -1
  159. package/es/env.d.ts +1 -1
  160. package/es/env.js +2 -2
  161. package/es/env.js.map +1 -1
  162. package/es/glyph/boxplot.js +4 -1
  163. package/es/glyph/boxplot.js.map +1 -1
  164. package/es/glyph/link-path.js +4 -1
  165. package/es/glyph/link-path.js.map +1 -1
  166. package/es/glyph/ripple.js +3 -1
  167. package/es/glyph/ripple.js.map +1 -1
  168. package/es/glyph/tree-path.js +4 -1
  169. package/es/glyph/tree-path.js.map +1 -1
  170. package/es/glyph/violin.js +4 -1
  171. package/es/glyph/violin.js.map +1 -1
  172. package/es/glyph/wave.js +3 -1
  173. package/es/glyph/wave.js.map +1 -1
  174. package/es/graph/animation/animate.js +4 -3
  175. package/es/graph/animation/animate.js.map +1 -1
  176. package/es/graph/animation/animation/grow-cartesian.js.map +1 -1
  177. package/es/graph/animation/animator.js +3 -2
  178. package/es/graph/animation/animator.js.map +1 -1
  179. package/es/graph/animation/attribute.d.ts +2 -2
  180. package/es/graph/animation/attribute.js +1 -1
  181. package/es/graph/animation/attribute.js.map +1 -1
  182. package/es/graph/animation/config.js +10 -8
  183. package/es/graph/animation/config.js.map +1 -1
  184. package/es/graph/animation/morph.js +1 -1
  185. package/es/graph/animation/morph.js.map +1 -1
  186. package/es/graph/attributes/line.d.ts +1 -0
  187. package/es/graph/attributes/line.js +8 -1
  188. package/es/graph/attributes/line.js.map +1 -1
  189. package/es/graph/attributes/transform.js +0 -24
  190. package/es/graph/attributes/transform.js.map +1 -1
  191. package/es/graph/canvas-renderer.d.ts +1 -1
  192. package/es/graph/canvas-renderer.js +2 -2
  193. package/es/graph/canvas-renderer.js.map +1 -1
  194. package/es/graph/constants.d.ts +1 -0
  195. package/es/graph/constants.js +2 -0
  196. package/es/graph/constants.js.map +1 -1
  197. package/es/graph/element.d.ts +2 -2
  198. package/es/graph/element.js +9 -10
  199. package/es/graph/element.js.map +1 -1
  200. package/es/graph/glyph-element.d.ts +1 -1
  201. package/es/graph/glyph-element.js.map +1 -1
  202. package/es/graph/mark/graphic.d.ts +22 -0
  203. package/es/graph/mark/graphic.js +98 -0
  204. package/es/graph/mark/graphic.js.map +1 -0
  205. package/es/graph/mark/large-rects.d.ts +2 -2
  206. package/es/graph/mark/large-rects.js +1 -1
  207. package/es/graph/mark/large-rects.js.map +1 -1
  208. package/es/graph/mark/large-symbols.d.ts +2 -2
  209. package/es/graph/mark/large-symbols.js +1 -1
  210. package/es/graph/mark/large-symbols.js.map +1 -1
  211. package/es/graph/util/env.js +1 -1
  212. package/es/graph/util/env.js.map +1 -1
  213. package/es/graph/util/events-extend.d.ts +1 -1
  214. package/es/graph/util/events-extend.js.map +1 -1
  215. package/es/graph/util/graphic.d.ts +3 -5
  216. package/es/graph/util/graphic.js +13 -35
  217. package/es/graph/util/graphic.js.map +1 -1
  218. package/es/index.d.ts +5 -2
  219. package/es/index.js +8 -2
  220. package/es/index.js.map +1 -1
  221. package/es/interactions/brush-active.d.ts +1 -1
  222. package/es/interactions/brush-active.js.map +1 -1
  223. package/es/interactions/brush-base.d.ts +1 -1
  224. package/es/interactions/brush-base.js.map +1 -1
  225. package/es/interactions/brush-filter.d.ts +1 -1
  226. package/es/interactions/brush-filter.js +2 -1
  227. package/es/interactions/brush-filter.js.map +1 -1
  228. package/es/interactions/brush-highlight.d.ts +1 -1
  229. package/es/interactions/brush-highlight.js.map +1 -1
  230. package/es/interactions/crosshair.js.map +1 -1
  231. package/es/interactions/drill-down.d.ts +1 -1
  232. package/es/interactions/drill-down.js.map +1 -1
  233. package/es/interactions/element-highlight-by-group.js +1 -2
  234. package/es/interactions/index.js +2 -1
  235. package/es/interactions/legend-filter.js +1 -1
  236. package/es/interactions/player-filter.js +1 -1
  237. package/es/interactions/roll-up.js +1 -1
  238. package/es/interactions/scrollbar-filter.js +1 -1
  239. package/es/interactions/slider-filter.js +1 -1
  240. package/es/interactions/tooltip.js +1 -1
  241. package/es/interactions/view-drag-mixin.js +1 -1
  242. package/es/parse/coordinate.js +1 -1
  243. package/es/parse/event.js +1 -1
  244. package/es/parse/mark.js +1 -1
  245. package/es/parse/option.js +1 -1
  246. package/es/parse/scale.js +3 -4
  247. package/es/parse/scale.js.map +1 -1
  248. package/es/parse/transform.js +1 -1
  249. package/es/parse/util.js +1 -1
  250. package/es/parse/view.js +1 -1
  251. package/es/semantic-marks/cell.d.ts +1 -1
  252. package/es/semantic-marks/interval.d.ts +1 -1
  253. package/es/semantic-marks/interval.js +3 -3
  254. package/es/semantic-marks/interval.js.map +1 -1
  255. package/es/transforms/data/contour.js +2 -2
  256. package/es/transforms/data/contour.js.map +1 -1
  257. package/es/transforms/data/sampling.js +5 -3
  258. package/es/transforms/data/sampling.js.map +1 -1
  259. package/es/transforms/data/unfold.js +3 -3
  260. package/es/transforms/data/unfold.js.map +1 -1
  261. package/es/transforms/mark/symmetry.js +2 -2
  262. package/es/transforms/mark/symmetry.js.map +1 -1
  263. package/es/transforms/util/util.d.ts +0 -2
  264. package/es/transforms/util/util.js +0 -8
  265. package/es/transforms/util/util.js.map +1 -1
  266. package/es/types/animate.d.ts +3 -1
  267. package/es/types/animate.js.map +1 -1
  268. package/es/types/component.d.ts +5 -5
  269. package/es/types/component.js.map +1 -1
  270. package/es/types/element.d.ts +1 -1
  271. package/es/types/element.js.map +1 -1
  272. package/es/types/event.d.ts +1 -1
  273. package/es/types/event.js.map +1 -1
  274. package/es/types/grammar.d.ts +5 -5
  275. package/es/types/grammar.js.map +1 -1
  276. package/es/types/interaction.d.ts +1 -1
  277. package/es/types/interaction.js.map +1 -1
  278. package/es/types/mark.d.ts +1 -1
  279. package/es/types/mark.js.map +1 -1
  280. package/es/types/morph.d.ts +1 -1
  281. package/es/types/morph.js.map +1 -1
  282. package/es/types/plot.d.ts +1 -1
  283. package/es/types/plot.js.map +1 -1
  284. package/es/types/renderer.d.ts +1 -1
  285. package/es/types/renderer.js.map +1 -1
  286. package/es/types/theme.d.ts +1 -1
  287. package/es/types/theme.js.map +1 -1
  288. package/es/types/view.d.ts +1 -1
  289. package/es/types/view.js.map +1 -1
  290. package/es/util/text.d.ts +1 -1
  291. package/es/util/text.js +1 -1
  292. package/es/util/text.js.map +1 -1
  293. package/es/view/View.d.ts +1 -1
  294. package/es/view/View.js +11 -12
  295. package/es/view/View.js.map +1 -1
  296. package/es/view/component.d.ts +1 -1
  297. package/es/view/coordinate.d.ts +1 -0
  298. package/es/view/coordinate.js +6 -0
  299. package/es/view/coordinate.js.map +1 -1
  300. package/es/view/mark.d.ts +4 -4
  301. package/es/view/mark.js +12 -7
  302. package/es/view/mark.js.map +1 -1
  303. package/es/view/scale.d.ts +1 -0
  304. package/es/view/scale.js +6 -0
  305. package/es/view/scale.js.map +1 -1
  306. package/package.json +11 -12
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/semantic-marks/interval.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAUjE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,OAAO,QAAS,SAAQ,IAAI;IAOhC,WAAW,CAAC,KAAa,EAAE,OAAsC,EAAE,KAA6B;QAC9F,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAEzC,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QAErC,OAAO,IAAI,CAAC;IACd,CAAC;IAES,wBAAwB,CAAC,KAAa;QAC9C,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACn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K,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO;QACL,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;;AAtIM,iBAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;AAyI7C,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC,CAAC","file":"interval.js","sourcesContent":["import type { IBandLikeScale, IBaseScale } from '@visactor/vscale';\n// eslint-disable-next-line no-duplicate-imports\nimport { ScaleEnum } from '@visactor/vscale';\nimport { GrammarMarkType } from '../graph/enums';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { isScaleEncode } from '../parse/mark';\nimport { getGrammarOutput, isFunctionType } from '../parse/util';\nimport type {\n StateEncodeSpec,\n MarkSpec,\n IElement,\n MarkFunctionType,\n AttributeTransform,\n GetSignleEncodeSpecByType,\n BaseSignleEncodeSpec\n} from '../types';\nimport { Mark } from '../view/mark';\nimport { isNil } from '@visactor/vutils';\nimport { createGraphicItem } from '../graph/util/graphic';\nimport type { IPolarCoordinate } from '@visactor/vgrammar-coordinate';\nimport { transformsByType } from '../graph/attributes/transform';\nimport { Factory } from '../core/factory';\n\nexport class Interval extends Mark {\n static markType = GrammarMarkType.interval;\n declare markType: GrammarMarkType.interval;\n protected declare spec: MarkSpec;\n\n protected _encoders: StateEncodeSpec;\n\n encodeState(state: string, channel: string | BaseSignleEncodeSpec, value?: MarkFunctionType<any>) {\n super.encodeState(state, channel, value);\n\n this._updateComponentEncoders(state);\n\n return this;\n }\n\n protected _updateComponentEncoders(state: string) {\n if (!this._encoders) {\n this._encoders = {};\n }\n\n const userEncoder = this.spec.encode[state] as GetSignleEncodeSpecByType<'interval'>;\n\n if (userEncoder && state === 'update') {\n const params = this.parameters();\n const scales: Record<string, IBaseScale> = isFunctionType(userEncoder)\n ? null\n : Object.keys(userEncoder).reduce((res, channel) => {\n if (isScaleEncode(userEncoder[channel])) {\n res[channel] = getGrammarOutput(userEncoder[channel].scale, params);\n }\n return res;\n }, {});\n\n this._encoders[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const userEncodeRes = invokeEncoder(userEncoder, datum, element, parameters);\n\n this.disableCoordinateTransform = false;\n if (scales && scales.x && scales.x.type === ScaleEnum.Band) {\n if (!isNil(scales.y)) {\n const domain = scales.y.domain();\n const min = Math.min.apply(null, domain);\n const max = Math.max.apply(null, domain);\n const baseValue = min > 0 ? min : max < 0 ? max : 0;\n\n userEncodeRes.y1 = scales.y.scale(baseValue);\n }\n const bandWidth = (scales.x as IBandLikeScale).bandwidth();\n\n // TODO: handle bandWidth dynamically\n userEncodeRes.x = userEncodeRes.x + bandWidth / 4;\n userEncodeRes.x1 = userEncodeRes.x + bandWidth / 2;\n } else if (scales && scales.y && scales.y.type === ScaleEnum.Band) {\n if (!isNil(scales.x)) {\n const domain = scales.x.domain();\n const min = Math.min.apply(null, domain);\n const max = Math.max.apply(null, domain);\n const baseValue = min > 0 ? min : max < 0 ? max : 0;\n\n userEncodeRes.x1 = scales.x.scale(baseValue);\n }\n const bandWidth = (scales.y as IBandLikeScale).bandwidth();\n\n userEncodeRes.y = userEncodeRes.y + bandWidth / 4;\n userEncodeRes.y1 = userEncodeRes.y + bandWidth / 2;\n }\n\n if (scales) {\n const scaleGrammar =\n this.view.getScaleById((userEncoder as any).x?.scale) ??\n this.view.getScaleById((userEncoder as any).y?.scale);\n const coord = scaleGrammar.getCoordinate();\n\n if (coord && coord.type === 'polar') {\n this.disableCoordinateTransform = true;\n const origin = (coord as IPolarCoordinate).origin();\n userEncodeRes.cx = origin.x;\n userEncodeRes.cy = origin.y;\n }\n }\n\n return userEncodeRes;\n }\n } as GetSignleEncodeSpecByType<'interval'>;\n } else {\n this._encoders[state] = userEncoder;\n }\n }\n\n protected _getEncoders() {\n return this._encoders ?? {};\n }\n\n getAttributeTransforms() {\n if (this.coord && this.coord.output().type === 'polar') {\n return [\n {\n channels: ['x', 'y', 'x1', 'y1', 'cx', 'cy'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = storedAttrs.cx;\n graphicAttributes.y = storedAttrs.cy;\n if (this.coord.output().isTransposed()) {\n graphicAttributes.startAngle = storedAttrs.y;\n graphicAttributes.endAngle = storedAttrs.y1;\n graphicAttributes.innerRadius = storedAttrs.x;\n graphicAttributes.outerRadius = storedAttrs.x1;\n } else {\n //\n graphicAttributes.startAngle = storedAttrs.x;\n graphicAttributes.endAngle = storedAttrs.x1;\n graphicAttributes.innerRadius = storedAttrs.y;\n graphicAttributes.outerRadius = storedAttrs.y1;\n }\n },\n storedAttrs: 'sizeAttrs'\n }\n ] as AttributeTransform[];\n }\n\n return transformsByType.rect;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const graphicItem = createGraphicItem(\n this,\n this.coord && this.coord.output().type === 'polar' ? GrammarMarkType.arc : GrammarMarkType.rect,\n attrs\n );\n\n return super.addGraphicItem(attrs, groupKey, graphicItem);\n }\n\n release(): void {\n super.release();\n this._encoders = null;\n }\n}\n\nexport const registerIntervalMark = () => {\n Factory.registerMark(GrammarMarkType.interval, Interval);\n};\n"]}
1
+ {"version":3,"sources":["../src/semantic-marks/interval.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAUjE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,UAAU,EAA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,CAAC;SAC3B;QAED,OAAO,gBAAgB,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,cAAc,CAAC,KAAU,EAAE,QAAiB;QAC1C,MAAM,WAAW,GAAG,iBAAiB,CACnC,IAAI,EACJ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,EAC/F,KAAK,CACN,CAAC;QAEF,OAAO,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO;QACL,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;;AAtIM,iBAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;AAyI7C,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC,CAAC","file":"interval.js","sourcesContent":["import type { IBandLikeScale, IBaseScale } from '@visactor/vscale';\n// eslint-disable-next-line no-duplicate-imports\nimport { ScaleEnum } from '@visactor/vscale';\nimport { GrammarMarkType } from '../graph/enums';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { isScaleEncode } from '../parse/mark';\nimport { getGrammarOutput, isFunctionType } from '../parse/util';\nimport type {\n StateEncodeSpec,\n MarkSpec,\n IElement,\n MarkFunctionType,\n AttributeTransform,\n GetSignleEncodeSpecByType,\n BaseSignleEncodeSpec\n} from '../types';\nimport { Mark } from '../view/mark';\nimport { isNil, maxInArray, minInArray } from '@visactor/vutils';\nimport { createGraphicItem } from '../graph/util/graphic';\nimport type { IPolarCoordinate } from '@visactor/vgrammar-coordinate';\nimport { transformsByType } from '../graph/attributes/transform';\nimport { Factory } from '../core/factory';\n\nexport class Interval extends Mark {\n static markType = GrammarMarkType.interval;\n declare markType: GrammarMarkType.interval;\n protected declare spec: MarkSpec;\n\n protected _encoders: StateEncodeSpec;\n\n encodeState(state: string, channel: string | BaseSignleEncodeSpec, value?: MarkFunctionType<any>) {\n super.encodeState(state, channel, value);\n\n this._updateComponentEncoders(state);\n\n return this;\n }\n\n protected _updateComponentEncoders(state: string) {\n if (!this._encoders) {\n this._encoders = {};\n }\n\n const userEncoder = this.spec.encode[state] as GetSignleEncodeSpecByType<'interval'>;\n\n if (userEncoder && state === 'update') {\n const params = this.parameters();\n const scales: Record<string, IBaseScale> = isFunctionType(userEncoder)\n ? null\n : Object.keys(userEncoder).reduce((res, channel) => {\n if (isScaleEncode(userEncoder[channel])) {\n res[channel] = getGrammarOutput(userEncoder[channel].scale, params);\n }\n return res;\n }, {});\n\n this._encoders[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const userEncodeRes = invokeEncoder(userEncoder, datum, element, parameters);\n\n this.disableCoordinateTransform = false;\n if (scales && scales.x && scales.x.type === ScaleEnum.Band) {\n if (!isNil(scales.y)) {\n const domain = scales.y.domain();\n const min = minInArray<number>(domain);\n const max = maxInArray<number>(domain);\n const baseValue = min > 0 ? min : max < 0 ? max : 0;\n\n userEncodeRes.y1 = scales.y.scale(baseValue);\n }\n const bandWidth = (scales.x as IBandLikeScale).bandwidth();\n\n // TODO: handle bandWidth dynamically\n userEncodeRes.x = userEncodeRes.x + bandWidth / 4;\n userEncodeRes.x1 = userEncodeRes.x + bandWidth / 2;\n } else if (scales && scales.y && scales.y.type === ScaleEnum.Band) {\n if (!isNil(scales.x)) {\n const domain = scales.x.domain();\n const min = minInArray(domain);\n const max = maxInArray(domain);\n const baseValue = min > 0 ? min : max < 0 ? max : 0;\n\n userEncodeRes.x1 = scales.x.scale(baseValue);\n }\n const bandWidth = (scales.y as IBandLikeScale).bandwidth();\n\n userEncodeRes.y = userEncodeRes.y + bandWidth / 4;\n userEncodeRes.y1 = userEncodeRes.y + bandWidth / 2;\n }\n\n if (scales) {\n const scaleGrammar =\n this.view.getScaleById((userEncoder as any).x?.scale) ??\n this.view.getScaleById((userEncoder as any).y?.scale);\n const coord = scaleGrammar.getCoordinate();\n\n if (coord && coord.type === 'polar') {\n this.disableCoordinateTransform = true;\n const origin = (coord as IPolarCoordinate).origin();\n userEncodeRes.cx = origin.x;\n userEncodeRes.cy = origin.y;\n }\n }\n\n return userEncodeRes;\n }\n } as GetSignleEncodeSpecByType<'interval'>;\n } else {\n this._encoders[state] = userEncoder;\n }\n }\n\n protected _getEncoders() {\n return this._encoders ?? {};\n }\n\n getAttributeTransforms() {\n if (this.coord && this.coord.output().type === 'polar') {\n return [\n {\n channels: ['x', 'y', 'x1', 'y1', 'cx', 'cy'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = storedAttrs.cx;\n graphicAttributes.y = storedAttrs.cy;\n if (this.coord.output().isTransposed()) {\n graphicAttributes.startAngle = storedAttrs.y;\n graphicAttributes.endAngle = storedAttrs.y1;\n graphicAttributes.innerRadius = storedAttrs.x;\n graphicAttributes.outerRadius = storedAttrs.x1;\n } else {\n //\n graphicAttributes.startAngle = storedAttrs.x;\n graphicAttributes.endAngle = storedAttrs.x1;\n graphicAttributes.innerRadius = storedAttrs.y;\n graphicAttributes.outerRadius = storedAttrs.y1;\n }\n },\n storedAttrs: 'sizeAttrs'\n }\n ] as AttributeTransform[];\n }\n\n return transformsByType.rect;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const graphicItem = createGraphicItem(\n this,\n this.coord && this.coord.output().type === 'polar' ? GrammarMarkType.arc : GrammarMarkType.rect,\n attrs\n );\n\n return super.addGraphicItem(attrs, groupKey, graphicItem);\n }\n\n release(): void {\n super.release();\n this._encoders = null;\n }\n}\n\nexport const registerIntervalMark = () => {\n Factory.registerMark(GrammarMarkType.interval, Interval);\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { isValid, isValidNumber } from "@visactor/vutils";
1
+ import { isValid, isValidNumber, maxInArray, minInArray } from "@visactor/vutils";
2
2
 
3
3
  const computeInteractionPoint = (xIndex, yIndex, cell, cellRow, cellColumn, threshold) => {
4
4
  const thresholdCell = [ cell[0] >= threshold ? 1 : 0, cell[1] >= threshold ? 1 : 0, cell[2] >= threshold ? 1 : 0, cell[3] >= threshold ? 1 : 0 ], points = [];
@@ -72,7 +72,7 @@ const computeInteractionPoint = (xIndex, yIndex, cell, cellRow, cellColumn, thre
72
72
  export const transform = (options, upstreamData) => {
73
73
  var _a;
74
74
  if (!upstreamData || 0 === upstreamData.length) return upstreamData;
75
- const row = options.row, column = options.column, cellRow = row - 1, cellColumn = column - 1, data = upstreamData.map((datum => datum[options.field])), extent = [ Math.min.apply(null, data), Math.max.apply(null, data) ], thresholds = null !== (_a = options.thresholds) && void 0 !== _a ? _a : [];
75
+ const row = options.row, column = options.column, cellRow = row - 1, cellColumn = column - 1, data = upstreamData.map((datum => datum[options.field])), extent = [ minInArray(data), maxInArray(data) ], thresholds = null !== (_a = options.thresholds) && void 0 !== _a ? _a : [];
76
76
  if (!isValid(options.thresholds) && isValidNumber(options.levels)) {
77
77
  const step = (extent[1] - extent[0]) / options.levels;
78
78
  for (let i = 1; i < options.levels; i++) thresholds.push(extent[0] + i * step);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transforms/data/contour.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAW1D,MAAM,uBAAuB,GAAG,CAC9B,MAAc,EACd,MAAc,EACd,IAAsC,EACtC,OAAe,EACf,UAAkB,EAClB,SAAiB,EACjB,EAAE;IACF,MAAM,aAAa,GAAG;QACpB,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,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ACvE,gBAAgB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC9B,IAAI,eAAe,CAAC,MAAM,EAAE;gBAC1B,MAAM,iBAAiB,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACjE,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;gBAE3F,MAAM,OAAO,GAAG;oBACd,CAAC,MAAA,OAAO,CAAC,WAAW,mCAAI,WAAW,CAAC,EAAE,SAAS;oBAC/C,CAAC,MAAA,OAAO,CAAC,QAAQ,mCAAI,QAAQ,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;wBAE1D,OAAO;4BACL,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG;4BACtB,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,MAAM;yBAC1B,CAAC;oBACJ,CAAC,CAAC;iBACH,CAAC;gBACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACxB;SACF,QAAQ,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;IACxC,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","file":"contour.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isValid, isValidNumber } from '@visactor/vutils';\nimport type { ContourTransformOption } from '../../types';\n\ntype InteractionPoint = {\n id: string;\n currentCell: number;\n nextCell: number;\n point: IPointLike;\n siblingPoint: InteractionPoint;\n};\n\nconst computeInteractionPoint = (\n xIndex: number,\n yIndex: number,\n cell: [number, number, number, number],\n cellRow: number,\n cellColumn: number,\n threshold: number\n) => {\n const thresholdCell = [\n cell[0] >= threshold ? 1 : 0,\n cell[1] >= threshold ? 1 : 0,\n cell[2] >= threshold ? 1 : 0,\n cell[3] >= threshold ? 1 : 0\n ];\n\n const points: InteractionPoint[] = [];\n if (thresholdCell[0] !== thresholdCell[1]) {\n points.push({\n id: `${xIndex}-${yIndex - 1}-${xIndex}-${yIndex}`,\n currentCell: yIndex * cellColumn + xIndex,\n nextCell: (yIndex - 1) * cellColumn + xIndex,\n point: {\n x: xIndex + (threshold - cell[0]) / (cell[1] - cell[0]),\n y: yIndex\n },\n siblingPoint: null\n });\n }\n if (thresholdCell[1] !== thresholdCell[2]) {\n points.push({\n id: `${xIndex}-${yIndex}-${xIndex + 1}-${yIndex}`,\n currentCell: yIndex * cellColumn + xIndex,\n nextCell: yIndex * cellColumn + xIndex + 1,\n point: {\n x: xIndex + 1,\n y: yIndex + (threshold - cell[1]) / (cell[2] - cell[1])\n },\n siblingPoint: null\n });\n }\n if (thresholdCell[2] !== thresholdCell[3]) {\n points.push({\n id: `${xIndex}-${yIndex}-${xIndex}-${yIndex + 1}`,\n currentCell: yIndex * cellColumn + xIndex,\n nextCell: (yIndex + 1) * cellColumn + xIndex,\n point: {\n x: xIndex + (threshold - cell[3]) / (cell[2] - cell[3]),\n y: yIndex + 1\n },\n siblingPoint: null\n });\n }\n if (thresholdCell[3] !== thresholdCell[0]) {\n points.push({\n id: `${xIndex - 1}-${yIndex}-${xIndex}-${yIndex}`,\n currentCell: yIndex * cellColumn + xIndex,\n nextCell: yIndex * cellColumn + xIndex - 1,\n point: {\n x: xIndex,\n y: yIndex + (threshold - cell[0]) / (cell[3] - cell[0])\n },\n siblingPoint: null\n });\n }\n\n const thresholdFlag =\n (thresholdCell[0] & 0b1000) +\n (thresholdCell[1] & 0b0100) +\n (thresholdCell[2] & 0b0010) +\n (thresholdCell[3] & 0b0001);\n if (thresholdFlag === 0b0110 || thresholdFlag === 0b1001) {\n points[0].siblingPoint = points[1];\n points[1].siblingPoint = points[0];\n points[2].siblingPoint = points[3];\n points[3].siblingPoint = points[2];\n } else if (points.length === 2) {\n points[0].siblingPoint = points[1];\n points[1].siblingPoint = points[0];\n }\n return points;\n};\n\nconst connectPoints = (point: InteractionPoint, grid: InteractionPoint[][]) => {\n const siblingPoint = point.siblingPoint;\n\n const connectResult = connectNextPoints(point, grid);\n if (connectResult.result === 'loop') {\n return connectResult.points;\n }\n const frontConnect = connectNextPoints(siblingPoint, grid);\n return frontConnect.points.reverse().concat(connectResult.points);\n};\n\nconst connectNextPoints = (point: InteractionPoint, grid: InteractionPoint[][]) => {\n const connectedPoints: InteractionPoint[] = [point];\n let currentPoint: InteractionPoint = point;\n const find = (p: InteractionPoint) => p.id === currentPoint.id;\n let result = 'break';\n do {\n const nextCell = grid[currentPoint.nextCell];\n const nextCellPoint = nextCell?.find(find);\n if (nextCellPoint) {\n currentPoint = nextCellPoint.siblingPoint;\n if (connectedPoints.includes(currentPoint)) {\n result = 'loop';\n // close the looped line\n connectedPoints.push(currentPoint);\n break;\n } else if (!currentPoint) {\n break;\n }\n connectedPoints.push(currentPoint);\n } else {\n currentPoint = null;\n }\n } while (currentPoint);\n return { points: connectedPoints, result };\n};\n\nexport const transform = (options: ContourTransformOption, upstreamData: any[]) => {\n if (!upstreamData || upstreamData.length === 0) {\n return upstreamData;\n }\n\n const row = options.row;\n const column = options.column;\n const cellRow = row - 1;\n const cellColumn = column - 1;\n\n const data = upstreamData.map(datum => datum[options.field]);\n const extent = [Math.min.apply(null, data), Math.max.apply(null, data)];\n const thresholds = options.thresholds ?? [];\n if (!isValid(options.thresholds) && isValidNumber(options.levels)) {\n const step = (extent[1] - extent[0]) / options.levels;\n for (let i = 1; i < options.levels; i++) {\n thresholds.push(extent[0] + i * step);\n }\n }\n\n // the cell value is stored like this:\n // top-left, top-right, bottom-right, bottom-left\n // tl - tr O - X\n // | | |\n // bl - br Y\n // the actually position in canvas does not effect the result of contouring\n const cells: [number, number, number, number][] = [];\n // data grid is row*column\n for (let yIndex = 1; yIndex < row; yIndex++) {\n for (let xIndex = 1; xIndex < column; xIndex++) {\n const topLeft = data[(yIndex - 1) * column + xIndex - 1];\n const topRight = data[(yIndex - 1) * column + xIndex];\n const bottomRight = data[yIndex * column + xIndex];\n const bottomLeft = data[yIndex * column + xIndex - 1];\n cells.push([topLeft, topRight, bottomRight, bottomLeft]);\n }\n }\n\n const contours: any[] = [];\n\n thresholds.forEach(threshold => {\n // compute intersection points\n const points: InteractionPoint[] = [];\n const gridPoints: InteractionPoint[][] = [];\n // cell grid is (row-1)*(column-1)\n for (let yIndex = 0; yIndex < cellRow; yIndex++) {\n for (let xIndex = 0; xIndex < cellColumn; xIndex++) {\n const cell = cells[yIndex * cellColumn + xIndex];\n const gridPoint = computeInteractionPoint(xIndex, yIndex, cell, cellRow, cellColumn, threshold);\n points.push(...gridPoint);\n gridPoints.push(gridPoint);\n }\n }\n\n // connect points\n let processingPoints = points.slice();\n do {\n const connectedPoints = connectPoints(processingPoints[0], gridPoints);\n processingPoints.splice(0, 1);\n if (connectedPoints.length) {\n const connectedPointIds = connectedPoints.map(point => point.id);\n processingPoints = processingPoints.filter(point => !connectedPointIds.includes(point.id));\n\n const contour = {\n [options.asThreshold ?? 'threshold']: threshold,\n [options.asPoints ?? 'points']: connectedPoints.map(point => {\n // normalize grid index into [0, 1]\n return {\n x: point.point.x / row,\n y: point.point.y / column\n };\n })\n };\n contours.push(contour);\n }\n } while (processingPoints.length > 0);\n });\n\n return contours;\n};\n"]}
1
+ {"version":3,"sources":["../src/transforms/data/contour.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAWlF,MAAM,uBAAuB,GAAG,CAC9B,MAAc,EACd,MAAc,EACd,IAAsC,EACtC,OAAe,EACf,UAAkB,EAClB,SAAiB,EACjB,EAAE;IACF,MAAM,aAAa,GAAG;QACpB,IAAI,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,C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AAE,UAAU,CAAC,CAAC;YACvE,gBAAgB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC9B,IAAI,eAAe,CAAC,MAAM,EAAE;gBAC1B,MAAM,iBAAiB,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACjE,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;gBAE3F,MAAM,OAAO,GAAG;oBACd,CAAC,MAAA,OAAO,CAAC,WAAW,mCAAI,WAAW,CAAC,EAAE,SAAS;oBAC/C,CAAC,MAAA,OAAO,CAAC,QAAQ,mCAAI,QAAQ,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;wBAE1D,OAAO;4BACL,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG;4BACtB,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,MAAM;yBAC1B,CAAC;oBACJ,CAAC,CAAC;iBACH,CAAC;gBACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACxB;SACF,QAAQ,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE;IACxC,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","file":"contour.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isValid, isValidNumber, maxInArray, minInArray } from '@visactor/vutils';\nimport type { ContourTransformOption } from '../../types';\n\ntype InteractionPoint = {\n id: string;\n currentCell: number;\n nextCell: number;\n point: IPointLike;\n siblingPoint: InteractionPoint;\n};\n\nconst computeInteractionPoint = (\n xIndex: number,\n yIndex: number,\n cell: [number, number, number, number],\n cellRow: number,\n cellColumn: number,\n threshold: number\n) => {\n const thresholdCell = [\n cell[0] >= threshold ? 1 : 0,\n cell[1] >= threshold ? 1 : 0,\n cell[2] >= threshold ? 1 : 0,\n cell[3] >= threshold ? 1 : 0\n ];\n\n const points: InteractionPoint[] = [];\n if (thresholdCell[0] !== thresholdCell[1]) {\n points.push({\n id: `${xIndex}-${yIndex - 1}-${xIndex}-${yIndex}`,\n currentCell: yIndex * cellColumn + xIndex,\n nextCell: (yIndex - 1) * cellColumn + xIndex,\n point: {\n x: xIndex + (threshold - cell[0]) / (cell[1] - cell[0]),\n y: yIndex\n },\n siblingPoint: null\n });\n }\n if (thresholdCell[1] !== thresholdCell[2]) {\n points.push({\n id: `${xIndex}-${yIndex}-${xIndex + 1}-${yIndex}`,\n currentCell: yIndex * cellColumn + xIndex,\n nextCell: yIndex * cellColumn + xIndex + 1,\n point: {\n x: xIndex + 1,\n y: yIndex + (threshold - cell[1]) / (cell[2] - cell[1])\n },\n siblingPoint: null\n });\n }\n if (thresholdCell[2] !== thresholdCell[3]) {\n points.push({\n id: `${xIndex}-${yIndex}-${xIndex}-${yIndex + 1}`,\n currentCell: yIndex * cellColumn + xIndex,\n nextCell: (yIndex + 1) * cellColumn + xIndex,\n point: {\n x: xIndex + (threshold - cell[3]) / (cell[2] - cell[3]),\n y: yIndex + 1\n },\n siblingPoint: null\n });\n }\n if (thresholdCell[3] !== thresholdCell[0]) {\n points.push({\n id: `${xIndex - 1}-${yIndex}-${xIndex}-${yIndex}`,\n currentCell: yIndex * cellColumn + xIndex,\n nextCell: yIndex * cellColumn + xIndex - 1,\n point: {\n x: xIndex,\n y: yIndex + (threshold - cell[0]) / (cell[3] - cell[0])\n },\n siblingPoint: null\n });\n }\n\n const thresholdFlag =\n (thresholdCell[0] & 0b1000) +\n (thresholdCell[1] & 0b0100) +\n (thresholdCell[2] & 0b0010) +\n (thresholdCell[3] & 0b0001);\n if (thresholdFlag === 0b0110 || thresholdFlag === 0b1001) {\n points[0].siblingPoint = points[1];\n points[1].siblingPoint = points[0];\n points[2].siblingPoint = points[3];\n points[3].siblingPoint = points[2];\n } else if (points.length === 2) {\n points[0].siblingPoint = points[1];\n points[1].siblingPoint = points[0];\n }\n return points;\n};\n\nconst connectPoints = (point: InteractionPoint, grid: InteractionPoint[][]) => {\n const siblingPoint = point.siblingPoint;\n\n const connectResult = connectNextPoints(point, grid);\n if (connectResult.result === 'loop') {\n return connectResult.points;\n }\n const frontConnect = connectNextPoints(siblingPoint, grid);\n return frontConnect.points.reverse().concat(connectResult.points);\n};\n\nconst connectNextPoints = (point: InteractionPoint, grid: InteractionPoint[][]) => {\n const connectedPoints: InteractionPoint[] = [point];\n let currentPoint: InteractionPoint = point;\n const find = (p: InteractionPoint) => p.id === currentPoint.id;\n let result = 'break';\n do {\n const nextCell = grid[currentPoint.nextCell];\n const nextCellPoint = nextCell?.find(find);\n if (nextCellPoint) {\n currentPoint = nextCellPoint.siblingPoint;\n if (connectedPoints.includes(currentPoint)) {\n result = 'loop';\n // close the looped line\n connectedPoints.push(currentPoint);\n break;\n } else if (!currentPoint) {\n break;\n }\n connectedPoints.push(currentPoint);\n } else {\n currentPoint = null;\n }\n } while (currentPoint);\n return { points: connectedPoints, result };\n};\n\nexport const transform = (options: ContourTransformOption, upstreamData: any[]) => {\n if (!upstreamData || upstreamData.length === 0) {\n return upstreamData;\n }\n\n const row = options.row;\n const column = options.column;\n const cellRow = row - 1;\n const cellColumn = column - 1;\n\n const data = upstreamData.map(datum => datum[options.field]);\n const extent = [minInArray(data), maxInArray(data)];\n const thresholds = options.thresholds ?? [];\n if (!isValid(options.thresholds) && isValidNumber(options.levels)) {\n const step = (extent[1] - extent[0]) / options.levels;\n for (let i = 1; i < options.levels; i++) {\n thresholds.push(extent[0] + i * step);\n }\n }\n\n // the cell value is stored like this:\n // top-left, top-right, bottom-right, bottom-left\n // tl - tr O - X\n // | | |\n // bl - br Y\n // the actually position in canvas does not effect the result of contouring\n const cells: [number, number, number, number][] = [];\n // data grid is row*column\n for (let yIndex = 1; yIndex < row; yIndex++) {\n for (let xIndex = 1; xIndex < column; xIndex++) {\n const topLeft = data[(yIndex - 1) * column + xIndex - 1];\n const topRight = data[(yIndex - 1) * column + xIndex];\n const bottomRight = data[yIndex * column + xIndex];\n const bottomLeft = data[yIndex * column + xIndex - 1];\n cells.push([topLeft, topRight, bottomRight, bottomLeft]);\n }\n }\n\n const contours: any[] = [];\n\n thresholds.forEach(threshold => {\n // compute intersection points\n const points: InteractionPoint[] = [];\n const gridPoints: InteractionPoint[][] = [];\n // cell grid is (row-1)*(column-1)\n for (let yIndex = 0; yIndex < cellRow; yIndex++) {\n for (let xIndex = 0; xIndex < cellColumn; xIndex++) {\n const cell = cells[yIndex * cellColumn + xIndex];\n const gridPoint = computeInteractionPoint(xIndex, yIndex, cell, cellRow, cellColumn, threshold);\n points.push(...gridPoint);\n gridPoints.push(gridPoint);\n }\n }\n\n // connect points\n let processingPoints = points.slice();\n do {\n const connectedPoints = connectPoints(processingPoints[0], gridPoints);\n processingPoints.splice(0, 1);\n if (connectedPoints.length) {\n const connectedPointIds = connectedPoints.map(point => point.id);\n processingPoints = processingPoints.filter(point => !connectedPointIds.includes(point.id));\n\n const contour = {\n [options.asThreshold ?? 'threshold']: threshold,\n [options.asPoints ?? 'points']: connectedPoints.map(point => {\n // normalize grid index into [0, 1]\n return {\n x: point.point.x / row,\n y: point.point.y / column\n };\n })\n };\n contours.push(contour);\n }\n } while (processingPoints.length > 0);\n });\n\n return contours;\n};\n"]}
@@ -1,8 +1,10 @@
1
- import { average, max, min, sum } from "../util/util";
1
+ import { maxInArray, minInArray } from "@visactor/vutils";
2
+
3
+ import { average, sum } from "../util/util";
2
4
 
3
5
  const samplerMap = {
4
- min: min,
5
- max: max,
6
+ min: minInArray,
7
+ max: maxInArray,
6
8
  average: average,
7
9
  sum: sum
8
10
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transforms/data/sampling.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE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C,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBAChF;YACH,CAAC,CAAC,CAAC;YAGH,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAEhC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;SAC9D;QACD,OAAO,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;KACrF;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC","file":"sampling.js","sourcesContent":["import type { SampleTransformOptions } from '../../types';\nimport { average, max, min, sum } from '../util/util';\n\nconst samplerMap = {\n min: min,\n max: max,\n average: average,\n sum: sum\n};\n\nfunction lttb(size: number, array: any[], isGroup: boolean, yfield: string) {\n const frameSize = Math.floor(array.length / size);\n const newIndices = [];\n const len = array.length;\n\n let currentIndex = 0;\n let sampledIndex = 0;\n let maxArea;\n let area;\n let nextIndex;\n\n // First frame use the first data.\n newIndices[sampledIndex++] = currentIndex;\n\n for (let i = 1; i < len - 1; i += frameSize) {\n const nextFrameStart = Math.min(i + frameSize, len - 1);\n const nextFrameEnd = Math.min(i + frameSize * 2, len);\n\n const avgX = (nextFrameEnd + nextFrameStart) / 2;\n let avgY = 0;\n\n for (let idx = nextFrameStart; idx < nextFrameEnd; idx++) {\n const value = array[idx][yfield];\n if (Number.isNaN(value)) {\n continue;\n }\n avgY += value;\n }\n avgY /= nextFrameEnd - nextFrameStart;\n\n const frameStart = i;\n const frameEnd = Math.min(i + frameSize, len);\n\n const pointAX = i - 1;\n const pointAY = array[currentIndex][yfield];\n\n maxArea = -1;\n\n nextIndex = frameStart;\n // Find a point from current frame that construct a triangel with largest area with previous selected point\n // And the average of next frame.\n for (let idx = frameStart; idx < frameEnd; idx++) {\n const value = array[idx][yfield];\n if (Number.isNaN(yfield)) {\n continue;\n }\n // Calculate triangle area over three buckets\n area = Math.abs((pointAX - avgX) * (value - pointAY) - (pointAX - idx) * (avgY - pointAY));\n if (area > maxArea) {\n maxArea = area;\n nextIndex = idx; // Next a is this b\n }\n }\n\n newIndices[sampledIndex++] = nextIndex;\n\n currentIndex = nextIndex; // This a is the next a (chosen b)\n }\n\n // First frame use the last data.\n if (newIndices[sampledIndex - 1] !== len - 1) {\n newIndices[sampledIndex++] = len - 1;\n }\n\n // output newly added tuples\n const newRawIndices = newIndices.map(i => (isGroup ? array[i].i : i));\n return newRawIndices;\n}\n\nfunction sample(size: number, array: any[], isGroup: boolean, mode: 'min' | 'max' | 'average' | 'sum', yfield: string) {\n let frameSize = Math.floor(array.length / size);\n const newIndices = [];\n const len = array.length;\n let sampledIndex = 0;\n let frameValues = [];\n\n newIndices.push(sampledIndex);\n array[sampledIndex][yfield] = array[sampledIndex][yfield];\n\n for (let i = 1; i < len - 1; i += frameSize) {\n if (frameSize > len - i) {\n frameSize = len - i;\n frameValues.length = frameSize;\n }\n frameValues = [];\n for (let k = 0; k < frameSize; k++) {\n frameValues.push(array[i + k][yfield]);\n }\n const value = samplerMap[mode](frameValues);\n sampledIndex = Math.min(Math.round(i + frameValues.length / 2) || 0, len - 1);\n array[sampledIndex][yfield] = value;\n newIndices.push(sampledIndex);\n }\n const newRawIndices = newIndices.map(i => (isGroup ? array[i].i : i));\n return newRawIndices;\n}\n\nfunction sampleMin(size: number, array: any[], isGroup: boolean, yfield: string) {\n return sample(size, array, isGroup, 'min', yfield);\n}\n\nfunction sampleMax(size: number, array: any[], isGroup: boolean, yfield: string) {\n return sample(size, array, isGroup, 'max', yfield);\n}\n\nfunction sampleAverage(size: number, array: any[], isGroup: boolean, yfield: string) {\n return sample(size, array, isGroup, 'average', yfield);\n}\n\nfunction sampleSum(size: number, array: any[], isGroup: boolean, yfield: string) {\n return sample(size, array, isGroup, 'sum', yfield);\n}\n\n/**\n * Samples tuples passing through this operator.\n * mode: 'lttb' - Uses lttb sampling to maintain a trend-maintained sample.\n * mode: 'min' | 'max' | 'average' | 'sum' - Uses aggregation methods to location sample points.\n * @constructor\n * @param {object} options - The parameters for this operator.\n * @param {number} [options.size=1000] - The maximum number of samples.\n * @param {string} [options.yfield] - The yfield string of data.\n * @param {string} [options.groupBy] - The groupBy string of data.\n */\n\nexport const transform = (options: SampleTransformOptions, upstreamData: any[]) => {\n let size = options.size;\n const factor = options.factor || 1;\n\n if (Array.isArray(size)) {\n size = Math.floor(size[1] - size[0]);\n }\n\n size *= factor;\n\n // size<=0的特殊情况不采样,返回空\n if (size <= 0) {\n return [];\n }\n\n // 数据<size的情况,不进行采样,保留所有数据\n if (upstreamData.length <= size) {\n return upstreamData;\n }\n\n const skipfirst = options.skipfirst;\n // 如果是ChartSpace的第一次数据流(evaluateAsync),不需要采样,返回一条数据供布局使用\n // 这里需要依据this.value.length判断是不是第一次数据流,\n // 以避免点击图例,updateChartData等操作清空所有label\n if (skipfirst) {\n return upstreamData.slice(0, 1);\n }\n\n const { mode, yfield: y, groupBy } = options;\n const yfield = y ?? 'y';\n\n // 采样方法\n let sampler = lttb;\n if (mode === 'min') {\n sampler = sampleMin;\n } else if (mode === 'max') {\n sampler = sampleMax;\n } else if (mode === 'average') {\n sampler = sampleAverage;\n } else if (mode === 'sum') {\n sampler = sampleSum;\n }\n\n // 处理数据source,source为采样前的原始数据\n if (upstreamData.length) {\n // 如果有groupBy,数据分组\n const groups = {};\n if (groupBy) {\n for (let i = 0, n = upstreamData.length; i < n; i++) {\n const datum = upstreamData[i];\n const groupId = datum[groupBy];\n if (groups[groupId]) {\n groups[groupId].push({ [yfield]: datum[yfield], i });\n } else {\n groups[groupId] = [];\n groups[groupId].push({ [yfield]: datum[yfield], i });\n }\n }\n\n // 分组采样\n let rawIndice: any[] = [];\n\n Object.keys(groups).forEach(groupName => {\n const group = groups[groupName];\n if (group.length <= size) {\n const indices = group.map((datum: any) => {\n return datum.i;\n });\n rawIndice = rawIndice.concat(indices);\n } else {\n const indices = sampler(size, group, true, yfield);\n rawIndice = rawIndice.concat(indices);\n group.forEach((datum: any) => (upstreamData[datum.i][yfield] = datum[yfield]));\n }\n });\n\n // 采样后,按照原始顺序排序\n rawIndice.sort((a, b) => a - b);\n\n return rawIndice.map((index: number) => upstreamData[index]);\n }\n return sampler(size, upstreamData, false, yfield).map(index => upstreamData[index]);\n }\n\n return [];\n};\n"]}
1
+ {"version":3,"sources":["../src/transforms/data/sampling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,UAAU,GAAG;IACjB,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,UAAU;IACf,OAAO,EAAE,OAAO;IAChB,GAAG,EAAE,GAAG;CACT,CAAC;AAEF,SAAS,IAAI,CAAC,IAAY,EAAE,KAAY,EAAE,OAAgB,EAAE,MAAc;IACxE,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IAEzB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,OAAO,CAAC;IACZ,IAAI,IAAI,CAAC;IACT,IAAI,SAAS,CAAC;IAGd,UAAU,CAAC,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC;IAE1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,IAAI,SAAS,EAAE;QAC3C,MAAM,cAAc,GAAG,IAAI,C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,EAAE;oBACxB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE;wBACvC,OAAO,KAAK,CAAC,CAAC,CAAC;oBACjB,CAAC,CAAC,CAAC;oBACH,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;iBACvC;qBAAM;oBACL,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;oBACnD,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;oBACtC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBAChF;YACH,CAAC,CAAC,CAAC;YAGH,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAEhC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,KAAa,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;SAC9D;QACD,OAAO,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;KACrF;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC","file":"sampling.js","sourcesContent":["import { maxInArray, minInArray } from '@visactor/vutils';\nimport type { SampleTransformOptions } from '../../types';\nimport { average, sum } from '../util/util';\n\nconst samplerMap = {\n min: minInArray,\n max: maxInArray,\n average: average,\n sum: sum\n};\n\nfunction lttb(size: number, array: any[], isGroup: boolean, yfield: string) {\n const frameSize = Math.floor(array.length / size);\n const newIndices = [];\n const len = array.length;\n\n let currentIndex = 0;\n let sampledIndex = 0;\n let maxArea;\n let area;\n let nextIndex;\n\n // First frame use the first data.\n newIndices[sampledIndex++] = currentIndex;\n\n for (let i = 1; i < len - 1; i += frameSize) {\n const nextFrameStart = Math.min(i + frameSize, len - 1);\n const nextFrameEnd = Math.min(i + frameSize * 2, len);\n\n const avgX = (nextFrameEnd + nextFrameStart) / 2;\n let avgY = 0;\n\n for (let idx = nextFrameStart; idx < nextFrameEnd; idx++) {\n const value = array[idx][yfield];\n if (Number.isNaN(value)) {\n continue;\n }\n avgY += value;\n }\n avgY /= nextFrameEnd - nextFrameStart;\n\n const frameStart = i;\n const frameEnd = Math.min(i + frameSize, len);\n\n const pointAX = i - 1;\n const pointAY = array[currentIndex][yfield];\n\n maxArea = -1;\n\n nextIndex = frameStart;\n // Find a point from current frame that construct a triangel with largest area with previous selected point\n // And the average of next frame.\n for (let idx = frameStart; idx < frameEnd; idx++) {\n const value = array[idx][yfield];\n if (Number.isNaN(yfield)) {\n continue;\n }\n // Calculate triangle area over three buckets\n area = Math.abs((pointAX - avgX) * (value - pointAY) - (pointAX - idx) * (avgY - pointAY));\n if (area > maxArea) {\n maxArea = area;\n nextIndex = idx; // Next a is this b\n }\n }\n\n newIndices[sampledIndex++] = nextIndex;\n\n currentIndex = nextIndex; // This a is the next a (chosen b)\n }\n\n // First frame use the last data.\n if (newIndices[sampledIndex - 1] !== len - 1) {\n newIndices[sampledIndex++] = len - 1;\n }\n\n // output newly added tuples\n const newRawIndices = newIndices.map(i => (isGroup ? array[i].i : i));\n return newRawIndices;\n}\n\nfunction sample(size: number, array: any[], isGroup: boolean, mode: 'min' | 'max' | 'average' | 'sum', yfield: string) {\n let frameSize = Math.floor(array.length / size);\n const newIndices = [];\n const len = array.length;\n let sampledIndex = 0;\n let frameValues = [];\n\n newIndices.push(sampledIndex);\n array[sampledIndex][yfield] = array[sampledIndex][yfield];\n\n for (let i = 1; i < len - 1; i += frameSize) {\n if (frameSize > len - i) {\n frameSize = len - i;\n frameValues.length = frameSize;\n }\n frameValues = [];\n for (let k = 0; k < frameSize; k++) {\n frameValues.push(array[i + k][yfield]);\n }\n const value = samplerMap[mode](frameValues);\n sampledIndex = Math.min(Math.round(i + frameValues.length / 2) || 0, len - 1);\n array[sampledIndex][yfield] = value;\n newIndices.push(sampledIndex);\n }\n const newRawIndices = newIndices.map(i => (isGroup ? array[i].i : i));\n return newRawIndices;\n}\n\nfunction sampleMin(size: number, array: any[], isGroup: boolean, yfield: string) {\n return sample(size, array, isGroup, 'min', yfield);\n}\n\nfunction sampleMax(size: number, array: any[], isGroup: boolean, yfield: string) {\n return sample(size, array, isGroup, 'max', yfield);\n}\n\nfunction sampleAverage(size: number, array: any[], isGroup: boolean, yfield: string) {\n return sample(size, array, isGroup, 'average', yfield);\n}\n\nfunction sampleSum(size: number, array: any[], isGroup: boolean, yfield: string) {\n return sample(size, array, isGroup, 'sum', yfield);\n}\n\n/**\n * Samples tuples passing through this operator.\n * mode: 'lttb' - Uses lttb sampling to maintain a trend-maintained sample.\n * mode: 'min' | 'max' | 'average' | 'sum' - Uses aggregation methods to location sample points.\n * @constructor\n * @param {object} options - The parameters for this operator.\n * @param {number} [options.size=1000] - The maximum number of samples.\n * @param {string} [options.yfield] - The yfield string of data.\n * @param {string} [options.groupBy] - The groupBy string of data.\n */\n\nexport const transform = (options: SampleTransformOptions, upstreamData: any[]) => {\n let size = options.size;\n const factor = options.factor || 1;\n\n if (Array.isArray(size)) {\n size = Math.floor(size[1] - size[0]);\n }\n\n size *= factor;\n\n // size<=0的特殊情况不采样,返回空\n if (size <= 0) {\n return [];\n }\n\n // 数据<size的情况,不进行采样,保留所有数据\n if (upstreamData.length <= size) {\n return upstreamData;\n }\n\n const skipfirst = options.skipfirst;\n // 如果是ChartSpace的第一次数据流(evaluateAsync),不需要采样,返回一条数据供布局使用\n // 这里需要依据this.value.length判断是不是第一次数据流,\n // 以避免点击图例,updateChartData等操作清空所有label\n if (skipfirst) {\n return upstreamData.slice(0, 1);\n }\n\n const { mode, yfield: y, groupBy } = options;\n const yfield = y ?? 'y';\n\n // 采样方法\n let sampler = lttb;\n if (mode === 'min') {\n sampler = sampleMin;\n } else if (mode === 'max') {\n sampler = sampleMax;\n } else if (mode === 'average') {\n sampler = sampleAverage;\n } else if (mode === 'sum') {\n sampler = sampleSum;\n }\n\n // 处理数据source,source为采样前的原始数据\n if (upstreamData.length) {\n // 如果有groupBy,数据分组\n const groups = {};\n if (groupBy) {\n for (let i = 0, n = upstreamData.length; i < n; i++) {\n const datum = upstreamData[i];\n const groupId = datum[groupBy];\n if (groups[groupId]) {\n groups[groupId].push({ [yfield]: datum[yfield], i });\n } else {\n groups[groupId] = [];\n groups[groupId].push({ [yfield]: datum[yfield], i });\n }\n }\n\n // 分组采样\n let rawIndice: any[] = [];\n\n Object.keys(groups).forEach(groupName => {\n const group = groups[groupName];\n if (group.length <= size) {\n const indices = group.map((datum: any) => {\n return datum.i;\n });\n rawIndice = rawIndice.concat(indices);\n } else {\n const indices = sampler(size, group, true, yfield);\n rawIndice = rawIndice.concat(indices);\n group.forEach((datum: any) => (upstreamData[datum.i][yfield] = datum[yfield]));\n }\n });\n\n // 采样后,按照原始顺序排序\n rawIndice.sort((a, b) => a - b);\n\n return rawIndice.map((index: number) => upstreamData[index]);\n }\n return sampler(size, upstreamData, false, yfield).map(index => upstreamData[index]);\n }\n\n return [];\n};\n"]}
@@ -1,9 +1,9 @@
1
- import { array } from "@visactor/vutils";
1
+ import { array, maxInArray, minInArray } from "@visactor/vutils";
2
2
 
3
3
  const aggregateFuncs = {
4
4
  sum: arr => arr.reduce(((sum, val) => sum + val), 0),
5
- min: arr => Math.min.apply(null, arr),
6
- max: arr => Math.max.apply(null, arr),
5
+ min: arr => minInArray(arr),
6
+ max: arr => maxInArray(arr),
7
7
  count: arr => arr.length,
8
8
  mean: arr => arr.reduce(((sum, val) => sum + val), 0) / arr.length
9
9
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transforms/data/unfold.ts"],"names":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AC,KAAU,EAAE,EAAE;YAClC,IAAI,CAAC,KAAK,EAAE;gBACV,OAAO;aACR;YAED,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE;gBACrC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;aAC3D;iBAAM;gBACL,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;aACzD;QACH,CAAC,CAAC,CAAC;KACJ;IACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACrC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;QACrC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;QAEvC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAChC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAEzB,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,IAAgB,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","file":"unfold.js","sourcesContent":["import type { UnfoldTransformOptions } from '../../types';\nimport { array } from '@visactor/vutils';\n\nconst aggregateFuncs = {\n sum: (arr: number[]) => arr.reduce((sum: number, val: number) => sum + val, 0),\n min: (arr: number[]) => Math.min.apply(null, arr),\n max: (arr: number[]) => Math.max.apply(null, arr),\n count: (arr: number[]) => arr.length,\n mean: (arr: number[]) => arr.reduce((sum: number, val: number) => sum + val, 0) / arr.length\n};\n\nexport const transform = (options: UnfoldTransformOptions, upstreamData: any[]) => {\n if (!upstreamData || !upstreamData.length) {\n return [];\n }\n\n const res: any[] = [];\n const groups = {};\n const keyField = options.keyField;\n const valueField = options.valueField;\n const aggregate = aggregateFuncs[options.aggregateType ?? 'sum'];\n\n if (options.groupBy) {\n const groupByFields = array(options.groupBy);\n upstreamData.forEach((entry: any) => {\n if (!entry) {\n return;\n }\n const datum = {};\n const keys: any[] = [];\n\n groupByFields.forEach((field: string) => {\n datum[field] = entry[field];\n keys.push(entry[field]);\n });\n\n const groupKey = keys.join('~');\n\n if (groups[groupKey]) {\n if (groups[groupKey].values[entry[keyField]]) {\n groups[groupKey].values[entry[keyField]].push(entry[valueField]);\n } else {\n groups[groupKey].values[entry[keyField]] = [entry[valueField]];\n }\n } else {\n groups[groupKey] = { datum, values: { [entry[keyField]]: [entry[valueField]] } };\n }\n });\n } else {\n groups[0] = { datum: {}, values: {} };\n upstreamData.forEach((entry: any) => {\n if (!entry) {\n return;\n }\n\n if (groups[0].values[entry[keyField]]) {\n groups[0].values[entry[keyField]].push(entry[valueField]);\n } else {\n groups[0].values[entry[keyField]] = [entry[valueField]];\n }\n });\n }\n Object.keys(groups).forEach(groupKey => {\n const datum = groups[groupKey].datum;\n const values = groups[groupKey].values;\n\n Object.keys(values).forEach(key => {\n const rows = values[key];\n\n datum[key] = aggregate(rows as number[]);\n });\n\n res.push(datum);\n });\n\n return res;\n};\n"]}
1
+ {"version":3,"sources":["../src/transforms/data/unfold.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEjE,MAAM,cAAc,GAAG;IACrB,GAAG,EAAE,CAAC,GAAa,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE,CAAC,GAAG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CAAC,CAAC,CAAC;aAC3D;iBAAM;gBACL,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;aACzD;QACH,CAAC,CAAC,CAAC;KACJ;IACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACrC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;QACrC,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;QAEvC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAChC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAEzB,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,IAAgB,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","file":"unfold.js","sourcesContent":["import type { UnfoldTransformOptions } from '../../types';\nimport { array, maxInArray, minInArray } from '@visactor/vutils';\n\nconst aggregateFuncs = {\n sum: (arr: number[]) => arr.reduce((sum: number, val: number) => sum + val, 0),\n min: (arr: number[]) => minInArray(arr),\n max: (arr: number[]) => maxInArray(arr),\n count: (arr: number[]) => arr.length,\n mean: (arr: number[]) => arr.reduce((sum: number, val: number) => sum + val, 0) / arr.length\n};\n\nexport const transform = (options: UnfoldTransformOptions, upstreamData: any[]) => {\n if (!upstreamData || !upstreamData.length) {\n return [];\n }\n\n const res: any[] = [];\n const groups = {};\n const keyField = options.keyField;\n const valueField = options.valueField;\n const aggregate = aggregateFuncs[options.aggregateType ?? 'sum'];\n\n if (options.groupBy) {\n const groupByFields = array(options.groupBy);\n upstreamData.forEach((entry: any) => {\n if (!entry) {\n return;\n }\n const datum = {};\n const keys: any[] = [];\n\n groupByFields.forEach((field: string) => {\n datum[field] = entry[field];\n keys.push(entry[field]);\n });\n\n const groupKey = keys.join('~');\n\n if (groups[groupKey]) {\n if (groups[groupKey].values[entry[keyField]]) {\n groups[groupKey].values[entry[keyField]].push(entry[valueField]);\n } else {\n groups[groupKey].values[entry[keyField]] = [entry[valueField]];\n }\n } else {\n groups[groupKey] = { datum, values: { [entry[keyField]]: [entry[valueField]] } };\n }\n });\n } else {\n groups[0] = { datum: {}, values: {} };\n upstreamData.forEach((entry: any) => {\n if (!entry) {\n return;\n }\n\n if (groups[0].values[entry[keyField]]) {\n groups[0].values[entry[keyField]].push(entry[valueField]);\n } else {\n groups[0].values[entry[keyField]] = [entry[valueField]];\n }\n });\n }\n Object.keys(groups).forEach(groupKey => {\n const datum = groups[groupKey].datum;\n const values = groups[groupKey].values;\n\n Object.keys(values).forEach(key => {\n const rows = values[key];\n\n datum[key] = aggregate(rows as number[]);\n });\n\n res.push(datum);\n });\n\n return res;\n};\n"]}
@@ -1,7 +1,7 @@
1
- import { isNil, isValidNumber } from "@visactor/vutils";
1
+ import { isNil, isValidNumber, maxInArray, minInArray } from "@visactor/vutils";
2
2
 
3
3
  const symmetryByChannel = (upstreamData, channel, align) => {
4
- const baseChannel = `${channel}1`, hasRangeValue = upstreamData.some((el => !isNil(el.getItemAttribute(baseChannel)))), middleValues = hasRangeValue ? upstreamData.map((el => (el.getItemAttribute(baseChannel) + el.getItemAttribute(channel)) / 2)) : upstreamData.map((el => el.getItemAttribute(channel))), maxMid = "min" === align ? Math.min.apply(null, middleValues) : Math.max.apply(null, middleValues);
4
+ const baseChannel = `${channel}1`, hasRangeValue = upstreamData.some((el => !isNil(el.getItemAttribute(baseChannel)))), middleValues = hasRangeValue ? upstreamData.map((el => (el.getItemAttribute(baseChannel) + el.getItemAttribute(channel)) / 2)) : upstreamData.map((el => el.getItemAttribute(channel))), maxMid = "min" === align ? minInArray(middleValues) : maxInArray(middleValues);
5
5
  return isValidNumber(maxMid) && upstreamData.forEach(((el, index) => {
6
6
  const offset = maxMid - middleValues[index];
7
7
  hasRangeValue ? el.setItemAttributes({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transforms/mark/symmetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,iBAAiB,GAAG,CAAC,YAAwB,EAAE,OAAkB,EAAE,KAAqB,EAAE,EAAE;IAChG,MAAM,WAAW,GAAG,GAAG,OAAO,GAAG,CAAC;IAClC,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACxF,MAAM,YAAY,GAAG,aAAa;QAChC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;QAC/F,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAEzG,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;QACzB,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACjC,MAAM,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAC5C,IAAI,aAAa,EAAE;gBACjB,EAAE,CAAC,iBAAiB,CAAC;oBACnB,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,MAAM;oBACxD,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,MAAM;iBACjD,CAAC,CAAC;aACJ;iBAAM;gBACL,EAAE,CAAC,iBAAiB,CAAC;oBACnB,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,MAAM;iBACjD,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAKF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAiC,EAAE,YAAwB,EAAE,EAAE;;IACtF,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA,MAAA,YAAY,CAAC,CAAC,CAAC,0CAAE,IAAI,CAAA,EAAE;QACxE,OAAO,YAAY,CAAC;KACrB;IAED,OAAO,iBAAiB,CAAC,YAAY,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC,CAAC","file":"symmetry.js","sourcesContent":["import { isNil, isValidNumber } from '@visactor/vutils';\nimport type { IElement, SymmetryTransformOptions } from '../../types';\n\nconst symmetryByChannel = (upstreamData: IElement[], channel: 'x' | 'y', align?: 'min' | 'max') => {\n const baseChannel = `${channel}1`;\n const hasRangeValue = upstreamData.some(el => !isNil(el.getItemAttribute(baseChannel)));\n const middleValues = hasRangeValue\n ? upstreamData.map(el => (el.getItemAttribute(baseChannel) + el.getItemAttribute(channel)) / 2)\n : upstreamData.map(el => el.getItemAttribute(channel));\n const maxMid = align === 'min' ? Math.min.apply(null, middleValues) : Math.max.apply(null, middleValues);\n\n if (isValidNumber(maxMid)) {\n upstreamData.forEach((el, index) => {\n const offset = maxMid - middleValues[index];\n if (hasRangeValue) {\n el.setItemAttributes({\n [baseChannel]: el.getItemAttribute(baseChannel) + offset,\n [channel]: el.getItemAttribute(channel) + offset\n });\n } else {\n el.setItemAttributes({\n [channel]: el.getItemAttribute(channel) + offset\n });\n }\n });\n }\n\n return upstreamData;\n};\n\n/**\n * 针对mark的symmetry变换,支持x、y方向\n */\nexport const symmetry = (options: SymmetryTransformOptions, upstreamData: IElement[]) => {\n if (!upstreamData || upstreamData.length === 0 || !upstreamData[0]?.mark) {\n return upstreamData;\n }\n\n return symmetryByChannel(upstreamData, options.channel ?? 'y', options.align);\n};\n"]}
1
+ {"version":3,"sources":["../src/transforms/mark/symmetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGhF,MAAM,iBAAiB,GAAG,CAAC,YAAwB,EAAE,OAAkB,EAAE,KAAqB,EAAE,EAAE;IAChG,MAAM,WAAW,GAAG,GAAG,OAAO,GAAG,CAAC;IAClC,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACxF,MAAM,YAAY,GAAG,aAAa;QAChC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;QAC/F,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAErF,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;QACzB,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE;YACjC,MAAM,MAAM,GAAG,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;YAC5C,IAAI,aAAa,EAAE;gBACjB,EAAE,CAAC,iBAAiB,CAAC;oBACnB,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,MAAM;oBACxD,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,MAAM;iBACjD,CAAC,CAAC;aACJ;iBAAM;gBACL,EAAE,CAAC,iBAAiB,CAAC;oBACnB,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,MAAM;iBACjD,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAKF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAiC,EAAE,YAAwB,EAAE,EAAE;;IACtF,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA,MAAA,YAAY,CAAC,CAAC,CAAC,0CAAE,IAAI,CAAA,EAAE;QACxE,OAAO,YAAY,CAAC;KACrB;IAED,OAAO,iBAAiB,CAAC,YAAY,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC,CAAC","file":"symmetry.js","sourcesContent":["import { isNil, isValidNumber, maxInArray, minInArray } from '@visactor/vutils';\nimport type { IElement, SymmetryTransformOptions } from '../../types';\n\nconst symmetryByChannel = (upstreamData: IElement[], channel: 'x' | 'y', align?: 'min' | 'max') => {\n const baseChannel = `${channel}1`;\n const hasRangeValue = upstreamData.some(el => !isNil(el.getItemAttribute(baseChannel)));\n const middleValues = hasRangeValue\n ? upstreamData.map(el => (el.getItemAttribute(baseChannel) + el.getItemAttribute(channel)) / 2)\n : upstreamData.map(el => el.getItemAttribute(channel));\n const maxMid = align === 'min' ? minInArray(middleValues) : maxInArray(middleValues);\n\n if (isValidNumber(maxMid)) {\n upstreamData.forEach((el, index) => {\n const offset = maxMid - middleValues[index];\n if (hasRangeValue) {\n el.setItemAttributes({\n [baseChannel]: el.getItemAttribute(baseChannel) + offset,\n [channel]: el.getItemAttribute(channel) + offset\n });\n } else {\n el.setItemAttributes({\n [channel]: el.getItemAttribute(channel) + offset\n });\n }\n });\n }\n\n return upstreamData;\n};\n\n/**\n * 针对mark的symmetry变换,支持x、y方向\n */\nexport const symmetry = (options: SymmetryTransformOptions, upstreamData: IElement[]) => {\n if (!upstreamData || upstreamData.length === 0 || !upstreamData[0]?.mark) {\n return upstreamData;\n }\n\n return symmetryByChannel(upstreamData, options.channel ?? 'y', options.align);\n};\n"]}
@@ -5,5 +5,3 @@ export declare function normalizeAngle(angle: number): number;
5
5
  export declare function computeQuadrant(angle: number): 1 | 2 | 3 | 4;
6
6
  export declare function sum(arr: any[]): any;
7
7
  export declare function average(arr: any[]): number;
8
- export declare function min(arr: any[]): number;
9
- export declare function max(arr: any[]): number;
@@ -39,12 +39,4 @@ export function average(arr) {
39
39
  if (0 === arr.length) return 0;
40
40
  return sum(arr) / arr.length;
41
41
  }
42
-
43
- export function min(arr) {
44
- return Math.min(...arr);
45
- }
46
-
47
- export function max(arr) {
48
- return Math.max(...arr);
49
- }
50
42
  //# sourceMappingURL=util.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/transforms/util/util.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EA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;IAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,GAAU;IAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;AAC1B,CAAC","file":"util.js","sourcesContent":["/* Adapted from vega by University of Washington Interactive Data Lab\n * https://vega.github.io/vega/\n * Licensed under the BSD-3-Clause\n\n * url: https://github.com/vega/vega/blob/main/packages/vega-transforms/src/util/util.js\n * License: https://github.com/vega/vega/blob/main/LICENSE\n * @license\n */\n\nimport { isNil, isString } from '@visactor/vutils';\nimport type { FieldGetterFunction } from '@visactor/vgrammar-util';\nimport { accessorName } from '@visactor/vgrammar-util';\n\n// use either provided alias or accessor field name\nexport function fieldNames(fields: string[] | FieldGetterFunction[], as?: string[]) {\n if (!fields) {\n return null;\n }\n return fields.map((f, i) => {\n return as[i] ?? (isString(f) ? f : accessorName(f));\n });\n}\n\nexport function partition(data?: any[], groupBy?: FieldGetterFunction[], field?: FieldGetterFunction) {\n // partition data points into groups\n if (isNil(groupBy)) {\n return [data.map(field)];\n }\n\n const groups: any[] = [];\n const map: Record<string, any> = {};\n data.forEach((entry: any) => {\n const groupKey = groupBy.map((groupFunc: (arg: any) => any) => groupFunc(entry)).toString();\n\n if (!map[groupKey]) {\n const groupItem: any[] = [];\n (groupItem as any).dims = groupKey;\n groups.push(groupItem);\n map[groupKey] = groupItem;\n } else {\n map[groupKey].push(field(entry));\n }\n });\n\n return groups;\n}\n\nexport function normalizeAngle(angle: number): number {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n return angle;\n}\n\nexport function computeQuadrant(angle: number): 1 | 2 | 3 | 4 {\n angle = normalizeAngle(angle);\n if (angle > 0 && angle <= Math.PI / 2) {\n return 2;\n } else if (angle > Math.PI / 2 && angle <= Math.PI) {\n return 3;\n } else if (angle > Math.PI && angle <= (3 * Math.PI) / 2) {\n return 4;\n }\n return 1;\n}\n\nexport function sum(arr: any[]) {\n return arr.reduce((accumulator, currentValue) => accumulator + currentValue, 0);\n}\n\nexport function average(arr: any[]) {\n if (arr.length === 0) {\n return 0;\n }\n const total = sum(arr);\n return total / arr.length;\n}\n\nexport function min(arr: any[]) {\n return Math.min(...arr);\n}\n\nexport function max(arr: any[]) {\n return Math.max(...arr);\n}\n"]}
1
+ {"version":3,"sources":["../src/transforms/util/util.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD,MAAM,UAAU,UAAU,CAAC,MAAwC,EAAE,EAAa;IAChF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,IAAI,CAAC;KACb;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;;QACzB,OAAO,MAAA,EAAE,CAAC,CAAC,CAAC,mCAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,OAA+B,EAAE,KAA2B;IAElG,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE;QAClB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;KAC1B;IAED,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,MAAM,GAAG,GAAwB,EAAE,CAAC;IACpC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,EAAE;QAC1B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,SAA4B,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAA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5B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,YAAY,EAAE,EAAE,CAAC,WAAW,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAAU;IAChC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;QACpB,OAAO,CAAC,CAAC;KACV;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,OAAO,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC;AAC5B,CAAC","file":"util.js","sourcesContent":["/* Adapted from vega by University of Washington Interactive Data Lab\n * https://vega.github.io/vega/\n * Licensed under the BSD-3-Clause\n\n * url: https://github.com/vega/vega/blob/main/packages/vega-transforms/src/util/util.js\n * License: https://github.com/vega/vega/blob/main/LICENSE\n * @license\n */\n\nimport { isNil, isString } from '@visactor/vutils';\nimport type { FieldGetterFunction } from '@visactor/vgrammar-util';\nimport { accessorName } from '@visactor/vgrammar-util';\n\n// use either provided alias or accessor field name\nexport function fieldNames(fields: string[] | FieldGetterFunction[], as?: string[]) {\n if (!fields) {\n return null;\n }\n return fields.map((f, i) => {\n return as[i] ?? (isString(f) ? f : accessorName(f));\n });\n}\n\nexport function partition(data?: any[], groupBy?: FieldGetterFunction[], field?: FieldGetterFunction) {\n // partition data points into groups\n if (isNil(groupBy)) {\n return [data.map(field)];\n }\n\n const groups: any[] = [];\n const map: Record<string, any> = {};\n data.forEach((entry: any) => {\n const groupKey = groupBy.map((groupFunc: (arg: any) => any) => groupFunc(entry)).toString();\n\n if (!map[groupKey]) {\n const groupItem: any[] = [];\n (groupItem as any).dims = groupKey;\n groups.push(groupItem);\n map[groupKey] = groupItem;\n } else {\n map[groupKey].push(field(entry));\n }\n });\n\n return groups;\n}\n\nexport function normalizeAngle(angle: number): number {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n return angle;\n}\n\nexport function computeQuadrant(angle: number): 1 | 2 | 3 | 4 {\n angle = normalizeAngle(angle);\n if (angle > 0 && angle <= Math.PI / 2) {\n return 2;\n } else if (angle > Math.PI / 2 && angle <= Math.PI) {\n return 3;\n } else if (angle > Math.PI && angle <= (3 * Math.PI) / 2) {\n return 4;\n }\n return 1;\n}\n\nexport function sum(arr: any[]) {\n return arr.reduce((accumulator, currentValue) => accumulator + currentValue, 0);\n}\n\nexport function average(arr: any[]) {\n if (arr.length === 0) {\n return 0;\n }\n const total = sum(arr);\n return total / arr.length;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { IGraphic, ACustomAnimate, EasingType } from '@visactor/vrender-core';
1
+ import type { IGraphic, ACustomAnimate, EasingType } from '@visactor/vrender/es/core';
2
2
  import type { IPointLike } from '@visactor/vutils';
3
3
  import type { MarkFunctionCallback, MarkFunctionType } from './mark';
4
4
  import type { IMark } from './grammar';
@@ -81,6 +81,7 @@ export interface IAnimationTypeConfig {
81
81
  customParameters?: MarkFunctionValueType<any>;
82
82
  easing?: EasingType;
83
83
  delay?: MarkFunctionValueType<number>;
84
+ delayAfter?: MarkFunctionValueType<number>;
84
85
  duration?: MarkFunctionValueType<number>;
85
86
  oneByOne?: MarkFunctionValueType<boolean | number>;
86
87
  startTime?: MarkFunctionValueType<number>;
@@ -104,6 +105,7 @@ export interface IAnimationTimeSlice {
104
105
  effects: IAnimationEffect | IAnimationEffect[];
105
106
  duration?: MarkFunctionValueType<number>;
106
107
  delay?: MarkFunctionValueType<number>;
108
+ delayAfter?: MarkFunctionValueType<number>;
107
109
  }
108
110
  export type IAnimationChannelFunction = (datum: any, element: IElement, parameters: IAnimationParameters) => any;
109
111
  export type IAnimationChannelAttrs = Record<string, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types/animate.ts"],"names":[],"mappings":"","file":"animate.js","sourcesContent":["import type { IGraphic, ACustomAnimate, EasingType } from '@visactor/vrender-core';\nimport type { IPointLike } from '@visactor/vutils';\nimport type { MarkFunctionCallback, MarkFunctionType } from './mark';\nimport type { IMark } from './grammar';\nimport type { IElement } from './element';\nimport type { FunctionCallback } from './signal';\n\nexport type TypeAnimation<T extends IElement> = (\n element: T,\n options: any,\n animationParameters: IAnimationParameters\n) => { from?: { [channel: string]: any }; to?: { [channel: string]: any } };\n\nexport interface IClipAnimationOptions {\n clipDimension?: 'x' | 'y' | 'auto' | 'default';\n}\n\nexport interface IGrowCartesianAnimationOptions {\n orient?: 'positive' | 'negative';\n overall?: boolean | number;\n direction?: 'x' | 'y' | 'xy';\n}\n\nexport interface IGrowAngleAnimationOptions {\n orient?: 'clockwise' | 'anticlockwise';\n overall?: boolean | number;\n}\n\nexport interface IGrowRadiusAnimationOptions {\n orient?: 'inside' | 'outside';\n overall?: boolean | number;\n}\n\nexport interface IGrowPointsAnimationOptions {\n orient?: 'positive' | 'negative';\n}\n\nexport interface IGrowPointsOverallAnimationOptions extends IGrowPointsAnimationOptions {\n center?: IPointLike;\n}\n\nexport interface IScaleAnimationOptions {\n direction?: 'x' | 'y' | 'xy';\n}\n\nexport interface IMoveAnimationOptions {\n direction?: 'x' | 'y' | 'xy';\n orient?: 'positive' | 'negative';\n offset?: number;\n point?: { x?: number; y?: number } | FunctionCallback<{ x?: number; y?: number }>;\n}\n\nexport interface IRotateAnimationOptions {\n orient?: 'clockwise' | 'anticlockwise';\n angle?: number;\n}\n\n/** VGrammar 层提供的图元text上的图形属性,现在暂时会和VRender不一致 */\nexport interface TextItemAttributes {\n fontSize?: number;\n lineHeight?: number;\n font?: string;\n fontStyle?: string;\n fontVariant?: string;\n fontWeight?: string | number;\n lineBreak?: string;\n text?: string | string[];\n limit?: number;\n align?: string;\n baseline?: string;\n ellipsis?: string | boolean;\n dir?: string;\n}\n\n/** animation */\nexport type MarkFunctionValueType<T> = MarkFunctionCallback<T> | T;\n\nexport type IAnimationConfig = IAnimationTimeline | IAnimationTypeConfig;\n\n/**\n * state动画,暂时只支持简单配置\n */\nexport interface IStateAnimationConfig {\n duration?: number;\n easing?: EasingType;\n}\n\n/**\n * 动画 config 简化配置\n */\nexport interface IAnimationTypeConfig {\n type?: string;\n channel?: IAnimationChannelAttrs | IAnimationChannelAttributes;\n custom?: IAnimationChannelInterpolator | IAnimationCustomConstructor;\n customParameters?: MarkFunctionValueType<any>;\n easing?: EasingType;\n delay?: MarkFunctionValueType<number>;\n duration?: MarkFunctionValueType<number>;\n oneByOne?: MarkFunctionValueType<boolean | number>;\n startTime?: MarkFunctionValueType<number>;\n totalTime?: MarkFunctionValueType<number>;\n /** loop: true 无限循环; loop: 正整数,表示循环的次数 */\n loop?: boolean | number;\n /** 动画 effect 配置项 */\n options?: MarkFunctionValueType<any>;\n /** 动画执行相关控制配置项 */\n controlOptions?: IAnimationControlOptions;\n}\n\n/**\n * 动画 timeline 完整配置,一条时间线内的动画单元只能串行\n * 多个timeline是可以并行的\n * 考虑到同一图元不能在多个timeline上,所以timeline不应该提供数组配置的能力\n */\nexport interface IAnimationTimeline {\n /** 为了方便动画编排,用户可以设置 id 用于识别时间线 */\n id?: string;\n /** 时间切片 */\n timeSlices: IAnimationTimeSlice | IAnimationTimeSlice[];\n /** 动画开始的相对时间,可以为负数 */\n startTime?: MarkFunctionValueType<number>;\n /** 动画时长 */\n totalTime?: MarkFunctionValueType<number>;\n /** 动画依次执行的延迟 */\n oneByOne?: MarkFunctionValueType<number | boolean>;\n /** loop: true 无限循环; loop: 正整数,表示循环的次数 */\n loop?: MarkFunctionValueType<number | boolean>;\n /** 对图元元素进行划分,和过滤类似,但是不同时间线不能同时作用在相同的元素上 */\n partitioner?: MarkFunctionCallback<boolean>;\n /** 对同一时间线上的元素进行排序 */\n sort?: (datumA: any, datumB: any, elementA: IElement, elementB: IElement, parameters: any) => number;\n /** 动画执行相关控制配置项 */\n controlOptions?: IAnimationControlOptions;\n}\n\nexport interface IAnimationTimeSlice {\n effects: IAnimationEffect | IAnimationEffect[];\n duration?: MarkFunctionValueType<number>;\n delay?: MarkFunctionValueType<number>;\n}\n\nexport type IAnimationChannelFunction = (datum: any, element: IElement, parameters: IAnimationParameters) => any;\nexport type IAnimationChannelAttrs = Record<\n string,\n {\n from?: any | IAnimationChannelFunction;\n to?: any | IAnimationChannelFunction;\n }\n>;\nexport type IAnimationChannelAttributes = string[];\nexport type IAnimationChannelInterpolator = (\n ratio: number,\n from: any,\n to: any,\n nextAttributes: any,\n datum: any,\n element: IElement,\n parameters: IAnimationParameters\n) => boolean | void;\n\n// TODO: fix ACustomAnimate<any>\nexport interface IAnimationCustomConstructor {\n new (from: any, to: any, duration: number, ease: EasingType, parameters?: any): ACustomAnimate<any>;\n}\n\nexport interface IAnimationEffect {\n type?: string;\n channel?: IAnimationChannelAttrs | IAnimationChannelAttributes;\n custom?: IAnimationChannelInterpolator | IAnimationCustomConstructor;\n customParameters?: MarkFunctionValueType<any>;\n easing?: EasingType;\n /** options暂时没有处理 */\n options?: MarkFunctionValueType<any>;\n}\n\nexport interface IAnimationControlOptions {\n /** 当动画状态变更时清空动画 */\n stopWhenStateChange?: boolean;\n /** 是否立即应用动画初始状态 */\n immediatelyApply?: boolean;\n}\n\n/**\n * Animation timeline should be parsed into animation units,\n * which record all necessary configs for animator to execute animation.\n *\n * animation unit time:\n * |<--initialDelay-->| |<--loopDelay--><--Slices--><--looDelayAfter-->| |<--loopDuration-->|\n * |<-----------------loopDuration--------------->|\n */\nexport interface IAnimationUnit {\n /**\n * initial delay time before any animation loop\n */\n initialDelay: number;\n /**\n * total time for one animation loop\n */\n loopDuration: number;\n /**\n * delay time before time slices\n */\n loopDelay: number;\n /**\n * delay time after time slices\n */\n loopDelayAfter: number;\n /**\n * animating time in one animation loop\n */\n loopAnimateDuration: number;\n loopCount: number;\n totalTime: number;\n timeSlices: IAnimationTimeSlice[];\n}\n\nexport interface IAnimationRecord {\n start: IGraphic;\n end: IGraphic;\n changes: any[];\n}\n\nexport interface IAnimationParameters {\n width: number;\n height: number;\n mark: IMark;\n group: IMark | null;\n elementIndex: number;\n elementCount: number;\n view: any;\n}\n\nexport interface IParsedAnimationConfig {\n state: string;\n timeline: IAnimationTimeline;\n originConfig: IAnimationConfig;\n id: string;\n}\n\nexport interface IParsedAnimationAttrs {\n from?: any;\n to?: any;\n custom?: IAnimationChannelInterpolator | IAnimationCustomConstructor;\n customParameters?: any;\n}\n\n// animate structure\n\nexport interface IAnimatorOptions {\n state: string;\n timeline: IAnimationTimeline;\n id: string;\n}\n\nexport interface IAnimator {\n id: number;\n element: IElement;\n animationOptions: IAnimatorOptions;\n isAnimating: boolean;\n\n /** execute animation */\n animate: (animationParameters: IAnimationParameters, parameters: any) => this;\n /** set animation callback */\n callback: (callbackFunction: (...args: any[]) => void) => this;\n\n // animation control\n stop: (stopState?: 'start' | 'end', invokeCallback?: boolean) => this;\n pause: () => this;\n resume: () => this;\n\n /** set additional initial animation delay */\n startAt: (startTime: number) => this;\n /** get total animation execution time */\n getTotalAnimationTime: () => number;\n\n getEndAttributes: () => Record<string, any>;\n}\n\nexport interface IAnimateArranger {\n // animation control api\n parallel: (arranger: IAnimateArranger) => this;\n after: (arranger: IAnimateArranger) => this;\n\n // internal properties\n afterArranger: IAnimateArranger;\n parallelArrangers: IAnimateArranger[];\n animators: IAnimator[];\n totalTime: number;\n startTime: number;\n endTime: number;\n arrangeTime: () => void;\n}\n\nexport interface IBaseAnimate {\n // animation control\n stop: () => this;\n pause: () => this;\n resume: () => this;\n\n // internal animation process api\n animate: () => this;\n enable: () => this;\n disable: () => this;\n enableAnimationState: (state: string | string[]) => this;\n disableAnimationState: (state: string | string[]) => this;\n isAnimating: () => boolean;\n\n release: () => void;\n}\n\nexport interface IViewAnimate extends IBaseAnimate {\n animateAddition: (mark: IMark) => this;\n}\n\nexport interface IAnimate extends IBaseAnimate {\n mark: IMark;\n\n // additional animation control\n run: (config: IAnimationConfig | IAnimationConfig[]) => IAnimateArranger;\n runAnimationByState: (animationState: string) => IAnimateArranger;\n stopAnimationByState: (animationState: string) => this;\n pauseAnimationByState: (animationState: string) => this;\n resumeAnimationByState: (animationState: string) => this;\n reverse: () => this;\n restart: () => this;\n record: () => this;\n recordEnd: () => this;\n\n // internal animation process api\n getAnimationConfigs: (animationState: string) => IParsedAnimationConfig[];\n updateConfig: (config: Record<string, IAnimationConfig | IAnimationConfig[]>) => void;\n updateState: (state: MarkFunctionType<string> | null) => void;\n isElementAnimating: (element: IElement) => boolean;\n getAnimatorCount: () => number;\n getElementAnimators: (element: IElement | IElement[], animationState?: string) => IAnimator[];\n release: () => void;\n}\n"]}
1
+ {"version":3,"sources":["../src/types/animate.ts"],"names":[],"mappings":"","file":"animate.js","sourcesContent":["import type { IGraphic, ACustomAnimate, EasingType } from '@visactor/vrender/es/core';\nimport type { IPointLike } from '@visactor/vutils';\nimport type { MarkFunctionCallback, MarkFunctionType } from './mark';\nimport type { IMark } from './grammar';\nimport type { IElement } from './element';\nimport type { FunctionCallback } from './signal';\n\nexport type TypeAnimation<T extends IElement> = (\n element: T,\n options: any,\n animationParameters: IAnimationParameters\n) => { from?: { [channel: string]: any }; to?: { [channel: string]: any } };\n\nexport interface IClipAnimationOptions {\n clipDimension?: 'x' | 'y' | 'auto' | 'default';\n}\n\nexport interface IGrowCartesianAnimationOptions {\n orient?: 'positive' | 'negative';\n overall?: boolean | number;\n direction?: 'x' | 'y' | 'xy';\n}\n\nexport interface IGrowAngleAnimationOptions {\n orient?: 'clockwise' | 'anticlockwise';\n overall?: boolean | number;\n}\n\nexport interface IGrowRadiusAnimationOptions {\n orient?: 'inside' | 'outside';\n overall?: boolean | number;\n}\n\nexport interface IGrowPointsAnimationOptions {\n orient?: 'positive' | 'negative';\n}\n\nexport interface IGrowPointsOverallAnimationOptions extends IGrowPointsAnimationOptions {\n center?: IPointLike;\n}\n\nexport interface IScaleAnimationOptions {\n direction?: 'x' | 'y' | 'xy';\n}\n\nexport interface IMoveAnimationOptions {\n direction?: 'x' | 'y' | 'xy';\n orient?: 'positive' | 'negative';\n offset?: number;\n point?: { x?: number; y?: number } | FunctionCallback<{ x?: number; y?: number }>;\n}\n\nexport interface IRotateAnimationOptions {\n orient?: 'clockwise' | 'anticlockwise';\n angle?: number;\n}\n\n/** VGrammar 层提供的图元text上的图形属性,现在暂时会和VRender不一致 */\nexport interface TextItemAttributes {\n fontSize?: number;\n lineHeight?: number;\n font?: string;\n fontStyle?: string;\n fontVariant?: string;\n fontWeight?: string | number;\n lineBreak?: string;\n text?: string | string[];\n limit?: number;\n align?: string;\n baseline?: string;\n ellipsis?: string | boolean;\n dir?: string;\n}\n\n/** animation */\nexport type MarkFunctionValueType<T> = MarkFunctionCallback<T> | T;\n\nexport type IAnimationConfig = IAnimationTimeline | IAnimationTypeConfig;\n\n/**\n * state动画,暂时只支持简单配置\n */\nexport interface IStateAnimationConfig {\n duration?: number;\n easing?: EasingType;\n}\n\n/**\n * 动画 config 简化配置\n */\nexport interface IAnimationTypeConfig {\n type?: string;\n channel?: IAnimationChannelAttrs | IAnimationChannelAttributes;\n custom?: IAnimationChannelInterpolator | IAnimationCustomConstructor;\n customParameters?: MarkFunctionValueType<any>;\n easing?: EasingType;\n delay?: MarkFunctionValueType<number>;\n delayAfter?: MarkFunctionValueType<number>;\n duration?: MarkFunctionValueType<number>;\n oneByOne?: MarkFunctionValueType<boolean | number>;\n startTime?: MarkFunctionValueType<number>;\n totalTime?: MarkFunctionValueType<number>;\n /** loop: true 无限循环; loop: 正整数,表示循环的次数 */\n loop?: boolean | number;\n /** 动画 effect 配置项 */\n options?: MarkFunctionValueType<any>;\n /** 动画执行相关控制配置项 */\n controlOptions?: IAnimationControlOptions;\n}\n\n/**\n * 动画 timeline 完整配置,一条时间线内的动画单元只能串行\n * 多个timeline是可以并行的\n * 考虑到同一图元不能在多个timeline上,所以timeline不应该提供数组配置的能力\n */\nexport interface IAnimationTimeline {\n /** 为了方便动画编排,用户可以设置 id 用于识别时间线 */\n id?: string;\n /** 时间切片 */\n timeSlices: IAnimationTimeSlice | IAnimationTimeSlice[];\n /** 动画开始的相对时间,可以为负数 */\n startTime?: MarkFunctionValueType<number>;\n /** 动画时长 */\n totalTime?: MarkFunctionValueType<number>;\n /** 动画依次执行的延迟 */\n oneByOne?: MarkFunctionValueType<number | boolean>;\n /** loop: true 无限循环; loop: 正整数,表示循环的次数 */\n loop?: MarkFunctionValueType<number | boolean>;\n /** 对图元元素进行划分,和过滤类似,但是不同时间线不能同时作用在相同的元素上 */\n partitioner?: MarkFunctionCallback<boolean>;\n /** 对同一时间线上的元素进行排序 */\n sort?: (datumA: any, datumB: any, elementA: IElement, elementB: IElement, parameters: any) => number;\n /** 动画执行相关控制配置项 */\n controlOptions?: IAnimationControlOptions;\n}\n\nexport interface IAnimationTimeSlice {\n effects: IAnimationEffect | IAnimationEffect[];\n duration?: MarkFunctionValueType<number>;\n delay?: MarkFunctionValueType<number>;\n delayAfter?: MarkFunctionValueType<number>;\n}\n\nexport type IAnimationChannelFunction = (datum: any, element: IElement, parameters: IAnimationParameters) => any;\nexport type IAnimationChannelAttrs = Record<\n string,\n {\n from?: any | IAnimationChannelFunction;\n to?: any | IAnimationChannelFunction;\n }\n>;\nexport type IAnimationChannelAttributes = string[];\nexport type IAnimationChannelInterpolator = (\n ratio: number,\n from: any,\n to: any,\n nextAttributes: any,\n datum: any,\n element: IElement,\n parameters: IAnimationParameters\n) => boolean | void;\n\n// TODO: fix ACustomAnimate<any>\nexport interface IAnimationCustomConstructor {\n new (from: any, to: any, duration: number, ease: EasingType, parameters?: any): ACustomAnimate<any>;\n}\n\nexport interface IAnimationEffect {\n type?: string;\n channel?: IAnimationChannelAttrs | IAnimationChannelAttributes;\n custom?: IAnimationChannelInterpolator | IAnimationCustomConstructor;\n customParameters?: MarkFunctionValueType<any>;\n easing?: EasingType;\n /** options暂时没有处理 */\n options?: MarkFunctionValueType<any>;\n}\n\nexport interface IAnimationControlOptions {\n /** 当动画状态变更时清空动画 */\n stopWhenStateChange?: boolean;\n /** 是否立即应用动画初始状态 */\n immediatelyApply?: boolean;\n}\n\n/**\n * Animation timeline should be parsed into animation units,\n * which record all necessary configs for animator to execute animation.\n *\n * animation unit time:\n * |<--initialDelay-->| |<--loopDelay--><--Slices--><--looDelayAfter-->| |<--loopDuration-->|\n * |<-----------------loopDuration--------------->|\n */\nexport interface IAnimationUnit {\n /**\n * initial delay time before any animation loop\n */\n initialDelay: number;\n /**\n * total time for one animation loop\n */\n loopDuration: number;\n /**\n * delay time before time slices\n */\n loopDelay: number;\n /**\n * delay time after time slices\n */\n loopDelayAfter: number;\n /**\n * animating time in one animation loop\n */\n loopAnimateDuration: number;\n loopCount: number;\n totalTime: number;\n timeSlices: IAnimationTimeSlice[];\n}\n\nexport interface IAnimationRecord {\n start: IGraphic;\n end: IGraphic;\n changes: any[];\n}\n\nexport interface IAnimationParameters {\n width: number;\n height: number;\n mark: IMark;\n group: IMark | null;\n elementIndex: number;\n elementCount: number;\n view: any;\n}\n\nexport interface IParsedAnimationConfig {\n state: string;\n timeline: IAnimationTimeline;\n originConfig: IAnimationConfig;\n id: string;\n}\n\nexport interface IParsedAnimationAttrs {\n from?: any;\n to?: any;\n custom?: IAnimationChannelInterpolator | IAnimationCustomConstructor;\n customParameters?: any;\n}\n\n// animate structure\n\nexport interface IAnimatorOptions {\n state: string;\n timeline: IAnimationTimeline;\n id: string;\n}\n\nexport interface IAnimator {\n id: number;\n element: IElement;\n animationOptions: IAnimatorOptions;\n isAnimating: boolean;\n\n /** execute animation */\n animate: (animationParameters: IAnimationParameters, parameters: any) => this;\n /** set animation callback */\n callback: (callbackFunction: (...args: any[]) => void) => this;\n\n // animation control\n stop: (stopState?: 'start' | 'end', invokeCallback?: boolean) => this;\n pause: () => this;\n resume: () => this;\n\n /** set additional initial animation delay */\n startAt: (startTime: number) => this;\n /** get total animation execution time */\n getTotalAnimationTime: () => number;\n\n getEndAttributes: () => Record<string, any>;\n}\n\nexport interface IAnimateArranger {\n // animation control api\n parallel: (arranger: IAnimateArranger) => this;\n after: (arranger: IAnimateArranger) => this;\n\n // internal properties\n afterArranger: IAnimateArranger;\n parallelArrangers: IAnimateArranger[];\n animators: IAnimator[];\n totalTime: number;\n startTime: number;\n endTime: number;\n arrangeTime: () => void;\n}\n\nexport interface IBaseAnimate {\n // animation control\n stop: () => this;\n pause: () => this;\n resume: () => this;\n\n // internal animation process api\n animate: () => this;\n enable: () => this;\n disable: () => this;\n enableAnimationState: (state: string | string[]) => this;\n disableAnimationState: (state: string | string[]) => this;\n isAnimating: () => boolean;\n\n release: () => void;\n}\n\nexport interface IViewAnimate extends IBaseAnimate {\n animateAddition: (mark: IMark) => this;\n}\n\nexport interface IAnimate extends IBaseAnimate {\n mark: IMark;\n\n // additional animation control\n run: (config: IAnimationConfig | IAnimationConfig[]) => IAnimateArranger;\n runAnimationByState: (animationState: string) => IAnimateArranger;\n stopAnimationByState: (animationState: string) => this;\n pauseAnimationByState: (animationState: string) => this;\n resumeAnimationByState: (animationState: string) => this;\n reverse: () => this;\n restart: () => this;\n record: () => this;\n recordEnd: () => this;\n\n // internal animation process api\n getAnimationConfigs: (animationState: string) => IParsedAnimationConfig[];\n updateConfig: (config: Record<string, IAnimationConfig | IAnimationConfig[]>) => void;\n updateState: (state: MarkFunctionType<string> | null) => void;\n isElementAnimating: (element: IElement) => boolean;\n getAnimatorCount: () => number;\n getElementAnimators: (element: IElement | IElement[], animationState?: string) => IAnimator[];\n release: () => void;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { IGraphicAttribute, ITextAttribute } from '@visactor/vrender-core';
1
+ import type { IGraphicAttribute, ITextAttribute, IRichTextCharacter } from '@visactor/vrender/es/core';
2
2
  import type { AxisBaseAttributes, BaseLabelAttrs, DataLabelAttrs, DataZoomAttributes, Direction, GridBaseAttributes, LegendBaseAttributes, OrientType, PlayerAttributes, ScrollBarAttributes, SliderAttributes, TitleAttrs } from '@visactor/vrender-components';
3
3
  import type { AxisEnum, ComponentEnum } from '../graph';
4
4
  import type { Nil } from './base';
@@ -135,13 +135,13 @@ export interface PlayerSpec extends ComponentSpec<Partial<PlayerAttributes>> {
135
135
  source?: IData | string | any[];
136
136
  }
137
137
  export interface ITitle extends IComponent {
138
- title: (text: MarkFunctionType<string | number | number[] | string[]> | Nil) => this;
139
- subTitle: (text: MarkFunctionType<string | number | number[] | string[]> | Nil) => this;
138
+ title: (text: MarkFunctionType<string | number | number[] | string[] | IRichTextCharacter[]> | Nil) => this;
139
+ subTitle: (text: MarkFunctionType<string | number | number[] | string[] | IRichTextCharacter[]> | Nil) => this;
140
140
  }
141
141
  export interface TitleSpec extends ComponentSpec<Partial<TitleAttrs>> {
142
142
  componentType: ComponentEnum.title;
143
- title?: MarkFunctionType<string | number | number[] | string[]>;
144
- subTitle?: MarkFunctionType<string | number | number[] | string[]>;
143
+ title?: MarkFunctionType<string | number | number[] | string[] | IRichTextCharacter[]>;
144
+ subTitle?: MarkFunctionType<string | number | number[] | string[] | IRichTextCharacter[]>;
145
145
  }
146
146
  export type ScrollbarFilterValue = {
147
147
  start?: number;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types/component.ts"],"names":[],"mappings":"","file":"component.js","sourcesContent":["import type { IGraphicAttribute, ITextAttribute } from '@visactor/vrender-core';\nimport type {\n AxisBaseAttributes,\n BaseLabelAttrs,\n DataLabelAttrs,\n DataZoomAttributes,\n Direction,\n GridBaseAttributes,\n LegendBaseAttributes,\n OrientType,\n PlayerAttributes,\n ScrollBarAttributes,\n SliderAttributes,\n TitleAttrs\n} from '@visactor/vrender-components';\nimport type { AxisEnum, ComponentEnum } from '../graph';\nimport type { Nil } from './base';\nimport type { IComponent, IData, IGroupMark, IMark, IScale } from './grammar';\nimport type {\n ChannelEncodeType,\n ComponentSpec,\n GenerateBasicEncoderSpec,\n MarkFunctionType,\n ScaleEncodeType\n} from './mark';\nimport type { IView } from './view';\nimport type { IBaseScale } from '@visactor/vscale';\nimport type { SimpleSignalType } from './signal';\n\n// scale component\n\nexport interface IScaleComponent extends IComponent {\n scale: (scale?: IScale | string | Nil) => this;\n\n // internal interface\n getScale: () => IScale;\n}\n\nexport interface ScaleComponentSpec<\n BasicEncoderSpec extends GenerateBasicEncoderSpec<IGraphicAttribute> = GenerateBasicEncoderSpec<IGraphicAttribute>\n> extends ComponentSpec<BasicEncoderSpec> {\n scale?: IScale | string;\n}\n\n// axis component\n\nexport type AxisType = 'line' | 'circle';\n\nexport interface IAxis extends IScaleComponent {\n axisType: (axisType: AxisType | Nil) => this;\n tickCount: (tickCount: SimpleSignalType<number> | Nil) => this;\n inside: (inside: MarkFunctionType<boolean> | Nil) => this;\n baseValue: (baseValue: MarkFunctionType<number> | Nil) => this;\n\n // internal interface\n getAxisComponentType: () => keyof typeof AxisEnum;\n}\n\nexport interface AxisSpec extends ScaleComponentSpec<Partial<AxisBaseAttributes>> {\n componentType: ComponentEnum.axis;\n axisType?: AxisType;\n tickCount?: SimpleSignalType<number>;\n inside?: MarkFunctionType<boolean>;\n baseValue?: MarkFunctionType<number>;\n}\n\n// grid component\n\nexport type GridShape = 'line' | 'circle' | 'polygon';\n\nexport interface IGrid extends IScaleComponent {\n gridType: (gridType: AxisType | Nil) => this;\n gridShape: (gridShape: GridShape | Nil) => this;\n target: (axis: IAxis | string | Nil) => this;\n tickCount: (tickCount: SimpleSignalType<number> | Nil) => this;\n inside: (inside: MarkFunctionType<boolean> | Nil) => this;\n baseValue: (baseValue: MarkFunctionType<number> | Nil) => this;\n}\n\nexport interface GridSpec extends ScaleComponentSpec<Partial<GridBaseAttributes>> {\n componentType: ComponentEnum.grid;\n gridType?: AxisType;\n gridShape?: GridShape;\n target?: IAxis | string;\n tickCount?: MarkFunctionType<number>;\n inside?: MarkFunctionType<boolean>;\n baseValue?: MarkFunctionType<number>;\n}\n\n// legend component\n\nexport type LegendType = 'auto' | 'discrete' | 'color' | 'size';\n\nexport interface ILegend extends IScaleComponent {\n legendType: (legendType: LegendType | Nil) => this;\n\n // immediate functions\n setSelected: (selectedValues: any[]) => this;\n\n // internal interface\n isContinuousLegend: () => boolean;\n}\n\nexport interface LegendSpec extends ScaleComponentSpec<LegendBaseAttributes> {\n componentType: ComponentEnum.legend;\n legendType?: LegendType;\n shapeScale?: IScale | string;\n}\n\n// slider component\n\nexport type SliderFilterValue = { start: number; end: number };\n\nexport interface ISlider extends IComponent {\n min: (min: MarkFunctionType<number> | Nil) => this;\n max: (max: MarkFunctionType<number> | Nil) => this;\n\n // immediate functions\n setStartEndValue: (start?: number, end?: number) => this;\n}\n\nexport interface SliderSpec extends ComponentSpec<Partial<SliderAttributes>> {\n componentType: ComponentEnum.slider;\n min?: MarkFunctionType<number>;\n max?: MarkFunctionType<number>;\n}\n\n// datazoom component\n\nexport type DatazoomFilterValue = { start: number; end: number; startRatio: number; endRatio: number };\n\nexport interface IDatazoom extends IComponent {\n preview: (\n data: IData | string | Nil,\n x: ScaleEncodeType | Nil,\n y: ScaleEncodeType | Nil,\n x1?: ChannelEncodeType | Nil,\n y1?: ChannelEncodeType | Nil\n ) => this;\n\n // immediate functions\n setStartEndValue: (start?: number, end?: number) => this;\n getStartEndValue: () => { start: number; end: number } | Nil;\n\n // internal interface\n invertDatazoomRatio: (ratio: number) => any;\n getDatazoomMainScale: () => IBaseScale;\n}\n\nexport type DataZoomEncoderSpec = GenerateBasicEncoderSpec<Partial<DataZoomAttributes> & { x1?: number; y1?: number }>;\nexport interface DatazoomSpec extends ComponentSpec<DataZoomEncoderSpec> {\n componentType: ComponentEnum.datazoom;\n preview?: {\n data: IData | string;\n x?: ScaleEncodeType;\n y?: ScaleEncodeType;\n x1?: ChannelEncodeType;\n y1?: ChannelEncodeType;\n };\n}\n\n// label component\n\nexport interface ILabel extends IComponent {\n labelStyle: (attributes: MarkFunctionType<Partial<BaseLabelAttrs>>) => this;\n size: (attributes: MarkFunctionType<DataLabelAttrs['size']>) => this;\n target: (mark: IMark | IMark[] | string | string[] | Nil) => this;\n}\n\nexport type LabelEncoderSpec = GenerateBasicEncoderSpec<Partial<BaseLabelAttrs> & { text?: ITextAttribute['text'] }>;\nexport interface LabelSpec extends ComponentSpec<LabelEncoderSpec> {\n componentType: ComponentEnum.label;\n labelStyle?: MarkFunctionType<Partial<BaseLabelAttrs>>;\n size?: MarkFunctionType<DataLabelAttrs['size']>;\n target?: IMark | IMark[] | string | string[];\n}\n\n// player component\n\nexport type PlayerType = 'auto' | 'discrete' | 'continuous';\n\nexport type PlayerFilterValue = { index: number; value: any };\n\nexport interface IPlayer extends IComponent {\n playerType: (playerType: PlayerType) => this;\n source: (source: IData | string | any[] | Nil) => this;\n\n // immediate functions\n play: () => this;\n pause: () => this;\n backward: () => this;\n forward: () => this;\n}\n\nexport interface PlayerSpec extends ComponentSpec<Partial<PlayerAttributes>> {\n componentType: ComponentEnum.player;\n playerType?: PlayerType;\n source?: IData | string | any[];\n}\n\n// title component\n\nexport interface ITitle extends IComponent {\n title: (text: MarkFunctionType<string | number | number[] | string[]> | Nil) => this;\n subTitle: (text: MarkFunctionType<string | number | number[] | string[]> | Nil) => this;\n}\n\nexport interface TitleSpec extends ComponentSpec<Partial<TitleAttrs>> {\n componentType: ComponentEnum.title;\n title?: MarkFunctionType<string | number | number[] | string[]>;\n subTitle?: MarkFunctionType<string | number | number[] | string[]>;\n}\n\n// scrollbar component\n\nexport type ScrollbarFilterValue = { start?: number; end?: number; startRatio: number; endRatio: number };\n\nexport interface IScrollbar extends IScaleComponent {\n container: (container: IGroupMark | string | Nil) => this;\n direction: (direction: MarkFunctionType<Direction> | Nil) => this;\n position: (position: MarkFunctionType<OrientType> | Nil) => this;\n\n // immediate functions\n setScrollStart: (start: number) => this;\n getScrollRange: () => [number, number] | Nil;\n}\n\nexport interface ScrollbarSpec extends ScaleComponentSpec<Partial<ScrollBarAttributes>> {\n componentType: ComponentEnum.scrollbar;\n container?: IGroupMark | string;\n direction?: MarkFunctionType<Direction>;\n position?: MarkFunctionType<OrientType>;\n}\n\n// built-in components\n\nexport type BuiltInComponentSpec =\n | AxisSpec\n | LegendSpec\n | SliderSpec\n | DatazoomSpec\n | LabelSpec\n | PlayerSpec\n | TitleSpec\n | ScrollbarSpec;\n\nexport interface IComponentConstructor {\n readonly componentType: string;\n\n new (view: IView, group?: IGroupMark, mode?: '2d' | '3d'): IComponent;\n}\n"]}
1
+ {"version":3,"sources":["../src/types/component.ts"],"names":[],"mappings":"","file":"component.js","sourcesContent":["import type { IGraphicAttribute, ITextAttribute, IRichTextCharacter } from '@visactor/vrender/es/core';\nimport type {\n AxisBaseAttributes,\n BaseLabelAttrs,\n DataLabelAttrs,\n DataZoomAttributes,\n Direction,\n GridBaseAttributes,\n LegendBaseAttributes,\n OrientType,\n PlayerAttributes,\n ScrollBarAttributes,\n SliderAttributes,\n TitleAttrs\n} from '@visactor/vrender-components';\nimport type { AxisEnum, ComponentEnum } from '../graph';\nimport type { Nil } from './base';\nimport type { IComponent, IData, IGroupMark, IMark, IScale } from './grammar';\nimport type {\n ChannelEncodeType,\n ComponentSpec,\n GenerateBasicEncoderSpec,\n MarkFunctionType,\n ScaleEncodeType\n} from './mark';\nimport type { IView } from './view';\nimport type { IBaseScale } from '@visactor/vscale';\nimport type { SimpleSignalType } from './signal';\n\n// scale component\n\nexport interface IScaleComponent extends IComponent {\n scale: (scale?: IScale | string | Nil) => this;\n\n // internal interface\n getScale: () => IScale;\n}\n\nexport interface ScaleComponentSpec<\n BasicEncoderSpec extends GenerateBasicEncoderSpec<IGraphicAttribute> = GenerateBasicEncoderSpec<IGraphicAttribute>\n> extends ComponentSpec<BasicEncoderSpec> {\n scale?: IScale | string;\n}\n\n// axis component\n\nexport type AxisType = 'line' | 'circle';\n\nexport interface IAxis extends IScaleComponent {\n axisType: (axisType: AxisType | Nil) => this;\n tickCount: (tickCount: SimpleSignalType<number> | Nil) => this;\n inside: (inside: MarkFunctionType<boolean> | Nil) => this;\n baseValue: (baseValue: MarkFunctionType<number> | Nil) => this;\n\n // internal interface\n getAxisComponentType: () => keyof typeof AxisEnum;\n}\n\nexport interface AxisSpec extends ScaleComponentSpec<Partial<AxisBaseAttributes>> {\n componentType: ComponentEnum.axis;\n axisType?: AxisType;\n tickCount?: SimpleSignalType<number>;\n inside?: MarkFunctionType<boolean>;\n baseValue?: MarkFunctionType<number>;\n}\n\n// grid component\n\nexport type GridShape = 'line' | 'circle' | 'polygon';\n\nexport interface IGrid extends IScaleComponent {\n gridType: (gridType: AxisType | Nil) => this;\n gridShape: (gridShape: GridShape | Nil) => this;\n target: (axis: IAxis | string | Nil) => this;\n tickCount: (tickCount: SimpleSignalType<number> | Nil) => this;\n inside: (inside: MarkFunctionType<boolean> | Nil) => this;\n baseValue: (baseValue: MarkFunctionType<number> | Nil) => this;\n}\n\nexport interface GridSpec extends ScaleComponentSpec<Partial<GridBaseAttributes>> {\n componentType: ComponentEnum.grid;\n gridType?: AxisType;\n gridShape?: GridShape;\n target?: IAxis | string;\n tickCount?: MarkFunctionType<number>;\n inside?: MarkFunctionType<boolean>;\n baseValue?: MarkFunctionType<number>;\n}\n\n// legend component\n\nexport type LegendType = 'auto' | 'discrete' | 'color' | 'size';\n\nexport interface ILegend extends IScaleComponent {\n legendType: (legendType: LegendType | Nil) => this;\n\n // immediate functions\n setSelected: (selectedValues: any[]) => this;\n\n // internal interface\n isContinuousLegend: () => boolean;\n}\n\nexport interface LegendSpec extends ScaleComponentSpec<LegendBaseAttributes> {\n componentType: ComponentEnum.legend;\n legendType?: LegendType;\n shapeScale?: IScale | string;\n}\n\n// slider component\n\nexport type SliderFilterValue = { start: number; end: number };\n\nexport interface ISlider extends IComponent {\n min: (min: MarkFunctionType<number> | Nil) => this;\n max: (max: MarkFunctionType<number> | Nil) => this;\n\n // immediate functions\n setStartEndValue: (start?: number, end?: number) => this;\n}\n\nexport interface SliderSpec extends ComponentSpec<Partial<SliderAttributes>> {\n componentType: ComponentEnum.slider;\n min?: MarkFunctionType<number>;\n max?: MarkFunctionType<number>;\n}\n\n// datazoom component\n\nexport type DatazoomFilterValue = { start: number; end: number; startRatio: number; endRatio: number };\n\nexport interface IDatazoom extends IComponent {\n preview: (\n data: IData | string | Nil,\n x: ScaleEncodeType | Nil,\n y: ScaleEncodeType | Nil,\n x1?: ChannelEncodeType | Nil,\n y1?: ChannelEncodeType | Nil\n ) => this;\n\n // immediate functions\n setStartEndValue: (start?: number, end?: number) => this;\n getStartEndValue: () => { start: number; end: number } | Nil;\n\n // internal interface\n invertDatazoomRatio: (ratio: number) => any;\n getDatazoomMainScale: () => IBaseScale;\n}\n\nexport type DataZoomEncoderSpec = GenerateBasicEncoderSpec<Partial<DataZoomAttributes> & { x1?: number; y1?: number }>;\nexport interface DatazoomSpec extends ComponentSpec<DataZoomEncoderSpec> {\n componentType: ComponentEnum.datazoom;\n preview?: {\n data: IData | string;\n x?: ScaleEncodeType;\n y?: ScaleEncodeType;\n x1?: ChannelEncodeType;\n y1?: ChannelEncodeType;\n };\n}\n\n// label component\n\nexport interface ILabel extends IComponent {\n labelStyle: (attributes: MarkFunctionType<Partial<BaseLabelAttrs>>) => this;\n size: (attributes: MarkFunctionType<DataLabelAttrs['size']>) => this;\n target: (mark: IMark | IMark[] | string | string[] | Nil) => this;\n}\n\nexport type LabelEncoderSpec = GenerateBasicEncoderSpec<Partial<BaseLabelAttrs> & { text?: ITextAttribute['text'] }>;\nexport interface LabelSpec extends ComponentSpec<LabelEncoderSpec> {\n componentType: ComponentEnum.label;\n labelStyle?: MarkFunctionType<Partial<BaseLabelAttrs>>;\n size?: MarkFunctionType<DataLabelAttrs['size']>;\n target?: IMark | IMark[] | string | string[];\n}\n\n// player component\n\nexport type PlayerType = 'auto' | 'discrete' | 'continuous';\n\nexport type PlayerFilterValue = { index: number; value: any };\n\nexport interface IPlayer extends IComponent {\n playerType: (playerType: PlayerType) => this;\n source: (source: IData | string | any[] | Nil) => this;\n\n // immediate functions\n play: () => this;\n pause: () => this;\n backward: () => this;\n forward: () => this;\n}\n\nexport interface PlayerSpec extends ComponentSpec<Partial<PlayerAttributes>> {\n componentType: ComponentEnum.player;\n playerType?: PlayerType;\n source?: IData | string | any[];\n}\n\n// title component\n\nexport interface ITitle extends IComponent {\n title: (text: MarkFunctionType<string | number | number[] | string[] | IRichTextCharacter[]> | Nil) => this;\n subTitle: (text: MarkFunctionType<string | number | number[] | string[] | IRichTextCharacter[]> | Nil) => this;\n}\n\nexport interface TitleSpec extends ComponentSpec<Partial<TitleAttrs>> {\n componentType: ComponentEnum.title;\n title?: MarkFunctionType<string | number | number[] | string[] | IRichTextCharacter[]>;\n subTitle?: MarkFunctionType<string | number | number[] | string[] | IRichTextCharacter[]>;\n}\n\n// scrollbar component\n\nexport type ScrollbarFilterValue = { start?: number; end?: number; startRatio: number; endRatio: number };\n\nexport interface IScrollbar extends IScaleComponent {\n container: (container: IGroupMark | string | Nil) => this;\n direction: (direction: MarkFunctionType<Direction> | Nil) => this;\n position: (position: MarkFunctionType<OrientType> | Nil) => this;\n\n // immediate functions\n setScrollStart: (start: number) => this;\n getScrollRange: () => [number, number] | Nil;\n}\n\nexport interface ScrollbarSpec extends ScaleComponentSpec<Partial<ScrollBarAttributes>> {\n componentType: ComponentEnum.scrollbar;\n container?: IGroupMark | string;\n direction?: MarkFunctionType<Direction>;\n position?: MarkFunctionType<OrientType>;\n}\n\n// built-in components\n\nexport type BuiltInComponentSpec =\n | AxisSpec\n | LegendSpec\n | SliderSpec\n | DatazoomSpec\n | LabelSpec\n | PlayerSpec\n | TitleSpec\n | ScrollbarSpec;\n\nexport interface IComponentConstructor {\n readonly componentType: string;\n\n new (view: IView, group?: IGroupMark, mode?: '2d' | '3d'): IComponent;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { IArc, IArc3d, IArea, ICircle, IGlyph, IGraphic, IGroup, IImage, ILine, IPath, IPolygon, IPyramid3d, IRect, IRect3d, IRichText, ISymbol, IText } from '@visactor/vrender-core';
1
+ import type { IArc, IArc3d, IArea, ICircle, IGlyph, IGraphic, IGroup, IImage, ILine, IPath, IPolygon, IPyramid3d, IRect, IRect3d, IRichText, ISymbol, IText } from '@visactor/vrender/es/core';
2
2
  import type { DiffState } from '../graph/enums';
3
3
  import type { IMark, IGlyphMark } from './grammar';
4
4
  import type { BaseEncodeSpec, IMarkConfig, MarkFunctionType, MarkKeySpec, MarkType } from './mark';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types/element.ts"],"names":[],"mappings":"","file":"element.js","sourcesContent":["import type {\n IArc,\n IArc3d,\n IArea,\n ICircle,\n IGlyph,\n IGraphic,\n IGroup,\n IImage,\n ILine,\n IPath,\n IPolygon,\n IPyramid3d,\n IRect,\n IRect3d,\n IRichText,\n ISymbol,\n IText\n} from '@visactor/vrender-core';\nimport type { DiffState } from '../graph/enums';\nimport type { IMark, IGlyphMark } from './grammar';\nimport type { BaseEncodeSpec, IMarkConfig, MarkFunctionType, MarkKeySpec, MarkType } from './mark';\n\nexport interface ElementGraphicMap {\n circle: ICircle;\n arc: IArc;\n area: IArea;\n image: IImage;\n line: ILine;\n path: IPath;\n rule: ILine;\n shape: IPath;\n symbol: ISymbol;\n text: IText;\n richtext: IRichText;\n polygon: IPolygon;\n cell: ISymbol;\n interval: IGraphic;\n rect: IRect;\n rect3d: IRect3d;\n arc3d: IArc3d;\n pyramid3d: IPyramid3d;\n group: IGroup;\n glyph: IGlyph;\n linkPath: IGlyph;\n treePath: IGlyph;\n wave: IGlyph;\n ripplePoint: IGlyph;\n barBoxplot: IGlyph;\n boxPlot: IGlyph;\n component: IGroup;\n axis: IGroup;\n legend: IGroup;\n corsshair: IGroup;\n slider: IGroup;\n datazoom: IGroup;\n label: IGroup;\n player: IGroup;\n}\n\nexport type GetGraphicByType<T> = T extends keyof ElementGraphicMap ? ElementGraphicMap[T] : IGraphic;\n\n/**\n * 保存graphicItem状态\n */\nexport interface MarkElementItem {\n /** 唯一key */\n key: string;\n /** 原始数据 */\n datum: any;\n /** VGrammar view */\n view: any;\n /** 当前渲染帧下graphicItem对应的最新属性 */\n nextAttrs?: any;\n /** 是否初始化过,用于解决collection mark对应的item,可能跳过enter状态的问题 */\n // hasEntered: boolean;\n}\nexport interface IElement {\n mark: IMark;\n isReserved: boolean;\n diffState: DiffState;\n key: string;\n groupKey?: string;\n data?: any[];\n /**\n * 不推荐使用,但是collection图元暂时可能回涉及到相关修改\n */\n items: MarkElementItem[];\n\n initGraphicItem: (attrs?: any) => void;\n updateGraphicItem: (config: IMarkConfig) => void;\n\n getDatum: () => any;\n getBounds: () => any;\n getGraphicItem: () => IGraphic;\n removeGraphicItem: () => void;\n resetGraphicItem: () => void;\n\n /**\n * 获取 graphic 视觉通道属性\n * @param channel 视觉通道\n * @param prev 是否从之前的 graphic 属性上获取,默认为 false\n * @returns 视觉通道值\n */\n getGraphicAttribute: (channel: string, prev?: boolean) => any;\n /**\n * 设置 graphic 视觉通道属性\n * @param channel 视觉通道\n * @param value 视觉通道属性\n * @param final 是否更新 graphic 最终变更的视觉通道结果,默认为 false\n */\n setGraphicAttribute: (channel: string, value: any, final?: boolean) => void;\n /**\n * 设置一系列 graphic 视觉通道属性\n * @param attributes 视觉通道键值对\n * @param final 是否更新 graphic 最终变更的视觉通道结果,默认为 false\n */\n setGraphicAttributes: (attributes: { [channel: string]: any }, final?: boolean) => void;\n\n /**\n * 【慎重使用】获取 VGrammar 自身的视觉通道属性\n * 只有在 'afterEncodeItems' 时机的mark transform中才能调用\n */\n getItemAttribute: (channel?: string) => any;\n /**\n * 【慎重使用】设置 VGrammar 自身的视觉通道\n * 只有在 'afterEncodeItems' 时机的mark transform中才能调用\n * @param attributes\n * @returns\n */\n setItemAttributes: (attributes: { [channel: string]: any } | any[]) => void;\n\n // element 执行流程相关接口\n updateData: (groupKey: string, data: any[], keyGenerator: MarkKeySpec, view: any) => void;\n state: (markState: MarkFunctionType<string | string[]>, parameters?: any) => void;\n encodeItems: (items: MarkElementItem[], encoders: BaseEncodeSpec, isReentered?: boolean, parameters?: any) => void;\n encodeGraphic: (attributes?: any) => void;\n transformElementItems: (items: MarkElementItem[], markType: MarkType, computePoints?: boolean) => Record<string, any>;\n remove: () => void;\n release: () => void;\n\n // 动画相关接口\n\n getFinalGraphicAttributes: () => { [key: string]: any };\n getPrevGraphicAttributes: () => { [key: string]: any };\n getNextGraphicAttributes: () => { [key: string]: any };\n clearChangedGraphicAttributes: () => void;\n clearGraphicAttributes: () => void;\n\n // state相关接口\n getStates: () => string[];\n hasState: (state: string) => boolean;\n clearStates: (noAnimation?: boolean) => void;\n addState: (state: string | string[], attrs?: any) => void;\n removeState: (state: string | string[]) => void;\n useStates: (states: string[], noAnimation?: boolean) => void;\n}\n\nexport interface IGlyphElement<P = any> extends IElement {\n mark: IGlyphMark;\n\n getGlyphGraphicItems: () => { [markName: string]: any };\n\n getGraphicAttribute: (channel: string, prev?: boolean, markName?: any) => any;\n setGraphicAttribute: (channel: string, value: any, final?: boolean, markName?: any) => void;\n setGraphicAttributes: (attributes: { [channel: string]: any }, final?: boolean, markName?: any) => void;\n\n getFinalGraphicAttributes: (markName?: string) => { [key: string]: any };\n getPrevGraphicAttributes: (markName?: string) => { [key: string]: any };\n getNextGraphicAttributes: (markName?: string) => { [key: string]: any };\n\n encodeCustom: (nextAttrs?: any) => { [markName: string]: any };\n}\n"]}
1
+ {"version":3,"sources":["../src/types/element.ts"],"names":[],"mappings":"","file":"element.js","sourcesContent":["import type {\n IArc,\n IArc3d,\n IArea,\n ICircle,\n IGlyph,\n IGraphic,\n IGroup,\n IImage,\n ILine,\n IPath,\n IPolygon,\n IPyramid3d,\n IRect,\n IRect3d,\n IRichText,\n ISymbol,\n IText\n} from '@visactor/vrender/es/core';\nimport type { DiffState } from '../graph/enums';\nimport type { IMark, IGlyphMark } from './grammar';\nimport type { BaseEncodeSpec, IMarkConfig, MarkFunctionType, MarkKeySpec, MarkType } from './mark';\n\nexport interface ElementGraphicMap {\n circle: ICircle;\n arc: IArc;\n area: IArea;\n image: IImage;\n line: ILine;\n path: IPath;\n rule: ILine;\n shape: IPath;\n symbol: ISymbol;\n text: IText;\n richtext: IRichText;\n polygon: IPolygon;\n cell: ISymbol;\n interval: IGraphic;\n rect: IRect;\n rect3d: IRect3d;\n arc3d: IArc3d;\n pyramid3d: IPyramid3d;\n group: IGroup;\n glyph: IGlyph;\n linkPath: IGlyph;\n treePath: IGlyph;\n wave: IGlyph;\n ripplePoint: IGlyph;\n barBoxplot: IGlyph;\n boxPlot: IGlyph;\n component: IGroup;\n axis: IGroup;\n legend: IGroup;\n corsshair: IGroup;\n slider: IGroup;\n datazoom: IGroup;\n label: IGroup;\n player: IGroup;\n}\n\nexport type GetGraphicByType<T> = T extends keyof ElementGraphicMap ? ElementGraphicMap[T] : IGraphic;\n\n/**\n * 保存graphicItem状态\n */\nexport interface MarkElementItem {\n /** 唯一key */\n key: string;\n /** 原始数据 */\n datum: any;\n /** VGrammar view */\n view: any;\n /** 当前渲染帧下graphicItem对应的最新属性 */\n nextAttrs?: any;\n /** 是否初始化过,用于解决collection mark对应的item,可能跳过enter状态的问题 */\n // hasEntered: boolean;\n}\nexport interface IElement {\n mark: IMark;\n isReserved: boolean;\n diffState: DiffState;\n key: string;\n groupKey?: string;\n data?: any[];\n /**\n * 不推荐使用,但是collection图元暂时可能回涉及到相关修改\n */\n items: MarkElementItem[];\n\n initGraphicItem: (attrs?: any) => void;\n updateGraphicItem: (config: IMarkConfig) => void;\n\n getDatum: () => any;\n getBounds: () => any;\n getGraphicItem: () => IGraphic;\n removeGraphicItem: () => void;\n resetGraphicItem: () => void;\n\n /**\n * 获取 graphic 视觉通道属性\n * @param channel 视觉通道\n * @param prev 是否从之前的 graphic 属性上获取,默认为 false\n * @returns 视觉通道值\n */\n getGraphicAttribute: (channel: string, prev?: boolean) => any;\n /**\n * 设置 graphic 视觉通道属性\n * @param channel 视觉通道\n * @param value 视觉通道属性\n * @param final 是否更新 graphic 最终变更的视觉通道结果,默认为 false\n */\n setGraphicAttribute: (channel: string, value: any, final?: boolean) => void;\n /**\n * 设置一系列 graphic 视觉通道属性\n * @param attributes 视觉通道键值对\n * @param final 是否更新 graphic 最终变更的视觉通道结果,默认为 false\n */\n setGraphicAttributes: (attributes: { [channel: string]: any }, final?: boolean) => void;\n\n /**\n * 【慎重使用】获取 VGrammar 自身的视觉通道属性\n * 只有在 'afterEncodeItems' 时机的mark transform中才能调用\n */\n getItemAttribute: (channel?: string) => any;\n /**\n * 【慎重使用】设置 VGrammar 自身的视觉通道\n * 只有在 'afterEncodeItems' 时机的mark transform中才能调用\n * @param attributes\n * @returns\n */\n setItemAttributes: (attributes: { [channel: string]: any } | any[]) => void;\n\n // element 执行流程相关接口\n updateData: (groupKey: string, data: any[], keyGenerator: MarkKeySpec, view: any) => void;\n state: (markState: MarkFunctionType<string | string[]>, parameters?: any) => void;\n encodeItems: (items: MarkElementItem[], encoders: BaseEncodeSpec, isReentered?: boolean, parameters?: any) => void;\n encodeGraphic: (attributes?: any) => void;\n transformElementItems: (items: MarkElementItem[], markType: MarkType, computePoints?: boolean) => Record<string, any>;\n remove: () => void;\n release: () => void;\n\n // 动画相关接口\n\n getFinalGraphicAttributes: () => { [key: string]: any };\n getPrevGraphicAttributes: () => { [key: string]: any };\n getNextGraphicAttributes: () => { [key: string]: any };\n clearChangedGraphicAttributes: () => void;\n clearGraphicAttributes: () => void;\n\n // state相关接口\n getStates: () => string[];\n hasState: (state: string) => boolean;\n clearStates: (noAnimation?: boolean) => void;\n addState: (state: string | string[], attrs?: any) => void;\n removeState: (state: string | string[]) => void;\n useStates: (states: string[], noAnimation?: boolean) => void;\n}\n\nexport interface IGlyphElement<P = any> extends IElement {\n mark: IGlyphMark;\n\n getGlyphGraphicItems: () => { [markName: string]: any };\n\n getGraphicAttribute: (channel: string, prev?: boolean, markName?: any) => any;\n setGraphicAttribute: (channel: string, value: any, final?: boolean, markName?: any) => void;\n setGraphicAttributes: (attributes: { [channel: string]: any }, final?: boolean, markName?: any) => void;\n\n getFinalGraphicAttributes: (markName?: string) => { [key: string]: any };\n getPrevGraphicAttributes: (markName?: string) => { [key: string]: any };\n getNextGraphicAttributes: (markName?: string) => { [key: string]: any };\n\n encodeCustom: (nextAttrs?: any) => { [markName: string]: any };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { CustomEvent, FederatedEvent } from '@visactor/vrender-core';
1
+ import type { CustomEvent, FederatedEvent } from '@visactor/vrender/es/core';
2
2
  import type { IAnimationConfig, IElement, IGlyphElement, IMark } from '.';
3
3
  import type { MarkType } from './mark';
4
4
  import type { SignalDependency } from './signal';
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types/event.ts"],"names":[],"mappings":"","file":"event.js","sourcesContent":["import type { CustomEvent, FederatedEvent } from '@visactor/vrender-core';\nimport type { IAnimationConfig, IElement, IGlyphElement, IMark } from '.';\nimport type { MarkType } from './mark';\nimport type { SignalDependency } from './signal';\n\nexport type AnimationEvent = {\n mark: IMark;\n animationState: string;\n animationConfig: IAnimationConfig;\n};\n\nexport type InteractionEvent = (FederatedEvent | CustomEvent) & { element?: IElement | IGlyphElement };\nexport type GrammarEvent = InteractionEvent | AnimationEvent;\n\nexport type EventHandler<T> = (event?: GrammarEvent, value?: T) => void;\nexport type BaseEventHandler = AnimationEventHandler | InteractionEventHandler;\nexport type AnimationEventHandler = (event?: AnimationEvent) => void;\nexport type InteractionEventHandler = (event?: InteractionEvent, element?: IElement | IGlyphElement) => void;\nexport type ResizeHandler = EventHandler<{ width?: number; height?: number }>;\n\nexport type AnimationEventType = 'animationStart' | 'animationEnd' | 'elementAnimationStart' | 'elementAnimationEnd';\n\nexport type AnimationListenerHandler = (event?: AnimationEvent, el?: IElement) => void;\n\nexport type ViewEventType =\n | 'view:pointerdown'\n | 'view:pointerup'\n | 'view:pointerupoutside'\n | 'view:pointertap'\n | 'view:pointerover'\n | 'view:pointerenter'\n | 'view:pointerleave'\n | 'view:pointerout'\n | 'view:mousedown'\n | 'view:mouseup'\n | 'view:mouseupoutside'\n // 右键操作\n | 'view:rightdown'\n | 'view:rightup'\n | 'view:rightupoutside'\n | 'view:click'\n // 双击\n | 'view:dblclick'\n | 'view:mousemove'\n | 'view:mouseover'\n | 'view:mouseout'\n // 不会冒泡\n | 'view:mouseenter'\n // 不会冒泡\n | 'view:mouseleave'\n | 'view:wheel'\n | 'view:tap'\n | 'view:touchstart'\n | 'view:touchend'\n | 'view:touchendoutside'\n | 'view:touchmove'\n | 'view:touchcancel'\n // dragNdrop\n | 'view:dragstart'\n | 'view:drag'\n | 'view:dragenter'\n | 'view:dragleave'\n | 'view:dragover'\n | 'view:dragend'\n | 'view:drop'\n // gesture\n | 'view:pan'\n | 'view:panstart'\n | 'view:panend'\n | 'view:press'\n | 'view:pressup'\n | 'view:pressend'\n | 'view:pinch'\n | 'view:pinchstart'\n | 'view:pinchend'\n | 'view:swipe';\n\nexport type EventType =\n | 'pointerdown'\n | 'pointerup'\n | 'pointermove'\n // 指针抬起与按下的图形不同时触发\n | 'pointerupoutside'\n | 'pointertap'\n | 'pointerover'\n | 'pointermove'\n | 'pointerenter'\n | 'pointerleave'\n | 'pointerout'\n | 'mousedown'\n | 'mouseup'\n | 'mouseupoutside'\n // 右键操作\n | 'rightdown'\n | 'rightup'\n | 'rightupoutside'\n | 'click'\n // 双击\n | 'dblclick'\n | 'mousemove'\n | 'mouseover'\n | 'mouseout'\n // 不会冒泡\n | 'mouseenter'\n // 不会冒泡\n | 'mouseleave'\n | 'wheel'\n | 'tap'\n | 'touchstart'\n | 'touchend'\n | 'touchendoutside'\n | 'touchmove'\n | 'touchcancel'\n // dragNdrop\n | 'dragstart'\n | 'drag'\n | 'dragenter'\n | 'dragleave'\n | 'dragover'\n | 'dragend'\n | 'drop'\n // gesture\n | 'pan'\n | 'panstart'\n | 'panend'\n | 'press'\n | 'pressup'\n | 'pressend'\n | 'pinch'\n | 'pinchstart'\n | 'pinchend'\n | 'swipe'\n // resize\n | 'resize';\n\nexport type WindowEventType = string;\n\nexport interface EventCallbackContext extends Event {\n element?: any;\n datum?: any;\n}\n\nexport type EventCallback = (context: EventCallbackContext, params?: any) => any;\nexport interface BaseEventSpec {\n type: string;\n filter?: (context: EventCallbackContext) => boolean;\n throttle?: number;\n debounce?: number;\n /** 阻止事件的执行和传播 */\n consume?: boolean;\n callback?: EventCallback;\n dependency?: SignalDependency | SignalDependency[];\n target?:\n | string\n | Array<{\n target: string;\n callback: EventCallback;\n }>;\n}\n\nexport type MergeEventSpec = Omit<BaseEventSpec, 'type'> & { merge: string[] | BaseEventSpec[] };\n\nexport interface ParsedViewEventSpec extends BaseEventSpec {\n source?: 'view';\n type: EventType;\n markId?: string;\n markName?: string;\n markType?: string;\n}\n\nexport interface ParsedWindowEventSpec extends BaseEventSpec {\n source: 'window';\n type: WindowEventType;\n markId?: string;\n markName?: string;\n markType?: MarkType;\n}\n\nexport type EventSpec =\n | BaseEventSpec\n | ({\n between: [BaseEventSpec, BaseEventSpec];\n } & BaseEventSpec)\n | MergeEventSpec;\n\nexport type EventSourceType = 'window' | 'view';\n"]}
1
+ {"version":3,"sources":["../src/types/event.ts"],"names":[],"mappings":"","file":"event.js","sourcesContent":["import type { CustomEvent, FederatedEvent } from '@visactor/vrender/es/core';\nimport type { IAnimationConfig, IElement, IGlyphElement, IMark } from '.';\nimport type { MarkType } from './mark';\nimport type { SignalDependency } from './signal';\n\nexport type AnimationEvent = {\n mark: IMark;\n animationState: string;\n animationConfig: IAnimationConfig;\n};\n\nexport type InteractionEvent = (FederatedEvent | CustomEvent) & { element?: IElement | IGlyphElement };\nexport type GrammarEvent = InteractionEvent | AnimationEvent;\n\nexport type EventHandler<T> = (event?: GrammarEvent, value?: T) => void;\nexport type BaseEventHandler = AnimationEventHandler | InteractionEventHandler;\nexport type AnimationEventHandler = (event?: AnimationEvent) => void;\nexport type InteractionEventHandler = (event?: InteractionEvent, element?: IElement | IGlyphElement) => void;\nexport type ResizeHandler = EventHandler<{ width?: number; height?: number }>;\n\nexport type AnimationEventType = 'animationStart' | 'animationEnd' | 'elementAnimationStart' | 'elementAnimationEnd';\n\nexport type AnimationListenerHandler = (event?: AnimationEvent, el?: IElement) => void;\n\nexport type ViewEventType =\n | 'view:pointerdown'\n | 'view:pointerup'\n | 'view:pointerupoutside'\n | 'view:pointertap'\n | 'view:pointerover'\n | 'view:pointerenter'\n | 'view:pointerleave'\n | 'view:pointerout'\n | 'view:mousedown'\n | 'view:mouseup'\n | 'view:mouseupoutside'\n // 右键操作\n | 'view:rightdown'\n | 'view:rightup'\n | 'view:rightupoutside'\n | 'view:click'\n // 双击\n | 'view:dblclick'\n | 'view:mousemove'\n | 'view:mouseover'\n | 'view:mouseout'\n // 不会冒泡\n | 'view:mouseenter'\n // 不会冒泡\n | 'view:mouseleave'\n | 'view:wheel'\n | 'view:tap'\n | 'view:touchstart'\n | 'view:touchend'\n | 'view:touchendoutside'\n | 'view:touchmove'\n | 'view:touchcancel'\n // dragNdrop\n | 'view:dragstart'\n | 'view:drag'\n | 'view:dragenter'\n | 'view:dragleave'\n | 'view:dragover'\n | 'view:dragend'\n | 'view:drop'\n // gesture\n | 'view:pan'\n | 'view:panstart'\n | 'view:panend'\n | 'view:press'\n | 'view:pressup'\n | 'view:pressend'\n | 'view:pinch'\n | 'view:pinchstart'\n | 'view:pinchend'\n | 'view:swipe';\n\nexport type EventType =\n | 'pointerdown'\n | 'pointerup'\n | 'pointermove'\n // 指针抬起与按下的图形不同时触发\n | 'pointerupoutside'\n | 'pointertap'\n | 'pointerover'\n | 'pointermove'\n | 'pointerenter'\n | 'pointerleave'\n | 'pointerout'\n | 'mousedown'\n | 'mouseup'\n | 'mouseupoutside'\n // 右键操作\n | 'rightdown'\n | 'rightup'\n | 'rightupoutside'\n | 'click'\n // 双击\n | 'dblclick'\n | 'mousemove'\n | 'mouseover'\n | 'mouseout'\n // 不会冒泡\n | 'mouseenter'\n // 不会冒泡\n | 'mouseleave'\n | 'wheel'\n | 'tap'\n | 'touchstart'\n | 'touchend'\n | 'touchendoutside'\n | 'touchmove'\n | 'touchcancel'\n // dragNdrop\n | 'dragstart'\n | 'drag'\n | 'dragenter'\n | 'dragleave'\n | 'dragover'\n | 'dragend'\n | 'drop'\n // gesture\n | 'pan'\n | 'panstart'\n | 'panend'\n | 'press'\n | 'pressup'\n | 'pressend'\n | 'pinch'\n | 'pinchstart'\n | 'pinchend'\n | 'swipe'\n // resize\n | 'resize';\n\nexport type WindowEventType = string;\n\nexport interface EventCallbackContext extends Event {\n element?: any;\n datum?: any;\n}\n\nexport type EventCallback = (context: EventCallbackContext, params?: any) => any;\nexport interface BaseEventSpec {\n type: string;\n filter?: (context: EventCallbackContext) => boolean;\n throttle?: number;\n debounce?: number;\n /** 阻止事件的执行和传播 */\n consume?: boolean;\n callback?: EventCallback;\n dependency?: SignalDependency | SignalDependency[];\n target?:\n | string\n | Array<{\n target: string;\n callback: EventCallback;\n }>;\n}\n\nexport type MergeEventSpec = Omit<BaseEventSpec, 'type'> & { merge: string[] | BaseEventSpec[] };\n\nexport interface ParsedViewEventSpec extends BaseEventSpec {\n source?: 'view';\n type: EventType;\n markId?: string;\n markName?: string;\n markType?: string;\n}\n\nexport interface ParsedWindowEventSpec extends BaseEventSpec {\n source: 'window';\n type: WindowEventType;\n markId?: string;\n markName?: string;\n markType?: MarkType;\n}\n\nexport type EventSpec =\n | BaseEventSpec\n | ({\n between: [BaseEventSpec, BaseEventSpec];\n } & BaseEventSpec)\n | MergeEventSpec;\n\nexport type EventSourceType = 'window' | 'view';\n"]}