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.
- package/CHANGELOG.md +127 -0
- package/README.md +20 -11
- package/knowledge/action-card.schema.json +1 -1
- package/knowledge/action-cards.json +1 -1
- package/knowledge/action-cards.schema.json +1 -1
- package/knowledge/extension-authoring.md +2 -1
- package/knowledge/intent-taxonomy.json +1 -1
- package/knowledge/mcp-resources.json +1 -1
- package/knowledge/task-resolver.js +1 -1
- package/package.json +10 -3
- package/src/actions/basic.js +4 -2
- package/src/actions/boxPlots/components.js +14 -4
- package/src/actions/boxPlots/edit.js +31 -5
- package/src/actions/boxPlots/materialize.js +13 -4
- package/src/actions/boxPlots/options.js +48 -16
- package/src/actions/canvas/actions.js +3 -1
- package/src/actions/canvas/fitting.js +211 -0
- package/src/actions/canvas/index.js +2 -0
- package/src/actions/categoryOrder/index.js +18 -6
- package/src/actions/charts/area.js +51 -0
- package/src/actions/charts/bar.js +13 -6
- package/src/actions/charts/beeswarm.js +70 -0
- package/src/actions/charts/density.js +48 -0
- package/src/actions/charts/ecdf.js +186 -0
- package/src/actions/charts/endpoints.js +473 -0
- package/src/actions/charts/heatmap.js +4 -3
- package/src/actions/charts/histogram.js +5 -4
- package/src/actions/charts/horizon.js +73 -0
- package/src/actions/charts/index.js +37 -0
- package/src/actions/charts/interval-regression.js +172 -0
- package/src/actions/charts/line.js +8 -6
- package/src/actions/charts/parallel.js +8 -2
- package/src/actions/charts/pie.js +52 -0
- package/src/actions/charts/polar.js +134 -0
- package/src/actions/charts/radar.js +305 -0
- package/src/actions/charts/radial.js +50 -0
- package/src/actions/charts/raincloud.js +422 -0
- package/src/actions/charts/rug-strip.js +283 -0
- package/src/actions/charts/scatter.js +11 -3
- package/src/actions/charts/shared.js +69 -10
- package/src/actions/composition/actions.js +129 -3
- package/src/actions/coordinates/actions.js +1 -1
- package/src/actions/coordinates/edit.js +76 -0
- package/src/actions/data/bin.js +29 -0
- package/src/actions/data/bin2d.js +57 -185
- package/src/actions/data/complete.js +26 -0
- package/src/actions/data/computed.js +24 -0
- package/src/actions/data/create.js +2 -2
- package/src/actions/data/density.js +12 -20
- package/src/actions/data/derived.js +111 -15
- package/src/actions/data/ecdf.js +38 -0
- package/src/actions/data/edit.js +539 -0
- package/src/actions/data/filter.js +226 -30
- package/src/actions/data/fold.js +24 -0
- package/src/actions/data/impute.js +26 -0
- package/src/actions/data/index.js +38 -0
- package/src/actions/data/interval.js +2 -0
- package/src/actions/data/intervalEdit.js +86 -4
- package/src/actions/data/normalize.js +27 -0
- package/src/actions/data/regression.js +19 -21
- package/src/actions/data/revisionBindings.js +145 -0
- package/src/actions/data/shared.js +20 -4
- package/src/actions/data/stack.js +26 -0
- package/src/actions/data/summary.js +26 -0
- package/src/actions/data/timeUnit.js +4 -1
- package/src/actions/data/window.js +1 -1
- package/src/actions/encodings/appearance.js +32 -13
- package/src/actions/encodings/barWidth.js +8 -0
- package/src/actions/encodings/basic.js +2 -0
- package/src/actions/encodings/channels.js +415 -0
- package/src/actions/encodings/color/continuous.js +19 -59
- package/src/actions/encodings/color/index.js +30 -23
- package/src/actions/encodings/color/layout.js +3 -97
- package/src/actions/encodings/color/policy.js +5 -8
- package/src/actions/encodings/density/resolve.js +37 -5
- package/src/actions/encodings/density.js +124 -34
- package/src/actions/encodings/histogram.js +3 -2
- package/src/actions/encodings/horizon/resolve.js +8 -4
- package/src/actions/encodings/horizon.js +18 -8
- package/src/actions/encodings/index.js +6 -0
- package/src/actions/encodings/offset.js +30 -29
- package/src/actions/encodings/parallel.js +2 -8
- package/src/actions/encodings/position/apply.js +63 -11
- package/src/actions/encodings/position/index.js +52 -6
- package/src/actions/encodings/position/policies/arc.js +14 -0
- package/src/actions/encodings/position/policies/area.js +4 -42
- package/src/actions/encodings/position/policies/bar.js +57 -13
- package/src/actions/encodings/position/resolve.js +88 -26
- package/src/actions/encodings/ranged.js +123 -97
- package/src/actions/encodings/remove.js +44 -34
- package/src/actions/encodings/ruleAppearance.js +24 -32
- package/src/actions/encodings/seriesLayout.js +105 -0
- package/src/actions/encodings/shared.js +107 -37
- package/src/actions/encodings/stroke.js +226 -0
- package/src/actions/encodings/strokeDash.js +9 -6
- package/src/actions/encodings/temporal.js +7 -0
- package/src/actions/encodings/text.js +30 -15
- package/src/actions/errorBands/create.js +41 -8
- package/src/actions/errorBands/edit.js +360 -25
- package/src/actions/errorBars/create.js +56 -17
- package/src/actions/errorBars/edit.js +372 -21
- package/src/actions/facets/actions.js +619 -41
- package/src/actions/facets/derive.js +139 -25
- package/src/actions/gradientPlots/components.js +43 -13
- package/src/actions/gradientPlots/edit.js +14 -4
- package/src/actions/gradientPlots/materialize.js +8 -8
- package/src/actions/gradientPlots/options.js +10 -2
- package/src/actions/guides/applicability.js +28 -19
- package/src/actions/guides/axes/axes.js +4 -3
- package/src/actions/guides/axes/axis.js +18 -18
- package/src/actions/guides/axes/components.js +43 -0
- package/src/actions/guides/axes/edit.js +16 -51
- package/src/actions/guides/axes/labels.js +184 -28
- package/src/actions/guides/axes/lines.js +13 -7
- package/src/actions/guides/axes/parallel/lifecycle.js +117 -0
- package/src/actions/guides/axes/parallel/policy.js +137 -0
- package/src/actions/guides/axes/parallel/resolve.js +50 -25
- package/src/actions/guides/axes/parallel.js +93 -217
- package/src/actions/guides/axes/policy.js +21 -67
- package/src/actions/guides/axes/tickGroups.js +15 -8
- package/src/actions/guides/axes/ticks.js +11 -6
- package/src/actions/guides/axes/titles.js +32 -11
- package/src/actions/guides/basic.js +2 -0
- package/src/actions/guides/facade.js +106 -0
- package/src/actions/guides/facadeAxes.js +200 -0
- package/src/actions/guides/facadeLegend.js +63 -0
- package/src/actions/guides/grids/grid.js +37 -33
- package/src/actions/guides/grids/resolve.js +17 -4
- package/src/actions/guides/guides.js +54 -31
- package/src/actions/guides/legends/blocks.js +426 -0
- package/src/actions/guides/legends/categorical/actions.js +309 -279
- package/src/actions/guides/legends/categorical/components.js +21 -17
- package/src/actions/guides/legends/categorical/index.js +37 -33
- package/src/actions/guides/legends/categorical/layout.js +123 -354
- package/src/actions/guides/legends/categorical/options.js +32 -16
- package/src/actions/guides/legends/categorical/recipes.js +114 -9
- package/src/actions/guides/legends/categorical/resolve.js +30 -15
- package/src/actions/guides/legends/categorical/symbols.js +87 -33
- package/src/actions/guides/legends/continuous/common.js +99 -26
- package/src/actions/guides/legends/continuous/gradient.js +120 -89
- package/src/actions/guides/legends/continuous/index.js +8 -2
- package/src/actions/guides/legends/continuous/interval.js +79 -95
- package/src/actions/guides/legends/continuous/opacity.js +113 -89
- package/src/actions/guides/legends/continuous/stroke.js +525 -0
- package/src/actions/guides/legends/creation.js +40 -0
- package/src/actions/guides/legends/edit.js +321 -90
- package/src/actions/guides/legends/focused.js +2 -2
- package/src/actions/guides/legends/index.js +2 -0
- package/src/actions/guides/legends/lane.js +149 -102
- package/src/actions/guides/legends/lifecycle.js +143 -0
- package/src/actions/guides/legends/remove.js +43 -78
- package/src/actions/guides/legends/sampling.js +140 -0
- package/src/actions/guides/legends/size.js +213 -116
- package/src/actions/guides/legends/strokeWidth.js +121 -73
- package/src/actions/guides/legends/target.js +123 -0
- package/src/actions/guides/legends/transition.js +192 -0
- package/src/actions/guides/polar/axes/facade.js +81 -66
- package/src/actions/guides/polar/axes/labels.js +28 -8
- package/src/actions/guides/polar/axes/lines.js +12 -5
- package/src/actions/guides/polar/axes/shared.js +22 -0
- package/src/actions/guides/polar/axes/ticks.js +6 -5
- package/src/actions/guides/polar/axes/titles.js +6 -5
- package/src/actions/guides/polar/grids.js +8 -8
- package/src/actions/guides/polar/resolve.js +12 -8
- package/src/actions/guides/reuse.js +44 -0
- package/src/actions/guides/tickValues.js +19 -21
- package/src/actions/index.js +15 -2
- package/src/actions/intervals/resolve.js +35 -15
- package/src/actions/marks/arc/actions.js +78 -20
- package/src/actions/marks/area/actions.js +51 -12
- package/src/actions/marks/area/materialize.js +22 -3
- package/src/actions/marks/bar/create.js +11 -2
- package/src/actions/marks/bar/edit.js +20 -3
- package/src/actions/marks/bar/materialize.js +33 -9
- package/src/actions/marks/index.js +14 -0
- package/src/actions/marks/line/actions.js +71 -113
- package/src/actions/marks/line/materialize.js +57 -56
- package/src/actions/marks/point/create.js +8 -2
- package/src/actions/marks/point/edit.js +29 -21
- package/src/actions/marks/point/index.js +1 -0
- package/src/actions/marks/point/jitter.js +3 -0
- package/src/actions/marks/point/materialize.js +154 -16
- package/src/actions/marks/point/packing.js +68 -0
- package/src/actions/marks/rect/actions.js +33 -12
- package/src/actions/marks/references.js +658 -0
- package/src/actions/marks/remove.js +87 -4
- package/src/actions/marks/rule/actions.js +77 -9
- package/src/actions/marks/rule/appearance.js +26 -0
- package/src/actions/marks/shared.js +13 -13
- package/src/actions/marks/text/actions.js +296 -13
- package/src/actions/marks/text/index.js +4 -0
- package/src/actions/marks/text/layout.js +156 -8
- package/src/actions/marks/text/removal.js +173 -0
- package/src/actions/marks/text/selection.js +73 -0
- package/src/actions/marks/tick/actions.js +22 -5
- package/src/actions/primitives/createGraphics.js +3 -1
- package/src/actions/primitives/editGraphics.js +26 -0
- package/src/actions/primitives/semantic.js +3 -2
- package/src/actions/primitives/semanticAction.js +120 -10
- package/src/actions/primitives/semanticValidation/guide.js +10 -0
- package/src/actions/primitives/semanticValidation/index.js +9 -1
- package/src/actions/primitives/semanticValidation/layer.js +23 -1
- package/src/actions/primitives/semanticValidation/scale.js +38 -8
- package/src/actions/regression/components.js +26 -11
- package/src/actions/regression/create.js +11 -3
- package/src/actions/regression/edit.js +40 -13
- package/src/actions/regression/resolve.js +1 -1
- package/src/actions/resources/index.js +7 -0
- package/src/actions/resources/remove.js +172 -0
- package/src/actions/scales/channels.js +212 -0
- package/src/actions/scales/consumers/common.js +21 -54
- package/src/actions/scales/consumers/families.js +28 -14
- package/src/actions/scales/consumers/index.js +42 -4
- package/src/actions/scales/consumers/seriesLayout.js +57 -12
- package/src/actions/scales/create.js +58 -26
- package/src/actions/scales/definitions.js +109 -39
- package/src/actions/scales/edit.js +101 -34
- package/src/actions/scales/editPolicy.js +95 -35
- package/src/actions/scales/index.js +6 -0
- package/src/actions/scales/materialize.js +14 -49
- package/src/actions/scales/offset.js +48 -0
- package/src/actions/scales/parallel.js +71 -0
- package/src/actions/scales/patch.js +1 -1
- package/src/actions/scales/preview.js +140 -0
- package/src/actions/scales/quantitativeColor.js +9 -5
- package/src/actions/selection/actions.js +154 -30
- package/src/actions/selection/index.js +3 -0
- package/src/actions/theme/actions.js +98 -0
- package/src/actions/theme/composition.js +238 -0
- package/src/actions/theme/index.js +16 -0
- package/src/actions/theme/reconcile.js +1130 -0
- package/src/actions/theme/state.js +160 -0
- package/src/actions/titles/actions.js +11 -10
- package/src/actions/titles/resolve.js +1 -40
- package/src/actions/violinPlots/create.js +90 -43
- package/src/actions/violinPlots/edit.js +192 -0
- package/src/actions/violinPlots/index.js +2 -0
- package/src/core/ChartProgram.js +7 -0
- package/src/core/action.js +32 -2
- package/src/core/compositionState.js +141 -8
- package/src/core/programState.js +20 -0
- package/src/core/resourceReferences.js +332 -0
- package/src/core/vocabulary.js +16 -3
- package/src/grammar/aggregate.js +66 -23
- package/src/grammar/arcs.js +58 -1
- package/src/grammar/areaEndpoints.js +46 -0
- package/src/grammar/areaSeries.js +87 -41
- package/src/grammar/bars/aggregate.js +37 -13
- package/src/grammar/bars/geometry.js +44 -0
- package/src/grammar/bars/policy.js +9 -7
- package/src/grammar/bin.js +226 -0
- package/src/grammar/categoryOrder.js +34 -0
- package/src/grammar/complete.js +279 -0
- package/src/grammar/computed.js +351 -0
- package/src/grammar/coordinates.js +37 -0
- package/src/grammar/density.js +239 -37
- package/src/grammar/displayLabels.js +57 -0
- package/src/grammar/ecdf.js +198 -0
- package/src/grammar/facets/dependencies.js +133 -1
- package/src/grammar/facets/guides.js +3 -0
- package/src/grammar/facets/index.js +123 -52
- package/src/grammar/facets/scales.js +15 -18
- package/src/grammar/fold.js +123 -0
- package/src/grammar/horizon.js +6 -4
- package/src/grammar/impute.js +340 -0
- package/src/grammar/interval.js +37 -20
- package/src/grammar/lineSeries.js +20 -63
- package/src/grammar/markFilter.js +22 -4
- package/src/grammar/markLabelSelection.js +57 -0
- package/src/grammar/markLabels.js +110 -0
- package/src/grammar/normalize.js +366 -0
- package/src/grammar/parallelAxisTitles.js +16 -0
- package/src/grammar/pathSeries.js +109 -0
- package/src/grammar/pointPacking.js +183 -0
- package/src/grammar/pointShapes.js +13 -4
- package/src/grammar/polar.js +90 -8
- package/src/grammar/positionDatum.js +12 -0
- package/src/grammar/rects.js +9 -1
- package/src/grammar/regression/derive.js +4 -0
- package/src/grammar/regression/index.js +8 -2
- package/src/grammar/regression/models.js +22 -7
- package/src/grammar/regression/parameters.js +63 -13
- package/src/grammar/rotation.js +29 -0
- package/src/grammar/roundedRect.js +180 -0
- package/src/grammar/rules.js +8 -21
- package/src/grammar/scales/color.js +23 -1
- package/src/grammar/scales/colorConsumers.js +57 -0
- package/src/grammar/scales/continuous.js +2 -2
- package/src/grammar/scales/definition.js +42 -5
- package/src/grammar/scales/discretized.js +11 -5
- package/src/grammar/scales/fields.js +38 -8
- package/src/grammar/scales/index.js +1 -0
- package/src/grammar/scales/mapping.js +2 -0
- package/src/grammar/scales/ordinal.js +12 -3
- package/src/grammar/scales/policies.js +2 -2
- package/src/grammar/scales/radial.js +55 -0
- package/src/grammar/scales/size.js +456 -0
- package/src/grammar/scales/types.js +1 -0
- package/src/grammar/schemas/concreteGraphic.js +14 -2
- package/src/grammar/schemas/graphic.js +15 -0
- package/src/grammar/schemas/graphicBounds.js +179 -30
- package/src/grammar/schemas/semanticPath.js +23 -4
- package/src/grammar/stack.js +170 -0
- package/src/grammar/statisticalReference.js +103 -0
- package/src/grammar/statistics/confidenceInterval.js +101 -0
- package/src/grammar/strokeStyle.js +77 -0
- package/src/grammar/summary.js +245 -0
- package/src/grammar/text.js +22 -16
- package/src/grammar/timeUnit.js +234 -13
- package/src/grammar/transformTopology.js +10 -0
- package/src/grammar/transforms.js +418 -16
- package/src/grammar/valueFormat.js +112 -0
- package/src/grammar/weightedStatistics.js +374 -0
- package/src/grammar/window.js +232 -21
- package/src/layout/aspect.js +80 -0
- package/src/layout/facets.js +100 -12
- package/src/layout/guideCollisions.js +12 -0
- package/src/layout/labels.js +343 -0
- package/src/layout/legend.js +2 -10
- package/src/layout/legendItems.js +102 -0
- package/src/layout/legendLane.js +100 -11
- package/src/materialization/bars/aggregate.js +56 -147
- package/src/materialization/bars/histogram.js +104 -20
- package/src/materialization/bars/ranged.js +19 -3
- package/src/materialization/bars/resolve.js +7 -4
- package/src/materialization/categorySlotOffset.js +40 -0
- package/src/materialization/composition.js +3 -1
- package/src/materialization/compositionSnapshot.js +1 -1
- package/src/materialization/coordinateBounds.js +204 -0
- package/src/materialization/dependencies.js +93 -16
- package/src/materialization/encodings.js +1 -1
- package/src/materialization/facetGuides/legacyCategorical.js +3 -0
- package/src/materialization/facetGuides/placement.js +8 -2
- package/src/materialization/facetGuides/preparation.js +12 -7
- package/src/materialization/facetHeaders.js +346 -0
- package/src/materialization/facets.js +23 -66
- package/src/materialization/guides/layout.js +57 -0
- package/src/materialization/guides/resources.js +28 -2
- package/src/materialization/legends.js +11 -2
- package/src/materialization/marks/capabilities.js +20 -5
- package/src/materialization/marks/grouping.js +52 -0
- package/src/materialization/marks/index.js +68 -27
- package/src/materialization/marks/policies.js +4 -1
- package/src/materialization/rect.js +55 -42
- package/src/materialization/rectConfig.js +5 -1
- package/src/materialization/rowEncoding.js +13 -13
- package/src/materialization/scaleGuideDependencies.js +8 -5
- package/src/materialization/scales/map.js +6 -3
- package/src/materialization/scales/policies/arc.js +42 -0
- package/src/materialization/scales/policies/binnedPosition.js +7 -4
- package/src/materialization/scales/policies/offset.js +50 -8
- package/src/materialization/scales/policies/series.js +5 -1
- package/src/materialization/scales/resolve.js +65 -17
- package/src/materialization/selection/compatibility.js +11 -0
- package/src/materialization/selection/items/arc.js +28 -4
- package/src/materialization/selection/items/bar.js +42 -71
- package/src/materialization/selection/items/common.js +27 -6
- package/src/materialization/selection/items/path.js +3 -13
- package/src/materialization/selection/items/rect.js +35 -8
- package/src/materialization/selection/path.js +1 -1
- package/src/materialization/selection/point.js +3 -1
- package/src/materialization/text.js +324 -14
- package/src/mcp/adapter.js +2 -2
- package/src/renderers/canvas/circle.js +2 -3
- package/src/renderers/canvas/line.js +2 -3
- package/src/renderers/canvas/native.js +4 -4
- package/src/renderers/canvas/path.js +2 -3
- package/src/renderers/canvas/rect.js +2 -3
- package/src/renderers/canvas/stroke.js +11 -0
- package/src/renderers/svg.js +19 -0
- package/src/selectors/datasets.js +44 -0
- package/src/selectors/layers.js +7 -2
- package/src/selectors/scales.js +6 -0
- package/src/theme/defaults.js +140 -0
- package/types/basic.d.ts +17 -2
- package/types/index.d.ts +211 -0
- package/types/program.d.ts +2182 -204
- 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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
|
112
|
+
const directMarks = [
|
|
80
113
|
...(markStep === undefined ? [] : [markStep]),
|
|
81
|
-
...
|
|
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
|
|
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,
|
|
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
|
|
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.
|
|
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?.
|
|
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:
|
|
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:
|
|
138
|
+
target: `${gradientPrefix}Title`,
|
|
134
139
|
property: "y",
|
|
135
|
-
value: source.graphicSpec.objects.
|
|
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.
|
|
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 {
|