ggaction 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +35 -13
  3. package/package.json +18 -7
  4. package/src/actions/boxPlots/create.js +13 -7
  5. package/src/actions/boxPlots/edit.js +31 -35
  6. package/src/actions/boxPlots/materialize.js +3 -0
  7. package/src/actions/boxPlots/options.js +8 -1
  8. package/src/actions/boxPlots/resolve.js +10 -2
  9. package/src/actions/charts/bar.js +50 -0
  10. package/src/actions/charts/heatmap.js +205 -0
  11. package/src/actions/charts/histogram.js +58 -0
  12. package/src/actions/charts/index.js +15 -0
  13. package/src/actions/charts/line.js +69 -0
  14. package/src/actions/charts/parallel.js +76 -0
  15. package/src/actions/charts/scatter.js +56 -0
  16. package/src/actions/charts/shared.js +121 -0
  17. package/src/actions/coordinates/parallel.js +50 -0
  18. package/src/actions/data/bin2d.js +137 -0
  19. package/src/actions/data/density.js +54 -13
  20. package/src/actions/data/derived.js +22 -0
  21. package/src/actions/data/filter.js +5 -0
  22. package/src/actions/data/gradientProfile.js +65 -0
  23. package/src/actions/data/horizon.js +71 -0
  24. package/src/actions/data/index.js +29 -2
  25. package/src/actions/data/window.js +50 -0
  26. package/src/actions/encodings/color/index.js +17 -1
  27. package/src/actions/encodings/color/layout.js +8 -0
  28. package/src/actions/encodings/density/resolve.js +109 -0
  29. package/src/actions/encodings/density.js +193 -88
  30. package/src/actions/encodings/horizon/resolve.js +283 -0
  31. package/src/actions/encodings/horizon.js +364 -0
  32. package/src/actions/encodings/index.js +6 -0
  33. package/src/actions/encodings/parallel.js +115 -0
  34. package/src/actions/encodings/pathOrder.js +131 -0
  35. package/src/actions/encodings/position/apply.js +73 -4
  36. package/src/actions/encodings/position/index.js +15 -2
  37. package/src/actions/encodings/position/policies/arc.js +27 -4
  38. package/src/actions/encodings/position/policies/area.js +33 -2
  39. package/src/actions/encodings/position/policies/index.js +7 -2
  40. package/src/actions/encodings/position/policies/line.js +18 -2
  41. package/src/actions/encodings/position/resolve.js +24 -2
  42. package/src/actions/encodings/ranged.js +3 -1
  43. package/src/actions/encodings/ruleAppearance.js +88 -10
  44. package/src/actions/facets/actions.js +1 -2
  45. package/src/actions/facets/derive.js +33 -3
  46. package/src/actions/facets/replay.js +7 -36
  47. package/src/actions/gradientPlots/components.js +177 -0
  48. package/src/actions/gradientPlots/create.js +96 -0
  49. package/src/actions/gradientPlots/edit.js +153 -0
  50. package/src/actions/gradientPlots/index.js +24 -0
  51. package/src/actions/gradientPlots/materialize.js +287 -0
  52. package/src/actions/gradientPlots/options.js +120 -0
  53. package/src/actions/gradientPlots/paint.js +107 -0
  54. package/src/actions/gradientPlots/rebind.js +51 -0
  55. package/src/actions/gradientPlots/resolve.js +81 -0
  56. package/src/actions/guides/applicability.js +44 -17
  57. package/src/actions/guides/axes/axes.js +37 -3
  58. package/src/actions/guides/axes/index.js +2 -0
  59. package/src/actions/guides/axes/labels.js +11 -6
  60. package/src/actions/guides/axes/parallel/resolve.js +86 -0
  61. package/src/actions/guides/axes/parallel.js +228 -0
  62. package/src/actions/guides/axes/titles.js +11 -8
  63. package/src/actions/guides/guides.js +60 -5
  64. package/src/actions/guides/legends/categorical/actions.js +48 -11
  65. package/src/actions/guides/legends/edit.js +5 -0
  66. package/src/actions/guides/legends/index.js +2 -0
  67. package/src/actions/guides/legends/remove.js +4 -11
  68. package/src/actions/guides/legends/strokeWidth.js +170 -0
  69. package/src/actions/index.js +6 -0
  70. package/src/actions/marks/area/actions.js +60 -136
  71. package/src/actions/marks/area/materialize.js +163 -0
  72. package/src/actions/marks/index.js +5 -1
  73. package/src/actions/marks/line/actions.js +99 -80
  74. package/src/actions/marks/line/materialize.js +146 -0
  75. package/src/actions/marks/point/create.js +76 -0
  76. package/src/actions/marks/point/edit.js +85 -0
  77. package/src/actions/marks/point/index.js +11 -1
  78. package/src/actions/marks/point/jitter.js +72 -0
  79. package/src/actions/marks/point/{actions.js → materialize.js} +175 -170
  80. package/src/actions/marks/rect/actions.js +3 -0
  81. package/src/actions/marks/remove.js +13 -2
  82. package/src/actions/marks/rule/actions.js +25 -3
  83. package/src/actions/marks/text/actions.js +19 -4
  84. package/src/actions/marks/text/index.js +7 -1
  85. package/src/actions/marks/text/layout.js +321 -0
  86. package/src/actions/primitives/semanticValidation/dataset.js +22 -0
  87. package/src/actions/primitives/semanticValidation/guide.js +43 -0
  88. package/src/actions/primitives/semanticValidation/index.js +23 -0
  89. package/src/actions/primitives/semanticValidation/layer.js +74 -0
  90. package/src/actions/primitives/semanticValidation/scale.js +74 -0
  91. package/src/actions/primitives/semanticValidation/shared.js +5 -0
  92. package/src/actions/primitives/semanticValue.js +1 -204
  93. package/src/actions/regression/edit.js +19 -21
  94. package/src/actions/scales/consumers/common.js +18 -0
  95. package/src/actions/scales/consumers/families.js +14 -3
  96. package/src/actions/scales/definitions.js +30 -0
  97. package/src/actions/scales/edit.js +6 -204
  98. package/src/actions/scales/editPolicy.js +214 -0
  99. package/src/actions/scales/materialize.js +1 -1
  100. package/src/actions/scales/patch.js +26 -0
  101. package/src/actions/selection/actions.js +28 -3
  102. package/src/actions/violinPlots/create.js +198 -0
  103. package/src/actions/violinPlots/index.js +5 -0
  104. package/src/core/textMetrics.js +47 -0
  105. package/src/core/vocabulary.js +7 -2
  106. package/src/grammar/arcs.js +49 -12
  107. package/src/grammar/areaSeries.js +41 -5
  108. package/src/grammar/bin2d.js +333 -0
  109. package/src/grammar/categoricalDensity.js +192 -0
  110. package/src/grammar/coordinates.js +1 -1
  111. package/src/grammar/curveCommands.js +3 -1
  112. package/src/grammar/density.js +252 -26
  113. package/src/grammar/facets/dependencies.js +3 -11
  114. package/src/grammar/facets/index.js +3 -1
  115. package/src/grammar/gradientProfile.js +213 -0
  116. package/src/grammar/horizon.js +455 -0
  117. package/src/grammar/jitter.js +197 -0
  118. package/src/grammar/lineSeries.js +69 -0
  119. package/src/grammar/paint.js +88 -0
  120. package/src/grammar/parallelCoordinates.js +213 -0
  121. package/src/grammar/pathOrder.js +35 -0
  122. package/src/grammar/pointShapes.js +24 -0
  123. package/src/grammar/rules.js +1 -0
  124. package/src/grammar/scales/appearance.js +21 -0
  125. package/src/grammar/schemas/concreteGraphic.js +11 -1
  126. package/src/grammar/schemas/graphicBounds.js +19 -37
  127. package/src/grammar/schemas/semanticPath.js +17 -2
  128. package/src/grammar/transforms.js +100 -11
  129. package/src/grammar/window.js +339 -0
  130. package/src/layout/labels.js +270 -0
  131. package/src/layout/text.js +4 -1
  132. package/src/layout/title.js +10 -20
  133. package/src/materialization/dataProvenance.js +56 -2
  134. package/src/materialization/dependencies.js +9 -14
  135. package/src/materialization/guides/resources.js +74 -24
  136. package/src/materialization/horizon.js +29 -0
  137. package/src/materialization/layout.js +15 -0
  138. package/src/materialization/marks/capabilities.js +21 -1
  139. package/src/materialization/marks/index.js +3 -0
  140. package/src/materialization/marks/pathOrder.js +71 -0
  141. package/src/materialization/marks/policies.js +6 -2
  142. package/src/materialization/scaleGuideDependencies.js +8 -0
  143. package/src/materialization/scales/resolve.js +2 -0
  144. package/src/materialization/selection/items/path.js +27 -1
  145. package/src/materialization/selection/items/point.js +1 -5
  146. package/src/materialization/selection/items/rect.js +21 -0
  147. package/src/materialization/selection/styles.js +20 -9
  148. package/src/materialization/text.js +12 -4
  149. package/src/renderers/canvas/fill.js +33 -0
  150. package/src/renderers/canvas/index.js +7 -0
  151. package/src/renderers/canvas/path.js +7 -4
  152. package/src/renderers/canvas/rect.js +9 -3
  153. package/src/selectors/datasets.js +4 -0
  154. package/src/theme/defaults.js +4 -0
  155. package/types/extension.d.ts +6 -0
  156. package/types/index.d.ts +76 -0
  157. package/types/program.d.ts +632 -10
