@opendata-ai/openchart-engine 9.4.0 → 9.6.0
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/dist/index.d.ts +2 -1
- package/dist/index.js +251 -154
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1642,6 +1642,7 @@ function normalizeTableSpec(spec, _warnings) {
|
|
|
1642
1642
|
data: spec.data,
|
|
1643
1643
|
columns: spec.columns,
|
|
1644
1644
|
rowKey: spec.rowKey,
|
|
1645
|
+
a11y: spec.a11y,
|
|
1645
1646
|
chrome: normalizeChrome2(spec.chrome),
|
|
1646
1647
|
theme: spec.theme ?? {},
|
|
1647
1648
|
search: spec.search ?? false,
|
|
@@ -1914,7 +1915,7 @@ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, paren
|
|
|
1914
1915
|
}
|
|
1915
1916
|
|
|
1916
1917
|
// src/compiler/validate.ts
|
|
1917
|
-
import { isRaceSpec as isRaceSpec2, jsonPointer as
|
|
1918
|
+
import { isRaceSpec as isRaceSpec2, jsonPointer as jsonPointer19, MARK_TYPES as MARK_TYPES2 } from "@opendata-ai/openchart-core";
|
|
1918
1919
|
|
|
1919
1920
|
// src/compiler/validation/barlist.ts
|
|
1920
1921
|
import { jsonPointer as jsonPointer3 } from "@opendata-ai/openchart-core";
|
|
@@ -3662,8 +3663,33 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
3662
3663
|
}
|
|
3663
3664
|
}
|
|
3664
3665
|
|
|
3666
|
+
// src/compiler/validation/chrome-links.ts
|
|
3667
|
+
import { isSafeLink, jsonPointer as jsonPointer8 } from "@opendata-ai/openchart-core";
|
|
3668
|
+
function validateChromeLinks(spec, errors, prefix = "") {
|
|
3669
|
+
const chrome = spec.chrome;
|
|
3670
|
+
if (chrome && typeof chrome === "object" && !Array.isArray(chrome)) {
|
|
3671
|
+
for (const [key, value] of Object.entries(chrome)) {
|
|
3672
|
+
if (!value || typeof value !== "object" || !("href" in value)) continue;
|
|
3673
|
+
if (value.href === void 0) continue;
|
|
3674
|
+
if (typeof value.href === "string" && isSafeLink(value.href)) continue;
|
|
3675
|
+
errors.push({
|
|
3676
|
+
code: "INVALID_VALUE",
|
|
3677
|
+
path: `${prefix}${jsonPointer8("chrome", key, "href")}`,
|
|
3678
|
+
message: `chrome.${key}.href must be an http, https or mailto link.`,
|
|
3679
|
+
suggestion: "Use an absolute http, https or mailto URL, or omit href."
|
|
3680
|
+
});
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
if (Array.isArray(spec.layer)) {
|
|
3684
|
+
for (const [index, child] of spec.layer.entries()) {
|
|
3685
|
+
if (child && typeof child === "object" && !Array.isArray(child))
|
|
3686
|
+
validateChromeLinks(child, errors, `${prefix}${jsonPointer8("layer", index)}`);
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3665
3691
|
// src/compiler/validation/common-fields.ts
|
|
3666
|
-
import { encodePointerToken as encodePointerToken2, jsonPointer as
|
|
3692
|
+
import { encodePointerToken as encodePointerToken2, jsonPointer as jsonPointer9 } from "@opendata-ai/openchart-core";
|
|
3667
3693
|
function validateAnimation(spec, errors) {
|
|
3668
3694
|
const animation = spec.animation;
|
|
3669
3695
|
if (typeof animation === "string" && !["fluid", "subtle"].includes(animation)) {
|
|
@@ -3722,7 +3748,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
3722
3748
|
errors.push({
|
|
3723
3749
|
code: "INVALID_VALUE",
|
|
3724
3750
|
suggestion: TIMING_SUGGESTION,
|
|
3725
|
-
path:
|
|
3751
|
+
path: jsonPointer9(...path),
|
|
3726
3752
|
message: "A phase cannot combine spring with duration or ease."
|
|
3727
3753
|
});
|
|
3728
3754
|
}
|
|
@@ -3730,7 +3756,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
3730
3756
|
errors.push({
|
|
3731
3757
|
code: "INVALID_VALUE",
|
|
3732
3758
|
suggestion: TIMING_SUGGESTION,
|
|
3733
|
-
path:
|
|
3759
|
+
path: jsonPointer9(...path, "spring"),
|
|
3734
3760
|
message: "Spring must be a configuration object."
|
|
3735
3761
|
});
|
|
3736
3762
|
} else {
|
|
@@ -3741,7 +3767,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
3741
3767
|
errors.push({
|
|
3742
3768
|
code: "INVALID_VALUE",
|
|
3743
3769
|
suggestion: TIMING_SUGGESTION,
|
|
3744
|
-
path:
|
|
3770
|
+
path: jsonPointer9(...path, "spring", key),
|
|
3745
3771
|
message: "Spring parameters must be finite positive stiffness, damping, or mass."
|
|
3746
3772
|
});
|
|
3747
3773
|
}
|
|
@@ -3756,7 +3782,7 @@ function validateDuration(duration, path, errors) {
|
|
|
3756
3782
|
errors.push({
|
|
3757
3783
|
code: "INVALID_VALUE",
|
|
3758
3784
|
suggestion: TIMING_SUGGESTION,
|
|
3759
|
-
path:
|
|
3785
|
+
path: jsonPointer9(...path, "duration"),
|
|
3760
3786
|
message: "Animation duration must be finite and nonnegative."
|
|
3761
3787
|
});
|
|
3762
3788
|
}
|
|
@@ -3766,7 +3792,7 @@ function validateEase(ease, path, errors) {
|
|
|
3766
3792
|
errors.push({
|
|
3767
3793
|
code: "INVALID_VALUE",
|
|
3768
3794
|
suggestion: "Use ease: 'smooth', 'snappy', or 'gentle'.",
|
|
3769
|
-
path:
|
|
3795
|
+
path: jsonPointer9(...path, "ease"),
|
|
3770
3796
|
message: `Animation ease must be 'smooth', 'snappy', or 'gentle', got ${JSON.stringify(ease)}.`
|
|
3771
3797
|
});
|
|
3772
3798
|
}
|
|
@@ -3832,7 +3858,7 @@ function validateFieldMetadata(obj, errors) {
|
|
|
3832
3858
|
return;
|
|
3833
3859
|
}
|
|
3834
3860
|
for (const [field, value] of Object.entries(obj.fields)) {
|
|
3835
|
-
const path =
|
|
3861
|
+
const path = jsonPointer9("fields", field);
|
|
3836
3862
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
3837
3863
|
fail2(path, "Field metadata must be an object.");
|
|
3838
3864
|
continue;
|
|
@@ -3875,7 +3901,7 @@ function validateFieldMetadata(obj, errors) {
|
|
|
3875
3901
|
}
|
|
3876
3902
|
|
|
3877
3903
|
// src/compiler/validation/geo-map.ts
|
|
3878
|
-
import { jsonPointer as
|
|
3904
|
+
import { jsonPointer as jsonPointer11 } from "@opendata-ai/openchart-core";
|
|
3879
3905
|
|
|
3880
3906
|
// src/geo/projections.ts
|
|
3881
3907
|
import { geoAlbersUsa, geoBounds, geoEqualEarth, geoIdentity, geoMercator } from "d3-geo";
|
|
@@ -3979,7 +4005,7 @@ function topologyBBox(topology) {
|
|
|
3979
4005
|
}
|
|
3980
4006
|
|
|
3981
4007
|
// src/compiler/validation/geo-time.ts
|
|
3982
|
-
import { jsonPointer as
|
|
4008
|
+
import { jsonPointer as jsonPointer10 } from "@opendata-ai/openchart-core";
|
|
3983
4009
|
var TIME_TYPES = ["temporal", "ordinal", "quantitative"];
|
|
3984
4010
|
var POINT_ONLY_OPTIONS = ["labels", "trails"];
|
|
3985
4011
|
function isRecord4(value) {
|
|
@@ -4037,7 +4063,7 @@ function checkPlaybackBlock(spec, errors) {
|
|
|
4037
4063
|
if (value === void 0 || value === false) continue;
|
|
4038
4064
|
errors.push(
|
|
4039
4065
|
invalid3(
|
|
4040
|
-
|
|
4066
|
+
jsonPointer10("playback", option),
|
|
4041
4067
|
`playback.${option} is only supported on point charts, not maps`,
|
|
4042
4068
|
`Remove playback.${option}.`
|
|
4043
4069
|
)
|
|
@@ -4199,7 +4225,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4199
4225
|
if (!["activeValue", "distribution"].includes(name) || typeof value !== "boolean")
|
|
4200
4226
|
errors.push({
|
|
4201
4227
|
code: "INVALID_VALUE",
|
|
4202
|
-
path:
|
|
4228
|
+
path: jsonPointer11("colorKey", name),
|
|
4203
4229
|
message: "colorKey accepts only boolean activeValue and distribution.",
|
|
4204
4230
|
suggestion: "Omit either option or set it to true or false."
|
|
4205
4231
|
});
|
|
@@ -4250,7 +4276,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4250
4276
|
if (typeof focus[i] !== "string" && typeof focus[i] !== "number") {
|
|
4251
4277
|
errors.push({
|
|
4252
4278
|
message: `Spec error: geo.focus array element [${i}] must be a string or number`,
|
|
4253
|
-
path:
|
|
4279
|
+
path: jsonPointer11("geo", "focus", i),
|
|
4254
4280
|
code: "INVALID_TYPE",
|
|
4255
4281
|
suggestion: "Each element in the focus array should be a feature id (string or number)"
|
|
4256
4282
|
});
|
|
@@ -4298,7 +4324,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4298
4324
|
if (typeof feats[i] !== "string" && typeof feats[i] !== "number") {
|
|
4299
4325
|
errors.push({
|
|
4300
4326
|
message: `Spec error: geo.focus.features[${i}] must be a string or number`,
|
|
4301
|
-
path:
|
|
4327
|
+
path: jsonPointer11("geo", "focus", "features", i),
|
|
4302
4328
|
code: "INVALID_TYPE",
|
|
4303
4329
|
suggestion: "Each element should be a feature id (string or number)"
|
|
4304
4330
|
});
|
|
@@ -4386,14 +4412,14 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4386
4412
|
if (!enc || typeof enc !== "object") {
|
|
4387
4413
|
errors.push({
|
|
4388
4414
|
message: `Spec error: points requires "${ch}" encoding channel`,
|
|
4389
|
-
path:
|
|
4415
|
+
path: jsonPointer11("points", ch),
|
|
4390
4416
|
code: "MISSING_FIELD",
|
|
4391
4417
|
suggestion: `Add points.${ch}, e.g. ${ch}: { field: "${ch === "longitude" ? "lon" : "lat"}", type: "quantitative" }`
|
|
4392
4418
|
});
|
|
4393
4419
|
} else if (!enc.field || typeof enc.field !== "string") {
|
|
4394
4420
|
errors.push({
|
|
4395
4421
|
message: `Spec error: points.${ch} must have a "field" string`,
|
|
4396
|
-
path:
|
|
4422
|
+
path: jsonPointer11("points", ch, "field"),
|
|
4397
4423
|
code: "MISSING_FIELD",
|
|
4398
4424
|
suggestion: `Add a field name, e.g. ${ch}: { field: "${ch === "longitude" ? "lon" : "lat"}" }`
|
|
4399
4425
|
});
|
|
@@ -4404,7 +4430,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
4404
4430
|
if (enc && typeof enc === "object" && (!enc.field || typeof enc.field !== "string")) {
|
|
4405
4431
|
errors.push({
|
|
4406
4432
|
message: `Spec error: points.${ch} must have a "field" string when provided`,
|
|
4407
|
-
path:
|
|
4433
|
+
path: jsonPointer11("points", ch, "field"),
|
|
4408
4434
|
code: "MISSING_FIELD",
|
|
4409
4435
|
suggestion: `Add a field name, e.g. ${ch}: { field: "myField" }`
|
|
4410
4436
|
});
|
|
@@ -4660,7 +4686,7 @@ function validateGeoMapViews(spec, errors) {
|
|
|
4660
4686
|
}
|
|
4661
4687
|
|
|
4662
4688
|
// src/compiler/validation/graph.ts
|
|
4663
|
-
import { jsonPointer as
|
|
4689
|
+
import { jsonPointer as jsonPointer12 } from "@opendata-ai/openchart-core";
|
|
4664
4690
|
function validateGraphSpec(spec, errors) {
|
|
4665
4691
|
if (!Array.isArray(spec.nodes)) {
|
|
4666
4692
|
errors.push({
|
|
@@ -4687,7 +4713,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4687
4713
|
if (!node3 || typeof node3 !== "object") {
|
|
4688
4714
|
errors.push({
|
|
4689
4715
|
message: `Spec error: nodes[${i}] must be an object`,
|
|
4690
|
-
path:
|
|
4716
|
+
path: jsonPointer12("nodes", i),
|
|
4691
4717
|
code: "INVALID_TYPE",
|
|
4692
4718
|
suggestion: 'Each node must be an object with at least an "id" field, e.g. { id: "a" }'
|
|
4693
4719
|
});
|
|
@@ -4696,7 +4722,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4696
4722
|
if (typeof node3.id !== "string" || node3.id === "") {
|
|
4697
4723
|
errors.push({
|
|
4698
4724
|
message: `Spec error: nodes[${i}] must have a non-empty string "id" field`,
|
|
4699
|
-
path:
|
|
4725
|
+
path: jsonPointer12("nodes", i, "id"),
|
|
4700
4726
|
code: "MISSING_FIELD",
|
|
4701
4727
|
suggestion: 'Add a string id to the node, e.g. { id: "node1" }'
|
|
4702
4728
|
});
|
|
@@ -4748,7 +4774,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4748
4774
|
if (!edge || typeof edge !== "object") {
|
|
4749
4775
|
errors.push({
|
|
4750
4776
|
message: `Spec error: edges[${i}] must be an object`,
|
|
4751
|
-
path:
|
|
4777
|
+
path: jsonPointer12("edges", i),
|
|
4752
4778
|
code: "INVALID_TYPE",
|
|
4753
4779
|
suggestion: 'Each edge must be an object with "source" and "target" fields, e.g. { source: "a", target: "b" }'
|
|
4754
4780
|
});
|
|
@@ -4757,14 +4783,14 @@ function validateGraphSpec(spec, errors) {
|
|
|
4757
4783
|
if (typeof edge.source !== "string" || edge.source === "") {
|
|
4758
4784
|
errors.push({
|
|
4759
4785
|
message: `Spec error: edges[${i}] must have a non-empty string "source" field`,
|
|
4760
|
-
path:
|
|
4786
|
+
path: jsonPointer12("edges", i, "source"),
|
|
4761
4787
|
code: "MISSING_FIELD",
|
|
4762
4788
|
suggestion: 'Add a source node id, e.g. { source: "a", target: "b" }'
|
|
4763
4789
|
});
|
|
4764
4790
|
} else if (nodeIds.size > 0 && !nodeIds.has(edge.source)) {
|
|
4765
4791
|
errors.push({
|
|
4766
4792
|
message: `Spec error: edges[${i}].source "${edge.source}" does not reference an existing node id`,
|
|
4767
|
-
path:
|
|
4793
|
+
path: jsonPointer12("edges", i, "source"),
|
|
4768
4794
|
code: "DATA_FIELD_MISSING",
|
|
4769
4795
|
suggestion: `Use one of the existing node ids: ${[...nodeIds].slice(0, 5).join(", ")}${nodeIds.size > 5 ? "..." : ""}.${didYouMean(edge.source, [...nodeIds])}`
|
|
4770
4796
|
});
|
|
@@ -4772,14 +4798,14 @@ function validateGraphSpec(spec, errors) {
|
|
|
4772
4798
|
if (typeof edge.target !== "string" || edge.target === "") {
|
|
4773
4799
|
errors.push({
|
|
4774
4800
|
message: `Spec error: edges[${i}] must have a non-empty string "target" field`,
|
|
4775
|
-
path:
|
|
4801
|
+
path: jsonPointer12("edges", i, "target"),
|
|
4776
4802
|
code: "MISSING_FIELD",
|
|
4777
4803
|
suggestion: 'Add a target node id, e.g. { source: "a", target: "b" }'
|
|
4778
4804
|
});
|
|
4779
4805
|
} else if (nodeIds.size > 0 && !nodeIds.has(edge.target)) {
|
|
4780
4806
|
errors.push({
|
|
4781
4807
|
message: `Spec error: edges[${i}].target "${edge.target}" does not reference an existing node id`,
|
|
4782
|
-
path:
|
|
4808
|
+
path: jsonPointer12("edges", i, "target"),
|
|
4783
4809
|
code: "DATA_FIELD_MISSING",
|
|
4784
4810
|
suggestion: `Use one of the existing node ids: ${[...nodeIds].slice(0, 5).join(", ")}${nodeIds.size > 5 ? "..." : ""}.${didYouMean(edge.target, [...nodeIds])}`
|
|
4785
4811
|
});
|
|
@@ -4811,7 +4837,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4811
4837
|
if (ch?.field && typeof ch.field === "string" && nodes.length > 0 && !nodeFields.has(ch.field)) {
|
|
4812
4838
|
errors.push({
|
|
4813
4839
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist on nodes. Available fields: ${[...nodeFields].join(", ")}`,
|
|
4814
|
-
path:
|
|
4840
|
+
path: jsonPointer12("encoding", channel, "field"),
|
|
4815
4841
|
code: "DATA_FIELD_MISSING",
|
|
4816
4842
|
suggestion: `Use one of the node fields: ${[...nodeFields].join(", ")}.${didYouMean(ch.field, [...nodeFields])}`
|
|
4817
4843
|
});
|
|
@@ -4823,7 +4849,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4823
4849
|
if (ch?.field && typeof ch.field === "string" && edges.length > 0 && !edgeFields.has(ch.field)) {
|
|
4824
4850
|
errors.push({
|
|
4825
4851
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist on edges. Available fields: ${[...edgeFields].join(", ")}`,
|
|
4826
|
-
path:
|
|
4852
|
+
path: jsonPointer12("encoding", channel, "field"),
|
|
4827
4853
|
code: "DATA_FIELD_MISSING",
|
|
4828
4854
|
suggestion: `Use one of the edge fields: ${[...edgeFields].join(", ")}.${didYouMean(ch.field, [...edgeFields])}`
|
|
4829
4855
|
});
|
|
@@ -4850,7 +4876,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
4850
4876
|
}
|
|
4851
4877
|
|
|
4852
4878
|
// src/compiler/validation/layer.ts
|
|
4853
|
-
import { jsonPointer as
|
|
4879
|
+
import { jsonPointer as jsonPointer13, MARK_TYPES } from "@opendata-ai/openchart-core";
|
|
4854
4880
|
function rootLeafPath(path, parentPrefix, leafPrefix, leaf, inheritsData) {
|
|
4855
4881
|
const [, first, second] = path.split("/");
|
|
4856
4882
|
const leafEncoding = leaf.encoding;
|
|
@@ -4874,7 +4900,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4874
4900
|
if (!child || typeof child !== "object" || Array.isArray(child)) {
|
|
4875
4901
|
errors.push({
|
|
4876
4902
|
message: `Spec error: layer[${i}] must be an object`,
|
|
4877
|
-
path: `${prefix}${
|
|
4903
|
+
path: `${prefix}${jsonPointer13("layer", i)}`,
|
|
4878
4904
|
code: "INVALID_TYPE",
|
|
4879
4905
|
suggestion: "Each layer must be a chart spec (with mark) or a nested layer spec (with layer)"
|
|
4880
4906
|
});
|
|
@@ -4884,7 +4910,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4884
4910
|
if (childObj.type === "race") {
|
|
4885
4911
|
errors.push({
|
|
4886
4912
|
code: "INVALID_VALUE",
|
|
4887
|
-
path: `${prefix}${
|
|
4913
|
+
path: `${prefix}${jsonPointer13("layer", i, "type")}`,
|
|
4888
4914
|
message: "Race specs cannot be layered.",
|
|
4889
4915
|
suggestion: "Render the race in its own container."
|
|
4890
4916
|
});
|
|
@@ -4895,14 +4921,14 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4895
4921
|
if (!isNestedLayer && !isChildChart) {
|
|
4896
4922
|
errors.push({
|
|
4897
4923
|
message: `Spec error: layer[${i}] must have a "mark" field or a "layer" array`,
|
|
4898
|
-
path: `${prefix}${
|
|
4924
|
+
path: `${prefix}${jsonPointer13("layer", i)}`,
|
|
4899
4925
|
code: "MISSING_FIELD",
|
|
4900
4926
|
suggestion: "Each layer must be a chart spec (with mark + encoding) or a nested layer spec (with layer array)"
|
|
4901
4927
|
});
|
|
4902
4928
|
continue;
|
|
4903
4929
|
}
|
|
4904
4930
|
if (isNestedLayer) {
|
|
4905
|
-
validateLayerSpec(childObj, errors, `${prefix}${
|
|
4931
|
+
validateLayerSpec(childObj, errors, `${prefix}${jsonPointer13("layer", i)}`);
|
|
4906
4932
|
} else if (isChildChart) {
|
|
4907
4933
|
const mark = childObj.mark;
|
|
4908
4934
|
let markValue;
|
|
@@ -4914,7 +4940,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4914
4940
|
if (!markValue || !MARK_TYPES.has(markValue)) {
|
|
4915
4941
|
errors.push({
|
|
4916
4942
|
message: `Spec error: layer[${i}].mark "${markValue ?? String(mark)}" is not a valid mark type`,
|
|
4917
|
-
path: `${prefix}${
|
|
4943
|
+
path: `${prefix}${jsonPointer13("layer", i, "mark")}`,
|
|
4918
4944
|
code: "INVALID_VALUE",
|
|
4919
4945
|
suggestion: `Change mark to one of: ${[...MARK_TYPES].join(", ")}`
|
|
4920
4946
|
});
|
|
@@ -4936,7 +4962,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4936
4962
|
if (mergedForValidation.data && mergedForValidation.encoding) {
|
|
4937
4963
|
const leafErrors = [];
|
|
4938
4964
|
validateChartSpec(mergedForValidation, leafErrors, { inLayer: true });
|
|
4939
|
-
const leafPrefix = `${prefix}${
|
|
4965
|
+
const leafPrefix = `${prefix}${jsonPointer13("layer", i)}`;
|
|
4940
4966
|
for (const error of leafErrors)
|
|
4941
4967
|
errors.push({
|
|
4942
4968
|
...error,
|
|
@@ -4949,10 +4975,10 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
4949
4975
|
}
|
|
4950
4976
|
|
|
4951
4977
|
// src/compiler/validation/race.ts
|
|
4952
|
-
import { jsonPointer as
|
|
4978
|
+
import { jsonPointer as jsonPointer15 } from "@opendata-ai/openchart-core";
|
|
4953
4979
|
|
|
4954
4980
|
// src/compiler/validation/race-options.ts
|
|
4955
|
-
import { jsonPointer as
|
|
4981
|
+
import { jsonPointer as jsonPointer14 } from "@opendata-ai/openchart-core";
|
|
4956
4982
|
var RACE_OPTIONS = [
|
|
4957
4983
|
"top",
|
|
4958
4984
|
"duration",
|
|
@@ -4995,7 +5021,7 @@ function checkUnknownRaceKeys(race, errors) {
|
|
|
4995
5021
|
const hint = didYouMean(option, RACE_OPTIONS);
|
|
4996
5022
|
errors.push({
|
|
4997
5023
|
code: "INVALID_VALUE",
|
|
4998
|
-
path:
|
|
5024
|
+
path: jsonPointer14("race", option),
|
|
4999
5025
|
message: `Spec error: Unknown race option "${option}"`,
|
|
5000
5026
|
suggestion: hint ? `Check the option name and keep its value.${hint}` : `Remove "${option}". Supported race options are ${RACE_OPTIONS.join(", ")}.`
|
|
5001
5027
|
});
|
|
@@ -5058,7 +5084,7 @@ function checkTimingAcrossBlocks(race, playback, errors) {
|
|
|
5058
5084
|
if (race[raceField2] === void 0 || playback[playbackField] === void 0) continue;
|
|
5059
5085
|
errors.push({
|
|
5060
5086
|
code: "INVALID_VALUE",
|
|
5061
|
-
path:
|
|
5087
|
+
path: jsonPointer14("playback", playbackField),
|
|
5062
5088
|
message: `Spec error: duration and step are mutually exclusive across race and playback (race.${raceField2}, playback.${playbackField})`,
|
|
5063
5089
|
suggestion: "Keep duration for the whole race or step for each period, in one block. Remove the other option."
|
|
5064
5090
|
});
|
|
@@ -5070,14 +5096,14 @@ function checkPlaybackAgainstRace(race, playback, errors) {
|
|
|
5070
5096
|
if (CHART_ONLY_PLAYBACK_OPTIONS.includes(field)) {
|
|
5071
5097
|
errors.push({
|
|
5072
5098
|
code: "INVALID_VALUE",
|
|
5073
|
-
path:
|
|
5099
|
+
path: jsonPointer14("playback", field),
|
|
5074
5100
|
message: `Spec error: playback.${field} applies to point and circle charts only`,
|
|
5075
5101
|
suggestion: `Remove playback.${field} from the race spec.`
|
|
5076
5102
|
});
|
|
5077
5103
|
} else if (isRecord5(race) && race[field] !== void 0 && playback[field] !== void 0) {
|
|
5078
5104
|
errors.push({
|
|
5079
5105
|
code: "INVALID_VALUE",
|
|
5080
|
-
path:
|
|
5106
|
+
path: jsonPointer14("playback", field),
|
|
5081
5107
|
message: `Spec error: ${field} is set in both race and playback`,
|
|
5082
5108
|
suggestion: `Keep ${field} in one block. Remove it from race or from playback.`
|
|
5083
5109
|
});
|
|
@@ -5155,7 +5181,7 @@ function validateEncoding(encoding, errors) {
|
|
|
5155
5181
|
if (!isRecord6(definition)) {
|
|
5156
5182
|
errors.push({
|
|
5157
5183
|
code: definition === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
|
|
5158
|
-
path:
|
|
5184
|
+
path: jsonPointer15("encoding", channel),
|
|
5159
5185
|
message: definition === void 0 ? `Spec error: race encoding requires a "${channel}" channel` : `Spec error: encoding.${channel} must be an object`,
|
|
5160
5186
|
suggestion: `Add encoding.${channel} with a field from your data, e.g. { field: "${example}" }.`
|
|
5161
5187
|
});
|
|
@@ -5165,7 +5191,7 @@ function validateEncoding(encoding, errors) {
|
|
|
5165
5191
|
if (typeof field !== "string" || field.trim() === "") {
|
|
5166
5192
|
errors.push({
|
|
5167
5193
|
code: field === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
|
|
5168
|
-
path:
|
|
5194
|
+
path: jsonPointer15("encoding", channel, "field"),
|
|
5169
5195
|
message: `Spec error: encoding.${channel} requires a non-empty "field" string`,
|
|
5170
5196
|
suggestion: `Set encoding.${channel}.field to the name of a column in your data, e.g. "${example}".`
|
|
5171
5197
|
});
|
|
@@ -5177,7 +5203,7 @@ function validateEncoding(encoding, errors) {
|
|
|
5177
5203
|
if (definition === void 0 || isRecord6(definition)) continue;
|
|
5178
5204
|
errors.push({
|
|
5179
5205
|
code: "INVALID_TYPE",
|
|
5180
|
-
path:
|
|
5206
|
+
path: jsonPointer15("encoding", channel),
|
|
5181
5207
|
message: `Spec error: encoding.${channel} must be an object`,
|
|
5182
5208
|
suggestion: `Use a channel definition or omit encoding.${channel}.`
|
|
5183
5209
|
});
|
|
@@ -5198,7 +5224,7 @@ function validateEncodingFields(encoding, data, errors) {
|
|
|
5198
5224
|
if (typeof field !== "string" || field.trim() === "" || dataColumns.has(field)) continue;
|
|
5199
5225
|
errors.push({
|
|
5200
5226
|
message: `Spec error: encoding.${channel}.field "${field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
5201
|
-
path:
|
|
5227
|
+
path: jsonPointer15("encoding", channel, "field"),
|
|
5202
5228
|
code: "DATA_FIELD_MISSING",
|
|
5203
5229
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(field, columnList)}`
|
|
5204
5230
|
});
|
|
@@ -5253,7 +5279,7 @@ function validateMark(mark, errors) {
|
|
|
5253
5279
|
if (option === "type" || option === supported) continue;
|
|
5254
5280
|
errors.push({
|
|
5255
5281
|
code: "INVALID_VALUE",
|
|
5256
|
-
path:
|
|
5282
|
+
path: jsonPointer15("mark", option),
|
|
5257
5283
|
message: `Spec error: unknown option "${option}" on the race "${type}" mark`,
|
|
5258
5284
|
suggestion: `Remove "${option}". The "${type}" mark supports "${supported}".${didYouMean(option, [supported])}`
|
|
5259
5285
|
});
|
|
@@ -5282,7 +5308,7 @@ function validateData(data, errors) {
|
|
|
5282
5308
|
const otherRows = invalidCount > 1 ? " and the other non-object rows" : "";
|
|
5283
5309
|
errors.push({
|
|
5284
5310
|
code: "INVALID_TYPE",
|
|
5285
|
-
path:
|
|
5311
|
+
path: jsonPointer15("data", firstInvalidRow),
|
|
5286
5312
|
message: `Spec error: each race data row must be an object. ${invalidCount} of ${data.length} rows ${invalidRows}.`,
|
|
5287
5313
|
suggestion: `Replace or remove row ${firstInvalidRow + 1}${otherRows}. Each row should name the fields used by time, key, and value.`
|
|
5288
5314
|
});
|
|
@@ -5307,7 +5333,7 @@ function validateRaceSpec(spec, errors) {
|
|
|
5307
5333
|
}
|
|
5308
5334
|
|
|
5309
5335
|
// src/compiler/validation/sankey.ts
|
|
5310
|
-
import { jsonPointer as
|
|
5336
|
+
import { jsonPointer as jsonPointer16 } from "@opendata-ai/openchart-core";
|
|
5311
5337
|
|
|
5312
5338
|
// src/sankey/overrides.ts
|
|
5313
5339
|
import { getBreakpoint } from "@opendata-ai/openchart-core";
|
|
@@ -5382,7 +5408,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
5382
5408
|
if (!ch || typeof ch !== "object") {
|
|
5383
5409
|
errors.push({
|
|
5384
5410
|
message: `Spec error: sankey encoding requires "${channel}" channel`,
|
|
5385
|
-
path:
|
|
5411
|
+
path: jsonPointer16("encoding", channel),
|
|
5386
5412
|
code: "MISSING_FIELD",
|
|
5387
5413
|
suggestion: `Add encoding.${channel} with a field from your data (${availableColumns}). Example: ${channel}: { field: "${columnList[0] ?? "myField"}", type: "${channel === "value" ? "quantitative" : "nominal"}" }`
|
|
5388
5414
|
});
|
|
@@ -5391,7 +5417,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
5391
5417
|
if (!ch.field || typeof ch.field !== "string") {
|
|
5392
5418
|
errors.push({
|
|
5393
5419
|
message: `Spec error: encoding.${channel} must have a "field" string`,
|
|
5394
|
-
path:
|
|
5420
|
+
path: jsonPointer16("encoding", channel, "field"),
|
|
5395
5421
|
code: "MISSING_FIELD",
|
|
5396
5422
|
suggestion: `Add a field name from your data columns: ${availableColumns}`
|
|
5397
5423
|
});
|
|
@@ -5400,7 +5426,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
5400
5426
|
if (!dataColumns.has(ch.field)) {
|
|
5401
5427
|
errors.push({
|
|
5402
5428
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
5403
|
-
path:
|
|
5429
|
+
path: jsonPointer16("encoding", channel, "field"),
|
|
5404
5430
|
code: "DATA_FIELD_MISSING",
|
|
5405
5431
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(ch.field, columnList)}`
|
|
5406
5432
|
});
|
|
@@ -5430,7 +5456,7 @@ function validateSankeyOverrides(overrides, errors) {
|
|
|
5430
5456
|
if (!breakpoints.includes(breakpoint)) {
|
|
5431
5457
|
errors.push({
|
|
5432
5458
|
message: `Spec error: sankey overrides has unknown breakpoint "${breakpoint}"`,
|
|
5433
|
-
path:
|
|
5459
|
+
path: jsonPointer16("overrides", breakpoint),
|
|
5434
5460
|
code: "INVALID_VALUE",
|
|
5435
5461
|
suggestion: `Valid breakpoints: compact (under 400px), medium (400 to 700px).${didYouMean(breakpoint, [...breakpoints])}`
|
|
5436
5462
|
});
|
|
@@ -5439,7 +5465,7 @@ function validateSankeyOverrides(overrides, errors) {
|
|
|
5439
5465
|
if (!isPlainObject2(block)) {
|
|
5440
5466
|
errors.push({
|
|
5441
5467
|
message: `Spec error: overrides.${breakpoint} must be an object`,
|
|
5442
|
-
path:
|
|
5468
|
+
path: jsonPointer16("overrides", breakpoint),
|
|
5443
5469
|
code: "INVALID_TYPE",
|
|
5444
5470
|
suggestion: `Use overrides.${breakpoint}: { other: 0.05 }`
|
|
5445
5471
|
});
|
|
@@ -5469,7 +5495,7 @@ var OVERRIDE_FIELD_CHECKS = {
|
|
|
5469
5495
|
function validateOverrideBlock(breakpoint, block, errors) {
|
|
5470
5496
|
const fields = SANKEY_OVERRIDE_FIELDS;
|
|
5471
5497
|
for (const [field, value] of Object.entries(block)) {
|
|
5472
|
-
const path =
|
|
5498
|
+
const path = jsonPointer16("overrides", breakpoint, field);
|
|
5473
5499
|
if (!fields.includes(field)) {
|
|
5474
5500
|
errors.push({
|
|
5475
5501
|
message: `Spec error: overrides.${breakpoint} cannot set "${field}"`,
|
|
@@ -5492,7 +5518,7 @@ function validateOverrideBlock(breakpoint, block, errors) {
|
|
|
5492
5518
|
}
|
|
5493
5519
|
|
|
5494
5520
|
// src/compiler/validation/table.ts
|
|
5495
|
-
import { jsonPointer as
|
|
5521
|
+
import { jsonPointer as jsonPointer17 } from "@opendata-ai/openchart-core";
|
|
5496
5522
|
function validateTableSpec(spec, errors) {
|
|
5497
5523
|
if (!Array.isArray(spec.data)) {
|
|
5498
5524
|
errors.push({
|
|
@@ -5541,7 +5567,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5541
5567
|
if (!col || typeof col !== "object") {
|
|
5542
5568
|
errors.push({
|
|
5543
5569
|
message: `Spec error: columns[${i}] must be an object`,
|
|
5544
|
-
path:
|
|
5570
|
+
path: jsonPointer17("columns", i),
|
|
5545
5571
|
code: "INVALID_TYPE",
|
|
5546
5572
|
suggestion: 'Each column entry should be an object, e.g. { key: "fieldName" }'
|
|
5547
5573
|
});
|
|
@@ -5550,7 +5576,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5550
5576
|
if (!col.key || typeof col.key !== "string") {
|
|
5551
5577
|
errors.push({
|
|
5552
5578
|
message: `Spec error: columns[${i}] must have a "key" string`,
|
|
5553
|
-
path:
|
|
5579
|
+
path: jsonPointer17("columns", i, "key"),
|
|
5554
5580
|
code: "MISSING_FIELD",
|
|
5555
5581
|
suggestion: `Add a key referencing a data field. Available columns: ${availableColumns}`
|
|
5556
5582
|
});
|
|
@@ -5559,7 +5585,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5559
5585
|
if (!dataColumns.has(col.key)) {
|
|
5560
5586
|
errors.push({
|
|
5561
5587
|
message: `Spec error: columns[${i}].key "${col.key}" does not exist in data. Available columns: ${availableColumns}`,
|
|
5562
|
-
path:
|
|
5588
|
+
path: jsonPointer17("columns", i, "key"),
|
|
5563
5589
|
code: "DATA_FIELD_MISSING",
|
|
5564
5590
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(col.key, columnList)}`
|
|
5565
5591
|
});
|
|
@@ -5570,7 +5596,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5570
5596
|
if (visuals.length > 1) {
|
|
5571
5597
|
errors.push({
|
|
5572
5598
|
message: `Spec error: columns[${i}] has multiple visual features (${visuals.join(", ")}). Only one is allowed per column.`,
|
|
5573
|
-
path:
|
|
5599
|
+
path: jsonPointer17("columns", i),
|
|
5574
5600
|
code: "INVALID_VALUE",
|
|
5575
5601
|
suggestion: `Keep only one visual feature per column. Remove all but one of: ${visuals.join(", ")}`
|
|
5576
5602
|
});
|
|
@@ -5579,7 +5605,7 @@ function validateTableSpec(spec, errors) {
|
|
|
5579
5605
|
}
|
|
5580
5606
|
|
|
5581
5607
|
// src/compiler/validation/tilemap.ts
|
|
5582
|
-
import { jsonPointer as
|
|
5608
|
+
import { jsonPointer as jsonPointer18 } from "@opendata-ai/openchart-core";
|
|
5583
5609
|
function validateTileMapSpec(spec, errors) {
|
|
5584
5610
|
validateTileMapTime(spec, errors);
|
|
5585
5611
|
if (!spec.data || typeof spec.data !== "object") {
|
|
@@ -5638,7 +5664,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
5638
5664
|
if (!ch || typeof ch !== "object") {
|
|
5639
5665
|
errors.push({
|
|
5640
5666
|
message: `Spec error: tilemap encoding requires "${channel}" channel`,
|
|
5641
|
-
path:
|
|
5667
|
+
path: jsonPointer18("encoding", channel),
|
|
5642
5668
|
code: "MISSING_FIELD",
|
|
5643
5669
|
suggestion: `Add encoding.${channel} with a field from your data (${availableColumns}). Example: ${channel}: { field: "${columnList[0] ?? "myField"}", type: "${channel === "value" ? "quantitative" : "nominal"}" }`
|
|
5644
5670
|
});
|
|
@@ -5647,7 +5673,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
5647
5673
|
if (!ch.field || typeof ch.field !== "string") {
|
|
5648
5674
|
errors.push({
|
|
5649
5675
|
message: `Spec error: encoding.${channel} must have a "field" string`,
|
|
5650
|
-
path:
|
|
5676
|
+
path: jsonPointer18("encoding", channel, "field"),
|
|
5651
5677
|
code: "MISSING_FIELD",
|
|
5652
5678
|
suggestion: `Add a field name from your data columns: ${availableColumns}`
|
|
5653
5679
|
});
|
|
@@ -5656,7 +5682,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
5656
5682
|
if (!dataColumns.has(ch.field)) {
|
|
5657
5683
|
errors.push({
|
|
5658
5684
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
5659
|
-
path:
|
|
5685
|
+
path: jsonPointer18("encoding", channel, "field"),
|
|
5660
5686
|
code: "DATA_FIELD_MISSING",
|
|
5661
5687
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(ch.field, columnList)}`
|
|
5662
5688
|
});
|
|
@@ -5693,7 +5719,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
5693
5719
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
5694
5720
|
errors.push({
|
|
5695
5721
|
code: "INVALID_VALUE",
|
|
5696
|
-
path: `${prefix}${
|
|
5722
|
+
path: `${prefix}${jsonPointer19("annotations", index, field)}`,
|
|
5697
5723
|
message: `${field} must be a positive finite number`,
|
|
5698
5724
|
suggestion: field === "maxWidth" ? "Use null for unlimited width." : "Omit subtitleFontSize to use the default ratio."
|
|
5699
5725
|
});
|
|
@@ -5701,7 +5727,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
5701
5727
|
if (annotation?.labelPlacement !== void 0 && !["auto", "start", "end", "outside"].includes(annotation.labelPlacement))
|
|
5702
5728
|
errors.push({
|
|
5703
5729
|
code: "INVALID_VALUE",
|
|
5704
|
-
path: `${prefix}${
|
|
5730
|
+
path: `${prefix}${jsonPointer19("annotations", index, "labelPlacement")}`,
|
|
5705
5731
|
message: "Unknown reference label placement",
|
|
5706
5732
|
suggestion: "Use auto, start, end or outside."
|
|
5707
5733
|
});
|
|
@@ -5709,7 +5735,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
5709
5735
|
if (bend !== void 0 && (typeof bend !== "number" || !Number.isFinite(bend) || bend < -1 || bend > 1)) {
|
|
5710
5736
|
errors.push({
|
|
5711
5737
|
code: "INVALID_VALUE",
|
|
5712
|
-
path: `${prefix}${
|
|
5738
|
+
path: `${prefix}${jsonPointer19("annotations", index, "connector", "bend")}`,
|
|
5713
5739
|
message: "Connector bend must be a finite number between -1 and 1",
|
|
5714
5740
|
suggestion: "Omit bend for the automatic curve, or use a number in [-1, 1]."
|
|
5715
5741
|
});
|
|
@@ -5741,6 +5767,7 @@ ${details}`);
|
|
|
5741
5767
|
function validateCommonSpecFields(obj, errors) {
|
|
5742
5768
|
errors.push(...collectRemovedSpecErrors(obj));
|
|
5743
5769
|
validateAnnotationLayout(obj, errors);
|
|
5770
|
+
validateChromeLinks(obj, errors);
|
|
5744
5771
|
validateFieldMetadata(obj, errors);
|
|
5745
5772
|
if (obj.chrome !== void 0) {
|
|
5746
5773
|
const chrome = obj.chrome;
|
|
@@ -5757,7 +5784,7 @@ function validateCommonSpecFields(obj, errors) {
|
|
|
5757
5784
|
if (value === void 0) continue;
|
|
5758
5785
|
if (typeof value !== "string" && (!value || typeof value !== "object" || Array.isArray(value) || typeof value.text !== "string")) {
|
|
5759
5786
|
errors.push({
|
|
5760
|
-
path:
|
|
5787
|
+
path: jsonPointer19("chrome", key),
|
|
5761
5788
|
code: "INVALID_TYPE",
|
|
5762
5789
|
message: `${key} must be text or an object with a string text property.`,
|
|
5763
5790
|
suggestion: "Preserve authored styling in the object and provide text as a string."
|
|
@@ -5800,7 +5827,7 @@ function validateSpecShape(spec) {
|
|
|
5800
5827
|
errors: [
|
|
5801
5828
|
{
|
|
5802
5829
|
message: `Spec error: "${key}" composition is not supported`,
|
|
5803
|
-
path:
|
|
5830
|
+
path: jsonPointer19(key),
|
|
5804
5831
|
code: "INVALID_VALUE",
|
|
5805
5832
|
suggestion: "Render each chart in its own container instead. For small multiples of the same chart, use the facet encoding channel: encoding.facet = { field, type }"
|
|
5806
5833
|
}
|
|
@@ -8574,11 +8601,16 @@ function resolveRangeAnnotation(annotation, scales, chartArea, isDark, fontFamil
|
|
|
8574
8601
|
width = Math.abs(x2px - x1px);
|
|
8575
8602
|
}
|
|
8576
8603
|
if (annotation.y1 !== void 0 && annotation.y2 !== void 0) {
|
|
8577
|
-
const
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8604
|
+
const edges = [
|
|
8605
|
+
resolveEdge(annotation.y1, scales.y, "start"),
|
|
8606
|
+
resolveEdge(annotation.y1, scales.y, "end"),
|
|
8607
|
+
resolveEdge(annotation.y2, scales.y, "start"),
|
|
8608
|
+
resolveEdge(annotation.y2, scales.y, "end")
|
|
8609
|
+
];
|
|
8610
|
+
if (edges.some((edge) => edge === null)) return null;
|
|
8611
|
+
const positions = edges.filter((edge) => edge !== null);
|
|
8612
|
+
y = Math.min(...positions);
|
|
8613
|
+
height = Math.max(...positions) - y;
|
|
8582
8614
|
}
|
|
8583
8615
|
const rect = { x, y, width, height };
|
|
8584
8616
|
let label;
|
|
@@ -8772,6 +8804,9 @@ function computeAnnotations(spec, ctx) {
|
|
|
8772
8804
|
...sourceAnnotation,
|
|
8773
8805
|
maxWidth: sourceAnnotation.maxWidth === void 0 ? defaultCalloutMaxWidth(sourceAnnotation, ctx) : sourceAnnotation.maxWidth
|
|
8774
8806
|
} : { ...sourceAnnotation, fontSize: sourceAnnotation.fontSize ?? ctx.smallFontSize ?? 12 };
|
|
8807
|
+
if (annotation.responsive === "hide" && ctx.strategy.annotationPosition === "tooltip-only") {
|
|
8808
|
+
continue;
|
|
8809
|
+
}
|
|
8775
8810
|
if (isCompact && annotation.responsive !== false) {
|
|
8776
8811
|
continue;
|
|
8777
8812
|
}
|
|
@@ -15761,6 +15796,11 @@ function computeScales(spec, chartArea, data) {
|
|
|
15761
15796
|
spec.markType,
|
|
15762
15797
|
"y"
|
|
15763
15798
|
);
|
|
15799
|
+
if (result.y.type === "band" || result.y.type === "point") {
|
|
15800
|
+
const scale = result.y.scale;
|
|
15801
|
+
const [r0, r1] = scale.range();
|
|
15802
|
+
scale.range([r1, r0]);
|
|
15803
|
+
}
|
|
15764
15804
|
applyTemporalBarInterval(result.y, spec, data);
|
|
15765
15805
|
if (result.y && encoding.y.type === "quantitative" && encoding.y.field) {
|
|
15766
15806
|
result.y.formatContext = computeFieldFormatContext3(fieldIterable(data, encoding.y.field));
|
|
@@ -15878,6 +15918,29 @@ function endpointFormatter(spec, displayedValues) {
|
|
|
15878
15918
|
return (value) => `${config?.prefix ?? ""}${formatter(value)}${config?.suffix ?? ""}`;
|
|
15879
15919
|
}
|
|
15880
15920
|
|
|
15921
|
+
// src/compile/data-clip.ts
|
|
15922
|
+
function filterClippedDomains(data, encoding) {
|
|
15923
|
+
let result = data;
|
|
15924
|
+
for (const channel of ["x", "y"]) {
|
|
15925
|
+
const enc = encoding[channel];
|
|
15926
|
+
if (!enc?.scale?.clip || !enc.scale.domain) continue;
|
|
15927
|
+
const domain = enc.scale.domain;
|
|
15928
|
+
const field = enc.field;
|
|
15929
|
+
if (!Array.isArray(domain)) continue;
|
|
15930
|
+
if (domain.length === 2 && typeof domain[0] === "number") {
|
|
15931
|
+
const [lo, hi] = domain;
|
|
15932
|
+
result = result.filter((row) => {
|
|
15933
|
+
const v = Number(row[field]);
|
|
15934
|
+
return Number.isFinite(v) && v >= lo && v <= hi;
|
|
15935
|
+
});
|
|
15936
|
+
} else if (typeof domain[0] === "string") {
|
|
15937
|
+
const allowed = new Set(domain);
|
|
15938
|
+
result = result.filter((row) => allowed.has(String(row[field])));
|
|
15939
|
+
}
|
|
15940
|
+
}
|
|
15941
|
+
return result;
|
|
15942
|
+
}
|
|
15943
|
+
|
|
15881
15944
|
// src/endpoint-labels/source.ts
|
|
15882
15945
|
function endpointSourceRows(spec) {
|
|
15883
15946
|
const field = seriesField(spec);
|
|
@@ -15885,14 +15948,15 @@ function endpointSourceRows(spec) {
|
|
|
15885
15948
|
const y = spec.encoding.y;
|
|
15886
15949
|
const groups = /* @__PURE__ */ new Map();
|
|
15887
15950
|
if (!field || !x || !y) return groups;
|
|
15951
|
+
const data = filterClippedDomains(spec.data, spec.encoding);
|
|
15888
15952
|
const stacked = spec.markType === "area" && y.stack !== null && y.stack !== false;
|
|
15889
15953
|
const gaps = /* @__PURE__ */ new Set();
|
|
15890
15954
|
if (stacked) {
|
|
15891
|
-
for (const row of
|
|
15955
|
+
for (const row of data) {
|
|
15892
15956
|
if (finiteNumber(row[y.field]) === void 0) gaps.add(String(row[x.field]));
|
|
15893
15957
|
}
|
|
15894
15958
|
}
|
|
15895
|
-
const rows = x.type === "nominal" || x.type === "ordinal" ?
|
|
15959
|
+
const rows = x.type === "nominal" || x.type === "ordinal" ? data : sortByField(data, x.field);
|
|
15896
15960
|
for (const row of rows) {
|
|
15897
15961
|
const xValue = row[x.field];
|
|
15898
15962
|
const positionalType = x.scale?.type;
|
|
@@ -15902,7 +15966,8 @@ function endpointSourceRows(spec) {
|
|
|
15902
15966
|
continue;
|
|
15903
15967
|
if (numeric && finiteNumber(xValue) === void 0) continue;
|
|
15904
15968
|
const name = String(row[field]);
|
|
15905
|
-
if (spec.highlight?.length && !spec.highlight.includes(name))
|
|
15969
|
+
if (spec.labels?.highlightedOnly && spec.highlight?.length && !spec.highlight.includes(name))
|
|
15970
|
+
continue;
|
|
15906
15971
|
if (row[x.field] == null || finiteNumber(row[y.field]) === void 0 || gaps.has(String(row[x.field])))
|
|
15907
15972
|
continue;
|
|
15908
15973
|
const group = groups.get(name);
|
|
@@ -18122,6 +18187,74 @@ function endpointObservation(mark, side, anchor = "boundary") {
|
|
|
18122
18187
|
return { ...point, datum: mark.data[index] ?? {}, band: false };
|
|
18123
18188
|
}
|
|
18124
18189
|
|
|
18190
|
+
// src/endpoint-labels/placement.ts
|
|
18191
|
+
function bidirectionalSweep(entries, areaTop, areaBottom) {
|
|
18192
|
+
const n = entries.length;
|
|
18193
|
+
if (n === 0) return [];
|
|
18194
|
+
const sorted = [...entries].sort((a, b) => a.naturalTop - b.naturalTop);
|
|
18195
|
+
const tops = sorted.map((e) => Math.max(areaTop, e.naturalTop));
|
|
18196
|
+
for (let i = 0; i < n; i++) {
|
|
18197
|
+
if (i > 0) {
|
|
18198
|
+
const minTop = tops[i - 1] + sorted[i - 1].height;
|
|
18199
|
+
if (tops[i] < minTop) tops[i] = minTop;
|
|
18200
|
+
}
|
|
18201
|
+
const maxTop = areaBottom - sorted[i].height;
|
|
18202
|
+
if (tops[i] > maxTop) tops[i] = maxTop;
|
|
18203
|
+
}
|
|
18204
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
18205
|
+
if (i < n - 1) {
|
|
18206
|
+
const maxTop = tops[i + 1] - sorted[i].height;
|
|
18207
|
+
if (tops[i] > maxTop) tops[i] = maxTop;
|
|
18208
|
+
}
|
|
18209
|
+
if (tops[i] < areaTop) tops[i] = areaTop;
|
|
18210
|
+
}
|
|
18211
|
+
const result = new Array(n);
|
|
18212
|
+
for (let i = 0; i < n; i++) {
|
|
18213
|
+
result[sorted[i].index] = tops[i];
|
|
18214
|
+
}
|
|
18215
|
+
return result;
|
|
18216
|
+
}
|
|
18217
|
+
function placeEndpointEntries(entries, areaTop, areaBottom) {
|
|
18218
|
+
const primary = entries.flatMap((entry, index) => entry.muted ? [] : [{ ...entry, index }]);
|
|
18219
|
+
const primaryTops = bidirectionalSweep(
|
|
18220
|
+
primary.map((entry, index) => ({ ...entry, index })),
|
|
18221
|
+
areaTop,
|
|
18222
|
+
areaBottom
|
|
18223
|
+
);
|
|
18224
|
+
const result = entries.map(() => null);
|
|
18225
|
+
const occupied = primary.map((entry, index) => {
|
|
18226
|
+
const top = primaryTops[index];
|
|
18227
|
+
result[entry.index] = top;
|
|
18228
|
+
return { top, bottom: top + entry.height };
|
|
18229
|
+
});
|
|
18230
|
+
const muted = entries.map((entry, index) => ({ ...entry, index })).filter((entry) => entry.muted).sort((a, b) => a.naturalTop - b.naturalTop || a.index - b.index);
|
|
18231
|
+
for (const entry of muted) {
|
|
18232
|
+
const top = nearestFreeTop(entry, occupied, areaTop, areaBottom);
|
|
18233
|
+
result[entry.index] = top;
|
|
18234
|
+
if (top !== null) occupied.push({ top, bottom: top + entry.height });
|
|
18235
|
+
}
|
|
18236
|
+
return result;
|
|
18237
|
+
}
|
|
18238
|
+
function nearestFreeTop(entry, occupied, areaTop, areaBottom) {
|
|
18239
|
+
const natural = Math.max(areaTop, Math.min(entry.naturalTop, areaBottom - entry.height));
|
|
18240
|
+
let best = null;
|
|
18241
|
+
let distance = Infinity;
|
|
18242
|
+
let gapStart = areaTop;
|
|
18243
|
+
const boxes2 = [...occupied].sort((a, b) => a.top - b.top);
|
|
18244
|
+
for (const box of [...boxes2, { top: areaBottom, bottom: areaBottom }]) {
|
|
18245
|
+
if (box.top - gapStart >= entry.height) {
|
|
18246
|
+
const top = Math.max(gapStart, Math.min(natural, box.top - entry.height));
|
|
18247
|
+
const delta = Math.abs(top - natural);
|
|
18248
|
+
if (delta < distance && delta <= entry.height) {
|
|
18249
|
+
best = top;
|
|
18250
|
+
distance = delta;
|
|
18251
|
+
}
|
|
18252
|
+
}
|
|
18253
|
+
gapStart = Math.max(gapStart, box.bottom);
|
|
18254
|
+
}
|
|
18255
|
+
return best;
|
|
18256
|
+
}
|
|
18257
|
+
|
|
18125
18258
|
// src/endpoint-labels/compute.ts
|
|
18126
18259
|
function emptyLayout2(theme) {
|
|
18127
18260
|
const labelStyle = {
|
|
@@ -18147,38 +18280,13 @@ function emptyLayout2(theme) {
|
|
|
18147
18280
|
swatchSize: ENDPOINT_SWATCH_SIZE,
|
|
18148
18281
|
gap: ENDPOINT_GAP,
|
|
18149
18282
|
valueGap: theme.spacing.endpointValueGap,
|
|
18283
|
+
mutedTextColor: theme.colors.axis,
|
|
18150
18284
|
swatchChipFill: theme.colors.annotationFill ?? theme.colors.background
|
|
18151
18285
|
};
|
|
18152
18286
|
}
|
|
18153
18287
|
function isLineOrArea(mark) {
|
|
18154
18288
|
return mark.type === "line" || mark.type === "area";
|
|
18155
18289
|
}
|
|
18156
|
-
function bidirectionalSweep(entries, areaTop, areaBottom) {
|
|
18157
|
-
const n = entries.length;
|
|
18158
|
-
if (n === 0) return [];
|
|
18159
|
-
const sorted = [...entries].sort((a, b) => a.naturalTop - b.naturalTop);
|
|
18160
|
-
const tops = sorted.map((e) => Math.max(areaTop, e.naturalTop));
|
|
18161
|
-
for (let i = 0; i < n; i++) {
|
|
18162
|
-
if (i > 0) {
|
|
18163
|
-
const minTop = tops[i - 1] + sorted[i - 1].height;
|
|
18164
|
-
if (tops[i] < minTop) tops[i] = minTop;
|
|
18165
|
-
}
|
|
18166
|
-
const maxTop = areaBottom - sorted[i].height;
|
|
18167
|
-
if (tops[i] > maxTop) tops[i] = maxTop;
|
|
18168
|
-
}
|
|
18169
|
-
for (let i = n - 1; i >= 0; i--) {
|
|
18170
|
-
if (i < n - 1) {
|
|
18171
|
-
const maxTop = tops[i + 1] - sorted[i].height;
|
|
18172
|
-
if (tops[i] > maxTop) tops[i] = maxTop;
|
|
18173
|
-
}
|
|
18174
|
-
if (tops[i] < areaTop) tops[i] = areaTop;
|
|
18175
|
-
}
|
|
18176
|
-
const result = new Array(n);
|
|
18177
|
-
for (let i = 0; i < n; i++) {
|
|
18178
|
-
result[sorted[i].index] = tops[i];
|
|
18179
|
-
}
|
|
18180
|
-
return result;
|
|
18181
|
-
}
|
|
18182
18290
|
function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpointLabelsDemoted, measureText, xScaleType) {
|
|
18183
18291
|
if (strategy?.labelMode === "none" && !endpointLabelsExplicitlyOn(spec)) {
|
|
18184
18292
|
return emptyLayout2(theme);
|
|
@@ -18195,6 +18303,8 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18195
18303
|
labelsHiddenByStrategy: false,
|
|
18196
18304
|
endpointLabelsDemoted
|
|
18197
18305
|
});
|
|
18306
|
+
const nameMuted = highlightActive && sup.showEndpointLabels && !spec.labels.highlightedOnly;
|
|
18307
|
+
const isMuted = (key) => highlightActive && !highlight.includes(key);
|
|
18198
18308
|
const epExplicitlyOff = spec.endpointLabels === false || typeof spec.endpointLabels === "object" && spec.endpointLabels?.show === false;
|
|
18199
18309
|
if (!sup.showEndpointLabels && !(highlightActive && !epExplicitlyOff)) return emptyLayout2(theme);
|
|
18200
18310
|
const bySeriesKey = /* @__PURE__ */ new Map();
|
|
@@ -18234,7 +18344,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18234
18344
|
}
|
|
18235
18345
|
}
|
|
18236
18346
|
const lineOrAreaMarks = Array.from(bySeriesKey.values()).filter(
|
|
18237
|
-
(mark) => !
|
|
18347
|
+
(mark) => !isMuted(mark.seriesKey) || nameMuted
|
|
18238
18348
|
);
|
|
18239
18349
|
if (lineOrAreaMarks.length < 2 && !highlightActive) return emptyLayout2(theme);
|
|
18240
18350
|
const config = typeof spec.endpointLabels === "object" ? spec.endpointLabels : void 0;
|
|
@@ -18281,7 +18391,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18281
18391
|
fontVariant: "tabular-nums"
|
|
18282
18392
|
};
|
|
18283
18393
|
const interior = config?.placement === "interior" ? lineOrAreaMarks.flatMap((mark) => {
|
|
18284
|
-
if (mark.type !== "area" || !mark.stacked) return [];
|
|
18394
|
+
if (mark.type !== "area" || !mark.stacked || isMuted(mark.seriesKey)) return [];
|
|
18285
18395
|
const color = mark.stroke ?? (typeof mark.fill === "string" ? mark.fill : theme.colors.text);
|
|
18286
18396
|
const label = fitInteriorLabel(
|
|
18287
18397
|
mark,
|
|
@@ -18306,7 +18416,6 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18306
18416
|
for (const mark of lineOrAreaMarks) {
|
|
18307
18417
|
const seriesKey = mark.seriesKey;
|
|
18308
18418
|
if (!seriesKey) continue;
|
|
18309
|
-
if (highlightActive && !highlight.includes(seriesKey)) continue;
|
|
18310
18419
|
const last = endpointObservation(mark, "trailing", anchor);
|
|
18311
18420
|
if (!last) continue;
|
|
18312
18421
|
const rawValue = last.datum[valueField ?? ""];
|
|
@@ -18342,6 +18451,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18342
18451
|
const entryHeight = labelHeight + (value ? theme.spacing.endpointValueGap : 0) + valueHeight + (date ? valueLineHeight + theme.spacing.endpointValueGap : 0);
|
|
18343
18452
|
const color = mark.type === "line" ? mark.stroke : mark.stroke ?? (typeof mark.fill === "string" ? mark.fill : theme.colors.categorical[0]);
|
|
18344
18453
|
provisional.push({
|
|
18454
|
+
muted: isMuted(seriesKey),
|
|
18345
18455
|
seriesKey,
|
|
18346
18456
|
labelLines,
|
|
18347
18457
|
value,
|
|
@@ -18358,20 +18468,21 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18358
18468
|
}
|
|
18359
18469
|
if (provisional.length === 0) return emptyLayout2(theme);
|
|
18360
18470
|
if (provisional.length < 2 && !highlightActive) return emptyLayout2(theme);
|
|
18361
|
-
const sweepInput = provisional.map((p
|
|
18471
|
+
const sweepInput = provisional.map((p) => ({
|
|
18362
18472
|
naturalTop: p.dataY - theme.fonts.sizes.endpointLabel / 2,
|
|
18363
18473
|
height: p.height + theme.spacing.endpointEntryGap,
|
|
18364
|
-
|
|
18474
|
+
muted: p.muted
|
|
18365
18475
|
}));
|
|
18366
|
-
const sweptTops =
|
|
18476
|
+
const sweptTops = placeEndpointEntries(sweepInput, chartArea.y, chartArea.y + chartArea.height);
|
|
18367
18477
|
const columnWidth = Math.max(
|
|
18368
18478
|
ENDPOINT_SWATCH_SIZE + ENDPOINT_GAP + Math.max(...provisional.map((p) => p.width), 0) + endpointTrailingPadding(spec.frame?.right),
|
|
18369
18479
|
32
|
|
18370
18480
|
);
|
|
18371
18481
|
const columnX = chartArea.x + chartArea.width + theme.spacing.endpointColumnGap;
|
|
18372
18482
|
const showLeader = config?.showLeader === true;
|
|
18373
|
-
const entries = provisional.
|
|
18483
|
+
const entries = provisional.flatMap((p, i) => {
|
|
18374
18484
|
const labelY = sweptTops[i];
|
|
18485
|
+
if (labelY === null) return [];
|
|
18375
18486
|
const swatchRowY = labelY + theme.fonts.sizes.endpointLabel / 2;
|
|
18376
18487
|
const displaced = Math.abs(swatchRowY - p.dataY) > ENDPOINT_LEADER_THRESHOLD;
|
|
18377
18488
|
const entry = {
|
|
@@ -18386,6 +18497,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18386
18497
|
labelY,
|
|
18387
18498
|
showLeader: p.band || showLeader && displaced
|
|
18388
18499
|
};
|
|
18500
|
+
if (p.muted) entry.muted = true;
|
|
18389
18501
|
if (p.strokeDasharray) entry.strokeDasharray = p.strokeDasharray;
|
|
18390
18502
|
if (showMarker && !p.band) {
|
|
18391
18503
|
entry.marker = {
|
|
@@ -18398,7 +18510,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18398
18510
|
radius: markerRadius
|
|
18399
18511
|
};
|
|
18400
18512
|
}
|
|
18401
|
-
return entry;
|
|
18513
|
+
return [entry];
|
|
18402
18514
|
});
|
|
18403
18515
|
const endsBoth = config?.ends === "both";
|
|
18404
18516
|
let leading;
|
|
@@ -18408,7 +18520,6 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18408
18520
|
for (const mark of lineOrAreaMarks) {
|
|
18409
18521
|
const seriesKey = mark.seriesKey;
|
|
18410
18522
|
if (!seriesKey) continue;
|
|
18411
|
-
if (highlightActive && !highlight.includes(seriesKey)) continue;
|
|
18412
18523
|
const first = endpointObservation(mark, "leading", anchor);
|
|
18413
18524
|
if (!first) continue;
|
|
18414
18525
|
const rawValue = first.datum[valueField ?? ""];
|
|
@@ -18444,6 +18555,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18444
18555
|
const entryHeight = labelHeight + (value ? theme.spacing.endpointValueGap : 0) + valueHeight + (date ? valueLineHeight + theme.spacing.endpointValueGap : 0);
|
|
18445
18556
|
const color = mark.type === "line" ? mark.stroke : mark.stroke ?? (typeof mark.fill === "string" ? mark.fill : theme.colors.categorical[0]);
|
|
18446
18557
|
leadingProvisional.push({
|
|
18558
|
+
muted: isMuted(seriesKey),
|
|
18447
18559
|
seriesKey,
|
|
18448
18560
|
labelLines,
|
|
18449
18561
|
value,
|
|
@@ -18463,12 +18575,12 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18463
18575
|
});
|
|
18464
18576
|
}
|
|
18465
18577
|
if (leadingProvisional.length >= 2 || leadingProvisional.length === 1 && highlightActive) {
|
|
18466
|
-
const leadingSweepInput = leadingProvisional.map((p
|
|
18578
|
+
const leadingSweepInput = leadingProvisional.map((p) => ({
|
|
18467
18579
|
naturalTop: p.dataY - theme.fonts.sizes.endpointLabel / 2,
|
|
18468
18580
|
height: p.height + theme.spacing.endpointEntryGap,
|
|
18469
|
-
|
|
18581
|
+
muted: p.muted
|
|
18470
18582
|
}));
|
|
18471
|
-
const leadingSweptTops =
|
|
18583
|
+
const leadingSweptTops = placeEndpointEntries(
|
|
18472
18584
|
leadingSweepInput,
|
|
18473
18585
|
chartArea.y,
|
|
18474
18586
|
chartArea.y + chartArea.height
|
|
@@ -18478,8 +18590,9 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18478
18590
|
32
|
|
18479
18591
|
);
|
|
18480
18592
|
const leadingColumnX = chartArea.x - theme.spacing.endpointColumnGap - leadingColumnWidth;
|
|
18481
|
-
leading = leadingProvisional.
|
|
18593
|
+
leading = leadingProvisional.flatMap((p, i) => {
|
|
18482
18594
|
const labelY = leadingSweptTops[i];
|
|
18595
|
+
if (labelY === null) return [];
|
|
18483
18596
|
const swatchRowY = labelY + theme.fonts.sizes.endpointLabel / 2;
|
|
18484
18597
|
const displaced = Math.abs(swatchRowY - p.dataY) > ENDPOINT_LEADER_THRESHOLD;
|
|
18485
18598
|
const entry = {
|
|
@@ -18494,6 +18607,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18494
18607
|
labelY,
|
|
18495
18608
|
showLeader: p.band || showLeader && displaced
|
|
18496
18609
|
};
|
|
18610
|
+
if (p.muted) entry.muted = true;
|
|
18497
18611
|
if (p.strokeDasharray) entry.strokeDasharray = p.strokeDasharray;
|
|
18498
18612
|
if (showMarker && !p.band) {
|
|
18499
18613
|
entry.marker = {
|
|
@@ -18506,7 +18620,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18506
18620
|
radius: markerRadius
|
|
18507
18621
|
};
|
|
18508
18622
|
}
|
|
18509
|
-
return entry;
|
|
18623
|
+
return [entry];
|
|
18510
18624
|
});
|
|
18511
18625
|
leadingBounds = {
|
|
18512
18626
|
x: leadingColumnX,
|
|
@@ -18530,6 +18644,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy, endpoint
|
|
|
18530
18644
|
swatchSize: ENDPOINT_SWATCH_SIZE,
|
|
18531
18645
|
gap: ENDPOINT_GAP,
|
|
18532
18646
|
valueGap: theme.spacing.endpointValueGap,
|
|
18647
|
+
mutedTextColor: theme.colors.axis,
|
|
18533
18648
|
swatchChipFill: theme.colors.annotationFill ?? theme.colors.background,
|
|
18534
18649
|
leading,
|
|
18535
18650
|
leadingBounds
|
|
@@ -21729,29 +21844,6 @@ ${placementErrors.map((error) => `${error.path}: ${error.message}`).join("\n")}`
|
|
|
21729
21844
|
};
|
|
21730
21845
|
}
|
|
21731
21846
|
|
|
21732
|
-
// src/compile/data-clip.ts
|
|
21733
|
-
function filterClippedDomains(data, encoding) {
|
|
21734
|
-
let result = data;
|
|
21735
|
-
for (const channel of ["x", "y"]) {
|
|
21736
|
-
const enc = encoding[channel];
|
|
21737
|
-
if (!enc?.scale?.clip || !enc.scale.domain) continue;
|
|
21738
|
-
const domain = enc.scale.domain;
|
|
21739
|
-
const field = enc.field;
|
|
21740
|
-
if (!Array.isArray(domain)) continue;
|
|
21741
|
-
if (domain.length === 2 && typeof domain[0] === "number") {
|
|
21742
|
-
const [lo, hi] = domain;
|
|
21743
|
-
result = result.filter((row) => {
|
|
21744
|
-
const v = Number(row[field]);
|
|
21745
|
-
return Number.isFinite(v) && v >= lo && v <= hi;
|
|
21746
|
-
});
|
|
21747
|
-
} else if (typeof domain[0] === "string") {
|
|
21748
|
-
const allowed = new Set(domain);
|
|
21749
|
-
result = result.filter((row) => allowed.has(String(row[field])));
|
|
21750
|
-
}
|
|
21751
|
-
}
|
|
21752
|
-
return result;
|
|
21753
|
-
}
|
|
21754
|
-
|
|
21755
21847
|
// src/compile/render-spec.ts
|
|
21756
21848
|
function buildRenderSpec(chartSpec) {
|
|
21757
21849
|
let renderData = chartSpec.data;
|
|
@@ -23064,20 +23156,26 @@ function mergeEndpointColumns(columns, area3, rightReserve, leadingColumnX, colu
|
|
|
23064
23156
|
const { leadersEnabled: _leadersEnabled, bandSeries: _bandSeries, ...first } = columns[0];
|
|
23065
23157
|
const sweep = (entries) => {
|
|
23066
23158
|
const size = first.labelStyle.fontSize;
|
|
23067
|
-
const tops =
|
|
23068
|
-
entries.map((entry
|
|
23159
|
+
const tops = placeEndpointEntries(
|
|
23160
|
+
entries.map((entry) => ({
|
|
23069
23161
|
naturalTop: entry.dataY - size / 2,
|
|
23070
23162
|
height: entry.labelLines.length * size * (first.labelStyle.lineHeight ?? 1.25) + (entry.value ? first.valueGap + first.valueStyle.fontSize * (first.valueStyle.lineHeight ?? 1.25) : 0) + (entry.date ? first.valueStyle.fontSize * (first.valueStyle.lineHeight ?? 1.25) + first.valueGap : 0) + entryGap,
|
|
23071
|
-
|
|
23163
|
+
muted: entry.muted === true
|
|
23072
23164
|
})),
|
|
23073
23165
|
area3.y,
|
|
23074
23166
|
area3.y + area3.height
|
|
23075
23167
|
);
|
|
23076
|
-
return entries.
|
|
23077
|
-
|
|
23078
|
-
|
|
23079
|
-
|
|
23080
|
-
|
|
23168
|
+
return entries.flatMap(({ leadersEnabled, bandLeader, ...entry }, index) => {
|
|
23169
|
+
const top = tops[index];
|
|
23170
|
+
if (top === null) return [];
|
|
23171
|
+
return [
|
|
23172
|
+
{
|
|
23173
|
+
...entry,
|
|
23174
|
+
labelY: top,
|
|
23175
|
+
showLeader: bandLeader || leadersEnabled && Math.abs(top + size / 2 - entry.dataY) > ENDPOINT_LEADER_THRESHOLD
|
|
23176
|
+
}
|
|
23177
|
+
];
|
|
23178
|
+
});
|
|
23081
23179
|
};
|
|
23082
23180
|
const leadingColumns = columns.filter((column) => column.leadingBounds);
|
|
23083
23181
|
const leadingWidth = Math.max(0, ...leadingColumns.map((column) => column.leadingBounds.width));
|
|
@@ -28249,11 +28347,9 @@ function compileGeoMapImpl(spec, options, scope) {
|
|
|
28249
28347
|
const geoCollection = viewSources?.primary.collection ?? topoFeature2(topology, topology.objects[objectKey]);
|
|
28250
28348
|
const insetSelection = viewSources ? selectGeoInsetFeatures(geoCollection.features, mapSpec.geo.insets ?? []) : void 0;
|
|
28251
28349
|
const geoFeatures = geoCollection.features;
|
|
28252
|
-
const
|
|
28253
|
-
|
|
28254
|
-
|
|
28255
|
-
mapSpec.points?.data.length ?? 0
|
|
28256
|
-
);
|
|
28350
|
+
const description = spec.a11y && typeof spec.a11y === "object" && "description" in spec.a11y && typeof spec.a11y.description === "string" ? spec.a11y.description : void 0;
|
|
28351
|
+
const authoredDescription = description?.trim() ? description : void 0;
|
|
28352
|
+
const emptyAltText = authoredDescription ?? describeGeoMap(geoFeatures.length, mapSpec.encoding.color, mapSpec.points?.data.length ?? 0);
|
|
28257
28353
|
if ((fullArea.width <= 0 || fullArea.height <= 0) && !hasGeoLabels(mapSpec)) {
|
|
28258
28354
|
return emptyLayout4(chrome, theme, options, watermark, emptyAltText);
|
|
28259
28355
|
}
|
|
@@ -29387,7 +29483,7 @@ function compileGeoMapImpl(spec, options, scope) {
|
|
|
29387
29483
|
}
|
|
29388
29484
|
const a11yDataField = colorEncoding?.field;
|
|
29389
29485
|
const a11y = {
|
|
29390
|
-
altText: describeGeoMap(geoFeatures.length, colorEncoding, pointMarks.length),
|
|
29486
|
+
altText: authoredDescription ?? describeGeoMap(geoFeatures.length, colorEncoding, pointMarks.length),
|
|
29391
29487
|
dataTableFallback: [
|
|
29392
29488
|
...featureMarks.filter((m) => m.data).map((m) => [
|
|
29393
29489
|
m.name ?? String(m.id),
|
|
@@ -29401,7 +29497,7 @@ function compileGeoMapImpl(spec, options, scope) {
|
|
|
29401
29497
|
role: "img",
|
|
29402
29498
|
keyboardNavigable: featureMarks.length > 0 || pointMarks.length > 0
|
|
29403
29499
|
};
|
|
29404
|
-
if (showChoroplethLegend && classScale) {
|
|
29500
|
+
if (!authoredDescription && showChoroplethLegend && classScale) {
|
|
29405
29501
|
a11y.altText += `. Color ranges: ${classScale.colors.map((_, index) => classIntervalText(classScale, index, formatter)).join("; ")}.`;
|
|
29406
29502
|
}
|
|
29407
29503
|
const resolvedFocus = resolveFocus(mapSpec.geo.focus, featureMarks, pointMarks, compileWarnings);
|
|
@@ -32733,7 +32829,8 @@ function compileTableLayout(spec, options, theme) {
|
|
|
32733
32829
|
totalRow: spec.totalRow ? buildTotalRow(spec.totalRow.label, spec.columns, resolvedColumns, filteredData) : void 0,
|
|
32734
32830
|
a11y: {
|
|
32735
32831
|
caption,
|
|
32736
|
-
summary: `${resolvedColumns.length} columns, ${totalFiltered} rows
|
|
32832
|
+
summary: `${resolvedColumns.length} columns, ${totalFiltered} rows`,
|
|
32833
|
+
description: spec.a11y?.description?.trim() || null
|
|
32737
32834
|
},
|
|
32738
32835
|
theme,
|
|
32739
32836
|
animation: resolveAnimation(spec.animation),
|