@visactor/vseed 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/cjs/index.cjs +646 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/esm/builder/builder/buildSpec.d.ts +1 -2
  4. package/dist/esm/builder/builder/buildSpec.js.map +1 -1
  5. package/dist/esm/builder/builder/builder.d.ts +1116 -106
  6. package/dist/esm/builder/builder/builder.js +10 -0
  7. package/dist/esm/builder/builder/builder.js.map +1 -1
  8. package/dist/esm/builder/builder/prepare.d.ts +12 -0
  9. package/dist/esm/builder/builder/prepare.js +269 -0
  10. package/dist/esm/builder/builder/prepare.js.map +1 -0
  11. package/dist/esm/dataReshape/constant.d.ts +1 -0
  12. package/dist/esm/dataReshape/constant.js +2 -1
  13. package/dist/esm/dataReshape/constant.js.map +1 -1
  14. package/dist/esm/dataSelector/selector.d.ts +71 -2
  15. package/dist/esm/dataSelector/selector.js +96 -32
  16. package/dist/esm/dataSelector/selector.js.map +1 -1
  17. package/dist/esm/pipeline/advanced/chart/pipes/default/defaultMeasures.js +2 -1
  18. package/dist/esm/pipeline/advanced/chart/pipes/default/defaultMeasures.js.map +1 -1
  19. package/dist/esm/pipeline/advanced/table/pipes/default/defaultMeasures.js +2 -1
  20. package/dist/esm/pipeline/advanced/table/pipes/default/defaultMeasures.js.map +1 -1
  21. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationHorizontalLine.js +10 -4
  22. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationHorizontalLine.js.map +1 -1
  23. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationPointCommon.d.ts +8 -2
  24. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationPointCommon.js +27 -5
  25. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationPointCommon.js.map +1 -1
  26. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationPointOfDualAxis.js +8 -4
  27. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationPointOfDualAxis.js.map +1 -1
  28. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationVerticalLine.js +10 -4
  29. package/dist/esm/pipeline/spec/chart/pipes/annotation/annotationVerticalLine.js.map +1 -1
  30. package/dist/esm/pipeline/spec/chart/pipes/annotation/utils.d.ts +9 -1
  31. package/dist/esm/pipeline/spec/chart/pipes/annotation/utils.js +7 -1
  32. package/dist/esm/pipeline/spec/chart/pipes/annotation/utils.js.map +1 -1
  33. package/dist/esm/pipeline/spec/chart/pipes/markStyle/barStyle.js +3 -2
  34. package/dist/esm/pipeline/spec/chart/pipes/markStyle/barStyle.js.map +1 -1
  35. package/dist/esm/pipeline/spec/chart/pipes/markStyle/lineStyle.js +5 -2
  36. package/dist/esm/pipeline/spec/chart/pipes/markStyle/lineStyle.js.map +1 -1
  37. package/dist/esm/pipeline/spec/chart/pipes/markStyle/pointStyle.js +3 -2
  38. package/dist/esm/pipeline/spec/chart/pipes/markStyle/pointStyle.js.map +1 -1
  39. package/dist/esm/pipeline/spec/table/pipes/cellStyle/common.d.ts +4 -1
  40. package/dist/esm/pipeline/spec/table/pipes/cellStyle/common.js +12 -1
  41. package/dist/esm/pipeline/spec/table/pipes/cellStyle/common.js.map +1 -1
  42. package/dist/esm/pipeline/spec/table/pipes/cellStyle/pivot.js +6 -3
  43. package/dist/esm/pipeline/spec/table/pipes/cellStyle/pivot.js.map +1 -1
  44. package/dist/esm/pipeline/spec/table/pipes/cellStyle/table.js +7 -3
  45. package/dist/esm/pipeline/spec/table/pipes/cellStyle/table.js.map +1 -1
  46. package/dist/esm/pipeline/utils/index.d.ts +1 -0
  47. package/dist/esm/pipeline/utils/index.js +1 -0
  48. package/dist/esm/pipeline/utils/sandbox/builtin-utils.d.ts +6 -0
  49. package/dist/esm/pipeline/utils/sandbox/builtin-utils.js +337 -0
  50. package/dist/esm/pipeline/utils/sandbox/builtin-utils.js.map +1 -0
  51. package/dist/esm/pipeline/utils/sandbox/execute.d.ts +73 -0
  52. package/dist/esm/pipeline/utils/sandbox/execute.js +716 -0
  53. package/dist/esm/pipeline/utils/sandbox/execute.js.map +1 -0
  54. package/dist/esm/pipeline/utils/sandbox/index.d.ts +7 -0
  55. package/dist/esm/pipeline/utils/sandbox/index.js +3 -0
  56. package/dist/esm/types/builder/builder.d.ts +1 -0
  57. package/dist/esm/types/builder/builder.js.map +1 -1
  58. package/dist/esm/types/chartType/area/zArea.d.ts +682 -18
  59. package/dist/esm/types/chartType/areaPercent/zAreaPercent.d.ts +682 -18
  60. package/dist/esm/types/chartType/bar/zBar.d.ts +362 -10
  61. package/dist/esm/types/chartType/barParallel/zBarParallel.d.ts +362 -10
  62. package/dist/esm/types/chartType/barPercent/zBarPercent.d.ts +362 -10
  63. package/dist/esm/types/chartType/boxPlot/zBoxPlot.d.ts +210 -14
  64. package/dist/esm/types/chartType/circlePacking/zCirclePacking.d.ts +2 -2
  65. package/dist/esm/types/chartType/column/zColumn.d.ts +362 -10
  66. package/dist/esm/types/chartType/columnParallel/zColumnParallel.d.ts +362 -10
  67. package/dist/esm/types/chartType/columnPercent/zColumnPercent.d.ts +362 -10
  68. package/dist/esm/types/chartType/donut/zDonut.d.ts +2 -2
  69. package/dist/esm/types/chartType/dualAxis/zDualAxis.d.ts +842 -22
  70. package/dist/esm/types/chartType/funnel/zFunnel.d.ts +2 -2
  71. package/dist/esm/types/chartType/heatmap/zHeatmap.d.ts +2 -2
  72. package/dist/esm/types/chartType/histogram/zHistogram.d.ts +362 -10
  73. package/dist/esm/types/chartType/line/zLine.d.ts +522 -14
  74. package/dist/esm/types/chartType/pie/zPie.d.ts +2 -2
  75. package/dist/esm/types/chartType/pivotTable/zPivotTable.d.ts +241 -4
  76. package/dist/esm/types/chartType/pivotTable/zPivotTable.js +1 -1
  77. package/dist/esm/types/chartType/pivotTable/zPivotTable.js.map +1 -1
  78. package/dist/esm/types/chartType/raceBar/zRaceBar.d.ts +362 -10
  79. package/dist/esm/types/chartType/raceColumn/zRaceColumn.d.ts +362 -10
  80. package/dist/esm/types/chartType/raceScatter/zRaceScatter.d.ts +362 -10
  81. package/dist/esm/types/chartType/radar/zRadar.d.ts +2 -2
  82. package/dist/esm/types/chartType/rose/zRose.d.ts +2 -2
  83. package/dist/esm/types/chartType/roseParallel/zRoseParallel.d.ts +2 -2
  84. package/dist/esm/types/chartType/scatter/zScatter.d.ts +362 -10
  85. package/dist/esm/types/chartType/sunburst/zSunburst.d.ts +2 -2
  86. package/dist/esm/types/chartType/table/zTable.d.ts +241 -4
  87. package/dist/esm/types/chartType/table/zTable.js +1 -1
  88. package/dist/esm/types/chartType/table/zTable.js.map +1 -1
  89. package/dist/esm/types/chartType/treeMap/zTreeMap.d.ts +2 -2
  90. package/dist/esm/types/dataSelector/selector.d.ts +594 -3
  91. package/dist/esm/types/dataSelector/selector.js +58 -2
  92. package/dist/esm/types/dataSelector/selector.js.map +1 -1
  93. package/dist/esm/types/properties/annotation/annotation.d.ts +200 -4
  94. package/dist/esm/types/properties/annotation/annotationHorizontalLine.d.ts +12 -0
  95. package/dist/esm/types/properties/annotation/annotationPoint.d.ts +19 -0
  96. package/dist/esm/types/properties/annotation/annotationVerticalLine.d.ts +12 -0
  97. package/dist/esm/types/properties/annotation/zAnnotationHorizontalLine.d.ts +10 -0
  98. package/dist/esm/types/properties/annotation/zAnnotationHorizontalLine.js +2 -0
  99. package/dist/esm/types/properties/annotation/zAnnotationHorizontalLine.js.map +1 -1
  100. package/dist/esm/types/properties/annotation/zAnnotationPoint.d.ts +80 -2
  101. package/dist/esm/types/properties/annotation/zAnnotationPoint.js +2 -1
  102. package/dist/esm/types/properties/annotation/zAnnotationPoint.js.map +1 -1
  103. package/dist/esm/types/properties/annotation/zAnnotationVerticalLine.d.ts +10 -0
  104. package/dist/esm/types/properties/annotation/zAnnotationVerticalLine.js +2 -0
  105. package/dist/esm/types/properties/annotation/zAnnotationVerticalLine.js.map +1 -1
  106. package/dist/esm/types/properties/cellStyle/bodyCellStyle.d.ts +105 -2
  107. package/dist/esm/types/properties/cellStyle/bodyCellStyle.js +2 -1
  108. package/dist/esm/types/properties/cellStyle/bodyCellStyle.js.map +1 -1
  109. package/dist/esm/types/properties/cellStyle/cellStyle.d.ts +83 -2
  110. package/dist/esm/types/properties/config/annotation/zAnnotation.d.ts +156 -0
  111. package/dist/esm/types/properties/config/area.d.ts +160 -4
  112. package/dist/esm/types/properties/config/bar.d.ts +240 -6
  113. package/dist/esm/types/properties/config/boxplot.d.ts +80 -2
  114. package/dist/esm/types/properties/config/circlePacking.d.ts +2 -2
  115. package/dist/esm/types/properties/config/column.d.ts +240 -6
  116. package/dist/esm/types/properties/config/config.d.ts +1300 -52
  117. package/dist/esm/types/properties/config/dualAxis.d.ts +80 -2
  118. package/dist/esm/types/properties/config/funnel.d.ts +2 -2
  119. package/dist/esm/types/properties/config/heatmap.d.ts +2 -2
  120. package/dist/esm/types/properties/config/histogram.d.ts +80 -2
  121. package/dist/esm/types/properties/config/label/zLabel.d.ts +2 -2
  122. package/dist/esm/types/properties/config/label/zPieLabel.d.ts +2 -2
  123. package/dist/esm/types/properties/config/line.d.ts +80 -2
  124. package/dist/esm/types/properties/config/pie.d.ts +6 -6
  125. package/dist/esm/types/properties/config/race.d.ts +240 -6
  126. package/dist/esm/types/properties/config/rose.d.ts +4 -4
  127. package/dist/esm/types/properties/config/scatter.d.ts +80 -2
  128. package/dist/esm/types/properties/config/sunburst.d.ts +2 -2
  129. package/dist/esm/types/properties/config/treeMap.d.ts +2 -2
  130. package/dist/esm/types/properties/markStyle/areaStyle.d.ts +19 -0
  131. package/dist/esm/types/properties/markStyle/barStyle.d.ts +99 -2
  132. package/dist/esm/types/properties/markStyle/barStyle.js +2 -1
  133. package/dist/esm/types/properties/markStyle/barStyle.js.map +1 -1
  134. package/dist/esm/types/properties/markStyle/boxPlotStyle.d.ts +2 -2
  135. package/dist/esm/types/properties/markStyle/lineStyle.d.ts +99 -2
  136. package/dist/esm/types/properties/markStyle/lineStyle.js +2 -1
  137. package/dist/esm/types/properties/markStyle/lineStyle.js.map +1 -1
  138. package/dist/esm/types/properties/markStyle/markStyle.d.ts +648 -24
  139. package/dist/esm/types/properties/markStyle/outlierStyle.d.ts +2 -2
  140. package/dist/esm/types/properties/markStyle/pointStyle.d.ts +99 -2
  141. package/dist/esm/types/properties/markStyle/pointStyle.js +2 -1
  142. package/dist/esm/types/properties/markStyle/pointStyle.js.map +1 -1
  143. package/dist/esm/types/properties/markStyle/zAreaStyle.d.ts +80 -2
  144. package/dist/esm/types/properties/markStyle/zAreaStyle.js +2 -1
  145. package/dist/esm/types/properties/markStyle/zAreaStyle.js.map +1 -1
  146. package/dist/esm/types/properties/theme/customTheme.d.ts +2600 -104
  147. package/dist/esm/types/sandbox.d.ts +19 -0
  148. package/dist/esm/types/sandbox.js +0 -0
  149. package/dist/esm/types/zVseed.d.ts +7 -25058
  150. package/dist/esm/types/zVseed.js.map +1 -1
  151. package/dist/umd/index.js +1786 -260
  152. package/dist/umd/index.js.map +1 -1
  153. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { buildAdvanced } from "./buildAdvanced.js";
