ggaction 0.0.12 → 0.0.15

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 (378) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/README.md +20 -11
  3. package/knowledge/action-card.schema.json +1 -1
  4. package/knowledge/action-cards.json +1 -1
  5. package/knowledge/action-cards.schema.json +1 -1
  6. package/knowledge/extension-authoring.md +2 -1
  7. package/knowledge/intent-taxonomy.json +1 -1
  8. package/knowledge/mcp-resources.json +1 -1
  9. package/knowledge/task-resolver.js +1 -1
  10. package/package.json +10 -3
  11. package/src/actions/basic.js +4 -2
  12. package/src/actions/boxPlots/components.js +14 -4
  13. package/src/actions/boxPlots/edit.js +31 -5
  14. package/src/actions/boxPlots/materialize.js +13 -4
  15. package/src/actions/boxPlots/options.js +48 -16
  16. package/src/actions/canvas/actions.js +3 -1
  17. package/src/actions/canvas/fitting.js +211 -0
  18. package/src/actions/canvas/index.js +2 -0
  19. package/src/actions/categoryOrder/index.js +18 -6
  20. package/src/actions/charts/area.js +51 -0
  21. package/src/actions/charts/bar.js +13 -6
  22. package/src/actions/charts/beeswarm.js +70 -0
  23. package/src/actions/charts/density.js +48 -0
  24. package/src/actions/charts/ecdf.js +186 -0
  25. package/src/actions/charts/endpoints.js +473 -0
  26. package/src/actions/charts/heatmap.js +4 -3
  27. package/src/actions/charts/histogram.js +5 -4
  28. package/src/actions/charts/horizon.js +73 -0
  29. package/src/actions/charts/index.js +37 -0
  30. package/src/actions/charts/interval-regression.js +172 -0
  31. package/src/actions/charts/line.js +8 -6
  32. package/src/actions/charts/parallel.js +8 -2
  33. package/src/actions/charts/pie.js +52 -0
  34. package/src/actions/charts/polar.js +134 -0
  35. package/src/actions/charts/radar.js +305 -0
  36. package/src/actions/charts/radial.js +50 -0
  37. package/src/actions/charts/raincloud.js +422 -0
  38. package/src/actions/charts/rug-strip.js +283 -0
  39. package/src/actions/charts/scatter.js +11 -3
  40. package/src/actions/charts/shared.js +69 -10
  41. package/src/actions/composition/actions.js +129 -3
  42. package/src/actions/coordinates/actions.js +1 -1
  43. package/src/actions/coordinates/edit.js +76 -0
  44. package/src/actions/data/bin.js +29 -0
  45. package/src/actions/data/bin2d.js +57 -185
  46. package/src/actions/data/complete.js +26 -0
  47. package/src/actions/data/computed.js +24 -0
  48. package/src/actions/data/create.js +2 -2
  49. package/src/actions/data/density.js +12 -20
  50. package/src/actions/data/derived.js +111 -15
  51. package/src/actions/data/ecdf.js +38 -0
  52. package/src/actions/data/edit.js +539 -0
  53. package/src/actions/data/filter.js +226 -30
  54. package/src/actions/data/fold.js +24 -0
  55. package/src/actions/data/impute.js +26 -0
  56. package/src/actions/data/index.js +38 -0
  57. package/src/actions/data/interval.js +2 -0
  58. package/src/actions/data/intervalEdit.js +86 -4
  59. package/src/actions/data/normalize.js +27 -0
  60. package/src/actions/data/regression.js +19 -21
  61. package/src/actions/data/revisionBindings.js +145 -0
  62. package/src/actions/data/shared.js +20 -4
  63. package/src/actions/data/stack.js +26 -0
  64. package/src/actions/data/summary.js +26 -0
  65. package/src/actions/data/timeUnit.js +4 -1
  66. package/src/actions/data/window.js +1 -1
  67. package/src/actions/encodings/appearance.js +32 -13
  68. package/src/actions/encodings/barWidth.js +8 -0
  69. package/src/actions/encodings/basic.js +2 -0
  70. package/src/actions/encodings/channels.js +415 -0
  71. package/src/actions/encodings/color/continuous.js +19 -59
  72. package/src/actions/encodings/color/index.js +30 -23
  73. package/src/actions/encodings/color/layout.js +3 -97
  74. package/src/actions/encodings/color/policy.js +5 -8
  75. package/src/actions/encodings/density/resolve.js +37 -5
  76. package/src/actions/encodings/density.js +124 -34
  77. package/src/actions/encodings/histogram.js +3 -2
  78. package/src/actions/encodings/horizon/resolve.js +8 -4
  79. package/src/actions/encodings/horizon.js +18 -8
  80. package/src/actions/encodings/index.js +6 -0
  81. package/src/actions/encodings/offset.js +30 -29
  82. package/src/actions/encodings/parallel.js +2 -8
  83. package/src/actions/encodings/position/apply.js +63 -11
  84. package/src/actions/encodings/position/index.js +52 -6
  85. package/src/actions/encodings/position/policies/arc.js +14 -0
  86. package/src/actions/encodings/position/policies/area.js +4 -42
  87. package/src/actions/encodings/position/policies/bar.js +57 -13
  88. package/src/actions/encodings/position/resolve.js +88 -26
  89. package/src/actions/encodings/ranged.js +123 -97
  90. package/src/actions/encodings/remove.js +44 -34
  91. package/src/actions/encodings/ruleAppearance.js +24 -32
  92. package/src/actions/encodings/seriesLayout.js +105 -0
  93. package/src/actions/encodings/shared.js +107 -37
  94. package/src/actions/encodings/stroke.js +226 -0
  95. package/src/actions/encodings/strokeDash.js +9 -6
  96. package/src/actions/encodings/temporal.js +7 -0
  97. package/src/actions/encodings/text.js +30 -15
  98. package/src/actions/errorBands/create.js +41 -8
  99. package/src/actions/errorBands/edit.js +360 -25
  100. package/src/actions/errorBars/create.js +56 -17
  101. package/src/actions/errorBars/edit.js +372 -21
  102. package/src/actions/facets/actions.js +619 -41
  103. package/src/actions/facets/derive.js +139 -25
  104. package/src/actions/gradientPlots/components.js +43 -13
  105. package/src/actions/gradientPlots/edit.js +14 -4
  106. package/src/actions/gradientPlots/materialize.js +8 -8
  107. package/src/actions/gradientPlots/options.js +10 -2
  108. package/src/actions/guides/applicability.js +28 -19
  109. package/src/actions/guides/axes/axes.js +4 -3
  110. package/src/actions/guides/axes/axis.js +18 -18
  111. package/src/actions/guides/axes/components.js +43 -0
  112. package/src/actions/guides/axes/edit.js +16 -51
  113. package/src/actions/guides/axes/labels.js +184 -28
  114. package/src/actions/guides/axes/lines.js +13 -7
  115. package/src/actions/guides/axes/parallel/lifecycle.js +117 -0
  116. package/src/actions/guides/axes/parallel/policy.js +137 -0
  117. package/src/actions/guides/axes/parallel/resolve.js +50 -25
  118. package/src/actions/guides/axes/parallel.js +93 -217
  119. package/src/actions/guides/axes/policy.js +21 -67
  120. package/src/actions/guides/axes/tickGroups.js +15 -8
  121. package/src/actions/guides/axes/ticks.js +11 -6
  122. package/src/actions/guides/axes/titles.js +32 -11
  123. package/src/actions/guides/basic.js +2 -0
  124. package/src/actions/guides/facade.js +106 -0
  125. package/src/actions/guides/facadeAxes.js +200 -0
  126. package/src/actions/guides/facadeLegend.js +63 -0
  127. package/src/actions/guides/grids/grid.js +37 -33
  128. package/src/actions/guides/grids/resolve.js +17 -4
  129. package/src/actions/guides/guides.js +54 -31
  130. package/src/actions/guides/legends/blocks.js +426 -0
  131. package/src/actions/guides/legends/categorical/actions.js +309 -279
  132. package/src/actions/guides/legends/categorical/components.js +21 -17
  133. package/src/actions/guides/legends/categorical/index.js +37 -33
  134. package/src/actions/guides/legends/categorical/layout.js +123 -354
  135. package/src/actions/guides/legends/categorical/options.js +32 -16
  136. package/src/actions/guides/legends/categorical/recipes.js +114 -9
  137. package/src/actions/guides/legends/categorical/resolve.js +30 -15
  138. package/src/actions/guides/legends/categorical/symbols.js +87 -33
  139. package/src/actions/guides/legends/continuous/common.js +99 -26
  140. package/src/actions/guides/legends/continuous/gradient.js +120 -89
  141. package/src/actions/guides/legends/continuous/index.js +8 -2
  142. package/src/actions/guides/legends/continuous/interval.js +79 -95
  143. package/src/actions/guides/legends/continuous/opacity.js +113 -89
  144. package/src/actions/guides/legends/continuous/stroke.js +525 -0
  145. package/src/actions/guides/legends/creation.js +40 -0
  146. package/src/actions/guides/legends/edit.js +321 -90
  147. package/src/actions/guides/legends/focused.js +2 -2
  148. package/src/actions/guides/legends/index.js +2 -0
  149. package/src/actions/guides/legends/lane.js +149 -102
  150. package/src/actions/guides/legends/lifecycle.js +143 -0
  151. package/src/actions/guides/legends/remove.js +43 -78
  152. package/src/actions/guides/legends/sampling.js +140 -0
  153. package/src/actions/guides/legends/size.js +213 -116
  154. package/src/actions/guides/legends/strokeWidth.js +121 -73
  155. package/src/actions/guides/legends/target.js +123 -0
  156. package/src/actions/guides/legends/transition.js +192 -0
  157. package/src/actions/guides/polar/axes/facade.js +81 -66
  158. package/src/actions/guides/polar/axes/labels.js +28 -8
  159. package/src/actions/guides/polar/axes/lines.js +12 -5
  160. package/src/actions/guides/polar/axes/shared.js +22 -0
  161. package/src/actions/guides/polar/axes/ticks.js +6 -5
  162. package/src/actions/guides/polar/axes/titles.js +6 -5
  163. package/src/actions/guides/polar/grids.js +8 -8
  164. package/src/actions/guides/polar/resolve.js +12 -8
  165. package/src/actions/guides/reuse.js +44 -0
  166. package/src/actions/guides/tickValues.js +19 -21
  167. package/src/actions/index.js +15 -2
  168. package/src/actions/intervals/resolve.js +35 -15
  169. package/src/actions/marks/arc/actions.js +78 -20
  170. package/src/actions/marks/area/actions.js +51 -12
  171. package/src/actions/marks/area/materialize.js +22 -3
  172. package/src/actions/marks/bar/create.js +11 -2
  173. package/src/actions/marks/bar/edit.js +20 -3
  174. package/src/actions/marks/bar/materialize.js +33 -9
  175. package/src/actions/marks/index.js +14 -0
  176. package/src/actions/marks/line/actions.js +71 -113
  177. package/src/actions/marks/line/materialize.js +57 -56
  178. package/src/actions/marks/point/create.js +8 -2
  179. package/src/actions/marks/point/edit.js +29 -21
  180. package/src/actions/marks/point/index.js +1 -0
  181. package/src/actions/marks/point/jitter.js +3 -0
  182. package/src/actions/marks/point/materialize.js +154 -16
  183. package/src/actions/marks/point/packing.js +68 -0
  184. package/src/actions/marks/rect/actions.js +33 -12
  185. package/src/actions/marks/references.js +658 -0
  186. package/src/actions/marks/remove.js +87 -4
  187. package/src/actions/marks/rule/actions.js +77 -9
  188. package/src/actions/marks/rule/appearance.js +26 -0
  189. package/src/actions/marks/shared.js +13 -13
  190. package/src/actions/marks/text/actions.js +296 -13
  191. package/src/actions/marks/text/index.js +4 -0
  192. package/src/actions/marks/text/layout.js +156 -8
  193. package/src/actions/marks/text/removal.js +173 -0
  194. package/src/actions/marks/text/selection.js +73 -0
  195. package/src/actions/marks/tick/actions.js +22 -5
  196. package/src/actions/primitives/createGraphics.js +3 -1
  197. package/src/actions/primitives/editGraphics.js +26 -0
  198. package/src/actions/primitives/semantic.js +3 -2
  199. package/src/actions/primitives/semanticAction.js +120 -10
  200. package/src/actions/primitives/semanticValidation/guide.js +10 -0
  201. package/src/actions/primitives/semanticValidation/index.js +9 -1
  202. package/src/actions/primitives/semanticValidation/layer.js +23 -1
  203. package/src/actions/primitives/semanticValidation/scale.js +38 -8
  204. package/src/actions/regression/components.js +26 -11
  205. package/src/actions/regression/create.js +11 -3
  206. package/src/actions/regression/edit.js +40 -13
  207. package/src/actions/regression/resolve.js +1 -1
  208. package/src/actions/resources/index.js +7 -0
  209. package/src/actions/resources/remove.js +172 -0
  210. package/src/actions/scales/channels.js +212 -0
  211. package/src/actions/scales/consumers/common.js +21 -54
  212. package/src/actions/scales/consumers/families.js +28 -14
  213. package/src/actions/scales/consumers/index.js +42 -4
  214. package/src/actions/scales/consumers/seriesLayout.js +57 -12
  215. package/src/actions/scales/create.js +58 -26
  216. package/src/actions/scales/definitions.js +109 -39
  217. package/src/actions/scales/edit.js +101 -34
  218. package/src/actions/scales/editPolicy.js +95 -35
  219. package/src/actions/scales/index.js +6 -0
  220. package/src/actions/scales/materialize.js +14 -49
  221. package/src/actions/scales/offset.js +48 -0
  222. package/src/actions/scales/parallel.js +71 -0
  223. package/src/actions/scales/patch.js +1 -1
  224. package/src/actions/scales/preview.js +140 -0
  225. package/src/actions/scales/quantitativeColor.js +9 -5
  226. package/src/actions/selection/actions.js +154 -30
  227. package/src/actions/selection/index.js +3 -0
  228. package/src/actions/theme/actions.js +98 -0
  229. package/src/actions/theme/composition.js +238 -0
  230. package/src/actions/theme/index.js +16 -0
  231. package/src/actions/theme/reconcile.js +1130 -0
  232. package/src/actions/theme/state.js +160 -0
  233. package/src/actions/titles/actions.js +11 -10
  234. package/src/actions/titles/resolve.js +1 -40
  235. package/src/actions/violinPlots/create.js +90 -43
  236. package/src/actions/violinPlots/edit.js +192 -0
  237. package/src/actions/violinPlots/index.js +2 -0
  238. package/src/core/ChartProgram.js +7 -0
  239. package/src/core/action.js +32 -2
  240. package/src/core/compositionState.js +141 -8
  241. package/src/core/programState.js +20 -0
  242. package/src/core/resourceReferences.js +332 -0
  243. package/src/core/vocabulary.js +16 -3
  244. package/src/grammar/aggregate.js +66 -23
  245. package/src/grammar/arcs.js +58 -1
  246. package/src/grammar/areaEndpoints.js +46 -0
  247. package/src/grammar/areaSeries.js +87 -41
  248. package/src/grammar/bars/aggregate.js +37 -13
  249. package/src/grammar/bars/geometry.js +44 -0
  250. package/src/grammar/bars/policy.js +9 -7
  251. package/src/grammar/bin.js +226 -0
  252. package/src/grammar/categoryOrder.js +34 -0
  253. package/src/grammar/complete.js +279 -0
  254. package/src/grammar/computed.js +351 -0
  255. package/src/grammar/coordinates.js +37 -0
  256. package/src/grammar/density.js +239 -37
  257. package/src/grammar/displayLabels.js +57 -0
  258. package/src/grammar/ecdf.js +198 -0
  259. package/src/grammar/facets/dependencies.js +133 -1
  260. package/src/grammar/facets/guides.js +3 -0
  261. package/src/grammar/facets/index.js +123 -52
  262. package/src/grammar/facets/scales.js +15 -18
  263. package/src/grammar/fold.js +123 -0
  264. package/src/grammar/horizon.js +6 -4
  265. package/src/grammar/impute.js +340 -0
  266. package/src/grammar/interval.js +37 -20
  267. package/src/grammar/lineSeries.js +20 -63
  268. package/src/grammar/markFilter.js +22 -4
  269. package/src/grammar/markLabelSelection.js +57 -0
  270. package/src/grammar/markLabels.js +110 -0
  271. package/src/grammar/normalize.js +366 -0
  272. package/src/grammar/parallelAxisTitles.js +16 -0
  273. package/src/grammar/pathSeries.js +109 -0
  274. package/src/grammar/pointPacking.js +183 -0
  275. package/src/grammar/pointShapes.js +13 -4
  276. package/src/grammar/polar.js +90 -8
  277. package/src/grammar/positionDatum.js +12 -0
  278. package/src/grammar/rects.js +9 -1
  279. package/src/grammar/regression/derive.js +4 -0
  280. package/src/grammar/regression/index.js +8 -2
  281. package/src/grammar/regression/models.js +22 -7
  282. package/src/grammar/regression/parameters.js +63 -13
  283. package/src/grammar/rotation.js +29 -0
  284. package/src/grammar/roundedRect.js +180 -0
  285. package/src/grammar/rules.js +8 -21
  286. package/src/grammar/scales/color.js +23 -1
  287. package/src/grammar/scales/colorConsumers.js +57 -0
  288. package/src/grammar/scales/continuous.js +2 -2
  289. package/src/grammar/scales/definition.js +42 -5
  290. package/src/grammar/scales/discretized.js +11 -5
  291. package/src/grammar/scales/fields.js +38 -8
  292. package/src/grammar/scales/index.js +1 -0
  293. package/src/grammar/scales/mapping.js +2 -0
  294. package/src/grammar/scales/ordinal.js +12 -3
  295. package/src/grammar/scales/policies.js +2 -2
  296. package/src/grammar/scales/radial.js +55 -0
  297. package/src/grammar/scales/size.js +456 -0
  298. package/src/grammar/scales/types.js +1 -0
  299. package/src/grammar/schemas/concreteGraphic.js +14 -2
  300. package/src/grammar/schemas/graphic.js +15 -0
  301. package/src/grammar/schemas/graphicBounds.js +179 -30
  302. package/src/grammar/schemas/semanticPath.js +23 -4
  303. package/src/grammar/stack.js +170 -0
  304. package/src/grammar/statisticalReference.js +103 -0
  305. package/src/grammar/statistics/confidenceInterval.js +101 -0
  306. package/src/grammar/strokeStyle.js +77 -0
  307. package/src/grammar/summary.js +245 -0
  308. package/src/grammar/text.js +22 -16
  309. package/src/grammar/timeUnit.js +234 -13
  310. package/src/grammar/transformTopology.js +10 -0
  311. package/src/grammar/transforms.js +418 -16
  312. package/src/grammar/valueFormat.js +112 -0
  313. package/src/grammar/weightedStatistics.js +374 -0
  314. package/src/grammar/window.js +232 -21
  315. package/src/layout/aspect.js +80 -0
  316. package/src/layout/facets.js +100 -12
  317. package/src/layout/guideCollisions.js +12 -0
  318. package/src/layout/labels.js +343 -0
  319. package/src/layout/legend.js +2 -10
  320. package/src/layout/legendItems.js +102 -0
  321. package/src/layout/legendLane.js +100 -11
  322. package/src/materialization/bars/aggregate.js +56 -147
  323. package/src/materialization/bars/histogram.js +104 -20
  324. package/src/materialization/bars/ranged.js +19 -3
  325. package/src/materialization/bars/resolve.js +7 -4
  326. package/src/materialization/categorySlotOffset.js +40 -0
  327. package/src/materialization/composition.js +3 -1
  328. package/src/materialization/compositionSnapshot.js +1 -1
  329. package/src/materialization/coordinateBounds.js +204 -0
  330. package/src/materialization/dependencies.js +93 -16
  331. package/src/materialization/encodings.js +1 -1
  332. package/src/materialization/facetGuides/legacyCategorical.js +3 -0
  333. package/src/materialization/facetGuides/placement.js +8 -2
  334. package/src/materialization/facetGuides/preparation.js +12 -7
  335. package/src/materialization/facetHeaders.js +346 -0
  336. package/src/materialization/facets.js +23 -66
  337. package/src/materialization/guides/layout.js +57 -0
  338. package/src/materialization/guides/resources.js +28 -2
  339. package/src/materialization/legends.js +11 -2
  340. package/src/materialization/marks/capabilities.js +20 -5
  341. package/src/materialization/marks/grouping.js +52 -0
  342. package/src/materialization/marks/index.js +68 -27
  343. package/src/materialization/marks/policies.js +4 -1
  344. package/src/materialization/rect.js +55 -42
  345. package/src/materialization/rectConfig.js +5 -1
  346. package/src/materialization/rowEncoding.js +13 -13
  347. package/src/materialization/scaleGuideDependencies.js +8 -5
  348. package/src/materialization/scales/map.js +6 -3
  349. package/src/materialization/scales/policies/arc.js +42 -0
  350. package/src/materialization/scales/policies/binnedPosition.js +7 -4
  351. package/src/materialization/scales/policies/offset.js +50 -8
  352. package/src/materialization/scales/policies/series.js +5 -1
  353. package/src/materialization/scales/resolve.js +65 -17
  354. package/src/materialization/selection/compatibility.js +11 -0
  355. package/src/materialization/selection/items/arc.js +28 -4
  356. package/src/materialization/selection/items/bar.js +42 -71
  357. package/src/materialization/selection/items/common.js +27 -6
  358. package/src/materialization/selection/items/path.js +3 -13
  359. package/src/materialization/selection/items/rect.js +35 -8
  360. package/src/materialization/selection/path.js +1 -1
  361. package/src/materialization/selection/point.js +3 -1
  362. package/src/materialization/text.js +324 -14
  363. package/src/mcp/adapter.js +2 -2
  364. package/src/renderers/canvas/circle.js +2 -3
  365. package/src/renderers/canvas/line.js +2 -3
  366. package/src/renderers/canvas/native.js +4 -4
  367. package/src/renderers/canvas/path.js +2 -3
  368. package/src/renderers/canvas/rect.js +2 -3
  369. package/src/renderers/canvas/stroke.js +11 -0
  370. package/src/renderers/svg.js +19 -0
  371. package/src/selectors/datasets.js +44 -0
  372. package/src/selectors/layers.js +7 -2
  373. package/src/selectors/scales.js +6 -0
  374. package/src/theme/defaults.js +140 -0
  375. package/types/basic.d.ts +17 -2
  376. package/types/index.d.ts +211 -0
  377. package/types/program.d.ts +2182 -204
  378. package/src/materialization/bars/grouped.js +0 -144
