ggaction 0.0.3 → 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 (223) hide show
  1. package/CHANGELOG.md +58 -3
  2. package/README.md +117 -83
  3. package/package.json +27 -11
  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/regression.js +1 -1
  26. package/src/actions/data/window.js +50 -0
  27. package/src/actions/encodings/appearance.js +1 -1
  28. package/src/actions/encodings/color/continuous.js +137 -0
  29. package/src/actions/encodings/color/index.js +167 -0
  30. package/src/actions/encodings/color/layout.js +99 -0
  31. package/src/actions/encodings/color/policy.js +88 -0
  32. package/src/actions/encodings/density/resolve.js +109 -0
  33. package/src/actions/encodings/density.js +193 -88
  34. package/src/actions/encodings/horizon/resolve.js +283 -0
  35. package/src/actions/encodings/horizon.js +364 -0
  36. package/src/actions/encodings/index.js +8 -2
  37. package/src/actions/encodings/offset.js +1 -1
  38. package/src/actions/encodings/parallel.js +115 -0
  39. package/src/actions/encodings/pathOrder.js +131 -0
  40. package/src/actions/encodings/position/apply.js +73 -4
  41. package/src/actions/encodings/{position.js → position/index.js} +21 -8
  42. package/src/actions/encodings/position/policies/arc.js +27 -4
  43. package/src/actions/encodings/position/policies/area.js +33 -2
  44. package/src/actions/encodings/position/policies/index.js +7 -2
  45. package/src/actions/encodings/position/policies/line.js +18 -2
  46. package/src/actions/encodings/position/resolve.js +25 -3
  47. package/src/actions/encodings/ranged.js +5 -3
  48. package/src/actions/encodings/ruleAppearance.js +88 -10
  49. package/src/actions/encodings/strokeDash.js +1 -1
  50. package/src/actions/encodings/text.js +1 -1
  51. package/src/actions/errorBands/options.js +1 -1
  52. package/src/actions/errorBars/options.js +1 -1
  53. package/src/actions/facets/actions.js +2 -3
  54. package/src/actions/facets/derive.js +35 -5
  55. package/src/actions/facets/guides.js +1 -1
  56. package/src/actions/facets/replay.js +7 -36
  57. package/src/actions/gradientPlots/components.js +177 -0
  58. package/src/actions/gradientPlots/create.js +96 -0
  59. package/src/actions/gradientPlots/edit.js +153 -0
  60. package/src/actions/gradientPlots/index.js +24 -0
  61. package/src/actions/gradientPlots/materialize.js +287 -0
  62. package/src/actions/gradientPlots/options.js +120 -0
  63. package/src/actions/gradientPlots/paint.js +107 -0
  64. package/src/actions/gradientPlots/rebind.js +51 -0
  65. package/src/actions/gradientPlots/resolve.js +81 -0
  66. package/src/actions/guides/applicability.js +44 -17
  67. package/src/actions/guides/axes/axes.js +37 -3
  68. package/src/actions/guides/axes/index.js +2 -0
  69. package/src/actions/guides/axes/labels.js +12 -7
  70. package/src/actions/guides/axes/parallel/resolve.js +86 -0
  71. package/src/actions/guides/axes/parallel.js +228 -0
  72. package/src/actions/guides/axes/ticks.js +1 -1
  73. package/src/actions/guides/axes/titles.js +12 -9
  74. package/src/actions/guides/grids/resolve.js +1 -1
  75. package/src/actions/guides/guides.js +60 -5
  76. package/src/actions/guides/legends/categorical/actions.js +48 -11
  77. package/src/actions/guides/legends/categorical/layout.js +4 -2
  78. package/src/actions/guides/legends/continuous/interval.js +1 -1
  79. package/src/actions/guides/legends/continuous/opacity.js +1 -1
  80. package/src/actions/guides/legends/edit.js +7 -20
  81. package/src/actions/guides/legends/index.js +2 -0
  82. package/src/actions/guides/legends/remove.js +6 -31
  83. package/src/actions/guides/legends/size.js +1 -1
  84. package/src/actions/guides/legends/strokeWidth.js +170 -0
  85. package/src/actions/guides/legends/target.js +25 -0
  86. package/src/actions/guides/polar/{axes.js → axes/index.js} +5 -5
  87. package/src/actions/guides/polar/index.js +1 -1
  88. package/src/actions/guides/polar/resolve.js +1 -1
  89. package/src/actions/guides/tickValues.js +1 -1
  90. package/src/actions/index.js +6 -0
  91. package/src/actions/intervals/resolve.js +1 -1
  92. package/src/actions/marks/arc/actions.js +2 -2
  93. package/src/actions/marks/area/actions.js +61 -137
  94. package/src/actions/marks/area/materialize.js +163 -0
  95. package/src/actions/marks/bar/edit.js +1 -1
  96. package/src/actions/marks/index.js +5 -1
  97. package/src/actions/marks/line/actions.js +100 -81
  98. package/src/actions/marks/line/materialize.js +146 -0
  99. package/src/actions/marks/point/create.js +76 -0
  100. package/src/actions/marks/point/edit.js +85 -0
  101. package/src/actions/marks/point/index.js +11 -1
  102. package/src/actions/marks/point/jitter.js +72 -0
  103. package/src/actions/marks/point/{actions.js → materialize.js} +175 -170
  104. package/src/actions/marks/rect/actions.js +4 -1
  105. package/src/actions/marks/remove.js +13 -2
  106. package/src/actions/marks/rule/actions.js +26 -4
  107. package/src/actions/marks/shared.js +1 -1
  108. package/src/actions/marks/text/actions.js +20 -5
  109. package/src/actions/marks/text/index.js +7 -1
  110. package/src/actions/marks/text/layout.js +321 -0
  111. package/src/actions/primitives/semanticValidation/dataset.js +22 -0
  112. package/src/actions/primitives/semanticValidation/guide.js +43 -0
  113. package/src/actions/primitives/semanticValidation/index.js +23 -0
  114. package/src/actions/primitives/semanticValidation/layer.js +74 -0
  115. package/src/actions/primitives/semanticValidation/scale.js +74 -0
  116. package/src/actions/primitives/semanticValidation/shared.js +5 -0
  117. package/src/actions/primitives/semanticValue.js +1 -204
  118. package/src/actions/regression/components.js +1 -1
  119. package/src/actions/regression/create.js +1 -1
  120. package/src/actions/regression/edit.js +20 -22
  121. package/src/actions/scales/consumers/common.js +109 -0
  122. package/src/actions/scales/consumers/families.js +58 -0
  123. package/src/actions/scales/consumers/index.js +41 -0
  124. package/src/actions/scales/{consumers.js → consumers/seriesLayout.js} +10 -132
  125. package/src/actions/scales/create.js +1 -1
  126. package/src/actions/scales/definitions.js +32 -2
  127. package/src/actions/scales/edit.js +8 -206
  128. package/src/actions/scales/editPolicy.js +214 -0
  129. package/src/actions/scales/materialize.js +3 -3
  130. package/src/actions/scales/patch.js +26 -0
  131. package/src/actions/selection/actions.js +28 -3
  132. package/src/actions/violinPlots/create.js +198 -0
  133. package/src/actions/violinPlots/index.js +5 -0
  134. package/src/core/ChartProgram.js +22 -236
  135. package/src/core/compositionState.js +169 -0
  136. package/src/core/materializationState.js +65 -0
  137. package/src/core/programState.js +28 -0
  138. package/src/core/textMetrics.js +47 -0
  139. package/src/core/vocabulary.js +7 -2
  140. package/src/grammar/arcs.js +50 -13
  141. package/src/grammar/areaSeries.js +42 -6
  142. package/src/grammar/bars/aggregate.js +1 -1
  143. package/src/grammar/bin2d.js +333 -0
  144. package/src/grammar/categoricalDensity.js +192 -0
  145. package/src/grammar/coordinates.js +1 -1
  146. package/src/grammar/curveCommands.js +3 -1
  147. package/src/grammar/density.js +253 -27
  148. package/src/grammar/facets/dependencies.js +3 -11
  149. package/src/grammar/{facets.js → facets/index.js} +8 -6
  150. package/src/grammar/gradientProfile.js +213 -0
  151. package/src/grammar/horizon.js +455 -0
  152. package/src/grammar/interval.js +2 -96
  153. package/src/grammar/jitter.js +197 -0
  154. package/src/grammar/lineSeries.js +70 -1
  155. package/src/grammar/paint.js +88 -0
  156. package/src/grammar/palettes.js +5 -7
  157. package/src/grammar/parallelCoordinates.js +213 -0
  158. package/src/grammar/pathOrder.js +35 -0
  159. package/src/grammar/pointShapes.js +24 -0
  160. package/src/grammar/polarLineCommands.js +1 -1
  161. package/src/grammar/regression/derive.js +97 -0
  162. package/src/grammar/regression/index.js +22 -0
  163. package/src/grammar/regression/models.js +282 -0
  164. package/src/grammar/regression/parameters.js +106 -0
  165. package/src/grammar/rules.js +2 -1
  166. package/src/grammar/scales/appearance.js +21 -0
  167. package/src/grammar/scales/color.js +4 -2
  168. package/src/grammar/schemas/concreteGraphic.js +11 -1
  169. package/src/grammar/schemas/graphicBounds.js +19 -37
  170. package/src/grammar/schemas/semanticPath.js +17 -2
  171. package/src/grammar/statistics/studentT.js +98 -0
  172. package/src/grammar/transforms.js +101 -12
  173. package/src/grammar/window.js +339 -0
  174. package/src/layout/labels.js +270 -0
  175. package/src/layout/text.js +4 -1
  176. package/src/layout/title.js +10 -20
  177. package/src/materialization/bars/aggregate.js +1 -1
  178. package/src/materialization/bars/grouped.js +1 -1
  179. package/src/materialization/bars/histogram.js +1 -1
  180. package/src/materialization/bars/ranged.js +1 -1
  181. package/src/materialization/dataProvenance.js +56 -2
  182. package/src/materialization/density.js +1 -1
  183. package/src/materialization/dependencies.js +15 -101
  184. package/src/materialization/encodings.js +2 -2
  185. package/src/materialization/facetGuides/index.js +2 -0
  186. package/src/materialization/facetGuides/legacyCategorical.js +125 -0
  187. package/src/materialization/facetGuides/placement.js +126 -0
  188. package/src/materialization/facetGuides/preparation.js +188 -0
  189. package/src/materialization/facets.js +1 -1
  190. package/src/materialization/guides/resources.js +74 -24
  191. package/src/materialization/horizon.js +29 -0
  192. package/src/materialization/layout.js +15 -0
  193. package/src/materialization/marks/capabilities.js +161 -0
  194. package/src/materialization/marks/index.js +108 -0
  195. package/src/materialization/marks/pathOrder.js +71 -0
  196. package/src/materialization/marks/policies.js +91 -0
  197. package/src/materialization/rect.js +1 -1
  198. package/src/materialization/rowEncoding.js +1 -1
  199. package/src/materialization/scaleGuideDependencies.js +102 -0
  200. package/src/materialization/scales/map.js +1 -1
  201. package/src/materialization/scales/policies/series.js +1 -1
  202. package/src/materialization/scales/resolve.js +3 -1
  203. package/src/materialization/selection/items/bar.js +1 -1
  204. package/src/materialization/selection/items/path.js +27 -1
  205. package/src/materialization/selection/items/point.js +1 -5
  206. package/src/materialization/selection/items/rect.js +21 -0
  207. package/src/materialization/selection/styles.js +21 -10
  208. package/src/materialization/text.js +12 -4
  209. package/src/renderers/canvas/fill.js +33 -0
  210. package/src/renderers/canvas/index.js +7 -0
  211. package/src/renderers/canvas/path.js +7 -4
  212. package/src/renderers/canvas/rect.js +9 -3
  213. package/src/renderers/canvas/text.js +14 -1
  214. package/src/selectors/datasets.js +4 -0
  215. package/src/theme/defaults.js +4 -0
  216. package/types/extension.d.ts +10 -1
  217. package/types/index.d.ts +76 -0
  218. package/types/program.d.ts +632 -10
  219. package/src/actions/encodings/color.js +0 -424
  220. package/src/grammar/regression.js +0 -578
  221. package/src/grammar/scales.js +0 -1
  222. package/src/materialization/facetGuides.js +0 -426
  223. package/src/materialization/marks.js +0 -316