package/CHANGELOG.md CHANGED
@@ -4,6 +4,35 @@ All notable changes to `ggaction` are recorded in this file.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## [0.0.5] - 2026-07-21
8
+
9
+ ### Added
10
+
11
+ - Added complete `createScatterPlot`, `createLinePlot`, `createBarPlot`, `createHistogram`, `createHeatmap`, and
12
+ `createParallelCoordinates` facades that reuse ordinary mark, encoding, scale, coordinate, and guide actions.
13
+ - Added deterministic point jitter, ordered line paths, collision-aware text labels, field-driven rule widths, and
14
+ weighted Polar sectors with immutable rematerialization across data, scale, Canvas, selection, and facet changes.
15
+ - Added window and rectangular 2D-bin data actions, binned heatmaps, categorical density and violin plots, Horizon
16
+ charts, Parallel Coordinates, and density-filled gradient plots with Browser Canvas and Node PNG parity.
17
+ - Added backend-neutral item-local gradient paint, expanded public declarations and action contracts, and runnable
18
+ chart examples for every new capability.
19
+
20
+ ### Changed
21
+
22
+ - Aligned Box Plot with the shared facade inference, ambiguity, public option-type, and opt-in guide contracts while
23
+ preserving its existing omitted-guide behavior.
24
+ - Reorganized source, test, documentation, and internal architecture ownership around explicit policies and capability
25
+ registries without changing the renderer's concrete `graphicSpec` boundary.
26
+ - Expanded public documentation with task-oriented API routing, generated split action references, improved mobile and
27
+ no-JavaScript navigation, complete facade discovery, and release-scoped deployment checks.
28
+
29
+ ### Fixed
30
+
31
+ - Materialized the documented default point radius, made direct quantitative line x/y authoring order-independent, and
32
+ made layered datum rules resolve to the expected full-span geometry instead of an empty result.
33
+ - Kept sticky documentation deep links below the top bar by sharing one computed fragment offset between CSS and the
34
+ page table of contents.
35
+
7
36
  ## [0.0.4] - 2026-07-19
