@visactor/vgrammar-core 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/cjs/component/axis.js +9 -9
  2. package/cjs/component/axis.js.map +1 -1
  3. package/cjs/component/datazoom.js +5 -5
  4. package/cjs/component/datazoom.js.map +1 -1
  5. package/cjs/component/grid.js +18 -18
  6. package/cjs/component/grid.js.map +1 -1
  7. package/cjs/component/label.js +16 -16
  8. package/cjs/component/label.js.map +1 -1
  9. package/cjs/component/legend.js +13 -13
  10. package/cjs/component/legend.js.map +1 -1
  11. package/cjs/component/scrollbar.js +7 -7
  12. package/cjs/component/scrollbar.js.map +1 -1
  13. package/cjs/component/slider.js +5 -5
  14. package/cjs/component/slider.js.map +1 -1
  15. package/cjs/component/title.js +5 -5
  16. package/cjs/component/title.js.map +1 -1
  17. package/cjs/core/factory.d.ts +5 -1
  18. package/cjs/core/factory.js +13 -3
  19. package/cjs/core/factory.js.map +1 -1
  20. package/cjs/graph/animation/animation/move.js +10 -8
  21. package/cjs/graph/animation/animation/move.js.map +1 -1
  22. package/cjs/graph/attributes/common.js +2 -10
  23. package/cjs/graph/attributes/common.js.map +1 -1
  24. package/cjs/graph/attributes/helpers.d.ts +2 -2
  25. package/cjs/graph/attributes/helpers.js +50 -17
  26. package/cjs/graph/attributes/helpers.js.map +1 -1
  27. package/cjs/graph/attributes/index.d.ts +4 -10
  28. package/cjs/graph/attributes/index.js +16 -251
  29. package/cjs/graph/attributes/index.js.map +1 -1
  30. package/cjs/graph/attributes/line.d.ts +3 -0
  31. package/cjs/graph/attributes/line.js +46 -0
  32. package/cjs/graph/attributes/line.js.map +1 -0
  33. package/cjs/graph/attributes/transform.d.ts +5 -0
  34. package/cjs/graph/attributes/transform.js +167 -0
  35. package/cjs/graph/attributes/transform.js.map +1 -0
  36. package/cjs/graph/canvas-renderer.js +1 -1
  37. package/cjs/graph/canvas-renderer.js.map +1 -1
  38. package/cjs/graph/constants.d.ts +0 -1
  39. package/cjs/graph/constants.js +2 -3
  40. package/cjs/graph/constants.js.map +1 -1
  41. package/cjs/graph/element.js +5 -5
  42. package/cjs/graph/element.js.map +1 -1
  43. package/cjs/graph/glyph-element.js +4 -4
  44. package/cjs/graph/glyph-element.js.map +1 -1
  45. package/cjs/graph/layout/relative.js.map +1 -1
  46. package/cjs/graph/mark/encode.js +4 -4
  47. package/cjs/graph/mark/encode.js.map +1 -1
  48. package/cjs/index.d.ts +3 -1
  49. package/cjs/index.js +3 -2
  50. package/cjs/index.js.map +1 -1
  51. package/cjs/interactions/base.js.map +1 -1
  52. package/cjs/interactions/brush-base.js +2 -2
  53. package/cjs/interactions/brush-base.js.map +1 -1
  54. package/cjs/interactions/brush-filter.js +2 -2
  55. package/cjs/interactions/brush-filter.js.map +1 -1
  56. package/cjs/interactions/crosshair.d.ts +1 -1
  57. package/cjs/interactions/crosshair.js +15 -15
  58. package/cjs/interactions/crosshair.js.map +1 -1
  59. package/cjs/interactions/datazoom-filter.js +3 -3
  60. package/cjs/interactions/datazoom-filter.js.map +1 -1
  61. package/cjs/interactions/drill-down.js +2 -2
  62. package/cjs/interactions/drill-down.js.map +1 -1
  63. package/cjs/interactions/legend-filter.js +3 -3
  64. package/cjs/interactions/legend-filter.js.map +1 -1
  65. package/cjs/interactions/player-filter.js +3 -3
  66. package/cjs/interactions/player-filter.js.map +1 -1
  67. package/cjs/interactions/roll-up.js +2 -2
  68. package/cjs/interactions/roll-up.js.map +1 -1
  69. package/cjs/interactions/scrollbar-filter.js +3 -3
  70. package/cjs/interactions/scrollbar-filter.js.map +1 -1
  71. package/cjs/interactions/slider-filter.js +3 -3
  72. package/cjs/interactions/slider-filter.js.map +1 -1
  73. package/cjs/parse/view.js +1 -1
  74. package/cjs/parse/view.js.map +1 -1
  75. package/cjs/semantic-marks/cell.d.ts +3 -1
  76. package/cjs/semantic-marks/cell.js +10 -4
  77. package/cjs/semantic-marks/cell.js.map +1 -1
  78. package/cjs/semantic-marks/interval.d.ts +2 -0
  79. package/cjs/semantic-marks/interval.js +10 -4
  80. package/cjs/semantic-marks/interval.js.map +1 -1
  81. package/cjs/semantic-marks/text.d.ts +1 -0
  82. package/cjs/semantic-marks/text.js +3 -3
  83. package/cjs/semantic-marks/text.js.map +1 -1
  84. package/cjs/types/animate.d.ts +5 -1
  85. package/cjs/types/animate.js.map +1 -1
  86. package/cjs/types/grammar.d.ts +1 -1
  87. package/cjs/types/grammar.js.map +1 -1
  88. package/cjs/types/mark.d.ts +5 -1
  89. package/cjs/types/mark.js.map +1 -1
  90. package/cjs/types/view.d.ts +1 -0
  91. package/cjs/types/view.js.map +1 -1
  92. package/cjs/view/View.d.ts +0 -1
  93. package/cjs/view/View.js +15 -25
  94. package/cjs/view/View.js.map +1 -1
  95. package/cjs/view/animate.d.ts +1 -0
  96. package/cjs/view/animate.js +12 -12
  97. package/cjs/view/animate.js.map +1 -1
  98. package/cjs/view/constants.d.ts +0 -3
  99. package/cjs/view/constants.js +2 -3
  100. package/cjs/view/constants.js.map +1 -1
  101. package/cjs/view/grammar-record.js +5 -5
  102. package/cjs/view/grammar-record.js.map +1 -1
  103. package/cjs/view/mark.js +1 -1
  104. package/cjs/view/mark.js.map +1 -1
  105. package/es/component/axis.js +1 -1
  106. package/es/component/axis.js.map +1 -1
  107. package/es/component/datazoom.js +1 -1
  108. package/es/component/datazoom.js.map +1 -1
  109. package/es/component/grid.js +1 -1
  110. package/es/component/grid.js.map +1 -1
  111. package/es/component/label.js +1 -1
  112. package/es/component/label.js.map +1 -1
  113. package/es/component/legend.js +1 -1
  114. package/es/component/legend.js.map +1 -1
  115. package/es/component/scrollbar.js +1 -1
  116. package/es/component/scrollbar.js.map +1 -1
  117. package/es/component/slider.js +1 -1
  118. package/es/component/slider.js.map +1 -1
  119. package/es/component/title.js +1 -1
  120. package/es/component/title.js.map +1 -1
  121. package/es/core/factory.d.ts +5 -1
  122. package/es/core/factory.js +11 -1
  123. package/es/core/factory.js.map +1 -1
  124. package/es/graph/animation/animation/move.js +5 -5
  125. package/es/graph/animation/animation/move.js.map +1 -1
  126. package/es/graph/attributes/common.js +2 -7
  127. package/es/graph/attributes/common.js.map +1 -1
  128. package/es/graph/attributes/helpers.d.ts +2 -2
  129. package/es/graph/attributes/helpers.js +46 -12
  130. package/es/graph/attributes/helpers.js.map +1 -1
  131. package/es/graph/attributes/index.d.ts +4 -10
  132. package/es/graph/attributes/index.js +4 -227
  133. package/es/graph/attributes/index.js.map +1 -1
  134. package/es/graph/attributes/line.d.ts +3 -0
  135. package/es/graph/attributes/line.js +42 -0
  136. package/es/graph/attributes/line.js.map +1 -0
  137. package/es/graph/attributes/transform.d.ts +5 -0
  138. package/es/graph/attributes/transform.js +153 -0
  139. package/es/graph/attributes/transform.js.map +1 -0
  140. package/es/graph/canvas-renderer.js +1 -1
  141. package/es/graph/canvas-renderer.js.map +1 -1
  142. package/es/graph/constants.d.ts +0 -1
  143. package/es/graph/constants.js +0 -2
  144. package/es/graph/constants.js.map +1 -1
  145. package/es/graph/element.js +4 -2
  146. package/es/graph/element.js.map +1 -1
  147. package/es/graph/glyph-element.js +1 -1
  148. package/es/graph/glyph-element.js.map +1 -1
  149. package/es/graph/layout/relative.js.map +1 -1
  150. package/es/graph/mark/encode.js +1 -1
  151. package/es/graph/mark/encode.js.map +1 -1
  152. package/es/index.d.ts +3 -1
  153. package/es/index.js +5 -1
  154. package/es/index.js.map +1 -1
  155. package/es/interactions/base.js.map +1 -1
  156. package/es/interactions/brush-base.js +1 -1
  157. package/es/interactions/brush-base.js.map +1 -1
  158. package/es/interactions/brush-filter.js +1 -1
  159. package/es/interactions/brush-filter.js.map +1 -1
  160. package/es/interactions/crosshair.d.ts +1 -1
  161. package/es/interactions/crosshair.js +1 -1
  162. package/es/interactions/crosshair.js.map +1 -1
  163. package/es/interactions/datazoom-filter.js +1 -1
  164. package/es/interactions/datazoom-filter.js.map +1 -1
  165. package/es/interactions/drill-down.js +1 -1
  166. package/es/interactions/drill-down.js.map +1 -1
  167. package/es/interactions/legend-filter.js +1 -1
  168. package/es/interactions/legend-filter.js.map +1 -1
  169. package/es/interactions/player-filter.js +1 -1
  170. package/es/interactions/player-filter.js.map +1 -1
  171. package/es/interactions/roll-up.js +1 -1
  172. package/es/interactions/roll-up.js.map +1 -1
  173. package/es/interactions/scrollbar-filter.js +1 -1
  174. package/es/interactions/scrollbar-filter.js.map +1 -1
  175. package/es/interactions/slider-filter.js +1 -1
  176. package/es/interactions/slider-filter.js.map +1 -1
  177. package/es/parse/view.js +1 -1
  178. package/es/parse/view.js.map +1 -1
  179. package/es/semantic-marks/cell.d.ts +3 -1
  180. package/es/semantic-marks/cell.js +11 -1
  181. package/es/semantic-marks/cell.js.map +1 -1
  182. package/es/semantic-marks/interval.d.ts +2 -0
  183. package/es/semantic-marks/interval.js +9 -1
  184. package/es/semantic-marks/interval.js.map +1 -1
  185. package/es/semantic-marks/text.d.ts +1 -0
  186. package/es/semantic-marks/text.js +3 -1
  187. package/es/semantic-marks/text.js.map +1 -1
  188. package/es/types/animate.d.ts +5 -1
  189. package/es/types/animate.js.map +1 -1
  190. package/es/types/grammar.d.ts +1 -1
  191. package/es/types/grammar.js.map +1 -1
  192. package/es/types/mark.d.ts +5 -1
  193. package/es/types/mark.js.map +1 -1
  194. package/es/types/view.d.ts +1 -0
  195. package/es/types/view.js.map +1 -1
  196. package/es/view/View.d.ts +0 -1
  197. package/es/view/View.js +13 -27
  198. package/es/view/View.js.map +1 -1
  199. package/es/view/animate.d.ts +1 -0
  200. package/es/view/animate.js +6 -6
  201. package/es/view/animate.js.map +1 -1
  202. package/es/view/constants.d.ts +0 -3
  203. package/es/view/constants.js +0 -6
  204. package/es/view/constants.js.map +1 -1
  205. package/es/view/grammar-record.js +1 -1
  206. package/es/view/grammar-record.js.map +1 -1
  207. package/es/view/mark.js +1 -1
  208. package/es/view/mark.js.map +1 -1
  209. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/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AAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAC7E,OAAO,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,QAAQ,EAAE,CAAC;SACjC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;;AArJe,sBAAa,GAAW,aAAa,CAAC,QAAQ,CAAC;AAwJjE,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,OAAO,CAAC,wBAAwB,CAC9B,aAAa,CAAC,QAAQ,EACtB,CAAC,KAAyB,EAAE,EAAE,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAwB,CACnF,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE5D,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,mBAAmB,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AACnE,CAAC,CAAC","file":"datazoom.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { DataZoomAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataZoom as DatazoomComponent } from '@visactor/vrender-components';\nimport { isNil, isString, merge, mixin } from '@visactor/vutils';\nimport { ComponentEnum } from '../graph';\nimport type {\n BaseSignleEncodeSpec,\n ChannelEncodeType,\n IData,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n Nil,\n RecursivePartial,\n ScaleEncodeType,\n StateEncodeSpec\n} from '../types';\nimport type { DatazoomSpec, IDatazoom } from '../types/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { Component } from '../view/component';\nimport { parseEncodeType } from '../parse/mark';\nimport { Factory } from '../core/factory';\nimport { DatazoomFilter } from '../interactions/datazoom-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateDatazoomAttributes = (\n data: any[],\n theme?: ITheme,\n addition?: RecursivePartial<DataZoomAttributes>\n): DataZoomAttributes => {\n const datazoomTheme = theme?.components?.datazoom;\n if (!data) {\n return merge({}, datazoomTheme, addition ?? {});\n }\n\n return merge({}, datazoomTheme, { previewData: data }, addition ?? {});\n};\n\nexport class Datazoom extends Component implements IDatazoom {\n static readonly componentType: string = ComponentEnum.datazoom;\n protected declare spec: DatazoomSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.datazoom, group);\n this.spec.componentType = ComponentEnum.datazoom;\n }\n\n protected parseAddition(spec: DatazoomSpec) {\n super.parseAddition(spec);\n this.preview(spec.preview?.data, spec.preview?.x, spec.preview?.y, spec.preview?.x1, spec.preview?.y1);\n this._updateComponentEncoders();\n return this;\n }\n\n preview(\n data: IData | string | Nil,\n x: ScaleEncodeType | Nil,\n y: ScaleEncodeType | Nil,\n x1?: ChannelEncodeType | Nil,\n y1?: ChannelEncodeType | Nil\n ) {\n if (!isNil(this.spec.preview)) {\n const lastData = this.spec.preview.data;\n const lastDataGrammar = isString(lastData) ? this.view.getDataById(lastData) : lastData;\n this.detach(lastDataGrammar);\n this.detach(parseEncodeType(this.spec.preview.x, this.view));\n this.detach(parseEncodeType(this.spec.preview.y, this.view));\n this.detach(parseEncodeType(this.spec.preview.x1, this.view));\n this.detach(parseEncodeType(this.spec.preview.y1, this.view));\n }\n this.spec.preview = undefined;\n if (data) {\n this.spec.preview = { data, x, y, x1, y1 };\n const dataGrammar = isString(data) ? this.view.getDataById(data) : data;\n this.attach(dataGrammar);\n this.attach(parseEncodeType(x, this.view));\n this.attach(parseEncodeType(y, this.view));\n this.attach(parseEncodeType(x1, this.view));\n this.attach(parseEncodeType(y1, this.view));\n }\n this._updateComponentEncoders();\n this.commit();\n return this;\n }\n\n setStartEndValue(start?: number, end?: number) {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n datazoom?.setStartAndEnd?.(start, end);\n return this;\n }\n\n getStartEndValue() {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n\n if (datazoom) {\n const state = datazoom.state;\n return {\n start: state.start,\n end: state.end\n };\n }\n\n return null;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const theme = this.view.getCurrentTheme();\n const initialAttributes = Object.assign({}, theme?.components?.datazoom, attrs);\n const graphicItem = Factory.createGraphicComponent(this.componentType, initialAttributes);\n const datazoom = graphicItem as unknown as DatazoomComponent;\n datazoom.setStatePointToData(state => {\n if (this.spec.preview) {\n return this.invertDatazoomRatio(state) ?? state;\n }\n return state;\n });\n\n datazoom.setPreviewPointsX((datum: any) => {\n if (this.spec.preview?.x && this.spec.preview?.data) {\n return invokeEncoder({ x: this.spec.preview.x }, datum, this.elements[0], this.parameters()).x;\n }\n\n return undefined;\n });\n datazoom.setPreviewPointsY((datum: any) => {\n if (this.spec.preview?.y && this.spec.preview?.data) {\n return invokeEncoder({ y: this.spec.preview.y }, datum, this.elements[0], this.parameters()).y;\n }\n\n return undefined;\n });\n\n datazoom.setPreviewPointsX1((datum: any) => {\n if (this.spec.preview?.x1 && this.spec.preview?.data) {\n return invokeEncoder({ x1: this.spec.preview.x1 }, datum, this.elements[0], this.parameters()).x1;\n }\n\n return undefined;\n });\n datazoom.setPreviewPointsY1((datum: any) => {\n if (this.spec.preview?.y1 && this.spec.preview?.data) {\n return invokeEncoder({ y1: this.spec.preview.y1 }, datum, this.elements[0], this.parameters()).y1;\n }\n\n return undefined;\n });\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const data = this.spec.preview?.data;\n const dataGrammar = isString(data) ? this.view.getDataById(data) : data;\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n return generateDatazoomAttributes(dataGrammar?.getValue?.(), theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n invertDatazoomRatio(ratio: number): any {\n const scale = this.getDatazoomMainScale();\n if (scale) {\n const range = scale.range();\n const scaledValue = (range[range.length - 1] - range[0]) * ratio + range[0];\n return scale.invert(scaledValue);\n }\n return null;\n }\n\n getDatazoomMainScale() {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n if (datazoom && this.spec.preview) {\n const isHorizontal = datazoom.attribute.orient === 'top' || datazoom.attribute.orient === 'bottom';\n const scale = isHorizontal ? this.spec.preview.x?.scale : this.spec.preview.y?.scale;\n const scaleGrammar = isString(scale) ? this.view.getScaleById(scale) : scale;\n return scaleGrammar?.getScale();\n }\n return null;\n }\n}\n\nexport const registerDataZoom = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.datazoom,\n (attrs: DataZoomAttributes) => new DatazoomComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.datazoom, Datazoom);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(DatazoomFilter.type, DatazoomFilter);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/datazoom.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAe/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C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ACnF,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE5D,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,mBAAmB,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AACnE,CAAC,CAAC","file":"datazoom.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { DataZoomAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataZoom as DatazoomComponent } from '@visactor/vrender-components';\nimport { isNil, isString, merge, mixin } from '@visactor/vutils';\nimport { ComponentEnum } from '../graph/enums';\nimport type {\n BaseSignleEncodeSpec,\n ChannelEncodeType,\n IData,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n Nil,\n RecursivePartial,\n ScaleEncodeType,\n StateEncodeSpec\n} from '../types';\nimport type { DatazoomSpec, IDatazoom } from '../types/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { Component } from '../view/component';\nimport { parseEncodeType } from '../parse/mark';\nimport { Factory } from '../core/factory';\nimport { DatazoomFilter } from '../interactions/datazoom-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateDatazoomAttributes = (\n data: any[],\n theme?: ITheme,\n addition?: RecursivePartial<DataZoomAttributes>\n): DataZoomAttributes => {\n const datazoomTheme = theme?.components?.datazoom;\n if (!data) {\n return merge({}, datazoomTheme, addition ?? {});\n }\n\n return merge({}, datazoomTheme, { previewData: data }, addition ?? {});\n};\n\nexport class Datazoom extends Component implements IDatazoom {\n static readonly componentType: string = ComponentEnum.datazoom;\n protected declare spec: DatazoomSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.datazoom, group);\n this.spec.componentType = ComponentEnum.datazoom;\n }\n\n protected parseAddition(spec: DatazoomSpec) {\n super.parseAddition(spec);\n this.preview(spec.preview?.data, spec.preview?.x, spec.preview?.y, spec.preview?.x1, spec.preview?.y1);\n this._updateComponentEncoders();\n return this;\n }\n\n preview(\n data: IData | string | Nil,\n x: ScaleEncodeType | Nil,\n y: ScaleEncodeType | Nil,\n x1?: ChannelEncodeType | Nil,\n y1?: ChannelEncodeType | Nil\n ) {\n if (!isNil(this.spec.preview)) {\n const lastData = this.spec.preview.data;\n const lastDataGrammar = isString(lastData) ? this.view.getDataById(lastData) : lastData;\n this.detach(lastDataGrammar);\n this.detach(parseEncodeType(this.spec.preview.x, this.view));\n this.detach(parseEncodeType(this.spec.preview.y, this.view));\n this.detach(parseEncodeType(this.spec.preview.x1, this.view));\n this.detach(parseEncodeType(this.spec.preview.y1, this.view));\n }\n this.spec.preview = undefined;\n if (data) {\n this.spec.preview = { data, x, y, x1, y1 };\n const dataGrammar = isString(data) ? this.view.getDataById(data) : data;\n this.attach(dataGrammar);\n this.attach(parseEncodeType(x, this.view));\n this.attach(parseEncodeType(y, this.view));\n this.attach(parseEncodeType(x1, this.view));\n this.attach(parseEncodeType(y1, this.view));\n }\n this._updateComponentEncoders();\n this.commit();\n return this;\n }\n\n setStartEndValue(start?: number, end?: number) {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n datazoom?.setStartAndEnd?.(start, end);\n return this;\n }\n\n getStartEndValue() {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n\n if (datazoom) {\n const state = datazoom.state;\n return {\n start: state.start,\n end: state.end\n };\n }\n\n return null;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const theme = this.view.getCurrentTheme();\n const initialAttributes = Object.assign({}, theme?.components?.datazoom, attrs);\n const graphicItem = Factory.createGraphicComponent(this.componentType, initialAttributes);\n const datazoom = graphicItem as unknown as DatazoomComponent;\n datazoom.setStatePointToData(state => {\n if (this.spec.preview) {\n return this.invertDatazoomRatio(state) ?? state;\n }\n return state;\n });\n\n datazoom.setPreviewPointsX((datum: any) => {\n if (this.spec.preview?.x && this.spec.preview?.data) {\n return invokeEncoder({ x: this.spec.preview.x }, datum, this.elements[0], this.parameters()).x;\n }\n\n return undefined;\n });\n datazoom.setPreviewPointsY((datum: any) => {\n if (this.spec.preview?.y && this.spec.preview?.data) {\n return invokeEncoder({ y: this.spec.preview.y }, datum, this.elements[0], this.parameters()).y;\n }\n\n return undefined;\n });\n\n datazoom.setPreviewPointsX1((datum: any) => {\n if (this.spec.preview?.x1 && this.spec.preview?.data) {\n return invokeEncoder({ x1: this.spec.preview.x1 }, datum, this.elements[0], this.parameters()).x1;\n }\n\n return undefined;\n });\n datazoom.setPreviewPointsY1((datum: any) => {\n if (this.spec.preview?.y1 && this.spec.preview?.data) {\n return invokeEncoder({ y1: this.spec.preview.y1 }, datum, this.elements[0], this.parameters()).y1;\n }\n\n return undefined;\n });\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const data = this.spec.preview?.data;\n const dataGrammar = isString(data) ? this.view.getDataById(data) : data;\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n return generateDatazoomAttributes(dataGrammar?.getValue?.(), theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n invertDatazoomRatio(ratio: number): any {\n const scale = this.getDatazoomMainScale();\n if (scale) {\n const range = scale.range();\n const scaledValue = (range[range.length - 1] - range[0]) * ratio + range[0];\n return scale.invert(scaledValue);\n }\n return null;\n }\n\n getDatazoomMainScale() {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n if (datazoom && this.spec.preview) {\n const isHorizontal = datazoom.attribute.orient === 'top' || datazoom.attribute.orient === 'bottom';\n const scale = isHorizontal ? this.spec.preview.x?.scale : this.spec.preview.y?.scale;\n const scaleGrammar = isString(scale) ? this.view.getScaleById(scale) : scale;\n return scaleGrammar?.getScale();\n }\n return null;\n }\n}\n\nexport const registerDataZoom = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.datazoom,\n (attrs: DataZoomAttributes) => new DatazoomComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.datazoom, Datazoom);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(DatazoomFilter.type, DatazoomFilter);\n};\n"]}