@@ -0,0 +1,204 @@
1
+ import { isSourceOwnedText } from "../grammar/text.js";
2
+ import { resolvePolarFrame } from "../grammar/polar.js";
3
+ import { resolveEffectiveBounds } from "../layout/aspect.js";
4
+ import { resolveGraphicBounds } from "../layout/canvas.js";
5
+ import { findCoordinate, requireCoordinate } from "../selectors/coordinates.js";
6
+ import { findSemanticScale } from "../selectors/scales.js";
7
+
8
+ const DATA_CHANNELS = Object.freeze(["x", "y"]);
9
+ const SECONDARY_CHANNELS = Object.freeze({ x2: "x", y2: "y" });
10
+
11
+ function samePair(left, right) {
12
+ return left.x === right.x && left.y === right.y;
13
+ }
14
+
15
+ export function resolveDataAspectScalePair(program, target) {
16
+ const coordinate = typeof target === "string"
17
+ ? requireCoordinate(program, target)
18
+ : target;
19
+ if (coordinate.type !== "cartesian") {
20
+ throw new Error("Coordinate data aspect requires a Cartesian coordinate.");
21
+ }
22
+ const layers = program.semanticSpec.layers.filter(layer =>
23
+ layer.coordinate === coordinate.id &&
24
+ !isSourceOwnedText(layer) &&
25
+ DATA_CHANNELS.some(channel => layer.encoding?.[channel] !== undefined)
26
+ );
27
+ if (layers.length === 0) {
28
+ throw new Error(
29
+ `Coordinate "${coordinate.id}" data aspect requires active x and y consumers.`
30
+ );
31
+ }
32
+ const pairs = layers.map(layer => {
33
+ for (const channel of DATA_CHANNELS) {
34
+ const encoding = layer.encoding?.[channel];
35
+ if (
36
+ encoding?.scale === undefined ||
37
+ encoding.fieldType !== "quantitative"
38
+ ) {
39
+ throw new Error(
40
+ `Coordinate "${coordinate.id}" data aspect requires quantitative x and y scale consumers.`
41
+ );
42
+ }
43
+ }
44
+ for (const [secondary, primary] of Object.entries(SECONDARY_CHANNELS)) {
45
+ const encoding = layer.encoding?.[secondary];
46
+ if (encoding !== undefined && (
47
+ encoding.fieldType !== "quantitative" ||
48
+ encoding.scale !== layer.encoding[primary].scale
49
+ )) {
50
+ throw new Error(
51
+ `Coordinate "${coordinate.id}" data aspect requires ${secondary} to share its quantitative ${primary} scale.`
52
+ );
53
+ }
54
+ }
55
+ return { x: layer.encoding.x.scale, y: layer.encoding.y.scale };
56
+ });
57
+ if (pairs.some(pair => !samePair(pair, pairs[0]))) {
58
+ throw new Error(
59
+ `Coordinate "${coordinate.id}" data aspect requires one consistent x/y scale pair.`
60
+ );
61
+ }
62
+ const scales = {
63
+ x: findSemanticScale(program, pairs[0].x),
64
+ y: findSemanticScale(program, pairs[0].y)
65
+ };
66
+ for (const channel of DATA_CHANNELS) {
67
+ if (scales[channel]?.type !== "linear") {
68
+ throw new Error(
69
+ `Coordinate data aspect requires a linear ${channel} scale.`
70
+ );
71
+ }
72
+ }
73
+ return Object.freeze({
74
+ x: pairs[0].x,
75
+ y: pairs[0].y
76
+ });
77
+ }
78
+
79
+ export function findDataAspectCoordinatesForScale(program, scaleId) {
80
+ return program.semanticSpec.coordinates.filter(coordinate => {
81
+ if (coordinate.aspect?.mode !== "data") return false;
82
+ const pair = resolveDataAspectScalePair(program, coordinate);
83
+ return pair.x === scaleId || pair.y === scaleId;
84
+ });
85
+ }
86
+
87
+ function sameNumericPair(left, right) {
88
+ return Array.isArray(left) && left.length === 2 &&
89
+ left.every((value, index) => Number.isFinite(value) &&
90
+ Math.abs(value - right[index]) <= 1e-9);
91
+ }
92
+
93
+ function validateExplicitDataRanges(program, pair, bounds) {
94
+ const expected = {
95
+ x: [bounds.x, bounds.x + bounds.width],
96
+ y: [bounds.y + bounds.height, bounds.y]
97
+ };
98
+ for (const channel of DATA_CHANNELS) {
99
+ const scale = findSemanticScale(program, pair[channel]);
100
+ if (scale.range === "auto") continue;
101
+ const directed = scale.reverse === true
102
+ ? [...expected[channel]].reverse()
103
+ : expected[channel];
104
+ if (!sameNumericPair(scale.range, directed)) {
105
+ throw new Error(
106
+ `Coordinate data aspect conflicts with explicit ${channel} scale range "${scale.id}".`
107
+ );
108
+ }
109
+ }
110
+ }
111
+
112
+ export function resolveCoordinateBounds(program, target, {
113
+ resolvedScales = program.resolvedScales
114
+ } = {}) {
115
+ const allocated = resolveGraphicBounds(program);
116
+ if (target === undefined) return allocated;
117
+ const coordinate = requireCoordinate(program, target);
118
+ const aspect = coordinate.aspect;
119
+ if (aspect === undefined || aspect === "auto") return allocated;
120
+ if (aspect.mode !== "data") {
121
+ return resolveEffectiveBounds(allocated, aspect);
122
+ }
123
+ const pair = resolveDataAspectScalePair(program, coordinate);
124
+ const x = resolvedScales[pair.x];
125
+ const y = resolvedScales[pair.y];
126
+ if (x?.type !== "linear" || y?.type !== "linear") {
127
+ throw new Error(
128
+ `Coordinate "${coordinate.id}" data aspect requires resolved linear x and y scales.`
129
+ );
130
+ }
131
+ const bounds = resolveEffectiveBounds(allocated, aspect, {
132
+ x: x.domain,
133
+ y: y.domain
134
+ });
135
+ validateExplicitDataRanges(program, pair, bounds);
136
+ return bounds;
137
+ }
138
+
139
+ export function resolveCoordinatePolarFrame(program, target, options) {
140
+ const coordinate = requireCoordinate(program, target);
141
+ if (coordinate.type !== "polar") {
142
+ throw new Error(`Coordinate "${coordinate.id}" is not Polar.`);
143
+ }
144
+ return resolvePolarFrame(
145
+ resolveCoordinateBounds(program, coordinate.id, options),
146
+ coordinate.polarFrame
147
+ );
148
+ }
149
+
150
+ function consumerCoordinateIds(consumers) {
151
+ return [...new Set(consumers.map(consumer => consumer.layer.coordinate))];
152
+ }
153
+
154
+ function sameBounds(left, right) {
155
+ return ["x", "y", "width", "height"].every(
156
+ property => Math.abs(left[property] - right[property]) <= 1e-9
157
+ );
158
+ }
159
+
160
+ export function resolveScaleConsumerBounds(program, consumers, options) {
161
+ const coordinateIds = consumerCoordinateIds(consumers);
162
+ if (coordinateIds.length === 0) return resolveGraphicBounds(program);
163
+ const allocated = resolveGraphicBounds(program);
164
+ const bounds = coordinateIds.map(id =>
165
+ id === undefined || findCoordinate(program, id) === undefined
166
+ ? allocated
167
+ : resolveCoordinateBounds(program, id, options)
168
+ );
169
+ if (bounds.slice(1).some(candidate => !sameBounds(candidate, bounds[0]))) {
170
+ throw new Error(
171
+ "A position scale cannot be shared across coordinates with different effective bounds."
172
+ );
173
+ }
174
+ return bounds[0];
175
+ }
176
+
177
+ export function resolveGuideCoordinateBounds(program, {
178
+ coordinate,
179
+ scale,
180
+ channel,
181
+ resolvedScales = program.resolvedScales
182
+ }) {
183
+ let target = coordinate;
184
+ if (target === undefined && scale !== undefined) {
185
+ const candidates = new Set();
186
+ for (const layer of program.semanticSpec.layers) {
187
+ if (isSourceOwnedText(layer)) continue;
188
+ if (layer.encoding?.[channel]?.scale === scale) {
189
+ candidates.add(layer.coordinate);
190
+ }
191
+ }
192
+ if (candidates.has(undefined)) {
193
+ throw new Error("Guide scale consumers require stored coordinates.");
194
+ }
195
+ if (candidates.size > 1) {
196
+ throw new Error("Guide bounds found no unique compatible coordinate.");
197
+ }
198
+ target = candidates.values().next().value;
199
+ }
200
+ if (target !== undefined && findCoordinate(program, target) === undefined) {
201
+ throw new Error(`Unknown coordinate "${target}".`);
202
+ }
203
+ return resolveCoordinateBounds(program, target, { resolvedScales });
204
+ }
@@ -1,12 +1,16 @@
1
+ import { withGuideLayoutTransaction } from "./guides/layout.js";
1
2
  import {
2
3
  canDeferScaleConsumerApplication,
4
+ getLayerScaleIds,
3
5
  getExistingMarkRematerializationStep,
4
6
  getMarkMaterializationStep,
5
- getSourceDependentMarkSteps
7
+ getScaleConsumerMarkSteps,
8
+ getSourceDependentMarkSteps,
9
+ reusePlannedMarkScales
6
10
  } from "./marks/index.js";
