ggaction 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +12 -1
- package/package.json +6 -1
- package/src/actions/boxPlots/components.js +3 -3
- package/src/actions/boxPlots/edit.js +277 -0
- package/src/actions/boxPlots/index.js +2 -0
- package/src/actions/boxPlots/materialize.js +12 -1
- package/src/actions/boxPlots/options.js +25 -14
- package/src/actions/canvas/actions.js +21 -17
- package/src/actions/composition/actions.js +247 -0
- package/src/actions/composition/index.js +1 -0
- package/src/actions/coordinates/actions.js +2 -5
- package/src/actions/data/density.js +7 -1
- package/src/actions/data/filter.js +3 -1
- package/src/actions/encodings/appearance.js +11 -0
- package/src/actions/encodings/barWidth.js +5 -3
- package/src/actions/encodings/color.js +120 -25
- package/src/actions/encodings/index.js +2 -0
- package/src/actions/encodings/offset.js +90 -72
- package/src/actions/encodings/position/apply.js +66 -0
- package/src/actions/encodings/position/policies/arc.js +26 -0
- package/src/actions/encodings/position/policies/bar.js +9 -5
- package/src/actions/encodings/position/policies/index.js +5 -1
- package/src/actions/encodings/position/policies/line.js +20 -3
- package/src/actions/encodings/position/resolve.js +57 -8
- package/src/actions/encodings/position.js +44 -90
- package/src/actions/encodings/ranged.js +28 -6
- package/src/actions/encodings/shared.js +17 -21
- package/src/actions/encodings/text.js +73 -0
- package/src/actions/errorBands/create.js +37 -29
- package/src/actions/errorBands/edit.js +206 -0
- package/src/actions/errorBands/index.js +9 -0
- package/src/actions/errorBands/options.js +39 -0
- package/src/actions/errorBars/create.js +50 -43
- package/src/actions/errorBars/edit.js +130 -0
- package/src/actions/errorBars/index.js +3 -0
- package/src/actions/errorBars/options.js +52 -0
- package/src/actions/facets/actions.js +162 -0
- package/src/actions/facets/derive.js +200 -0
- package/src/actions/facets/guides.js +16 -0
- package/src/actions/facets/index.js +1 -0
- package/src/actions/facets/replay.js +69 -0
- package/src/actions/guides/applicability.js +113 -0
- package/src/actions/guides/axes/axes.js +70 -16
- package/src/actions/guides/axes/edit.js +126 -0
- package/src/actions/guides/axes/index.js +12 -0
- package/src/actions/guides/axes/labels.js +21 -18
- package/src/actions/guides/axes/remove.js +60 -0
- package/src/actions/guides/axes/tickGroups.js +7 -5
- package/src/actions/guides/axes/ticks.js +9 -4
- package/src/actions/guides/axes/titles.js +7 -5
- package/src/actions/guides/grids/grid.js +144 -15
- package/src/actions/guides/grids/resolve.js +5 -13
- package/src/actions/guides/guides.js +17 -75
- package/src/actions/guides/index.js +6 -0
- package/src/actions/guides/legends/categorical/actions.js +48 -9
- package/src/actions/guides/legends/categorical/components.js +16 -16
- package/src/actions/guides/legends/categorical/index.js +14 -14
- package/src/actions/guides/legends/categorical/layout.js +3 -1
- package/src/actions/guides/legends/categorical/options.js +2 -5
- package/src/actions/guides/legends/categorical/resolve.js +2 -2
- package/src/actions/guides/legends/categorical/symbols.js +14 -14
- package/src/actions/guides/legends/continuous/common.js +7 -7
- package/src/actions/guides/legends/continuous/interval.js +5 -5
- package/src/actions/guides/legends/edit.js +2 -6
- package/src/actions/guides/legends/focused.js +63 -0
- package/src/actions/guides/legends/index.js +4 -0
- package/src/actions/guides/legends/remove.js +64 -0
- package/src/actions/guides/legends/size.js +12 -14
- package/src/actions/guides/polar/axes/facade.js +219 -0
- package/src/actions/guides/polar/axes/labels.js +188 -0
- package/src/actions/guides/polar/axes/lines.js +113 -0
- package/src/actions/guides/polar/axes/shared.js +112 -0
- package/src/actions/guides/polar/axes/ticks.js +164 -0
- package/src/actions/guides/polar/axes/titles.js +165 -0
- package/src/actions/guides/polar/axes.js +55 -0
- package/src/actions/guides/polar/grids.js +252 -0
- package/src/actions/guides/polar/index.js +2 -0
- package/src/actions/guides/polar/resolve.js +269 -0
- package/src/actions/index.js +4 -0
- package/src/actions/marks/arc/actions.js +239 -0
- package/src/actions/marks/arc/index.js +1 -0
- package/src/actions/marks/{area.js → area/actions.js} +51 -38
- package/src/actions/marks/area/index.js +4 -0
- package/src/actions/marks/bar/create.js +26 -5
- package/src/actions/marks/bar/materialize.js +25 -31
- package/src/actions/marks/index.js +12 -4
- package/src/actions/marks/lifecycle.js +27 -0
- package/src/actions/marks/line/actions.js +373 -0
- package/src/actions/marks/line/index.js +1 -0
- package/src/actions/marks/{point.js → point/actions.js} +67 -108
- package/src/actions/marks/point/index.js +1 -0
- package/src/actions/marks/rect/actions.js +165 -0
- package/src/actions/marks/rect/index.js +1 -0
- package/src/actions/marks/remove.js +214 -0
- package/src/actions/marks/{rule.js → rule/actions.js} +34 -28
- package/src/actions/marks/rule/index.js +1 -0
- package/src/actions/marks/shared.js +156 -25
- package/src/actions/marks/text/actions.js +192 -0
- package/src/actions/marks/text/index.js +1 -0
- package/src/actions/primitives/createGraphics.js +13 -6
- package/src/actions/primitives/editGraphics.js +10 -3
- package/src/actions/primitives/semantic.js +26 -3
- package/src/actions/primitives/semanticValue.js +25 -3
- package/src/actions/regression/components.js +1 -1
- package/src/actions/regression/create.js +18 -1
- package/src/actions/regression/edit.js +247 -0
- package/src/actions/regression/index.js +3 -0
- package/src/actions/regression/resolve.js +3 -1
- package/src/actions/scales/consumers.js +15 -6
- package/src/actions/scales/definitions.js +13 -4
- package/src/actions/scales/edit.js +42 -19
- package/src/actions/scales/materialize.js +57 -408
- package/src/actions/selection/actions.js +38 -24
- package/src/actions/selection/index.js +2 -0
- package/src/actions/titles/actions.js +63 -2
- package/src/actions/titles/index.js +2 -0
- package/src/actions/titles/resolve.js +12 -17
- package/src/composition.js +10 -0
- package/src/core/ChartProgram.js +200 -2
- package/src/core/action.js +10 -0
- package/src/core/validation.js +16 -0
- package/src/core/vocabulary.js +154 -4
- package/src/grammar/arcs.js +154 -0
- package/src/grammar/bars/aggregate.js +2 -2
- package/src/grammar/bars/geometry.js +3 -3
- package/src/grammar/bars/policy.js +7 -1
- package/src/grammar/coordinates.js +3 -7
- package/src/grammar/density.js +20 -1
- package/src/grammar/facets/dependencies.js +185 -0
- package/src/grammar/facets/guides.js +257 -0
- package/src/grammar/facets/scales.js +254 -0
- package/src/grammar/facets.js +122 -0
- package/src/grammar/lineSeries.js +111 -3
- package/src/grammar/polar.js +102 -0
- package/src/grammar/polarGuides.js +243 -0
- package/src/grammar/polarLineCommands.js +43 -0
- package/src/grammar/polarPaths.js +161 -0
- package/src/grammar/positionCompatibility.js +18 -2
- package/src/grammar/rects.js +26 -0
- package/src/grammar/scales/continuous.js +6 -1
- package/src/grammar/scales/fields.js +7 -0
- package/src/grammar/scales/ordinal.js +5 -2
- package/src/grammar/scales/policies.js +1 -1
- package/src/grammar/schemas/graphic.js +1 -1
- package/src/grammar/schemas/graphicBounds.js +64 -9
- package/src/grammar/schemas/graphicTree.js +44 -10
- package/src/grammar/schemas/semanticPath.js +31 -9
- package/src/grammar/seriesLayout.js +13 -2
- package/src/grammar/text.js +71 -0
- package/src/grammar/ticks.js +50 -13
- package/src/index.js +1 -0
- package/src/layout/composition.js +310 -0
- package/src/layout/facets.js +131 -0
- package/src/layout/title.js +6 -0
- package/src/materialization/bars/aggregate.js +5 -2
- package/src/materialization/bars/grouped.js +75 -37
- package/src/materialization/composition.js +152 -0
- package/src/materialization/compositionSnapshot.js +114 -0
- package/src/materialization/dependencies.js +71 -16
- package/src/materialization/encodings.js +14 -28
- package/src/materialization/facetGuides.js +426 -0
- package/src/materialization/facets.js +214 -0
- package/src/materialization/graphicHierarchy.js +15 -5
- package/src/materialization/guides/resources.js +46 -0
- package/src/materialization/marks.js +220 -14
- package/src/materialization/planner.js +105 -12
- package/src/materialization/rect.js +138 -0
- package/src/materialization/rectConfig.js +38 -0
- package/src/materialization/rowEncoding.js +33 -0
- package/src/materialization/scales/map.js +40 -0
- package/src/materialization/scales/policies/arc.js +37 -0
- package/src/materialization/scales/policies/bar.js +132 -0
- package/src/materialization/scales/policies/series.js +76 -0
- package/src/materialization/scales/resolve.js +326 -0
- package/src/materialization/selection/items/arc.js +29 -0
- package/src/materialization/selection/items/bar.js +255 -0
- package/src/materialization/selection/items/common.js +131 -0
- package/src/materialization/selection/items/index.js +6 -0
- package/src/materialization/selection/items/path.js +59 -0
- package/src/materialization/selection/items/point.js +55 -0
- package/src/materialization/selection/items/rect.js +23 -0
- package/src/materialization/selection/items/rule.js +25 -0
- package/src/materialization/selection/policies/arc.js +10 -0
- package/src/materialization/selection/policies/area.js +1 -1
- package/src/materialization/selection/policies/bar.js +1 -1
- package/src/materialization/selection/policies/index.js +5 -1
- package/src/materialization/selection/policies/line.js +1 -1
- package/src/materialization/selection/policies/point.js +1 -1
- package/src/materialization/selection/policies/rect.js +10 -0
- package/src/materialization/selection/policies/rule.js +1 -1
- package/src/materialization/selection/styles.js +24 -16
- package/src/materialization/text.js +156 -0
- package/src/renderers/canvas/index.js +68 -22
- package/types/extension.d.ts +1 -0
- package/types/index.d.ts +56 -1
- package/types/program.d.ts +664 -27
- package/src/actions/marks/line.js +0 -248
- package/src/materialization/selection/items.js +0 -503
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import { action } from "
|
|
2
|
-
import { validateUserId } from "
|
|
1
|
+
import { action } from "../../../core/action.js";
|
|
2
|
+
import { validateUserId } from "../../../core/identifiers.js";
|
|
3
3
|
import {
|
|
4
4
|
validateNonEmptyString,
|
|
5
5
|
validateNonNegativeFinite,
|
|
6
6
|
validateUnitInterval
|
|
7
|
-
} from "
|
|
7
|
+
} from "../../../core/validation.js";
|
|
8
8
|
import {
|
|
9
9
|
deriveAreaSeries,
|
|
10
10
|
deriveDensityAreaSeries,
|
|
11
11
|
layoutDensityAreaSeries
|
|
12
|
-
} from "
|
|
13
|
-
import { mapContinuousScaleValues, mapOrdinalValues } from "
|
|
12
|
+
} from "../../../grammar/areaSeries.js";
|
|
13
|
+
import { mapContinuousScaleValues, mapOrdinalValues } from "../../../grammar/scales.js";
|
|
14
14
|
import {
|
|
15
15
|
assertMarkAvailable,
|
|
16
|
+
applyLayeredMarkInheritance,
|
|
17
|
+
materializeInheritedMark,
|
|
18
|
+
resolveLayeredMarkInheritance,
|
|
16
19
|
resolveMarkId,
|
|
17
20
|
resolveMarkData,
|
|
18
21
|
validateMarkOptions
|
|
19
|
-
} from "
|
|
20
|
-
import { DEFAULT_COLORS } from "
|
|
21
|
-
import { findDataset } from "
|
|
22
|
-
import { findLayer } from "
|
|
22
|
+
} from "../shared.js";
|
|
23
|
+
import { DEFAULT_COLORS } from "../../../theme/defaults.js";
|
|
24
|
+
import { findDataset } from "../../../selectors/datasets.js";
|
|
25
|
+
import { findLayer } from "../../../selectors/layers.js";
|
|
23
26
|
import {
|
|
24
27
|
buildAreaCurvePathCommands,
|
|
25
28
|
validateCurveInterpolation
|
|
26
|
-
} from "
|
|
27
|
-
import { buildLinearPathCommands } from "
|
|
28
|
-
import { resolveEligibleLayer } from "
|
|
29
|
-
import { canMaterializeArea } from "
|
|
30
|
-
import { findUpstreamTransform } from "
|
|
29
|
+
} from "../../../grammar/curveCommands.js";
|
|
30
|
+
import { buildLinearPathCommands } from "../../../grammar/pathCommands.js";
|
|
31
|
+
import { resolveEligibleLayer } from "../../../selectors/layers.js";
|
|
32
|
+
import { canMaterializeArea } from "../../../materialization/marks.js";
|
|
33
|
+
import { findUpstreamTransform } from "../../../materialization/dataProvenance.js";
|
|
31
34
|
import { resolveMarkGraphicPlacement } from
|
|
32
|
-
"
|
|
35
|
+
"../../../materialization/graphicHierarchy.js";
|
|
36
|
+
import { rematerializeHighlightBaseline } from "../lifecycle.js";
|
|
33
37
|
|
|
34
38
|
const CREATE_OPTIONS = Object.freeze([
|
|
35
39
|
"id", "data", "fill", "opacity", "stroke", "strokeWidth", "curve"
|
|
@@ -37,7 +41,7 @@ const CREATE_OPTIONS = Object.freeze([
|
|
|
37
41
|
const EDIT_OPTIONS = Object.freeze([
|
|
38
42
|
"target", "fill", "opacity", "stroke", "strokeWidth", "curve"
|
|
39
43
|
]);
|
|
40
|
-
const REMATERIALIZE_OPTIONS = Object.freeze(["id"]);
|
|
44
|
+
const REMATERIALIZE_OPTIONS = Object.freeze(["id", "scales"]);
|
|
41
45
|
|
|
42
46
|
export function validateAreaCreateOutline(args, operation = "createAreaMark") {
|
|
43
47
|
if (Object.hasOwn(args, "strokeWidth") && !Object.hasOwn(args, "stroke")) {
|
|
@@ -67,20 +71,27 @@ const createAreaMark = action(
|
|
|
67
71
|
markType: "area",
|
|
68
72
|
operation: "createAreaMark"
|
|
69
73
|
});
|
|
70
|
-
const
|
|
74
|
+
const inherited = resolveLayeredMarkInheritance(this, args, "area");
|
|
75
|
+
const { data } = resolveMarkData(this, {
|
|
76
|
+
...args,
|
|
77
|
+
...(args.data === undefined && this.context.currentData === undefined &&
|
|
78
|
+
inherited?.data !== undefined ? { data: inherited.data } : {})
|
|
79
|
+
});
|
|
71
80
|
const fill = validateNonEmptyString(args.fill ?? DEFAULT_COLORS.mark, "Area fill");
|
|
72
81
|
const opacity = validateUnitInterval(args.opacity ?? 0.2, "Area opacity");
|
|
73
82
|
const curve = validateCurveInterpolation(args.curve ?? "linear");
|
|
74
83
|
const { stroke, strokeWidth } = validateAreaCreateOutline(args);
|
|
75
84
|
assertMarkAvailable(this, id);
|
|
76
|
-
|
|
85
|
+
let created = this
|
|
77
86
|
.editSemantic({ property: `layer[${id}].mark.type`, value: "area" })
|
|
78
|
-
.editSemantic({ property: `layer[${id}].data`, value: data })
|
|
87
|
+
.editSemantic({ property: `layer[${id}].data`, value: data });
|
|
88
|
+
created = applyLayeredMarkInheritance(created, id, inherited);
|
|
89
|
+
created = created
|
|
79
90
|
.createGraphics({
|
|
80
91
|
id,
|
|
81
92
|
type: "path",
|
|
82
93
|
length: 0,
|
|
83
|
-
...resolveMarkGraphicPlacement(
|
|
94
|
+
...resolveMarkGraphicPlacement(created, { data, markType: "area" })
|
|
84
95
|
})
|
|
85
96
|
._withMarkConfig(id, {
|
|
86
97
|
fill,
|
|
@@ -88,6 +99,7 @@ const createAreaMark = action(
|
|
|
88
99
|
...(Object.hasOwn(args, "curve") ? { curve } : {}),
|
|
89
100
|
...(stroke === undefined ? {} : { stroke, strokeWidth })
|
|
90
101
|
});
|
|
102
|
+
return materializeInheritedMark(created, id);
|
|
91
103
|
}
|
|
92
104
|
);
|
|
93
105
|
|
|
@@ -98,20 +110,17 @@ const rematerializeAreaMark = action(
|
|
|
98
110
|
},
|
|
99
111
|
function (args = {}) {
|
|
100
112
|
validateMarkOptions(args, REMATERIALIZE_OPTIONS, "rematerializeAreaMark");
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.materializationConfigs.highlights ?? {}
|
|
104
|
-
).filter(([, config]) => config.target === id);
|
|
105
|
-
if (highlights.length > 0) {
|
|
106
|
-
let baseline = this;
|
|
107
|
-
for (const [highlightId] of highlights) {
|
|
108
|
-
baseline = baseline._withoutMaterializationConfig(["highlights", highlightId]);
|
|
109
|
-
}
|
|
110
|
-
return baseline
|
|
111
|
-
.editGraphics({ target: id, property: "length", value: 0 })
|
|
112
|
-
.rematerializeAreaMark({ id })
|
|
113
|
-
.rematerializeMarkHighlights({ target: id, highlights });
|
|
113
|
+
if (args.scales !== undefined && typeof args.scales !== "boolean") {
|
|
114
|
+
throw new TypeError("rematerializeAreaMark scales must be a boolean.");
|
|
114
115
|
}
|
|
116
|
+
const id = validateUserId(args.id, "Area mark id");
|
|
117
|
+
const highlighted = rematerializeHighlightBaseline(this, {
|
|
118
|
+
target: id,
|
|
119
|
+
operation: "rematerializeAreaMark",
|
|
120
|
+
resetProperty: "length",
|
|
121
|
+
resetValue: 0
|
|
122
|
+
});
|
|
123
|
+
if (highlighted !== undefined) return highlighted;
|
|
115
124
|
const layer = findLayer(this, id);
|
|
116
125
|
const dataset = findDataset(this, layer?.data);
|
|
117
126
|
if (layer?.mark?.type !== "area" || this.graphicSpec.objects[id]?.type !== "path") {
|
|
@@ -148,10 +157,12 @@ const rematerializeAreaMark = action(
|
|
|
148
157
|
const derived = densityTransform === undefined
|
|
149
158
|
? rawDerived
|
|
150
159
|
: layoutDensityAreaSeries(rawDerived, layout);
|
|
151
|
-
let resolved =
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
160
|
+
let resolved = args.scales === false
|
|
161
|
+
? this
|
|
162
|
+
: this
|
|
163
|
+
.rematerializeScale({ id: xScaleId })
|
|
164
|
+
.rematerializeScale({ id: yScaleId });
|
|
165
|
+
if (args.scales !== false && colorEncoding?.scale !== undefined) {
|
|
155
166
|
resolved = resolved.rematerializeScale({ id: colorEncoding.scale });
|
|
156
167
|
}
|
|
157
168
|
const xScale = resolved.resolvedScales[xScaleId];
|
|
@@ -259,7 +270,9 @@ const rematerializeAreaMark = action(
|
|
|
259
270
|
);
|
|
260
271
|
});
|
|
261
272
|
const config = this.markConfigs[id];
|
|
262
|
-
const fills =
|
|
273
|
+
const fills = config.errorBand?.fill !== undefined
|
|
274
|
+
? paths.map(() => config.errorBand.fill)
|
|
275
|
+
: colorEncoding?.scale === undefined
|
|
263
276
|
? paths.map(() => config.fill)
|
|
264
277
|
: mapOrdinalValues(
|
|
265
278
|
derived.series.map(series => series.key[colorEncoding.field]),
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { action } from "../../../core/action.js";
|
|
2
2
|
import {
|
|
3
3
|
assertMarkAvailable,
|
|
4
|
+
applyLayeredMarkInheritance,
|
|
5
|
+
materializeInheritedMark,
|
|
6
|
+
resolveLayeredMarkInheritance,
|
|
4
7
|
resolveMarkId,
|
|
5
8
|
resolveMarkData,
|
|
6
9
|
validateMarkOptions
|
|
@@ -8,7 +11,9 @@ import {
|
|
|
8
11
|
import { resolveMarkGraphicPlacement } from
|
|
9
12
|
"../../../materialization/graphicHierarchy.js";
|
|
10
13
|
|
|
11
|
-
const CREATE_OPTIONS = Object.freeze([
|
|
14
|
+
const CREATE_OPTIONS = Object.freeze([
|
|
15
|
+
"id", "data", "fill", "opacity", "stroke", "strokeWidth"
|
|
16
|
+
]);
|
|
12
17
|
|
|
13
18
|
export const createBarMark = action(
|
|
14
19
|
{
|
|
@@ -23,11 +28,16 @@ export const createBarMark = action(
|
|
|
23
28
|
markType: "bar",
|
|
24
29
|
operation: "createBarMark"
|
|
25
30
|
});
|
|
26
|
-
const
|
|
31
|
+
const inherited = resolveLayeredMarkInheritance(this, args, "bar");
|
|
32
|
+
const { data } = resolveMarkData(this, {
|
|
33
|
+
...args,
|
|
34
|
+
...(args.data === undefined && this.context.currentData === undefined &&
|
|
35
|
+
inherited?.data !== undefined ? { data: inherited.data } : {})
|
|
36
|
+
});
|
|
27
37
|
|
|
28
38
|
assertMarkAvailable(this, id);
|
|
29
39
|
|
|
30
|
-
|
|
40
|
+
let created = this
|
|
31
41
|
.editSemantic({
|
|
32
42
|
property: `layer[${id}].mark.type`,
|
|
33
43
|
value: "bar"
|
|
@@ -35,12 +45,23 @@ export const createBarMark = action(
|
|
|
35
45
|
.editSemantic({
|
|
36
46
|
property: `layer[${id}].data`,
|
|
37
47
|
value: data
|
|
38
|
-
})
|
|
48
|
+
});
|
|
49
|
+
created = applyLayeredMarkInheritance(created, id, inherited);
|
|
50
|
+
created = created
|
|
39
51
|
.createGraphics({
|
|
40
52
|
id,
|
|
41
53
|
type: "rect",
|
|
42
54
|
length: 0,
|
|
43
|
-
...resolveMarkGraphicPlacement(
|
|
55
|
+
...resolveMarkGraphicPlacement(created, { data, markType: "bar" })
|
|
44
56
|
});
|
|
57
|
+
created = materializeInheritedMark(created, id);
|
|
58
|
+
const appearance = Object.fromEntries(
|
|
59
|
+
["fill", "opacity", "stroke", "strokeWidth"]
|
|
60
|
+
.filter(property => Object.hasOwn(args, property))
|
|
61
|
+
.map(property => [property, args[property]])
|
|
62
|
+
);
|
|
63
|
+
return Object.keys(appearance).length === 0
|
|
64
|
+
? created
|
|
65
|
+
: created.editBarMark({ target: id, ...appearance });
|
|
45
66
|
}
|
|
46
67
|
);
|
|
@@ -5,9 +5,13 @@ import { deriveAggregateRectangles } from "../../../materialization/bars/aggrega
|
|
|
5
5
|
import { deriveHistogramRectangles } from "../../../materialization/bars/histogram.js";
|
|
6
6
|
import { requireCompleteBar } from "../../../materialization/bars/resolve.js";
|
|
7
7
|
import { deriveRangedRectangles } from "../../../materialization/bars/ranged.js";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
BAR_GRAINS,
|
|
10
|
+
resolveBarOffsetChannel
|
|
11
|
+
} from "../../../grammar/bars/policy.js";
|
|
12
|
+
import { rematerializeHighlightBaseline } from "../lifecycle.js";
|
|
9
13
|
|
|
10
|
-
const REMATERIALIZE_OPTIONS = Object.freeze(["id"]);
|
|
14
|
+
const REMATERIALIZE_OPTIONS = Object.freeze(["id", "scales"]);
|
|
11
15
|
|
|
12
16
|
function editRectangles(program, id, rectangles) {
|
|
13
17
|
let next = program
|
|
@@ -69,45 +73,36 @@ export const rematerializeBarMark = action(
|
|
|
69
73
|
"rematerializeBarMark"
|
|
70
74
|
);
|
|
71
75
|
const id = validateUserId(args.id, "Bar mark id");
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
).filter(([, config]) => config.target === id);
|
|
75
|
-
if (highlights.length > 0) {
|
|
76
|
-
let baseline = this;
|
|
77
|
-
for (const [highlightId] of highlights) {
|
|
78
|
-
baseline = baseline._withoutMaterializationConfig([
|
|
79
|
-
"highlights",
|
|
80
|
-
highlightId
|
|
81
|
-
]);
|
|
82
|
-
}
|
|
83
|
-
return baseline
|
|
84
|
-
.editGraphics({ target: id, property: "length", value: 0 })
|
|
85
|
-
.rematerializeBarMark({ id })
|
|
86
|
-
.rematerializeMarkHighlights({ target: id, highlights });
|
|
76
|
+
if (args.scales !== undefined && typeof args.scales !== "boolean") {
|
|
77
|
+
throw new TypeError("rematerializeBarMark scales must be a boolean.");
|
|
87
78
|
}
|
|
79
|
+
const highlighted = rematerializeHighlightBaseline(this, {
|
|
80
|
+
target: id,
|
|
81
|
+
operation: "rematerializeBarMark",
|
|
82
|
+
resetProperty: "length",
|
|
83
|
+
resetValue: 0
|
|
84
|
+
});
|
|
85
|
+
if (highlighted !== undefined) return highlighted;
|
|
88
86
|
const required = requireCompleteBar(this, id);
|
|
89
|
-
let resolved = this
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
let resolved = this;
|
|
88
|
+
if (args.scales !== false) {
|
|
89
|
+
resolved = resolved
|
|
90
|
+
.rematerializeScale({ id: required.xEncoding.scale })
|
|
91
|
+
.rematerializeScale({ id: required.yEncoding.scale });
|
|
92
|
+
}
|
|
92
93
|
|
|
93
94
|
const colorScaleId = required.layer.encoding?.color?.scale;
|
|
94
|
-
if (colorScaleId !== undefined) {
|
|
95
|
+
if (colorScaleId !== undefined && args.scales !== false) {
|
|
95
96
|
resolved = resolved.rematerializeScale({ id: colorScaleId });
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
if (required.materialization === "aggregate") {
|
|
99
|
-
const
|
|
100
|
-
|
|
100
|
+
const offsetChannel = resolveBarOffsetChannel(required.layer);
|
|
101
|
+
const offsetScaleId = required.layer.encoding?.[offsetChannel]?.scale;
|
|
102
|
+
if (offsetScaleId !== undefined && args.scales !== false) {
|
|
101
103
|
resolved = resolved.rematerializeScale({ id: offsetScaleId });
|
|
102
104
|
}
|
|
103
105
|
const width = resolved.markConfigs[id]?.barWidth;
|
|
104
|
-
if (width === undefined) {
|
|
105
|
-
return resolved.editGraphics({
|
|
106
|
-
target: id,
|
|
107
|
-
property: "length",
|
|
108
|
-
value: 0
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
106
|
return editRectangles(
|
|
112
107
|
resolved,
|
|
113
108
|
id,
|
|
@@ -117,7 +112,6 @@ export const rematerializeBarMark = action(
|
|
|
117
112
|
|
|
118
113
|
if (required.materialization === BAR_GRAINS.ranged) {
|
|
119
114
|
const width = resolved.markConfigs[id]?.barWidth;
|
|
120
|
-
if (width === undefined) return resolved.editGraphics({ target: id, property: "length", value: 0 });
|
|
121
115
|
return editRectangles(resolved, id, deriveRangedRectangles(required, resolved, width));
|
|
122
116
|
}
|
|
123
117
|
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { registerBarMarkActions } from "./bar/index.js";
|
|
2
|
-
import { registerAreaMarkActions } from "./area.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { registerAreaMarkActions } from "./area/index.js";
|
|
3
|
+
import { registerArcMarkActions } from "./arc/index.js";
|
|
4
|
+
import { registerLineMarkActions } from "./line/index.js";
|
|
5
|
+
import { registerPointMarkActions } from "./point/index.js";
|
|
6
|
+
import { registerRectMarkActions } from "./rect/index.js";
|
|
7
|
+
import { registerRuleMarkActions } from "./rule/index.js";
|
|
8
|
+
import { registerTextMarkActions } from "./text/index.js";
|
|
9
|
+
import { removeMark } from "./remove.js";
|
|
6
10
|
|
|
7
11
|
export function registerMarkActions(ProgramClass) {
|
|
8
12
|
registerPointMarkActions(ProgramClass);
|
|
13
|
+
registerRectMarkActions(ProgramClass);
|
|
9
14
|
registerAreaMarkActions(ProgramClass);
|
|
15
|
+
registerArcMarkActions(ProgramClass);
|
|
10
16
|
registerLineMarkActions(ProgramClass);
|
|
11
17
|
registerBarMarkActions(ProgramClass);
|
|
12
18
|
registerRuleMarkActions(ProgramClass);
|
|
19
|
+
registerTextMarkActions(ProgramClass);
|
|
20
|
+
ProgramClass.prototype.removeMark = removeMark;
|
|
13
21
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function rematerializeHighlightBaseline(program, {
|
|
2
|
+
target,
|
|
3
|
+
operation,
|
|
4
|
+
resetProperty,
|
|
5
|
+
resetValue
|
|
6
|
+
}) {
|
|
7
|
+
const highlights = Object.entries(
|
|
8
|
+
program.materializationConfigs.highlights ?? {}
|
|
9
|
+
).filter(([, config]) => config.target === target);
|
|
10
|
+
if (highlights.length === 0) return undefined;
|
|
11
|
+
|
|
12
|
+
let baseline = program;
|
|
13
|
+
for (const [highlightId] of highlights) {
|
|
14
|
+
baseline = baseline._withoutMaterializationConfig([
|
|
15
|
+
"highlights",
|
|
16
|
+
highlightId
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
return baseline
|
|
20
|
+
.editGraphics({
|
|
21
|
+
target,
|
|
22
|
+
property: resetProperty,
|
|
23
|
+
value: resetValue
|
|
24
|
+
})
|
|
25
|
+
[operation]({ id: target })
|
|
26
|
+
.rematerializeMarkHighlights({ target, highlights });
|
|
27
|
+
}
|