@visactor/vchart 1.12.4 → 1.12.5

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 (169) hide show
  1. package/build/es5/index.js +1 -1
  2. package/build/index.js +196 -453
  3. package/build/index.min.js +1 -1
  4. package/build/tsconfig.tsbuildinfo +1 -1
  5. package/cjs/chart/base/base-chart-transformer.js +4 -4
  6. package/cjs/chart/base/base-chart-transformer.js.map +1 -1
  7. package/cjs/compile/mark/compilable-mark.d.ts +0 -3
  8. package/cjs/compile/mark/compilable-mark.js +2 -9
  9. package/cjs/compile/mark/compilable-mark.js.map +1 -1
  10. package/cjs/compile/mark/interface.d.ts +0 -2
  11. package/cjs/compile/mark/interface.js.map +1 -1
  12. package/cjs/component/axis/cartesian/axis.d.ts +1 -0
  13. package/cjs/component/axis/cartesian/axis.js +28 -1
  14. package/cjs/component/axis/cartesian/axis.js.map +1 -1
  15. package/cjs/component/axis/polar/axis.js +3 -17
  16. package/cjs/component/axis/polar/axis.js.map +1 -1
  17. package/cjs/component/axis/polar/util/common.js +1 -1
  18. package/cjs/component/axis/polar/util/common.js.map +1 -1
  19. package/cjs/component/brush/brush.js +2 -8
  20. package/cjs/component/brush/brush.js.map +1 -1
  21. package/cjs/component/crosshair/cartesian.js +2 -18
  22. package/cjs/component/crosshair/cartesian.js.map +1 -1
  23. package/cjs/component/crosshair/polar.js +2 -18
  24. package/cjs/component/crosshair/polar.js.map +1 -1
  25. package/cjs/component/custom-mark/custom-mark.d.ts +1 -3
  26. package/cjs/component/custom-mark/custom-mark.js +2 -16
  27. package/cjs/component/custom-mark/custom-mark.js.map +1 -1
  28. package/cjs/component/data-zoom/data-zoom/data-zoom.d.ts +0 -3
  29. package/cjs/component/data-zoom/data-zoom/data-zoom.js +0 -19
  30. package/cjs/component/data-zoom/data-zoom/data-zoom.js.map +1 -1
  31. package/cjs/component/data-zoom/scroll-bar/scroll-bar.d.ts +0 -3
  32. package/cjs/component/data-zoom/scroll-bar/scroll-bar.js +0 -19
  33. package/cjs/component/data-zoom/scroll-bar/scroll-bar.js.map +1 -1
  34. package/cjs/component/indicator/indicator.js +2 -18
  35. package/cjs/component/indicator/indicator.js.map +1 -1
  36. package/cjs/component/interface/common.d.ts +1 -1
  37. package/cjs/component/interface/common.js.map +1 -1
  38. package/cjs/component/label/interface.d.ts +2 -2
  39. package/cjs/component/label/interface.js.map +1 -1
  40. package/cjs/component/legend/continuous/legend.js +6 -18
  41. package/cjs/component/legend/continuous/legend.js.map +1 -1
  42. package/cjs/component/legend/discrete/legend.js +1 -17
  43. package/cjs/component/legend/discrete/legend.js.map +1 -1
  44. package/cjs/component/map-label/component.js +3 -8
  45. package/cjs/component/map-label/component.js.map +1 -1
  46. package/cjs/component/marker/base-marker.js +2 -18
  47. package/cjs/component/marker/base-marker.js.map +1 -1
  48. package/cjs/component/player/player.d.ts +1 -3
  49. package/cjs/component/player/player.js +0 -9
  50. package/cjs/component/player/player.js.map +1 -1
  51. package/cjs/component/title/title.js +2 -18
  52. package/cjs/component/title/title.js.map +1 -1
  53. package/cjs/component/tooltip/tooltip.d.ts +1 -3
  54. package/cjs/component/tooltip/tooltip.js +0 -19
  55. package/cjs/component/tooltip/tooltip.js.map +1 -1
  56. package/cjs/component/util.d.ts +3 -0
  57. package/cjs/component/util.js +16 -1
  58. package/cjs/component/util.js.map +1 -1
  59. package/cjs/core/index.d.ts +1 -1
  60. package/cjs/core/index.js +1 -1
  61. package/cjs/core/index.js.map +1 -1
  62. package/cjs/event/event-dispatcher.js +1 -9
  63. package/cjs/event/event-dispatcher.js.map +1 -1
  64. package/cjs/series/base/base-series-transformer.js +7 -4
  65. package/cjs/series/base/base-series-transformer.js.map +1 -1
  66. package/cjs/series/base/base-series.js +3 -5
  67. package/cjs/series/base/base-series.js.map +1 -1
  68. package/cjs/series/dot/dot.d.ts +0 -1
  69. package/cjs/series/dot/dot.js +0 -5
  70. package/cjs/series/dot/dot.js.map +1 -1
  71. package/cjs/series/polar/animation.d.ts +1 -0
  72. package/cjs/series/polar/animation.js +15 -17
  73. package/cjs/series/polar/animation.js.map +1 -1
  74. package/cjs/series/polar/polar.js +9 -2
  75. package/cjs/series/polar/polar.js.map +1 -1
  76. package/cjs/series/radar/radar.js +1 -0
  77. package/cjs/series/radar/radar.js.map +1 -1
  78. package/cjs/series/word-cloud/base.js +21 -10
  79. package/cjs/series/word-cloud/base.js.map +1 -1
  80. package/cjs/theme/builtin/common/mark.js +2 -0
  81. package/cjs/theme/builtin/common/mark.js.map +1 -1
  82. package/cjs/typings/spec/common.d.ts +1 -0
  83. package/cjs/typings/spec/common.js.map +1 -1
  84. package/cjs/util/math.d.ts +1 -0
  85. package/cjs/util/math.js +7 -2
  86. package/cjs/util/math.js.map +1 -1
  87. package/esm/chart/base/base-chart-transformer.js +5 -3
  88. package/esm/chart/base/base-chart-transformer.js.map +1 -1
  89. package/esm/compile/mark/compilable-mark.d.ts +0 -3
  90. package/esm/compile/mark/compilable-mark.js +2 -9
  91. package/esm/compile/mark/compilable-mark.js.map +1 -1
  92. package/esm/compile/mark/interface.d.ts +0 -2
  93. package/esm/compile/mark/interface.js.map +1 -1
  94. package/esm/component/axis/cartesian/axis.d.ts +1 -0
  95. package/esm/component/axis/cartesian/axis.js +28 -1
  96. package/esm/component/axis/cartesian/axis.js.map +1 -1
  97. package/esm/component/axis/polar/axis.js +3 -16
  98. package/esm/component/axis/polar/axis.js.map +1 -1
  99. package/esm/component/axis/polar/util/common.js +2 -2
  100. package/esm/component/axis/polar/util/common.js.map +1 -1
  101. package/esm/component/brush/brush.js +4 -8
  102. package/esm/component/brush/brush.js.map +1 -1
  103. package/esm/component/crosshair/cartesian.js +4 -18
  104. package/esm/component/crosshair/cartesian.js.map +1 -1
  105. package/esm/component/crosshair/polar.js +4 -18
  106. package/esm/component/crosshair/polar.js.map +1 -1
  107. package/esm/component/custom-mark/custom-mark.d.ts +1 -3
  108. package/esm/component/custom-mark/custom-mark.js +3 -17
  109. package/esm/component/custom-mark/custom-mark.js.map +1 -1
  110. package/esm/component/data-zoom/data-zoom/data-zoom.d.ts +0 -3
  111. package/esm/component/data-zoom/data-zoom/data-zoom.js +1 -20
  112. package/esm/component/data-zoom/data-zoom/data-zoom.js.map +1 -1
  113. package/esm/component/data-zoom/scroll-bar/scroll-bar.d.ts +0 -3
  114. package/esm/component/data-zoom/scroll-bar/scroll-bar.js +1 -20
  115. package/esm/component/data-zoom/scroll-bar/scroll-bar.js.map +1 -1
  116. package/esm/component/indicator/indicator.js +4 -18
  117. package/esm/component/indicator/indicator.js.map +1 -1
  118. package/esm/component/interface/common.d.ts +1 -1
  119. package/esm/component/interface/common.js.map +1 -1
  120. package/esm/component/label/interface.d.ts +2 -2
  121. package/esm/component/label/interface.js.map +1 -1
  122. package/esm/component/legend/continuous/legend.js +7 -18
  123. package/esm/component/legend/continuous/legend.js.map +1 -1
  124. package/esm/component/legend/discrete/legend.js +3 -19
  125. package/esm/component/legend/discrete/legend.js.map +1 -1
  126. package/esm/component/map-label/component.js +3 -7
  127. package/esm/component/map-label/component.js.map +1 -1
  128. package/esm/component/marker/base-marker.js +4 -18
  129. package/esm/component/marker/base-marker.js.map +1 -1
  130. package/esm/component/player/player.d.ts +1 -3
  131. package/esm/component/player/player.js +1 -10
  132. package/esm/component/player/player.js.map +1 -1
  133. package/esm/component/title/title.js +4 -18
  134. package/esm/component/title/title.js.map +1 -1
  135. package/esm/component/tooltip/tooltip.d.ts +1 -3
  136. package/esm/component/tooltip/tooltip.js +1 -20
  137. package/esm/component/tooltip/tooltip.js.map +1 -1
  138. package/esm/component/util.d.ts +3 -0
  139. package/esm/component/util.js +14 -1
  140. package/esm/component/util.js.map +1 -1
  141. package/esm/core/index.d.ts +1 -1
  142. package/esm/core/index.js +1 -1
  143. package/esm/core/index.js.map +1 -1
  144. package/esm/event/event-dispatcher.js +1 -9
  145. package/esm/event/event-dispatcher.js.map +1 -1
  146. package/esm/series/base/base-series-transformer.js +7 -4
  147. package/esm/series/base/base-series-transformer.js.map +1 -1
  148. package/esm/series/base/base-series.js +3 -5
  149. package/esm/series/base/base-series.js.map +1 -1
  150. package/esm/series/dot/dot.d.ts +0 -1
  151. package/esm/series/dot/dot.js +0 -5
  152. package/esm/series/dot/dot.js.map +1 -1
  153. package/esm/series/polar/animation.d.ts +1 -0
  154. package/esm/series/polar/animation.js +15 -16
  155. package/esm/series/polar/animation.js.map +1 -1
  156. package/esm/series/polar/polar.js +9 -1
  157. package/esm/series/polar/polar.js.map +1 -1
  158. package/esm/series/radar/radar.js +1 -0
  159. package/esm/series/radar/radar.js.map +1 -1
  160. package/esm/series/word-cloud/base.js +20 -10
  161. package/esm/series/word-cloud/base.js.map +1 -1
  162. package/esm/theme/builtin/common/mark.js +2 -0
  163. package/esm/theme/builtin/common/mark.js.map +1 -1
  164. package/esm/typings/spec/common.d.ts +1 -0
  165. package/esm/typings/spec/common.js.map +1 -1
  166. package/esm/util/math.d.ts +1 -0
  167. package/esm/util/math.js +4 -0
  168. package/esm/util/math.js.map +1 -1
  169. package/package.json +15 -15
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", {
14
14
  value: !0