2
2
  import { buildSpec } from "./buildSpec.js";
3
3
  import { build } from "./build.js";
4
+ import { prepare } from "./prepare.js";
4
5
  import { intl } from "../../i18n/index.js";
5
6
  import { getColorIdMap, getColorItems } from "./advanced/index.js";
6
7
  class Builder {
@@ -9,6 +10,7 @@ class Builder {
9
10
  _spec = null;
10
11
  _performance = {};
11
12
  _locale;
13
+ _isPrepared = false;
12
14
  constructor(vseed){
13
15
  this._vseed = vseed;
14
16
  this._locale = vseed.locale || intl.getLocale();
@@ -16,6 +18,7 @@ class Builder {
16
18
  get locale() {
17
19
  return this._locale;
18
20
  }
21
+ prepare = async ()=>prepare(this);
19
22
  build = ()=>build(this);
20
23
  buildSpec = (advanced)=>buildSpec(this, advanced);
21
24
  buildAdvanced = ()=>buildAdvanced(this);
@@ -26,6 +29,13 @@ class Builder {
26
29
  }
27
30
  set vseed(value) {
28
31
  this._vseed = value;
32
+ this._isPrepared = false;
33
+ }
34
+ get isPrepared() {
35
+ return this._isPrepared;
36
+ }
37
+ set isPrepared(value) {
38
+ this._isPrepared = value;
29
39
  }
30
40
  get advancedVSeed() {
31
41
  return this._advancedVSeed;
@@ -1 +1 @@
1
- {"version":3,"file":"builder/builder/builder.js","sources":["webpack://@visactor/vseed/./src/builder/builder/builder.ts"],"sourcesContent":["import type {\n AdvancedPipe,\n AdvancedPipeline,\n AdvancedVSeed,\n ChartType,\n CustomThemeConfig,\n Locale,\n Spec,\n SpecPipe,\n SpecPipeline,\n VSeed,\n VSeedBuilder,\n} from 'src/types'\nimport { buildAdvanced } from './buildAdvanced'\nimport { buildSpec } from './buildSpec'\nimport { build } from './build'\nimport { intl } from 'src/i18n'\nimport { getColorIdMap, getColorItems } from './advanced'\n\nexport class Builder implements VSeedBuilder {\n private _vseed: VSeed\n private _advancedVSeed: AdvancedVSeed | null = null\n private _spec: Spec | null = null\n private _performance: Record<string, string | number> = {}\n\n private _locale: Locale\n\n /**\n * @description 初始化 Builder 实例。\n * @param vseed VSeed 数据对象,包含图表类型、数据和映射配置。\n */\n constructor(vseed: VSeed) {\n this._vseed = vseed\n this._locale = vseed.locale || intl.getLocale()\n }\n\n /**\n * @description 获取当前 Builder 使用的语言环境。\n * @returns 语言环境代码 (如 'zh-CN', 'en-US')。\n */\n get locale() {\n return this._locale\n }\n\n /**\n * @description 生成最终的图表配置 (Spec)。\n * 这是最常用的核心方法。拿到 Spec 后,直接传给 VChart 或 VTable 即可渲染图表。\n * @returns VChart 或 VTable 的标准 Spec 对象。\n * @example\n * const spec = builder.build();\n * // const vchart = new VChart(spec, { dom: 'chart-container' });\n * // vchart.render();\n */\n build = <T extends Spec>(): T => build(this) as T\n\n /**\n * @description 将中间层配置 (AdvancedVSeed) 转换为最终 Spec。\n * 仅当你需要深度定制中间层配置时使用。通常流程是:buildAdvanced() -> 修改配置 -> buildSpec()。\n * @param advanced 修改后的 AdvancedVSeed 对象。\n * @returns VChart 或 VTable 的标准 Spec 对象。\n */\n buildSpec = (advanced: AdvancedVSeed): Spec => buildSpec(this, advanced)\n\n /**\n * @description 生成中间层配置 (AdvancedVSeed)。\n * 中间层配置也就是常说的 \"图表模版\",它比原始 VSeed 更详细,暴露了更多图表细节(如坐标轴、图例的具体配置)。\n * 如果默认的 build() 结果不满足需求,可以先获取这个中间配置进行修改,再调用 buildSpec 生成最终结果。\n * @returns AdvancedVSeed 对象 (模版配置)。\n */\n buildAdvanced = (): AdvancedVSeed | null => buildAdvanced(this)\n\n /**\n * @description 获取数据中涉及颜色的字段信息。\n * 常用于生成图表的图例或颜色筛选器 UI。\n * @returns 颜色字段列表 (包含 id 和别名)。\n */\n getColorItems = () => getColorItems(this)\n\n /**\n * @description 获取颜色字段的详细映射表。\n * @returns Key 为颜色 ID,Value 为详细信息的对象。\n */\n getColorIdMap = () => getColorIdMap(this)\n\n /**\n * @description 获取当前的 VSeed 输入数据。\n */\n get vseed() {\n return this._vseed\n }\n\n /**\n * @description 更新 VSeed 输入数据。\n * 更新后,后续调用 build() 将基于新数据生成。\n * @param value 新的 VSeed 对象。\n */\n set vseed(value) {\n this._vseed = value\n }\n\n /**\n * @description 获取当前的 AdvancedVSeed 中间配置对象。\n * @returns AdvancedVSeed 对象。\n */\n get advancedVSeed() {\n return this._advancedVSeed\n }\n\n /**\n * @description 设置 AdvancedVSeed 中间配置对象。\n * 通常用于缓存或复用已有的中间配置。\n * @param value 新的 AdvancedVSeed 对象。\n */\n set advancedVSeed(value) {\n this._advancedVSeed = value\n }\n\n /**\n * @description 获取当前生成的最终 Spec 对象。\n * @returns Spec 对象。\n */\n get spec() {\n return this._spec\n }\n\n /**\n * @description 设置 Spec 对象。\n * 通常用于缓存。\n * @param value 新的 Spec 对象。\n */\n set spec(value) {\n this._spec = value\n }\n\n /**\n * @description 获取构建过程中的性能统计信息。\n * @returns 包含各阶段耗时的对象 (单位: ms)。\n */\n get performance() {\n return this._performance\n }\n\n /**\n * @description 设置性能统计信息。\n * @param value 新的性能统计对象。\n */\n set performance(value) {\n this._performance = value\n }\n\n /**\n * @description [内部方法] 获取指定图表类型的模版构建管线。\n * 用于查看或调试该图表类型是如何从 VSeed 转换为 AdvancedVSeed 的。\n * @param chartType 图表类型 (如 'bar', 'line')。\n * @returns AdvancedPipeline 数组。\n */\n static getAdvancedPipeline = (chartType: ChartType) => {\n const customPipe = Builder._customAdvancedPipe[chartType] as AdvancedPipe\n const pipeline = Builder._advancedPipelineMap[chartType] as AdvancedPipeline\n if (customPipe) {\n pipeline.push(customPipe)\n }\n return pipeline\n }\n\n /**\n * @description [内部方法] 获取指定图表类型的 Spec 构建管线。\n * 用于查看或调试该图表类型是如何从 AdvancedVSeed 转换为 Spec 的。\n * @param chartType 图表类型。\n * @returns SpecPipeline 数组。\n */\n static getSpecPipeline = (chartType: ChartType) => {\n const customPipe = Builder._customSpecPipe[chartType] as SpecPipe\n const pipeline = Builder._specPipelineMap[chartType] as SpecPipeline\n if (customPipe) {\n pipeline.push(customPipe)\n }\n return pipeline\n }\n\n /**\n * @description 获取指定主题的配置。\n * @param themeKey 主题名称 (例如 'light', 'dark')。如果不传,默认为 'light'。\n * @returns 主题配置对象。\n */\n static getTheme = (themeKey?: string) => Builder._themeMap[themeKey || 'light']\n\n /**\n * @description 获取所有已注册的主题配置。\n * @returns 主题配置映射表。\n */\n static getThemeMap = () => Builder._themeMap\n\n /**\n * @description 静态工厂方法,用于便捷地创建 Builder 实例。\n * @param vseed VSeed 数据对象。\n * @returns 新的 Builder 实例。\n * @example\n * const builder = Builder.from(vseedJson);\n */\n static from = (vseed: VSeed) => new Builder(vseed)\n\n /**\n * @description [扩展方法] 注册一个新的图表类型(模版构建阶段)。\n * 如果你要让 Builder 支持一种全新的图表,需要在这里注册它的模版构建逻辑。\n * @param chartType 新图表类型的名称。\n * @param pipeline 处理管道数组。\n */\n static registerAdvancedPipeline = (chartType: ChartType, pipeline: AdvancedPipeline) => {\n Builder._advancedPipelineMap[chartType] = pipeline\n }\n\n /**\n * @description [扩展方法] 注册一个新的图表类型(Spec 构建阶段)。\n * 如果你要让 Builder 支持一种全新的图表,需要在这里注册它的 Spec 构建逻辑。\n * @param chartType 图表类型。\n * @param pipeline 处理管道数组。\n */\n static registerSpecPipeline = (chartType: ChartType, pipeline: SpecPipeline) => {\n Builder._specPipelineMap[chartType] = pipeline\n }\n\n /**\n * @description [扩展方法] 修改现有的图表模版构建逻辑。\n * 可以在现有图表的构建流程中插入自定义逻辑(Pipe),从而影响生成的 AdvancedVSeed。\n * @param chartType 目标图表类型。\n * @param pipe 自定义处理函数。\n */\n static updateAdvanced = (chartType: ChartType, pipe: AdvancedPipe) => {\n Builder._customAdvancedPipe[chartType] = pipe\n }\n\n /**\n * @description [扩展方法] 修改现有的图表 Spec 构建逻辑。\n * 可以在现有图表的构建流程中插入自定义逻辑(Pipe),从而影响生成的最终 Spec。\n * @param chartType 目标图表类型。\n * @param pipe 自定义处理函数。\n */\n static updateSpec = (chartType: ChartType, pipe: SpecPipe) => {\n Builder._customSpecPipe[chartType] = pipe\n }\n\n /**\n * @description [扩展方法] 注册自定义主题。\n * @param key 主题名称。\n * @param theme 主题配置对象。\n */\n static registerTheme = (key: string, theme: CustomThemeConfig) => {\n Builder._themeMap[key] = theme\n }\n\n private static _advancedPipelineMap: Partial<Record<ChartType, AdvancedPipeline>> = {}\n private static _specPipelineMap: Partial<Record<ChartType, SpecPipeline>> = {}\n private static _customAdvancedPipe: Partial<Record<ChartType, AdvancedPipe>> = {}\n private static _customSpecPipe: Partial<Record<ChartType, SpecPipe>> = {}\n private static _themeMap: Record<string, CustomThemeConfig> = {}\n}\n"],"names":["Builder","vseed","intl","build","advanced","buildSpec","buildAdvanced","getColorItems","getColorIdMap","value","chartType","customPipe","pipeline","themeKey","pipe","key","theme"],"mappings":";;;;;AAmBO,MAAMA;IACH,OAAa;IACb,iBAAuC,KAAI;IAC3C,QAAqB,KAAI;IACzB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IAAIC,YACFC,SAAS,IAAI,CAACD;QAEhB,OAAOC;IACT,EAAC;IAOD,OAAO,WAAW,CAACC,WAAsBb,QAAQ,SAAS,CAACa,YAAY,QAAQ;IAM/E,OAAO,cAAc,IAAMb,QAAQ,SAAS;IAS5C,OAAO,OAAO,CAACC,QAAiB,IAAID,QAAQC,OAAM;IAQlD,OAAO,2BAA2B,CAACS,WAAsBE;QACvDZ,QAAQ,oBAAoB,CAACU,UAAU,GAAGE;IAC5C,EAAC;IAQD,OAAO,uBAAuB,CAACF,WAAsBE;QACnDZ,QAAQ,gBAAgB,CAACU,UAAU,GAAGE;IACxC,EAAC;IAQD,OAAO,iBAAiB,CAACF,WAAsBI;QAC7Cd,QAAQ,mBAAmB,CAACU,UAAU,GAAGI;IAC3C,EAAC;IAQD,OAAO,aAAa,CAACJ,WAAsBI;QACzCd,QAAQ,eAAe,CAACU,UAAU,GAAGI;IACvC,EAAC;IAOD,OAAO,gBAAgB,CAACC,KAAaC;QACnChB,QAAQ,SAAS,CAACe,IAAI,GAAGC;IAC3B,EAAC;IAED,OAAe,uBAAqE,CAAC,EAAC;IACtF,OAAe,mBAA6D,CAAC,EAAC;IAC9E,OAAe,sBAAgE,CAAC,EAAC;IACjF,OAAe,kBAAwD,CAAC,EAAC;IACzE,OAAe,YAA+C,CAAC,EAAC;AAClE"}
1
+ {"version":3,"file":"builder/builder/builder.js","sources":["webpack://@visactor/vseed/./src/builder/builder/builder.ts"],"sourcesContent":["import type {\n AdvancedPipe,\n AdvancedPipeline,\n AdvancedVSeed,\n ChartType,\n CustomThemeConfig,\n Locale,\n Spec,\n SpecPipe,\n SpecPipeline,\n VSeed,\n VSeedBuilder,\n} from 'src/types'\nimport { buildAdvanced } from './buildAdvanced'\nimport { buildSpec } from './buildSpec'\nimport { build } from './build'\nimport { prepare } from './prepare'\nimport { intl } from 'src/i18n'\nimport { getColorIdMap, getColorItems } from './advanced'\n\nexport class Builder implements VSeedBuilder {\n private _vseed: VSeed\n private _advancedVSeed: AdvancedVSeed | null = null\n private _spec: Spec | null = null\n private _performance: Record<string, string | number> = {}\n\n private _locale: Locale\n\n // prepare() 相关状态\n private _isPrepared: boolean = false\n\n /**\n * @description 初始化 Builder 实例。\n * @param vseed VSeed 数据对象,包含图表类型、数据和映射配置。\n */\n constructor(vseed: VSeed) {\n this._vseed = vseed\n this._locale = vseed.locale || intl.getLocale()\n }\n\n /**\n * @description 获取当前 Builder 使用的语言环境。\n * @returns 语言环境代码 (如 'zh-CN', 'en-US')。\n */\n get locale() {\n return this._locale\n }\n\n /**\n * @description 准备阶段 - 异步执行动态过滤器代码。\n *\n * 在 build() 之前调用,用于执行 dynamicFilter 中的 code。包含以下步骤:\n * 1. 检查是否存在需要执行的 dynamicFilter (有 code 字段)\n * 2. 如果存在,给 dataset 添加内部索引 __row_index\n * 3. 生成 AdvancedVSeed 中间配置\n * 4. 执行所有 dynamicFilter 的 code,将结果写入 filter.result\n * 5. 缓存 AdvancedVSeed,供后续 build() 使用\n *\n * **注意:**\n * - 此方法具有幂等性,多次调用不会重复执行\n * - 如果没有 dynamicFilter code,调用此方法无副作用\n * - 如果 dynamicFilter 只有静态 result 而没有 code,无需调用此方法\n *\n * @returns Promise<void>\n * @example\n * // 有 dynamicFilter code 的场景\n * const builder = VBI.from(data, 'table')\n * .dynamicFilter({ code: 'return data.filter(d => d.sales > 1000)' })\n *\n * await builder.prepare() // 异步执行 code\n * const spec = builder.build() // 同步构建 spec\n *\n * // 没有 dynamicFilter 的场景\n * const builder = VBI.from(data, 'table')\n * const spec = builder.build() // 直接构建,无需 prepare\n */\n prepare = async (): Promise<void> => prepare(this)\n\n /**\n * @description 生成最终的图表配置 (Spec)。\n *\n * 这是最常用的核心方法。拿到 Spec 后,直接传给 VChart 或 VTable 即可渲染图表。\n *\n * **注意:**\n * - 如果配置中包含 dynamicFilter code,需要先调用 prepare() 异步执行\n * - 如果已调用过 prepare(),build() 会复用缓存的结果,提升性能\n *\n * @returns VChart 或 VTable 的标准 Spec 对象。\n * @example\n * // 场景 1: 无 dynamicFilter,直接构建\n * const spec = builder.build();\n *\n * // 场景 2: 有 dynamicFilter code,先 prepare 再 build\n * await builder.prepare();\n * const spec = builder.build();\n */\n build = <T extends Spec>(): T => build(this) as T\n\n /**\n * @description 将中间层配置 (AdvancedVSeed) 转换为最终 Spec。\n * 仅当你需要深度定制中间层配置时使用。通常流程是:buildAdvanced() -> 修改配置 -> buildSpec()。\n * @param advanced 修改后的 AdvancedVSeed 对象。\n * @returns VChart 或 VTable 的标准 Spec 对象。\n */\n buildSpec = (advanced: AdvancedVSeed): Spec => buildSpec(this, advanced)\n\n /**\n * @description 生成中间层配置 (AdvancedVSeed)。\n * 中间层配置也就是常说的 \"图表模版\",它比原始 VSeed 更详细,暴露了更多图表细节(如坐标轴、图例的具体配置)。\n * 如果默认的 build() 结果不满足需求,可以先获取这个中间配置进行修改,再调用 buildSpec 生成最终结果。\n * @returns AdvancedVSeed 对象 (模版配置)。\n */\n buildAdvanced = (): AdvancedVSeed | null => buildAdvanced(this)\n\n /**\n * @description 获取数据中涉及颜色的字段信息。\n * 常用于生成图表的图例或颜色筛选器 UI。\n * @returns 颜色字段列表 (包含 id 和别名)。\n */\n getColorItems = () => getColorItems(this)\n\n /**\n * @description 获取颜色字段的详细映射表。\n * @returns Key 为颜色 ID,Value 为详细信息的对象。\n */\n getColorIdMap = () => getColorIdMap(this)\n\n /**\n * @description 获取当前的 VSeed 输入数据。\n */\n get vseed() {\n return this._vseed\n }\n\n /**\n * @description 更新 VSeed 输入数据。\n * 更新后,后续调用 build() 将基于新数据生成。\n * **注意:** 更新 vseed 后会清除 prepare() 的缓存状态。\n * @param value 新的 VSeed 对象。\n */\n set vseed(value) {\n this._vseed = value\n // 清除 prepare 缓存\n this._isPrepared = false\n }\n\n /**\n * @description 获取 prepare() 状态\n * @internal\n */\n get isPrepared() {\n return this._isPrepared\n }\n\n /**\n * @description 设置 prepare() 状态\n * @internal\n */\n set isPrepared(value: boolean) {\n this._isPrepared = value\n }\n\n /**\n * @description 获取当前的 AdvancedVSeed 中间配置对象。\n * @returns AdvancedVSeed 对象。\n */\n get advancedVSeed() {\n return this._advancedVSeed\n }\n\n /**\n * @description 设置 AdvancedVSeed 中间配置对象。\n * 通常用于缓存或复用已有的中间配置。\n * @param value 新的 AdvancedVSeed 对象。\n */\n set advancedVSeed(value) {\n this._advancedVSeed = value\n }\n\n /**\n * @description 获取当前生成的最终 Spec 对象。\n * @returns Spec 对象。\n */\n get spec() {\n return this._spec\n }\n\n /**\n * @description 设置 Spec 对象。\n * 通常用于缓存。\n * @param value 新的 Spec 对象。\n */\n set spec(value) {\n this._spec = value\n }\n\n /**\n * @description 获取构建过程中的性能统计信息。\n * @returns 包含各阶段耗时的对象 (单位: ms)。\n */\n get performance() {\n return this._performance\n }\n\n /**\n * @description 设置性能统计信息。\n * @param value 新的性能统计对象。\n */\n set performance(value) {\n this._performance = value\n }\n\n /**\n * @description [内部方法] 获取指定图表类型的模版构建管线。\n * 用于查看或调试该图表类型是如何从 VSeed 转换为 AdvancedVSeed 的。\n * @param chartType 图表类型 (如 'bar', 'line')。\n * @returns AdvancedPipeline 数组。\n */\n static getAdvancedPipeline = (chartType: ChartType) => {\n const customPipe = Builder._customAdvancedPipe[chartType] as AdvancedPipe\n const pipeline = Builder._advancedPipelineMap[chartType] as AdvancedPipeline\n if (customPipe) {\n pipeline.push(customPipe)\n }\n return pipeline\n }\n\n /**\n * @description [内部方法] 获取指定图表类型的 Spec 构建管线。\n * 用于查看或调试该图表类型是如何从 AdvancedVSeed 转换为 Spec 的。\n * @param chartType 图表类型。\n * @returns SpecPipeline 数组。\n */\n static getSpecPipeline = (chartType: ChartType) => {\n const customPipe = Builder._customSpecPipe[chartType] as SpecPipe\n const pipeline = Builder._specPipelineMap[chartType] as SpecPipeline\n if (customPipe) {\n pipeline.push(customPipe)\n }\n return pipeline\n }\n\n /**\n * @description 获取指定主题的配置。\n * @param themeKey 主题名称 (例如 'light', 'dark')。如果不传,默认为 'light'。\n * @returns 主题配置对象。\n */\n static getTheme = (themeKey?: string) => Builder._themeMap[themeKey || 'light']\n\n /**\n * @description 获取所有已注册的主题配置。\n * @returns 主题配置映射表。\n */\n static getThemeMap = () => Builder._themeMap\n\n /**\n * @description 静态工厂方法,用于便捷地创建 Builder 实例。\n * @param vseed VSeed 数据对象。\n * @returns 新的 Builder 实例。\n * @example\n * const builder = Builder.from(vseedJson);\n */\n static from = (vseed: VSeed) => new Builder(vseed)\n\n /**\n * @description [扩展方法] 注册一个新的图表类型(模版构建阶段)。\n * 如果你要让 Builder 支持一种全新的图表,需要在这里注册它的模版构建逻辑。\n * @param chartType 新图表类型的名称。\n * @param pipeline 处理管道数组。\n */\n static registerAdvancedPipeline = (chartType: ChartType, pipeline: AdvancedPipeline) => {\n Builder._advancedPipelineMap[chartType] = pipeline\n }\n\n /**\n * @description [扩展方法] 注册一个新的图表类型(Spec 构建阶段)。\n * 如果你要让 Builder 支持一种全新的图表,需要在这里注册它的 Spec 构建逻辑。\n * @param chartType 图表类型。\n * @param pipeline 处理管道数组。\n */\n static registerSpecPipeline = (chartType: ChartType, pipeline: SpecPipeline) => {\n Builder._specPipelineMap[chartType] = pipeline\n }\n\n /**\n * @description [扩展方法] 修改现有的图表模版构建逻辑。\n * 可以在现有图表的构建流程中插入自定义逻辑(Pipe),从而影响生成的 AdvancedVSeed。\n * @param chartType 目标图表类型。\n * @param pipe 自定义处理函数。\n */\n static updateAdvanced = (chartType: ChartType, pipe: AdvancedPipe) => {\n Builder._customAdvancedPipe[chartType] = pipe\n }\n\n /**\n * @description [扩展方法] 修改现有的图表 Spec 构建逻辑。\n * 可以在现有图表的构建流程中插入自定义逻辑(Pipe),从而影响生成的最终 Spec。\n * @param chartType 目标图表类型。\n * @param pipe 自定义处理函数。\n */\n static updateSpec = (chartType: ChartType, pipe: SpecPipe) => {\n Builder._customSpecPipe[chartType] = pipe\n }\n\n /**\n * @description [扩展方法] 注册自定义主题。\n * @param key 主题名称。\n * @param theme 主题配置对象。\n */\n static registerTheme = (key: string, theme: CustomThemeConfig) => {\n Builder._themeMap[key] = theme\n }\n\n private static _advancedPipelineMap: Partial<Record<ChartType, AdvancedPipeline>> = {}\n private static _specPipelineMap: Partial<Record<ChartType, SpecPipeline>> = {}\n private static _customAdvancedPipe: Partial<Record<ChartType, AdvancedPipe>> = {}\n private static _customSpecPipe: Partial<Record<ChartType, SpecPipe>> = {}\n private static _themeMap: Record<string, CustomThemeConfig> = {}\n}\n"],"names":["Builder","vseed","intl","prepare","build","advanced","buildSpec","buildAdvanced","getColorItems","getColorIdMap","value","chartType","customPipe","pipeline","themeKey","pipe","key","theme"],"mappings":";;;;;;AAoBO,MAAMA;IACH,OAAa;IACb,iBAAuC,KAAI;IAC3C,QAAqB,KAAI;IACzB,eAAgD,CAAC,EAAC;IAElD,QAAe;IAGf,cAAuB,MAAK;IAMpC,YAAYC,KAAY,CAAE;QACxB,IAAI,CAAC,MAAM,GAAGA;QACd,IAAI,CAAC,OAAO,GAAGA,MAAM,MAAM,IAAIC,KAAK,SAAS;IAC/C;IAMA,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO;IACrB;IA8BA,UAAU,UAA2BC,QAAQ,IAAI,EAAC;IAoBlD,QAAQ,IAAyBC,MAAM,IAAI,EAAM;IAQjD,YAAY,CAACC,WAAkCC,UAAU,IAAI,EAAED,UAAS;IAQxE,gBAAgB,IAA4BE,cAAc,IAAI,EAAC;IAO/D,gBAAgB,IAAMC,cAAc,IAAI,EAAC;IAMzC,gBAAgB,IAAMC,cAAc,IAAI,EAAC;IAKzC,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM;IACpB;IAQA,IAAI,MAAMC,KAAK,EAAE;QACf,IAAI,CAAC,MAAM,GAAGA;QAEd,IAAI,CAAC,WAAW,GAAG;IACrB;IAMA,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,WAAW;IACzB;IAMA,IAAI,WAAWA,KAAc,EAAE;QAC7B,IAAI,CAAC,W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,eAAe,CAACW,UAAU,GAAGI;IACvC,EAAC;IAOD,OAAO,gBAAgB,CAACC,KAAaC;QACnCjB,QAAQ,SAAS,CAACgB,IAAI,GAAGC;IAC3B,EAAC;IAED,OAAe,uBAAqE,CAAC,EAAC;IACtF,OAAe,mBAA6D,CAAC,EAAC;IAC9E,OAAe,sBAAgE,CAAC,EAAC;IACjF,OAAe,kBAAwD,CAAC,EAAC;IACzE,OAAe,YAA+C,CAAC,EAAC;AAClE"}
@@ -0,0 +1,12 @@
1
+ import type { Builder } from './builder';
2
+ /**
3
+ * 准备阶段 - 执行动态过滤器代码
4
+ * @description 在 build() 之前调用,用于:
5
+ * 1. 检查是否存在需要执行的 dynamicFilter (有 code 字段)
6
+ * 2. 创建 vseed 的副本,给 dataset 添加 __row_index
7
+ * 3. 收集所有 dynamicFilter 并执行 code
8
+ * 4. 将结果直接写入 dynamicFilter.result
9
+ * 5. 更新 builder.vseed 为处理后的副本
10
+ * @returns Promise<void>
11
+ */
12
+ export declare const prepare: (builder: Builder) => Promise<void>;
@@ -0,0 +1,269 @@
1
+ import { InnerRowIndex } from "../../dataReshape/index.js";
2
+ import { executeDynamicFilter, isDynamicFilter } from "../../dataSelector/selector.js";
3
+ const generateDynamicFilterKeyPaths = ()=>{
4
+ const dynamicFilterConfig = {
5
+ table: [
6
+ 'bodyCellStyle'
7
+ ],
8
+ pivotTable: [
9
+ 'bodyCellStyle'
10
+ ],
11
+ bar: [
12
+ 'barStyle',
13
+ 'annotationPoint',
14
+ 'annotationVerticalLine'
15
+ ],
16
+ barParallel: [
17
+ 'barStyle',
18
+ 'annotationPoint',
19
+ 'annotationVerticalLine'
20
+ ],
21
+ barPercent: [
22
+ 'barStyle',
23
+ 'annotationPoint',
24
+ 'annotationVerticalLine'
25
+ ],
26
+ column: [
27
+ 'barStyle',
28
+ 'annotationPoint',
29
+ 'annotationHorizontalLine'
30
+ ],
31
+ columnParallel: [
32
+ 'barStyle',
33
+ 'annotationPoint',
34
+ 'annotationHorizontalLine'
35
+ ],
36
+ columnPercent: [
37
+ 'barStyle',
38
+ 'annotationPoint',
39
+ 'annotationHorizontalLine'
40
+ ],
41
+ line: [
42
+ 'lineStyle',
43
+ 'pointStyle',
44
+ 'annotationPoint',
45
+ 'annotationHorizontalLine'
46
+ ],
47
+ area: [
48
+ 'lineStyle',
49
+ 'pointStyle',
50
+ 'annotationPoint',
51
+ 'annotationHorizontalLine'
52
+ ],
53
+ areaPercent: [
54
+ 'lineStyle',
55
+ 'pointStyle',
56
+ 'annotationPoint',
57
+ 'annotationHorizontalLine'
58
+ ],
59
+ dualAxis: [
60
+ 'barStyle',
61
+ 'lineStyle',
62
+ 'pointStyle',
63
+ 'annotationPoint',
64
+ 'annotationHorizontalLine'
65
+ ],
66
+ scatter: [
67
+ 'pointStyle',
68
+ 'annotationPoint',
69
+ 'annotationHorizontalLine',
70
+ 'annotationVerticalLine'
71
+ ],
72
+ histogram: [
73
+ 'annotationHorizontalLine'
74
+ ],
75
+ boxPlot: [
76
+ 'annotationHorizontalLine'
77
+ ]
78
+ };
79
+ const result = {};
80
+ for (const [chartType, baseKeyPaths] of Object.entries(dynamicFilterConfig))result[chartType] = baseKeyPaths.flatMap((basePath)=>[
81
+ `${basePath}[].dynamicFilter`,
82
+ `${basePath}.dynamicFilter`
83
+ ]);
84
+ return result;
85
+ };
86
+ const dynamicFilterKeyPathsByChartType = generateDynamicFilterKeyPaths();
87
+ const getBasePathsForDeepClone = (chartType)=>{
88
+ const config = {
89
+ table: [
90
+ 'bodyCellStyle'
91
+ ],
92
+ pivotTable: [
93
+ 'bodyCellStyle'
94
+ ],
95
+ bar: [
96
+ 'barStyle',
97
+ 'annotationPoint',
98
+ 'annotationVerticalLine'
99
+ ],
100
+ barParallel: [
101
+ 'barStyle',
102
+ 'annotationPoint',
103
+ 'annotationVerticalLine'
104
+ ],
105
+ barPercent: [
106
+ 'barStyle',
107
+ 'annotationPoint',
108
+ 'annotationVerticalLine'
109
+ ],
110
+ column: [
111
+ 'barStyle',
112
+ 'annotationPoint',
113
+ 'annotationHorizontalLine'
114
+ ],
115
+ columnParallel: [
116
+ 'barStyle',
117
+ 'annotationPoint',
118
+ 'annotationHorizontalLine'
119
+ ],
120
+ columnPercent: [
121
+ 'barStyle',
122
+ 'annotationPoint',
123
+ 'annotationHorizontalLine'
124
+ ],
125
+ line: [
126
+ 'lineStyle',
127
+ 'pointStyle',
128
+ 'annotationPoint',
129
+ 'annotationHorizontalLine'
130
+ ],
131
+ area: [
132
+ 'lineStyle',
133
+ 'pointStyle',
134
+ 'annotationPoint',
135
+ 'annotationHorizontalLine'
136
+ ],
137
+ areaPercent: [
138
+ 'lineStyle',
139
+ 'pointStyle',
140
+ 'annotationPoint',
141
+ 'annotationHorizontalLine'
142
+ ],
143
+ dualAxis: [
144
+ 'barStyle',
145
+ 'lineStyle',
146
+ 'pointStyle',
147
+ 'annotationPoint',
148
+ 'annotationHorizontalLine'
149
+ ],
150
+ scatter: [
151
+ 'pointStyle',
152
+ 'annotationPoint',
153
+ 'annotationHorizontalLine',
154
+ 'annotationVerticalLine'
155
+ ],
156
+ histogram: [
157
+ 'annotationHorizontalLine'
158
+ ],
159
+ boxPlot: [
160
+ 'annotationHorizontalLine'
161
+ ]
162
+ };
163
+ return config[chartType] ?? [];
164
+ };
165
+ const parseKeyPath = (path)=>path.split('.').map((segment)=>{
166
+ if (segment.endsWith('[]')) return {
167
+ key: segment.slice(0, -2),
168
+ isArray: true
169
+ };
170
+ return {
171
+ key: segment,
172
+ isArray: false
173
+ };
174
+ });
175
+ const getValuesByKeyPath = (target, path)=>{
176
+ const segments = parseKeyPath(path);
177
+ let current = [
178
+ target
179
+ ];
180
+ for (const segment of segments){
181
+ const next = [];
182
+ for (const node of current){
183
+ if (!node || 'object' != typeof node) continue;
184
+ const value = node[segment.key];
185
+ if (segment.isArray) {
186
+ if (Array.isArray(value)) next.push(...value);
187
+ } else if (void 0 !== value) next.push(value);
188
+ }
189
+ current = next;
190
+ }
191
+ return current;
192
+ };
193
+ const collectDynamicFiltersByKeyPaths = (target, chartType)=>{
194
+ const paths = dynamicFilterKeyPathsByChartType[chartType] ?? [];
195
+ if (!paths.length) return [];
196
+ return paths.flatMap((path)=>getValuesByKeyPath(target, path)).filter((value)=>isDynamicFilter(value) && !!value?.code);
197
+ };
198
+ const executeDynamicFiltersAndInject = async (filters, dataset)=>{
199
+ if (!filters.length || !dataset.length) return;
200
+ await Promise.all(filters.map(async (filter)=>{
201
+ const { success, data, error } = await executeDynamicFilter(filter, dataset);
202
+ filter.result = {
203
+ success,
204
+ error,
205
+ data: data
206
+ };
207
+ }));
208
+ };
209
+ const deepCloneDynamicFilterPaths = (vseed, chartType)=>{
210
+ const basePaths = getBasePathsForDeepClone(chartType);
211
+ if (!basePaths.length) return {
212
+ ...vseed
213
+ };
214
+ const clonedVseed = {
215
+ ...vseed
216
+ };
217
+ for (const basePath of basePaths){
218
+ if (!(basePath in clonedVseed)) continue;
219
+ const value = clonedVseed[basePath];
220
+ if (Array.isArray(value)) clonedVseed[basePath] = value.map((item)=>{
221
+ if (!item || 'object' != typeof item) return item;
222
+ const clonedItem = {
223
+ ...item
224
+ };
225
+ if (clonedItem.dynamicFilter && 'object' == typeof clonedItem.dynamicFilter) clonedItem.dynamicFilter = {
226
+ ...clonedItem.dynamicFilter
227
+ };
228
+ return clonedItem;
229
+ });
230
+ else if (value && 'object' == typeof value) {
231
+ clonedVseed[basePath] = {
232
+ ...value
233
+ };
234
+ if (clonedVseed[basePath].dynamicFilter && 'object' == typeof clonedVseed[basePath].dynamicFilter) clonedVseed[basePath].dynamicFilter = {
235
+ ...clonedVseed[basePath].dynamicFilter
236
+ };
237
+ }
238
+ }
239
+ return clonedVseed;
240
+ };
241
+ const prepare = async (builder)=>{
242
+ if (builder.isPrepared || !builder.vseed || !builder.vseed?.chartType || !builder.vseed.dataset) return;
243
+ const filters = collectDynamicFiltersByKeyPaths(builder.vseed, builder.vseed.chartType);
244
+ if (!filters.length) {
245
+ builder.isPrepared = true;
246
+ return;
247
+ }
248
+ const clonedVseed = deepCloneDynamicFilterPaths(builder.vseed, builder.vseed.chartType);
249
+ const originalDataset = clonedVseed.dataset;
250
+ let datasetWithIndex = originalDataset;
251
+ if (!originalDataset[0] || !(InnerRowIndex in originalDataset[0])) datasetWithIndex = originalDataset.map((item, index)=>({
252
+ ...item,
253
+ [InnerRowIndex]: index
254
+ }));
255
+ builder.vseed = {
256
+ ...clonedVseed,
257
+ dataset: datasetWithIndex
258
+ };
259
+ const clonedFilters = collectDynamicFiltersByKeyPaths(builder.vseed, builder.vseed.chartType);
260
+ try {
261
+ await executeDynamicFiltersAndInject(clonedFilters, datasetWithIndex);
262
+ } catch (e) {
263
+ throw new Error(`Failed to execute dynamic filters: ${e.message}`);
264
+ }
265
+ builder.isPrepared = true;
266
+ };
267
+ export { prepare };
268
+
269
+ //# sourceMappingURL=prepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder/builder/prepare.js","sources":["webpack://@visactor/vseed/./src/builder/builder/prepare.ts"],"sourcesContent":["import type { ChartType } from 'src/types'\nimport { InnerRowIndex } from 'src/dataReshape'\nimport type { Builder } from './builder'\nimport { executeDynamicFilter, isDynamicFilter } from 'src/dataSelector/selector'\nimport type { DynamicFilter } from 'src/dataSelector/selector'\nimport type { ChartDynamicFilterRes, TableDynamicFilterRes } from 'src/types/dataSelector'\n\n/**\n * 生成完整的 keyPath 配置\n * 对每个基路径生成数组和非数组两种形式\n */\nconst generateDynamicFilterKeyPaths = (): Partial<Record<ChartType, string[]>> => {\n /**\n * 动态筛选器基础配置 - 配置每个图表类型中可能包含动态筛选器的字段\n * 生成时会自动添加 [] 和非 [] 两种形式\n */\n const dynamicFilterConfig: Partial<Record<ChartType, string[]>> = {\n table: ['bodyCellStyle'],\n pivotTable: ['bodyCellStyle'],\n bar: ['barStyle', 'annotationPoint', 'annotationVerticalLine'],\n barParallel: ['barStyle', 'annotationPoint', 'annotationVerticalLine'],\n barPercent: ['barStyle', 'annotationPoint', 'annotationVerticalLine'],\n column: ['barStyle', 'annotationPoint', 'annotationHorizontalLine'],\n columnParallel: ['barStyle', 'annotationPoint', 'annotationHorizontalLine'],\n columnPercent: ['barStyle', 'annotationPoint', 'annotationHorizontalLine'],\n line: ['lineStyle', 'pointStyle', 'annotationPoint', 'annotationHorizontalLine'],\n area: ['lineStyle', 'pointStyle', 'annotationPoint', 'annotationHorizontalLine'],\n areaPercent: ['lineStyle', 'pointStyle', 'annotationPoint', 'annotationHorizontalLine'],\n dualAxis: ['barStyle', 'lineStyle', 'pointStyle', 'annotationPoint', 'annotationHorizontalLine'],\n scatter: ['pointStyle', 'annotationPoint', 'annotationHorizontalLine', 'annotationVerticalLine'],\n histogram: ['annotationHorizontalLine'],\n boxPlot: ['annotationHorizontalLine'],\n }\n\n const result: Partial<Record<ChartType, string[]>> = {}\n for (const [chartType, baseKeyPaths] of Object.entries(dynamicFilterConfig)) {\n result[chartType as ChartType] = baseKeyPaths.flatMap((basePath) => [\n `${basePath}[].dynamicFilter`,\n `${basePath}.dynamicFilter`,\n ])\n }\n return result\n}\n\nconst dynamicFilterKeyPathsByChartType = generateDynamicFilterKeyPaths()\n\n/**\n * 提取图表类型对应的基础路径(用于深拷贝)\n */\nconst getBasePathsForDeepClone = (chartType: ChartType): string[] => {\n const config: Partial<Record<ChartType, string[]>> = {\n table: ['bodyCellStyle'],\n pivotTable: ['bodyCellStyle'],\n bar: ['barStyle', 'annotationPoint', 'annotationVerticalLine'],\n barParallel: ['barStyle', 'annotationPoint', 'annotationVerticalLine'],\n barPercent: ['barStyle', 'annotationPoint', 'annotationVerticalLine'],\n column: ['barStyle', 'annotationPoint', 'annotationHorizontalLine'],\n columnParallel: ['barStyle', 'annotationPoint', 'annotationHorizontalLine'],\n columnPercent: ['barStyle', 'annotationPoint', 'annotationHorizontalLine'],\n line: ['lineStyle', 'pointStyle', 'annotationPoint', 'annotationHorizontalLine'],\n area: ['lineStyle', 'pointStyle', 'annotationPoint', 'annotationHorizontalLine'],\n areaPercent: ['lineStyle', 'pointStyle', 'annotationPoint', 'annotationHorizontalLine'],\n dualAxis: ['barStyle', 'lineStyle', 'pointStyle', 'annotationPoint', 'annotationHorizontalLine'],\n scatter: ['pointStyle', 'annotationPoint', 'annotationHorizontalLine', 'annotationVerticalLine'],\n histogram: ['annotationHorizontalLine'],\n boxPlot: ['annotationHorizontalLine'],\n }\n\n return config[chartType] ?? []\n}\n\nconst parseKeyPath = (path: string) => {\n return path.split('.').map((segment) => {\n if (segment.endsWith('[]')) {\n return { key: segment.slice(0, -2), isArray: true }\n }\n return { key: segment, isArray: false }\n })\n}\n\nconst getValuesByKeyPath = (target: unknown, path: string): unknown[] => {\n const segments = parseKeyPath(path)\n let current: unknown[] = [target]\n\n for (const segment of segments) {\n const next: unknown[] = []\n for (const node of current) {\n if (!node || typeof node !== 'object') continue\n const value = (node as Record<string, unknown>)[segment.key]\n if (segment.isArray) {\n if (Array.isArray(value)) {\n next.push(...value)\n }\n } else if (value !== undefined) {\n next.push(value)\n }\n }\n current = next\n }\n\n return current\n}\n\nconst collectDynamicFiltersByKeyPaths = (target: unknown, chartType: ChartType): DynamicFilter[] => {\n const paths = dynamicFilterKeyPathsByChartType[chartType] ?? []\n if (!paths.length) return []\n\n return paths\n .flatMap((path) => getValuesByKeyPath(target, path))\n .filter((value): value is DynamicFilter => isDynamicFilter(value) && !!value?.code)\n}\n/**\n * 执行所有 dynamicFilter 的 code,将结果直接写入 filter.result\n */\nconst executeDynamicFiltersAndInject = async (filters: DynamicFilter[], dataset: any[]): Promise<void> => {\n if (!filters.length || !dataset.length) return\n\n await Promise.all(\n filters.map(async (filter) => {\n const { success, data, error } = await executeDynamicFilter(filter, dataset)\n filter.result = {\n success,\n error,\n data: data as TableDynamicFilterRes[] | ChartDynamicFilterRes[],\n }\n }),\n )\n}\n\n/**\n * 针对性深拷贝 vseed 中包含 dynamicFilter 的路径\n * @description 只深拷贝需要修改的路径,避免完全深拷贝的性能开销\n */\nconst deepCloneDynamicFilterPaths = (vseed: any, chartType: ChartType): any => {\n const basePaths = getBasePathsForDeepClone(chartType)\n if (!basePaths.length) return { ...vseed }\n\n const clonedVseed = { ...vseed }\n\n for (const basePath of basePaths) {\n if (!(basePath in clonedVseed)) continue\n\n const value = clonedVseed[basePath]\n\n // 如果是数组,深拷贝数组及其元素\n if (Array.isArray(value)) {\n clonedVseed[basePath] = value.map((item) => {\n if (!item || typeof item !== 'object') return item\n\n const clonedItem = { ...item }\n\n // 如果有 dynamicFilter,深拷贝它\n if (clonedItem.dynamicFilter && typeof clonedItem.dynamicFilter === 'object') {\n clonedItem.dynamicFilter = { ...clonedItem.dynamicFilter }\n }\n\n return clonedItem\n })\n }\n // 如果是对象\n else if (value && typeof value === 'object') {\n clonedVseed[basePath] = { ...value }\n\n // 如果有 dynamicFilter,深拷贝它\n if (clonedVseed[basePath].dynamicFilter && typeof clonedVseed[basePath].dynamicFilter === 'object') {\n clonedVseed[basePath].dynamicFilter = { ...clonedVseed[basePath].dynamicFilter }\n }\n }\n }\n\n return clonedVseed\n}\n\n/**\n * 准备阶段 - 执行动态过滤器代码\n * @description 在 build() 之前调用,用于:\n * 1. 检查是否存在需要执行的 dynamicFilter (有 code 字段)\n * 2. 创建 vseed 的副本,给 dataset 添加 __row_index\n * 3. 收集所有 dynamicFilter 并执行 code\n * 4. 将结果直接写入 dynamicFilter.result\n * 5. 更新 builder.vseed 为处理后的副本\n * @returns Promise<void>\n */\nexport const prepare = async (builder: Builder): Promise<void> => {\n // 幂等性:如果已经准备过,直接返回\n if (builder.isPrepared || !builder.vseed || !builder.vseed?.chartType || !builder.vseed.dataset) {\n return\n }\n\n // 1. 收集原始 vseed 中的所有 dynamicFilter\n const filters = collectDynamicFiltersByKeyPaths(builder.vseed, builder.vseed.chartType)\n if (!filters.length) {\n // 标记为已准备(虽然实际没做什么)\n builder.isPrepared = true\n return\n }\n\n // 2. 针对性深拷贝 vseed(只拷贝包含 dynamicFilter 的路径)\n const clonedVseed = deepCloneDynamicFilterPaths(builder.vseed, builder.vseed.chartType)\n\n // 3. 创建带 __row_index 的 dataset\n const originalDataset = clonedVseed.dataset as any[]\n let datasetWithIndex = originalDataset\n\n // 如果还没有注入 __row_index,创建新的副本\n if (!originalDataset[0] || !(InnerRowIndex in originalDataset[0])) {\n datasetWithIndex = originalDataset.map((item, index) => ({\n ...item,\n [InnerRowIndex]: index,\n }))\n }\n\n // 4. 更新 builder.vseed,使用深拷贝后的 vseed 和带 __row_index 的 dataset\n builder.vseed = {\n ...clonedVseed,\n dataset: datasetWithIndex,\n }\n\n // 5. 重新收集 dynamicFilter(从新的 vseed 中)\n const clonedFilters = collectDynamicFiltersByKeyPaths(builder.vseed, builder.vseed.chartType)\n\n // 6. 执行所有 dynamicFilter 的 code,结果直接写入 filter.result\n try {\n await executeDynamicFiltersAndInject(clonedFilters, datasetWithIndex)\n } catch (e) {\n throw new Error(`Failed to execute dynamic filters: ${(e as Error).message}`)\n }\n\n // 7. 标记为已准备\n builder.isPrepared = true\n}\n"],"names":["generateDynamicFilterKeyPaths","dynamicFilterConfig","result","chartType","baseKeyPaths","Object","basePath","dynamicFilterKeyPathsByChartType","getBasePathsForDeepClone","config","parseKeyPath","path","segment","getValuesByKeyPath","target","segments","current","next","node","value","Array","undefined","collectDynamicFiltersByKeyPaths","paths","isDynamicFilter","executeDynamicFiltersAndInject","filters","dataset","Promise","filter","success","data","error","executeDynamicFilter","deepCloneDynamicFilterPaths","vseed","basePaths","clonedVseed","item","clonedItem","prepare","builder","originalDataset","datasetWithIndex","InnerRowIndex","index","clonedFilters","e","Error"],"mappings":";;AAWA,MAAMA,gCAAgC;IAKpC,MAAMC,sBAA4D;QAChE,OAAO;YAAC;SAAgB;QACxB,YAAY;YAAC;SAAgB;QAC7B,KAAK;YAAC;YAAY;YAAmB;SAAyB;QAC9D,aAAa;YAAC;YAAY;YAAmB;SAAyB;QACtE,YAAY;YAAC;YAAY;YAAmB;SAAyB;QACrE,QAAQ;YAAC;YAAY;YAAmB;S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AAU,IAAI,CAACA,QAAQ,KAAK,IAAI,CAACA,QAAQ,KAAK,EAAE,aAAa,CAACA,QAAQ,KAAK,CAAC,OAAO,EAC7F;IAIF,MAAMf,UAAUJ,gCAAgCmB,QAAQ,KAAK,EAAEA,QAAQ,KAAK,CAAC,SAAS;IACtF,IAAI,CAACf,QAAQ,MAAM,EAAE;QAEnBe,QAAQ,UAAU,GAAG;QACrB;IACF;IAGA,MAAMJ,cAAcH,4BAA4BO,QAAQ,KAAK,EAAEA,QAAQ,KAAK,CAAC,SAAS;IAGtF,MAAMC,kBAAkBL,YAAY,OAAO;IAC3C,IAAIM,mBAAmBD;IAGvB,IAAI,CAACA,eAAe,CAAC,EAAE,IAAI,CAAEE,CAAAA,iBAAiBF,eAAe,CAAC,EAAC,GAC7DC,mBAAmBD,gBAAgB,GAAG,CAAC,CAACJ,MAAMO,QAAW;YACvD,GAAGP,IAAI;YACP,CAACM,cAAc,EAAEC;QACnB;IAIFJ,QAAQ,KAAK,GAAG;QACd,GAAGJ,WAAW;QACd,SAASM;IACX;IAGA,MAAMG,gBAAgBxB,gCAAgCmB,QAAQ,KAAK,EAAEA,QAAQ,KAAK,CAAC,SAAS;IAG5F,IAAI;QACF,MAAMhB,+BAA+BqB,eAAeH;IACtD,EAAE,OAAOI,GAAG;QACV,MAAM,IAAIC,MAAM,CAAC,mCAAmC,EAAGD,EAAY,OAAO,EAAE;IAC9E;IAGAN,QAAQ,UAAU,GAAG;AACvB"}
@@ -31,3 +31,4 @@ export declare const BinStartMeasureId = "__BinStart__";
31
31
  export declare const BinEndMeasureId = "__BinEnd__";
32
32
  export declare const BinCountMeasureId = "__BinCount__";
33
33
  export declare const BinPercentageMeasureId = "__BinPercentage__";
34
+ export declare const InnerRowIndex = "__row_index";
@@ -31,6 +31,7 @@ const BinStartMeasureId = '__BinStart__';
31
31
  const BinEndMeasureId = '__BinEnd__';
32
32
  const BinCountMeasureId = '__BinCount__';
33
33
  const BinPercentageMeasureId = '__BinPercentage__';
34
- export { AngleEncoding, BinCountMeasureId, BinEndMeasureId, BinPercentageMeasureId, BinStartMeasureId, BoxPlotPivotIndicator, ColorEncoding, ColorIdEncoding, DetailEncoding, DimAxisType, FoldMeasureId, FoldMeasureName, FoldMeasureValue, FoldPrimaryMeasureValue, FoldSecondaryMeasureValue, FoldXMeasureId, FoldXMeasureValue, FoldYMeasureId, FoldYMeasureValue, HierarchyEncoding, LowerWhisker, MeasureId, MeasureName, MedianMeasureId, ORIGINAL_DATA, OutliersMeasureId, PlayerEncoding, Q1MeasureValue, Q3MeasureValue, Separator, UpperWhisker, XEncoding, YEncoding };
34
+ const InnerRowIndex = '__row_index';
35
+ export { AngleEncoding, BinCountMeasureId, BinEndMeasureId, BinPercentageMeasureId, BinStartMeasureId, BoxPlotPivotIndicator, ColorEncoding, ColorIdEncoding, DetailEncoding, DimAxisType, FoldMeasureId, FoldMeasureName, FoldMeasureValue, FoldPrimaryMeasureValue, FoldSecondaryMeasureValue, FoldXMeasureId, FoldXMeasureValue, FoldYMeasureId, FoldYMeasureValue, HierarchyEncoding, InnerRowIndex, LowerWhisker, MeasureId, MeasureName, MedianMeasureId, ORIGINAL_DATA, OutliersMeasureId, PlayerEncoding, Q1MeasureValue, Q3MeasureValue, Separator, UpperWhisker, XEncoding, YEncoding };
35
36
 
36
37
  //# sourceMappingURL=constant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dataReshape/constant.js","sources":["webpack://@visactor/vseed/./src/dataReshape/constant.ts"],"sourcesContent":["// Reshape\nexport const ORIGINAL_DATA = '__OriginalData__'\nexport const Separator = '-'\n\n// Measures\nexport const FoldMeasureName = '__MeaName__'\nexport const FoldMeasureId = '__MeaId__'\nexport const FoldMeasureValue = '__MeaValue__'\nexport const MeasureId = FoldMeasureId\nexport const MeasureName = FoldMeasureName\n\n// Measures For DualAxis\nexport const FoldPrimaryMeasureValue = '__MeaPrimaryValue__'\nexport const FoldSecondaryMeasureValue = '__MeaSecondaryValue__'\nexport const DimAxisType = '__Dim_AxisType__'\n\n// Measures For Scatter\nexport const FoldXMeasureValue = '__MeaXValue__'\nexport const FoldYMeasureValue = '__MeaYValue__'\nexport const FoldXMeasureId = '__MeaXId__'\nexport const FoldYMeasureId = '__MeaYId__'\n// Encoding\nexport const XEncoding = '__Dim_X__'\nexport const YEncoding = '__Dim_Y__'\nexport const AngleEncoding = '__Dim_Angle__'\nexport const DetailEncoding = '__Dim_Detail__'\nexport const PlayerEncoding = '__Dim_Player__'\nexport const ColorEncoding = '__Dim_Color__'\nexport const ColorIdEncoding = '__Dim_ColorId__'\nexport const HierarchyEncoding = '__Dim_Hierarchy__'\n\n// Measures For boxPlot\nexport const BoxPlotPivotIndicator = '__BoxPlot_Pivot_Indicator__'\nexport const Q1MeasureValue = '__Q1__'\nexport const Q3MeasureValue = '__Q3__'\nexport const LowerWhisker = '__Lower_Whisker__'\nexport const UpperWhisker = '__Upper_Whisker__'\nexport const OutliersMeasureId = '__Outliers__'\nexport const MedianMeasureId = '__Meadian__'\n\n// Measures For Histogram\nexport const BinStartMeasureId = '__BinStart__'\nexport const BinEndMeasureId = '__BinEnd__'\nexport const BinCountMeasureId = '__BinCount__'\nexport const BinPercentageMeasureId = '__BinPercentage__'\n"],"names":["ORIGINAL_DATA","Separator","FoldMeasureName","FoldMeasureId","FoldMeasureValue","MeasureId","MeasureName","FoldPrimaryMeasureValue","FoldSecondaryMeasureValue","DimAxisType","FoldXMeasureValue","FoldYMeasureValue","FoldXMeasureId","FoldYMeasureId","XEncoding","YEncoding","AngleEncoding","DetailEncoding","PlayerEncoding","ColorEncoding","ColorIdEncoding","HierarchyEncoding","BoxPlotPivotIndicator","Q1MeasureValue","Q3MeasureValue","LowerWhisker","UpperWhisker","OutliersMeasureId","MedianMeasureId","BinStartMeasureId","BinEndMeasureId","BinCountMeasureId","BinPercentageMeasureId"],"mappings":"AACO,MAAMA,gBAAgB;AACtB,MAAMC,YAAY;AAGlB,MAAMC,kBAAkB;AACxB,MAAMC,gBAAgB;AACtB,MAAMC,mBAAmB;AACzB,MAAMC,YAAYF;AAClB,MAAMG,cAAcJ;AAGpB,MAAMK,0BAA0B;AAChC,MAAMC,4BAA4B;AAClC,MAAMC,cAAc;AAGpB,MAAMC,oBAAoB;AAC1B,MAAMC,oBAAoB;AAC1B,MAAMC,iBAAiB;AACvB,MAAMC,iBAAiB;AAEvB,MAAMC,YAAY;AAClB,MAAMC,YAAY;AAClB,MAAMC,gBAAgB;AACtB,MAAMC,iBAAiB;AACvB,MAAMC,iBAAiB;AACvB,MAAMC,gBAAgB;AACtB,MAAMC,kBAAkB;AACxB,MAAMC,oBAAoB;AAG1B,MAAMC,wBAAwB;AAC9B,MAAMC,iBAAiB;AACvB,MAAMC,iBAAiB;AACvB,MAAMC,eAAe;AACrB,MAAMC,eAAe;AACrB,MAAMC,oBAAoB;AAC1B,MAAMC,kBAAkB;AAGxB,MAAMC,oBAAoB;AAC1B,MAAMC,kBAAkB;AACxB,MAAMC,oBAAoB;AAC1B,MAAMC,yBAAyB"}
1
+ {"version":3,"file":"dataReshape/constant.js","sources":["webpack://@visactor/vseed/./src/dataReshape/constant.ts"],"sourcesContent":["// Reshape\nexport const ORIGINAL_DATA = '__OriginalData__'\nexport const Separator = '-'\n\n// Measures\nexport const FoldMeasureName = '__MeaName__'\nexport const FoldMeasureId = '__MeaId__'\nexport const FoldMeasureValue = '__MeaValue__'\nexport const MeasureId = FoldMeasureId\nexport const MeasureName = FoldMeasureName\n\n// Measures For DualAxis\nexport const FoldPrimaryMeasureValue = '__MeaPrimaryValue__'\nexport const FoldSecondaryMeasureValue = '__MeaSecondaryValue__'\nexport const DimAxisType = '__Dim_AxisType__'\n\n// Measures For Scatter\nexport const FoldXMeasureValue = '__MeaXValue__'\nexport const FoldYMeasureValue = '__MeaYValue__'\nexport const FoldXMeasureId = '__MeaXId__'\nexport const FoldYMeasureId = '__MeaYId__'\n// Encoding\nexport const XEncoding = '__Dim_X__'\nexport const YEncoding = '__Dim_Y__'\nexport const AngleEncoding = '__Dim_Angle__'\nexport const DetailEncoding = '__Dim_Detail__'\nexport const PlayerEncoding = '__Dim_Player__'\nexport const ColorEncoding = '__Dim_Color__'\nexport const ColorIdEncoding = '__Dim_ColorId__'\nexport const HierarchyEncoding = '__Dim_Hierarchy__'\n\n// Measures For boxPlot\nexport const BoxPlotPivotIndicator = '__BoxPlot_Pivot_Indicator__'\nexport const Q1MeasureValue = '__Q1__'\nexport const Q3MeasureValue = '__Q3__'\nexport const LowerWhisker = '__Lower_Whisker__'\nexport const UpperWhisker = '__Upper_Whisker__'\nexport const OutliersMeasureId = '__Outliers__'\nexport const MedianMeasureId = '__Meadian__'\n\n// Measures For Histogram\nexport const BinStartMeasureId = '__BinStart__'\nexport const BinEndMeasureId = '__BinEnd__'\nexport const BinCountMeasureId = '__BinCount__'\nexport const BinPercentageMeasureId = '__BinPercentage__'\n\n// Inner row index for code execute\nexport const InnerRowIndex = '__row_index'\n"],"names":["ORIGINAL_DATA","Separator","FoldMeasureName","FoldMeasureId","FoldMeasureValue","MeasureId","MeasureName","FoldPrimaryMeasureValue","FoldSecondaryMeasureValue","DimAxisType","FoldXMeasureValue","FoldYMeasureValue","FoldXMeasureId","FoldYMeasureId","XEncoding","YEncoding","AngleEncoding","DetailEncoding","PlayerEncoding","ColorEncoding","ColorIdEncoding","HierarchyEncoding","BoxPlotPivotIndicator","Q1MeasureValue","Q3MeasureValue","LowerWhisker","UpperWhisker","OutliersMeasureId","MedianMeasureId","BinStartMeasureId","BinEndMeasureId","BinCountMeasureId","BinPercentageMeasureId","InnerRowIndex"],"mappings":"AACO,MAAMA,gBAAgB;AACtB,MAAMC,YAAY;AAGlB,MAAMC,kBAAkB;AACxB,MAAMC,gBAAgB;AACtB,MAAMC,mBAAmB;AACzB,MAAMC,YAAYF;AAClB,MAAMG,cAAcJ;AAGpB,MAAMK,0BAA0B;AAChC,MAAMC,4BAA4B;AAClC,MAAMC,cAAc;AAGpB,MAAMC,oBAAoB;AAC1B,MAAMC,oBAAoB;AAC1B,MAAMC,iBAAiB;AACvB,MAAMC,iBAAiB;AAEvB,MAAMC,YAAY;AAClB,MAAMC,YAAY;AAClB,MAAMC,gBAAgB;AACtB,MAAMC,iBAAiB;AACvB,MAAMC,iBAAiB;AACvB,MAAMC,gBAAgB;AACtB,MAAMC,kBAAkB;AACxB,MAAMC,oBAAoB;AAG1B,MAAMC,wBAAwB;AAC9B,MAAMC,iBAAiB;AACvB,MAAMC,iBAAiB;AACvB,MAAMC,eAAe;AACrB,MAAMC,eAAe;AACrB,MAAMC,oBAAoB;AAC1B,MAAMC,kBAAkB;AAGxB,MAAMC,oBAAoB;AAC1B,MAAMC,kBAAkB;AACxB,MAAMC,oBAAoB;AAC1B,MAAMC,yBAAyB;AAG/B,MAAMC,gBAAgB"}
@@ -1,7 +1,8 @@
1
1
  import type { Datum } from '../types';
2
- import type { DimensionSelector, MeasureSelector, PartialDatumSelector, Selector, Selectors, ValueSelector } from '../types/dataSelector';
2
+ import type { ChartDynamicFilter, ChartDynamicFilterRes, DimensionSelector, MeasureSelector, PartialDatumSelector, Selector, Selectors, TableDynamicFilterRes, TableDynamicFilter, ValueSelector, ValueDynamicFilter } from '../types/dataSelector';
3
+ export type DynamicFilter = TableDynamicFilter | ChartDynamicFilter | ValueDynamicFilter;
4
+ export type DynamicFilterResult = TableDynamicFilterRes[] | ChartDynamicFilterRes[] | number | string;
3
5
  export declare const selector: (vchartDatum: Datum, selector: Selector | Selectors | undefined | null, selectorMode?: "And" | "Or") => boolean;
4
- export declare const selectorDatum: (datum: Datum, selector: Selector | Selectors | undefined | null) => Datum[];
5
6
  export declare const isValueSelector: (selector: Selector) => selector is ValueSelector;
6
7
  export declare const isPartialDatumSelector: (selector: Selector) => selector is PartialDatumSelector;
7
8
  export declare const isMeasureSelector: (selector: Selector) => selector is MeasureSelector;
@@ -10,3 +11,71 @@ export declare const selectByMeasure: (selector: MeasureSelector, datum: Datum)
10
11
  export declare const selectByDmension: (selector: DimensionSelector, datum: Datum) => boolean;
11
12
  export declare const selectByPartial: (selector: PartialDatumSelector, datum: Datum) => boolean;
12
13
  export declare const selectByValue: (selector: ValueSelector, datum: Datum) => boolean;
14
+ /**
15
+ * 识别是否为row-with-field动态过滤器
16
+ */
17
+ export declare const isRowWithFieldDynamicFilter: (selector: any) => selector is TableDynamicFilter;
18
+ /**
19
+ * 识别是否为数值动态过滤器(用于标注线等场景)
20
+ */
21
+ export declare const isValueDynamicFilter: (selector: any) => selector is ValueDynamicFilter;
22
+ /**
23
+ * 识别是否为动态过滤器(通用判断,包含所有类型的动态过滤器)
24
+ */
25
+ export declare const isDynamicFilter: (selector: any) => selector is DynamicFilter;
26
+ /**
27
+ * 执行动态过滤器代码,获取匹配结果
28
+ * @description
29
+ * 阶段1:执行阶段 - 一次性执行 dynamicFilter.code,获取所有匹配结果
30
+ * - TableDynamicFilter → CellSelector[]
31
+ * - ChartDynamicFilter → PartialDatumSelector[]
32
+ * - ValueDynamicFilter → number | string
33
+ *
34
+ * @param filter 动态过滤器配置
35
+ * @param allData 完整数据集
36
+ * @returns 执行结果数组或标量值
37
+ */
38
+ export declare const executeDynamicFilter: (filter: DynamicFilter, allData: Datum[]) => Promise<{
39
+ success: boolean;
40
+ data: DynamicFilterResult;
41
+ error?: string;
42
+ }>;
43
+ /**
44
+ * 匹配动态过滤器结果
45
+ * @description
46
+ * 阶段2:匹配阶段 - 判断当前 datum/cell 是否在执行结果中
47
+ * - 使用 OR 策略:结果数组中任一项匹配即返回 true
48
+ * - 表格场景:检查 { row, field } 是否在 CellSelector[] 中
49
+ * - 图表场景:检查 datum 的维度值是否匹配 PartialDatumSelector[] 中任一项
50
+ * - 数值场景:不适用(ValueDynamicFilter返回标量值,不用于匹配)
51
+ *
52
+ * @param result 动态过滤器执行结果(CellSelector[] 或 PartialDatumSelector[],不包括 ValueDynamicFilter)
53
+ * @param datum 当前数据项
54
+ * @param selectorType 选择器类型(用于区分表格和图表动态过滤器)
55
+ * @returns 是否匹配(OR 策略)
56
+ */
57
+ export declare const matchDynamicFilterResult: (result: DynamicFilterResult, datum: Datum, selectorType?: "table" | "chart") => boolean;
58
+ /**
59
+ * 带有动态过滤器支持的选择器
60
+ * @description
61
+ * 处理流程(两阶段设计):
62
+ *
63
+ * 阶段1 - 执行(Execute):
64
+ * - 在 prepare() 阶段执行,结果写入 dynamicFilter.result
65
+ * - TableDynamicFilter → CellSelector[]
66
+ * - ChartDynamicFilter → PartialDatumSelector[]
67
+ * - ValueDynamicFilter → number | string(用于读取,不用于匹配)
68
+ *
69
+ * 阶段2 - 匹配(Match):
70
+ * - 读取 dynamicFilter.result
71
+ * - 使用 OR 策略:结果数组中任一项匹配即返回 true
72
+ * - 表格:判断 { row, field } 是否在 CellSelector[] 中
73
+ * - 图表:判断 datum 是否匹配 PartialDatumSelector[] 中任一项
74
+ * - 数值:不用于匹配,直接返回 false(数值过滤器在主要用于标注线值,不用于行列选择)
75
+ *
76
+ * @param vchartDatum 单个数据项
77
+ * @param selectorConfig 选择器配置(可包含 DynamicFilter)
78
+ * @param defaultSelector 传统选择器(仅在 DynamicFilter 无结果且有 fallback 时使用)
79
+ * @returns 该数据项是否符合选择条件
80
+ */
81
+ export declare const selectorWithDynamicFilter: (vchartDatum: Datum, selectorConfig: DynamicFilter, defaultSelector?: Selector | Selector[] | null) => boolean;