ggaction 0.0.24 → 0.0.26
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 +47 -0
- package/README.md +2 -2
- package/knowledge/action-cards.json +1 -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 +1 -1
- package/src/accessibility.js +13 -0
- package/src/actions/canvas/actions.js +2 -1
- package/src/actions/canvas/fitting.js +68 -13
- package/src/actions/charts/beeswarm.js +2 -1
- package/src/actions/charts/ecdf.js +2 -1
- package/src/actions/charts/endpoints.js +25 -16
- package/src/actions/charts/heatmap.js +5 -3
- package/src/actions/charts/missing.js +17 -0
- package/src/actions/charts/radar.js +70 -33
- package/src/actions/charts/raincloud.js +18 -4
- package/src/actions/charts/rug-strip.js +2 -2
- package/src/actions/charts/shared.js +17 -0
- package/src/actions/composition/actions.js +24 -7
- package/src/actions/composition/adjacent.js +90 -0
- package/src/actions/composition/index.js +11 -1
- package/src/actions/composition/layer.js +42 -0
- package/src/actions/composition/layerPlan.js +176 -0
- package/src/actions/composition/targets.js +105 -0
- package/src/actions/data/derived.js +3 -0
- package/src/actions/data/filter.js +1 -1
- package/src/actions/data/raincloudFilter.js +3 -1
- package/src/actions/encodings/appearance.js +26 -7
- package/src/actions/encodings/channels.js +1 -0
- package/src/actions/encodings/color/continuous.js +37 -34
- package/src/actions/encodings/color/index.js +57 -43
- package/src/actions/encodings/color/policy.js +15 -0
- package/src/actions/encodings/density/resolve.js +3 -2
- package/src/actions/encodings/density.js +2 -2
- package/src/actions/encodings/offset.js +2 -0
- package/src/actions/encodings/pathOrder.js +2 -0
- package/src/actions/encodings/position/areaAlignment.js +42 -0
- package/src/actions/encodings/position/index.js +37 -3
- package/src/actions/encodings/position/policies/line.js +1 -1
- package/src/actions/encodings/ranged.js +2 -0
- package/src/actions/encodings/remove.js +13 -10
- package/src/actions/encodings/ruleAppearance.js +14 -2
- package/src/actions/facets/actions.js +1 -1
- package/src/actions/guides/axes/axes.js +2 -1
- package/src/actions/guides/axes/edit.js +1 -1
- package/src/actions/guides/axes/labels.js +2 -1
- package/src/actions/guides/axes/parallel/lifecycle.js +11 -4
- package/src/actions/guides/axes/parallel/policy.js +5 -2
- package/src/actions/guides/axes/parallel/resolve.js +3 -1
- package/src/actions/guides/axes/parallel.js +9 -4
- package/src/actions/guides/axes/titles.js +1 -1
- package/src/actions/guides/facadeLegend.js +3 -2
- package/src/actions/guides/grids/grid.js +3 -2
- package/src/actions/guides/grids/resolve.js +2 -1
- package/src/actions/guides/guides.js +3 -2
- package/src/actions/guides/legends/automatic.js +28 -0
- package/src/actions/guides/legends/blocks.js +15 -21
- package/src/actions/guides/legends/categorical/actions.js +1 -1
- package/src/actions/guides/legends/categorical/components.js +4 -3
- package/src/actions/guides/legends/categorical/layout.js +5 -2
- package/src/actions/guides/legends/categorical/options.js +9 -14
- package/src/actions/guides/legends/categorical/recipes.js +3 -0
- package/src/actions/guides/legends/categorical/resolve.js +7 -5
- package/src/actions/guides/legends/colorSize.js +51 -14
- package/src/actions/guides/legends/continuous/common.js +1 -1
- package/src/actions/guides/legends/continuous/gradient.js +1 -1
- package/src/actions/guides/legends/continuous/opacity.js +2 -0
- package/src/actions/guides/legends/edit.js +1 -1
- package/src/actions/guides/legends/focused.js +2 -2
- package/src/actions/guides/legends/group.js +1 -1
- package/src/actions/guides/legends/lane.js +1 -1
- package/src/actions/guides/legends/lifecycle.js +2 -2
- package/src/actions/guides/legends/remove.js +18 -4
- package/src/actions/guides/legends/size.js +1 -1
- package/src/actions/guides/legends/transition.js +15 -6
- package/src/actions/guides/polar/axes/facade.js +4 -2
- package/src/actions/guides/polar/axes/labels.js +6 -1
- package/src/actions/guides/polar/axes/shared.js +4 -4
- package/src/actions/guides/polar/axes/titles.js +13 -2
- package/src/actions/guides/polar/grids.js +6 -3
- package/src/actions/guides/tickValues.js +7 -1
- package/src/actions/index.js +2 -0
- package/src/actions/marks/area/actions.js +9 -2
- package/src/actions/marks/area/materialize.js +1 -1
- package/src/actions/marks/bar/materialize.js +4 -4
- package/src/actions/marks/lifecycle.js +14 -0
- package/src/actions/marks/line/actions.js +3 -0
- package/src/actions/marks/line/materialize.js +4 -2
- package/src/actions/marks/point/edit.js +2 -0
- package/src/actions/marks/point/jitter.js +2 -0
- package/src/actions/marks/point/materialize.js +5 -4
- package/src/actions/marks/point/packing.js +2 -0
- package/src/actions/marks/references.js +5 -3
- package/src/actions/marks/remove.js +16 -0
- package/src/actions/marks/shared.js +2 -1
- package/src/actions/marks/text/actions.js +5 -2
- package/src/actions/overlays/index.js +168 -0
- package/src/actions/overlays/snapshot.js +45 -0
- package/src/actions/primitives/editGraphics.js +21 -27
- package/src/actions/primitives/semanticAction.js +4 -5
- package/src/actions/primitives/semanticValidation/guide.js +1 -0
- package/src/actions/primitives/semanticValidation/layer.js +7 -0
- package/src/actions/scales/consumers/common.js +10 -0
- package/src/actions/scales/consumers/families.js +1 -1
- package/src/actions/scales/preview.js +1 -1
- package/src/actions/selection/actions.js +63 -11
- package/src/actions/titles/actions.js +3 -14
- package/src/actions/titles/resolve.js +12 -9
- package/src/core/action.js +41 -25
- package/src/core/compositionScales.js +12 -0
- package/src/core/compositionState.js +16 -2
- package/src/core/immutable.js +11 -6
- package/src/core/programState.js +16 -0
- package/src/core/resourceReferences.js +19 -3
- package/src/core/validation.js +7 -0
- package/src/core/vocabulary.js +8 -2
- package/src/grammar/actionTargets.js +24 -0
- package/src/grammar/bin2d.js +7 -0
- package/src/grammar/colorSizeLegend.js +56 -5
- package/src/grammar/displayLabels.js +10 -0
- package/src/grammar/facetHeaders.js +1 -1
- package/src/grammar/facets/dependencies.js +10 -3
- package/src/grammar/facets/guides.js +2 -1
- package/src/grammar/facets/legendIntent.js +7 -5
- package/src/grammar/legendBlocks.js +1 -1
- package/src/grammar/legendCombinations.js +1 -1
- package/src/grammar/legendGroups.js +1 -1
- package/src/grammar/legendItemsOffset.js +12 -0
- package/src/grammar/legendOverflow.js +25 -0
- package/src/grammar/lineSeries.js +1 -1
- package/src/grammar/markSelection.js +23 -0
- package/src/grammar/overlay.js +51 -0
- package/src/grammar/parallelCoordinates.js +1 -208
- package/src/grammar/pathCommands.js +8 -2
- package/src/grammar/pathSeries.js +1 -1
- package/src/grammar/plotComposition.js +152 -0
- package/src/grammar/pointShapes.js +18 -0
- package/src/grammar/scales/transformed.js +1 -1
- package/src/grammar/schemas/concreteGraphic.js +8 -1
- package/src/grammar/schemas/graphicBounds.js +8 -1
- package/src/grammar/schemas/graphicTree.js +18 -2
- package/src/grammar/schemas/semanticPath.js +3 -0
- package/src/grammar/strokeStyle.js +14 -8
- package/src/grammar/text.js +72 -0
- package/src/inspection.js +1 -1
- package/src/inspectionDescriptors.js +1 -1
- package/src/layout/composition.js +30 -4
- package/src/layout/compositionLegend.js +91 -0
- package/src/layout/facetHeaderTitles.js +1 -1
- package/src/layout/labels.js +55 -27
- package/src/layout/legend.js +3 -2
- package/src/layout/legendGroup.js +1 -1
- package/src/layout/legendItems.js +7 -6
- package/src/layout/legendLane.js +1 -1
- package/src/layout/legendText.js +1 -1
- package/src/materialization/adjacentSource.js +27 -0
- package/src/materialization/composition.js +165 -52
- package/src/materialization/compositionLegends.js +120 -0
- package/src/materialization/compositionScales.js +125 -0
- package/src/materialization/compositionTitle.js +96 -0
- package/src/materialization/facetGuides/edit.js +22 -2
- package/src/materialization/facetGuides/layout.js +1 -1
- package/src/materialization/facetGuides/owner.js +4 -3
- package/src/materialization/facetGuides/ownerLayout.js +12 -6
- package/src/materialization/facetGuides/placement.js +19 -22
- package/src/materialization/facetGuides/preparation.js +17 -5
- package/src/materialization/facetHeaders.js +5 -1
- package/src/materialization/facets.js +1 -1
- package/src/materialization/guides/layout.js +1 -1
- package/src/materialization/guides/resources.js +1 -1
- package/src/materialization/guides/visibility.js +105 -0
- package/src/materialization/legendClip.js +1 -1
- package/src/materialization/legendGroups.js +1 -1
- package/src/materialization/legendItemsOffset.js +68 -0
- package/src/materialization/legendSuppression.js +22 -0
- package/src/materialization/legends.js +3 -2
- package/src/materialization/marks/capabilities.js +4 -0
- package/src/materialization/marks/index.js +5 -1
- package/src/materialization/marks/pathOrder.js +1 -1
- package/src/materialization/marks/policies.js +2 -1
- package/src/materialization/overlayItems.js +154 -0
- package/src/materialization/scales/policies/binnedPosition.js +43 -5
- package/src/materialization/scales/policies/series.js +12 -4
- package/src/materialization/scales/resolve.js +2 -0
- package/src/materialization/selection/items/bar.js +21 -3
- package/src/materialization/selection/items/common.js +18 -5
- package/src/materialization/selection/items/overlay.js +15 -0
- package/src/materialization/selection/items/path.js +1 -0
- package/src/materialization/selection/items/point.js +2 -3
- package/src/materialization/selection/items/tick.js +3 -12
- package/src/materialization/selection/path.js +2 -2
- package/src/materialization/selection/policies/bar.js +2 -0
- package/src/materialization/selection/policies/index.js +35 -1
- package/src/materialization/selection/policies/point.js +2 -0
- package/src/materialization/selection/policies/text.js +17 -0
- package/src/materialization/selection/rows.js +103 -0
- package/src/materialization/selection/state.js +19 -3
- package/src/materialization/selection/styles.js +8 -0
- package/src/materialization/text.js +6 -489
- package/src/materialization/textGeometry.js +503 -0
- package/src/materialization/textLines.js +20 -0
- package/src/persistence/validation.js +97 -24
- package/src/renderers/canvas/index.js +12 -7
- package/src/renderers/canvas/text.js +5 -5
- package/src/renderers/nativeBackend.js +25 -0
- package/src/renderers/pdf.js +3 -3
- package/src/renderers/png.js +4 -3
- package/src/renderers/svgSerialization.js +1 -643
- package/src/scene.js +5 -3
- package/src/selectors/plotComposition.js +115 -0
- package/src/selectors/selectionTargets.js +19 -0
- package/src/version.js +1 -1
- package/types/basic.d.ts +2 -2
- package/types/index.d.ts +11 -0
- package/types/inspection.d.ts +34 -0
- package/types/program.d.ts +553 -365
|
@@ -1,493 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
normalizeMarkLabelPlacement,
|
|
5
|
-
resolveMarkLabelPlacement
|
|
6
|
-
} from "../layout/labels.js";
|
|
7
|
-
import { resolveMarkLabelValues } from "../grammar/markLabels.js";
|
|
8
|
-
import { formatTextValue, resolveTextLines, resolveTextOffsetDataset, textOffsetValue } from "../grammar/text.js";
|
|
9
|
-
import { normalizePositionDatum } from "../grammar/positionDatum.js";
|
|
10
|
-
import { mapOrdinalPositionValues } from "../grammar/scales/index.js";
|
|
11
|
-
import { findDataset } from "../selectors/datasets.js";
|
|
12
|
-
import { findCoordinate } from "../selectors/coordinates.js";
|
|
13
|
-
import { findLayer } from "../selectors/layers.js";
|
|
14
|
-
import { unionConcreteGraphicBounds } from
|
|
15
|
-
"../grammar/schemas/graphicBounds.js";
|
|
16
|
-
import { polarDirection } from "../grammar/polar.js";
|
|
17
|
-
import { resolveMarkItems } from "./selection/policies/index.js";
|
|
18
|
-
import { resolveMarkSelection } from "./selection/state.js";
|
|
19
|
-
import { mapScaleConsumerValues } from "./scales/map.js";
|
|
20
|
-
import { resolveRowEncodingValues } from "./rowEncoding.js";
|
|
1
|
+
import { resolveMarkItems } from './selection/policies/index.js';
|
|
2
|
+
import { resolveTextGraphicEntries as resolveEntries } from './textGeometry.js';
|
|
3
|
+
export { sourceValue, validateSourceMarkLabelPlacement } from './textGeometry.js';
|
|
21
4
|
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
: source.mark.type === "arc" ? "radius" : undefined;
|
|
25
|
-
const encoding = source.encoding?.[measure];
|
|
26
|
-
if (encoding?.field === field && encoding.aggregate != null && item.channels[measure] !== undefined) {
|
|
27
|
-
return source.mark.type === "bar"
|
|
28
|
-
? item.channels[`${measure}2`] ?? item.channels[measure]
|
|
29
|
-
: item.channels[measure];
|
|
30
|
-
}
|
|
31
|
-
if (Object.hasOwn(item.fields, field)) return item.fields[field];
|
|
32
|
-
for (const [channel, encoding] of Object.entries(source.encoding ?? {})) {
|
|
33
|
-
if (encoding?.field !== field || item.channels[channel] === undefined) continue;
|
|
34
|
-
if (source.mark.type === "bar" && item.channels[`${channel}2`] !== undefined) {
|
|
35
|
-
return item.channels[`${channel}2`];
|
|
36
|
-
}
|
|
37
|
-
return item.channels[channel];
|
|
38
|
-
}
|
|
39
|
-
if (item.members.length === 1 && Object.hasOwn(item.members[0], field)) {
|
|
40
|
-
return item.members[0][field];
|
|
41
|
-
}
|
|
42
|
-
if (source.mark.type === "line" && item.members.length > 0) {
|
|
43
|
-
const endpoint = item.members.at(-1);
|
|
44
|
-
if (Object.hasOwn(endpoint, field)) return endpoint[field];
|
|
45
|
-
}
|
|
46
|
-
return undefined;
|
|
5
|
+
export function resolveTextGraphicEntries(program, layer, config, options = {}) {
|
|
6
|
+
return resolveEntries(program, layer, config, { ...options, resolveMarkItems });
|
|
47
7
|
}
|
|
48
|
-
|
|
49
|
-
function barAnchor(program, source, item) {
|
|
50
|
-
const channels = resolveBarChannels(source);
|
|
51
|
-
const measure = channels.measure;
|
|
52
|
-
const endpoint = item.channels[`${measure}2`];
|
|
53
|
-
const scale = program.resolvedScales[source.encoding[measure].scale];
|
|
54
|
-
const mapped = endpoint === undefined || scale === undefined
|
|
55
|
-
? undefined
|
|
56
|
-
: mapScaleConsumerValues([endpoint], scale, measure)[0];
|
|
57
|
-
return measure === "x"
|
|
58
|
-
? {
|
|
59
|
-
x: mapped ?? item.properties.x + item.properties.width,
|
|
60
|
-
y: item.properties.y + item.properties.height / 2
|
|
61
|
-
}
|
|
62
|
-
: {
|
|
63
|
-
x: item.properties.x + item.properties.width / 2,
|
|
64
|
-
y: mapped ?? item.properties.y
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function sourceAnchor(program, source, item) {
|
|
69
|
-
if (source.mark.type === "bar") return barAnchor(program, source, item);
|
|
70
|
-
if (source.mark.type === "rect") {
|
|
71
|
-
return {
|
|
72
|
-
x: item.properties.x + item.properties.width / 2,
|
|
73
|
-
y: item.properties.y + item.properties.height / 2
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
if (source.mark.type === "rule") {
|
|
77
|
-
return {
|
|
78
|
-
x: item.properties.x2,
|
|
79
|
-
y: item.properties.y2
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (source.mark.type === "line") {
|
|
83
|
-
const graphicId = item.graphicIds?.[0];
|
|
84
|
-
const graphic = program.graphicSpec.objects[source.id]?.items?.find(
|
|
85
|
-
candidate => candidate.id === graphicId
|
|
86
|
-
);
|
|
87
|
-
const commands = graphic?.properties?.commands;
|
|
88
|
-
const endpoint = Array.isArray(commands)
|
|
89
|
-
? [...commands].reverse().find(command => Number.isFinite(command.x) && Number.isFinite(command.y))
|
|
90
|
-
: undefined;
|
|
91
|
-
return { x: endpoint?.x, y: endpoint?.y };
|
|
92
|
-
}
|
|
93
|
-
return { x: item.properties.x, y: item.properties.y };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function explicitIntervalAxis(source) {
|
|
97
|
-
const axes = ["x", "y"].filter(axis =>
|
|
98
|
-
source.encoding?.[axis] !== undefined &&
|
|
99
|
-
source.encoding?.[`${axis}2`] !== undefined
|
|
100
|
-
);
|
|
101
|
-
return axes.length === 1 ? axes[0] : undefined;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function sourcePlacementContext(program, source) {
|
|
105
|
-
const coordinateType = findCoordinate(program, source.coordinate)?.type;
|
|
106
|
-
return {
|
|
107
|
-
markType: source.mark.type,
|
|
108
|
-
coordinateType,
|
|
109
|
-
intervalAxis: source.mark.type === "bar"
|
|
110
|
-
? resolveBarChannels(source).measure
|
|
111
|
-
: source.mark.type === "rect"
|
|
112
|
-
? explicitIntervalAxis(source)
|
|
113
|
-
: undefined
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function validateSourceMarkLabelPlacement(program, sourceId, value) {
|
|
118
|
-
const source = findLayer(program, sourceId);
|
|
119
|
-
if (source === undefined) {
|
|
120
|
-
throw new Error(`Unknown mark label placement source "${sourceId}".`);
|
|
121
|
-
}
|
|
122
|
-
const placement = normalizeMarkLabelPlacement(value);
|
|
123
|
-
assertMarkLabelPlacementSupport(sourcePlacementContext(program, source), placement);
|
|
124
|
-
return placement;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function rectangleBounds(item) {
|
|
128
|
-
const { x, y, width, height } = item.properties;
|
|
129
|
-
if (![x, y, width, height].every(Number.isFinite)) {
|
|
130
|
-
throw new TypeError("Interval mark label placement requires finite rectangle geometry.");
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
left: Math.min(x, x + width),
|
|
134
|
-
right: Math.max(x, x + width),
|
|
135
|
-
top: Math.min(y, y + height),
|
|
136
|
-
bottom: Math.max(y, y + height)
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function mappedChannel(program, source, item, channel) {
|
|
141
|
-
const value = item.channels[channel];
|
|
142
|
-
const primary = channel === "x2" ? "x" : channel === "y2" ? "y" : channel;
|
|
143
|
-
const scale = program.resolvedScales[
|
|
144
|
-
source.encoding?.[channel]?.scale ?? source.encoding?.[primary]?.scale
|
|
145
|
-
];
|
|
146
|
-
return value === undefined || scale === undefined
|
|
147
|
-
? undefined
|
|
148
|
-
: mapScaleConsumerValues([value], scale, channel)[0];
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function scaleIncreaseDirection(program, source, axis) {
|
|
152
|
-
const scale = program.resolvedScales[source.encoding?.[axis]?.scale];
|
|
153
|
-
const domain = scale?.domain;
|
|
154
|
-
if (!Array.isArray(domain) || domain.length < 2) {
|
|
155
|
-
return axis === "x" ? { x: 1, y: 0 } : { x: 0, y: -1 };
|
|
156
|
-
}
|
|
157
|
-
const mapped = mapScaleConsumerValues(
|
|
158
|
-
[domain[0], domain.at(-1)],
|
|
159
|
-
scale,
|
|
160
|
-
axis
|
|
161
|
-
);
|
|
162
|
-
const delta = mapped[1] - mapped[0];
|
|
163
|
-
if (!Number.isFinite(delta) || delta === 0) {
|
|
164
|
-
return axis === "x" ? { x: 1, y: 0 } : { x: 0, y: -1 };
|
|
165
|
-
}
|
|
166
|
-
return axis === "x"
|
|
167
|
-
? { x: Math.sign(delta), y: 0 }
|
|
168
|
-
: { x: 0, y: Math.sign(delta) };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function intervalPlacementGeometry(program, source, item, axis) {
|
|
172
|
-
const bounds = rectangleBounds(item);
|
|
173
|
-
const primary = mappedChannel(program, source, item, axis);
|
|
174
|
-
const secondary = mappedChannel(program, source, item, `${axis}2`);
|
|
175
|
-
if (![primary, secondary].every(Number.isFinite)) {
|
|
176
|
-
throw new TypeError(
|
|
177
|
-
`${source.mark.type === "bar" ? "Bar" : "Rect"} semantic label placement requires resolved ${axis}/${axis}2 endpoints.`
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
const cross = axis === "x"
|
|
181
|
-
? (bounds.top + bounds.bottom) / 2
|
|
182
|
-
: (bounds.left + bounds.right) / 2;
|
|
183
|
-
const start = axis === "x" ? { x: primary, y: cross } : { x: cross, y: primary };
|
|
184
|
-
const end = axis === "x" ? { x: secondary, y: cross } : { x: cross, y: secondary };
|
|
185
|
-
const delta = { x: end.x - start.x, y: end.y - start.y };
|
|
186
|
-
const length = Math.hypot(delta.x, delta.y);
|
|
187
|
-
const endOutward = length > 0
|
|
188
|
-
? { x: delta.x / length, y: delta.y / length }
|
|
189
|
-
: scaleIncreaseDirection(program, source, axis);
|
|
190
|
-
return {
|
|
191
|
-
kind: "interval",
|
|
192
|
-
center: {
|
|
193
|
-
x: (bounds.left + bounds.right) / 2,
|
|
194
|
-
y: (bounds.top + bounds.bottom) / 2
|
|
195
|
-
},
|
|
196
|
-
start: {
|
|
197
|
-
point: start,
|
|
198
|
-
outward: { x: -endOutward.x, y: -endOutward.y }
|
|
199
|
-
},
|
|
200
|
-
end: { point: end, outward: endOutward },
|
|
201
|
-
bounds
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function pointPlacementGeometry(program, source, item) {
|
|
206
|
-
const center = { x: item.properties.x, y: item.properties.y };
|
|
207
|
-
const coordinateType = findCoordinate(program, source.coordinate)?.type;
|
|
208
|
-
if (coordinateType !== "polar") return { kind: "point", center };
|
|
209
|
-
const thetaScale = program.resolvedScales[source.encoding?.theta?.scale];
|
|
210
|
-
const theta = item.channels.theta === undefined || thetaScale === undefined
|
|
211
|
-
? undefined
|
|
212
|
-
: mapScaleConsumerValues([item.channels.theta], thetaScale, "theta")[0];
|
|
213
|
-
const outward = Number.isFinite(theta) ? polarDirection(theta) : { x: 0, y: -1 };
|
|
214
|
-
const objectBounds = unionConcreteGraphicBounds(
|
|
215
|
-
program.graphicSpec,
|
|
216
|
-
item.graphicIds
|
|
217
|
-
, program.materializationConfigs.textMetrics);
|
|
218
|
-
const corners = objectBounds === undefined ? [] : [
|
|
219
|
-
{ x: objectBounds.left, y: objectBounds.top },
|
|
220
|
-
{ x: objectBounds.right, y: objectBounds.top },
|
|
221
|
-
{ x: objectBounds.right, y: objectBounds.bottom },
|
|
222
|
-
{ x: objectBounds.left, y: objectBounds.bottom }
|
|
223
|
-
];
|
|
224
|
-
const support = Math.max(0, ...corners.map(point =>
|
|
225
|
-
(point.x - center.x) * outward.x + (point.y - center.y) * outward.y
|
|
226
|
-
));
|
|
227
|
-
return {
|
|
228
|
-
kind: "point",
|
|
229
|
-
center,
|
|
230
|
-
end: {
|
|
231
|
-
point: {
|
|
232
|
-
x: center.x + outward.x * support,
|
|
233
|
-
y: center.y + outward.y * support
|
|
234
|
-
},
|
|
235
|
-
outward
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function sourcePlacementGeometry(program, source, item) {
|
|
241
|
-
if (source.mark.type === "bar") {
|
|
242
|
-
return intervalPlacementGeometry(
|
|
243
|
-
program,
|
|
244
|
-
source,
|
|
245
|
-
item,
|
|
246
|
-
resolveBarChannels(source).measure
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
if (source.mark.type === "rect") {
|
|
250
|
-
const axis = explicitIntervalAxis(source);
|
|
251
|
-
return axis === undefined
|
|
252
|
-
? { kind: "point", center: sourceAnchor(program, source, item) }
|
|
253
|
-
: intervalPlacementGeometry(program, source, item, axis);
|
|
254
|
-
}
|
|
255
|
-
if (source.mark.type === "arc") return item.geometry;
|
|
256
|
-
if (source.mark.type === "point") {
|
|
257
|
-
return pointPlacementGeometry(program, source, item);
|
|
258
|
-
}
|
|
259
|
-
return { kind: "point", center: sourceAnchor(program, source, item) };
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function contentValue(encoding, rowOrItem, source) {
|
|
263
|
-
return Object.hasOwn(encoding, "field")
|
|
264
|
-
? source === undefined
|
|
265
|
-
? rowOrItem[encoding.field]
|
|
266
|
-
: sourceValue(rowOrItem, source, encoding.field)
|
|
267
|
-
: encoding.datum;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function concreteTextItem(config, position, text, { offsets = true } = {}) {
|
|
271
|
-
const x = position.x;
|
|
272
|
-
const y = position.y;
|
|
273
|
-
if (text === undefined || !Number.isFinite(x) || !Number.isFinite(y)) {
|
|
274
|
-
return undefined;
|
|
275
|
-
}
|
|
276
|
-
const lines = resolveTextLines(text, config);
|
|
277
|
-
return {
|
|
278
|
-
type: "text",
|
|
279
|
-
properties: {
|
|
280
|
-
x: x + (offsets ? config.dx : 0),
|
|
281
|
-
y: y + (offsets ? config.dy : 0),
|
|
282
|
-
text,
|
|
283
|
-
...(lines === undefined ? {} : { lines }),
|
|
284
|
-
fill: config.fill,
|
|
285
|
-
opacity: config.opacity,
|
|
286
|
-
fontSize: config.fontSize,
|
|
287
|
-
fontFamily: config.fontFamily,
|
|
288
|
-
fontWeight: config.fontWeight,
|
|
289
|
-
textAlign: config.align,
|
|
290
|
-
textBaseline: config.baseline,
|
|
291
|
-
rotation: config.rotation
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function concreteItem(config, position, value, format) {
|
|
297
|
-
return concreteTextItem(config, position, formatTextValue(value, format));
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function relativeLuminance(color) {
|
|
301
|
-
if (typeof color !== "string" || !/^#[0-9a-f]{6}$/i.test(color)) {
|
|
302
|
-
return undefined;
|
|
303
|
-
}
|
|
304
|
-
const channels = [1, 3, 5].map(offset =>
|
|
305
|
-
Number.parseInt(color.slice(offset, offset + 2), 16) / 255
|
|
306
|
-
).map(value => value <= 0.04045
|
|
307
|
-
? value / 12.92
|
|
308
|
-
: ((value + 0.055) / 1.055) ** 2.4
|
|
309
|
-
);
|
|
310
|
-
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2];
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function sourceTextConfig(config, source, item) {
|
|
314
|
-
if (config.inheritColor && config.fillExplicit !== true) {
|
|
315
|
-
const fill = item.properties[config.inheritColor];
|
|
316
|
-
if (typeof fill !== "string") throw new Error(`Source mark "${source.id}" has no resolved ${config.inheritColor} color.`);
|
|
317
|
-
return { ...config, fill };
|
|
318
|
-
}
|
|
319
|
-
if (
|
|
320
|
-
!["arc", "rect"].includes(source.mark.type) ||
|
|
321
|
-
config.fillExplicit === true
|
|
322
|
-
) return config;
|
|
323
|
-
const luminance = relativeLuminance(item.properties.fill);
|
|
324
|
-
if (luminance === undefined) return config;
|
|
325
|
-
return {
|
|
326
|
-
...config,
|
|
327
|
-
fill: luminance >= 0.26 ? "#0f172a" : "#f8fafc"
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function resolveSourceTextItems(program, layer, config) {
|
|
332
|
-
const source = findLayer(program, layer.source);
|
|
333
|
-
if (source === undefined) {
|
|
334
|
-
throw new Error(`Text mark "${layer.id}" requires source layer "${layer.source}".`);
|
|
335
|
-
}
|
|
336
|
-
const requested = program.markConfigs[layer.id]?.labelAuthoring?.selection ?? {
|
|
337
|
-
kind: "all"
|
|
338
|
-
};
|
|
339
|
-
let allItems;
|
|
340
|
-
let items;
|
|
341
|
-
if (requested.kind === "all") {
|
|
342
|
-
allItems = resolveMarkItems(program, source.id);
|
|
343
|
-
items = allItems;
|
|
344
|
-
} else if (requested.kind === "inline") {
|
|
345
|
-
const resolved = resolveMarkSelection(program, source.id, requested.selector);
|
|
346
|
-
allItems = resolved.items;
|
|
347
|
-
const selected = new Set(resolved.keys);
|
|
348
|
-
items = allItems.filter(item => selected.has(item.key));
|
|
349
|
-
} else if (requested.kind === "named") {
|
|
350
|
-
const definition = program.materializationConfigs.selections?.[requested.id];
|
|
351
|
-
if (definition === undefined) {
|
|
352
|
-
throw new Error(`Unknown label selection "${requested.id}".`);
|
|
353
|
-
}
|
|
354
|
-
if (definition.target !== source.id) {
|
|
355
|
-
throw new Error(
|
|
356
|
-
`Label selection "${requested.id}" must target source mark "${source.id}".`
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
const resolved = resolveMarkSelection(program, source.id, definition.selector);
|
|
360
|
-
allItems = resolved.items;
|
|
361
|
-
const selected = new Set(resolved.keys);
|
|
362
|
-
items = allItems.filter(item => selected.has(item.key));
|
|
363
|
-
} else {
|
|
364
|
-
throw new Error(`Unknown label selection kind "${requested.kind}".`);
|
|
365
|
-
}
|
|
366
|
-
const resolvedValues = layer.encoding.text.content === undefined ? undefined
|
|
367
|
-
: resolveMarkLabelValues(source, allItems, layer.encoding.text);
|
|
368
|
-
const values = resolvedValues === undefined ? undefined : new Map(
|
|
369
|
-
allItems.map((item, index) => [item.key, resolvedValues[index]])
|
|
370
|
-
);
|
|
371
|
-
return items.flatMap(item => {
|
|
372
|
-
let resolvedConfig = sourceTextConfig(config, source, item);
|
|
373
|
-
const text = formatTextValue(
|
|
374
|
-
values === undefined
|
|
375
|
-
? contentValue(layer.encoding.text, item, source)
|
|
376
|
-
: values.get(item.key),
|
|
377
|
-
layer.encoding.text.format
|
|
378
|
-
);
|
|
379
|
-
if (text === undefined) return [];
|
|
380
|
-
const placement = program.markConfigs[layer.id]?.labelAuthoring?.placement;
|
|
381
|
-
if (placement === undefined) {
|
|
382
|
-
const anchor = sourceAnchor(program, source, item);
|
|
383
|
-
const concrete = concreteTextItem(resolvedConfig, anchor, text);
|
|
384
|
-
return concrete === undefined ? [] : [{ graphic: concrete, anchor }];
|
|
385
|
-
}
|
|
386
|
-
assertMarkLabelPlacementSupport(sourcePlacementContext(program, source), placement);
|
|
387
|
-
const resolved = resolveMarkLabelPlacement({
|
|
388
|
-
placement,
|
|
389
|
-
geometry: sourcePlacementGeometry(program, source, item),
|
|
390
|
-
text: {
|
|
391
|
-
text,
|
|
392
|
-
lines: resolveTextLines(text, resolvedConfig),
|
|
393
|
-
fontSize: resolvedConfig.fontSize,
|
|
394
|
-
fontFamily: resolvedConfig.fontFamily,
|
|
395
|
-
fontWeight: resolvedConfig.fontWeight,
|
|
396
|
-
textAlign: resolvedConfig.align,
|
|
397
|
-
textBaseline: resolvedConfig.baseline,
|
|
398
|
-
rotation: resolvedConfig.rotation,
|
|
399
|
-
dx: resolvedConfig.dx,
|
|
400
|
-
dy: resolvedConfig.dy
|
|
401
|
-
}
|
|
402
|
-
}, program.materializationConfigs.textMetrics);
|
|
403
|
-
if (!resolved.visible) return [];
|
|
404
|
-
if (
|
|
405
|
-
resolved.anchor.startsWith("outside") &&
|
|
406
|
-
config.fillExplicit !== true && !config.inheritColor
|
|
407
|
-
) {
|
|
408
|
-
resolvedConfig = config;
|
|
409
|
-
}
|
|
410
|
-
const anchor = { x: resolved.sourceX, y: resolved.sourceY };
|
|
411
|
-
return [{
|
|
412
|
-
graphic: concreteTextItem(
|
|
413
|
-
resolvedConfig,
|
|
414
|
-
{ x: resolved.x, y: resolved.y },
|
|
415
|
-
text,
|
|
416
|
-
{ offsets: false }
|
|
417
|
-
),
|
|
418
|
-
anchor,
|
|
419
|
-
placement: resolved
|
|
420
|
-
}];
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function resolveRowTextItems(program, layer, config) {
|
|
425
|
-
const sourceDataset = findDataset(program, layer.data);
|
|
426
|
-
if (sourceDataset === undefined) {
|
|
427
|
-
throw new Error(`Text mark "${layer.id}" requires an existing dataset.`);
|
|
428
|
-
}
|
|
429
|
-
const dataset = resolveTextOffsetDataset(layer, sourceDataset);
|
|
430
|
-
const encodings = [layer.encoding?.x, layer.encoding?.y, layer.encoding?.text, layer.encoding?.color,
|
|
431
|
-
layer.encoding?.dx, layer.encoding?.dy];
|
|
432
|
-
const length = encodings.some(encoding => encoding !== undefined && Object.hasOwn(encoding, "field"))
|
|
433
|
-
? dataset.values.length
|
|
434
|
-
: 1;
|
|
435
|
-
const positionValues = channel => {
|
|
436
|
-
const encoding = layer.encoding?.[channel];
|
|
437
|
-
if (encoding === undefined) return undefined;
|
|
438
|
-
if (Object.hasOwn(encoding, "field")) {
|
|
439
|
-
return resolveRowEncodingValues(program, layer, dataset, channel);
|
|
440
|
-
}
|
|
441
|
-
const scale = program.resolvedScales[encoding.scale];
|
|
442
|
-
if (scale === undefined) {
|
|
443
|
-
throw new Error(
|
|
444
|
-
`text mark "${layer.id}" requires resolved ${channel} scale "${encoding.scale}".`
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
const datum = normalizePositionDatum(
|
|
448
|
-
encoding.datum,
|
|
449
|
-
encoding.fieldType,
|
|
450
|
-
channel,
|
|
451
|
-
encoding.temporalUnit,
|
|
452
|
-
"Text"
|
|
453
|
-
);
|
|
454
|
-
const mapped = ["nominal", "ordinal"].includes(encoding.fieldType)
|
|
455
|
-
? mapOrdinalPositionValues([datum], scale)
|
|
456
|
-
: mapScaleConsumerValues([datum], scale, channel);
|
|
457
|
-
return Array.from({ length }, () => mapped[0]);
|
|
458
|
-
};
|
|
459
|
-
const x = positionValues("x");
|
|
460
|
-
const y = positionValues("y");
|
|
461
|
-
if (x === undefined || y === undefined) return [];
|
|
462
|
-
const rows = length === 1 && dataset.values.length === 0
|
|
463
|
-
? [undefined]
|
|
464
|
-
: dataset.values.slice(0, length);
|
|
465
|
-
const fills = resolveRowEncodingValues(program, layer, dataset, "color");
|
|
466
|
-
return rows.flatMap((row, index) => {
|
|
467
|
-
const concrete = concreteItem(
|
|
468
|
-
{
|
|
469
|
-
...config,
|
|
470
|
-
...(fills === undefined ? {} : { fill: fills[index] }),
|
|
471
|
-
dx: textOffsetValue(layer.encoding?.dx, row, config.dx),
|
|
472
|
-
dy: textOffsetValue(layer.encoding?.dy, row, config.dy)
|
|
473
|
-
},
|
|
474
|
-
{ x: x[index], y: y[index] },
|
|
475
|
-
contentValue(layer.encoding.text, row),
|
|
476
|
-
layer.encoding.text.format
|
|
477
|
-
);
|
|
478
|
-
return concrete === undefined
|
|
479
|
-
? []
|
|
480
|
-
: [{ graphic: concrete, anchor: { x: x[index], y: y[index] } }];
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
export function resolveTextGraphicEntries(program, layer, config) {
|
|
485
|
-
return layer.source === undefined
|
|
486
|
-
? resolveRowTextItems(program, layer, config)
|
|
487
|
-
: resolveSourceTextItems(program, layer, config);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
8
|
export function resolveTextGraphicItems(program, layer, config) {
|
|
491
|
-
return resolveTextGraphicEntries(program, layer, config)
|
|
492
|
-
.map(entry => entry.graphic);
|
|
9
|
+
return resolveTextGraphicEntries(program, layer, config).map(entry => entry.graphic);
|
|
493
10
|
}
|