15
15
  }), exports.registerIndicator = exports.Indicator = void 0;
16
16
 
17
- const vdataset_1 = require("@visactor/vdataset"), layout_1 = require("../../constant/layout"), type_1 = require("../interface/type"), base_component_1 = require("../base/base-component"), vutils_extension_1 = require("@visactor/vutils-extension"), style_1 = require("../../util/style"), space_1 = require("../../util/space"), vutils_1 = require("@visactor/vutils"), util_1 = require("./util"), register_1 = require("../../data/register"), compilable_data_1 = require("../../compile/data/compilable-data"), vrender_components_1 = require("@visactor/vrender-components"), factory_1 = require("../../core/factory");
17
+ const vdataset_1 = require("@visactor/vdataset"), layout_1 = require("../../constant/layout"), type_1 = require("../interface/type"), base_component_1 = require("../base/base-component"), vutils_extension_1 = require("@visactor/vutils-extension"), style_1 = require("../../util/style"), space_1 = require("../../util/space"), vutils_1 = require("@visactor/vutils"), util_1 = require("./util"), register_1 = require("../../data/register"), compilable_data_1 = require("../../compile/data/compilable-data"), vrender_components_1 = require("@visactor/vrender-components"), factory_1 = require("../../core/factory"), util_2 = require("../util");
18
18
 