@@ -1,316 +0,0 @@
1
- import { findDataset } from "../selectors/datasets.js";
2
- import { findLayer } from "../selectors/layers.js";
3
- import { isAggregate } from "../grammar/aggregate.js";
4
- import {
5
- BAR_GRAINS,
6
- resolveBarColorLayout,
7
- resolveBarOffsetChannel,
8
- resolveBarGrain
9
- } from "../grammar/bars/policy.js";
10
- import { resolveRuleMode } from "../grammar/rules.js";
11
- import { findUpstreamTransform } from "./dataProvenance.js";
12
- import { POSITION_CHANNELS } from "../core/vocabulary.js";
13
- import { resolveRectMode } from "../grammar/rects.js";
14
-
15
- function hasCartesianPositionScales(layer) {
16
- return (
17
- layer.encoding?.x?.scale !== undefined &&
18
- layer.encoding?.y?.scale !== undefined
19
- );
20
- }
21
-
22
- function hasPolarPositionScales(layer) {
23
- return (
24
- layer.encoding?.theta?.scale !== undefined &&
25
- layer.encoding?.radius?.scale !== undefined
26
- );
27
- }
28
-
29
- function hasPositionScales(layer) {
30
- return hasCartesianPositionScales(layer);
31
- }
32
-
33
- export function canMaterializePoint(_program, layer) {
34
- return layer.mark?.type === "point" && (
35
- hasCartesianPositionScales(layer) || hasPolarPositionScales(layer)
36
- );
37
- }
38
-
39
- export function canMaterializeLine(program, layer) {
40
- const dataset = findDataset(program, layer.data);
41
- const interval = dataset?.transform?.some(item => item.type === "interval");
42
- if (hasPolarPositionScales(layer)) {
43
- return (
44
- layer.mark?.type === "line" &&
45
- ["quantitative", "temporal", "ordinal", "nominal"].includes(
46
- layer.encoding.theta.fieldType
47
- ) &&
48
- layer.encoding.radius.fieldType === "quantitative"
49
- );
50
- }
51
- return (
52
- layer.mark?.type === "line" &&
53
- hasPositionScales(layer) &&
54
- (isAggregate(layer.encoding.y.aggregate) ||
55
- (layer.encoding.x.fieldType === "quantitative" &&
56
- layer.encoding.y.fieldType === "quantitative") ||
57
- ((interval || layer.encoding.y.aggregate === undefined) &&
58
- ["quantitative", "temporal"].includes(layer.encoding.x.fieldType) &&
59
- ["quantitative", "temporal"].includes(layer.encoding.y.fieldType) &&
60
- layer.encoding.x.fieldType !== layer.encoding.y.fieldType))
61
- );
62
- }
63
-
64
- export function canMaterializeArea(program, layer) {
65
- if (layer.mark?.type !== "area" || !hasPositionScales(layer)) {
66
- return false;
67
- }
68
-
69
- const dataset = findDataset(program, layer.data);
70
- const densityTransform = findUpstreamTransform(program, dataset, "density");
71
- const completeDensity =
72
- densityTransform !== undefined &&
73
- (densityTransform.groupBy === undefined ||
74
- layer.encoding?.group?.field === densityTransform.groupBy);
75
-
76
- return (
77
- completeDensity ||
78
- layer.encoding?.y2?.scale === layer.encoding.y.scale ||
79
- layer.encoding?.x2?.scale === layer.encoding.x.scale
80
- );
81
- }
82
-
83
- export function canMaterializeArc(_program, layer) {
84
- if (
85
- layer.mark?.type !== "arc" ||
86
- layer.encoding?.theta?.scale === undefined ||
87
- !["nominal", "ordinal"].includes(layer.encoding.theta.fieldType)
88
- ) {
89
- return false;
90
- }
91
- if (layer.encoding.theta.aggregate === "count") {
92
- return layer.encoding?.radius === undefined;
93
- }
94
- return (
95
- layer.encoding.theta.aggregate === undefined &&
96
- layer.encoding?.radius?.scale !== undefined &&
97
- layer.encoding.radius.fieldType === "quantitative"
98
- );
99
- }
100
-
101
- export function canMaterializeBar(program, layer) {
102
- if (layer.mark?.type !== "bar" || !hasPositionScales(layer)) {
103
- return false;
104
- }
105
- const grain = resolveBarGrain(layer);
106
- if (![BAR_GRAINS.histogram, BAR_GRAINS.aggregate, BAR_GRAINS.ranged].includes(grain)) {
107
- return false;
108
- }
109
- if (
110
- grain === BAR_GRAINS.aggregate &&
111
- resolveBarColorLayout(layer) === "group"
112
- ) {
113
- const offsetChannel = resolveBarOffsetChannel(layer);
114
- return (
115
- layer.encoding?.color?.field !== undefined &&
116
- layer.encoding?.[offsetChannel]?.field === layer.encoding.color.field &&
117
- layer.encoding[offsetChannel].scale !== undefined
118
- );
119
- }
120
- return true;
121
- }
122
-
123
- export function canMaterializeRule(program, layer) {
124
- const fixedSpan = program.markConfigs[layer.id]?.fixedSpan;
125
- const boxSpanOwner = program.markConfigs[layer.id]?.boxSpanOwner;
126
- return layer.mark?.type === "rule" && (
127
- resolveRuleMode(layer) !== undefined ||
128
- (boxSpanOwner !== undefined && hasPositionScales(layer)) ||
129
- (fixedSpan !== undefined && hasPositionScales(layer))
130
- );
131
- }
132
-
133
- export function canMaterializeText(program, layer) {
134
- if (layer.mark?.type !== "text" || layer.encoding?.text === undefined) {
135
- return false;
136
- }
137
- if (layer.source !== undefined) {
138
- const source = findLayer(program, layer.source);
139
- return source !== undefined &&
140
- ["point", "bar", "rule", "rect"].includes(source.mark?.type) &&
141
- Array.isArray(program.graphicSpec.objects[source.id]?.items);
142
- }
143
- return hasCartesianPositionScales(layer);
144
- }
145
-
146
- export function canMaterializeRect(_program, layer) {
147
- return resolveRectMode(layer) !== undefined;
148
- }
149
-
150
- const MARK_MATERIALIZATION_POLICIES = Object.freeze({
151
- point: Object.freeze({
152
- canMaterialize: canMaterializePoint,
153
- op: "rematerializePointMark",
154
- positionEncoding: Object.freeze({ incomplete: "mark", scaleFirst: true }),
155
- encoding: Object.freeze({ scaleFirst: true }),
156
- scaleApplication: Object.freeze({
157
- deferWithMark: true,
158
- position: "rematerialize",
159
- deferredChannels: Object.freeze(["size", "shape"]),
160
- default: "direct"
161
- }),
162
- rematerializeIncompleteExisting: true
163
- }),
164
- line: Object.freeze({
165
- canMaterialize: canMaterializeLine,
166
- op: "rematerializeLineMark",
167
- positionEncoding: Object.freeze({ incomplete: "scale", scaleFirst: false }),
168
- scaleApplication: Object.freeze({ default: "defer" })
169
- }),
170
- area: Object.freeze({
171
- canMaterialize: canMaterializeArea,
172
- op: "rematerializeAreaMark",
173
- positionEncoding: Object.freeze({ incomplete: "scale", scaleFirst: true }),
174
- encoding: Object.freeze({ sharedChannels: Object.freeze(["color"]) }),
175
- scaleApplication: Object.freeze({ default: "defer" })
176
- }),
177
- arc: Object.freeze({
178
- canMaterialize: canMaterializeArc,
179
- op: "rematerializeArcMark",
180
- positionEncoding: Object.freeze({ incomplete: "scale", scaleFirst: false }),
181
- encoding: Object.freeze({ completeOnly: true }),
182
- scaleApplication: Object.freeze({ default: "defer" })
183
- }),
184
- bar: Object.freeze({
185
- canMaterialize: canMaterializeBar,
186
- op: "rematerializeBarMark",
187
- positionEncoding: Object.freeze({ incomplete: "scale", scaleFirst: false }),
188
- scaleApplication: Object.freeze({ default: "defer" })
189
- }),
190
- rule: Object.freeze({
191
- canMaterialize: canMaterializeRule,
192
- op: "rematerializeRuleMark",
193
- positionEncoding: Object.freeze({ incomplete: "mark", scaleFirst: false }),
194
- scaleApplication: Object.freeze({ default: "defer" })
195
- }),
196
- text: Object.freeze({
197
- canMaterialize: canMaterializeText,
198
- op: "rematerializeTextMark",
199
- positionEncoding: Object.freeze({ incomplete: "mark", scaleFirst: true }),
200
- encoding: Object.freeze({ scaleFirst: true }),
201
- scaleApplication: Object.freeze({
202
- deferWithMark: true,
203
- position: "rematerialize",
204
- default: "defer"
205
- }),
206
- rematerializeIncompleteExisting: true,
207
- sourceDependent: true
208
- }),
209
- rect: Object.freeze({
210
- canMaterialize: canMaterializeRect,
211
- op: "rematerializeRectMark",
212
- positionEncoding: Object.freeze({ incomplete: "scale", scaleFirst: true }),
213
- encoding: Object.freeze({ scaleFirst: true }),
214
- scaleApplication: Object.freeze({
215
- deferWithMark: true,
216
- position: "rematerialize",
217
- default: "defer"
218
- }),
219
- rematerializeIncompleteExisting: true
220
- })
221
- });
222
-
223
- function getMarkPolicy(layer) {
224
- return MARK_MATERIALIZATION_POLICIES[layer.mark?.type];
225
- }
226
-
227
- export function getMarkRematerializationStep(layer) {
228
- const policy = getMarkPolicy(layer);
229
- return policy === undefined
230
- ? undefined
231
- : { op: policy.op, args: { id: layer.id } };
232
- }
233
-
234
- export function getMarkMaterializationStep(program, layer) {
235
- const policy = getMarkPolicy(layer);
236
- if (policy === undefined || !policy.canMaterialize(program, layer)) {
237
- return undefined;
238
- }
239
- return getMarkRematerializationStep(layer);
240
- }
241
-
242
- export function getSourceDependentMarkSteps(program, sourceId) {
243
- return program.semanticSpec.layers.flatMap(layer =>
244
- layer.source === sourceId && getMarkPolicy(layer)?.sourceDependent === true
245
- ? [getMarkMaterializationStep(program, layer)].filter(
246
- step => step !== undefined
247
- )
248
- : []
249
- );
250
- }
251
-
252
- export function getPositionEncodingMaterializationSteps(program, layer, scaleId) {
253
- const policy = getMarkPolicy(layer);
254
- if (policy === undefined) return [];
255
- const scale = { op: "rematerializeScale", args: { id: scaleId } };
256
- const complete = policy.canMaterialize(program, layer);
257
- const mark = getMarkRematerializationStep(layer);
258
- if (!complete) {
259
- if (policy.positionEncoding.incomplete === "scale") return [scale];
260
- return policy.positionEncoding.scaleFirst ? [scale, mark] : [mark];
261
- }
262
- return policy.positionEncoding.scaleFirst ? [scale, mark] : [mark];
263
- }
264
-
265
- export function getScaleConsumerMaterializationMode(layer, channel) {
266
- const policy = getMarkPolicy(layer);
267
- if (policy === undefined) return "direct";
268
- if (POSITION_CHANNELS.includes(channel)) {
269
- return policy.scaleApplication.position ?? policy.scaleApplication.default;
270
- }
271
- if (policy.scaleApplication.deferredChannels?.includes(channel)) {
272
- return "defer";
273
- }
274
- return policy.scaleApplication.default;
275
- }
276
-
277
- export function canDeferScaleConsumerApplication(layer) {
278
- return getMarkPolicy(layer)?.scaleApplication.deferWithMark === true;
279
- }
280
-
281
- export function getExistingMarkRematerializationStep(program, layer) {
282
- const policy = getMarkPolicy(layer);
283
- if (
284
- policy?.rematerializeIncompleteExisting !== true ||
285
- program.graphicSpec.objects[layer.id] === undefined
286
- ) {
287
- return undefined;
288
- }
289
- return getMarkRematerializationStep(layer);
290
- }
291
-
292
- export function getEncodingMaterializationStages(program, layer, channel, scale) {
293
- const policy = getMarkPolicy(layer);
294
- if (policy === undefined) return { scales: [], marks: [] };
295
- const scales = policy.encoding?.scaleFirst === true && scale !== undefined
296
- ? [{
297
- op: "rematerializeScale",
298
- args: { id: scale, guides: false, marks: false }
299
- }]
300
- : [];
301
- const shared = policy.encoding?.sharedChannels?.includes(channel) === true &&
302
- scale !== undefined;
303
- const candidates = shared
304
- ? program.semanticSpec.layers.filter(candidate =>
305
- candidate.mark?.type === layer.mark?.type &&
306
- candidate.encoding?.[channel]?.scale === scale
307
- )
308
- : [layer];
309
- const marks = candidates.flatMap(candidate => {
310
- const step = policy.encoding?.completeOnly === true
311
- ? getMarkMaterializationStep(program, candidate)
312
- : getMarkRematerializationStep(candidate);
313
- return step === undefined ? [] : [step];
314
- });
315
- return { scales, marks };
316
- }