@opendata-ai/openchart-engine 9.7.0 → 9.7.1
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 +1 -1
- package/dist/index.js +212 -149
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6963,7 +6963,7 @@ function buildArcPath(geom) {
|
|
|
6963
6963
|
}) ?? "";
|
|
6964
6964
|
}
|
|
6965
6965
|
var DEFAULT_PALETTE = CATEGORICAL_FILL_PALETTE;
|
|
6966
|
-
function groupSmallSlices(slices, threshold) {
|
|
6966
|
+
function groupSmallSlices(slices, threshold, fields) {
|
|
6967
6967
|
const total = slices.reduce((sum, s) => sum + s.value, 0);
|
|
6968
6968
|
if (total === 0) return slices;
|
|
6969
6969
|
const big = [];
|
|
@@ -6979,7 +6979,7 @@ function groupSmallSlices(slices, threshold) {
|
|
|
6979
6979
|
big.push({
|
|
6980
6980
|
label: "Other",
|
|
6981
6981
|
value: otherValue,
|
|
6982
|
-
originalRow: { label: "Other", value: otherValue }
|
|
6982
|
+
originalRow: { [fields.category ?? "label"]: "Other", [fields.value]: otherValue }
|
|
6983
6983
|
});
|
|
6984
6984
|
}
|
|
6985
6985
|
return big;
|
|
@@ -7026,18 +7026,16 @@ function computePieMarks(spec, scales, chartArea, _strategy, innerRadiusSpec = 0
|
|
|
7026
7026
|
const val = finiteNumber(row[valueChannel.field]);
|
|
7027
7027
|
if (val === void 0 || val < 0) continue;
|
|
7028
7028
|
categoryTotals.set(cat, (categoryTotals.get(cat) ?? 0) + val);
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7029
|
+
const rows = categoryRows.get(cat);
|
|
7030
|
+
if (rows) rows.push(row);
|
|
7031
|
+
else categoryRows.set(cat, [row]);
|
|
7032
7032
|
}
|
|
7033
7033
|
for (const [label, value] of categoryTotals) {
|
|
7034
|
+
const rows = categoryRows.get(label) ?? [];
|
|
7034
7035
|
slices.push({
|
|
7035
7036
|
label,
|
|
7036
7037
|
value,
|
|
7037
|
-
originalRow:
|
|
7038
|
-
[categoryField]: label,
|
|
7039
|
-
[valueChannel.field]: value
|
|
7040
|
-
}
|
|
7038
|
+
originalRow: rows.length === 1 ? rows[0] : { [categoryField]: rows[0]?.[categoryField] ?? label, [valueChannel.field]: value }
|
|
7041
7039
|
});
|
|
7042
7040
|
}
|
|
7043
7041
|
} else {
|
|
@@ -7051,7 +7049,10 @@ function computePieMarks(spec, scales, chartArea, _strategy, innerRadiusSpec = 0
|
|
|
7051
7049
|
}
|
|
7052
7050
|
if (slices.length === 0) return [];
|
|
7053
7051
|
slices.sort((a, b) => b.value - a.value);
|
|
7054
|
-
slices = groupSmallSlices(slices, SMALL_SLICE_THRESHOLD
|
|
7052
|
+
slices = groupSmallSlices(slices, SMALL_SLICE_THRESHOLD, {
|
|
7053
|
+
category: categoryField,
|
|
7054
|
+
value: valueChannel.field
|
|
7055
|
+
});
|
|
7055
7056
|
const pieGenerator = d3Pie().value((d) => d.value).sort(null).padAngle(PIE_PAD_ANGLE).startAngle(startAngle).endAngle(endAngle);
|
|
7056
7057
|
const arcs = pieGenerator(slices);
|
|
7057
7058
|
const sweepBounds = computeSweepBounds(startAngle, endAngle);
|
|
@@ -8609,7 +8610,7 @@ function describeRefusal(markType, display, faceted, layered) {
|
|
|
8609
8610
|
}
|
|
8610
8611
|
|
|
8611
8612
|
// src/compiler/validation/locale.ts
|
|
8612
|
-
import { matchLocale, SUPPORTED_LOCALES } from "@opendata-ai/openchart-core";
|
|
8613
|
+
import { jsonPointer, matchLocale, SUPPORTED_LOCALES } from "@opendata-ai/openchart-core";
|
|
8613
8614
|
var INVALID_LOCALE_TYPE = "[INVALID_LOCALE_TYPE]";
|
|
8614
8615
|
var LOCALE_WARNING_PREFIX = 'locale "';
|
|
8615
8616
|
function isLocaleWarning(message) {
|
|
@@ -8625,10 +8626,21 @@ function validateLocale(spec, errors) {
|
|
|
8625
8626
|
suggestion: 'Use a string such as "de-DE".'
|
|
8626
8627
|
});
|
|
8627
8628
|
};
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8629
|
+
const validateSpecLocales = (current, prefix) => {
|
|
8630
|
+
validate(current.locale, `${prefix}/locale`);
|
|
8631
|
+
const theme = current.theme;
|
|
8632
|
+
if (theme && typeof theme === "object" && "locale" in theme)
|
|
8633
|
+
validate(theme.locale, `${prefix}/theme/locale`);
|
|
8634
|
+
if (Array.isArray(current.layer)) {
|
|
8635
|
+
for (const [index, child] of current.layer.entries())
|
|
8636
|
+
if (child && typeof child === "object" && !Array.isArray(child))
|
|
8637
|
+
validateSpecLocales(
|
|
8638
|
+
child,
|
|
8639
|
+
`${prefix}${jsonPointer("layer", index)}`
|
|
8640
|
+
);
|
|
8641
|
+
}
|
|
8642
|
+
};
|
|
8643
|
+
validateSpecLocales(spec, "");
|
|
8632
8644
|
}
|
|
8633
8645
|
function localeWarnings(locale) {
|
|
8634
8646
|
if (locale === void 0) return [];
|
|
@@ -8733,7 +8745,7 @@ import {
|
|
|
8733
8745
|
} from "@opendata-ai/openchart-core";
|
|
8734
8746
|
|
|
8735
8747
|
// src/compiler/mark-options.ts
|
|
8736
|
-
import { jsonPointer } from "@opendata-ai/openchart-core";
|
|
8748
|
+
import { jsonPointer as jsonPointer2 } from "@opendata-ai/openchart-core";
|
|
8737
8749
|
var APPLIES_TO = {
|
|
8738
8750
|
ticks: ["errorbar"],
|
|
8739
8751
|
point: ["line", "area", "density"],
|
|
@@ -8792,7 +8804,7 @@ function collectMarkOptionErrors(input, path = "") {
|
|
|
8792
8804
|
if (mark[key] !== void 0 && !allowed.includes(mark.type)) {
|
|
8793
8805
|
errors.push({
|
|
8794
8806
|
code: "INVALID_VALUE",
|
|
8795
|
-
path: `${path}${
|
|
8807
|
+
path: `${path}${jsonPointer2("mark", key)}`,
|
|
8796
8808
|
message: `Option "${key}" is not supported by mark "${mark.type}".`,
|
|
8797
8809
|
suggestion: `Remove ${key}, or use a supported mark: ${allowed.join(", ")}.`
|
|
8798
8810
|
});
|
|
@@ -8802,7 +8814,7 @@ function collectMarkOptionErrors(input, path = "") {
|
|
|
8802
8814
|
if (key !== "render" && !SHARED_OPTIONS.has(key) && !(key in APPLIES_TO)) {
|
|
8803
8815
|
errors.push({
|
|
8804
8816
|
code: "INVALID_VALUE",
|
|
8805
|
-
path: `${path}${
|
|
8817
|
+
path: `${path}${jsonPointer2("mark", key)}`,
|
|
8806
8818
|
message: `Unknown mark option "${key}".`,
|
|
8807
8819
|
suggestion: `Remove ${key}.`
|
|
8808
8820
|
});
|
|
@@ -16828,15 +16840,15 @@ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, paren
|
|
|
16828
16840
|
}
|
|
16829
16841
|
|
|
16830
16842
|
// src/compiler/validate.ts
|
|
16831
|
-
import { isRaceSpec as isRaceSpec2, jsonPointer as
|
|
16843
|
+
import { isRaceSpec as isRaceSpec2, jsonPointer as jsonPointer22, MARK_TYPES as MARK_TYPES2 } from "@opendata-ai/openchart-core";
|
|
16832
16844
|
|
|
16833
16845
|
// src/compiler/validation/barlist.ts
|
|
16834
|
-
import { jsonPointer as
|
|
16846
|
+
import { jsonPointer as jsonPointer4 } from "@opendata-ai/openchart-core";
|
|
16835
16847
|
|
|
16836
16848
|
// src/compiler/validation/helpers.ts
|
|
16837
16849
|
import {
|
|
16838
16850
|
DIVERGING_PALETTES as DIVERGING_PALETTES2,
|
|
16839
|
-
jsonPointer as
|
|
16851
|
+
jsonPointer as jsonPointer3,
|
|
16840
16852
|
resolveSchemeName as resolveSchemeName3,
|
|
16841
16853
|
SEQUENTIAL_PALETTES as SEQUENTIAL_PALETTES2,
|
|
16842
16854
|
SUPPORTED_SCHEME_NAMES
|
|
@@ -16906,7 +16918,7 @@ function checkSchemeName(channelObj, channelPath, errors) {
|
|
|
16906
16918
|
if (scale && typeof scale.scheme === "string" && !resolveSchemeName3(scale.scheme)) {
|
|
16907
16919
|
errors.push({
|
|
16908
16920
|
message: `Spec error: ${channelPath.join(".")}.scale.scheme "${scale.scheme}" is not a supported scheme name`,
|
|
16909
|
-
path:
|
|
16921
|
+
path: jsonPointer3(...channelPath, "scale", "scheme"),
|
|
16910
16922
|
code: "INVALID_VALUE",
|
|
16911
16923
|
suggestion: `Use one of the supported scheme names: ${[...SUPPORTED_SCHEME_NAMES].join(", ")}. Or provide explicit colors via scale.range.`
|
|
16912
16924
|
});
|
|
@@ -16919,7 +16931,7 @@ function checkSchemeUnused(encoding, errors, familyNote, suggestion) {
|
|
|
16919
16931
|
if (scale && typeof scale.scheme === "string") {
|
|
16920
16932
|
errors.push({
|
|
16921
16933
|
message: `Spec error: encoding.${channel}.scale.scheme has no effect \u2014 ${familyNote}`,
|
|
16922
|
-
path:
|
|
16934
|
+
path: jsonPointer3("encoding", channel, "scale", "scheme"),
|
|
16923
16935
|
code: "INVALID_VALUE",
|
|
16924
16936
|
suggestion
|
|
16925
16937
|
});
|
|
@@ -16933,7 +16945,7 @@ function checkMapSchemeName(channelObj, channelPath, errors) {
|
|
|
16933
16945
|
if (channelObj.type === "nominal" || channelObj.type === "ordinal") {
|
|
16934
16946
|
errors.push({
|
|
16935
16947
|
message: `Spec error: ${channelPath.join(".")}.scale.scheme has no effect \u2014 categorical map colors come from scale.range and scale.domain`,
|
|
16936
|
-
path:
|
|
16948
|
+
path: jsonPointer3(...channelPath, "scale", "scheme"),
|
|
16937
16949
|
code: "INVALID_VALUE",
|
|
16938
16950
|
suggestion: "Remove scale.scheme. To customize categorical map colors, provide explicit colors via scale.range (with scale.domain for category order)."
|
|
16939
16951
|
});
|
|
@@ -16942,7 +16954,7 @@ function checkMapSchemeName(channelObj, channelPath, errors) {
|
|
|
16942
16954
|
if (!(scale.scheme in SEQUENTIAL_PALETTES2) && !(scale.scheme in DIVERGING_PALETTES2)) {
|
|
16943
16955
|
errors.push({
|
|
16944
16956
|
message: `Spec error: ${channelPath.join(".")}.scale.scheme "${scale.scheme}" is not a supported map palette`,
|
|
16945
|
-
path:
|
|
16957
|
+
path: jsonPointer3(...channelPath, "scale", "scheme"),
|
|
16946
16958
|
code: "INVALID_VALUE",
|
|
16947
16959
|
suggestion: `Maps support sequential and diverging palettes: ${MAP_PALETTE_NAMES}. The default is "blue".`
|
|
16948
16960
|
});
|
|
@@ -16997,7 +17009,7 @@ function validateBarListSpec(spec, errors) {
|
|
|
16997
17009
|
if (!ch || typeof ch !== "object") {
|
|
16998
17010
|
errors.push({
|
|
16999
17011
|
message: `Spec error: barlist encoding requires "${channel}" channel`,
|
|
17000
|
-
path:
|
|
17012
|
+
path: jsonPointer4("encoding", channel),
|
|
17001
17013
|
code: "MISSING_FIELD",
|
|
17002
17014
|
suggestion: `Add encoding.${channel} with a field from your data (${availableColumns}). Example: ${channel}: { field: "${columnList[0] ?? "myField"}", type: "${channel === "value" ? "quantitative" : "nominal"}" }`
|
|
17003
17015
|
});
|
|
@@ -17006,7 +17018,7 @@ function validateBarListSpec(spec, errors) {
|
|
|
17006
17018
|
if (!ch.field || typeof ch.field !== "string") {
|
|
17007
17019
|
errors.push({
|
|
17008
17020
|
message: `Spec error: encoding.${channel} must have a "field" string`,
|
|
17009
|
-
path:
|
|
17021
|
+
path: jsonPointer4("encoding", channel, "field"),
|
|
17010
17022
|
code: "MISSING_FIELD",
|
|
17011
17023
|
suggestion: `Add a field name from your data columns: ${availableColumns}`
|
|
17012
17024
|
});
|
|
@@ -17015,7 +17027,7 @@ function validateBarListSpec(spec, errors) {
|
|
|
17015
17027
|
if (!dataColumns.has(ch.field)) {
|
|
17016
17028
|
errors.push({
|
|
17017
17029
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
17018
|
-
path:
|
|
17030
|
+
path: jsonPointer4("encoding", channel, "field"),
|
|
17019
17031
|
code: "DATA_FIELD_MISSING",
|
|
17020
17032
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(ch.field, columnList)}`
|
|
17021
17033
|
});
|
|
@@ -17028,7 +17040,7 @@ function validateBarListSpec(spec, errors) {
|
|
|
17028
17040
|
if (field && typeof field === "string" && !dataColumns.has(field)) {
|
|
17029
17041
|
errors.push({
|
|
17030
17042
|
message: `Spec error: encoding.${channel}.field "${field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
17031
|
-
path:
|
|
17043
|
+
path: jsonPointer4("encoding", channel, "field"),
|
|
17032
17044
|
code: "DATA_FIELD_MISSING",
|
|
17033
17045
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(field, columnList)}`
|
|
17034
17046
|
});
|
|
@@ -17095,7 +17107,7 @@ function validateBarListSpec(spec, errors) {
|
|
|
17095
17107
|
// src/compiler/validation/chart.ts
|
|
17096
17108
|
import {
|
|
17097
17109
|
inferFieldType as inferFieldType6,
|
|
17098
|
-
jsonPointer as
|
|
17110
|
+
jsonPointer as jsonPointer8,
|
|
17099
17111
|
MARK_ENCODING_RULES
|
|
17100
17112
|
} from "@opendata-ai/openchart-core";
|
|
17101
17113
|
|
|
@@ -17328,7 +17340,7 @@ function validatePreparedLabelPlacement(spec) {
|
|
|
17328
17340
|
}
|
|
17329
17341
|
|
|
17330
17342
|
// src/compiler/validation/mark-rules.ts
|
|
17331
|
-
import { inferFieldType as inferFieldType5, jsonPointer as
|
|
17343
|
+
import { inferFieldType as inferFieldType5, jsonPointer as jsonPointer5 } from "@opendata-ai/openchart-core";
|
|
17332
17344
|
var VALID_RANGE_STYLES = /* @__PURE__ */ new Set(["dumbbell", "arrow", "bar"]);
|
|
17333
17345
|
function validateRangeSpec(spec, errors) {
|
|
17334
17346
|
const encoding = spec.encoding;
|
|
@@ -17507,7 +17519,7 @@ function validateCalendarSpec(spec, errors) {
|
|
|
17507
17519
|
if (value != null && !isParseableDate(value)) {
|
|
17508
17520
|
errors.push({
|
|
17509
17521
|
message: `Spec error: encoding.x.field "${x.field}" contains an unparseable date at data[${i}]: ${JSON.stringify(value)}`,
|
|
17510
|
-
path:
|
|
17522
|
+
path: jsonPointer5("data", i, x.field),
|
|
17511
17523
|
code: "INVALID_VALUE",
|
|
17512
17524
|
suggestion: `Fix data[${i}].${x.field} to a parseable date (ISO 8601 strings like "2024-01-15" or Date objects)`
|
|
17513
17525
|
});
|
|
@@ -17525,7 +17537,7 @@ function validateCalendarSpec(spec, errors) {
|
|
|
17525
17537
|
if (firstIndex !== void 0) {
|
|
17526
17538
|
errors.push({
|
|
17527
17539
|
message: `Spec error: calendar chart requires daily granularity, but data[${firstIndex}] and data[${i}] fall on the same day (${JSON.stringify(value)})`,
|
|
17528
|
-
path:
|
|
17540
|
+
path: jsonPointer5("data", i, x.field),
|
|
17529
17541
|
code: "ENCODING_MISMATCH",
|
|
17530
17542
|
suggestion: `Aggregate to one row per day first, e.g. transform: [{ timeUnit: "yearmonthdate", field: "${x.field}", as: "day" }] plus an aggregate over the value field, or pre-aggregate the data.`
|
|
17531
17543
|
});
|
|
@@ -17539,7 +17551,7 @@ function pointSizeError(tokens, value) {
|
|
|
17539
17551
|
const radius = Math.max(1, Math.round(Math.sqrt(value / Math.PI)));
|
|
17540
17552
|
return {
|
|
17541
17553
|
message: `Spec error: ${tokens.join(".")} is a radius in pixels, and ${value} would draw a ${Math.round(value * 2)}px-wide circle. This usually means the value was written in Vega-Lite's units, where point size is an area in px^2.`,
|
|
17542
|
-
path:
|
|
17554
|
+
path: jsonPointer5(...tokens),
|
|
17543
17555
|
code: "INVALID_VALUE",
|
|
17544
17556
|
suggestion: `Point sizes are radii in px (default 5, typical 2-12). For the dot a Vega-Lite size of ${value} draws, use ${radius} (r = sqrt(area / pi)).`
|
|
17545
17557
|
};
|
|
@@ -17672,7 +17684,7 @@ function checkStack(x, errors) {
|
|
|
17672
17684
|
}
|
|
17673
17685
|
|
|
17674
17686
|
// src/compiler/validation/time.ts
|
|
17675
|
-
import { jsonPointer as
|
|
17687
|
+
import { jsonPointer as jsonPointer7 } from "@opendata-ai/openchart-core";
|
|
17676
17688
|
|
|
17677
17689
|
// src/playback/periods.ts
|
|
17678
17690
|
var ISO_TIME_WITHOUT_OFFSET = /T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?$/i;
|
|
@@ -17737,7 +17749,7 @@ function firstDuplicateCell(rows, identityOf, time) {
|
|
|
17737
17749
|
}
|
|
17738
17750
|
|
|
17739
17751
|
// src/compiler/validation/playback.ts
|
|
17740
|
-
import { jsonPointer as
|
|
17752
|
+
import { jsonPointer as jsonPointer6 } from "@opendata-ai/openchart-core";
|
|
17741
17753
|
var PLAYBACK_OPTIONS = [
|
|
17742
17754
|
"duration",
|
|
17743
17755
|
"step",
|
|
@@ -17770,7 +17782,7 @@ function checkUnknownPlaybackKeys(block, errors) {
|
|
|
17770
17782
|
const hint = didYouMean(option, PLAYBACK_OPTIONS);
|
|
17771
17783
|
errors.push(
|
|
17772
17784
|
invalid2(
|
|
17773
|
-
|
|
17785
|
+
jsonPointer6("playback", option),
|
|
17774
17786
|
`Unknown playback option "${option}"`,
|
|
17775
17787
|
hint ? `Check the option name and keep its value.${hint}` : `Remove "${option}". Supported playback options are ${PLAYBACK_OPTIONS.join(", ")}.`
|
|
17776
17788
|
)
|
|
@@ -17794,7 +17806,7 @@ function checkTiming(name, block, errors) {
|
|
|
17794
17806
|
if (isFiniteNumber(value) && value >= 0 && (value > 0 || allowZero)) continue;
|
|
17795
17807
|
errors.push(
|
|
17796
17808
|
invalid2(
|
|
17797
|
-
|
|
17809
|
+
jsonPointer6(name, option),
|
|
17798
17810
|
`${name}.${option} must be a finite number ${allowZero ? "of zero or more" : "greater than zero"}`,
|
|
17799
17811
|
`Use ${option}: ${example} or omit the option. Times are in milliseconds.`
|
|
17800
17812
|
)
|
|
@@ -17816,7 +17828,7 @@ function checkSwitches(name, block, errors) {
|
|
|
17816
17828
|
if (block[option] === void 0 || typeof block[option] === "boolean") continue;
|
|
17817
17829
|
errors.push(
|
|
17818
17830
|
invalid2(
|
|
17819
|
-
|
|
17831
|
+
jsonPointer6(name, option),
|
|
17820
17832
|
`${name}.${option} must be true or false`,
|
|
17821
17833
|
`Use ${option}: false to disable it or ${option}: true to enable it.`
|
|
17822
17834
|
)
|
|
@@ -17946,7 +17958,7 @@ function checkUnsupportedFeatures(spec, encoding, context, errors) {
|
|
|
17946
17958
|
if (encoding[channel] === void 0) continue;
|
|
17947
17959
|
errors.push(
|
|
17948
17960
|
mismatch(
|
|
17949
|
-
|
|
17961
|
+
jsonPointer7("encoding", channel),
|
|
17950
17962
|
`encoding.time cannot be combined with encoding.${channel}, which facets the chart`,
|
|
17951
17963
|
`Remove encoding.${channel}, or remove encoding.time.`
|
|
17952
17964
|
)
|
|
@@ -17988,7 +18000,7 @@ function checkPointOnlyOptions(spec, errors) {
|
|
|
17988
18000
|
if (value === void 0 || value === false) continue;
|
|
17989
18001
|
errors.push(
|
|
17990
18002
|
mismatch(
|
|
17991
|
-
|
|
18003
|
+
jsonPointer7("playback", option),
|
|
17992
18004
|
`playback.${option} is only supported on point marks, not ${mark}`,
|
|
17993
18005
|
`Remove playback.${option}, or change the mark to point.`
|
|
17994
18006
|
)
|
|
@@ -18005,7 +18017,7 @@ function checkTrailAxes(spec, encoding, errors) {
|
|
|
18005
18017
|
if (type === void 0 || type === "quantitative") continue;
|
|
18006
18018
|
errors.push(
|
|
18007
18019
|
mismatch(
|
|
18008
|
-
|
|
18020
|
+
jsonPointer7("playback", "trails"),
|
|
18009
18021
|
`playback.trails needs quantitative x and y, but ${channel} is not quantitative (${JSON.stringify(type)})`,
|
|
18010
18022
|
`Make encoding.${channel} quantitative, or remove playback.trails.`
|
|
18011
18023
|
)
|
|
@@ -18021,7 +18033,7 @@ function checkAggregateKeepsTime(spec, timeField, errors) {
|
|
|
18021
18033
|
if (groupby.includes(timeField)) return;
|
|
18022
18034
|
errors.push(
|
|
18023
18035
|
mismatch(
|
|
18024
|
-
|
|
18036
|
+
jsonPointer7("transform", index, "groupby"),
|
|
18025
18037
|
`this aggregate drops the time field '${timeField}', so there is nothing to play over`,
|
|
18026
18038
|
`Add '${timeField}' to the aggregate's groupby.`
|
|
18027
18039
|
)
|
|
@@ -18109,7 +18121,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18109
18121
|
markType !== "bar" || !["x", "y", "x2", "y2"].includes(name) || channel.type !== "temporal")
|
|
18110
18122
|
errors.push({
|
|
18111
18123
|
code: "INVALID_VALUE",
|
|
18112
|
-
path:
|
|
18124
|
+
path: jsonPointer8("encoding", name, "interval"),
|
|
18113
18125
|
message: "interval requires a temporal position channel of a bar mark and a calendar unit or finite positive milliseconds.",
|
|
18114
18126
|
suggestion: "Use day, week, month, quarter, year, or a positive millisecond interval on a temporal position channel of a bar mark."
|
|
18115
18127
|
});
|
|
@@ -18178,7 +18190,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18178
18190
|
const suggestedChannel = channel === "y" && isThetaMark ? "theta" : channel;
|
|
18179
18191
|
errors.push({
|
|
18180
18192
|
message: `Spec error: ${markType} chart requires encoding.${suggestedChannel} but none was provided`,
|
|
18181
|
-
path:
|
|
18193
|
+
path: jsonPointer8("encoding", suggestedChannel),
|
|
18182
18194
|
code: "MISSING_FIELD",
|
|
18183
18195
|
suggestion: `Add encoding.${suggestedChannel} with a field from your data (${availableColumns}) and type (${allowedTypes}). Example: ${suggestedChannel}: { field: "${[...dataColumns][0] ?? "myField"}", type: "${rule.allowedTypes[0]}" }`
|
|
18184
18196
|
});
|
|
@@ -18230,7 +18242,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18230
18242
|
if (t && typeof t === "object" && typeof t.calculate === "string") {
|
|
18231
18243
|
errors.push({
|
|
18232
18244
|
message: `Spec error: transform[${i}].calculate must be a structured expression object, not a string`,
|
|
18233
|
-
path:
|
|
18245
|
+
path: jsonPointer8("transform", i, "calculate"),
|
|
18234
18246
|
code: "INVALID_TYPE",
|
|
18235
18247
|
suggestion: 'Use the structured form for single operations, e.g. calculate: { op: "/", field: "a", field2: "b" } with as: "ratio". For running or grouped computations use the window or aggregate transforms.'
|
|
18236
18248
|
});
|
|
@@ -18272,7 +18284,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18272
18284
|
if (!elem.field || typeof elem.field !== "string") {
|
|
18273
18285
|
errors.push({
|
|
18274
18286
|
message: `Spec error: encoding.tooltip[${i}] must have a "field" string`,
|
|
18275
|
-
path:
|
|
18287
|
+
path: jsonPointer8("encoding", "tooltip", i, "field"),
|
|
18276
18288
|
code: "MISSING_FIELD",
|
|
18277
18289
|
suggestion: `Add a field name from your data columns: ${availableColumns}`
|
|
18278
18290
|
});
|
|
@@ -18281,7 +18293,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18281
18293
|
if (!dataColumns.has(elem.field) && !transformFields.has(elem.field)) {
|
|
18282
18294
|
errors.push({
|
|
18283
18295
|
message: `Spec error: encoding.tooltip[${i}].field "${elem.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
18284
|
-
path:
|
|
18296
|
+
path: jsonPointer8("encoding", "tooltip", i, "field"),
|
|
18285
18297
|
code: "DATA_FIELD_MISSING",
|
|
18286
18298
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(elem.field, columnList)}`
|
|
18287
18299
|
});
|
|
@@ -18289,7 +18301,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18289
18301
|
if (elem.type && !VALID_FIELD_TYPES.has(elem.type)) {
|
|
18290
18302
|
errors.push({
|
|
18291
18303
|
message: `Spec error: encoding.tooltip[${i}].type "${elem.type}" is not valid. Must be one of: ${[...VALID_FIELD_TYPES].join(", ")}`,
|
|
18292
|
-
path:
|
|
18304
|
+
path: jsonPointer8("encoding", "tooltip", i, "type"),
|
|
18293
18305
|
code: "INVALID_VALUE",
|
|
18294
18306
|
suggestion: `Use one of: ${[...VALID_FIELD_TYPES].join(", ")}`
|
|
18295
18307
|
});
|
|
@@ -18323,7 +18335,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18323
18335
|
if (!channelObj.field || typeof channelObj.field !== "string") {
|
|
18324
18336
|
errors.push({
|
|
18325
18337
|
message: `Spec error: encoding.${channel} must have a "field" string`,
|
|
18326
|
-
path:
|
|
18338
|
+
path: jsonPointer8("encoding", channel, "field"),
|
|
18327
18339
|
code: "MISSING_FIELD",
|
|
18328
18340
|
suggestion: `For constant colors, use mark.fill (e.g., mark: { type: "bar", fill: "#1b7fa3" }) instead of encoding.${channel}. Encoding channels require a data field: ${availableColumns}`
|
|
18329
18341
|
});
|
|
@@ -18332,7 +18344,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18332
18344
|
if (!dataColumns.has(channelObj.field) && !transformFields.has(channelObj.field)) {
|
|
18333
18345
|
errors.push({
|
|
18334
18346
|
message: `Spec error: encoding.${channel}.field "${channelObj.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
18335
|
-
path:
|
|
18347
|
+
path: jsonPointer8("encoding", channel, "field"),
|
|
18336
18348
|
code: "DATA_FIELD_MISSING",
|
|
18337
18349
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(channelObj.field, columnList)}`
|
|
18338
18350
|
});
|
|
@@ -18340,7 +18352,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18340
18352
|
if (channelObj.type && !VALID_FIELD_TYPES.has(channelObj.type)) {
|
|
18341
18353
|
errors.push({
|
|
18342
18354
|
message: `Spec error: encoding.${channel}.type "${channelObj.type}" is not valid. Must be one of: ${[...VALID_FIELD_TYPES].join(", ")}`,
|
|
18343
|
-
path:
|
|
18355
|
+
path: jsonPointer8("encoding", channel, "type"),
|
|
18344
18356
|
code: "INVALID_VALUE",
|
|
18345
18357
|
suggestion: `Use one of: ${[...VALID_FIELD_TYPES].join(", ")}`
|
|
18346
18358
|
});
|
|
@@ -18350,7 +18362,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18350
18362
|
if (!channelRule.allowedTypes.includes(channelObj.type)) {
|
|
18351
18363
|
errors.push({
|
|
18352
18364
|
message: `Spec error: encoding.${channel} for ${markType} chart does not accept type "${channelObj.type}". Allowed types: ${channelRule.allowedTypes.join(", ")}`,
|
|
18353
|
-
path:
|
|
18365
|
+
path: jsonPointer8("encoding", channel, "type"),
|
|
18354
18366
|
code: "ENCODING_MISMATCH",
|
|
18355
18367
|
suggestion: `Change encoding.${channel}.type to one of: ${channelRule.allowedTypes.join(", ")}`
|
|
18356
18368
|
});
|
|
@@ -18372,7 +18384,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18372
18384
|
if (nonDateCount > 0) {
|
|
18373
18385
|
errors.push({
|
|
18374
18386
|
message: `Spec error: encoding.${channel}.field "${fieldName}" is declared as temporal but contains non-date values`,
|
|
18375
|
-
path:
|
|
18387
|
+
path: jsonPointer8("encoding", channel),
|
|
18376
18388
|
code: "ENCODING_MISMATCH",
|
|
18377
18389
|
suggestion: `Either change the type to "nominal" or ensure "${fieldName}" values are parseable dates (ISO 8601 strings like "2024-01-15" or Date objects)`
|
|
18378
18390
|
});
|
|
@@ -18389,7 +18401,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18389
18401
|
if (nonNumericCount > 0) {
|
|
18390
18402
|
errors.push({
|
|
18391
18403
|
message: `Spec error: encoding.${channel}.field "${fieldName}" is declared as quantitative but contains non-numeric values`,
|
|
18392
|
-
path:
|
|
18404
|
+
path: jsonPointer8("encoding", channel),
|
|
18393
18405
|
code: "ENCODING_MISMATCH",
|
|
18394
18406
|
suggestion: `Either change the type to "nominal" or ensure "${fieldName}" values are numbers`
|
|
18395
18407
|
});
|
|
@@ -18466,14 +18478,14 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18466
18478
|
if (!facetCh.field || typeof facetCh.field !== "string") {
|
|
18467
18479
|
errors.push({
|
|
18468
18480
|
message: `Spec error: encoding.${channel}.field is required and must be a non-empty string`,
|
|
18469
|
-
path:
|
|
18481
|
+
path: jsonPointer8("encoding", channel, "field"),
|
|
18470
18482
|
code: "MISSING_FIELD",
|
|
18471
18483
|
suggestion: `Add a field property to encoding.${channel} (e.g. { field: "category", type: "nominal" })`
|
|
18472
18484
|
});
|
|
18473
18485
|
} else if (!dataColumns.has(facetCh.field) && !transformFields.has(facetCh.field)) {
|
|
18474
18486
|
errors.push({
|
|
18475
18487
|
message: `Spec error: encoding.${channel}.field "${facetCh.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
18476
|
-
path:
|
|
18488
|
+
path: jsonPointer8("encoding", channel, "field"),
|
|
18477
18489
|
code: "DATA_FIELD_MISSING",
|
|
18478
18490
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(facetCh.field, columnList)}`
|
|
18479
18491
|
});
|
|
@@ -18481,7 +18493,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18481
18493
|
if (!facetCh.type || facetCh.type !== "nominal" && facetCh.type !== "ordinal") {
|
|
18482
18494
|
errors.push({
|
|
18483
18495
|
message: `Spec error: encoding.${channel}.type must be "nominal" or "ordinal"${facetCh.type ? `, got "${facetCh.type}"` : ""}`,
|
|
18484
|
-
path:
|
|
18496
|
+
path: jsonPointer8("encoding", channel, "type"),
|
|
18485
18497
|
code: facetCh.type ? "INVALID_VALUE" : "MISSING_FIELD",
|
|
18486
18498
|
suggestion: `Set encoding.${channel}.type to "nominal" or "ordinal"`
|
|
18487
18499
|
});
|
|
@@ -18489,7 +18501,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18489
18501
|
if (encoding.facet && typeof encoding.facet === "object") {
|
|
18490
18502
|
errors.push({
|
|
18491
18503
|
message: `Spec error: encoding.${channel} and encoding.facet cannot be used together`,
|
|
18492
|
-
path:
|
|
18504
|
+
path: jsonPointer8("encoding", channel),
|
|
18493
18505
|
code: "INVALID_VALUE",
|
|
18494
18506
|
suggestion: `Use either encoding.${channel} or encoding.facet, not both`
|
|
18495
18507
|
});
|
|
@@ -18498,7 +18510,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18498
18510
|
if (encoding[otherChannel]) {
|
|
18499
18511
|
errors.push({
|
|
18500
18512
|
message: "Spec error: encoding.row and encoding.column cannot be used together (cross-product faceting is not yet supported)",
|
|
18501
|
-
path:
|
|
18513
|
+
path: jsonPointer8("encoding", channel),
|
|
18502
18514
|
code: "INVALID_VALUE",
|
|
18503
18515
|
suggestion: "Use encoding.facet with columns for grid layout, or use only row or column"
|
|
18504
18516
|
});
|
|
@@ -18551,7 +18563,7 @@ function validateChartSpec(spec, errors, context = {}) {
|
|
|
18551
18563
|
}
|
|
18552
18564
|
|
|
18553
18565
|
// src/compiler/validation/chrome-links.ts
|
|
18554
|
-
import { isSafeLink, jsonPointer as
|
|
18566
|
+
import { isSafeLink, jsonPointer as jsonPointer9 } from "@opendata-ai/openchart-core";
|
|
18555
18567
|
function validateChromeLinks(spec, errors, prefix = "") {
|
|
18556
18568
|
const chrome = spec.chrome;
|
|
18557
18569
|
if (chrome && typeof chrome === "object" && !Array.isArray(chrome)) {
|
|
@@ -18561,7 +18573,7 @@ function validateChromeLinks(spec, errors, prefix = "") {
|
|
|
18561
18573
|
if (typeof value.href === "string" && isSafeLink(value.href)) continue;
|
|
18562
18574
|
errors.push({
|
|
18563
18575
|
code: "INVALID_VALUE",
|
|
18564
|
-
path: `${prefix}${
|
|
18576
|
+
path: `${prefix}${jsonPointer9("chrome", key, "href")}`,
|
|
18565
18577
|
message: `chrome.${key}.href must be an http, https or mailto link.`,
|
|
18566
18578
|
suggestion: "Use an absolute http, https or mailto URL, or omit href."
|
|
18567
18579
|
});
|
|
@@ -18570,13 +18582,13 @@ function validateChromeLinks(spec, errors, prefix = "") {
|
|
|
18570
18582
|
if (Array.isArray(spec.layer)) {
|
|
18571
18583
|
for (const [index, child] of spec.layer.entries()) {
|
|
18572
18584
|
if (child && typeof child === "object" && !Array.isArray(child))
|
|
18573
|
-
validateChromeLinks(child, errors, `${prefix}${
|
|
18585
|
+
validateChromeLinks(child, errors, `${prefix}${jsonPointer9("layer", index)}`);
|
|
18574
18586
|
}
|
|
18575
18587
|
}
|
|
18576
18588
|
}
|
|
18577
18589
|
|
|
18578
18590
|
// src/compiler/validation/common-fields.ts
|
|
18579
|
-
import { encodePointerToken as encodePointerToken2, jsonPointer as
|
|
18591
|
+
import { encodePointerToken as encodePointerToken2, jsonPointer as jsonPointer10 } from "@opendata-ai/openchart-core";
|
|
18580
18592
|
function validateAnimation(spec, errors) {
|
|
18581
18593
|
const animation = spec.animation;
|
|
18582
18594
|
if (typeof animation === "string" && !["fluid", "subtle"].includes(animation)) {
|
|
@@ -18635,7 +18647,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
18635
18647
|
errors.push({
|
|
18636
18648
|
code: "INVALID_VALUE",
|
|
18637
18649
|
suggestion: TIMING_SUGGESTION,
|
|
18638
|
-
path:
|
|
18650
|
+
path: jsonPointer10(...path),
|
|
18639
18651
|
message: "A phase cannot combine spring with duration or ease."
|
|
18640
18652
|
});
|
|
18641
18653
|
}
|
|
@@ -18643,7 +18655,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
18643
18655
|
errors.push({
|
|
18644
18656
|
code: "INVALID_VALUE",
|
|
18645
18657
|
suggestion: TIMING_SUGGESTION,
|
|
18646
|
-
path:
|
|
18658
|
+
path: jsonPointer10(...path, "spring"),
|
|
18647
18659
|
message: "Spring must be a configuration object."
|
|
18648
18660
|
});
|
|
18649
18661
|
} else {
|
|
@@ -18654,7 +18666,7 @@ function validatePhaseTiming(settings, path, errors) {
|
|
|
18654
18666
|
errors.push({
|
|
18655
18667
|
code: "INVALID_VALUE",
|
|
18656
18668
|
suggestion: TIMING_SUGGESTION,
|
|
18657
|
-
path:
|
|
18669
|
+
path: jsonPointer10(...path, "spring", key),
|
|
18658
18670
|
message: "Spring parameters must be finite positive stiffness, damping, or mass."
|
|
18659
18671
|
});
|
|
18660
18672
|
}
|
|
@@ -18669,7 +18681,7 @@ function validateDuration(duration, path, errors) {
|
|
|
18669
18681
|
errors.push({
|
|
18670
18682
|
code: "INVALID_VALUE",
|
|
18671
18683
|
suggestion: TIMING_SUGGESTION,
|
|
18672
|
-
path:
|
|
18684
|
+
path: jsonPointer10(...path, "duration"),
|
|
18673
18685
|
message: "Animation duration must be finite and nonnegative."
|
|
18674
18686
|
});
|
|
18675
18687
|
}
|
|
@@ -18679,7 +18691,7 @@ function validateEase(ease, path, errors) {
|
|
|
18679
18691
|
errors.push({
|
|
18680
18692
|
code: "INVALID_VALUE",
|
|
18681
18693
|
suggestion: "Use ease: 'smooth', 'snappy', or 'gentle'.",
|
|
18682
|
-
path:
|
|
18694
|
+
path: jsonPointer10(...path, "ease"),
|
|
18683
18695
|
message: `Animation ease must be 'smooth', 'snappy', or 'gentle', got ${JSON.stringify(ease)}.`
|
|
18684
18696
|
});
|
|
18685
18697
|
}
|
|
@@ -18745,7 +18757,7 @@ function validateFieldMetadata(obj, errors) {
|
|
|
18745
18757
|
return;
|
|
18746
18758
|
}
|
|
18747
18759
|
for (const [field, value] of Object.entries(obj.fields)) {
|
|
18748
|
-
const path =
|
|
18760
|
+
const path = jsonPointer10("fields", field);
|
|
18749
18761
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
18750
18762
|
fail2(path, "Field metadata must be an object.");
|
|
18751
18763
|
continue;
|
|
@@ -18788,7 +18800,7 @@ function validateFieldMetadata(obj, errors) {
|
|
|
18788
18800
|
}
|
|
18789
18801
|
|
|
18790
18802
|
// src/compiler/validation/geo-map.ts
|
|
18791
|
-
import { jsonPointer as
|
|
18803
|
+
import { jsonPointer as jsonPointer12 } from "@opendata-ai/openchart-core";
|
|
18792
18804
|
|
|
18793
18805
|
// src/geo/projections.ts
|
|
18794
18806
|
import { geoAlbersUsa, geoBounds, geoEqualEarth, geoIdentity, geoMercator } from "d3-geo";
|
|
@@ -18892,7 +18904,7 @@ function topologyBBox(topology) {
|
|
|
18892
18904
|
}
|
|
18893
18905
|
|
|
18894
18906
|
// src/compiler/validation/geo-time.ts
|
|
18895
|
-
import { jsonPointer as
|
|
18907
|
+
import { jsonPointer as jsonPointer11 } from "@opendata-ai/openchart-core";
|
|
18896
18908
|
var TIME_TYPES = ["temporal", "ordinal", "quantitative"];
|
|
18897
18909
|
var POINT_ONLY_OPTIONS = ["labels", "trails"];
|
|
18898
18910
|
function isRecord4(value) {
|
|
@@ -18950,7 +18962,7 @@ function checkPlaybackBlock(spec, errors) {
|
|
|
18950
18962
|
if (value === void 0 || value === false) continue;
|
|
18951
18963
|
errors.push(
|
|
18952
18964
|
invalid3(
|
|
18953
|
-
|
|
18965
|
+
jsonPointer11("playback", option),
|
|
18954
18966
|
`playback.${option} is only supported on point charts, not maps`,
|
|
18955
18967
|
`Remove playback.${option}.`
|
|
18956
18968
|
)
|
|
@@ -19112,7 +19124,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
19112
19124
|
if (!["activeValue", "distribution"].includes(name) || typeof value !== "boolean")
|
|
19113
19125
|
errors.push({
|
|
19114
19126
|
code: "INVALID_VALUE",
|
|
19115
|
-
path:
|
|
19127
|
+
path: jsonPointer12("colorKey", name),
|
|
19116
19128
|
message: "colorKey accepts only boolean activeValue and distribution.",
|
|
19117
19129
|
suggestion: "Omit either option or set it to true or false."
|
|
19118
19130
|
});
|
|
@@ -19163,7 +19175,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
19163
19175
|
if (typeof focus[i] !== "string" && typeof focus[i] !== "number") {
|
|
19164
19176
|
errors.push({
|
|
19165
19177
|
message: `Spec error: geo.focus array element [${i}] must be a string or number`,
|
|
19166
|
-
path:
|
|
19178
|
+
path: jsonPointer12("geo", "focus", i),
|
|
19167
19179
|
code: "INVALID_TYPE",
|
|
19168
19180
|
suggestion: "Each element in the focus array should be a feature id (string or number)"
|
|
19169
19181
|
});
|
|
@@ -19211,7 +19223,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
19211
19223
|
if (typeof feats[i] !== "string" && typeof feats[i] !== "number") {
|
|
19212
19224
|
errors.push({
|
|
19213
19225
|
message: `Spec error: geo.focus.features[${i}] must be a string or number`,
|
|
19214
|
-
path:
|
|
19226
|
+
path: jsonPointer12("geo", "focus", "features", i),
|
|
19215
19227
|
code: "INVALID_TYPE",
|
|
19216
19228
|
suggestion: "Each element should be a feature id (string or number)"
|
|
19217
19229
|
});
|
|
@@ -19299,14 +19311,14 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
19299
19311
|
if (!enc || typeof enc !== "object") {
|
|
19300
19312
|
errors.push({
|
|
19301
19313
|
message: `Spec error: points requires "${ch}" encoding channel`,
|
|
19302
|
-
path:
|
|
19314
|
+
path: jsonPointer12("points", ch),
|
|
19303
19315
|
code: "MISSING_FIELD",
|
|
19304
19316
|
suggestion: `Add points.${ch}, e.g. ${ch}: { field: "${ch === "longitude" ? "lon" : "lat"}", type: "quantitative" }`
|
|
19305
19317
|
});
|
|
19306
19318
|
} else if (!enc.field || typeof enc.field !== "string") {
|
|
19307
19319
|
errors.push({
|
|
19308
19320
|
message: `Spec error: points.${ch} must have a "field" string`,
|
|
19309
|
-
path:
|
|
19321
|
+
path: jsonPointer12("points", ch, "field"),
|
|
19310
19322
|
code: "MISSING_FIELD",
|
|
19311
19323
|
suggestion: `Add a field name, e.g. ${ch}: { field: "${ch === "longitude" ? "lon" : "lat"}" }`
|
|
19312
19324
|
});
|
|
@@ -19317,7 +19329,7 @@ function validateGeoMapSpec(spec, errors) {
|
|
|
19317
19329
|
if (enc && typeof enc === "object" && (!enc.field || typeof enc.field !== "string")) {
|
|
19318
19330
|
errors.push({
|
|
19319
19331
|
message: `Spec error: points.${ch} must have a "field" string when provided`,
|
|
19320
|
-
path:
|
|
19332
|
+
path: jsonPointer12("points", ch, "field"),
|
|
19321
19333
|
code: "MISSING_FIELD",
|
|
19322
19334
|
suggestion: `Add a field name, e.g. ${ch}: { field: "myField" }`
|
|
19323
19335
|
});
|
|
@@ -19573,7 +19585,7 @@ function validateGeoMapViews(spec, errors) {
|
|
|
19573
19585
|
}
|
|
19574
19586
|
|
|
19575
19587
|
// src/compiler/validation/graph.ts
|
|
19576
|
-
import { jsonPointer as
|
|
19588
|
+
import { jsonPointer as jsonPointer13 } from "@opendata-ai/openchart-core";
|
|
19577
19589
|
function validateGraphSpec(spec, errors) {
|
|
19578
19590
|
if (!Array.isArray(spec.nodes)) {
|
|
19579
19591
|
errors.push({
|
|
@@ -19600,7 +19612,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
19600
19612
|
if (!node3 || typeof node3 !== "object") {
|
|
19601
19613
|
errors.push({
|
|
19602
19614
|
message: `Spec error: nodes[${i}] must be an object`,
|
|
19603
|
-
path:
|
|
19615
|
+
path: jsonPointer13("nodes", i),
|
|
19604
19616
|
code: "INVALID_TYPE",
|
|
19605
19617
|
suggestion: 'Each node must be an object with at least an "id" field, e.g. { id: "a" }'
|
|
19606
19618
|
});
|
|
@@ -19609,7 +19621,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
19609
19621
|
if (typeof node3.id !== "string" || node3.id === "") {
|
|
19610
19622
|
errors.push({
|
|
19611
19623
|
message: `Spec error: nodes[${i}] must have a non-empty string "id" field`,
|
|
19612
|
-
path:
|
|
19624
|
+
path: jsonPointer13("nodes", i, "id"),
|
|
19613
19625
|
code: "MISSING_FIELD",
|
|
19614
19626
|
suggestion: 'Add a string id to the node, e.g. { id: "node1" }'
|
|
19615
19627
|
});
|
|
@@ -19661,7 +19673,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
19661
19673
|
if (!edge || typeof edge !== "object") {
|
|
19662
19674
|
errors.push({
|
|
19663
19675
|
message: `Spec error: edges[${i}] must be an object`,
|
|
19664
|
-
path:
|
|
19676
|
+
path: jsonPointer13("edges", i),
|
|
19665
19677
|
code: "INVALID_TYPE",
|
|
19666
19678
|
suggestion: 'Each edge must be an object with "source" and "target" fields, e.g. { source: "a", target: "b" }'
|
|
19667
19679
|
});
|
|
@@ -19670,14 +19682,14 @@ function validateGraphSpec(spec, errors) {
|
|
|
19670
19682
|
if (typeof edge.source !== "string" || edge.source === "") {
|
|
19671
19683
|
errors.push({
|
|
19672
19684
|
message: `Spec error: edges[${i}] must have a non-empty string "source" field`,
|
|
19673
|
-
path:
|
|
19685
|
+
path: jsonPointer13("edges", i, "source"),
|
|
19674
19686
|
code: "MISSING_FIELD",
|
|
19675
19687
|
suggestion: 'Add a source node id, e.g. { source: "a", target: "b" }'
|
|
19676
19688
|
});
|
|
19677
19689
|
} else if (nodeIds.size > 0 && !nodeIds.has(edge.source)) {
|
|
19678
19690
|
errors.push({
|
|
19679
19691
|
message: `Spec error: edges[${i}].source "${edge.source}" does not reference an existing node id`,
|
|
19680
|
-
path:
|
|
19692
|
+
path: jsonPointer13("edges", i, "source"),
|
|
19681
19693
|
code: "DATA_FIELD_MISSING",
|
|
19682
19694
|
suggestion: `Use one of the existing node ids: ${[...nodeIds].slice(0, 5).join(", ")}${nodeIds.size > 5 ? "..." : ""}.${didYouMean(edge.source, [...nodeIds])}`
|
|
19683
19695
|
});
|
|
@@ -19685,14 +19697,14 @@ function validateGraphSpec(spec, errors) {
|
|
|
19685
19697
|
if (typeof edge.target !== "string" || edge.target === "") {
|
|
19686
19698
|
errors.push({
|
|
19687
19699
|
message: `Spec error: edges[${i}] must have a non-empty string "target" field`,
|
|
19688
|
-
path:
|
|
19700
|
+
path: jsonPointer13("edges", i, "target"),
|
|
19689
19701
|
code: "MISSING_FIELD",
|
|
19690
19702
|
suggestion: 'Add a target node id, e.g. { source: "a", target: "b" }'
|
|
19691
19703
|
});
|
|
19692
19704
|
} else if (nodeIds.size > 0 && !nodeIds.has(edge.target)) {
|
|
19693
19705
|
errors.push({
|
|
19694
19706
|
message: `Spec error: edges[${i}].target "${edge.target}" does not reference an existing node id`,
|
|
19695
|
-
path:
|
|
19707
|
+
path: jsonPointer13("edges", i, "target"),
|
|
19696
19708
|
code: "DATA_FIELD_MISSING",
|
|
19697
19709
|
suggestion: `Use one of the existing node ids: ${[...nodeIds].slice(0, 5).join(", ")}${nodeIds.size > 5 ? "..." : ""}.${didYouMean(edge.target, [...nodeIds])}`
|
|
19698
19710
|
});
|
|
@@ -19724,7 +19736,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
19724
19736
|
if (ch?.field && typeof ch.field === "string" && nodes.length > 0 && !nodeFields.has(ch.field)) {
|
|
19725
19737
|
errors.push({
|
|
19726
19738
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist on nodes. Available fields: ${[...nodeFields].join(", ")}`,
|
|
19727
|
-
path:
|
|
19739
|
+
path: jsonPointer13("encoding", channel, "field"),
|
|
19728
19740
|
code: "DATA_FIELD_MISSING",
|
|
19729
19741
|
suggestion: `Use one of the node fields: ${[...nodeFields].join(", ")}.${didYouMean(ch.field, [...nodeFields])}`
|
|
19730
19742
|
});
|
|
@@ -19736,7 +19748,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
19736
19748
|
if (ch?.field && typeof ch.field === "string" && edges.length > 0 && !edgeFields.has(ch.field)) {
|
|
19737
19749
|
errors.push({
|
|
19738
19750
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist on edges. Available fields: ${[...edgeFields].join(", ")}`,
|
|
19739
|
-
path:
|
|
19751
|
+
path: jsonPointer13("encoding", channel, "field"),
|
|
19740
19752
|
code: "DATA_FIELD_MISSING",
|
|
19741
19753
|
suggestion: `Use one of the edge fields: ${[...edgeFields].join(", ")}.${didYouMean(ch.field, [...edgeFields])}`
|
|
19742
19754
|
});
|
|
@@ -19763,7 +19775,7 @@ function validateGraphSpec(spec, errors) {
|
|
|
19763
19775
|
}
|
|
19764
19776
|
|
|
19765
19777
|
// src/compiler/validation/layer.ts
|
|
19766
|
-
import { jsonPointer as
|
|
19778
|
+
import { jsonPointer as jsonPointer14, MARK_TYPES } from "@opendata-ai/openchart-core";
|
|
19767
19779
|
function rootLeafPath(path, parentPrefix, leafPrefix, leaf, inheritsData) {
|
|
19768
19780
|
const [, first, second] = path.split("/");
|
|
19769
19781
|
const leafEncoding = leaf.encoding;
|
|
@@ -19787,7 +19799,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
19787
19799
|
if (!child || typeof child !== "object" || Array.isArray(child)) {
|
|
19788
19800
|
errors.push({
|
|
19789
19801
|
message: `Spec error: layer[${i}] must be an object`,
|
|
19790
|
-
path: `${prefix}${
|
|
19802
|
+
path: `${prefix}${jsonPointer14("layer", i)}`,
|
|
19791
19803
|
code: "INVALID_TYPE",
|
|
19792
19804
|
suggestion: "Each layer must be a chart spec (with mark) or a nested layer spec (with layer)"
|
|
19793
19805
|
});
|
|
@@ -19797,7 +19809,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
19797
19809
|
if (childObj.type === "race") {
|
|
19798
19810
|
errors.push({
|
|
19799
19811
|
code: "INVALID_VALUE",
|
|
19800
|
-
path: `${prefix}${
|
|
19812
|
+
path: `${prefix}${jsonPointer14("layer", i, "type")}`,
|
|
19801
19813
|
message: "Race specs cannot be layered.",
|
|
19802
19814
|
suggestion: "Render the race in its own container."
|
|
19803
19815
|
});
|
|
@@ -19808,14 +19820,14 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
19808
19820
|
if (!isNestedLayer && !isChildChart) {
|
|
19809
19821
|
errors.push({
|
|
19810
19822
|
message: `Spec error: layer[${i}] must have a "mark" field or a "layer" array`,
|
|
19811
|
-
path: `${prefix}${
|
|
19823
|
+
path: `${prefix}${jsonPointer14("layer", i)}`,
|
|
19812
19824
|
code: "MISSING_FIELD",
|
|
19813
19825
|
suggestion: "Each layer must be a chart spec (with mark + encoding) or a nested layer spec (with layer array)"
|
|
19814
19826
|
});
|
|
19815
19827
|
continue;
|
|
19816
19828
|
}
|
|
19817
19829
|
if (isNestedLayer) {
|
|
19818
|
-
validateLayerSpec(childObj, errors, `${prefix}${
|
|
19830
|
+
validateLayerSpec(childObj, errors, `${prefix}${jsonPointer14("layer", i)}`);
|
|
19819
19831
|
} else if (isChildChart) {
|
|
19820
19832
|
const mark = childObj.mark;
|
|
19821
19833
|
let markValue;
|
|
@@ -19827,7 +19839,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
19827
19839
|
if (!markValue || !MARK_TYPES.has(markValue)) {
|
|
19828
19840
|
errors.push({
|
|
19829
19841
|
message: `Spec error: layer[${i}].mark "${markValue ?? String(mark)}" is not a valid mark type`,
|
|
19830
|
-
path: `${prefix}${
|
|
19842
|
+
path: `${prefix}${jsonPointer14("layer", i, "mark")}`,
|
|
19831
19843
|
code: "INVALID_VALUE",
|
|
19832
19844
|
suggestion: `Change mark to one of: ${[...MARK_TYPES].join(", ")}`
|
|
19833
19845
|
});
|
|
@@ -19849,7 +19861,7 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
19849
19861
|
if (mergedForValidation.data && mergedForValidation.encoding) {
|
|
19850
19862
|
const leafErrors = [];
|
|
19851
19863
|
validateChartSpec(mergedForValidation, leafErrors, { inLayer: true });
|
|
19852
|
-
const leafPrefix = `${prefix}${
|
|
19864
|
+
const leafPrefix = `${prefix}${jsonPointer14("layer", i)}`;
|
|
19853
19865
|
for (const error of leafErrors)
|
|
19854
19866
|
errors.push({
|
|
19855
19867
|
...error,
|
|
@@ -19862,10 +19874,10 @@ function validateLayerSpec(spec, errors, prefix = "") {
|
|
|
19862
19874
|
}
|
|
19863
19875
|
|
|
19864
19876
|
// src/compiler/validation/race.ts
|
|
19865
|
-
import { jsonPointer as
|
|
19877
|
+
import { jsonPointer as jsonPointer16 } from "@opendata-ai/openchart-core";
|
|
19866
19878
|
|
|
19867
19879
|
// src/compiler/validation/race-options.ts
|
|
19868
|
-
import { jsonPointer as
|
|
19880
|
+
import { jsonPointer as jsonPointer15 } from "@opendata-ai/openchart-core";
|
|
19869
19881
|
var RACE_OPTIONS = [
|
|
19870
19882
|
"top",
|
|
19871
19883
|
"duration",
|
|
@@ -19908,7 +19920,7 @@ function checkUnknownRaceKeys(race, errors) {
|
|
|
19908
19920
|
const hint = didYouMean(option, RACE_OPTIONS);
|
|
19909
19921
|
errors.push({
|
|
19910
19922
|
code: "INVALID_VALUE",
|
|
19911
|
-
path:
|
|
19923
|
+
path: jsonPointer15("race", option),
|
|
19912
19924
|
message: `Spec error: Unknown race option "${option}"`,
|
|
19913
19925
|
suggestion: hint ? `Check the option name and keep its value.${hint}` : `Remove "${option}". Supported race options are ${RACE_OPTIONS.join(", ")}.`
|
|
19914
19926
|
});
|
|
@@ -19971,7 +19983,7 @@ function checkTimingAcrossBlocks(race, playback, errors) {
|
|
|
19971
19983
|
if (race[raceField2] === void 0 || playback[playbackField] === void 0) continue;
|
|
19972
19984
|
errors.push({
|
|
19973
19985
|
code: "INVALID_VALUE",
|
|
19974
|
-
path:
|
|
19986
|
+
path: jsonPointer15("playback", playbackField),
|
|
19975
19987
|
message: `Spec error: duration and step are mutually exclusive across race and playback (race.${raceField2}, playback.${playbackField})`,
|
|
19976
19988
|
suggestion: "Keep duration for the whole race or step for each period, in one block. Remove the other option."
|
|
19977
19989
|
});
|
|
@@ -19983,14 +19995,14 @@ function checkPlaybackAgainstRace(race, playback, errors) {
|
|
|
19983
19995
|
if (CHART_ONLY_PLAYBACK_OPTIONS.includes(field)) {
|
|
19984
19996
|
errors.push({
|
|
19985
19997
|
code: "INVALID_VALUE",
|
|
19986
|
-
path:
|
|
19998
|
+
path: jsonPointer15("playback", field),
|
|
19987
19999
|
message: `Spec error: playback.${field} applies to point and circle charts only`,
|
|
19988
20000
|
suggestion: `Remove playback.${field} from the race spec.`
|
|
19989
20001
|
});
|
|
19990
20002
|
} else if (isRecord5(race) && race[field] !== void 0 && playback[field] !== void 0) {
|
|
19991
20003
|
errors.push({
|
|
19992
20004
|
code: "INVALID_VALUE",
|
|
19993
|
-
path:
|
|
20005
|
+
path: jsonPointer15("playback", field),
|
|
19994
20006
|
message: `Spec error: ${field} is set in both race and playback`,
|
|
19995
20007
|
suggestion: `Keep ${field} in one block. Remove it from race or from playback.`
|
|
19996
20008
|
});
|
|
@@ -20068,7 +20080,7 @@ function validateEncoding(encoding, errors) {
|
|
|
20068
20080
|
if (!isRecord6(definition)) {
|
|
20069
20081
|
errors.push({
|
|
20070
20082
|
code: definition === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
|
|
20071
|
-
path:
|
|
20083
|
+
path: jsonPointer16("encoding", channel),
|
|
20072
20084
|
message: definition === void 0 ? `Spec error: race encoding requires a "${channel}" channel` : `Spec error: encoding.${channel} must be an object`,
|
|
20073
20085
|
suggestion: `Add encoding.${channel} with a field from your data, e.g. { field: "${example}" }.`
|
|
20074
20086
|
});
|
|
@@ -20078,7 +20090,7 @@ function validateEncoding(encoding, errors) {
|
|
|
20078
20090
|
if (typeof field !== "string" || field.trim() === "") {
|
|
20079
20091
|
errors.push({
|
|
20080
20092
|
code: field === void 0 ? "MISSING_FIELD" : "INVALID_TYPE",
|
|
20081
|
-
path:
|
|
20093
|
+
path: jsonPointer16("encoding", channel, "field"),
|
|
20082
20094
|
message: `Spec error: encoding.${channel} requires a non-empty "field" string`,
|
|
20083
20095
|
suggestion: `Set encoding.${channel}.field to the name of a column in your data, e.g. "${example}".`
|
|
20084
20096
|
});
|
|
@@ -20090,7 +20102,7 @@ function validateEncoding(encoding, errors) {
|
|
|
20090
20102
|
if (definition === void 0 || isRecord6(definition)) continue;
|
|
20091
20103
|
errors.push({
|
|
20092
20104
|
code: "INVALID_TYPE",
|
|
20093
|
-
path:
|
|
20105
|
+
path: jsonPointer16("encoding", channel),
|
|
20094
20106
|
message: `Spec error: encoding.${channel} must be an object`,
|
|
20095
20107
|
suggestion: `Use a channel definition or omit encoding.${channel}.`
|
|
20096
20108
|
});
|
|
@@ -20111,7 +20123,7 @@ function validateEncodingFields(encoding, data, errors) {
|
|
|
20111
20123
|
if (typeof field !== "string" || field.trim() === "" || dataColumns.has(field)) continue;
|
|
20112
20124
|
errors.push({
|
|
20113
20125
|
message: `Spec error: encoding.${channel}.field "${field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
20114
|
-
path:
|
|
20126
|
+
path: jsonPointer16("encoding", channel, "field"),
|
|
20115
20127
|
code: "DATA_FIELD_MISSING",
|
|
20116
20128
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(field, columnList)}`
|
|
20117
20129
|
});
|
|
@@ -20166,7 +20178,7 @@ function validateMark(mark, errors) {
|
|
|
20166
20178
|
if (option === "type" || option === supported) continue;
|
|
20167
20179
|
errors.push({
|
|
20168
20180
|
code: "INVALID_VALUE",
|
|
20169
|
-
path:
|
|
20181
|
+
path: jsonPointer16("mark", option),
|
|
20170
20182
|
message: `Spec error: unknown option "${option}" on the race "${type}" mark`,
|
|
20171
20183
|
suggestion: `Remove "${option}". The "${type}" mark supports "${supported}".${didYouMean(option, [supported])}`
|
|
20172
20184
|
});
|
|
@@ -20195,7 +20207,7 @@ function validateData(data, errors) {
|
|
|
20195
20207
|
const otherRows = invalidCount > 1 ? " and the other non-object rows" : "";
|
|
20196
20208
|
errors.push({
|
|
20197
20209
|
code: "INVALID_TYPE",
|
|
20198
|
-
path:
|
|
20210
|
+
path: jsonPointer16("data", firstInvalidRow),
|
|
20199
20211
|
message: `Spec error: each race data row must be an object. ${invalidCount} of ${data.length} rows ${invalidRows}.`,
|
|
20200
20212
|
suggestion: `Replace or remove row ${firstInvalidRow + 1}${otherRows}. Each row should name the fields used by time, key, and value.`
|
|
20201
20213
|
});
|
|
@@ -20220,7 +20232,7 @@ function validateRaceSpec(spec, errors) {
|
|
|
20220
20232
|
}
|
|
20221
20233
|
|
|
20222
20234
|
// src/compiler/validation/sankey.ts
|
|
20223
|
-
import { jsonPointer as
|
|
20235
|
+
import { jsonPointer as jsonPointer17 } from "@opendata-ai/openchart-core";
|
|
20224
20236
|
|
|
20225
20237
|
// src/sankey/overrides.ts
|
|
20226
20238
|
import { getBreakpoint } from "@opendata-ai/openchart-core";
|
|
@@ -20295,7 +20307,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
20295
20307
|
if (!ch || typeof ch !== "object") {
|
|
20296
20308
|
errors.push({
|
|
20297
20309
|
message: `Spec error: sankey encoding requires "${channel}" channel`,
|
|
20298
|
-
path:
|
|
20310
|
+
path: jsonPointer17("encoding", channel),
|
|
20299
20311
|
code: "MISSING_FIELD",
|
|
20300
20312
|
suggestion: `Add encoding.${channel} with a field from your data (${availableColumns}). Example: ${channel}: { field: "${columnList[0] ?? "myField"}", type: "${channel === "value" ? "quantitative" : "nominal"}" }`
|
|
20301
20313
|
});
|
|
@@ -20304,7 +20316,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
20304
20316
|
if (!ch.field || typeof ch.field !== "string") {
|
|
20305
20317
|
errors.push({
|
|
20306
20318
|
message: `Spec error: encoding.${channel} must have a "field" string`,
|
|
20307
|
-
path:
|
|
20319
|
+
path: jsonPointer17("encoding", channel, "field"),
|
|
20308
20320
|
code: "MISSING_FIELD",
|
|
20309
20321
|
suggestion: `Add a field name from your data columns: ${availableColumns}`
|
|
20310
20322
|
});
|
|
@@ -20313,7 +20325,7 @@ function validateSankeySpec(spec, errors) {
|
|
|
20313
20325
|
if (!dataColumns.has(ch.field)) {
|
|
20314
20326
|
errors.push({
|
|
20315
20327
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
20316
|
-
path:
|
|
20328
|
+
path: jsonPointer17("encoding", channel, "field"),
|
|
20317
20329
|
code: "DATA_FIELD_MISSING",
|
|
20318
20330
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(ch.field, columnList)}`
|
|
20319
20331
|
});
|
|
@@ -20343,7 +20355,7 @@ function validateSankeyOverrides(overrides, errors) {
|
|
|
20343
20355
|
if (!breakpoints.includes(breakpoint)) {
|
|
20344
20356
|
errors.push({
|
|
20345
20357
|
message: `Spec error: sankey overrides has unknown breakpoint "${breakpoint}"`,
|
|
20346
|
-
path:
|
|
20358
|
+
path: jsonPointer17("overrides", breakpoint),
|
|
20347
20359
|
code: "INVALID_VALUE",
|
|
20348
20360
|
suggestion: `Valid breakpoints: compact (under 400px), medium (400 to 700px).${didYouMean(breakpoint, [...breakpoints])}`
|
|
20349
20361
|
});
|
|
@@ -20352,7 +20364,7 @@ function validateSankeyOverrides(overrides, errors) {
|
|
|
20352
20364
|
if (!isPlainObject2(block)) {
|
|
20353
20365
|
errors.push({
|
|
20354
20366
|
message: `Spec error: overrides.${breakpoint} must be an object`,
|
|
20355
|
-
path:
|
|
20367
|
+
path: jsonPointer17("overrides", breakpoint),
|
|
20356
20368
|
code: "INVALID_TYPE",
|
|
20357
20369
|
suggestion: `Use overrides.${breakpoint}: { other: 0.05 }`
|
|
20358
20370
|
});
|
|
@@ -20382,7 +20394,7 @@ var OVERRIDE_FIELD_CHECKS = {
|
|
|
20382
20394
|
function validateOverrideBlock(breakpoint, block, errors) {
|
|
20383
20395
|
const fields = SANKEY_OVERRIDE_FIELDS;
|
|
20384
20396
|
for (const [field, value] of Object.entries(block)) {
|
|
20385
|
-
const path =
|
|
20397
|
+
const path = jsonPointer17("overrides", breakpoint, field);
|
|
20386
20398
|
if (!fields.includes(field)) {
|
|
20387
20399
|
errors.push({
|
|
20388
20400
|
message: `Spec error: overrides.${breakpoint} cannot set "${field}"`,
|
|
@@ -20405,7 +20417,7 @@ function validateOverrideBlock(breakpoint, block, errors) {
|
|
|
20405
20417
|
}
|
|
20406
20418
|
|
|
20407
20419
|
// src/compiler/validation/table.ts
|
|
20408
|
-
import { jsonPointer as
|
|
20420
|
+
import { jsonPointer as jsonPointer18 } from "@opendata-ai/openchart-core";
|
|
20409
20421
|
function validateTableSpec(spec, errors) {
|
|
20410
20422
|
if (!Array.isArray(spec.data)) {
|
|
20411
20423
|
errors.push({
|
|
@@ -20454,7 +20466,7 @@ function validateTableSpec(spec, errors) {
|
|
|
20454
20466
|
if (!col || typeof col !== "object") {
|
|
20455
20467
|
errors.push({
|
|
20456
20468
|
message: `Spec error: columns[${i}] must be an object`,
|
|
20457
|
-
path:
|
|
20469
|
+
path: jsonPointer18("columns", i),
|
|
20458
20470
|
code: "INVALID_TYPE",
|
|
20459
20471
|
suggestion: 'Each column entry should be an object, e.g. { key: "fieldName" }'
|
|
20460
20472
|
});
|
|
@@ -20463,7 +20475,7 @@ function validateTableSpec(spec, errors) {
|
|
|
20463
20475
|
if (!col.key || typeof col.key !== "string") {
|
|
20464
20476
|
errors.push({
|
|
20465
20477
|
message: `Spec error: columns[${i}] must have a "key" string`,
|
|
20466
|
-
path:
|
|
20478
|
+
path: jsonPointer18("columns", i, "key"),
|
|
20467
20479
|
code: "MISSING_FIELD",
|
|
20468
20480
|
suggestion: `Add a key referencing a data field. Available columns: ${availableColumns}`
|
|
20469
20481
|
});
|
|
@@ -20472,7 +20484,7 @@ function validateTableSpec(spec, errors) {
|
|
|
20472
20484
|
if (!dataColumns.has(col.key)) {
|
|
20473
20485
|
errors.push({
|
|
20474
20486
|
message: `Spec error: columns[${i}].key "${col.key}" does not exist in data. Available columns: ${availableColumns}`,
|
|
20475
|
-
path:
|
|
20487
|
+
path: jsonPointer18("columns", i, "key"),
|
|
20476
20488
|
code: "DATA_FIELD_MISSING",
|
|
20477
20489
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(col.key, columnList)}`
|
|
20478
20490
|
});
|
|
@@ -20483,7 +20495,7 @@ function validateTableSpec(spec, errors) {
|
|
|
20483
20495
|
if (visuals.length > 1) {
|
|
20484
20496
|
errors.push({
|
|
20485
20497
|
message: `Spec error: columns[${i}] has multiple visual features (${visuals.join(", ")}). Only one is allowed per column.`,
|
|
20486
|
-
path:
|
|
20498
|
+
path: jsonPointer18("columns", i),
|
|
20487
20499
|
code: "INVALID_VALUE",
|
|
20488
20500
|
suggestion: `Keep only one visual feature per column. Remove all but one of: ${visuals.join(", ")}`
|
|
20489
20501
|
});
|
|
@@ -20492,13 +20504,62 @@ function validateTableSpec(spec, errors) {
|
|
|
20492
20504
|
}
|
|
20493
20505
|
|
|
20494
20506
|
// src/compiler/validation/theme-chrome.ts
|
|
20495
|
-
import { isSafeLogoSource, jsonPointer as
|
|
20507
|
+
import { isSafeLogoSource, jsonPointer as jsonPointer20 } from "@opendata-ai/openchart-core";
|
|
20508
|
+
|
|
20509
|
+
// src/compiler/validation/theme-ramps.ts
|
|
20510
|
+
import { jsonPointer as jsonPointer19 } from "@opendata-ai/openchart-core";
|
|
20496
20511
|
function isObject(value) {
|
|
20497
20512
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
20498
20513
|
}
|
|
20514
|
+
function isStop(stop) {
|
|
20515
|
+
return typeof stop === "string" || isObject(stop) && typeof stop.light === "string" && typeof stop.dark === "string";
|
|
20516
|
+
}
|
|
20517
|
+
function validateThemeRamps(theme, themePath, errors) {
|
|
20518
|
+
if (!isObject(theme.colors)) return;
|
|
20519
|
+
for (const kind of ["sequential", "diverging"]) {
|
|
20520
|
+
const ramps = theme.colors[kind];
|
|
20521
|
+
if (ramps === void 0) continue;
|
|
20522
|
+
const kindPath = `${themePath}${jsonPointer19("colors", kind)}`;
|
|
20523
|
+
if (!isObject(ramps)) {
|
|
20524
|
+
errors.push({
|
|
20525
|
+
code: "INVALID_TYPE",
|
|
20526
|
+
path: kindPath,
|
|
20527
|
+
message: `theme.colors.${kind} must be an object mapping ramp names to arrays of stops.`,
|
|
20528
|
+
suggestion: 'Use { name: ["#fff", { light: "#eef", dark: "#113" }] }, or omit it.'
|
|
20529
|
+
});
|
|
20530
|
+
continue;
|
|
20531
|
+
}
|
|
20532
|
+
for (const [name, stops] of Object.entries(ramps)) {
|
|
20533
|
+
const rampPath = `${kindPath}${jsonPointer19(name)}`;
|
|
20534
|
+
if (!Array.isArray(stops)) {
|
|
20535
|
+
errors.push({
|
|
20536
|
+
code: "INVALID_TYPE",
|
|
20537
|
+
path: rampPath,
|
|
20538
|
+
message: `theme.colors.${kind}.${name} must be an array of stops.`,
|
|
20539
|
+
suggestion: "Use an array of color strings or { light, dark } pairs."
|
|
20540
|
+
});
|
|
20541
|
+
continue;
|
|
20542
|
+
}
|
|
20543
|
+
for (const [index, stop] of stops.entries()) {
|
|
20544
|
+
if (isStop(stop)) continue;
|
|
20545
|
+
errors.push({
|
|
20546
|
+
code: "INVALID_VALUE",
|
|
20547
|
+
path: `${rampPath}${jsonPointer19(index)}`,
|
|
20548
|
+
message: `theme.colors.${kind}.${name}[${index}] must be a color string or a { light, dark } pair of strings.`,
|
|
20549
|
+
suggestion: 'Use a color string such as "#336699" or { light: "#eef", dark: "#113" }.'
|
|
20550
|
+
});
|
|
20551
|
+
}
|
|
20552
|
+
}
|
|
20553
|
+
}
|
|
20554
|
+
}
|
|
20555
|
+
|
|
20556
|
+
// src/compiler/validation/theme-chrome.ts
|
|
20557
|
+
function isObject2(value) {
|
|
20558
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
20559
|
+
}
|
|
20499
20560
|
function validateThemeChrome(spec, errors) {
|
|
20500
20561
|
function validate(current, prefix) {
|
|
20501
|
-
if (
|
|
20562
|
+
if (isObject2(current.chrome) && current.chrome.logo !== void 0 && typeof current.chrome.logo !== "boolean")
|
|
20502
20563
|
errors.push({
|
|
20503
20564
|
code: "INVALID_VALUE",
|
|
20504
20565
|
path: `${prefix}/chrome/logo`,
|
|
@@ -20506,15 +20567,16 @@ function validateThemeChrome(spec, errors) {
|
|
|
20506
20567
|
suggestion: "Use true or false, or omit chrome.logo."
|
|
20507
20568
|
});
|
|
20508
20569
|
const theme = current.theme;
|
|
20509
|
-
if (
|
|
20510
|
-
|
|
20570
|
+
if (isObject2(theme)) {
|
|
20571
|
+
validateThemeRamps(theme, `${prefix}/theme`, errors);
|
|
20572
|
+
if (theme.logo !== void 0 && theme.logo !== null && !isObject2(theme.logo))
|
|
20511
20573
|
errors.push({
|
|
20512
20574
|
code: "INVALID_VALUE",
|
|
20513
20575
|
path: `${prefix}/theme/logo`,
|
|
20514
20576
|
message: "theme.logo must be an object or null.",
|
|
20515
20577
|
suggestion: "Use a logo object, null, or omit theme.logo."
|
|
20516
20578
|
});
|
|
20517
|
-
if (
|
|
20579
|
+
if (isObject2(theme.logo)) {
|
|
20518
20580
|
if (typeof theme.logo.src !== "string" || !isSafeLogoSource(theme.logo.src))
|
|
20519
20581
|
errors.push({
|
|
20520
20582
|
code: "INVALID_VALUE",
|
|
@@ -20554,39 +20616,39 @@ function validateThemeChrome(spec, errors) {
|
|
|
20554
20616
|
suggestion: "Use a string for alt, or omit it."
|
|
20555
20617
|
});
|
|
20556
20618
|
}
|
|
20557
|
-
if (
|
|
20619
|
+
if (isObject2(theme.chrome))
|
|
20558
20620
|
for (const [key, value] of Object.entries(theme.chrome)) {
|
|
20559
|
-
if (!
|
|
20621
|
+
if (!isObject2(value)) continue;
|
|
20560
20622
|
for (const field of ["prefix", "fontFamily"]) {
|
|
20561
20623
|
if (value[field] !== void 0 && typeof value[field] !== "string")
|
|
20562
20624
|
errors.push({
|
|
20563
20625
|
code: "INVALID_VALUE",
|
|
20564
|
-
path: `${prefix}${
|
|
20626
|
+
path: `${prefix}${jsonPointer20("theme", "chrome", key, field)}`,
|
|
20565
20627
|
message: `theme.chrome.${key}.${field} must be a string.`,
|
|
20566
20628
|
suggestion: `Use a string for ${field}, or omit it.`
|
|
20567
20629
|
});
|
|
20568
20630
|
}
|
|
20569
|
-
if (value.
|
|
20570
|
-
if (value.
|
|
20631
|
+
if (value.align === void 0) continue;
|
|
20632
|
+
if (value.align === "left" || value.align === "center" || value.align === "right")
|
|
20571
20633
|
continue;
|
|
20572
20634
|
errors.push({
|
|
20573
20635
|
code: "INVALID_VALUE",
|
|
20574
|
-
path: `${prefix}${
|
|
20575
|
-
suggestion: "Use left, center or right, or omit
|
|
20576
|
-
message: `theme.chrome.${key}.
|
|
20636
|
+
path: `${prefix}${jsonPointer20("theme", "chrome", key, "align")}`,
|
|
20637
|
+
suggestion: "Use left, center or right, or omit align.",
|
|
20638
|
+
message: `theme.chrome.${key}.align must be left, center or right.`
|
|
20577
20639
|
});
|
|
20578
20640
|
}
|
|
20579
20641
|
}
|
|
20580
20642
|
if (Array.isArray(current.layer))
|
|
20581
20643
|
for (const [index, child] of current.layer.entries()) {
|
|
20582
|
-
if (
|
|
20644
|
+
if (isObject2(child)) validate(child, `${prefix}${jsonPointer20("layer", index)}`);
|
|
20583
20645
|
}
|
|
20584
20646
|
}
|
|
20585
20647
|
validate(spec, "");
|
|
20586
20648
|
}
|
|
20587
20649
|
|
|
20588
20650
|
// src/compiler/validation/tilemap.ts
|
|
20589
|
-
import { jsonPointer as
|
|
20651
|
+
import { jsonPointer as jsonPointer21 } from "@opendata-ai/openchart-core";
|
|
20590
20652
|
function validateTileMapSpec(spec, errors) {
|
|
20591
20653
|
validateTileMapTime(spec, errors);
|
|
20592
20654
|
if (!spec.data || typeof spec.data !== "object") {
|
|
@@ -20645,7 +20707,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
20645
20707
|
if (!ch || typeof ch !== "object") {
|
|
20646
20708
|
errors.push({
|
|
20647
20709
|
message: `Spec error: tilemap encoding requires "${channel}" channel`,
|
|
20648
|
-
path:
|
|
20710
|
+
path: jsonPointer21("encoding", channel),
|
|
20649
20711
|
code: "MISSING_FIELD",
|
|
20650
20712
|
suggestion: `Add encoding.${channel} with a field from your data (${availableColumns}). Example: ${channel}: { field: "${columnList[0] ?? "myField"}", type: "${channel === "value" ? "quantitative" : "nominal"}" }`
|
|
20651
20713
|
});
|
|
@@ -20654,7 +20716,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
20654
20716
|
if (!ch.field || typeof ch.field !== "string") {
|
|
20655
20717
|
errors.push({
|
|
20656
20718
|
message: `Spec error: encoding.${channel} must have a "field" string`,
|
|
20657
|
-
path:
|
|
20719
|
+
path: jsonPointer21("encoding", channel, "field"),
|
|
20658
20720
|
code: "MISSING_FIELD",
|
|
20659
20721
|
suggestion: `Add a field name from your data columns: ${availableColumns}`
|
|
20660
20722
|
});
|
|
@@ -20663,7 +20725,7 @@ function validateTileMapSpec(spec, errors) {
|
|
|
20663
20725
|
if (!dataColumns.has(ch.field)) {
|
|
20664
20726
|
errors.push({
|
|
20665
20727
|
message: `Spec error: encoding.${channel}.field "${ch.field}" does not exist in data. Available columns: ${availableColumns}`,
|
|
20666
|
-
path:
|
|
20728
|
+
path: jsonPointer21("encoding", channel, "field"),
|
|
20667
20729
|
code: "DATA_FIELD_MISSING",
|
|
20668
20730
|
suggestion: `Use one of the available data columns: ${availableColumns}.${didYouMean(ch.field, columnList)}`
|
|
20669
20731
|
});
|
|
@@ -20700,7 +20762,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
20700
20762
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
20701
20763
|
errors.push({
|
|
20702
20764
|
code: "INVALID_VALUE",
|
|
20703
|
-
path: `${prefix}${
|
|
20765
|
+
path: `${prefix}${jsonPointer22("annotations", index, field)}`,
|
|
20704
20766
|
message: `${field} must be a positive finite number`,
|
|
20705
20767
|
suggestion: field === "maxWidth" ? "Use null for unlimited width." : "Omit subtitleFontSize to use the default ratio."
|
|
20706
20768
|
});
|
|
@@ -20708,7 +20770,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
20708
20770
|
if (annotation?.labelPlacement !== void 0 && !["auto", "start", "end", "outside"].includes(annotation.labelPlacement))
|
|
20709
20771
|
errors.push({
|
|
20710
20772
|
code: "INVALID_VALUE",
|
|
20711
|
-
path: `${prefix}${
|
|
20773
|
+
path: `${prefix}${jsonPointer22("annotations", index, "labelPlacement")}`,
|
|
20712
20774
|
message: "Unknown reference label placement",
|
|
20713
20775
|
suggestion: "Use auto, start, end or outside."
|
|
20714
20776
|
});
|
|
@@ -20716,7 +20778,7 @@ function validateAnnotationLayout(spec, errors, prefix = "") {
|
|
|
20716
20778
|
if (bend !== void 0 && (typeof bend !== "number" || !Number.isFinite(bend) || bend < -1 || bend > 1)) {
|
|
20717
20779
|
errors.push({
|
|
20718
20780
|
code: "INVALID_VALUE",
|
|
20719
|
-
path: `${prefix}${
|
|
20781
|
+
path: `${prefix}${jsonPointer22("annotations", index, "connector", "bend")}`,
|
|
20720
20782
|
message: "Connector bend must be a finite number between -1 and 1",
|
|
20721
20783
|
suggestion: "Omit bend for the automatic curve, or use a number in [-1, 1]."
|
|
20722
20784
|
});
|
|
@@ -20767,7 +20829,7 @@ function validateCommonSpecFields(obj, errors) {
|
|
|
20767
20829
|
if (value === void 0) continue;
|
|
20768
20830
|
if (typeof value !== "string" && (!value || typeof value !== "object" || Array.isArray(value) || typeof value.text !== "string")) {
|
|
20769
20831
|
errors.push({
|
|
20770
|
-
path:
|
|
20832
|
+
path: jsonPointer22("chrome", key),
|
|
20771
20833
|
code: "INVALID_TYPE",
|
|
20772
20834
|
message: `${key} must be text or an object with a string text property.`,
|
|
20773
20835
|
suggestion: "Preserve authored styling in the object and provide text as a string."
|
|
@@ -20810,7 +20872,7 @@ function validateSpecShape(spec) {
|
|
|
20810
20872
|
errors: [
|
|
20811
20873
|
{
|
|
20812
20874
|
message: `Spec error: "${key}" composition is not supported`,
|
|
20813
|
-
path:
|
|
20875
|
+
path: jsonPointer22(key),
|
|
20814
20876
|
code: "INVALID_VALUE",
|
|
20815
20877
|
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 }"
|
|
20816
20878
|
}
|
|
@@ -32779,7 +32841,7 @@ function sortData(data, sort) {
|
|
|
32779
32841
|
}
|
|
32780
32842
|
|
|
32781
32843
|
// src/tables/sparkline.ts
|
|
32782
|
-
import { formatRawNumber as formatRawNumber20 } from "@opendata-ai/openchart-core";
|
|
32844
|
+
import { buildD3Formatter as buildD3Formatter6, formatRawNumber as formatRawNumber20 } from "@opendata-ai/openchart-core";
|
|
32783
32845
|
function extractSparklineValues(row, columnKey, config) {
|
|
32784
32846
|
const field = config.valuesField ?? columnKey;
|
|
32785
32847
|
const raw = row[field];
|
|
@@ -32820,7 +32882,8 @@ function computeSparkline(values, config, theme, _darkMode, domain) {
|
|
|
32820
32882
|
const normalize = (v) => range === 0 ? 0.5 : Math.max(0, Math.min(1, (v - min4) / range));
|
|
32821
32883
|
const startValue = values[0];
|
|
32822
32884
|
const endValue = values[values.length - 1];
|
|
32823
|
-
const
|
|
32885
|
+
const formatThousands = buildD3Formatter6(",.0f", theme.locale) ?? String;
|
|
32886
|
+
const formatEndValue = (value) => Math.abs(value) >= 1e3 ? formatThousands(value) : formatRawNumber20(value.toFixed(Math.abs(value) >= 100 ? 0 : 1), theme.locale);
|
|
32824
32887
|
const formattedStartValue = formatEndValue(startValue);
|
|
32825
32888
|
const formattedEndValue = formatEndValue(endValue);
|
|
32826
32889
|
if (type === "line") {
|
|
@@ -34195,7 +34258,7 @@ var lineGeometry = (model, layout, frame) => {
|
|
|
34195
34258
|
};
|
|
34196
34259
|
|
|
34197
34260
|
// src/race/layout-table.ts
|
|
34198
|
-
import { buildD3Formatter as
|
|
34261
|
+
import { buildD3Formatter as buildD3Formatter7 } from "@opendata-ai/openchart-core";
|
|
34199
34262
|
var DEFAULT_COLUMNS2 = ["rank", "change", "name", "bar", "value", "share"];
|
|
34200
34263
|
var LABELS = {
|
|
34201
34264
|
rank: "Rank",
|
|
@@ -34209,7 +34272,7 @@ var COMPACT_WIDTH4 = 520;
|
|
|
34209
34272
|
var COMPACT_CHANGE = "\u2195";
|
|
34210
34273
|
var CHIP_WIDTH_AND_GAP = 14;
|
|
34211
34274
|
var EMPTY = "\u2014";
|
|
34212
|
-
var formatShare = (locale) =>
|
|
34275
|
+
var formatShare = (locale) => buildD3Formatter7(".1%", locale) ?? String;
|
|
34213
34276
|
var VALUE_WIDTH_SAMPLES = [0.25, 0.5, 0.75, Math.SQRT1_2];
|
|
34214
34277
|
function frameShareBase(values, period, fraction) {
|
|
34215
34278
|
let total = 0;
|
|
@@ -35814,7 +35877,7 @@ function recommendCompositions(data, question, roles) {
|
|
|
35814
35877
|
|
|
35815
35878
|
// src/geo/reader-index.ts
|
|
35816
35879
|
import {
|
|
35817
|
-
buildD3Formatter as
|
|
35880
|
+
buildD3Formatter as buildD3Formatter8,
|
|
35818
35881
|
computeFieldFormatContext as computeFieldFormatContext12,
|
|
35819
35882
|
formatRawNumber as formatRawNumber21
|
|
35820
35883
|
} from "@opendata-ai/openchart-core";
|
|
@@ -35932,7 +35995,7 @@ function buildGeoReaderIndex(spec, layout) {
|
|
|
35932
35995
|
(field) => {
|
|
35933
35996
|
const raw = datum?.[field.field];
|
|
35934
35997
|
const numeric = finiteNumber(raw);
|
|
35935
|
-
const format = field.format ?
|
|
35998
|
+
const format = field.format ? buildD3Formatter8(field.format, layout.theme.locale) : void 0;
|
|
35936
35999
|
return {
|
|
35937
36000
|
label: field.title ?? spec.fields?.[field.field]?.label ?? field.field,
|
|
35938
36001
|
value: raw == null ? "No data" : field.type === "quantitative" ? numeric === void 0 ? "No data" : format ? format(numeric) : formatRawNumber21(numeric, layout.theme.locale) : String(raw)
|