19
19
  class Indicator extends base_component_1.BaseComponent {
20
20
  constructor() {
@@ -23,23 +23,7 @@ class Indicator extends base_component_1.BaseComponent {
23
23
  this.layoutLevel = layout_1.LayoutLevel.Indicator, this._gap = 0, this._activeDatum = null;
24
24
  }
25
25
  static getSpecInfo(chartSpec) {
26
- if (this.type !== Indicator.type) return null;
27
- const indicatorSpec = chartSpec[this.specKey];
28
- if (!(0, vutils_1.isArray)(indicatorSpec)) return !1 === indicatorSpec.visible ? [] : [ {
29
- spec: indicatorSpec,
30
- specPath: [ this.specKey ],
31
- specInfoPath: [ "component", this.specKey, 0 ],
32
- type: type_1.ComponentTypeEnum.indicator
33
- } ];
34
- const specInfos = [];
35
- return indicatorSpec.forEach(((s, i) => {
36
- s && !1 !== s.visible && specInfos.push({
37
- spec: s,
38
- specPath: [ this.specKey, i ],
39
- specInfoPath: [ "component", this.specKey, i ],
40
- type: type_1.ComponentTypeEnum.indicator
41
- });
42
- })), specInfos;
26
+ return (0, util_2.getSpecInfo)(chartSpec, this.specKey, this.type, (s => s && !1 !== s.visible));
43
27
  }
44
28
  created() {
45
29
  super.created(), this.initData(), this.initEvent();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/indicator/indicator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAA8C;AAC9C,kDAAkE;AAElE,4CAAsD;AACtD,2DAAuD;AAIvD,iEAAuD;AACvD,4CAA2D;AAC3D,4CAAqD;AACrD,6CAA6F;AAC7F,iCAAyC;AAEzC,kDAAuE;AACvE,wEAAoE;AACpE,qEAAgF;AAKhF,gDAA6C;AAI7C,MAAa,SAAoC,SAAQ,8BAAgB;IAAzE;;QAEE,SAAI,GAAG,wBAAiB,CAAC,SAAS,CAAC;QACnC,SAAI,GAAW,wBAAiB,CAAC,SAAS,CAAC;QAG3C,YAA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AC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IAEO,eAAe,CAAC,QAAgB;QACtC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAES,8BAA8B;QACtC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAwB,CAAC;IAC3D,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAED,qBAAqB;QACnB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AAhRH,8BAiRC;AAhRQ,cAAI,GAAG,wBAAiB,CAAC,SAAS,CAAC;AAInC,iBAAO,GAAG,WAAW,CAAC;AA8QxB,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,iBAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B","file":"indicator.js","sourcesContent":["import { DataView } from '@visactor/vdataset';\nimport { LayoutLevel, LayoutZIndex } from '../../constant/layout';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../interface/type';\nimport { BaseComponent } from '../base/base-component';\nimport type { IRegion } from '../../region/interface';\nimport type { IIndicator, IIndicatorItemSpec, IIndicatorSpec } from './interface';\nimport type { Maybe } from '../../typings';\nimport { mergeSpec } from '@visactor/vutils-extension';\nimport { transformIndicatorStyle } from '../../util/style';\nimport { getActualNumValue } from '../../util/space';\nimport { isEqual, isValid, isFunction, array, isArray, pickWithout } from '@visactor/vutils';\nimport { indicatorMapper } from './util';\nimport type { IModelSpecInfo } from '../../model/interface';\nimport { registerDataSetInstanceTransform } from '../../data/register';\nimport { CompilableData } from '../../compile/data/compilable-data';\nimport { Indicator as IndicatorComponents } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IndicatorAttributes } from '@visactor/vrender-components';\nimport type { IGraphic, INode, IGroup } from '@visactor/vrender-core';\nimport type { FunctionType } from '../../typings/visual';\nimport { Factory } from '../../core/factory';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IRichTextCharacter } from '@visactor/vrender-core';\n\nexport class Indicator<T extends IIndicatorSpec> extends BaseComponent<T> implements IIndicator {\n static type = ComponentTypeEnum.indicator;\n type = ComponentTypeEnum.indicator;\n name: string = ComponentTypeEnum.indicator;\n\n static specKey = 'indicator';\n specKey = 'indicator';\n\n layoutType: 'none' = 'none';\n layoutZIndex: number = LayoutZIndex.Indicator;\n layoutLevel: number = LayoutLevel.Indicator;\n\n private _gap: number = 0;\n\n private _activeDatum: any = null;\n private _displayData!: CompilableData;\n\n private _title: IIndicatorItemSpec;\n private _content: IIndicatorItemSpec[];\n\n private _indicatorComponent: IndicatorComponents;\n private _cacheAttrs: IndicatorAttributes;\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n if (this.type !== Indicator.type) {\n return null;\n }\n const indicatorSpec = chartSpec[this.specKey];\n if (!isArray(indicatorSpec)) {\n if (indicatorSpec.visible === false) {\n return [];\n }\n return [\n {\n spec: indicatorSpec,\n specPath: [this.specKey],\n specInfoPath: ['component', this.specKey, 0],\n type: ComponentTypeEnum.indicator\n }\n ];\n }\n\n const specInfos: IModelSpecInfo[] = [];\n indicatorSpec.forEach((s, i) => {\n if (s && s.visible !== false) {\n specInfos.push({\n spec: s,\n specPath: [this.specKey, i],\n specInfoPath: ['component', this.specKey, i],\n type: ComponentTypeEnum.indicator\n });\n }\n });\n return specInfos;\n }\n\n created() {\n super.created();\n // data\n this.initData();\n // event\n this.initEvent();\n }\n\n setAttrFromSpec() {\n super.setAttrFromSpec();\n this._gap = this._spec.gap || 0;\n this._title = this._spec.title;\n this._content = array(this._spec.content);\n this._regions = this._option.getRegionsInUserIdOrIndex(array(this._spec.regionId), array(this._spec.regionIndex));\n }\n\n onRender(ctx: any): void {\n // do nothing\n }\n\n // region\n changeRegions(regions: IRegion[]): void {\n // do nothing\n }\n\n // event\n protected initEvent() {\n if (this._option.disableTriggerEvent) {\n return;\n }\n const trigger = this._spec.trigger;\n if (trigger === 'none') {\n return;\n }\n\n const view = this.getCompiler()?.getVGrammarView();\n\n if (!view) {\n return;\n }\n\n if (this._spec.trigger === 'hover') {\n view.addEventListener('element-highlight:start', (params: any) => {\n if (this.isRelativeModel(params.options.regionId)) {\n this.updateDatum(params.elements[0].getDatum());\n }\n });\n view.addEventListener('element-highlight:reset', (params: any) => {\n if (this.isRelativeModel(params.options.regionId)) {\n this.updateDatum(null);\n }\n });\n } else {\n view.addEventListener('element-select:start', (params: any) => {\n if (this.isRelativeModel(params.options.regionId)) {\n this.updateDatum(params.elements[0].getDatum());\n }\n });\n view.addEventListener('element-select:reset', (params: any) => {\n if (this.isRelativeModel(params.options.regionId)) {\n this.updateDatum(null);\n }\n });\n }\n }\n\n updateDatum(datum: any) {\n this._activeDatum = datum;\n this._displayData.updateData();\n const attrs = this._getIndicatorAttrs();\n this._createOrUpdateIndicatorComponent(attrs);\n }\n\n // data\n private initData() {\n registerDataSetInstanceTransform(this._option.dataSet, 'indicatorFilter', indicatorMapper);\n const displayData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n displayData.transform({\n type: 'indicatorFilter',\n options: {\n title: this._title,\n content: this._content,\n datum: () => this._activeDatum\n }\n });\n\n displayData.target.addListener('change', this.updateDatum.bind(this));\n\n this._displayData = new CompilableData(this._option, displayData);\n }\n\n updateLayoutAttribute(): void {\n const attrs = this._getIndicatorAttrs();\n this._createOrUpdateIndicatorComponent(attrs);\n\n super.updateLayoutAttribute();\n }\n\n private _getIndicatorAttrs() {\n if (this._spec.visible === false || (this._spec.fixed === false && this._activeDatum === null)) {\n return {\n visible: false\n } as IndicatorAttributes;\n }\n\n const region = this._regions[0];\n const { width, height } = region.getLayoutRect();\n const { x, y } = region.getLayoutStartPoint();\n const { content, offsetX, offsetY, limitRatio, title, ...restSpec } = this._spec;\n\n const contentComponentSpec: IIndicatorItemSpec[] = [];\n array(content).forEach((eachItem: IIndicatorItemSpec) => {\n const contentSpec = mergeSpec({}, this._theme.content, eachItem);\n contentComponentSpec.push({\n visible: contentSpec.visible !== false && (contentSpec.field ? this._activeDatum !== null : true),\n space: contentSpec.space || this._gap,\n autoLimit: contentSpec.autoLimit,\n autoFit: contentSpec.autoFit,\n fitPercent: contentSpec.fitPercent,\n fitStrategy: contentSpec.fitStrategy,\n style: {\n ...transformIndicatorStyle(pickWithout(contentSpec.style, ['text']), this._activeDatum),\n text: this._createText(contentSpec.field, contentSpec.style.text)\n }\n });\n });\n\n return {\n visible: true,\n size: {\n width: width,\n height: height\n },\n zIndex: this.layoutZIndex,\n x: x,\n y: y,\n dx: offsetX ? getActualNumValue(offsetX, this._computeLayoutRadius()) : 0,\n dy: offsetY ? getActualNumValue(offsetY, this._computeLayoutRadius()) : 0,\n limitRatio: limitRatio || Infinity,\n title: {\n visible: title.visible !== false && (!isValid(title.field) || this._activeDatum !== null),\n space: title.space || this._gap,\n autoLimit: title.autoLimit,\n autoFit: title.autoFit,\n fitPercent: title.fitPercent,\n fitStrategy: title.fitStrategy,\n style: {\n ...transformIndicatorStyle(pickWithout(title.style, ['text']), this._activeDatum),\n text: this._createText(title.field, title.style.text as any) // FIXME: type\n }\n },\n content: contentComponentSpec,\n ...(restSpec as unknown as IndicatorAttributes)\n } as IndicatorAttributes;\n }\n\n private _createOrUpdateIndicatorComponent(attrs: IndicatorAttributes): IndicatorComponents {\n if (this._indicatorComponent) {\n if (!isEqual(attrs, this._cacheAttrs)) {\n this._indicatorComponent.setAttributes(attrs);\n }\n } else {\n const container = this.getContainer();\n //FIXME:类型“IndicatorAttributes”的参数不能赋给类型“Required<IndicatorAttributes>”的参数\n const indicator = new IndicatorComponents(attrs as any);\n indicator.name = 'indicator';\n container.add(indicator as unknown as INode);\n this._indicatorComponent = indicator;\n this._indicatorComponent.on('*', (event: any, type: string) =>\n this._delegateEvent(this._indicatorComponent as unknown as IGraphic, event, type)\n );\n }\n this._cacheAttrs = attrs;\n return this._indicatorComponent;\n }\n\n private _createText(\n field: string | undefined,\n text:\n | string\n | number\n | string[]\n | number[]\n | IRichTextCharacter[]\n | FunctionType<number | number[] | string | string[] | IRichTextCharacter[]>\n ) {\n if (field) {\n return this._activeDatum ? this._activeDatum[field] : '';\n }\n if (isFunction(text)) {\n return text(this._activeDatum, undefined) ?? '';\n }\n return text ?? '';\n }\n\n private _computeLayoutRadius() {\n const region = this._regions[0];\n const { width, height } = region.getLayoutRect();\n return Math.min(width / 2, height / 2);\n }\n\n private isRelativeModel(regionId: number) {\n return this._regions.some(region => region.id === regionId);\n }\n\n protected _getNeedClearVRenderComponents(): IGraphic[] {\n return [this._indicatorComponent] as unknown as IGroup[];\n }\n\n clear(): void {\n this._cacheAttrs = null;\n super.clear();\n }\n\n getIndicatorComponent(): IndicatorComponents {\n return this._indicatorComponent;\n }\n}\n\nexport const registerIndicator = () => {\n Factory.registerComponent(Indicator.type, Indicator);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/indicator/indicator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAA8C;AAC9C,kDAAkE;AAElE,4CAAsD;AACtD,2DAAuD;AAIvD,iEAAuD;AACvD,4CAA2D;AAC3D,4CAAqD;AACrD,6CAAoF;AACpF,iCAAyC;AAEzC,kDAAuE;AACvE,wEAAoE;AACpE,qEAAgF;AAKhF,gDAA6C;AAG7C,kCAAsC;AAEtC,MAAa,SAAoC,SAAQ,8BAAgB;IAAzE;;QAEE,SAAI,GAAG,wBAAiB,CAAC,SAAS,CAAC;QACnC,SAAI,GAAW,wBAAiB,CAAC,SAAS,CAAC;QAG3C,YAAO,GAAG,WAAW,CAAC;QAEtB,eAAU,GAAW,MAAM,CAAC;QAC5B,iBAAY,GAAW,qBAAY,CAAC,SAAS,C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I,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,mCAAI,EAAE,CAAC;SACjD;QACD,OAAO,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;IACpB,CAAC;IAEO,oBAAoB;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,aAAa,EAAE,CAAC;QACjD,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;IAEO,eAAe,CAAC,QAAgB;QACtC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAES,8BAA8B;QACtC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAwB,CAAC;IAC3D,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;IAED,qBAAqB;QACnB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;;AArPH,8BAsPC;AArPQ,cAAI,GAAG,wBAAiB,CAAC,SAAS,CAAC;AAInC,iBAAO,GAAG,WAAW,CAAC;AAmPxB,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,iBAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B","file":"indicator.js","sourcesContent":["import { DataView } from '@visactor/vdataset';\nimport { LayoutLevel, LayoutZIndex } from '../../constant/layout';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../interface/type';\nimport { BaseComponent } from '../base/base-component';\nimport type { IRegion } from '../../region/interface';\nimport type { IIndicator, IIndicatorItemSpec, IIndicatorSpec } from './interface';\nimport type { Maybe } from '../../typings';\nimport { mergeSpec } from '@visactor/vutils-extension';\nimport { transformIndicatorStyle } from '../../util/style';\nimport { getActualNumValue } from '../../util/space';\nimport { isEqual, isValid, isFunction, array, pickWithout } from '@visactor/vutils';\nimport { indicatorMapper } from './util';\nimport type { IModelSpecInfo } from '../../model/interface';\nimport { registerDataSetInstanceTransform } from '../../data/register';\nimport { CompilableData } from '../../compile/data/compilable-data';\nimport { Indicator as IndicatorComponents } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IndicatorAttributes } from '@visactor/vrender-components';\nimport type { IGraphic, INode, IGroup } from '@visactor/vrender-core';\nimport type { FunctionType } from '../../typings/visual';\nimport { Factory } from '../../core/factory';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IRichTextCharacter } from '@visactor/vrender-core';\nimport { getSpecInfo } from '../util';\n\nexport class Indicator<T extends IIndicatorSpec> extends BaseComponent<T> implements IIndicator {\n static type = ComponentTypeEnum.indicator;\n type = ComponentTypeEnum.indicator;\n name: string = ComponentTypeEnum.indicator;\n\n static specKey = 'indicator';\n specKey = 'indicator';\n\n layoutType: 'none' = 'none';\n layoutZIndex: number = LayoutZIndex.Indicator;\n layoutLevel: number = LayoutLevel.Indicator;\n\n private _gap: number = 0;\n\n private _activeDatum: any = null;\n private _displayData!: CompilableData;\n\n private _title: IIndicatorItemSpec;\n private _content: IIndicatorItemSpec[];\n\n private _indicatorComponent: IndicatorComponents;\n private _cacheAttrs: IndicatorAttributes;\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n return getSpecInfo<IIndicatorSpec>(chartSpec, this.specKey, this.type, (s: IIndicatorSpec) => {\n return s && s.visible !== false;\n });\n }\n\n created() {\n super.created();\n // data\n this.initData();\n // event\n this.initEvent();\n }\n\n setAttrFromSpec() {\n super.setAttrFromSpec();\n this._gap = this._spec.gap || 0;\n this._title = this._spec.title;\n this._content = array(this._spec.content);\n this._regions = this._option.getRegionsInUserIdOrIndex(array(this._spec.regionId), array(this._spec.regionIndex));\n }\n\n onRender(ctx: any): void {\n // do nothing\n }\n\n // region\n changeRegions(regions: IRegion[]): void {\n // do nothing\n }\n\n // event\n protected initEvent() {\n if (this._option.disableTriggerEvent) {\n return;\n }\n const trigger = this._spec.trigger;\n if (trigger === 'none') {\n return;\n }\n\n const view = this.getCompiler()?.getVGrammarView();\n\n if (!view) {\n return;\n }\n\n if (this._spec.trigger === 'hover') {\n view.addEventListener('element-highlight:start', (params: any) => {\n if (this.isRelativeModel(params.options.regionId)) {\n this.updateDatum(params.elements[0].getDatum());\n }\n });\n view.addEventListener('element-highlight:reset', (params: any) => {\n if (this.isRelativeModel(params.options.regionId)) {\n this.updateDatum(null);\n }\n });\n } else {\n view.addEventListener('element-select:start', (params: any) => {\n if (this.isRelativeModel(params.options.regionId)) {\n this.updateDatum(params.elements[0].getDatum());\n }\n });\n view.addEventListener('element-select:reset', (params: any) => {\n if (this.isRelativeModel(params.options.regionId)) {\n this.updateDatum(null);\n }\n });\n }\n }\n\n updateDatum(datum: any) {\n this._activeDatum = datum;\n this._displayData.updateData();\n const attrs = this._getIndicatorAttrs();\n this._createOrUpdateIndicatorComponent(attrs);\n }\n\n // data\n private initData() {\n registerDataSetInstanceTransform(this._option.dataSet, 'indicatorFilter', indicatorMapper);\n const displayData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n displayData.transform({\n type: 'indicatorFilter',\n options: {\n title: this._title,\n content: this._content,\n datum: () => this._activeDatum\n }\n });\n\n displayData.target.addListener('change', this.updateDatum.bind(this));\n\n this._displayData = new CompilableData(this._option, displayData);\n }\n\n updateLayoutAttribute(): void {\n const attrs = this._getIndicatorAttrs();\n this._createOrUpdateIndicatorComponent(attrs);\n\n super.updateLayoutAttribute();\n }\n\n private _getIndicatorAttrs() {\n if (this._spec.visible === false || (this._spec.fixed === false && this._activeDatum === null)) {\n return {\n visible: false\n } as IndicatorAttributes;\n }\n\n const region = this._regions[0];\n const { width, height } = region.getLayoutRect();\n const { x, y } = region.getLayoutStartPoint();\n const { content, offsetX, offsetY, limitRatio, title, ...restSpec } = this._spec;\n\n const contentComponentSpec: IIndicatorItemSpec[] = [];\n array(content).forEach((eachItem: IIndicatorItemSpec) => {\n const contentSpec = mergeSpec({}, this._theme.content, eachItem);\n contentComponentSpec.push({\n visible: contentSpec.visible !== false && (contentSpec.field ? this._activeDatum !== null : true),\n space: contentSpec.space || this._gap,\n autoLimit: contentSpec.autoLimit,\n autoFit: contentSpec.autoFit,\n fitPercent: contentSpec.fitPercent,\n fitStrategy: contentSpec.fitStrategy,\n style: {\n ...transformIndicatorStyle(pickWithout(contentSpec.style, ['text']), this._activeDatum),\n text: this._createText(contentSpec.field, contentSpec.style.text)\n }\n });\n });\n\n return {\n visible: true,\n size: {\n width: width,\n height: height\n },\n zIndex: this.layoutZIndex,\n x: x,\n y: y,\n dx: offsetX ? getActualNumValue(offsetX, this._computeLayoutRadius()) : 0,\n dy: offsetY ? getActualNumValue(offsetY, this._computeLayoutRadius()) : 0,\n limitRatio: limitRatio || Infinity,\n title: {\n visible: title.visible !== false && (!isValid(title.field) || this._activeDatum !== null),\n space: title.space || this._gap,\n autoLimit: title.autoLimit,\n autoFit: title.autoFit,\n fitPercent: title.fitPercent,\n fitStrategy: title.fitStrategy,\n style: {\n ...transformIndicatorStyle(pickWithout(title.style, ['text']), this._activeDatum),\n text: this._createText(title.field, title.style.text as any) // FIXME: type\n }\n },\n content: contentComponentSpec,\n ...(restSpec as unknown as IndicatorAttributes)\n } as IndicatorAttributes;\n }\n\n private _createOrUpdateIndicatorComponent(attrs: IndicatorAttributes): IndicatorComponents {\n if (this._indicatorComponent) {\n if (!isEqual(attrs, this._cacheAttrs)) {\n this._indicatorComponent.setAttributes(attrs);\n }\n } else {\n const container = this.getContainer();\n //FIXME:类型“IndicatorAttributes”的参数不能赋给类型“Required<IndicatorAttributes>”的参数\n const indicator = new IndicatorComponents(attrs as any);\n indicator.name = 'indicator';\n container.add(indicator as unknown as INode);\n this._indicatorComponent = indicator;\n this._indicatorComponent.on('*', (event: any, type: string) =>\n this._delegateEvent(this._indicatorComponent as unknown as IGraphic, event, type)\n );\n }\n this._cacheAttrs = attrs;\n return this._indicatorComponent;\n }\n\n private _createText(\n field: string | undefined,\n text:\n | string\n | number\n | string[]\n | number[]\n | IRichTextCharacter[]\n | FunctionType<number | number[] | string | string[] | IRichTextCharacter[]>\n ) {\n if (field) {\n return this._activeDatum ? this._activeDatum[field] : '';\n }\n if (isFunction(text)) {\n return text(this._activeDatum, undefined) ?? '';\n }\n return text ?? '';\n }\n\n private _computeLayoutRadius() {\n const region = this._regions[0];\n const { width, height } = region.getLayoutRect();\n return Math.min(width / 2, height / 2);\n }\n\n private isRelativeModel(regionId: number) {\n return this._regions.some(region => region.id === regionId);\n }\n\n protected _getNeedClearVRenderComponents(): IGraphic[] {\n return [this._indicatorComponent] as unknown as IGroup[];\n }\n\n clear(): void {\n this._cacheAttrs = null;\n super.clear();\n }\n\n getIndicatorComponent(): IndicatorComponents {\n return this._indicatorComponent;\n }\n}\n\nexport const registerIndicator = () => {\n Factory.registerComponent(Indicator.type, Indicator);\n};\n"]}
@@ -33,7 +33,7 @@ export interface IComponent extends ILayoutModel {
33
33
  export interface IComponentConstructor extends IModelConstructor {
34
34
  type: string;
35
35
  specKey?: string;
36
- getSpecInfo: (chartSpec: any, chartSpecInfo?: IChartSpecInfo) => Maybe<IModelSpecInfo[]>;
36
+ getSpecInfo?: (chartSpec: any, chartSpecInfo?: IChartSpecInfo) => Maybe<IModelSpecInfo[]>;
37
37
  createComponent: (specInfo: IModelSpecInfo, options: IComponentOption) => IComponent;
38
38
  new (spec: any, options: IComponentOption): IComponent;
39
39
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/interface/common.ts"],"names":[],"mappings":"","file":"common.js","sourcesContent":["import type { ISeriesFilter } from '../../region/interface';\nimport type { IAnimate } from '../../animation/interface';\nimport type { ILayoutModel, IModelConstructor, IModelOption, IModelSpecInfo } from '../../model/interface';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IRegion } from '../../region/interface';\nimport type { ISeries } from '../../series/interface';\nimport type { Maybe, StringOrNumber } from '../../typings';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { IChartSpecInfo } from '../../chart/interface';\n/**\n * 组件作为图表辅助阅读等功能的模块,除了model提供的能力之外,还有以下功能特点\n * 支持对多region的绑定。\n * 能够在resize时正常的重新对内部元素布局。\n * 保持数据独立,模块间的依赖关系,能从数据上处理的应当从数据上处理。\n */\n\nexport interface IComponentOption extends IModelOption {\n // 区域\n getAllRegions: () => IRegion[];\n getRegionsInIndex: (index?: number[]) => IRegion[];\n getRegionsInIds: (ids: number[]) => IRegion[];\n getRegionsInUserIdOrIndex: (user_ids?: StringOrNumber[], index?: number[]) => IRegion[];\n // series\n getAllSeries: () => ISeries[];\n getSeriesInIndex: (index?: number[]) => ISeries[];\n getSeriesInIds: (ids?: number[]) => ISeries[];\n getSeriesInUserIdOrIndex: (user_ids?: StringOrNumber[], index?: number[]) => ISeries[];\n // component\n getAllComponents: () => IComponent[];\n getComponentByIndex: (key: string, index: number) => IComponent | undefined;\n getComponentByUserId: (userId: StringOrNumber) => IComponent | undefined;\n getComponentsByKey: (key: string) => IComponent[];\n getComponentsByType: (type: string) => IComponent[];\n}\n\nexport interface IComponent extends ILayoutModel {\n readonly name: string;\n readonly animate?: IAnimate;\n\n // 区域\n getRegions: () => IRegion[];\n getBindSeriesFilter?: () => ISeriesFilter;\n changeRegions: (regions: IRegion[]) => void;\n getVRenderComponents: () => IGraphic[];\n\n // 清空,用于更新等场景\n clear: () => void;\n}\n\nexport interface IComponentConstructor extends IModelConstructor {\n type: string;\n specKey?: string;\n getSpecInfo: (chartSpec: any, chartSpecInfo?: IChartSpecInfo) => Maybe<IModelSpecInfo[]>;\n createComponent: (specInfo: IModelSpecInfo, options: IComponentOption) => IComponent;\n new (spec: any, options: IComponentOption): IComponent;\n}\n"]}
1
+ {"version":3,"sources":["../src/component/interface/common.ts"],"names":[],"mappings":"","file":"common.js","sourcesContent":["import type { ISeriesFilter } from '../../region/interface';\nimport type { IAnimate } from '../../animation/interface';\nimport type { ILayoutModel, IModelConstructor, IModelOption, IModelSpecInfo } from '../../model/interface';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IRegion } from '../../region/interface';\nimport type { ISeries } from '../../series/interface';\nimport type { Maybe, StringOrNumber } from '../../typings';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { IChartSpecInfo } from '../../chart/interface';\n/**\n * 组件作为图表辅助阅读等功能的模块,除了model提供的能力之外,还有以下功能特点\n * 支持对多region的绑定。\n * 能够在resize时正常的重新对内部元素布局。\n * 保持数据独立,模块间的依赖关系,能从数据上处理的应当从数据上处理。\n */\n\nexport interface IComponentOption extends IModelOption {\n // 区域\n getAllRegions: () => IRegion[];\n getRegionsInIndex: (index?: number[]) => IRegion[];\n getRegionsInIds: (ids: number[]) => IRegion[];\n getRegionsInUserIdOrIndex: (user_ids?: StringOrNumber[], index?: number[]) => IRegion[];\n // series\n getAllSeries: () => ISeries[];\n getSeriesInIndex: (index?: number[]) => ISeries[];\n getSeriesInIds: (ids?: number[]) => ISeries[];\n getSeriesInUserIdOrIndex: (user_ids?: StringOrNumber[], index?: number[]) => ISeries[];\n // component\n getAllComponents: () => IComponent[];\n getComponentByIndex: (key: string, index: number) => IComponent | undefined;\n getComponentByUserId: (userId: StringOrNumber) => IComponent | undefined;\n getComponentsByKey: (key: string) => IComponent[];\n getComponentsByType: (type: string) => IComponent[];\n}\n\nexport interface IComponent extends ILayoutModel {\n readonly name: string;\n readonly animate?: IAnimate;\n\n // 区域\n getRegions: () => IRegion[];\n getBindSeriesFilter?: () => ISeriesFilter;\n changeRegions: (regions: IRegion[]) => void;\n getVRenderComponents: () => IGraphic[];\n\n // 清空,用于更新等场景\n clear: () => void;\n}\n\nexport interface IComponentConstructor extends IModelConstructor {\n type: string;\n specKey?: string;\n getSpecInfo?: (chartSpec: any, chartSpecInfo?: IChartSpecInfo) => Maybe<IModelSpecInfo[]>;\n createComponent: (specInfo: IModelSpecInfo, options: IComponentOption) => IComponent;\n new (spec: any, options: IComponentOption): IComponent;\n}\n"]}
@@ -6,7 +6,7 @@ import type { ISeries } from '../../series';
6
6
  export interface ILabelFormatMethodContext {
7
7
  series?: ISeries;
8
8
  }
9
- export interface ILabelSpec extends IComponentSpec {
9
+ export interface ILabelSpec extends IComponentSpec, ILabelAnimationSpec {
10
10
  visible?: boolean;
11
11
  interactive?: boolean;
12
12
  textType?: 'text' | 'rich';
@@ -18,7 +18,6 @@ export interface ILabelSpec extends IComponentSpec {
18
18
  state?: LabelStateStyle<Partial<IComposedTextMarkSpec>>;
19
19
  overlap?: BaseLabelAttrs['overlap'];
20
20
  smartInvert?: BaseLabelAttrs['smartInvert'];
21
- animation?: BaseLabelAttrs['animation'];
22
21
  stackDataFilterType?: 'min' | 'max';
23
22
  dataFilter?: BaseLabelAttrs['dataFilter'];
24
23
  customLayoutFunc?: BaseLabelAttrs['customLayoutFunc'];
@@ -27,6 +26,7 @@ export interface ILabelSpec extends IComponentSpec {
27
26
  support3d?: boolean;
28
27
  syncState?: boolean;
29
28
  }
29
+ export type ILabelAnimationSpec = Pick<BaseLabelAttrs, 'animation' | 'animationEnter' | 'animationUpdate' | 'animationExit'>;
30
30
  export type IMultiLabelSpec<T extends Omit<ILabelSpec, 'position'>> = T | T[];
31
31
  type LabelStateStyle<T> = {
32
32
  hover?: T;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/label/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { BaseLabelAttrs } from '@visactor/vrender-components';\nimport type { ConvertToMarkStyleSpec, Datum, IComposedTextMarkSpec, IFormatMethod, ITextMarkSpec } from '../../typings';\nimport type { IComponentSpec } from '../base/interface';\nimport type { ILabelMark } from '../../mark/label';\nimport type { ISeries } from '../../series';\n\nexport interface ILabelFormatMethodContext {\n series?: ISeries;\n}\n\nexport interface ILabelSpec extends IComponentSpec {\n /** 默认不显示标签 */\n visible?: boolean;\n /**\n * 是否支持交互。\n * @default false\n */\n interactive?: boolean;\n /**\n * 文本类型:text, rich,\n * @since 1.7.0\n * @deprecated\n */\n textType?: 'text' | 'rich';\n /**\n * 格式化函数\n * @since 1.10.0 支持返回结构 `{type:'rich', text: [{text:'some text', fill:'black', fontSize: 20}]}\n */\n formatMethod?: IFormatMethod<[text: string | string[], datum?: Datum, ctx?: ILabelFormatMethodContext]>;\n /**\n * 字符串模版\n * 用{}包裹变量名的字符串模版, 变量名取自数据属性值\n * eg: 'type={type},value={value}'\n * @since 1.7.0\n */\n formatter?: string | string[];\n /** 标签与其对应数据图元的间距 */\n offset?: number;\n /** 标签位置 */\n position?: string;\n /** 标签样式配置 */\n style?: ConvertToMarkStyleSpec<IComposedTextMarkSpec>;\n /** 交互样式配置 */\n state?: LabelStateStyle<Partial<IComposedTextMarkSpec>>;\n /** 标签防重叠配置 */\n overlap?: BaseLabelAttrs['overlap'];\n /** 标签智能反色配置 */\n smartInvert?: BaseLabelAttrs['smartInvert'];\n /** 动画配置 */\n animation?: BaseLabelAttrs['animation'];\n /**\n * 堆积数据过滤类型\n * @since 1.12.0\n */\n stackDataFilterType?: 'min' | 'max';\n /** 自定义标签数据筛选和排序\n * @since 1.3.0\n */\n dataFilter?: BaseLabelAttrs['dataFilter'];\n /** 自定义标签布局函数。\n * @description 当配置了 customLayoutFunc 后,默认布局和防重叠逻辑将不再生效。(overlap/position/offset不生效)\n * @since 1.3.0\n */\n customLayoutFunc?: BaseLabelAttrs['customLayoutFunc'];\n /** 自定义标签躲避函数\n * @description 当配置了 customOverlapFunc 后,会根据 position 和 offset 进行初始布局。配置的防重叠逻辑(overlap)不生效。\n * @since 1.3.0\n */\n customOverlapFunc?: BaseLabelAttrs['customOverlapFunc'];\n /** 标签布局 */\n labelLayout?: 'series' | 'region';\n /** 是否支持3D */\n support3d?: boolean;\n /**\n * 是否同步数据图元的状态变化\n * @default false\n * @since 1.9.0\n */\n syncState?: boolean;\n}\n\nexport type IMultiLabelSpec<T extends Omit<ILabelSpec, 'position'>> = T | T[];\n\ntype LabelStateStyle<T> = {\n hover?: T;\n hover_reverse?: T;\n selected?: T;\n selected_reverse?: T;\n};\n\nexport type ITotalLabelSpec = Pick<\n ILabelSpec,\n 'visible' | 'formatMethod' | 'interactive' | 'offset' | 'style' | 'state' | 'textType' | 'overlap'\n>;\n\nexport interface ITotalLabelTheme\n extends Pick<ILabelSpec, 'visible' | 'interactive' | 'offset' | 'overlap' | 'smartInvert' | 'animation'> {\n style?: ITextMarkSpec;\n}\n\n// 内部处理转换后的标签配置\nexport type TransformedLabelSpec = ILabelSpec & {\n getStyleHandler: (series: ISeries) => (mark?: ILabelMark, spec?: any) => void;\n};\n"]}
1
+ {"version":3,"sources":["../src/component/label/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { BaseLabelAttrs } from '@visactor/vrender-components';\nimport type { ConvertToMarkStyleSpec, Datum, IComposedTextMarkSpec, IFormatMethod, ITextMarkSpec } from '../../typings';\nimport type { IComponentSpec } from '../base/interface';\nimport type { ILabelMark } from '../../mark/label';\nimport type { ISeries } from '../../series';\n\nexport interface ILabelFormatMethodContext {\n series?: ISeries;\n}\n\nexport interface ILabelSpec extends IComponentSpec, ILabelAnimationSpec {\n /** 默认不显示标签 */\n visible?: boolean;\n /**\n * 是否支持交互。\n * @default false\n */\n interactive?: boolean;\n /**\n * 文本类型:text, rich,\n * @since 1.7.0\n * @deprecated\n */\n textType?: 'text' | 'rich';\n /**\n * 格式化函数\n * @since 1.10.0 支持返回结构 `{type:'rich', text: [{text:'some text', fill:'black', fontSize: 20}]}\n */\n formatMethod?: IFormatMethod<[text: string | string[], datum?: Datum, ctx?: ILabelFormatMethodContext]>;\n /**\n * 字符串模版\n * 用{}包裹变量名的字符串模版, 变量名取自数据属性值\n * eg: 'type={type},value={value}'\n * @since 1.7.0\n */\n formatter?: string | string[];\n /** 标签与其对应数据图元的间距 */\n offset?: number;\n /** 标签位置 */\n position?: string;\n /** 标签样式配置 */\n style?: ConvertToMarkStyleSpec<IComposedTextMarkSpec>;\n /** 交互样式配置 */\n state?: LabelStateStyle<Partial<IComposedTextMarkSpec>>;\n /** 标签防重叠配置 */\n overlap?: BaseLabelAttrs['overlap'];\n /** 标签智能反色配置 */\n smartInvert?: BaseLabelAttrs['smartInvert'];\n /**\n * 堆积数据过滤类型\n * @since 1.12.0\n */\n stackDataFilterType?: 'min' | 'max';\n /** 自定义标签数据筛选和排序\n * @since 1.3.0\n */\n dataFilter?: BaseLabelAttrs['dataFilter'];\n /** 自定义标签布局函数。\n * @description 当配置了 customLayoutFunc 后,默认布局和防重叠逻辑将不再生效。(overlap/position/offset不生效)\n * @since 1.3.0\n */\n customLayoutFunc?: BaseLabelAttrs['customLayoutFunc'];\n /** 自定义标签躲避函数\n * @description 当配置了 customOverlapFunc 后,会根据 position 和 offset 进行初始布局。配置的防重叠逻辑(overlap)不生效。\n * @since 1.3.0\n */\n customOverlapFunc?: BaseLabelAttrs['customOverlapFunc'];\n /** 标签布局 */\n labelLayout?: 'series' | 'region';\n /** 是否支持3D */\n support3d?: boolean;\n /**\n * 是否同步数据图元的状态变化\n * @default false\n * @since 1.9.0\n */\n syncState?: boolean;\n}\n\nexport type ILabelAnimationSpec = Pick<\n BaseLabelAttrs,\n 'animation' | 'animationEnter' | 'animationUpdate' | 'animationExit'\n>;\nexport type IMultiLabelSpec<T extends Omit<ILabelSpec, 'position'>> = T | T[];\n\ntype LabelStateStyle<T> = {\n hover?: T;\n hover_reverse?: T;\n selected?: T;\n selected_reverse?: T;\n};\n\nexport type ITotalLabelSpec = Pick<\n ILabelSpec,\n 'visible' | 'formatMethod' | 'interactive' | 'offset' | 'style' | 'state' | 'textType' | 'overlap'\n>;\n\nexport interface ITotalLabelTheme\n extends Pick<ILabelSpec, 'visible' | 'interactive' | 'offset' | 'overlap' | 'smartInvert' | 'animation'> {\n style?: ITextMarkSpec;\n}\n\n// 内部处理转换后的标签配置\nexport type TransformedLabelSpec = ILabelSpec & {\n getStyleHandler: (series: ISeries) => (mark?: ILabelMark, spec?: any) => void;\n};\n"]}
@@ -4,27 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.registerContinuousLegend = exports.ContinuousLegend = void 0;
6
6
 
7
- const vutils_1 = require("@visactor/vutils"), vdataset_1 = require("@visactor/vdataset"), type_1 = require("../../interface/type"), register_1 = require("../../../data/register"), model_1 = require("../../../util/model"), data_1 = require("../../../util/data"), type_2 = require("../../../util/type"), continuous_1 = require("../../../data/transforms/legend-data/continuous/continuous"), util_1 = require("./util"), base_legend_1 = require("../base-legend"), event_1 = require("../../../constant/event"), factory_1 = require("../../../core/factory"), initialize_1 = require("../../../data/initialize"), SINGLE_SEQUENCE = [ "#C4E7FF", "#98CAFF", "#75ACFF", "#518FF9", "#2775DC", "#005CBE", "#00429F", "#00287E" ], SIZE = [ 2, 10 ];
7
+ const vutils_1 = require("@visactor/vutils"), vdataset_1 = require("@visactor/vdataset"), type_1 = require("../../interface/type"), register_1 = require("../../../data/register"), model_1 = require("../../../util/model"), data_1 = require("../../../util/data"), type_2 = require("../../../util/type"), continuous_1 = require("../../../data/transforms/legend-data/continuous/continuous"), util_1 = require("./util"), base_legend_1 = require("../base-legend"), event_1 = require("../../../constant/event"), factory_1 = require("../../../core/factory"), initialize_1 = require("../../../data/initialize"), util_2 = require("../../util"), SINGLE_SEQUENCE = [ "#C4E7FF", "#98CAFF", "#75ACFF", "#518FF9", "#2775DC", "#005CBE", "#00429F", "#00287E" ], SIZE = [ 2, 10 ];
8
8
 
9
9
  class ContinuousLegend extends base_legend_1.BaseLegend {
10
10
  static getSpecInfo(chartSpec) {
11
- const legendSpec = chartSpec[this.specKey];
12
- if (!legendSpec) return;
13
- if (!(0, vutils_1.isArray)(legendSpec)) return (0, util_1.isContinuousLegend)(legendSpec.type) ? [ {
14
- spec: legendSpec,
15
- specPath: [ this.specKey ],
16
- specInfoPath: [ "component", this.specKey, 0 ],
17
- type: "color" === legendSpec.type ? type_1.ComponentTypeEnum.colorLegend : type_1.ComponentTypeEnum.sizeLegend
18
- } ] : void 0;
19
- const specInfos = [];
20
- return legendSpec.forEach(((s, i) => {
21
- (0, util_1.isContinuousLegend)(s.type) && specInfos.push({
22
- spec: s,
23
- specPath: [ this.specKey, i ],
24
- specInfoPath: [ "component", this.specKey, i ],
25
- type: "color" === s.type ? type_1.ComponentTypeEnum.colorLegend : type_1.ComponentTypeEnum.sizeLegend
26
- });
27
- })), specInfos;
11
+ const infos = (0, util_2.getSpecInfo)(chartSpec, this.specKey, this.type, (s => (0,
12
+ util_1.isContinuousLegend)(s.type)));
13
+ return infos && infos.forEach((info => {
14
+ info.type = "color" === info.spec.type ? type_1.ComponentTypeEnum.colorLegend : type_1.ComponentTypeEnum.sizeLegend;
15
+ })), infos;
28
16
  }
29
17
  constructor(spec, options) {
30
18
  super(spec, options), this.type = type_1.ComponentTypeEnum.colorLegend, this.name = type_1.ComponentTypeEnum.colorLegend;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/legend/continuous/legend.ts"],"names":[],"mappings":";;;AAKA,6CAA0E;AAC1E,iDAA8C;AAK9C,+CAAyD;AAEzD,qDAA0E;AAC1E,+CAA4D;AAC5D,6CAAmD;AACnD,6CAAsD;AAEtD,2FAGoE;AACpE,iCAAgG;AAChG,gDAA4C;AAC5C,mDAAqD;AACrD,mDAAgD;AAChD,yDAA0D;AAG1D,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AACjH,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAErB,MAAa,gBAEX,SAAQ,wBAAa;IAUrB,MAAM,CAAC,WAAW,CA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EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAC3F,CAAC,EAAE,EAAE,CAAC,CACP,CAAC;SACH;IACH,CAAC;;AA5MH,4CA6MC;AA1MQ,wBAAO,GAAG,SAAS,CAAC;AAEpB,qBAAI,GAAG,wBAAiB,CAAC,gBAAgB,CAAC;AA0M5C,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,iBAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;AACrE,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC","file":"legend.js","sourcesContent":["/**\n * @description color legend component\n */\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { debounce, isEmpty, isNil, isArray, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\nimport type { IComponentOption } from '../../interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries, getSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\nimport type { IColorLegendSpec, ISizeLegendSpec } from './interface';\nimport {\n continuousLegendDataMake,\n continuousLegendFilter\n} from '../../../data/transforms/legend-data/continuous/continuous';\nimport { ContinuousLegendMap, getContinuousLegendAttributes, isContinuousLegend } from './util';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\n\nconst SINGLE_SEQUENCE = ['#C4E7FF', '#98CAFF', '#75ACFF', '#518FF9', '#2775DC', '#005CBE', '#00429F', '#00287E'];\nconst SIZE = [2, 10];\n\nexport class ContinuousLegend<\n T extends IColorLegendSpec | ISizeLegendSpec = IColorLegendSpec | ISizeLegendSpec\n> extends BaseLegend<T> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.continuousLegend;\n type = ComponentTypeEnum.colorLegend;\n name: string = ComponentTypeEnum.colorLegend;\n\n private _field: string | undefined;\n private _legendType: string;\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n const legendSpec = chartSpec[this.specKey];\n if (!legendSpec) {\n return undefined;\n }\n if (!isArray(legendSpec)) {\n if (isContinuousLegend(legendSpec.type)) {\n return [\n {\n spec: legendSpec,\n specPath: [this.specKey],\n specInfoPath: ['component', this.specKey, 0],\n type: legendSpec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend\n }\n ];\n }\n return undefined;\n }\n const specInfos: IModelSpecInfo[] = [];\n legendSpec.forEach((s: IColorLegendSpec | ISizeLegendSpec, i: number) => {\n if (isContinuousLegend(s.type)) {\n specInfos.push({\n spec: s,\n specPath: [this.specKey, i],\n specInfoPath: ['component', this.specKey, i],\n type: s.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend\n });\n }\n });\n return specInfos;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n\n // 这里需要区分下是 colorLegend 还是 sizeLegend\n const legendName = this._spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n this.type = legendName;\n this.name = legendName;\n }\n\n setAttrFromSpec() {\n super.setAttrFromSpec();\n this._field = this._spec.field;\n this._legendType = this._spec.type;\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'continuousLegendFilter',\n options: {\n selected: () => this._selectedData,\n field: () => this._field,\n data: () => this._legendData.getLatestData(),\n isHierarchyData: s.isHierarchyData\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n private _getScaleInGlobal() {\n const globalScale = this._option.globalScale;\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n return globalScale.getScale(scaleKey);\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendFilter', continuousLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendDataMake', continuousLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'continuousLegendDataMake',\n options: {\n series: () => {\n return getSeries(this._regions, {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n });\n },\n field: () => this._field,\n scale: this._getScaleInGlobal.bind(this)\n }\n });\n return legendData;\n }\n\n protected _initSelectedData(): void {\n if (this._spec.defaultSelected) {\n this._selectedData = this._spec.defaultSelected.slice();\n } else {\n this._selectedData = this._legendData.getLatestData();\n }\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n const field = this._field;\n if (field) {\n // 默认使用第0个系列的对应别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), field);\n return;\n }\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(scaleKey);\n if (!isDataDomainSpec(scaleSpec?.domain)) {\n return;\n }\n const dataInfo = scaleSpec.domain[0];\n if (dataInfo.fields.length === 0) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(this._option.dataSet.getDataView(dataInfo.dataId), dataInfo.fields[0]);\n return;\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const align = layout === 'horizontal' ? 'bottom' : this.layoutOrient;\n\n // 获取关联的 scale 以获取 colors / size\n let visualMappingRange = [];\n const scale = this._getScaleInGlobal();\n if (scale && scale.type === 'linear') {\n visualMappingRange = scale.range();\n }\n if (isEmpty(visualMappingRange)) {\n visualMappingRange = this._legendType === 'color' ? SINGLE_SEQUENCE : SIZE;\n }\n let min = this._legendData.getLatestData()[0] ?? 0;\n let max = this._legendData.getLatestData()[1] ?? 1;\n\n const isSame = this._legendData.getLatestData()[0] === this._legendData.getLatestData()[1];\n if (isSame) {\n min = Math.min(0, this._legendData.getLatestData()[0]);\n max = this._legendData.getLatestData()[0] === 0 ? 1 : Math.max(0, this._legendData.getLatestData()[0]);\n }\n\n const attrs: any = {\n layout,\n align,\n zIndex: this.layoutZIndex,\n min,\n max,\n value: this._spec.defaultSelected,\n [this._legendType === 'color' ? 'colors' : 'sizeRange']: visualMappingRange,\n ...getContinuousLegendAttributes(this._spec)\n };\n this._addDefaultTitleText(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return ContinuousLegendMap[this._legendType];\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(\n 'change',\n debounce((e: any) => {\n const selectedData = get(e, 'detail.value');\n if (doFilter) {\n this.setSelectedData(selectedData);\n }\n this.event.emit(ChartEvent.legendFilter, { model: this, value: selectedData, event: e });\n }, 30)\n );\n }\n }\n}\n\nexport const registerContinuousLegend = () => {\n Factory.registerComponent(ContinuousLegend.type, ContinuousLegend);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/legend/continuous/legend.ts"],"names":[],"mappings":";;;AAKA,6CAAiE;AACjE,iDAA8C;AAK9C,+CAAyD;AAEzD,qDAA0E;AAC1E,+CAA4D;AAC5D,6CAAmD;AACnD,6CAAsD;AAEtD,2FAGoE;AACpE,iCAAgG;AAChG,gDAA4C;AAC5C,mDAAqD;AACrD,m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CAAC,CAAC;AACrE,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC","file":"legend.js","sourcesContent":["/**\n * @description color legend component\n */\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { debounce, isEmpty, isNil, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\nimport type { IComponentOption } from '../../interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries, getSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\nimport type { IColorLegendSpec, ISizeLegendSpec } from './interface';\nimport {\n continuousLegendDataMake,\n continuousLegendFilter\n} from '../../../data/transforms/legend-data/continuous/continuous';\nimport { ContinuousLegendMap, getContinuousLegendAttributes, isContinuousLegend } from './util';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport { getSpecInfo } from '../../util';\n\nconst SINGLE_SEQUENCE = ['#C4E7FF', '#98CAFF', '#75ACFF', '#518FF9', '#2775DC', '#005CBE', '#00429F', '#00287E'];\nconst SIZE = [2, 10];\n\nexport class ContinuousLegend<\n T extends IColorLegendSpec | ISizeLegendSpec = IColorLegendSpec | ISizeLegendSpec\n> extends BaseLegend<T> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.continuousLegend;\n type = ComponentTypeEnum.colorLegend;\n name: string = ComponentTypeEnum.colorLegend;\n\n private _field: string | undefined;\n private _legendType: string;\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n const infos = getSpecInfo<IColorLegendSpec | ISizeLegendSpec>(\n chartSpec,\n this.specKey,\n this.type,\n (s: IColorLegendSpec | ISizeLegendSpec) => {\n return isContinuousLegend(s.type);\n }\n );\n\n if (infos) {\n infos.forEach(info => {\n info.type = info.spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n });\n }\n\n return infos;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n\n // 这里需要区分下是 colorLegend 还是 sizeLegend\n const legendName = this._spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n this.type = legendName;\n this.name = legendName;\n }\n\n setAttrFromSpec() {\n super.setAttrFromSpec();\n this._field = this._spec.field;\n this._legendType = this._spec.type;\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'continuousLegendFilter',\n options: {\n selected: () => this._selectedData,\n field: () => this._field,\n data: () => this._legendData.getLatestData(),\n isHierarchyData: s.isHierarchyData\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n private _getScaleInGlobal() {\n const globalScale = this._option.globalScale;\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n return globalScale.getScale(scaleKey);\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendFilter', continuousLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendDataMake', continuousLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'continuousLegendDataMake',\n options: {\n series: () => {\n return getSeries(this._regions, {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n });\n },\n field: () => this._field,\n scale: this._getScaleInGlobal.bind(this)\n }\n });\n return legendData;\n }\n\n protected _initSelectedData(): void {\n if (this._spec.defaultSelected) {\n this._selectedData = this._spec.defaultSelected.slice();\n } else {\n this._selectedData = this._legendData.getLatestData();\n }\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n const field = this._field;\n if (field) {\n // 默认使用第0个系列的对应别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), field);\n return;\n }\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(scaleKey);\n if (!isDataDomainSpec(scaleSpec?.domain)) {\n return;\n }\n const dataInfo = scaleSpec.domain[0];\n if (dataInfo.fields.length === 0) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(this._option.dataSet.getDataView(dataInfo.dataId), dataInfo.fields[0]);\n return;\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const align = layout === 'horizontal' ? 'bottom' : this.layoutOrient;\n\n // 获取关联的 scale 以获取 colors / size\n let visualMappingRange = [];\n const scale = this._getScaleInGlobal();\n if (scale && scale.type === 'linear') {\n visualMappingRange = scale.range();\n }\n if (isEmpty(visualMappingRange)) {\n visualMappingRange = this._legendType === 'color' ? SINGLE_SEQUENCE : SIZE;\n }\n let min = this._legendData.getLatestData()[0] ?? 0;\n let max = this._legendData.getLatestData()[1] ?? 1;\n\n const isSame = this._legendData.getLatestData()[0] === this._legendData.getLatestData()[1];\n if (isSame) {\n min = Math.min(0, this._legendData.getLatestData()[0]);\n max = this._legendData.getLatestData()[0] === 0 ? 1 : Math.max(0, this._legendData.getLatestData()[0]);\n }\n\n const attrs: any = {\n layout,\n align,\n zIndex: this.layoutZIndex,\n min,\n max,\n value: this._spec.defaultSelected,\n [this._legendType === 'color' ? 'colors' : 'sizeRange']: visualMappingRange,\n ...getContinuousLegendAttributes(this._spec)\n };\n this._addDefaultTitleText(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return ContinuousLegendMap[this._legendType];\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(\n 'change',\n debounce((e: any) => {\n const selectedData = get(e, 'detail.value');\n if (doFilter) {\n this.setSelectedData(selectedData);\n }\n this.event.emit(ChartEvent.legendFilter, { model: this, value: selectedData, event: e });\n }, 30)\n );\n }\n }\n}\n\nexport const registerContinuousLegend = () => {\n Factory.registerComponent(ContinuousLegend.type, ContinuousLegend);\n};\n"]}
@@ -11,23 +11,7 @@ class DiscreteLegend extends base_legend_1.BaseLegend {
11
11
  super(...arguments), this.type = type_1.ComponentTypeEnum.discreteLegend, this.name = type_1.ComponentTypeEnum.discreteLegend;
12
12
  }
13
13
  static getSpecInfo(chartSpec) {
14
- const legendSpec = chartSpec[this.specKey];
15
- if (!legendSpec) return;
16
- if (!(0, vutils_1.isArray)(legendSpec)) return legendSpec.type && "discrete" !== legendSpec.type ? void 0 : [ {
17
- spec: legendSpec,
18
- specPath: [ this.specKey ],
19
- specInfoPath: [ "component", this.specKey, 0 ],
20
- type: type_1.ComponentTypeEnum.discreteLegend
21
- } ];
22
- const specInfos = [];
23
- return legendSpec.forEach(((s, i) => {
24
- s.type && "discrete" !== s.type || specInfos.push({
25
- spec: s,
26
- specPath: [ this.specKey, i ],
27
- specInfoPath: [ "component", this.specKey, i ],
28
- type: type_1.ComponentTypeEnum.discreteLegend
29
- });
30
- })), specInfos;
14
+ return (0, util_2.getSpecInfo)(chartSpec, this.specKey, this.type, (s => !s.type || "discrete" === s.type));
31
15
  }
32
16
  init(option) {
33
17
  super.init(option), (0, model_1.eachSeries)(this._regions, (s => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/legend/discrete/legend.ts"],"names":[],"mappings":";;;AAEA,6CAAkF;AAClF,iDAA8C;AAM9C,+CAAyD;AA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, isValidNumber, isArray, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\nimport type { IDiscreteLegendSpec } from './interface';\n// eslint-disable-next-line no-duplicate-imports\nimport type { ISeries } from '../../../series/interface';\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { getLegendAttributes } from './util';\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\n// eslint-disable-next-line no-duplicate-imports\nimport type { LegendItemDatum } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { LegendEvent } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DiscreteLegend as LegendComponent } from '@visactor/vrender-components';\nimport { discreteLegendDataMake, discreteLegendFilter } from '../../../data/transforms/legend-data/discrete/discrete';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport type { StringOrNumber } from '../../../typings';\nimport { getFormatFunction } from '../../util';\nimport type { IDiscreteLegendData } from '../../../data/transforms/legend-data/discrete';\n\nexport class DiscreteLegend extends BaseLegend<IDiscreteLegendSpec> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.discreteLegend;\n type = ComponentTypeEnum.discreteLegend;\n name: string = ComponentTypeEnum.discreteLegend;\n\n protected _unselectedData: StringOrNumber[];\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n const legendSpec = chartSpec[this.specKey];\n if (!legendSpec) {\n return undefined;\n }\n if (!isArray(legendSpec)) {\n if (!legendSpec.type || legendSpec.type === 'discrete') {\n return [\n {\n spec: legendSpec,\n specPath: [this.specKey],\n specInfoPath: ['component', this.specKey, 0],\n type: ComponentTypeEnum.discreteLegend\n }\n ];\n }\n return undefined;\n }\n const specInfos: IModelSpecInfo[] = [];\n legendSpec.forEach((s: IDiscreteLegendSpec, i: number) => {\n if (!s.type || s.type === 'discrete') {\n specInfos.push({\n spec: s,\n specPath: [this.specKey, i],\n specInfoPath: ['component', this.specKey, i],\n type: ComponentTypeEnum.discreteLegend\n });\n }\n });\n return specInfos;\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'discreteLegendFilter',\n options: {\n series: s,\n selected: () => this._selectedData,\n field: () => this._getSeriesLegendField(s),\n data: () => this.getLegendDefaultData()\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'discreteLegendFilter', discreteLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'discreteLegendDataMake', discreteLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'discreteLegendDataMake',\n options: {\n series: () => {\n const result: ISeries[] = [];\n eachSeries(\n this._regions,\n s => {\n result.push(s);\n },\n {\n specIndex: this._spec.seriesIndex,\n userId: this._spec.seriesId\n }\n );\n return result;\n },\n seriesField: (s: ISeries) => this._getSeriesLegendField(s)\n }\n });\n\n return legendData;\n }\n\n protected _getSeriesLegendField(s: ISeries) {\n const defaultField = s.getSeriesField();\n const specifyScaleId = this._spec.scaleName ?? this._spec.scale;\n\n if (isNil(specifyScaleId)) {\n return defaultField;\n }\n if (!s.getRawData()) {\n return defaultField;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(specifyScaleId);\n if (!scaleSpec) {\n return defaultField;\n }\n\n // field是只在图例指定了scale的情况下生效\n if (this._spec.field) {\n return this._spec.field;\n }\n\n if (!isDataDomainSpec(scaleSpec.domain)) {\n return defaultField;\n }\n const seriesData = scaleSpec.domain.find(d => d.dataId === s.getRawData().name);\n if (!seriesData) {\n return defaultField;\n }\n return seriesData.fields?.[0] ?? defaultField;\n }\n\n protected _initSelectedData(): void {\n const fullSelectedData = this.getLegendDefaultData();\n\n if (this._unselectedData) {\n const selected: StringOrNumber[] = [];\n const unselected: StringOrNumber[] = [];\n\n fullSelectedData.forEach((entry: StringOrNumber) => {\n if (this._unselectedData.includes(entry)) {\n unselected.push(entry);\n } else {\n selected.push(entry);\n }\n });\n this._selectedData = selected;\n this._unselectedData = unselected;\n } else if (this._spec.defaultSelected) {\n this._selectedData = [...this._spec.defaultSelected];\n } else {\n this._selectedData = fullSelectedData;\n }\n }\n\n getLegendDefaultData(originalData?: boolean) {\n if (isFunction(this._spec.data)) {\n return this._getLegendItems().map((obj: LegendItemDatum) => obj.label);\n }\n\n return this._legendData\n .getLatestData()\n .map(originalData ? (obj: IDiscreteLegendData) => obj.originalKey : (obj: IDiscreteLegendData) => obj.key);\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n // 默认使用第0个系列的 seriesField 别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), series.getSeriesField());\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const attrs = {\n layout,\n items: this._getLegendItems(),\n zIndex: this.layoutZIndex,\n ...getLegendAttributes(this._spec, rect),\n // maxWidth 和 maxHeight 已经在布局模块处理了,所以 rect 的优先级最高\n maxWidth: rect.width,\n maxHeight: rect.height\n };\n this._addDefaultTitleText(attrs);\n this._addLegendItemFormatMethods(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return LegendComponent;\n }\n\n setSelectedData(selectedData: StringOrNumber[]) {\n if (selectedData) {\n this._unselectedData = this.getLegendDefaultData().filter(\n (entry: StringOrNumber) => !selectedData.includes(entry)\n );\n }\n\n super.setSelectedData(selectedData);\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(LegendEvent.legendItemClick, (e: any) => {\n const selectedData = get(e, 'detail.currentSelected');\n doFilter && this.setSelectedData(selectedData);\n this.event.emit(ChartEvent.legendItemClick, { model: this, value: selectedData, event: e });\n });\n\n this._legendComponent.addEventListener(LegendEvent.legendItemHover, (e: any) => {\n const detail = get(e, 'detail');\n this.event.emit(ChartEvent.legendItemHover, { model: this, value: detail, event: e });\n });\n\n this._legendComponent.addEventListener(LegendEvent.legendItemUnHover, (e: any) => {\n const detail = get(e, 'detail');\n this.event.emit(ChartEvent.legendItemUnHover, { model: this, value: detail, event: e });\n });\n }\n }\n\n private _getLegendItems() {\n const originData = (this._legendData.getLatestData() || []).map((datum: any) => {\n const fillOpacity = datum.style('fillOpacity');\n const strokeOpacity = datum.style('strokeOpacity');\n const opacity = datum.style('opacity');\n const texture = datum.style('texture');\n\n return {\n label: datum.key,\n shape: {\n symbolType: datum.style('symbolType') ?? datum.shapeType ?? 'circle',\n fillOpacity: isValidNumber(fillOpacity) ? fillOpacity : 1,\n strokeOpacity: isValidNumber(strokeOpacity) ? strokeOpacity : 1,\n opacity: isValidNumber(opacity) ? opacity : 1,\n texturePadding: texture ? 1 : null,\n textureSize: texture ? 4 : null,\n texture,\n fill: datum.style('fill'),\n stroke: datum.style('stroke'),\n textureColor: datum.style('textureColor'),\n innerBorder: datum.style('innerBorder'),\n outerBorder: datum.style('outerBorder'),\n lineDash: datum.style('lineDash'),\n lineDashOffset: datum.style('lineDashOffset'),\n lineWidth: datum.style('lineWidth')\n }\n };\n });\n const legendItems = isFunction(this._spec.data)\n ? this._spec.data(originData, this._option.globalScale.getScale('color'), this._option.globalScale)\n : originData;\n return legendItems;\n }\n\n private _addLegendItemFormatMethods(attrs: any) {\n const { formatMethod: labelFormatMethod, formatter: labelFormatter } = this._spec.item?.label ?? {};\n const { formatMethod: valueFormatMethod, formatter: valueFormatter } = this._spec.item?.value ?? {};\n\n const { formatFunc: labelFormatFunc } = getFormatFunction(labelFormatMethod, labelFormatter);\n if (labelFormatter && !labelFormatMethod && labelFormatFunc) {\n attrs.item.label.formatMethod = (value: string, datum: any) => {\n return labelFormatFunc(value, datum, labelFormatter);\n };\n }\n const { formatFunc: valueFormatFunc } = getFormatFunction(valueFormatMethod, valueFormatter);\n if (valueFormatter && !valueFormatMethod && valueFormatFunc) {\n attrs.item.value.formatMethod = (value: string, datum: any) => {\n return valueFormatFunc(valueFormatter, value, datum, labelFormatter);\n };\n }\n }\n}\n\nexport const registerDiscreteLegend = () => {\n Factory.registerComponent(DiscreteLegend.type, DiscreteLegend);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/legend/discrete/legend.ts"],"names":[],"mappings":";;;AAEA,6CAAyE;AACzE,iDAA8C;AAM9C,+CAAyD;AAEzD,iCAA6C;AAC7C,qDAA0E;AAC1E,+CAAiD;AACjD,6CAAmD;AACnD,6CAAsD;AAItD,qEAA2D;AAE3D,qEAAiF;AACjF,qFAAsH;AACtH,gDAA4C;AAC5C,mDAAqD;AACrD,mDAAgD;AAChD,yDAA0D;AAG1D,qCAA4D;AAG5D,MAAa,cAAe,SAAQ,wBAA+B;IAAnE;;QAIE,SAAI,GAAG,wBAAiB,CAAC,cAAc,CAAC;QACxC,SAAI,GAAW,wBAAiB,CAAC,cAAc,CAAC;IA8OlD,CAAC;IA1OC,MAAM,CAAC,WAAW,CAAC,SAAc;QAC/B,OAAO,IAAA,kBAAW,EAAsB,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAsB,EAAE,EAAE;YACrG,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;QAC1C,CAAC,CAAC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AI,0CAAE,KAAK,mCAAI,EAAE,CAAC;QAEpG,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,IAAA,wBAAiB,EAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAC7F,IAAI,cAAc,IAAI,CAAC,iBAAiB,IAAI,eAAe,EAAE;YAC3D,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,KAAa,EAAE,KAAU,EAAE,EAAE;gBAC5D,OAAO,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;YACvD,CAAC,CAAC;SACH;QACD,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,IAAA,wBAAiB,EAAC,iBAAiB,EAAE,cAAc,CAAC,CAAC;QAC7F,IAAI,cAAc,IAAI,CAAC,iBAAiB,IAAI,eAAe,EAAE;YAC3D,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,KAAa,EAAE,KAAU,EAAE,EAAE;gBAC5D,OAAO,eAAe,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;YACvE,CAAC,CAAC;SACH;IACH,CAAC;;AAlPH,wCAmPC;AAlPQ,sBAAO,GAAG,SAAS,CAAC;AAEpB,mBAAI,GAAG,wBAAiB,CAAC,cAAc,CAAC;AAkP1C,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,iBAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AACjE,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","file":"legend.js","sourcesContent":["import type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isFunction, isNil, isValidNumber, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\nimport type { IDiscreteLegendSpec } from './interface';\n// eslint-disable-next-line no-duplicate-imports\nimport type { ISeries } from '../../../series/interface';\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { getLegendAttributes } from './util';\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\n// eslint-disable-next-line no-duplicate-imports\nimport type { LegendItemDatum } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { LegendEvent } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DiscreteLegend as LegendComponent } from '@visactor/vrender-components';\nimport { discreteLegendDataMake, discreteLegendFilter } from '../../../data/transforms/legend-data/discrete/discrete';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport type { StringOrNumber } from '../../../typings';\nimport { getFormatFunction, getSpecInfo } from '../../util';\nimport type { IDiscreteLegendData } from '../../../data/transforms/legend-data/discrete';\n\nexport class DiscreteLegend extends BaseLegend<IDiscreteLegendSpec> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.discreteLegend;\n type = ComponentTypeEnum.discreteLegend;\n name: string = ComponentTypeEnum.discreteLegend;\n\n protected _unselectedData: StringOrNumber[];\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n return getSpecInfo<IDiscreteLegendSpec>(chartSpec, this.specKey, this.type, (s: IDiscreteLegendSpec) => {\n return !s.type || s.type === 'discrete';\n });\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'discreteLegendFilter',\n options: {\n series: s,\n selected: () => this._selectedData,\n field: () => this._getSeriesLegendField(s),\n data: () => this.getLegendDefaultData()\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'discreteLegendFilter', discreteLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'discreteLegendDataMake', discreteLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'discreteLegendDataMake',\n options: {\n series: () => {\n const result: ISeries[] = [];\n eachSeries(\n this._regions,\n s => {\n result.push(s);\n },\n {\n specIndex: this._spec.seriesIndex,\n userId: this._spec.seriesId\n }\n );\n return result;\n },\n seriesField: (s: ISeries) => this._getSeriesLegendField(s)\n }\n });\n\n return legendData;\n }\n\n protected _getSeriesLegendField(s: ISeries) {\n const defaultField = s.getSeriesField();\n const specifyScaleId = this._spec.scaleName ?? this._spec.scale;\n\n if (isNil(specifyScaleId)) {\n return defaultField;\n }\n if (!s.getRawData()) {\n return defaultField;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(specifyScaleId);\n if (!scaleSpec) {\n return defaultField;\n }\n\n // field是只在图例指定了scale的情况下生效\n if (this._spec.field) {\n return this._spec.field;\n }\n\n if (!isDataDomainSpec(scaleSpec.domain)) {\n return defaultField;\n }\n const seriesData = scaleSpec.domain.find(d => d.dataId === s.getRawData().name);\n if (!seriesData) {\n return defaultField;\n }\n return seriesData.fields?.[0] ?? defaultField;\n }\n\n protected _initSelectedData(): void {\n const fullSelectedData = this.getLegendDefaultData();\n\n if (this._unselectedData) {\n const selected: StringOrNumber[] = [];\n const unselected: StringOrNumber[] = [];\n\n fullSelectedData.forEach((entry: StringOrNumber) => {\n if (this._unselectedData.includes(entry)) {\n unselected.push(entry);\n } else {\n selected.push(entry);\n }\n });\n this._selectedData = selected;\n this._unselectedData = unselected;\n } else if (this._spec.defaultSelected) {\n this._selectedData = [...this._spec.defaultSelected];\n } else {\n this._selectedData = fullSelectedData;\n }\n }\n\n getLegendDefaultData(originalData?: boolean) {\n if (isFunction(this._spec.data)) {\n return this._getLegendItems().map((obj: LegendItemDatum) => obj.label);\n }\n\n return this._legendData\n .getLatestData()\n .map(originalData ? (obj: IDiscreteLegendData) => obj.originalKey : (obj: IDiscreteLegendData) => obj.key);\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n // 默认使用第0个系列的 seriesField 别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), series.getSeriesField());\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const attrs = {\n layout,\n items: this._getLegendItems(),\n zIndex: this.layoutZIndex,\n ...getLegendAttributes(this._spec, rect),\n // maxWidth 和 maxHeight 已经在布局模块处理了,所以 rect 的优先级最高\n maxWidth: rect.width,\n maxHeight: rect.height\n };\n this._addDefaultTitleText(attrs);\n this._addLegendItemFormatMethods(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return LegendComponent;\n }\n\n setSelectedData(selectedData: StringOrNumber[]) {\n if (selectedData) {\n this._unselectedData = this.getLegendDefaultData().filter(\n (entry: StringOrNumber) => !selectedData.includes(entry)\n );\n }\n\n super.setSelectedData(selectedData);\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(LegendEvent.legendItemClick, (e: any) => {\n const selectedData = get(e, 'detail.currentSelected');\n doFilter && this.setSelectedData(selectedData);\n this.event.emit(ChartEvent.legendItemClick, { model: this, value: selectedData, event: e });\n });\n\n this._legendComponent.addEventListener(LegendEvent.legendItemHover, (e: any) => {\n const detail = get(e, 'detail');\n this.event.emit(ChartEvent.legendItemHover, { model: this, value: detail, event: e });\n });\n\n this._legendComponent.addEventListener(LegendEvent.legendItemUnHover, (e: any) => {\n const detail = get(e, 'detail');\n this.event.emit(ChartEvent.legendItemUnHover, { model: this, value: detail, event: e });\n });\n }\n }\n\n private _getLegendItems() {\n const originData = (this._legendData.getLatestData() || []).map((datum: any) => {\n const fillOpacity = datum.style('fillOpacity');\n const strokeOpacity = datum.style('strokeOpacity');\n const opacity = datum.style('opacity');\n const texture = datum.style('texture');\n\n return {\n label: datum.key,\n shape: {\n symbolType: datum.style('symbolType') ?? datum.shapeType ?? 'circle',\n fillOpacity: isValidNumber(fillOpacity) ? fillOpacity : 1,\n strokeOpacity: isValidNumber(strokeOpacity) ? strokeOpacity : 1,\n opacity: isValidNumber(opacity) ? opacity : 1,\n texturePadding: texture ? 1 : null,\n textureSize: texture ? 4 : null,\n texture,\n fill: datum.style('fill'),\n stroke: datum.style('stroke'),\n textureColor: datum.style('textureColor'),\n innerBorder: datum.style('innerBorder'),\n outerBorder: datum.style('outerBorder'),\n lineDash: datum.style('lineDash'),\n lineDashOffset: datum.style('lineDashOffset'),\n lineWidth: datum.style('lineWidth')\n }\n };\n });\n const legendItems = isFunction(this._spec.data)\n ? this._spec.data(originData, this._option.globalScale.getScale('color'), this._option.globalScale)\n : originData;\n return legendItems;\n }\n\n private _addLegendItemFormatMethods(attrs: any) {\n const { formatMethod: labelFormatMethod, formatter: labelFormatter } = this._spec.item?.label ?? {};\n const { formatMethod: valueFormatMethod, formatter: valueFormatter } = this._spec.item?.value ?? {};\n\n const { formatFunc: labelFormatFunc } = getFormatFunction(labelFormatMethod, labelFormatter);\n if (labelFormatter && !labelFormatMethod && labelFormatFunc) {\n attrs.item.label.formatMethod = (value: string, datum: any) => {\n return labelFormatFunc(value, datum, labelFormatter);\n };\n }\n const { formatFunc: valueFormatFunc } = getFormatFunction(valueFormatMethod, valueFormatter);\n if (valueFormatter && !valueFormatMethod && valueFormatFunc) {\n attrs.item.value.formatMethod = (value: string, datum: any) => {\n return valueFormatFunc(valueFormatter, value, datum, labelFormatter);\n };\n }\n }\n}\n\nexport const registerDiscreteLegend = () => {\n Factory.registerComponent(DiscreteLegend.type, DiscreteLegend);\n};\n"]}
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.registerMapLabel = exports.MapLabelComponent = void 0;
6
6
 
7
- const vdataset_1 = require("@visactor/vdataset"), base_component_1 = require("../base/base-component"), type_1 = require("../interface/type"), layout_1 = require("../../constant/layout"), layout_2 = require("./layout"), compilable_data_1 = require("../../compile/data/compilable-data"), space_1 = require("../../util/space"), vrender_components_1 = require("@visactor/vrender-components"), vrender_core_1 = require("@visactor/vrender-core"), style_1 = require("../../util/style"), vutils_1 = require("@visactor/vutils"), factory_1 = require("../../core/factory"), initialize_1 = require("../../data/initialize");
7
+ const vdataset_1 = require("@visactor/vdataset"), base_component_1 = require("../base/base-component"), type_1 = require("../interface/type"), layout_1 = require("../../constant/layout"), layout_2 = require("./layout"), compilable_data_1 = require("../../compile/data/compilable-data"), space_1 = require("../../util/space"), vrender_components_1 = require("@visactor/vrender-components"), vrender_core_1 = require("@visactor/vrender-core"), style_1 = require("../../util/style"), vutils_1 = require("@visactor/vutils"), factory_1 = require("../../core/factory"), initialize_1 = require("../../data/initialize"), util_1 = require("../util");
8
8
 
9
9
  class MapLabelComponent extends base_component_1.BaseComponent {
10
10
  constructor() {
@@ -13,13 +13,8 @@ class MapLabelComponent extends base_component_1.BaseComponent {
13
13
  this._activeDatum = [];
14
14
  }
15
15
  static getSpecInfo(chartSpec) {
16
- const labelSpec = chartSpec[this.specKey];
17
- return labelSpec && labelSpec.visible && !(0, vutils_1.isValid)(labelSpec.series) ? [ {
18
- spec: labelSpec,
19
- specPath: [ this.specKey ],
20
- specInfoPath: [ "component", this.specKey, 0 ],
21
- type: type_1.ComponentTypeEnum.mapLabel
22
- } ] : null;
16
+ return (0, util_1.getSpecInfo)(chartSpec, this.specKey, this.type, (s => s.visible && (0,
17
+ vutils_1.isValid)(s.seriesId)));
23
18
  }
24
19
  setAttrFromSpec() {
25
20
  var _a, _b, _c, _d;