8
37
 
9
38
  ### Changed
@@ -82,6 +111,7 @@ All notable changes to `ggaction` are recorded in this file.
82
111
  - Cartesian charts are the complete current path. Polar semantic tokens exist only where explicitly documented and do
83
112
  not imply complete polar rendering.
84
113
 
114
+ [0.0.5]: https://github.com/ggaction/ggaction/releases/tag/v0.0.5
85
115
  [0.0.4]: https://github.com/ggaction/ggaction/releases/tag/v0.0.4
86
116
  [0.0.3]: https://github.com/ggaction/ggaction/releases/tag/v0.0.3
87
117
  [0.0.2]: https://github.com/ggaction/ggaction/releases/tag/v0.0.2
package/README.md CHANGED
@@ -38,10 +38,13 @@ import { chart } from "ggaction";
38
38
  const program = chart()
39
39
  .createCanvas()
40
40
  .createData({ values: cars })
41
- .createPointMark({ id: "points" })
42
- .encodeX({ field: "Displacement" })
43
- .encodeY({ field: "Acceleration" })
44
- .encodeColor({ field: "Origin" })
41
+ .createScatterPlot({
42
+ id: "points",
43
+ x: "Displacement",
44
+ y: "Acceleration",
45
+ color: "Origin",
46
+ guides: false
47
+ })
45
48
  .createRegression()
46
49
  .createGuides();
47
50
  ```
@@ -74,22 +77,41 @@ const program = chart()
74
77
  margin: { top: 30, right: 130, bottom: 60, left: 70 }
75
78
  })
76
79
  .createData({ values: observations })
77
- .createPointMark()
78
- .encodeX({ field: "displacement" })
79
- .encodeY({ field: "acceleration" })
80
- .encodeColor({ field: "origin" })
81
- .encodeRadius({ value: 4 })
82
- .createGuides();
80
+ .createScatterPlot({
81
+ x: "displacement",
82
+ y: "acceleration",
83
+ color: "origin"
84
+ });
83
85
 
84
86
  const context = document.querySelector("#chart").getContext("2d");
85
87
  render(program, context);
86
88
  ```
87
89
 