7
- import { requireLayer } from "../selectors/layers.js";
11
+ import { findLayer, requireLayer } from "../selectors/layers.js";
8
12
  import {
9
- applyMaterializationPlan,
13
+ applyMaterializationPlan as executeMaterializationPlan,
10
14
  buildMaterializationPlan
11
15
  } from "./planner.js";
12
16
  import { hasMaterializedLegend } from "./legends.js";
@@ -15,13 +19,7 @@ import {
15
19
  planScaleGuideRematerialization
16
20
  } from "./scaleGuideDependencies.js";
17
21
  import { planLayoutRematerialization } from "./layout.js";
18
-
19
- function layerScaleIds(layer) {
20
- return [
21
- ...Object.values(layer.encoding ?? {}).map(encoding => encoding?.scale),
22
- ...(layer.encoding?.parallel?.dimensions ?? []).map(dimension => dimension.scale)
23
- ].filter(scale => scale !== undefined);
24
- }
22
+ import { requireCoordinate } from "../selectors/coordinates.js";
25
23
 
26
24
  export function planCanvasRematerialization(program) {
27
25
  const marks = [];
@@ -38,7 +36,7 @@ export function planCanvasRematerialization(program) {
38
36
  if (needsCanvasScaleRematerialization(program, scale)) {
39
37
  const deferredConsumers = program.semanticSpec.layers.filter(layer =>
40
38
  canDeferScaleConsumerApplication(layer) &&
41
- layerScaleIds(layer).includes(scale.id)
39
+ getLayerScaleIds(layer).includes(scale.id)
42
40
  );
43
41
  const canDeferMarks = deferredConsumers.length === 0 ||
44
42
  deferredConsumers.every(layer => deferredMarkIds.has(layer.id));
@@ -64,9 +62,44 @@ export function planCanvasRematerialization(program) {
64
62
  return buildMaterializationPlan({ scales, marks, guides, layout });
65
63
  }
66
64
 
65
+ export function planCoordinateRematerialization(program, target) {
66
+ requireCoordinate(program, target);
67
+ const layers = program.semanticSpec.layers.filter(
68
+ layer => layer.coordinate === target
69
+ );
70
+ const scaleIds = [...new Set(layers.flatMap(layer => [
71
+ ...["x", "y", "x2", "y2", "theta", "radius"].map(
72
+ channel => layer.encoding?.[channel]?.scale
73
+ ),
74
+ ...(layer.encoding?.parallel?.dimensions ?? []).map(
75
+ dimension => dimension.scale
76
+ )
77
+ ]).filter(id => id !== undefined))];
78
+ const directMarks = layers
79
+ .map(layer => getMarkMaterializationStep(program, layer))
80
+ .filter(step => step !== undefined);
81
+ const marks = [
82
+ ...directMarks,
83
+ ...directMarks.flatMap(step =>
84
+ getSourceDependentMarkSteps(program, step.args.id)
85
+ )
86
+ ];
87
+ return buildMaterializationPlan({
88
+ scales: scaleIds.map(id => ({
89
+ op: "rematerializeScale",
90
+ args: { id, guides: false, marks: false }
91
+ })),
92
+ marks: reusePlannedMarkScales(program, marks, scaleIds),
93
+ guides: scaleIds.flatMap(id =>
94
+ planScaleGuideRematerialization(program, id)
95
+ ),
96
+ layout: planLayoutRematerialization(program)
97
+ });
98
+ }
99
+
67
100
  export function planLayerDataRematerialization(program, id) {
68
101
  const layer = requireLayer(program, id);
69
- const scaleIds = [...new Set(layerScaleIds(layer))];
102
+ const scaleIds = [...new Set(getLayerScaleIds(layer))];
70
103
  const markStep = getMarkMaterializationStep(program, layer);
71
104
  const scales = scaleIds.map(scale => ({
72
105
  op: "rematerializeScale",
@@ -76,15 +109,19 @@ export function planLayerDataRematerialization(program, id) {
76
109
  ...(markStep === undefined ? {} : { marks: false })
77
110
  }
78
111
  }));
79
- const marks = [
112
+ const directMarks = [
80
113
  ...(markStep === undefined ? [] : [markStep]),
81
- ...getSourceDependentMarkSteps(program, id)
114
+ ...getScaleConsumerMarkSteps(program, scaleIds)
115
+ ];
116
+ const marks = [
117
+ ...directMarks,
118
+ ...directMarks.flatMap(step => getSourceDependentMarkSteps(program, step.args.id))
82
119
  ];
83
120
  if (scales.length > 0 || marks.length > 0) {
84
121
  const guides = scaleIds.flatMap(scale =>
85
122
  planScaleGuideRematerialization(program, scale)
86
123
  );
87
- return buildMaterializationPlan({ scales, marks, guides });
124
+ return buildMaterializationPlan({ scales, marks: reusePlannedMarkScales(program, marks, scaleIds), guides });
88
125
  }
89
126
  const existingStep = getExistingMarkRematerializationStep(program, layer);
90
127
  return buildMaterializationPlan({
@@ -99,5 +136,45 @@ export function applyLayerDataRematerialization(program, id) {
99
136
  );
100
137
  }
101
138
 
102
- export { applyMaterializationPlan } from "./planner.js";
139
+ export function applyLayerEmptyDataView(program, id) {
140
+ requireLayer(program, id);
141
+ const targets = [
142
+ id,
143
+ ...getSourceDependentMarkSteps(program, id).map(step => step.args.id)
144
+ ];
145
+ let next = program;
146
+ for (const target of new Set(targets)) {
147
+ const graphic = next.graphicSpec.objects[target];
148
+ if (graphic === undefined) continue;
149
+ next = graphic.type === "collection"
150
+ ? next.editGraphics({ target, property: "items", value: [] })
151
+ : next.editGraphics({ target, property: "length", value: 0 });
152
+ }
153
+ return next;
154
+ }
155
+
156
+ export function applyDetachedScaleRematerialization(program, previousLayers) {
157
+ const retained = new Set(program.semanticSpec.layers.flatMap(getLayerScaleIds));
158
+ const scaleIds = [...new Set(previousLayers.flatMap(layer => {
159
+ const current = findLayer(program, layer.id);
160
+ const currentIds = current === undefined ? [] : getLayerScaleIds(current);
161
+ return getLayerScaleIds(layer).filter(id => !currentIds.includes(id) && retained.has(id));
162
+ }))];
163
+ if (scaleIds.length === 0) return program;
164
+ const directMarks = getScaleConsumerMarkSteps(program, scaleIds);
165
+ return applyMaterializationPlan(program, buildMaterializationPlan({
166
+ scales: scaleIds.map(id => ({
167
+ op: "rematerializeScale", args: { id, guides: false, marks: false }
168
+ })),
169
+ marks: [
170
+ ...directMarks,
171
+ ...directMarks.flatMap(step => getSourceDependentMarkSteps(program, step.args.id))
172
+ ],
173
+ guides: scaleIds.flatMap(id => planScaleGuideRematerialization(program, id))
174
+ }));
175
+ }
176
+
177
+ export function applyMaterializationPlan(program, plan) {
178
+ return withGuideLayoutTransaction(program, next => executeMaterializationPlan(next, plan));
179
+ }
103
180
  export { planScaleGuideRematerialization };
@@ -25,7 +25,7 @@ export function planEncodingRematerialization(program, {
25
25
  );
26
26
  const marks = [
27
27
  ...directMarks,
28
- ...getSourceDependentMarkSteps(program, target)
28
+ ...directMarks.flatMap(step => getSourceDependentMarkSteps(program, step.args.id))
29
29
  ];
30
30
 
31
31
  const guides = [];
@@ -29,6 +29,9 @@ function collection(program, id, items) {
29
29
  }
30
30
 
31
31
  export function resolveLegacyCategoricalLegend(program) {
32
+ if (program.semanticSpec.layers.some(layer =>
33
+ layer.encoding?.stroke?.scale !== undefined
34
+ )) return undefined;
32
35
  const encodings = program.semanticSpec.layers.flatMap(layer =>
33
36
  layer.encoding?.color === undefined
34
37
  ? []
@@ -46,10 +46,16 @@ function legendTranslation(prepared, plot, layout) {
46
46
  y: layout.legend.y - prepared.bounds.top
47
47
  };
48
48
  }
49
- const strips = prepared.source.graphicSpec.objects.colorGradientStrips;
49
+ const gradientKind = prepared.kinds?.find(kind =>
50
+ ["gradient", "strokeGradient"].includes(kind)
51
+ );
52
+ const prefix = gradientKind === "strokeGradient"
53
+ ? "strokeGradient"
54
+ : "colorGradient";
55
+ const strips = prepared.source.graphicSpec.objects[`${prefix}Strips`];
50
56
  if (strips?.items?.[0] !== undefined) {
51
57
  const properties = strips.items[0].properties;
52
- const length = prepared.source.guideConfigs.legend.gradient.gradient.length;
58
+ const length = prepared.source.guideConfigs.legend[gradientKind].gradient.length;
53
59
  return {
54
60
  x: layout.legend.x - (position === "left"
55
61
  ? prepared.bounds.left
@@ -35,7 +35,7 @@ function legendCandidates(program) {
35
35
  const layer = color[0];
36
36
  return {
37
37
  target: layer.id,
38
- channels: ["color", "shape", "strokeDash"].filter(
38
+ channels: ["color", "stroke", "shape", "strokeDash"].filter(
39
39
  channel => layer.encoding?.[channel]?.scale !== undefined
40
40
  )
41
41
  };
@@ -45,7 +45,7 @@ function legendCandidates(program) {
45
45
  "Shared facet legend requires one unambiguous color legend target."
46
46
  );
47
47
  }
48
- for (const channel of ["shape", "strokeDash", "size", "opacity"]) {
48
+ for (const channel of ["stroke", "shape", "strokeDash", "size", "opacity"]) {
49
49
  const candidates = layers.filter(
50
50
  layer => layer.encoding?.[channel]?.scale !== undefined
51
51
  );
@@ -105,9 +105,14 @@ function prepareAutoLegendSource(child) {
105
105
  }
106
106
  const scale = findSemanticScale(
107
107
  source,
108
- findLayer(source, request.target)?.encoding?.color?.scale
108
+ findLayer(source, request.target)?.encoding?.[
109
+ request.channels.includes("color") ? "color" : "stroke"
110
+ ]?.scale
109
111
  );
110
112
  const gradient = scale?.type === "sequential";
113
+ const gradientPrefix = request.channels.includes("color")
114
+ ? "colorGradient"
115
+ : "strokeGradient";
111
116
  source = source.createLegend({
112
117
  target: request.target,
113
118
  channels: request.channels,
@@ -122,7 +127,7 @@ function prepareAutoLegendSource(child) {
122
127
  const resolved = source.resolvedScales[scale.id];
123
128
  source = source
124
129
  .editGraphics({
125
- target: "colorGradientLabels",
130
+ target: `${gradientPrefix}Labels`,
126
131
  property: "text",
127
132
  value: formatDistinctNumericSamples(
128
133
  continuousValues(resolved.domain, 5),
@@ -130,9 +135,9 @@ function prepareAutoLegendSource(child) {
130
135
  )
131
136
  })
132
137
  .editGraphics({
133
- target: "colorGradientTitle",
138
+ target: `${gradientPrefix}Title`,
134
139
  property: "y",
135
- value: source.graphicSpec.objects.colorGradientTitle.properties.y + 8
140
+ value: source.graphicSpec.objects[`${gradientPrefix}Title`].properties.y + 8
136
141
  });
137
142
  }
138
143
  return source;
@@ -196,7 +201,7 @@ export function prepareSharedFacetLegend(program) {
196
201
  if (bounds === undefined) {
197
202
  throw new Error("Shared facet legend has no measurable concrete bounds.");
198
203
  }
199
- const gradient = kinds.includes("gradient");
204
+ const gradient = kinds.some(kind => ["gradient", "strokeGradient"].includes(kind));
200
205
  const placement = promotedLegendPlacement(source, kinds);
201
206
  const width = Math.ceil(bounds.right - bounds.left);
202
207
  return {