@@ -2,7 +2,7 @@ import { isString, merge } from "@visactor/vutils";
2
2
 
3
3
  import { CircleAxisGrid, LineAxisGrid } from "@visactor/vrender-components";
4
4
 
5
- import { AxisEnum, ComponentEnum, GridEnum } from "../graph";
5
+ import { AxisEnum, ComponentEnum, GridEnum } from "../graph/enums";
6
6
 
7
7
  import { ScaleComponent } from "./scale";
8
8
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/grid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAe5E,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,+BAA+B,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,KAAiB,EACjB,KAAc,EACd,QAAmD,EACnD,SAAkB,EACM,EAAE;;IAC1B,MAAM,SAAS,GAAG,MAAA,MAAA,KAAK,aAA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;IAC/B,OAAO,CAAC,wBAAwB,CAC9B,QAAQ,CAAC,YAAY,EACrB,CAAC,KAA6B,EAAE,IAAkB,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,KAAK,EAAE,IAAI,CAAwB,CAC5G,CAAC;IAEF,OAAO,CAAC,wBAAwB,CAC9B,QAAQ,CAAC,cAAc,EACvB,CAAC,KAA+B,EAAE,IAAkB,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,KAAK,CAAwB,CAC1G,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC,CAAC","file":"grid.js","sourcesContent":["import { isString, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { CircleAxisGridAttributes, LineAxisGridAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { CircleAxisGrid, LineAxisGrid } from '@visactor/vrender-components';\nimport type { IBaseScale } from '@visactor/vscale';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IScale,\n ITheme,\n IView,\n MarkFunctionType,\n MarkRelativeItemSpec,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { AxisEnum, ComponentEnum, GridEnum } from '../graph';\nimport type { GridShape, GridSpec, AxisType, IAxis, IGrid } from '../types/component';\nimport { ScaleComponent } from './scale';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { generateCoordinateAxisAttribute } from './axis';\nimport { Factory } from '../core/factory';\n\nexport const generateLineAxisGridAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<LineAxisGridAttributes>,\n tickCount?: number\n): LineAxisGridAttributes => {\n const gridTheme = theme?.components?.grid ?? {};\n if (!scale) {\n return merge({}, gridTheme, addition ?? {});\n }\n const tickData = scale.tickData?.(tickCount) ?? [];\n const items = tickData.map(tick => ({\n id: tick.index,\n label: tick.tick,\n value: tick.value,\n rawValue: tick.tick\n }));\n return merge({}, gridTheme, { items }, addition ?? {});\n};\n\nexport const generateCircleAxisGridAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<CircleAxisGridAttributes>,\n tickCount?: number\n): CircleAxisGridAttributes => {\n const gridTheme = theme?.components?.circleGrid ?? {};\n if (!scale) {\n return merge({}, gridTheme, addition ?? {});\n }\n const tickData = scale.tickData?.(tickCount) ?? [];\n const items = tickData.map(tick => ({\n id: tick.index,\n label: tick.tick,\n value: tick.value,\n rawValue: tick.tick\n }));\n return merge({}, gridTheme, { items }, addition ?? {});\n};\n\nexport class Grid extends ScaleComponent implements IGrid {\n static readonly componentType: string = ComponentEnum.grid;\n protected declare spec: GridSpec;\n\n protected mode?: '2d' | '3d';\n\n private _gridComponentType: keyof typeof GridEnum;\n private _targetAxis: IAxis;\n\n constructor(view: IView, group?: IGroupMark, mode?: '2d' | '3d') {\n super(view, ComponentEnum.grid, group);\n this.spec.componentType = ComponentEnum.grid;\n this.mode = mode;\n }\n\n protected parseAddition(spec: GridSpec) {\n super.parseAddition(spec);\n this.target(spec.target);\n this.gridType(spec.gridType);\n this.gridShape(spec.gridShape);\n return this;\n }\n\n scale(scale?: IScale | string | Nil) {\n super.scale(scale);\n this._gridComponentType = null;\n return this;\n }\n\n gridType(gridType: AxisType | Nil) {\n this.spec.gridType = gridType;\n this._gridComponentType = null;\n this._prepareRejoin();\n this.commit();\n return this;\n }\n\n gridShape(gridShape: GridShape | Nil) {\n this.spec.gridShape = gridShape;\n // no need to rejoin when gridShape is updated\n // this._gridComponentType = null;\n // this._prepareRejoin();\n this.commit();\n return this;\n }\n\n target(axis: IAxis | string | Nil) {\n if (this.spec.target) {\n const prevAxis = isString(this.spec.target)\n ? (this.view.getMarkById(this.spec.target) as IAxis)\n : this.spec.target;\n this.detach(prevAxis);\n }\n this.spec.target = axis;\n const nextAxis = isString(axis) ? (this.view.getMarkById(axis) as IAxis) : axis;\n this.attach(nextAxis);\n this._targetAxis = nextAxis;\n\n // clear grid type when target is updated\n this._gridComponentType = null;\n this._updateComponentEncoders();\n\n this.commit();\n return this;\n }\n\n tickCount(tickCount: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(tickCount, 'tickCount');\n }\n\n inside(inside: MarkFunctionType<boolean> | Nil) {\n return this.setFunctionSpec(inside, 'inside');\n }\n\n baseValue(baseValue: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(baseValue, 'baseValue');\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const defaultAttributes = { x: 0, y: 0, start: { x: 0, y: 0 }, end: { x: 0, y: 0 } };\n const initialAttributes = merge(defaultAttributes, attrs);\n const graphicItem = Factory.createGraphicComponent(this._getGridComponentType(), initialAttributes, this.mode);\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n let addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n let scaleGrammar: IScale;\n const baseValue = invokeFunctionType(this.spec.baseValue, parameters, datum, element);\n\n // get attributes from target axis\n if (this._targetAxis) {\n const targetScale = this._targetAxis.getSpec()?.scale as IScale | string | Nil;\n scaleGrammar = isString(targetScale) ? this.view.getScaleById(targetScale) : targetScale;\n\n const targetElement = this._targetAxis.elements[0];\n if (targetElement) {\n switch (this._getGridComponentType()) {\n case GridEnum.lineAxisGrid:\n addition = Object.assign(\n {\n x: targetElement.getGraphicAttribute('x'),\n y: targetElement.getGraphicAttribute('y'),\n start: targetElement.getGraphicAttribute('start'),\n end: targetElement.getGraphicAttribute('end'),\n verticalFactor: targetElement.getGraphicAttribute('verticalFactor') ?? 1\n },\n addition\n );\n break;\n case GridEnum.circleAxisGrid:\n addition = Object.assign(\n {\n x: targetElement.getGraphicAttribute('x'),\n y: targetElement.getGraphicAttribute('y'),\n center: targetElement.getGraphicAttribute('center'),\n radius: targetElement.getGraphicAttribute('radius'),\n innerRadius: targetElement.getGraphicAttribute('innerRadius'),\n inside: targetElement.getGraphicAttribute('inside'),\n startAngle: targetElement.getGraphicAttribute('startAngle'),\n endAngle: targetElement.getGraphicAttribute('endAngle')\n },\n addition\n );\n break;\n }\n }\n }\n // compute attribute by spec\n else {\n scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const inside = invokeFunctionType(this.spec.inside, parameters, datum, element);\n\n const coordinate = scaleGrammar?.getCoordinate?.();\n if (coordinate) {\n addition = Object.assign(\n generateCoordinateAxisAttribute(\n scaleGrammar,\n coordinate,\n inside,\n baseValue,\n this.spec.layout as MarkRelativeItemSpec,\n true\n ),\n addition\n );\n }\n }\n\n // compute addition shape attributes for line grid\n if (this._getGridComponentType() === GridEnum.lineAxisGrid) {\n if (this.spec.gridShape === 'line' || !this.spec.gridShape) {\n // set axis type\n addition = Object.assign({}, addition, { type: 'line' });\n } else {\n // set addition length & axis type\n addition = Object.assign(\n {\n center: addition.start,\n closed: true\n },\n addition,\n { type: this.spec.gridShape }\n );\n }\n }\n\n const scale = scaleGrammar?.getScale?.();\n const tickCount = invokeFunctionType(this.spec.tickCount, parameters, datum, element);\n switch (this._getGridComponentType()) {\n case GridEnum.lineAxisGrid:\n return generateLineAxisGridAttributes(scale, theme, addition, tickCount);\n case GridEnum.circleAxisGrid:\n return generateCircleAxisGridAttributes(scale, theme, addition, tickCount);\n }\n return addition;\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n private _getGridComponentType() {\n if (this._gridComponentType) {\n return this._gridComponentType;\n }\n\n if (this.spec.gridType) {\n switch (this.spec.gridType) {\n case 'circle':\n this._gridComponentType = GridEnum.circleAxisGrid;\n break;\n case 'line':\n default:\n this._gridComponentType = GridEnum.lineAxisGrid;\n }\n } else if (this._targetAxis) {\n const axisComponentType = this._targetAxis.getAxisComponentType();\n switch (axisComponentType) {\n case AxisEnum.circleAxis:\n this._gridComponentType = GridEnum.circleAxisGrid;\n break;\n case AxisEnum.lineAxis:\n default:\n this._gridComponentType = GridEnum.lineAxisGrid;\n }\n } else if (this.spec.scale) {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n this._gridComponentType = scaleGrammar?.getCoordinate?.()\n ? scaleGrammar.getCoordinateAxisPoints()\n ? GridEnum.lineAxisGrid\n : GridEnum.circleAxisGrid\n : GridEnum.lineAxisGrid;\n } else {\n this._gridComponentType = GridEnum.lineAxisGrid;\n }\n\n return this._gridComponentType;\n }\n}\n\nexport const registerGrid = () => {\n Factory.registerGraphicComponent(\n GridEnum.lineAxisGrid,\n (attrs: LineAxisGridAttributes, mode?: '2d' | '3d') => new LineAxisGrid(attrs, mode) as unknown as IGraphic\n );\n\n Factory.registerGraphicComponent(\n GridEnum.circleAxisGrid,\n (attrs: CircleAxisGridAttributes, mode?: '2d' | '3d') => new CircleAxisGrid(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.grid, Grid);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/grid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAe5E,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,+BAA+B,EAAE,MAAM,QAAQ,CAAC;AAC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I,CAAC,kBAAkB,GAAG,QAAQ,CAAC,YAAY,CAAC;SACjD;QAED,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACjC,CAAC;;AAlOe,kBAAa,GAAW,aAAa,CAAC,IAAI,CAAC;AAqO7D,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,OAAO,CAAC,wBAAwB,CAC9B,QAAQ,CAAC,YAAY,EACrB,CAAC,KAA6B,EAAE,IAAkB,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,KAAK,EAAE,IAAI,CAAwB,CAC5G,CAAC;IAEF,OAAO,CAAC,wBAAwB,CAC9B,QAAQ,CAAC,cAAc,EACvB,CAAC,KAA+B,EAAE,IAAkB,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,KAAK,CAAwB,CAC1G,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC,CAAC","file":"grid.js","sourcesContent":["import { isString, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { CircleAxisGridAttributes, LineAxisGridAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { CircleAxisGrid, LineAxisGrid } from '@visactor/vrender-components';\nimport type { IBaseScale } from '@visactor/vscale';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IScale,\n ITheme,\n IView,\n MarkFunctionType,\n MarkRelativeItemSpec,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { AxisEnum, ComponentEnum, GridEnum } from '../graph/enums';\nimport type { GridShape, GridSpec, AxisType, IAxis, IGrid } from '../types/component';\nimport { ScaleComponent } from './scale';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { generateCoordinateAxisAttribute } from './axis';\nimport { Factory } from '../core/factory';\n\nexport const generateLineAxisGridAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<LineAxisGridAttributes>,\n tickCount?: number\n): LineAxisGridAttributes => {\n const gridTheme = theme?.components?.grid ?? {};\n if (!scale) {\n return merge({}, gridTheme, addition ?? {});\n }\n const tickData = scale.tickData?.(tickCount) ?? [];\n const items = tickData.map(tick => ({\n id: tick.index,\n label: tick.tick,\n value: tick.value,\n rawValue: tick.tick\n }));\n return merge({}, gridTheme, { items }, addition ?? {});\n};\n\nexport const generateCircleAxisGridAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<CircleAxisGridAttributes>,\n tickCount?: number\n): CircleAxisGridAttributes => {\n const gridTheme = theme?.components?.circleGrid ?? {};\n if (!scale) {\n return merge({}, gridTheme, addition ?? {});\n }\n const tickData = scale.tickData?.(tickCount) ?? [];\n const items = tickData.map(tick => ({\n id: tick.index,\n label: tick.tick,\n value: tick.value,\n rawValue: tick.tick\n }));\n return merge({}, gridTheme, { items }, addition ?? {});\n};\n\nexport class Grid extends ScaleComponent implements IGrid {\n static readonly componentType: string = ComponentEnum.grid;\n protected declare spec: GridSpec;\n\n protected mode?: '2d' | '3d';\n\n private _gridComponentType: keyof typeof GridEnum;\n private _targetAxis: IAxis;\n\n constructor(view: IView, group?: IGroupMark, mode?: '2d' | '3d') {\n super(view, ComponentEnum.grid, group);\n this.spec.componentType = ComponentEnum.grid;\n this.mode = mode;\n }\n\n protected parseAddition(spec: GridSpec) {\n super.parseAddition(spec);\n this.target(spec.target);\n this.gridType(spec.gridType);\n this.gridShape(spec.gridShape);\n return this;\n }\n\n scale(scale?: IScale | string | Nil) {\n super.scale(scale);\n this._gridComponentType = null;\n return this;\n }\n\n gridType(gridType: AxisType | Nil) {\n this.spec.gridType = gridType;\n this._gridComponentType = null;\n this._prepareRejoin();\n this.commit();\n return this;\n }\n\n gridShape(gridShape: GridShape | Nil) {\n this.spec.gridShape = gridShape;\n // no need to rejoin when gridShape is updated\n // this._gridComponentType = null;\n // this._prepareRejoin();\n this.commit();\n return this;\n }\n\n target(axis: IAxis | string | Nil) {\n if (this.spec.target) {\n const prevAxis = isString(this.spec.target)\n ? (this.view.getMarkById(this.spec.target) as IAxis)\n : this.spec.target;\n this.detach(prevAxis);\n }\n this.spec.target = axis;\n const nextAxis = isString(axis) ? (this.view.getMarkById(axis) as IAxis) : axis;\n this.attach(nextAxis);\n this._targetAxis = nextAxis;\n\n // clear grid type when target is updated\n this._gridComponentType = null;\n this._updateComponentEncoders();\n\n this.commit();\n return this;\n }\n\n tickCount(tickCount: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(tickCount, 'tickCount');\n }\n\n inside(inside: MarkFunctionType<boolean> | Nil) {\n return this.setFunctionSpec(inside, 'inside');\n }\n\n baseValue(baseValue: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(baseValue, 'baseValue');\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const defaultAttributes = { x: 0, y: 0, start: { x: 0, y: 0 }, end: { x: 0, y: 0 } };\n const initialAttributes = merge(defaultAttributes, attrs);\n const graphicItem = Factory.createGraphicComponent(this._getGridComponentType(), initialAttributes, this.mode);\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n let addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n let scaleGrammar: IScale;\n const baseValue = invokeFunctionType(this.spec.baseValue, parameters, datum, element);\n\n // get attributes from target axis\n if (this._targetAxis) {\n const targetScale = this._targetAxis.getSpec()?.scale as IScale | string | Nil;\n scaleGrammar = isString(targetScale) ? this.view.getScaleById(targetScale) : targetScale;\n\n const targetElement = this._targetAxis.elements[0];\n if (targetElement) {\n switch (this._getGridComponentType()) {\n case GridEnum.lineAxisGrid:\n addition = Object.assign(\n {\n x: targetElement.getGraphicAttribute('x'),\n y: targetElement.getGraphicAttribute('y'),\n start: targetElement.getGraphicAttribute('start'),\n end: targetElement.getGraphicAttribute('end'),\n verticalFactor: targetElement.getGraphicAttribute('verticalFactor') ?? 1\n },\n addition\n );\n break;\n case GridEnum.circleAxisGrid:\n addition = Object.assign(\n {\n x: targetElement.getGraphicAttribute('x'),\n y: targetElement.getGraphicAttribute('y'),\n center: targetElement.getGraphicAttribute('center'),\n radius: targetElement.getGraphicAttribute('radius'),\n innerRadius: targetElement.getGraphicAttribute('innerRadius'),\n inside: targetElement.getGraphicAttribute('inside'),\n startAngle: targetElement.getGraphicAttribute('startAngle'),\n endAngle: targetElement.getGraphicAttribute('endAngle')\n },\n addition\n );\n break;\n }\n }\n }\n // compute attribute by spec\n else {\n scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const inside = invokeFunctionType(this.spec.inside, parameters, datum, element);\n\n const coordinate = scaleGrammar?.getCoordinate?.();\n if (coordinate) {\n addition = Object.assign(\n generateCoordinateAxisAttribute(\n scaleGrammar,\n coordinate,\n inside,\n baseValue,\n this.spec.layout as MarkRelativeItemSpec,\n true\n ),\n addition\n );\n }\n }\n\n // compute addition shape attributes for line grid\n if (this._getGridComponentType() === GridEnum.lineAxisGrid) {\n if (this.spec.gridShape === 'line' || !this.spec.gridShape) {\n // set axis type\n addition = Object.assign({}, addition, { type: 'line' });\n } else {\n // set addition length & axis type\n addition = Object.assign(\n {\n center: addition.start,\n closed: true\n },\n addition,\n { type: this.spec.gridShape }\n );\n }\n }\n\n const scale = scaleGrammar?.getScale?.();\n const tickCount = invokeFunctionType(this.spec.tickCount, parameters, datum, element);\n switch (this._getGridComponentType()) {\n case GridEnum.lineAxisGrid:\n return generateLineAxisGridAttributes(scale, theme, addition, tickCount);\n case GridEnum.circleAxisGrid:\n return generateCircleAxisGridAttributes(scale, theme, addition, tickCount);\n }\n return addition;\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n private _getGridComponentType() {\n if (this._gridComponentType) {\n return this._gridComponentType;\n }\n\n if (this.spec.gridType) {\n switch (this.spec.gridType) {\n case 'circle':\n this._gridComponentType = GridEnum.circleAxisGrid;\n break;\n case 'line':\n default:\n this._gridComponentType = GridEnum.lineAxisGrid;\n }\n } else if (this._targetAxis) {\n const axisComponentType = this._targetAxis.getAxisComponentType();\n switch (axisComponentType) {\n case AxisEnum.circleAxis:\n this._gridComponentType = GridEnum.circleAxisGrid;\n break;\n case AxisEnum.lineAxis:\n default:\n this._gridComponentType = GridEnum.lineAxisGrid;\n }\n } else if (this.spec.scale) {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n this._gridComponentType = scaleGrammar?.getCoordinate?.()\n ? scaleGrammar.getCoordinateAxisPoints()\n ? GridEnum.lineAxisGrid\n : GridEnum.circleAxisGrid\n : GridEnum.lineAxisGrid;\n } else {\n this._gridComponentType = GridEnum.lineAxisGrid;\n }\n\n return this._gridComponentType;\n }\n}\n\nexport const registerGrid = () => {\n Factory.registerGraphicComponent(\n GridEnum.lineAxisGrid,\n (attrs: LineAxisGridAttributes, mode?: '2d' | '3d') => new LineAxisGrid(attrs, mode) as unknown as IGraphic\n );\n\n Factory.registerGraphicComponent(\n GridEnum.circleAxisGrid,\n (attrs: CircleAxisGridAttributes, mode?: '2d' | '3d') => new CircleAxisGrid(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.grid, Grid);\n};\n"]}
@@ -2,7 +2,7 @@ import { array, isNil, isString, merge } from "@visactor/vutils";
2
2
 
3
3
  import { DataLabel } from "@visactor/vrender-components";
4
4
 
5
- import { ComponentEnum, GrammarMarkType } from "../graph";
5
+ import { ComponentEnum, GrammarMarkType } from "../graph/enums";
6
6
 
7
7
  import { Component } from "../view/component";
8
8
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/label.ts"],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AAE,QAAQ,EAAE,CAAC;yBAC3C;wBACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;wBAE1C,OAAO,uBAAuB,CAC5B,KAAK,EACL,IAAI,EACJ,OAA+B,EAC/B,IAAI,CAAC,IAAI,CAAC,UAAU,EACpB,UAAU,EACV,KAAK,CACN,CAAC;oBACJ,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AAxEe,mBAAa,GAAW,aAAa,CAAC,KAAK,CAAC;AA2E9D,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,OAAO,CAAC,wBAAwB,CAC9B,aAAa,CAAC,KAAK,EACnB,CAAC,KAAqB,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,KAAK,CAAwB,CACvE,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC","file":"label.js","sourcesContent":["import { array, isNil, isString, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { BaseLabelAttrs, DataLabelAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataLabel } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph';\nimport type { ILabel, LabelSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateLabelAttributes = (\n marks: IMark[],\n groupSize: { width: number; height: number },\n encoder: BaseSignleEncodeSpec,\n labelStyle: MarkFunctionType<Partial<BaseLabelAttrs>>,\n parameters: any,\n theme?: ITheme\n): DataLabelAttrs => {\n const labelTheme = theme?.components?.dataLabel;\n const dataLabels = marks\n .map((mark, index) => {\n const labelParameters = { ...parameters, labelIndex: index };\n let currentTheme: any = {};\n switch (mark.markType) {\n case GrammarMarkType.line:\n case GrammarMarkType.area:\n currentTheme = theme?.components?.lineDataLabel;\n break;\n case GrammarMarkType.rect:\n case GrammarMarkType.interval:\n currentTheme = theme?.components?.rectLabel;\n break;\n case GrammarMarkType.symbol:\n case GrammarMarkType.circle:\n case GrammarMarkType.cell:\n currentTheme = theme?.components?.symbolLabel;\n break;\n case GrammarMarkType.arc:\n case GrammarMarkType.arc3d:\n currentTheme = theme?.components?.arcLabel;\n break;\n case GrammarMarkType.polygon:\n case GrammarMarkType.path:\n default:\n currentTheme = theme?.components?.pointLabel;\n break;\n }\n const data: any[] = [];\n const themeDatum = currentTheme?.data?.[0] ?? {};\n // process by order of elements\n mark.elements.forEach(element => {\n const graphicItem = element.getGraphicItem();\n if ((graphicItem as any).releaseStatus !== 'willRelease') {\n if (mark.isCollectionMark()) {\n const datum = element.getDatum();\n\n datum.forEach((entry: any) => {\n const attributes = invokeEncoder(encoder, entry, element, labelParameters);\n data.push(merge({}, themeDatum, attributes));\n });\n } else {\n const attributes = invokeEncoder(encoder, element.getDatum(), element, labelParameters);\n const datum = merge({}, themeDatum, attributes);\n data.push(datum);\n }\n }\n });\n const addition = invokeFunctionType(labelStyle, labelParameters, mark);\n const graphicItemName = mark.graphicItem?.name;\n return merge(\n {},\n currentTheme,\n {\n data,\n baseMarkGroupName: graphicItemName,\n // FIXME: hack\n // 标签是对数据顺序有强要求的场景,因为顺序会影响标签躲避结果;而目前没有机制保证 vrender 图元顺序与数据顺序一致。\n // 这里目前只能通过自定义方法来 hack\n getBaseMarks: () => mark.elements.map(element => element.getGraphicItem())\n },\n addition ?? {}\n );\n })\n .filter(label => !isNil(label));\n\n return merge({}, labelTheme, { size: groupSize, dataLabels });\n};\n\nexport class Label extends Component implements ILabel {\n static readonly componentType: string = ComponentEnum.label;\n protected declare spec: LabelSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.label, group);\n this.spec.componentType = ComponentEnum.label;\n }\n\n protected parseAddition(spec: LabelSpec) {\n super.parseAddition(spec);\n this.labelStyle(spec.labelStyle);\n this.size(spec.size);\n this.target(spec.target);\n return this;\n }\n\n labelStyle(style: MarkFunctionType<Partial<BaseLabelAttrs>>) {\n return this.setFunctionSpec(style, 'labelStyle');\n }\n\n size(size: LabelSpec['size']) {\n return this.setFunctionSpec(size, 'size');\n }\n\n target(mark: IMark | IMark[] | string | string[] | Nil): this {\n if (this.spec.target) {\n const prevMarks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.detach(prevMarks);\n }\n this.spec.target = mark;\n if (mark) {\n const nextMarks = array(mark).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.attach(nextMarks);\n }\n this.commit();\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const marks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n const groupGraphicItem = this.group?.getGroupGraphicItem?.();\n let size = invokeFunctionType(this.spec.size, parameters);\n if (!size) {\n size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: Infinity, height: Infinity };\n }\n const theme = this.view.getCurrentTheme();\n\n return generateLabelAttributes(\n marks,\n size,\n encoder as BaseSignleEncodeSpec,\n this.spec.labelStyle,\n parameters,\n theme\n );\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerLabel = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.label,\n (attrs: DataLabelAttrs) => new DataLabel(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.label, Label);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/label.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIjE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAYzD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAAc,EACd,SAA4C,EAC5C,OAA6B,EAC7B,UAAqD,EACrD,UAAe,EACf,KAAc,EACE,EAAE;;IAClB,MAAM,UAAU,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,SAAS,CAAC;IAChD,MAAM,UAAU,GAAG,KAAK;SACrB,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;;QACnB,MAAM,eAAe,mCAAQ,UAAU,KAAE,UAAU,EAAE,KAAK,GAAE,CAAC;QAC7D,IAAI,YAAY,GAAQ,EAAE,CAAC;QAC3B,QAAQ,IAAI,CAAC,QAAQ,EAAE;YACrB,KAAK,eAAe,CAAC,IAAI,CAAC;YAC1B,KAAK,eAAe,CAAC,IAAI;gBACvB,YAAY,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,aAAa,CAAC;gBAChD,MAAM;YACR,KAAK,eAAe,CA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AAE;oCAC9E,MAAM,EAAE,MAAA,gBAAgB,CAAC,SAAS,CAAC,MAAM,mCAAI,gBAAgB,CAAC,UAAU,CAAC,MAAM,EAAE;iCAClF;gCACH,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;yBAC3C;wBACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;wBAE1C,OAAO,uBAAuB,CAC5B,KAAK,EACL,IAAI,EACJ,OAA+B,EAC/B,IAAI,CAAC,IAAI,CAAC,UAAU,EACpB,UAAU,EACV,KAAK,CACN,CAAC;oBACJ,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AAxEe,mBAAa,GAAW,aAAa,CAAC,KAAK,CAAC;AA2E9D,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,OAAO,CAAC,wBAAwB,CAC9B,aAAa,CAAC,KAAK,EACnB,CAAC,KAAqB,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,KAAK,CAAwB,CACvE,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC","file":"label.js","sourcesContent":["import { array, isNil, isString, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { BaseLabelAttrs, DataLabelAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataLabel } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph/enums';\nimport type { ILabel, LabelSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateLabelAttributes = (\n marks: IMark[],\n groupSize: { width: number; height: number },\n encoder: BaseSignleEncodeSpec,\n labelStyle: MarkFunctionType<Partial<BaseLabelAttrs>>,\n parameters: any,\n theme?: ITheme\n): DataLabelAttrs => {\n const labelTheme = theme?.components?.dataLabel;\n const dataLabels = marks\n .map((mark, index) => {\n const labelParameters = { ...parameters, labelIndex: index };\n let currentTheme: any = {};\n switch (mark.markType) {\n case GrammarMarkType.line:\n case GrammarMarkType.area:\n currentTheme = theme?.components?.lineDataLabel;\n break;\n case GrammarMarkType.rect:\n case GrammarMarkType.interval:\n currentTheme = theme?.components?.rectLabel;\n break;\n case GrammarMarkType.symbol:\n case GrammarMarkType.circle:\n case GrammarMarkType.cell:\n currentTheme = theme?.components?.symbolLabel;\n break;\n case GrammarMarkType.arc:\n case GrammarMarkType.arc3d:\n currentTheme = theme?.components?.arcLabel;\n break;\n case GrammarMarkType.polygon:\n case GrammarMarkType.path:\n default:\n currentTheme = theme?.components?.pointLabel;\n break;\n }\n const data: any[] = [];\n const themeDatum = currentTheme?.data?.[0] ?? {};\n // process by order of elements\n mark.elements.forEach(element => {\n const graphicItem = element.getGraphicItem();\n if ((graphicItem as any).releaseStatus !== 'willRelease') {\n if (mark.isCollectionMark()) {\n const datum = element.getDatum();\n\n datum.forEach((entry: any) => {\n const attributes = invokeEncoder(encoder, entry, element, labelParameters);\n data.push(merge({}, themeDatum, attributes));\n });\n } else {\n const attributes = invokeEncoder(encoder, element.getDatum(), element, labelParameters);\n const datum = merge({}, themeDatum, attributes);\n data.push(datum);\n }\n }\n });\n const addition = invokeFunctionType(labelStyle, labelParameters, mark);\n const graphicItemName = mark.graphicItem?.name;\n return merge(\n {},\n currentTheme,\n {\n data,\n baseMarkGroupName: graphicItemName,\n // FIXME: hack\n // 标签是对数据顺序有强要求的场景,因为顺序会影响标签躲避结果;而目前没有机制保证 vrender 图元顺序与数据顺序一致。\n // 这里目前只能通过自定义方法来 hack\n getBaseMarks: () => mark.elements.map(element => element.getGraphicItem())\n },\n addition ?? {}\n );\n })\n .filter(label => !isNil(label));\n\n return merge({}, labelTheme, { size: groupSize, dataLabels });\n};\n\nexport class Label extends Component implements ILabel {\n static readonly componentType: string = ComponentEnum.label;\n protected declare spec: LabelSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.label, group);\n this.spec.componentType = ComponentEnum.label;\n }\n\n protected parseAddition(spec: LabelSpec) {\n super.parseAddition(spec);\n this.labelStyle(spec.labelStyle);\n this.size(spec.size);\n this.target(spec.target);\n return this;\n }\n\n labelStyle(style: MarkFunctionType<Partial<BaseLabelAttrs>>) {\n return this.setFunctionSpec(style, 'labelStyle');\n }\n\n size(size: LabelSpec['size']) {\n return this.setFunctionSpec(size, 'size');\n }\n\n target(mark: IMark | IMark[] | string | string[] | Nil): this {\n if (this.spec.target) {\n const prevMarks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.detach(prevMarks);\n }\n this.spec.target = mark;\n if (mark) {\n const nextMarks = array(mark).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.attach(nextMarks);\n }\n this.commit();\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const marks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n const groupGraphicItem = this.group?.getGroupGraphicItem?.();\n let size = invokeFunctionType(this.spec.size, parameters);\n if (!size) {\n size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: Infinity, height: Infinity };\n }\n const theme = this.view.getCurrentTheme();\n\n return generateLabelAttributes(\n marks,\n size,\n encoder as BaseSignleEncodeSpec,\n this.spec.labelStyle,\n parameters,\n theme\n );\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerLabel = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.label,\n (attrs: DataLabelAttrs) => new DataLabel(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.label, Label);\n};\n"]}
@@ -4,7 +4,7 @@ import { DiscreteLegend, ColorContinuousLegend, SizeContinuousLegend } from "@vi
4
4
 
5
5
  import { array, isString, merge, last, mixin } from "@visactor/vutils";
6
6
 
7
- import { ComponentEnum, LegendEnum } from "../graph";
7
+ import { ComponentEnum, LegendEnum } from "../graph/enums";
8
8
 
9
9
  import { parseColor } from "../parse/util";
10
10
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/legend.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAC3G,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAarD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,CAAC,M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;IAExD,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,mBAAmB,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAC/D,CAAC,CAAC","file":"legend.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { IBaseScale } from '@visactor/vscale';\n// eslint-disable-next-line no-duplicate-imports\nimport { isContinuous } from '@visactor/vscale';\nimport type { DiscreteLegendAttrs, ColorLegendAttributes, SizeLegendAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DiscreteLegend, ColorContinuousLegend, SizeContinuousLegend } from '@visactor/vrender-components';\nimport { array, isString, merge, last, mixin } from '@visactor/vutils';\nimport { ComponentEnum, LegendEnum } from '../graph';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IScale,\n ITheme,\n IView,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport type { ILegend, LegendSpec, LegendType } from '../types/component';\nimport { parseColor } from '../parse/util';\nimport { ScaleComponent } from './scale';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { Factory } from '../core/factory';\nimport { LegendFilter } from '../interactions/legend-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateDiscreteLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<DiscreteLegendAttrs>,\n shapeScale?: IBaseScale\n): DiscreteLegendAttrs => {\n const legendTheme = theme?.components?.discreteLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n // get domain items without repetitions\n const domainItems = Array.from(new Set(array(scale.domain())));\n const items = domainItems.map((item, index) => {\n const value = scale.scale(item);\n const color = parseColor(value);\n const shape = color\n ? {\n ...(theme?.components?.discreteLegend?.items?.[0]?.shape ?? {}),\n fill: color,\n stroke: color\n }\n : theme?.components?.discreteLegend?.items?.[0]?.shape ?? {};\n\n if (shapeScale) {\n Object.assign(shape, { symbolType: shapeScale.scale(item) });\n }\n\n return {\n label: item.toString(),\n id: item,\n shape,\n index\n };\n });\n return merge({}, legendTheme, { items }, addition ?? {});\n};\n\nexport const generateColorLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<ColorLegendAttributes>\n): ColorLegendAttributes => {\n const legendTheme = theme?.components?.colorLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n const domain = scale.domain();\n return merge({}, legendTheme, { colors: scale.range().slice(), min: domain[0], max: last(domain) }, addition ?? {});\n};\n\nexport const generateSizeLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<SizeLegendAttributes>\n): SizeLegendAttributes => {\n const legendTheme = theme?.components?.sizeLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n const domain = scale.domain();\n const attributes = {\n min: domain[0],\n max: domain[domain.length - 1],\n value: [domain[0], domain[domain.length - 1]]\n };\n return merge({}, legendTheme, attributes, addition ?? {});\n};\n\nexport class Legend extends ScaleComponent implements ILegend {\n static readonly componentType: string = ComponentEnum.legend;\n protected declare spec: LegendSpec;\n\n private _legendComponentType: keyof typeof LegendEnum;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.legend, group);\n this.spec.componentType = ComponentEnum.legend;\n this.spec.legendType = 'auto';\n }\n\n protected parseAddition(spec: LegendSpec) {\n this.shapeScale(spec.shapeScale);\n super.parseAddition(spec);\n this.legendType(spec.legendType);\n return this;\n }\n\n scale(scale?: IScale | string | Nil) {\n super.scale(scale);\n this._legendComponentType = null;\n return this;\n }\n\n shapeScale(shapeScale: LegendSpec['shapeScale']) {\n if (this.spec.shapeScale) {\n const lastScaleGrammar = isString(this.spec.shapeScale)\n ? this.view.getScaleById(this.spec.shapeScale)\n : this.spec.shapeScale;\n this.detach(lastScaleGrammar);\n this.spec.shapeScale = undefined;\n }\n const scaleGrammar = isString(shapeScale) ? this.view.getScaleById(shapeScale) : shapeScale;\n this.spec.shapeScale = scaleGrammar;\n this.attach(scaleGrammar);\n\n this.commit();\n return this;\n }\n\n legendType(legendType: LegendType | Nil) {\n this.spec.legendType = legendType;\n // clear legend type when spec is changed\n this._legendComponentType = null;\n this._prepareRejoin();\n this.commit();\n return this;\n }\n\n isContinuousLegend() {\n return this._getLegendComponentType() !== LegendEnum.discreteLegend;\n }\n\n setSelected(selectedValues: any[]) {\n // FIXME: provide ILegend interface in vis-component\n const legend = this.elements[0]?.getGraphicItem?.() as unknown as DiscreteLegend;\n legend.setSelected(selectedValues);\n return this;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const graphicItem = Factory.createGraphicComponent(this._getLegendComponentType(), attrs);\n return super.addGraphicItem(attrs, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const shapeScaleGrammar = isString(this.spec.shapeScale)\n ? this.view.getScaleById(this.spec.shapeScale)\n : this.spec.shapeScale;\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n const scale = scaleGrammar?.getScale?.();\n switch (this._getLegendComponentType()) {\n case LegendEnum.discreteLegend:\n return generateDiscreteLegendAttributes(scale, theme, addition, shapeScaleGrammar?.getScale?.());\n case LegendEnum.colorLegend:\n return generateColorLegendAttributes(scale, theme, addition);\n case LegendEnum.sizeLegend:\n return generateSizeLegendAttributes(scale, theme, addition);\n }\n return addition;\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n private _getLegendComponentType() {\n if (this._legendComponentType) {\n return this._legendComponentType;\n }\n\n // compute legend component type when needed\n if (!this.spec.legendType || this.spec.legendType === 'auto') {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const scaleType = scaleGrammar?.getScaleType?.();\n if (scaleType && isContinuous(scaleType)) {\n const range: any[] = scaleGrammar.getScale().range();\n if (parseColor(range?.[0])) {\n this._legendComponentType = LegendEnum.colorLegend;\n } else {\n this._legendComponentType = LegendEnum.sizeLegend;\n }\n } else {\n this._legendComponentType = LegendEnum.discreteLegend;\n }\n } else {\n this._legendComponentType =\n this.spec.legendType === 'color'\n ? 'colorLegend'\n : this.spec.legendType === 'size'\n ? 'sizeLegend'\n : 'discreteLegend';\n }\n return this._legendComponentType;\n }\n}\n\nexport const registerLegend = () => {\n Factory.registerGraphicComponent(\n LegendEnum.discreteLegend,\n (attrs: DiscreteLegendAttrs) => new DiscreteLegend(attrs) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n LegendEnum.colorLegend,\n (attrs: ColorLegendAttributes) => new ColorContinuousLegend(attrs) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n LegendEnum.sizeLegend,\n (attrs: SizeLegendAttributes) => new SizeContinuousLegend(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.legend, Legend);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(LegendFilter.type, LegendFilter);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/legend.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAC3G,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAa3D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EA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AAC,IAAI,qBAAqB,CAAC,KAAK,CAAwB,CAC1F,CAAC;IACF,OAAO,CAAC,wBAAwB,CAC9B,UAAU,CAAC,UAAU,EACrB,CAAC,KAA2B,EAAE,EAAE,CAAC,IAAI,oBAAoB,CAAC,KAAK,CAAwB,CACxF,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAExD,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,mBAAmB,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAC/D,CAAC,CAAC","file":"legend.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { IBaseScale } from '@visactor/vscale';\n// eslint-disable-next-line no-duplicate-imports\nimport { isContinuous } from '@visactor/vscale';\nimport type { DiscreteLegendAttrs, ColorLegendAttributes, SizeLegendAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DiscreteLegend, ColorContinuousLegend, SizeContinuousLegend } from '@visactor/vrender-components';\nimport { array, isString, merge, last, mixin } from '@visactor/vutils';\nimport { ComponentEnum, LegendEnum } from '../graph/enums';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IScale,\n ITheme,\n IView,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport type { ILegend, LegendSpec, LegendType } from '../types/component';\nimport { parseColor } from '../parse/util';\nimport { ScaleComponent } from './scale';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { Factory } from '../core/factory';\nimport { LegendFilter } from '../interactions/legend-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateDiscreteLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<DiscreteLegendAttrs>,\n shapeScale?: IBaseScale\n): DiscreteLegendAttrs => {\n const legendTheme = theme?.components?.discreteLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n // get domain items without repetitions\n const domainItems = Array.from(new Set(array(scale.domain())));\n const items = domainItems.map((item, index) => {\n const value = scale.scale(item);\n const color = parseColor(value);\n const shape = color\n ? {\n ...(theme?.components?.discreteLegend?.items?.[0]?.shape ?? {}),\n fill: color,\n stroke: color\n }\n : theme?.components?.discreteLegend?.items?.[0]?.shape ?? {};\n\n if (shapeScale) {\n Object.assign(shape, { symbolType: shapeScale.scale(item) });\n }\n\n return {\n label: item.toString(),\n id: item,\n shape,\n index\n };\n });\n return merge({}, legendTheme, { items }, addition ?? {});\n};\n\nexport const generateColorLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<ColorLegendAttributes>\n): ColorLegendAttributes => {\n const legendTheme = theme?.components?.colorLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n const domain = scale.domain();\n return merge({}, legendTheme, { colors: scale.range().slice(), min: domain[0], max: last(domain) }, addition ?? {});\n};\n\nexport const generateSizeLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<SizeLegendAttributes>\n): SizeLegendAttributes => {\n const legendTheme = theme?.components?.sizeLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n const domain = scale.domain();\n const attributes = {\n min: domain[0],\n max: domain[domain.length - 1],\n value: [domain[0], domain[domain.length - 1]]\n };\n return merge({}, legendTheme, attributes, addition ?? {});\n};\n\nexport class Legend extends ScaleComponent implements ILegend {\n static readonly componentType: string = ComponentEnum.legend;\n protected declare spec: LegendSpec;\n\n private _legendComponentType: keyof typeof LegendEnum;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.legend, group);\n this.spec.componentType = ComponentEnum.legend;\n this.spec.legendType = 'auto';\n }\n\n protected parseAddition(spec: LegendSpec) {\n this.shapeScale(spec.shapeScale);\n super.parseAddition(spec);\n this.legendType(spec.legendType);\n return this;\n }\n\n scale(scale?: IScale | string | Nil) {\n super.scale(scale);\n this._legendComponentType = null;\n return this;\n }\n\n shapeScale(shapeScale: LegendSpec['shapeScale']) {\n if (this.spec.shapeScale) {\n const lastScaleGrammar = isString(this.spec.shapeScale)\n ? this.view.getScaleById(this.spec.shapeScale)\n : this.spec.shapeScale;\n this.detach(lastScaleGrammar);\n this.spec.shapeScale = undefined;\n }\n const scaleGrammar = isString(shapeScale) ? this.view.getScaleById(shapeScale) : shapeScale;\n this.spec.shapeScale = scaleGrammar;\n this.attach(scaleGrammar);\n\n this.commit();\n return this;\n }\n\n legendType(legendType: LegendType | Nil) {\n this.spec.legendType = legendType;\n // clear legend type when spec is changed\n this._legendComponentType = null;\n this._prepareRejoin();\n this.commit();\n return this;\n }\n\n isContinuousLegend() {\n return this._getLegendComponentType() !== LegendEnum.discreteLegend;\n }\n\n setSelected(selectedValues: any[]) {\n // FIXME: provide ILegend interface in vis-component\n const legend = this.elements[0]?.getGraphicItem?.() as unknown as DiscreteLegend;\n legend.setSelected(selectedValues);\n return this;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const graphicItem = Factory.createGraphicComponent(this._getLegendComponentType(), attrs);\n return super.addGraphicItem(attrs, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const shapeScaleGrammar = isString(this.spec.shapeScale)\n ? this.view.getScaleById(this.spec.shapeScale)\n : this.spec.shapeScale;\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n const scale = scaleGrammar?.getScale?.();\n switch (this._getLegendComponentType()) {\n case LegendEnum.discreteLegend:\n return generateDiscreteLegendAttributes(scale, theme, addition, shapeScaleGrammar?.getScale?.());\n case LegendEnum.colorLegend:\n return generateColorLegendAttributes(scale, theme, addition);\n case LegendEnum.sizeLegend:\n return generateSizeLegendAttributes(scale, theme, addition);\n }\n return addition;\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n private _getLegendComponentType() {\n if (this._legendComponentType) {\n return this._legendComponentType;\n }\n\n // compute legend component type when needed\n if (!this.spec.legendType || this.spec.legendType === 'auto') {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const scaleType = scaleGrammar?.getScaleType?.();\n if (scaleType && isContinuous(scaleType)) {\n const range: any[] = scaleGrammar.getScale().range();\n if (parseColor(range?.[0])) {\n this._legendComponentType = LegendEnum.colorLegend;\n } else {\n this._legendComponentType = LegendEnum.sizeLegend;\n }\n } else {\n this._legendComponentType = LegendEnum.discreteLegend;\n }\n } else {\n this._legendComponentType =\n this.spec.legendType === 'color'\n ? 'colorLegend'\n : this.spec.legendType === 'size'\n ? 'sizeLegend'\n : 'discreteLegend';\n }\n return this._legendComponentType;\n }\n}\n\nexport const registerLegend = () => {\n Factory.registerGraphicComponent(\n LegendEnum.discreteLegend,\n (attrs: DiscreteLegendAttrs) => new DiscreteLegend(attrs) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n LegendEnum.colorLegend,\n (attrs: ColorLegendAttributes) => new ColorContinuousLegend(attrs) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n LegendEnum.sizeLegend,\n (attrs: SizeLegendAttributes) => new SizeContinuousLegend(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.legend, Legend);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(LegendFilter.type, LegendFilter);\n};\n"]}
@@ -2,7 +2,7 @@ import { isString, merge, mixin } from "@visactor/vutils";
2
2
 
3
3
  import { ScrollBar as ScrollbarComponent } from "@visactor/vrender-components";
4
4
 
5
- import { ComponentEnum, GrammarMarkType } from "../graph";
5
+ import { ComponentEnum, GrammarMarkType } from "../graph/enums";
6
6
 
7
7
  import { invokeEncoder } from "../graph/mark/encode";
8
8
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/scrollbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAI1D,OAAO,EAAE,SAAS,IAAI,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAY/E,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE7D,SAAS,gBAAgB,CAAC,SAAoB;IAC5C,OAAO,SAAS,KAAK,UAAU,IAAI,SAAS,KAAK,YAAY,CAAC;AAChE,CAAC;AAED,SAAS,eAAe,CAAC,QAAoB;IAC3C,OAAO,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,OAAO,CAAC;AACpG,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAoB;IAChD,OAAO,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,QAAQ,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,SAA4C,EAC5C,SAAqB,EACrB,QAAqB,EACrB,KAAc,EACd,QAAgD,EAC3B,EAAE;;IACvB,MAAM,cAAc,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,SAA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AC;gCACE,KAAK,EAAE,MAAA,gBAAgB,CAAC,SAAS,CAAC,KAAK,mCAAI,gBAAgB,CAAC,UAAU,CAAC,KAAK,EAAE;gCAC9E,MAAM,EAAE,MAAA,gBAAgB,CAAC,SAAS,CAAC,MAAM,mCAAI,gBAAgB,CAAC,UAAU,CAAC,MAAM,EAAE;6BAClF;4BACH,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;wBAC7D,OAAO,2BAA2B,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;oBACjF,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AAhGe,uBAAa,GAAW,aAAa,CAAC,SAAS,CAAC;AAmGlE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,OAAO,CAAC,wBAAwB,CAC9B,aAAa,CAAC,SAAS,EACvB,CAAC,KAA0B,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAwB,CACrF,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAE9D,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,mBAAmB,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AACrE,CAAC,CAAC","file":"scrollbar.js","sourcesContent":["import { isString, merge, mixin } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { Direction, OrientType, ScrollBarAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { ScrollBar as ScrollbarComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph';\nimport type { IScrollbar, ScrollbarSpec } from '../types/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\nimport { ScaleComponent } from './scale';\nimport { ScrollbarFilter } from '../interactions/scrollbar-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nfunction isValidDirection(direction: Direction) {\n return direction === 'vertical' || direction === 'horizontal';\n}\n\nfunction isValidPosition(position: OrientType) {\n return position === 'top' || position === 'bottom' || position === 'left' || position === 'right';\n}\n\nfunction isHorizontalPosition(position: OrientType) {\n return position === 'top' || position === 'bottom';\n}\n\nexport const generateScrollbarAttributes = (\n groupSize: { width: number; height: number },\n direction?: Direction,\n position?: OrientType,\n theme?: ITheme,\n addition?: RecursivePartial<ScrollBarAttributes>\n): ScrollBarAttributes => {\n const scrollbarTheme = theme?.components?.scrollbar;\n\n let finalDirection: Direction = 'horizontal';\n let finalPosition: OrientType = 'bottom';\n if (!isValidDirection(direction) && !isValidPosition(position)) {\n finalDirection = 'horizontal';\n finalPosition = 'bottom';\n } else if (!isValidDirection(direction) && isValidPosition(position)) {\n finalDirection = isHorizontalPosition(position) ? 'horizontal' : 'vertical';\n finalPosition = position;\n } else if (isValidDirection(direction) && !isValidPosition(position)) {\n finalDirection = direction;\n finalPosition = direction === 'horizontal' ? 'bottom' : 'right';\n } else {\n finalDirection = direction;\n finalPosition =\n direction === 'horizontal' && !isHorizontalPosition(position)\n ? 'bottom'\n : direction === 'vertical' && isHorizontalPosition(position)\n ? 'right'\n : position;\n }\n\n const attributes: RecursivePartial<ScrollBarAttributes> = { direction: finalDirection };\n if (finalDirection === 'horizontal') {\n const size = addition.height ?? scrollbarTheme?.height ?? 12;\n\n // top or bottom\n if (finalPosition === 'top') {\n Object.assign(attributes, {\n width: groupSize.width,\n height: size,\n x: 0,\n y: 0\n });\n } else {\n Object.assign(attributes, {\n width: groupSize.width,\n height: size,\n x: 0,\n y: groupSize.height - size\n });\n }\n } else {\n const size = addition.width ?? scrollbarTheme?.width ?? 12;\n\n // left or right\n if (finalPosition === 'left') {\n Object.assign(attributes, {\n width: size,\n height: groupSize.height,\n x: 0,\n y: 0\n });\n } else {\n Object.assign(attributes, {\n width: size,\n height: groupSize.height,\n x: groupSize.width - size,\n y: 0\n });\n }\n }\n\n return merge({}, scrollbarTheme, attributes, addition ?? {});\n};\n\nexport class Scrollbar extends ScaleComponent implements IScrollbar {\n static readonly componentType: string = ComponentEnum.scrollbar;\n protected declare spec: ScrollbarSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.scrollbar, group);\n this.spec.componentType = ComponentEnum.scrollbar;\n }\n\n protected parseAddition(spec: ScrollbarSpec) {\n super.parseAddition(spec);\n this.container(spec.container);\n this.direction(spec.direction);\n this.position(spec.position);\n return this;\n }\n\n container(container: IGroupMark | string | Nil): this {\n if (this.spec.container) {\n const prevContainer = isString(this.spec.container)\n ? this.view.getMarkById(this.spec.container)\n : this.spec.container;\n this.detach(prevContainer);\n }\n this.spec.container = container;\n if (container) {\n const nextContainer = isString(container) ? this.view.getMarkById(container) : container;\n this.attach(nextContainer);\n }\n this.commit();\n return this;\n }\n\n direction(direction: MarkFunctionType<Direction> | Nil) {\n return this.setFunctionSpec(direction, 'direction');\n }\n\n position(position: MarkFunctionType<OrientType> | Nil) {\n return this.setFunctionSpec(position, 'position');\n }\n\n setScrollStart(start: number) {\n const scrollbar = this.elements[0]?.getGraphicItem?.() as unknown as ScrollbarComponent;\n const range = scrollbar?.attribute?.range;\n if (scrollbar && range) {\n const nextRange: [number, number] = [start, range[1] - range[0] + start];\n scrollbar.setScrollRange(nextRange);\n }\n return this;\n }\n\n getScrollRange() {\n const scrollbar = this.elements[0]?.getGraphicItem?.() as unknown as ScrollbarComponent;\n\n if (scrollbar) {\n return scrollbar.getScrollRange();\n }\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const defaultAttributes = { range: [0, 1] };\n const initialAttributes = merge(defaultAttributes, attrs);\n const graphicItem = Factory.createGraphicComponent(ComponentEnum.scrollbar, initialAttributes);\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const direction = invokeFunctionType(this.spec.direction, parameters, datum, element);\n const position = invokeFunctionType(this.spec.position, parameters, datum, element);\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n const targetMark = this.spec.container\n ? isString(this.spec.container)\n ? this.view.getMarkById(this.spec.container)\n : this.spec.container\n : null;\n const groupMark = targetMark && targetMark.markType === GrammarMarkType.group ? targetMark : this.group;\n const groupGraphicItem = groupMark.getGroupGraphicItem();\n const size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: this.view.width(), height: this.view.height() };\n return generateScrollbarAttributes(size, direction, position, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerScrollbar = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.scrollbar,\n (attrs: ScrollBarAttributes) => new ScrollbarComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.scrollbar, Scrollbar);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(ScrollbarFilter.type, ScrollbarFilter);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/scrollbar.ts"],"names":[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AAA,gBAAgB,CAAC,SAAS,CAAC,MAAM,mCAAI,gBAAgB,CAAC,UAAU,CAAC,MAAM,EAAE;6BAClF;4BACH,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;wBAC7D,OAAO,2BAA2B,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;oBACjF,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AAhGe,uBAAa,GAAW,aAAa,CAAC,SAAS,CAAC;AAmGlE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,OAAO,CAAC,wBAAwB,CAC9B,aAAa,CAAC,SAAS,EACvB,CAAC,KAA0B,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,KAAK,CAAwB,CACrF,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAE9D,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,mBAAmB,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AACrE,CAAC,CAAC","file":"scrollbar.js","sourcesContent":["import { isString, merge, mixin } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { Direction, OrientType, ScrollBarAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { ScrollBar as ScrollbarComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph/enums';\nimport type { IScrollbar, ScrollbarSpec } from '../types/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\nimport { ScaleComponent } from './scale';\nimport { ScrollbarFilter } from '../interactions/scrollbar-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nfunction isValidDirection(direction: Direction) {\n return direction === 'vertical' || direction === 'horizontal';\n}\n\nfunction isValidPosition(position: OrientType) {\n return position === 'top' || position === 'bottom' || position === 'left' || position === 'right';\n}\n\nfunction isHorizontalPosition(position: OrientType) {\n return position === 'top' || position === 'bottom';\n}\n\nexport const generateScrollbarAttributes = (\n groupSize: { width: number; height: number },\n direction?: Direction,\n position?: OrientType,\n theme?: ITheme,\n addition?: RecursivePartial<ScrollBarAttributes>\n): ScrollBarAttributes => {\n const scrollbarTheme = theme?.components?.scrollbar;\n\n let finalDirection: Direction = 'horizontal';\n let finalPosition: OrientType = 'bottom';\n if (!isValidDirection(direction) && !isValidPosition(position)) {\n finalDirection = 'horizontal';\n finalPosition = 'bottom';\n } else if (!isValidDirection(direction) && isValidPosition(position)) {\n finalDirection = isHorizontalPosition(position) ? 'horizontal' : 'vertical';\n finalPosition = position;\n } else if (isValidDirection(direction) && !isValidPosition(position)) {\n finalDirection = direction;\n finalPosition = direction === 'horizontal' ? 'bottom' : 'right';\n } else {\n finalDirection = direction;\n finalPosition =\n direction === 'horizontal' && !isHorizontalPosition(position)\n ? 'bottom'\n : direction === 'vertical' && isHorizontalPosition(position)\n ? 'right'\n : position;\n }\n\n const attributes: RecursivePartial<ScrollBarAttributes> = { direction: finalDirection };\n if (finalDirection === 'horizontal') {\n const size = addition.height ?? scrollbarTheme?.height ?? 12;\n\n // top or bottom\n if (finalPosition === 'top') {\n Object.assign(attributes, {\n width: groupSize.width,\n height: size,\n x: 0,\n y: 0\n });\n } else {\n Object.assign(attributes, {\n width: groupSize.width,\n height: size,\n x: 0,\n y: groupSize.height - size\n });\n }\n } else {\n const size = addition.width ?? scrollbarTheme?.width ?? 12;\n\n // left or right\n if (finalPosition === 'left') {\n Object.assign(attributes, {\n width: size,\n height: groupSize.height,\n x: 0,\n y: 0\n });\n } else {\n Object.assign(attributes, {\n width: size,\n height: groupSize.height,\n x: groupSize.width - size,\n y: 0\n });\n }\n }\n\n return merge({}, scrollbarTheme, attributes, addition ?? {});\n};\n\nexport class Scrollbar extends ScaleComponent implements IScrollbar {\n static readonly componentType: string = ComponentEnum.scrollbar;\n protected declare spec: ScrollbarSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.scrollbar, group);\n this.spec.componentType = ComponentEnum.scrollbar;\n }\n\n protected parseAddition(spec: ScrollbarSpec) {\n super.parseAddition(spec);\n this.container(spec.container);\n this.direction(spec.direction);\n this.position(spec.position);\n return this;\n }\n\n container(container: IGroupMark | string | Nil): this {\n if (this.spec.container) {\n const prevContainer = isString(this.spec.container)\n ? this.view.getMarkById(this.spec.container)\n : this.spec.container;\n this.detach(prevContainer);\n }\n this.spec.container = container;\n if (container) {\n const nextContainer = isString(container) ? this.view.getMarkById(container) : container;\n this.attach(nextContainer);\n }\n this.commit();\n return this;\n }\n\n direction(direction: MarkFunctionType<Direction> | Nil) {\n return this.setFunctionSpec(direction, 'direction');\n }\n\n position(position: MarkFunctionType<OrientType> | Nil) {\n return this.setFunctionSpec(position, 'position');\n }\n\n setScrollStart(start: number) {\n const scrollbar = this.elements[0]?.getGraphicItem?.() as unknown as ScrollbarComponent;\n const range = scrollbar?.attribute?.range;\n if (scrollbar && range) {\n const nextRange: [number, number] = [start, range[1] - range[0] + start];\n scrollbar.setScrollRange(nextRange);\n }\n return this;\n }\n\n getScrollRange() {\n const scrollbar = this.elements[0]?.getGraphicItem?.() as unknown as ScrollbarComponent;\n\n if (scrollbar) {\n return scrollbar.getScrollRange();\n }\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const defaultAttributes = { range: [0, 1] };\n const initialAttributes = merge(defaultAttributes, attrs);\n const graphicItem = Factory.createGraphicComponent(ComponentEnum.scrollbar, initialAttributes);\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const direction = invokeFunctionType(this.spec.direction, parameters, datum, element);\n const position = invokeFunctionType(this.spec.position, parameters, datum, element);\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n const targetMark = this.spec.container\n ? isString(this.spec.container)\n ? this.view.getMarkById(this.spec.container)\n : this.spec.container\n : null;\n const groupMark = targetMark && targetMark.markType === GrammarMarkType.group ? targetMark : this.group;\n const groupGraphicItem = groupMark.getGroupGraphicItem();\n const size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: this.view.width(), height: this.view.height() };\n return generateScrollbarAttributes(size, direction, position, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerScrollbar = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.scrollbar,\n (attrs: ScrollBarAttributes) => new ScrollbarComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.scrollbar, Scrollbar);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(ScrollbarFilter.type, ScrollbarFilter);\n};\n"]}
@@ -2,7 +2,7 @@ import { isNil, merge, mixin } from "@visactor/vutils";
2
2
 
3
3
  import { Slider as SliderComponent } from "@visactor/vrender-components";
4
4
 
5
- import { ComponentEnum } from "../graph";
5
+ import { ComponentEnum } from "../graph/enums";
6
6
 
7
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type { SliderAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { Slider as SliderComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum } from '../graph';\nimport type { ISlider, SliderSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\nimport { SliderFilter } from '../interactions/slider-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateSliderAttributes = (\n min: number,\n max: number,\n theme?: ITheme,\n addition?: RecursivePartial<SliderAttributes>\n): SliderAttributes => {\n const sliderTheme = theme?.components?.slider;\n return merge({}, sliderTheme, { min, max, value: [min, max] }, addition ?? {});\n};\n\nexport class Slider extends Component implements ISlider {\n static readonly componentType: string = ComponentEnum.slider;\n protected declare spec: SliderSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.slider, group);\n this.spec.componentType = ComponentEnum.slider;\n }\n\n protected parseAddition(spec: SliderSpec) {\n super.parseAddition(spec);\n this.min(spec.min);\n this.max(spec.max);\n return this;\n }\n\n min(min: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(min, 'min');\n }\n\n max(max: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(max, 'max');\n }\n\n setStartEndValue(start?: number, end?: number) {\n const slider = this.elements[0]?.getGraphicItem?.() as unknown as SliderComponent;\n slider.setValue([start, end]);\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const min = !isNil(this.spec.min) ? invokeFunctionType(this.spec.min, parameters, datum, element) : 0;\n const max = !isNil(this.spec.max) ? invokeFunctionType(this.spec.max, parameters, datum, element) : 1;\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n return generateSliderAttributes(min, max, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerSlider = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.slider,\n (attrs: SliderAttributes) => new SliderComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.slider, Slider);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(SliderFilter.type, SliderFilter);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/slider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIvD,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAYzE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,GAAW,EACX,GAAW,EACX,KAAc,EACd,QAA6C,EAC3B,EAAE;;IACpB,MAAM,WAAW,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,MAAM,CAAC;IAC9C,OAAO,KAAK,CAAC,EAAE,EAAE,WAAW,EAAE,EAA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AAC,MAAM,EACpB,CAAC,KAAuB,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,KAAK,CAAwB,CAC/E,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAExD,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,mBAAmB,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAC/D,CAAC,CAAC","file":"slider.js","sourcesContent":["import { isNil, merge, mixin } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { SliderAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { Slider as SliderComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum } from '../graph/enums';\nimport type { ISlider, SliderSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\nimport { SliderFilter } from '../interactions/slider-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateSliderAttributes = (\n min: number,\n max: number,\n theme?: ITheme,\n addition?: RecursivePartial<SliderAttributes>\n): SliderAttributes => {\n const sliderTheme = theme?.components?.slider;\n return merge({}, sliderTheme, { min, max, value: [min, max] }, addition ?? {});\n};\n\nexport class Slider extends Component implements ISlider {\n static readonly componentType: string = ComponentEnum.slider;\n protected declare spec: SliderSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.slider, group);\n this.spec.componentType = ComponentEnum.slider;\n }\n\n protected parseAddition(spec: SliderSpec) {\n super.parseAddition(spec);\n this.min(spec.min);\n this.max(spec.max);\n return this;\n }\n\n min(min: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(min, 'min');\n }\n\n max(max: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(max, 'max');\n }\n\n setStartEndValue(start?: number, end?: number) {\n const slider = this.elements[0]?.getGraphicItem?.() as unknown as SliderComponent;\n slider.setValue([start, end]);\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const min = !isNil(this.spec.min) ? invokeFunctionType(this.spec.min, parameters, datum, element) : 0;\n const max = !isNil(this.spec.max) ? invokeFunctionType(this.spec.max, parameters, datum, element) : 1;\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n return generateSliderAttributes(min, max, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerSlider = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.slider,\n (attrs: SliderAttributes) => new SliderComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.slider, Slider);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(SliderFilter.type, SliderFilter);\n};\n"]}
@@ -2,7 +2,7 @@ import { isValid, merge } from "@visactor/vutils";
2
2
 
3
3
  import { Title as TitleComponent } from "@visactor/vrender-components";
4
4
 
5
- import { ComponentEnum } from "../graph";
5
+ import { ComponentEnum } from "../graph/enums";
6
6
 
7
7
  import { Component } from "../view/component";
8
8
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/title.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAYvE,OAAO,EAAE,aAAa,EAAE,MAA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CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AAzCe,mBAAa,GAAW,aAAa,CAAC,KAAK,CAAC;AA4C9D,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,OAAO,CAAC,wBAAwB,CAC9B,aAAa,CAAC,KAAK,EACnB,CAAC,KAAiB,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,KAAK,CAAwB,CACxE,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC","file":"title.js","sourcesContent":["import { isValid, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { TitleAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { Title as TitleComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum } from '../graph';\nimport type { ITitle, TitleSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateTitleAttributes = (\n title?: string | number | number[] | string[],\n subTitle?: string | number | number[] | string[],\n theme?: ITheme,\n addition?: RecursivePartial<TitleAttrs>\n): TitleAttrs => {\n const titleTheme = theme?.components?.title;\n const attributes: RecursivePartial<TitleAttrs> = {};\n if (isValid(title)) {\n attributes.text = title;\n }\n if (isValid(subTitle)) {\n attributes.subtext = subTitle;\n }\n return merge({}, titleTheme, attributes, addition ?? {});\n};\n\nexport class Title extends Component implements ITitle {\n static readonly componentType: string = ComponentEnum.title;\n protected declare spec: TitleSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.title, group);\n this.spec.componentType = ComponentEnum.title;\n }\n\n protected parseAddition(spec: TitleSpec) {\n super.parseAddition(spec);\n this.title(spec.title);\n this.subTitle(spec.subTitle);\n return this;\n }\n\n title(text: MarkFunctionType<string | number | number[] | string[]> | Nil) {\n return this.setFunctionSpec(text, 'title');\n }\n\n subTitle(text: MarkFunctionType<string | number | number[] | string[]> | Nil) {\n return this.setFunctionSpec(text, 'subTitle');\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const title = invokeFunctionType(this.spec.title, parameters, datum, element);\n const subTitle = invokeFunctionType(this.spec.subTitle, parameters, datum, element);\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n return generateTitleAttributes(title, subTitle, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerTitle = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.title,\n (attrs: TitleAttrs) => new TitleComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.title, Title);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/title.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIlD,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAYvE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,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B,CACxE,CAAC;IAEF,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC","file":"title.js","sourcesContent":["import { isValid, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { TitleAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { Title as TitleComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum } from '../graph/enums';\nimport type { ITitle, TitleSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateTitleAttributes = (\n title?: string | number | number[] | string[],\n subTitle?: string | number | number[] | string[],\n theme?: ITheme,\n addition?: RecursivePartial<TitleAttrs>\n): TitleAttrs => {\n const titleTheme = theme?.components?.title;\n const attributes: RecursivePartial<TitleAttrs> = {};\n if (isValid(title)) {\n attributes.text = title;\n }\n if (isValid(subTitle)) {\n attributes.subtext = subTitle;\n }\n return merge({}, titleTheme, attributes, addition ?? {});\n};\n\nexport class Title extends Component implements ITitle {\n static readonly componentType: string = ComponentEnum.title;\n protected declare spec: TitleSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.title, group);\n this.spec.componentType = ComponentEnum.title;\n }\n\n protected parseAddition(spec: TitleSpec) {\n super.parseAddition(spec);\n this.title(spec.title);\n this.subTitle(spec.subTitle);\n return this;\n }\n\n title(text: MarkFunctionType<string | number | number[] | string[]> | Nil) {\n return this.setFunctionSpec(text, 'title');\n }\n\n subTitle(text: MarkFunctionType<string | number | number[] | string[]> | Nil) {\n return this.setFunctionSpec(text, 'subTitle');\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const title = invokeFunctionType(this.spec.title, parameters, datum, element);\n const subTitle = invokeFunctionType(this.spec.subTitle, parameters, datum, element);\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n return generateTitleAttributes(title, subTitle, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerTitle = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.title,\n (attrs: TitleAttrs) => new TitleComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.title, Title);\n};\n"]}
@@ -1,7 +1,8 @@
1
1
  import type { IGraphic } from '@visactor/vrender-core';
2
- import type { GlyphChannelEncoder, GlyphDefaultEncoder, IComponentConstructor, IElement, IGlyphElement, IGlyphMeta, IGrammarBaseConstructor, IGroupMark, IInteractionConstructor, IPlotMarkConstructor, ISemanticMark, ITransform, IView, MarkType, TypeAnimation } from '../types';
2
+ import type { GlyphChannelEncoder, GlyphDefaultEncoder, IComponentConstructor, IElement, IGlyphElement, IGlyphMeta, IGrammarBaseConstructor, IGroupMark, IInteractionConstructor, IMark, IMarkConstructor, IPlotMarkConstructor, ISemanticMark, ITransform, IView, MarkType, TypeAnimation } from '../types';
3
3
  export declare class Factory {
4
4
  private static _plotMarks;
5
+ private static _marks;
5
6
  private static _components;
6
7
  private static _graphicComponents;
7
8
  private static _transforms;
@@ -11,6 +12,9 @@ export declare class Factory {
11
12
  private static _interactions;
12
13
  static registerPlotMarks(key: string, mark: IPlotMarkConstructor): void;
13
14
  static createPlotMark(type: string, id?: string): ISemanticMark<any, any> | null;
15
+ static registerMark(key: string, mark: IMarkConstructor): void;
16
+ static createMark(type: string, view: IView, group?: IGroupMark): IMark | null;
17
+ static hasMark(type: string): boolean;
14
18
  static registerComponent(key: string, component: IComponentConstructor): void;
15
19
  static createComponent(componentType: string, view: IView, group?: IGroupMark, mode?: '2d' | '3d'): import("../types").IComponent;
16
20
  static hasComponent(componentType: string): boolean;
@@ -8,6 +8,16 @@ export class Factory {
8
8
  if (!Factory._plotMarks[type]) return null;
9
9
  return new (0, Factory._plotMarks[type])(id);
10
10
  }
11
+ static registerMark(key, mark) {
12
+ Factory._marks[key] = mark;
13
+ }
14
+ static createMark(type, view, group) {
15
+ if (!Factory._marks[type]) return null;
16
+ return new (0, Factory._marks[type])(view, type, group);
17
+ }
18
+ static hasMark(type) {
19
+ return !!Factory._marks[type];
20
+ }
11
21
  static registerComponent(key, component) {
12
22
  Factory._components[key] = component;
13
23
  }
@@ -62,7 +72,7 @@ export class Factory {
62
72
  }
63
73
  }
64
74
 
65
- Factory._plotMarks = {}, Factory._components = {}, Factory._graphicComponents = {},
75
+ Factory._plotMarks = {}, Factory._marks = {}, Factory._components = {}, Factory._graphicComponents = {},
66
76
  Factory._transforms = {}, Factory._grammars = {}, Factory._glyphs = {}, Factory._animations = {},
67
77
  Factory._interactions = {}, Factory.registerGlyph = (glyphType, marks, encoders, defaultEncoder, progressiveChannels) => (Factory._glyphs[glyphType] = new GlyphMeta(marks, encoders, defaultEncoder, progressiveChannels),
68
78
  Factory._glyphs[glyphType]), Factory.registerAnimationType = (animationType, animation) => {