88
- For the advanced version, follow the [regression recipe](https://ggaction.github.io/ggaction/recipes/regression-scatterplot/) or open the [runnable example](./examples/cars-regression-scatterplot/).
90
+ Use `createLinePlot`, `createBarPlot`, `createHistogram`, and `createHeatmap` for
91
+ the other basic Cartesian charts. Each facade records the regular mark,
92
+ encoding, and guide actions as trace children, and the same resource-specific
93
+ actions remain available for later edits. See the
94
+ [Basic Charts API](https://ggaction.github.io/ggaction/api/basic-charts/).
95
+
96
+ Use `createParallelCoordinates({ dimensions })` to connect each source row
97
+ across ordered, dimension-local scales and axes. See the
98
+ [Parallel Coordinates API](https://ggaction.github.io/ggaction/api/parallel-coordinates/)
99
+ or the [runnable Cars example](./examples/cars-parallel-coordinates/).
100
+
101
+ For an advanced layered example, follow the [regression recipe](https://ggaction.github.io/ggaction/recipes/regression-scatterplot/)
102
+ or open the [runnable regression example](./examples/cars-regression-scatterplot/).
103
+ To compare category distributions with density-filled strips, read the
104
+ [gradient-plot guide](https://ggaction.github.io/ggaction/api/gradient-plots/)
105
+ or open the [runnable example](./examples/cars-gradient-plot/).
106
+ For symmetric or split density shapes centered on categories, use the
107
+ [violin-plot API](https://ggaction.github.io/ggaction/api/violin-plots/) or the
108
+ [runnable Cars example](./examples/cars-acceleration-violins/).
109
+ For compact signed time-series bands, use `encodeHorizon` on an area mark and
110
+ open the [runnable Gapminder example](./examples/gapminder-horizon/).
89
111
 
90
112
  ## What it supports
91
113
 
92
- - Cartesian and polar charts
114
+ - Cartesian, Polar, and Parallel-coordinate charts
93
115
  - Statistical layers and intervals
94
116
  - Faceting and program composition
95
117
  - Mark selection and coordinated highlighting
@@ -120,7 +142,7 @@ All entries include TypeScript declarations. The default entry is browser-safe;
120
142
 
121
143
  ## Status and development
122
144
 
123
- > **Status:** `0.0.4` is the current experimental public release. APIs may change before `1.0.0`; changes are recorded in the [changelog](./CHANGELOG.md).
145
+ > **Status:** `0.0.5` is the current experimental public release. APIs may change before `1.0.0`; changes are recorded in the [changelog](./CHANGELOG.md).
124
146
 
125
147
  ```bash
126
148
  npm install
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ggaction",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Build charts through immutable, traceable graphical actions.",
5
5
  "license": "MIT",
6
6
  "author": "Hyeon Jeon",
@@ -22,7 +22,7 @@
22
22
  "type": "module",
23
23
  "files": [
24
24
  "src/",
25
- "!src/AGENTS.md",
25
+ "!src/**/AGENTS.md",
26
26
  "types/",
27
27
  "README.md",
28
28
  "CHANGELOG.md",
@@ -54,19 +54,29 @@
54
54
  "test:docs:built": "node scripts/check-built-docs.js _site",
55
55
  "test:docs:browser": "node scripts/test-built-docs.js _site",
56
56
  "test:coverage": "node scripts/run-tests.js coverage",
57
- "test:render": "node test/support/artifacts.js && node scripts/run-tests.js render && node scripts/generate-roadmap-gallery.js && node scripts/test-roadmap-gallery.js",
57
+ "test:render": "node scripts/run-render-tests.js",
58
58
  "assets:readme": "node scripts/generate-readme-demo.js",
59
- "artifacts:gallery": "node scripts/generate-roadmap-gallery.js",
60
- "artifacts:gallery:test": "node scripts/test-roadmap-gallery.js",
59
+ "artifacts:clean": "node test/support/artifacts.js",
60
+ "artifacts:gallery": "node scripts/generate-artifact-gallery.js",
61
+ "artifacts:gallery:test": "node scripts/test-artifact-gallery.js",
61
62
  "docs:images": "node scripts/generate-doc-images.js",
62
63
  "docs:llms": "node scripts/generate-llm-docs.js",
63
64
  "docs:capabilities": "node scripts/generate-doc-capabilities.js",
64
65
  "docs:capabilities:check": "node scripts/generate-doc-capabilities.js --check",
66
+ "docs:actions": "node scripts/generate-doc-action-metadata.js",
67
+ "docs:actions:check": "node scripts/generate-doc-action-metadata.js --check",
68
+ "docs:search": "node scripts/generate-doc-search-index.js",
69
+ "docs:search:check": "node scripts/generate-doc-search-index.js --check",
70
+ "docs:reference": "node scripts/generate-doc-action-reference.js",
71
+ "docs:reference:check": "node scripts/generate-doc-action-reference.js --check",
72
+ "docs:metadata": "node scripts/generate-doc-page-metadata.js",
73
+ "docs:metadata:check": "node scripts/generate-doc-page-metadata.js --check",
74
+ "docs:preflight": "node scripts/check-docs-environment.js",
65
75
  "docs:signatures": "node scripts/generate-doc-signatures.js",
66
76
  "docs:signatures:check": "node scripts/generate-doc-signatures.js --check",
67
- "docs:generate": "npm run docs:signatures && npm run docs:capabilities && npm run docs:images && npm run docs:llms",
77
+ "docs:generate": "npm run docs:signatures && npm run docs:capabilities && npm run docs:actions && npm run docs:reference && npm run docs:metadata && npm run docs:search && npm run docs:images && npm run docs:llms",
68
78
  "docs:build": "bundle exec jekyll build --source docs --destination _site --baseurl /ggaction",
69
- "docs:verify": "npm run docs:generate && npm run test:docs && npm run docs:build && npm run test:docs:built && npm run test:docs:browser",
79
+ "docs:verify": "npm run docs:preflight && npm run docs:generate && npm run test:docs && npm run docs:build && npm run test:docs:built && npm run test:docs:browser",
70
80
  "contracts:catalog": "node scripts/generate-action-catalog.js",
71
81
  "contracts:catalog:check": "node scripts/generate-action-catalog.js --check",
72
82
  "package:check": "node scripts/package-artifact.js --check",
@@ -86,6 +96,7 @@
86
96
  "@napi-rs/canvas": "^1.0.2"
87
97
  },
88
98
  "devDependencies": {
99
+ "@axe-core/playwright": "^4.12.1",
89
100
  "es-module-lexer": "^1.7.0",
90
101
  "gifenc": "^1.0.3",
91
102
  "playwright": "^1.61.1",
@@ -1,7 +1,7 @@
1
1
  import { action } from "../../core/action.js";
2
2
  import { validateKeys } from "../../core/validation.js";
3
- import { findDataset } from "../../selectors/datasets.js";
4
3
  import { findSemanticScale } from "../../selectors/scales.js";
4
+ import { resolveFacadeData } from "../charts/shared.js";
5
5
  import {
6
6
  BOX_PLOT_OPTIONS,
7
7
  boxEncodingArgs,
@@ -9,6 +9,7 @@ import {
9
9
  resolveBoxMedianAppearance,
10
10
  resolveBoxOutlierAppearance,
11
11
  resolveBoxPosition,
12
+ resolveBoxGuides,
12
13
  resolveBoxWhisker,
13
14
  resolveBoxWidth
14
15
  } from "./options.js";
@@ -26,11 +27,14 @@ export const createBoxPlot = action(
26
27
  function (args = {}) {
27
28
  validateKeys(args, BOX_PLOT_OPTIONS, "createBoxPlot");
28
29
  const id = resolveBoxPlotId(this, args.id);
29
- const source = resolveBoxSourceLayer(this, args.target);
30
- const data = args.data ?? source?.data ?? this.context.currentData;
31
- if (findDataset(this, data) === undefined) {
32
- throw new Error("createBoxPlot requires data or one inferable dataset.");
33
- }
30
+ const source = resolveBoxSourceLayer(this, args.target, {
31
+ requiresInference: args.x === undefined || args.y === undefined
32
+ });
33
+ const data = resolveFacadeData(
34
+ this,
35
+ args.data ?? source?.data,
36
+ "createBoxPlot"
37
+ );
34
38
  const x = resolveBoxPosition(args.x, "x") ?? source?.encoding?.x;
35
39
  const y = resolveBoxPosition(args.y, "y") ?? source?.encoding?.y;
36
40
  const whisker = resolveBoxWhisker(args.whisker);
@@ -41,6 +45,7 @@ export const createBoxPlot = action(
41
45
  const box = resolveBoxAppearance(args.box);
42
46
  const median = resolveBoxMedianAppearance(args.median);
43
47
  const outlier = resolveBoxOutlierAppearance(args.outlier);
48
+ const guides = resolveBoxGuides(args.guides);
44
49
  if (x !== undefined && y !== undefined && resolveBoxOrientation(x, y) === undefined) {
45
50
  throw new Error(
46
51
  "createBoxPlot requires one categorical axis and one quantitative axis."
@@ -62,7 +67,8 @@ export const createBoxPlot = action(
62
67
  outliers: args.outliers ?? true,
63
68
  box,
64
69
  median,
65
- outlier
70
+ outlier,
71
+ guides
66
72
  }
67
73
  });
68
74
  if (x !== undefined) {
@@ -4,7 +4,8 @@ import { validateUserId } from "../../core/identifiers.js";
4
4
  import { validateKeys } from "../../core/validation.js";
5
5
  import { BOX_FIELDS, deriveBoxData, normalizeBoxTransform } from
6
6
  "../../grammar/boxPlot.js";
7
- import { hasDataset } from "../../selectors/index.js";
7
+ import { planDerivedDataRevision } from
8
+ "../../materialization/dataProvenance.js";
8
9
  import { findDataset } from "../../selectors/datasets.js";
9
10
  import { findLayer } from "../../selectors/layers.js";
10
11
  import {
@@ -61,14 +62,6 @@ function resolveEditedWhisker(current, value) {
61
62
  return resolveBoxWhisker(candidate, "editBoxPlot");
62
63
  }
63
64
 
64
- function nextRevisionId(program, ownerId, kind) {
65
- let revision = 1;
66
- while (hasDataset(program, `${ownerId}${kind}Revision${revision}`)) {
67
- revision += 1;
68
- }
69
- return `${ownerId}${kind}Revision${revision}`;
70
- }
71
-
72
65
  function removeOwnedMark(program, id) {
73
66
  return program
74
67
  .editSemantic({ property: `layer[${id}]`, remove: true })
@@ -76,10 +69,6 @@ function removeOwnedMark(program, id) {
76
69
  ._withoutMaterializationConfig(["marks", id]);
77
70
  }
78
71
 
79
- function rebindRuleData(program, id, data) {
80
- return program.editSemantic({ property: `layer[${id}].data`, value: data });
81
- }
82
-
83
72
  export const editBoxPlot = action(
84
73
  {
85
74
  op: "editBoxPlot",
@@ -156,7 +145,18 @@ export const editBoxPlot = action(
156
145
  derived.outliers.length > 0;
157
146
 
158
147
  if (revisesData) {
159
- summaryId = nextRevisionId(this, owner.id, "SummaryData");
148
+ const whiskerConfig = next.markConfigs[current.whiskerId];
149
+ const capIds = [
150
+ whiskerConfig.errorBar.lowerCapId,
151
+ whiskerConfig.errorBar.upperCapId
152
+ ].filter(id => id !== undefined);
153
+ const summaryRevision = planDerivedDataRevision(this, {
154
+ owner: owner.id,
155
+ role: "SummaryData",
156
+ previous: current.summaryId,
157
+ consumers: [owner.id, current.whiskerId, ...capIds, current.medianId]
158
+ });
159
+ summaryId = summaryRevision.id;
160
160
  next = next.createBoxSummaryData({
161
161
  id: summaryId,
162
162
  source: current.source,
@@ -166,7 +166,16 @@ export const editBoxPlot = action(
166
166
  ...(whisker.factor === undefined ? {} : { factor: whisker.factor })
167
167
  });
168
168
  if (hasOutliers) {
169
- outlierDataId = nextRevisionId(this, owner.id, "OutlierData");
169
+ const hadOutlierLayer = findLayer(next, current.outlierId) !== undefined;
170
+ const outlierRevision = planDerivedDataRevision(this, {
171
+ owner: owner.id,
172
+ role: "OutlierData",
173
+ ...(current.outlierDataId === undefined
174
+ ? {}
175
+ : { previous: current.outlierDataId }),
176
+ consumers: hadOutlierLayer ? [current.outlierId] : []
177
+ });
178
+ outlierDataId = outlierRevision.id;
170
179
  next = next.createBoxOutlierData({
171
180
  id: outlierDataId,
172
181
  source: current.source,
@@ -175,37 +184,24 @@ export const editBoxPlot = action(
175
184
  whisker: whisker.type,
176
185
  factor: whisker.factor
177
186
  });
187
+ for (const rebind of outlierRevision.rebinds) {
188
+ next = next.rebindLayerData(rebind);
189
+ }
178
190
  } else {
179
191
  outlierDataId = undefined;
180
192
  }
181
193
 
182
- next = next.editSemantic({
183
- property: `layer[${owner.id}].data`,
184
- value: summaryId
185
- });
186
- const whiskerConfig = next.markConfigs[current.whiskerId];
187
- const capIds = [
188
- whiskerConfig.errorBar.lowerCapId,
189
- whiskerConfig.errorBar.upperCapId
190
- ].filter(id => id !== undefined);
191
- next = rebindRuleData(next, current.whiskerId, summaryId)
192
- ._withMarkConfig(current.whiskerId, {
194
+ for (const rebind of summaryRevision.rebinds) {
195
+ next = next.rebindLayerData(rebind);
196
+ }
197
+ next = next._withMarkConfig(current.whiskerId, {
193
198
  ...whiskerConfig,
194
199
  errorBar: { ...whiskerConfig.errorBar, data: summaryId }
195
200
  });
196
- for (const capId of capIds) {
197
- next = rebindRuleData(next, capId, summaryId);
198
- }
199
- next = rebindRuleData(next, current.medianId, summaryId);
200
201
 
201
202
  const hadOutlierLayer = findLayer(next, current.outlierId) !== undefined;
202
203
  if (hadOutlierLayer && !hasOutliers) {
203
204
  next = removeOwnedMark(next, current.outlierId);
204
- } else if (hadOutlierLayer && hasOutliers) {
205
- next = next.editSemantic({
206
- property: `layer[${current.outlierId}].data`,
207
- value: outlierDataId
208
- });
209
205
  } else if (!hadOutlierLayer && hasOutliers) {
210
206
  next = next.createBoxOutliers({
211
207
  id: current.outlierId,
@@ -189,6 +189,9 @@ export const materializeBoxPlot = action(
189
189
  outlierDataId: hasOutliers ? outlierDataId : undefined
190
190
  }
191
191
  });
192
+ if (config.guides !== false) {
193
+ next = next.createGuides(config.guides);
194
+ }
192
195
  return next._withContext({ currentMark: ownerId, currentData: source });
193
196
  }
194
197
  );
@@ -8,10 +8,11 @@ import {
8
8
  } from "../../core/validation.js";
9
9
  import { validatePointShape } from "../../grammar/pointShapes.js";
10
10
  import { DEFAULT_COLORS } from "../../theme/defaults.js";
11
+ import { normalizeGuides } from "../charts/shared.js";
11
12
 
12
13
  export const BOX_PLOT_OPTIONS = Object.freeze([
13
14
  "id", "target", "data", "x", "y", "coordinate", "whisker",
14
- "width", "outliers", "box", "median", "outlier"
15
+ "width", "outliers", "box", "median", "outlier", "guides"
15
16
  ]);
16
17
 
17
18
  const DEFAULT_BOX = Object.freeze({
@@ -52,6 +53,12 @@ export function boxEncodingArgs(value) {
52
53
  };
53
54
  }
54
55
 
56
+ export function resolveBoxGuides(value) {
57
+ return value === undefined
58
+ ? false
59
+ : normalizeGuides(value, "createBoxPlot");
60
+ }
61
+
55
62
  export function resolveBoxWhisker(value, operation = "createBoxPlot") {
56
63
  if (value === undefined) return Object.freeze({ type: "tukey", factor: 1.5 });
57
64
  if (!isPlainObject(value)) {
@@ -11,7 +11,9 @@ export function resolveBoxOrientation(x, y) {
11
11
  return undefined;
12
12
  }
13
13
 
14
- export function resolveBoxSourceLayer(program, target) {
14
+ export function resolveBoxSourceLayer(program, target, {
15
+ requiresInference = true
16
+ } = {}) {
15
17
  if (target !== undefined) {
16
18
  const layer = findLayer(program, validateUserId(target, "Box source layer id"));
17
19
  if (layer === undefined) throw new Error(`Unknown box source layer "${target}".`);
@@ -24,7 +26,13 @@ export function resolveBoxSourceLayer(program, target) {
24
26
  const eligible = program.semanticSpec.layers.filter(
25
27
  layer => layer.encoding?.x !== undefined && layer.encoding?.y !== undefined
26
28
  );
27
- return eligible.length === 1 ? eligible[0] : undefined;
29
+ if (eligible.length === 1) return eligible[0];
30
+ if (eligible.length > 1 && requiresInference) {
31
+ throw new Error(
32
+ "createBoxPlot target is ambiguous; provide target or explicit x and y."
33
+ );
34
+ }
35
+ return undefined;
28
36
  }
29
37
 
30
38
  export function resolveBoxPlotId(program, requested) {
@@ -0,0 +1,50 @@
1
+ import { action } from "../../core/action.js";
2
+ import {
3
+ applyFacadeGuides,
4
+ normalizeAppearance,
5
+ normalizeEncoding,
6
+ normalizeFieldEncoding,
7
+ normalizeGuides,
8
+ normalizeTargetOptions,
9
+ positionArgs,
10
+ resolveFacadeData,
11
+ resolveFacadeId,
12
+ targetArgs,
13
+ validateFacadeOptions
14
+ } from "./shared.js";
15
+
16
+ const OPTIONS = Object.freeze([
17
+ "id", "data", "coordinate", "x", "y", "color", "width", "bar", "guides"
18
+ ]);
19
+ const BAR_OPTIONS = Object.freeze([
20
+ "fill", "opacity", "stroke", "strokeWidth"
21
+ ]);
22
+
23
+ export const createBarPlot = action(
24
+ {
25
+ op: "createBarPlot",
26
+ description: "Create a Cartesian bar plot from existing chart data."
27
+ },
28
+ function (args = {}) {
29
+ validateFacadeOptions(args, OPTIONS, "createBarPlot");
30
+ const id = resolveFacadeId(this, args.id, {
31
+ defaultId: "barPlot",
32
+ operation: "createBarPlot"
33
+ });
34
+ const data = resolveFacadeData(this, args.data, "createBarPlot");
35
+ const bar = normalizeAppearance(args.bar, BAR_OPTIONS, "createBarPlot bar");
36
+ const x = normalizeFieldEncoding(args.x, "createBarPlot x");
37
+ const y = normalizeFieldEncoding(args.y, "createBarPlot y");
38
+ const color = normalizeEncoding(args.color, "createBarPlot color");
39
+ const width = normalizeTargetOptions(args.width, "createBarPlot width");
40
+ const guides = normalizeGuides(args.guides, "createBarPlot");
41
+
42
+ let next = this
43
+ .createBarMark({ id, data, ...bar })
44
+ .encodeX(positionArgs(x, { target: id, coordinate: args.coordinate }))
45
+ .encodeY(positionArgs(y, { target: id, coordinate: args.coordinate }));
46
+ if (color !== undefined) next = next.encodeColor(targetArgs(color, id));
47
+ if (width !== undefined) next = next.encodeBarWidth(targetArgs(width, id));
48
+ return applyFacadeGuides(next, guides);
49
+ }
50
+ );
@@ -0,0 +1,205 @@
1
+ import { action } from "../../core/action.js";
2
+ import { isPlainObject } from "../../core/immutable.js";
3
+ import {
4
+ validateNonEmptyString,
5
+ validateOptionObject
6
+ } from "../../core/validation.js";
7
+ import { requireDataset } from "../../selectors/datasets.js";
8
+ import {
9
+ applyFacadeGuides,
10
+ normalizeAppearance,
11
+ normalizeFieldEncoding,
12
+ normalizeGuides,
13
+ positionArgs,
14
+ resolveFacadeData,
15
+ resolveFacadeId,
16
+ targetArgs,
17
+ validateFacadeOptions
18
+ } from "./shared.js";
19
+
20
+ const OPTIONS = Object.freeze([
21
+ "id", "data", "coordinate", "x", "y", "bin", "color", "rect", "guides"
22
+ ]);
23
+ const RECT_OPTIONS = Object.freeze([
24
+ "opacity", "stroke", "strokeWidth"
25
+ ]);
26
+ const BIN_OPTIONS = Object.freeze([
27
+ "bins", "extent", "includeEmpty"
28
+ ]);
29
+ const BINNED_POSITION_OPTIONS = Object.freeze([
30
+ "field", "fieldType", "scale"
31
+ ]);
32
+ const BINNED_COLOR_OPTIONS = Object.freeze([
33
+ "scale", "palette"
34
+ ]);
35
+
36
+ function normalizeBin(value) {
37
+ if (!isPlainObject(value)) {
38
+ throw new TypeError("createHeatmap bin must be a plain object.");
39
+ }
40
+ validateOptionObject(value, BIN_OPTIONS, "createHeatmap bin");
41
+ return {
42
+ ...value,
43
+ includeEmpty: value.includeEmpty ?? true
44
+ };
45
+ }
46
+
47
+ function normalizeBinnedPosition(value, channel) {
48
+ const label = `createHeatmap ${channel}`;
49
+ const encoding = normalizeFieldEncoding(value, label);
50
+ validateOptionObject(encoding, BINNED_POSITION_OPTIONS, label);
51
+ const field = validateNonEmptyString(encoding.field, `${label} field`);
52
+ const fieldType = encoding.fieldType ?? "quantitative";
53
+ if (fieldType !== "quantitative") {
54
+ throw new Error(`${label} requires a quantitative field.`);
55
+ }
56
+ if (encoding.scale !== undefined && !isPlainObject(encoding.scale)) {
57
+ throw new TypeError(`${label} scale must be a plain object.`);
58
+ }
59
+ return { ...encoding, field, fieldType };
60
+ }
61
+
62
+ function normalizeBinnedColor(value) {
63
+ if (value === undefined) return {};
64
+ if (!isPlainObject(value)) {
65
+ throw new TypeError("createHeatmap binned color must be a plain object.");
66
+ }
67
+ validateOptionObject(value, BINNED_COLOR_OPTIONS, "createHeatmap binned color");
68
+ return { ...value };
69
+ }
70
+
71
+ function resolvedPosition(encoding, field, extent) {
72
+ const scale = encoding.scale ?? {};
73
+ return {
74
+ field,
75
+ fieldType: "quantitative",
76
+ scale: {
77
+ type: "linear",
78
+ nice: false,
79
+ zero: false,
80
+ ...scale,
81
+ domain: scale.domain === undefined || scale.domain === "auto"
82
+ ? extent
83
+ : scale.domain
84
+ }
85
+ };
86
+ }
87
+
88
+ function axisWithTitle(value, text) {
89
+ if (value === false) return false;
90
+ if (value !== undefined && !isPlainObject(value)) {
91
+ throw new TypeError("createHeatmap binned axis must be false or a plain object.");
92
+ }
93
+ if (value?.title !== undefined && !isPlainObject(value.title)) {
94
+ throw new TypeError("createHeatmap binned axis title must be a plain object.");
95
+ }
96
+ return {
97
+ ...value,
98
+ title: {
99
+ text,
100
+ ...value?.title
101
+ }
102
+ };
103
+ }
104
+
105
+ function binnedGuides(guides, xTitle, yTitle) {
106
+ if (guides === false) return false;
107
+ for (const key of ["axes", "legend"]) {
108
+ if (
109
+ guides[key] !== undefined &&
110
+ guides[key] !== false &&
111
+ !isPlainObject(guides[key])
112
+ ) {
113
+ throw new TypeError(
114
+ `createHeatmap guides ${key} must be false or a plain object.`
115
+ );
116
+ }
117
+ }
118
+ const axes = guides.axes === false
119
+ ? false
120
+ : {
121
+ ...guides.axes,
122
+ x: axisWithTitle(guides.axes?.x, xTitle),
123
+ y: axisWithTitle(guides.axes?.y, yTitle)
124
+ };
125
+ const legend = guides.legend === false
126
+ ? false
127
+ : { title: "Count", ...guides.legend };
128
+ return {
129
+ ...guides,
130
+ axes,
131
+ grid: guides.grid ?? false,
132
+ legend
133
+ };
134
+ }
135
+
136
+ function createPreGriddedHeatmap(program, args, { id, data, rect, guides }) {
137
+ const x = normalizeFieldEncoding(args.x, "createHeatmap x");
138
+ const y = normalizeFieldEncoding(args.y, "createHeatmap y");
139
+ const color = normalizeFieldEncoding(args.color, "createHeatmap color");
140
+ const next = program
141
+ .createRectMark({ id, data, ...rect })
142
+ .encodeX(positionArgs(x, { target: id, coordinate: args.coordinate }))
143
+ .encodeY(positionArgs(y, { target: id, coordinate: args.coordinate }))
144
+ .encodeColor(targetArgs(color, id));
145
+ return applyFacadeGuides(next, guides);
146
+ }
147
+
148
+ function createBinnedHeatmap(program, args, { id, data, rect, guides }) {
149
+ const x = normalizeBinnedPosition(args.x, "x");
150
+ const y = normalizeBinnedPosition(args.y, "y");
151
+ const bin = normalizeBin(args.bin);
152
+ const color = normalizeBinnedColor(args.color);
153
+ const resolvedGuides = binnedGuides(guides, x.field, y.field);
154
+ const generatedData = `${id}Bin2DData`;
155
+ const binned = program.createBin2DData({
156
+ id: generatedData,
157
+ source: data,
158
+ x: x.field,
159
+ y: y.field,
160
+ ...bin
161
+ });
162
+ const dataset = requireDataset(binned, generatedData);
163
+ const transform = dataset.transform[0];
164
+ const resolved = transform.resolved;
165
+ const xEncoding = resolvedPosition(x, transform.as.x0, resolved.extent.x);
166
+ const yEncoding = resolvedPosition(y, transform.as.y0, resolved.extent.y);
167
+
168
+ const next = binned
169
+ .createRectMark({ id, data: generatedData, ...rect })
170
+ .encodeX(positionArgs(xEncoding, { target: id, coordinate: args.coordinate }))
171
+ .encodeX2({ target: id, field: transform.as.x1, fieldType: "quantitative" })
172
+ .encodeY(positionArgs(yEncoding, { target: id, coordinate: args.coordinate }))
173
+ .encodeY2({ target: id, field: transform.as.y1, fieldType: "quantitative" })
174
+ .encodeColor({
175
+ target: id,
176
+ field: transform.as.count,
177
+ fieldType: "quantitative",
178
+ ...color
179
+ });
180
+ return applyFacadeGuides(
181
+ next,
182
+ resolvedGuides
183
+ );
184
+ }
185
+
186
+ export const createHeatmap = action(
187
+ {
188
+ op: "createHeatmap",
189
+ description: "Create a pre-gridded or rectangularly binned heatmap."
190
+ },
191
+ function (args = {}) {
192
+ validateFacadeOptions(args, OPTIONS, "createHeatmap");
193
+ const id = resolveFacadeId(this, args.id, {
194
+ defaultId: "heatmap",
195
+ operation: "createHeatmap"
196
+ });
197
+ const data = resolveFacadeData(this, args.data, "createHeatmap");
198
+ const rect = normalizeAppearance(args.rect, RECT_OPTIONS, "createHeatmap rect");
199
+ const guides = normalizeGuides(args.guides, "createHeatmap");
200
+ const shared = { id, data, rect, guides };
201
+ return args.bin === undefined
202
+ ? createPreGriddedHeatmap(this, args, shared)
203
+ : createBinnedHeatmap(this, args, shared);
204
+ }
205
+ );