ggaction 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/README.md +22 -2
- package/knowledge/action-cards.json +1 -1
- package/knowledge/intent-taxonomy.json +1 -1
- package/knowledge/mcp-resources.json +1 -1
- package/knowledge/task-packet.schema.json +1 -1
- package/knowledge/task-resolver.js +1 -1
- package/package.json +33 -6
- package/src/BasicChartProgram.js +3 -1
- package/src/ChartProgram.js +2 -0
- package/src/accessibility.js +157 -0
- package/src/actions/boxPlots/components.js +6 -8
- package/src/actions/boxPlots/create.js +4 -5
- package/src/actions/boxPlots/edit.js +3 -4
- package/src/actions/boxPlots/materialize.js +1 -1
- package/src/actions/canvas/actions.js +3 -3
- package/src/actions/canvas/fitting.js +1 -1
- package/src/actions/categoryOrder/index.js +6 -8
- package/src/actions/charts/area.js +1 -1
- package/src/actions/charts/bar.js +1 -1
- package/src/actions/charts/beeswarm.js +1 -1
- package/src/actions/charts/density.js +1 -1
- package/src/actions/charts/ecdf.js +2 -2
- package/src/actions/charts/endpoints.js +4 -4
- package/src/actions/charts/heatmap.js +1 -1
- package/src/actions/charts/histogram.js +1 -1
- package/src/actions/charts/horizon.js +1 -1
- package/src/actions/charts/interval-regression.js +2 -2
- package/src/actions/charts/line.js +1 -1
- package/src/actions/charts/parallel.js +1 -1
- package/src/actions/charts/pie.js +1 -1
- package/src/actions/charts/polar.js +2 -2
- package/src/actions/charts/radar.js +1 -1
- package/src/actions/charts/radial.js +2 -2
- package/src/actions/charts/raincloud.js +2 -2
- package/src/actions/charts/rug-strip.js +2 -2
- package/src/actions/charts/scatter.js +1 -1
- package/src/actions/composition/actions.js +20 -24
- package/src/actions/coordinates/actions.js +1 -1
- package/src/actions/coordinates/edit.js +1 -1
- package/src/actions/data/basicBin2d.js +4 -5
- package/src/actions/data/bin.js +2 -2
- package/src/actions/data/bin2d.js +6 -8
- package/src/actions/data/bin2dMaterialize.js +4 -5
- package/src/actions/data/box.js +4 -4
- package/src/actions/data/complete.js +2 -2
- package/src/actions/data/computed.js +2 -2
- package/src/actions/data/create.js +5 -12
- package/src/actions/data/density.js +3 -3
- package/src/actions/data/derived.js +10 -14
- package/src/actions/data/ecdf.js +2 -2
- package/src/actions/data/edit.js +35 -23
- package/src/actions/data/filter.js +14 -20
- package/src/actions/data/fold.js +2 -2
- package/src/actions/data/gradientProfile.js +2 -2
- package/src/actions/data/horizon.js +2 -2
- package/src/actions/data/impute.js +2 -2
- package/src/actions/data/index.js +55 -54
- package/src/actions/data/interval.js +2 -2
- package/src/actions/data/intervalEdit.js +26 -18
- package/src/actions/data/normalize.js +2 -2
- package/src/actions/data/regression.js +5 -6
- package/src/actions/data/revise.js +48 -0
- package/src/actions/data/revisionBindings.js +13 -33
- package/src/actions/data/stack.js +2 -2
- package/src/actions/data/summary.js +2 -2
- package/src/actions/data/timeUnit.js +2 -2
- package/src/actions/data/window.js +2 -2
- package/src/actions/encodings/angle.js +1 -1
- package/src/actions/encodings/appearance.js +4 -4
- package/src/actions/encodings/barWidth.js +1 -1
- package/src/actions/encodings/channels.js +2 -2
- package/src/actions/encodings/color/index.js +1 -1
- package/src/actions/encodings/density.js +2 -2
- package/src/actions/encodings/histogram.js +1 -1
- package/src/actions/encodings/horizon.js +6 -8
- package/src/actions/encodings/offset.js +2 -2
- package/src/actions/encodings/parallel.js +4 -5
- package/src/actions/encodings/pathOrder.js +6 -11
- package/src/actions/encodings/position/index.js +4 -4
- package/src/actions/encodings/ranged.js +5 -5
- package/src/actions/encodings/remove.js +4 -5
- package/src/actions/encodings/ruleAppearance.js +1 -1
- package/src/actions/encodings/seriesLayout.js +1 -1
- package/src/actions/encodings/stroke.js +1 -1
- package/src/actions/encodings/strokeDash.js +2 -2
- package/src/actions/encodings/text.js +1 -1
- package/src/actions/errorBands/create.js +11 -17
- package/src/actions/errorBands/edit.js +13 -131
- package/src/actions/errorBars/create.js +8 -13
- package/src/actions/errorBars/edit.js +10 -121
- package/src/actions/facets/actions.js +30 -16
- package/src/actions/facets/derive.js +8 -2
- package/src/actions/facets/guides.js +4 -5
- package/src/actions/facets/replay.js +4 -5
- package/src/actions/gradientPlots/components.js +5 -6
- package/src/actions/gradientPlots/create.js +4 -5
- package/src/actions/gradientPlots/edit.js +4 -5
- package/src/actions/gradientPlots/materialize.js +2 -2
- package/src/actions/gradientPlots/rebind.js +4 -5
- package/src/actions/guides/axes/axes.js +23 -4
- package/src/actions/guides/axes/axis.js +2 -2
- package/src/actions/guides/axes/edit.js +2 -2
- package/src/actions/guides/axes/labels.js +9 -9
- package/src/actions/guides/axes/lines.js +9 -7
- package/src/actions/guides/axes/parallel/lifecycle.js +13 -13
- package/src/actions/guides/axes/parallel.js +5 -5
- package/src/actions/guides/axes/remove.js +4 -4
- package/src/actions/guides/axes/tickGroups.js +4 -4
- package/src/actions/guides/axes/ticks.js +13 -4
- package/src/actions/guides/axes/titles.js +10 -10
- package/src/actions/guides/grids/grid.js +18 -29
- package/src/actions/guides/guides.js +1 -1
- package/src/actions/guides/legends/blocks.js +1 -1
- package/src/actions/guides/legends/categorical/actions.js +4 -4
- package/src/actions/guides/legends/categorical/components.js +38 -33
- package/src/actions/guides/legends/categorical/layout.js +1 -1
- package/src/actions/guides/legends/categorical/symbols.js +27 -30
- package/src/actions/guides/legends/continuous/common.js +46 -8
- package/src/actions/guides/legends/continuous/gradient.js +89 -155
- package/src/actions/guides/legends/continuous/interval.js +13 -13
- package/src/actions/guides/legends/continuous/opacity.js +30 -79
- package/src/actions/guides/legends/continuous/stroke.js +22 -322
- package/src/actions/guides/legends/edit.js +1 -1
- package/src/actions/guides/legends/focused.js +5 -5
- package/src/actions/guides/legends/lane.js +6 -6
- package/src/actions/guides/legends/remove.js +4 -5
- package/src/actions/guides/legends/size.js +21 -82
- package/src/actions/guides/legends/strokeWidth.js +17 -77
- package/src/actions/guides/polar/axes/facade.js +4 -4
- package/src/actions/guides/polar/axes/labels.js +5 -5
- package/src/actions/guides/polar/axes/lines.js +9 -15
- package/src/actions/guides/polar/axes/ticks.js +9 -15
- package/src/actions/guides/polar/axes/titles.js +5 -5
- package/src/actions/guides/polar/grids.js +11 -13
- package/src/actions/index.js +2 -0
- package/src/actions/intervals/revision.js +126 -0
- package/src/actions/marks/arc/actions.js +3 -3
- package/src/actions/marks/area/actions.js +4 -4
- package/src/actions/marks/bar/create.js +1 -1
- package/src/actions/marks/bar/edit.js +1 -1
- package/src/actions/marks/bar/materialize.js +12 -38
- package/src/actions/marks/line/actions.js +3 -3
- package/src/actions/marks/point/create.js +1 -1
- package/src/actions/marks/point/edit.js +1 -1
- package/src/actions/marks/point/jitter.js +6 -8
- package/src/actions/marks/point/materialize.js +16 -24
- package/src/actions/marks/point/packing.js +6 -8
- package/src/actions/marks/rect/actions.js +3 -3
- package/src/actions/marks/references.js +8 -10
- package/src/actions/marks/remove.js +5 -49
- package/src/actions/marks/rule/actions.js +4 -4
- package/src/actions/marks/text/actions.js +5 -5
- package/src/actions/marks/text/layout.js +12 -20
- package/src/actions/marks/text/removal.js +1 -1
- package/src/actions/marks/text/selection.js +4 -5
- package/src/actions/marks/tick/actions.js +3 -3
- package/src/actions/primitives/createGraphics.js +5 -4
- package/src/actions/primitives/editGraphics.js +5 -4
- package/src/actions/primitives/graphicProperties.js +6 -0
- package/src/actions/primitives/semantic.js +10 -3
- package/src/actions/primitives/semanticAction.js +7 -4
- package/src/actions/primitives/semanticValidation/dataset.js +2 -4
- package/src/actions/regression/components.js +10 -14
- package/src/actions/regression/create.js +3 -4
- package/src/actions/regression/edit.js +3 -4
- package/src/actions/resources/remove.js +12 -11
- package/src/actions/scales/create.js +1 -1
- package/src/actions/scales/edit.js +1 -1
- package/src/actions/scales/materialize.js +1 -1
- package/src/actions/scales/offset.js +2 -2
- package/src/actions/scales/parallel.js +1 -1
- package/src/actions/scales/quantitativeColor.js +4 -5
- package/src/actions/selection/actions.js +25 -36
- package/src/actions/textMetrics/index.js +56 -0
- package/src/actions/theme/actions.js +2 -2
- package/src/actions/theme/reconcile.js +65 -121
- package/src/actions/titles/actions.js +8 -8
- package/src/actions/titles/resolve.js +3 -3
- package/src/actions/violinPlots/create.js +1 -1
- package/src/actions/violinPlots/edit.js +1 -1
- package/src/core/action.js +107 -35
- package/src/core/diagnostics.js +16 -0
- package/src/core/extensionRegistry.js +27 -0
- package/src/core/font.js +18 -0
- package/src/core/identifiers.js +5 -4
- package/src/core/immutable.js +10 -3
- package/src/core/optionRequirements.js +8 -0
- package/src/core/programState.js +1 -1
- package/src/core/resourceReferences.js +15 -6
- package/src/core/textMetricProfile.js +28 -0
- package/src/core/textMetrics.js +24 -3
- package/src/core/validation.js +22 -10
- package/src/diagnostics.js +1 -0
- package/src/grammar/impute.js +3 -2
- package/src/grammar/scales/types.js +8 -0
- package/src/grammar/schemas/graphicBounds.js +11 -11
- package/src/layout/labels.js +11 -10
- package/src/layout/legend.js +4 -4
- package/src/layout/legendItems.js +6 -6
- package/src/layout/text.js +10 -9
- package/src/layout/title.js +9 -9
- package/src/materialization/facetGuides/placement.js +1 -1
- package/src/materialization/facetGuides/preparation.js +1 -1
- package/src/materialization/facetHeaders.js +11 -10
- package/src/materialization/guides/layout.js +3 -3
- package/src/materialization/scaleGuideDependencies.js +10 -0
- package/src/materialization/selection/items/common.js +1 -1
- package/src/materialization/text.js +2 -2
- package/src/materialization/typography.js +31 -0
- package/src/mcp/cli.js +5 -3
- package/src/persistence/codec.js +65 -0
- package/src/persistence/validation.js +185 -0
- package/src/persistence.js +74 -0
- package/src/renderers/canvas/index.js +5 -4
- package/src/renderers/nativeBackend.js +10 -0
- package/src/renderers/options.js +13 -0
- package/src/renderers/pdf.js +25 -54
- package/src/renderers/png.js +22 -17
- package/src/renderers/svg.js +10 -14
- package/src/renderers/text.js +1 -11
- package/src/selectors/coordinates.js +3 -1
- package/src/selectors/datasets.js +8 -6
- package/src/selectors/layers.js +6 -4
- package/src/selectors/markOwners.js +46 -0
- package/src/selectors/scales.js +6 -4
- package/src/theme/defaults.js +2 -1
- package/src/version.js +2 -0
- package/types/accessibility.d.ts +37 -0
- package/types/basic.d.ts +4 -2
- package/types/diagnostics.d.ts +15 -0
- package/types/index.d.ts +5 -0
- package/types/pdf.d.ts +9 -0
- package/types/persistence.d.ts +7 -0
- package/types/png.d.ts +9 -0
- package/types/program.d.ts +34 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ChartProgram } from "./ChartProgram.js";
|
|
2
|
+
import { BasicChartProgram } from "./BasicChartProgram.js";
|
|
3
|
+
import { cloneAndFreeze } from "./core/immutable.js";
|
|
4
|
+
import { hasRegisteredExtension, isBuiltinProgramClass } from "./core/extensionRegistry.js";
|
|
5
|
+
import { packageVersion } from "./version.js";
|
|
6
|
+
import { decodeValue, encodeValue, invalidSnapshot } from "./persistence/codec.js";
|
|
7
|
+
import { exactKeys, requireObject, STATE_KEYS, validateGraphic, validateProgramState, validateTrace } from "./persistence/validation.js";
|
|
8
|
+
|
|
9
|
+
function canonicalState(program, extensions, path = "payload") {
|
|
10
|
+
if (!(program instanceof ChartProgram || program instanceof BasicChartProgram) || !isBuiltinProgramClass(program.constructor)) {
|
|
11
|
+
throw invalidSnapshot(`Cannot persist an unregistered program class at ${path}.`, path);
|
|
12
|
+
}
|
|
13
|
+
if (program.actionStack.length !== 0) throw invalidSnapshot("Cannot persist an open actionStack.", `${path}.actionStack`);
|
|
14
|
+
const state = Object.fromEntries(STATE_KEYS.map(key => [key, program[key]]));
|
|
15
|
+
state.children = Object.fromEntries(Object.entries(program.children).map(([id, child]) => [id, canonicalState(child, extensions, `${path}.children.${id}`)]));
|
|
16
|
+
validateTrace(program.trace, program.constructor, extensions, `${path}.trace`);
|
|
17
|
+
validateProgramState(program, path);
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function envelope(kind, payload, extensions = []) {
|
|
22
|
+
return JSON.stringify({ schemaVersion: 1, kind, packageVersion, extensions, payload: encodeValue(payload) });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function readEnvelope(text, kind) {
|
|
26
|
+
if (typeof text !== "string") throw invalidSnapshot("Snapshot must be a JSON string.", "snapshot");
|
|
27
|
+
let value;
|
|
28
|
+
try { value = JSON.parse(text); } catch { throw invalidSnapshot("Snapshot must be valid JSON.", "snapshot"); }
|
|
29
|
+
exactKeys(value, ["schemaVersion", "kind", "packageVersion", "extensions", "payload"], "snapshot");
|
|
30
|
+
if (value.schemaVersion !== 1 || value.kind !== kind) throw invalidSnapshot(`Unsupported snapshot schema or kind; expected schema 1 ${kind}.`, "snapshot");
|
|
31
|
+
if (typeof value.packageVersion !== "string" || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(value.packageVersion)) throw invalidSnapshot("Invalid snapshot packageVersion.", "snapshot.packageVersion");
|
|
32
|
+
if (!Array.isArray(value.extensions) || new Set(value.extensions).size !== value.extensions.length ||
|
|
33
|
+
value.extensions.some(name => typeof name !== "string" || !hasRegisteredExtension(name)) || (kind === "graphic" && value.extensions.length)) {
|
|
34
|
+
throw invalidSnapshot("Snapshot requires unknown, duplicate, or inapplicable extensions.", "snapshot.extensions");
|
|
35
|
+
}
|
|
36
|
+
return { ...value, payload: decodeValue(value.payload) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function restoreState(state, extensions, path = "payload") {
|
|
40
|
+
exactKeys(state, STATE_KEYS, path);
|
|
41
|
+
if (!Array.isArray(state.actionStack) || state.actionStack.length) throw invalidSnapshot("Snapshot actionStack must be empty.", `${path}.actionStack`);
|
|
42
|
+
requireObject(state.children, `${path}.children`);
|
|
43
|
+
validateTrace(state.trace, ChartProgram, extensions, `${path}.trace`);
|
|
44
|
+
const children = Object.fromEntries(Object.entries(state.children).map(([id, child]) => [id, restoreState(child, extensions, `${path}.children.${id}`)]));
|
|
45
|
+
const program = new ChartProgram({ ...state, children });
|
|
46
|
+
validateProgramState(program, path);
|
|
47
|
+
return program;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function serializeProgram(program) {
|
|
51
|
+
const extensions = new Set();
|
|
52
|
+
return envelope("editable", canonicalState(program, extensions), [...extensions].sort());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function deserializeProgram(text) {
|
|
56
|
+
const stored = readEnvelope(text, "editable");
|
|
57
|
+
const extensions = new Set();
|
|
58
|
+
const program = restoreState(stored.payload, extensions);
|
|
59
|
+
if (extensions.size !== stored.extensions.length || stored.extensions.some(name => !extensions.has(name))) {
|
|
60
|
+
throw invalidSnapshot("Snapshot extensions must exactly match its action traces.", "snapshot.extensions");
|
|
61
|
+
}
|
|
62
|
+
return program;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function serializeGraphic(program) {
|
|
66
|
+
validateGraphic(program?.graphicSpec);
|
|
67
|
+
return envelope("graphic", program.graphicSpec);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function deserializeGraphic(text) {
|
|
71
|
+
const { payload } = readEnvelope(text, "graphic");
|
|
72
|
+
validateGraphic(payload);
|
|
73
|
+
return cloneAndFreeze({ graphicSpec: payload });
|
|
74
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { annotateError } from "../../core/diagnostics.js";
|
|
1
2
|
import { drawCircleGraphic } from "./circle.js";
|
|
2
3
|
import { drawLineGraphic } from "./line.js";
|
|
3
4
|
import { drawPathGraphic } from "./path.js";
|
|
@@ -208,14 +209,14 @@ export function render(program, context, { pixelRatio = 1 } = {}) {
|
|
|
208
209
|
physicalWidth > MAX_RASTER_DIMENSION ||
|
|
209
210
|
physicalHeight > MAX_RASTER_DIMENSION
|
|
210
211
|
) {
|
|
211
|
-
throw new RangeError(
|
|
212
|
+
throw annotateError(new RangeError(
|
|
212
213
|
`render physical Canvas dimensions must not exceed ${MAX_RASTER_DIMENSION}.`
|
|
213
|
-
);
|
|
214
|
+
), { code: "resource-limit", operation: "render", optionPath: "physicalDimensions", limit: MAX_RASTER_DIMENSION, actual: Math.max(physicalWidth, physicalHeight) });
|
|
214
215
|
}
|
|
215
216
|
if (physicalWidth * physicalHeight > MAX_RASTER_PIXELS) {
|
|
216
|
-
throw new RangeError(
|
|
217
|
+
throw annotateError(new RangeError(
|
|
217
218
|
`render physical Canvas pixel count must not exceed ${MAX_RASTER_PIXELS}.`
|
|
218
|
-
);
|
|
219
|
+
), { code: "resource-limit", operation: "render", optionPath: "physicalPixels", limit: MAX_RASTER_PIXELS, actual: physicalWidth * physicalHeight });
|
|
219
220
|
}
|
|
220
221
|
preflightCanvasGraphicSpec(target, pixelRatio);
|
|
221
222
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export async function loadNativeBackend() {
|
|
2
|
+
try {
|
|
3
|
+
return await import("@napi-rs/canvas");
|
|
4
|
+
} catch (error) {
|
|
5
|
+
if (error.code === "ERR_MODULE_NOT_FOUND" && error.message.includes("@napi-rs/canvas")) {
|
|
6
|
+
throw new Error("PNG/PDF output requires @napi-rs/canvas. Install it with: npm install ggaction @napi-rs/canvas", { cause: error });
|
|
7
|
+
}
|
|
8
|
+
throw error;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { annotateError } from "../core/diagnostics.js";
|
|
2
|
+
import { isPlainObject } from "../core/immutable.js";
|
|
3
|
+
|
|
4
|
+
export function validateRendererOptions(options, allowed, label) {
|
|
5
|
+
if (!isPlainObject(options)) {
|
|
6
|
+
throw annotateError(new TypeError(`${label} must be a plain object.`), { code: "invalid-option" });
|
|
7
|
+
}
|
|
8
|
+
for (const key of Object.keys(options)) {
|
|
9
|
+
if (!allowed.has(key)) {
|
|
10
|
+
throw annotateError(new TypeError(`${label} does not support option "${key}".`), { code: "invalid-option", optionPath: key });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/renderers/pdf.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { loadNativeBackend } from "./nativeBackend.js";
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
drawResolvedGraphicSpec,
|
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
resolveGraphicRenderTarget
|
|
10
10
|
} from "./canvas/index.js";
|
|
11
11
|
import { preflightCanvasGraphicSpec } from "./canvas/native.js";
|
|
12
|
+
import { validateRendererOptions } from "./options.js";
|
|
12
13
|
|
|
13
14
|
const PDF_OPTIONS = new Set(["output", "metadata"]);
|
|
15
|
+
const BUFFER_OPTIONS = new Set(["metadata"]);
|
|
14
16
|
const PDF_METADATA = new Set([
|
|
15
17
|
"title",
|
|
16
18
|
"author",
|
|
@@ -19,30 +21,9 @@ const PDF_METADATA = new Set([
|
|
|
19
21
|
]);
|
|
20
22
|
const MAX_PDF_DIMENSION = 16_777_216;
|
|
21
23
|
|
|
22
|
-
function requirePlainObject(value, label) {
|
|
23
|
-
if (
|
|
24
|
-
value === null ||
|
|
25
|
-
typeof value !== "object" ||
|
|
26
|
-
Array.isArray(value) ||
|
|
27
|
-
Object.getPrototypeOf(value) !== Object.prototype
|
|
28
|
-
) {
|
|
29
|
-
throw new TypeError(`${label} must be a plain object.`);
|
|
30
|
-
}
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function requireClosedKeys(value, allowed, label) {
|
|
35
|
-
for (const key of Object.keys(value)) {
|
|
36
|
-
if (!allowed.has(key)) {
|
|
37
|
-
throw new TypeError(`${label} does not support option "${key}".`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
24
|
function requireMetadata(metadata) {
|
|
43
25
|
if (metadata === undefined) return undefined;
|
|
44
|
-
|
|
45
|
-
requireClosedKeys(metadata, PDF_METADATA, "renderToPDF metadata");
|
|
26
|
+
validateRendererOptions(metadata, PDF_METADATA, "renderToPDF metadata");
|
|
46
27
|
|
|
47
28
|
const resolved = {};
|
|
48
29
|
for (const key of ["title", "author", "subject"]) {
|
|
@@ -75,26 +56,6 @@ function requireMetadata(metadata) {
|
|
|
75
56
|
return resolved;
|
|
76
57
|
}
|
|
77
58
|
|
|
78
|
-
function requirePDFOptions(options) {
|
|
79
|
-
requirePlainObject(options, "renderToPDF options");
|
|
80
|
-
requireClosedKeys(options, PDF_OPTIONS, "renderToPDF");
|
|
81
|
-
if (typeof options.output !== "string" || options.output.length === 0) {
|
|
82
|
-
throw new TypeError("renderToPDF requires a non-empty output path.");
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
output: resolve(options.output),
|
|
86
|
-
metadata: requireMetadata(options.metadata)
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function renderPDFBuffer(target, metadata) {
|
|
91
|
-
const document = new PDFDocument(metadata);
|
|
92
|
-
const context = document.beginPage(target.width, target.height);
|
|
93
|
-
drawResolvedGraphicSpec(target, context);
|
|
94
|
-
document.endPage();
|
|
95
|
-
return document.close();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
59
|
function requirePDFPageDimensions(target) {
|
|
99
60
|
if (![target.width, target.height].every(value =>
|
|
100
61
|
Number.isSafeInteger(value) && value > 0 && value <= MAX_PDF_DIMENSION
|
|
@@ -105,22 +66,32 @@ function requirePDFPageDimensions(target) {
|
|
|
105
66
|
}
|
|
106
67
|
}
|
|
107
68
|
|
|
108
|
-
export async function
|
|
109
|
-
|
|
69
|
+
export async function renderToPDFBuffer(program, options = {}) {
|
|
70
|
+
validateRendererOptions(options, BUFFER_OPTIONS, "renderToPDFBuffer options");
|
|
71
|
+
const metadata = requireMetadata(options.metadata);
|
|
110
72
|
const graphicSpec = requireProgramGraphicSpec(program);
|
|
111
73
|
const target = resolveGraphicRenderTarget(graphicSpec);
|
|
112
74
|
requirePDFPageDimensions(target);
|
|
113
75
|
preflightCanvasGraphicSpec(target);
|
|
114
|
-
const
|
|
76
|
+
const { PDFDocument } = await loadNativeBackend();
|
|
77
|
+
const document = new PDFDocument(metadata);
|
|
78
|
+
const context = document.beginPage(target.width, target.height);
|
|
79
|
+
drawResolvedGraphicSpec(target, context);
|
|
80
|
+
document.endPage();
|
|
81
|
+
const buffer = document.close();
|
|
82
|
+
return Object.freeze({
|
|
83
|
+
buffer, width: target.width, height: target.height, pages: 1, bytes: buffer.length
|
|
84
|
+
});
|
|
85
|
+
}
|
|
115
86
|
|
|
87
|
+
export async function renderToPDF(program, options = {}) {
|
|
88
|
+
validateRendererOptions(options, PDF_OPTIONS, "renderToPDF options");
|
|
89
|
+
if (typeof options.output !== "string" || options.output.length === 0) {
|
|
90
|
+
throw new TypeError("renderToPDF requires a non-empty output path.");
|
|
91
|
+
}
|
|
92
|
+
const { buffer, ...result } = await renderToPDFBuffer(program, { metadata: options.metadata });
|
|
93
|
+
const output = resolve(options.output);
|
|
116
94
|
await mkdir(dirname(output), { recursive: true });
|
|
117
95
|
await writeFile(output, buffer);
|
|
118
|
-
|
|
119
|
-
return Object.freeze({
|
|
120
|
-
output,
|
|
121
|
-
width: target.width,
|
|
122
|
-
height: target.height,
|
|
123
|
-
pages: 1,
|
|
124
|
-
bytes: buffer.length
|
|
125
|
-
});
|
|
96
|
+
return Object.freeze({ output, ...result });
|
|
126
97
|
}
|
package/src/renderers/png.js
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { render } from "./canvas/index.js";
|
|
4
|
+
import { validateRendererOptions } from "./options.js";
|
|
5
|
+
import { loadNativeBackend } from "./nativeBackend.js";
|
|
3
6
|
|
|
4
|
-
|
|
7
|
+
const PNG_OPTIONS = new Set(["output", "pixelRatio"]);
|
|
8
|
+
const BUFFER_OPTIONS = new Set(["pixelRatio"]);
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
export async function renderToPNGBuffer(program, options = {}) {
|
|
11
|
+
validateRendererOptions(options, BUFFER_OPTIONS, "renderToPNGBuffer options");
|
|
12
|
+
const { pixelRatio = 1 } = options;
|
|
13
|
+
const { createCanvas } = await loadNativeBackend();
|
|
14
|
+
const canvas = createCanvas(1, 1);
|
|
15
|
+
render(program, canvas.getContext("2d"), { pixelRatio });
|
|
16
|
+
// Canvas drawing is synchronous; encoding uses the native async worker.
|
|
17
|
+
const buffer = await canvas.encode("png");
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
buffer, width: canvas.width, height: canvas.height, pixelRatio, bytes: buffer.length
|
|
20
|
+
});
|
|
21
|
+
}
|
|
7
22
|
|
|
8
|
-
export async function renderToPNG(program,
|
|
23
|
+
export async function renderToPNG(program, options = {}) {
|
|
24
|
+
validateRendererOptions(options, PNG_OPTIONS, "renderToPNG options");
|
|
25
|
+
const { output, pixelRatio } = options;
|
|
9
26
|
if (typeof output !== "string" || output.length === 0) {
|
|
10
27
|
throw new TypeError("renderToPNG requires a non-empty output path.");
|
|
11
28
|
}
|
|
12
|
-
|
|
13
|
-
const canvas = createCanvas(1, 1);
|
|
14
|
-
const context = canvas.getContext("2d");
|
|
15
|
-
render(program, context, { pixelRatio });
|
|
16
|
-
|
|
29
|
+
const { buffer, ...result } = await renderToPNGBuffer(program, { pixelRatio });
|
|
17
30
|
const path = resolve(output);
|
|
18
|
-
const buffer = canvas.toBuffer("image/png");
|
|
19
31
|
await mkdir(dirname(path), { recursive: true });
|
|
20
32
|
await writeFile(path, buffer);
|
|
21
|
-
|
|
22
|
-
return Object.freeze({
|
|
23
|
-
output: path,
|
|
24
|
-
width: canvas.width,
|
|
25
|
-
height: canvas.height,
|
|
26
|
-
pixelRatio,
|
|
27
|
-
bytes: buffer.length
|
|
28
|
-
});
|
|
33
|
+
return Object.freeze({ output: path, ...result });
|
|
29
34
|
}
|
package/src/renderers/svg.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isOwned } from "../core/immutable.js";
|
|
1
2
|
import {
|
|
2
3
|
requireSingleOrderedGraphicByType,
|
|
3
4
|
walkGraphicTreeEvents
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
requireStringProperty
|
|
18
19
|
} from "./canvas/validation.js";
|
|
19
20
|
import { normalizeRendererFontWeight } from "./text.js";
|
|
21
|
+
import { validateRendererOptions } from "./options.js";
|
|
20
22
|
|
|
21
23
|
const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
22
24
|
const SVG_OPTIONS = new Set(["title", "description", "resourceNamespace"]);
|
|
@@ -37,14 +39,20 @@ const DOMINANT_BASELINES = Object.freeze({
|
|
|
37
39
|
bottom: "text-after-edge"
|
|
38
40
|
});
|
|
39
41
|
|
|
42
|
+
const namespaceByGraphic = new WeakMap();
|
|
43
|
+
|
|
40
44
|
function resourceNamespace(graphicSpec) {
|
|
45
|
+
const cached = namespaceByGraphic.get(graphicSpec);
|
|
46
|
+
if (cached !== undefined) return cached;
|
|
41
47
|
const serialized = JSON.stringify(graphicSpec);
|
|
42
48
|
let hash = 0xcbf29ce484222325n;
|
|
43
49
|
for (let index = 0; index < serialized.length; index += 1) {
|
|
44
50
|
hash ^= BigInt(serialized.charCodeAt(index));
|
|
45
51
|
hash = BigInt.asUintN(64, hash * 0x100000001b3n);
|
|
46
52
|
}
|
|
47
|
-
|
|
53
|
+
const namespace = hash.toString(36);
|
|
54
|
+
if (isOwned(graphicSpec)) namespaceByGraphic.set(graphicSpec, namespace);
|
|
55
|
+
return namespace;
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
function escapeText(value) {
|
|
@@ -525,19 +533,7 @@ function serializeBody(graphicSpec, rootId, rootCanvas, width, height, state) {
|
|
|
525
533
|
}
|
|
526
534
|
|
|
527
535
|
function requireSVGOptions(options) {
|
|
528
|
-
|
|
529
|
-
options === null ||
|
|
530
|
-
typeof options !== "object" ||
|
|
531
|
-
Array.isArray(options) ||
|
|
532
|
-
Object.getPrototypeOf(options) !== Object.prototype
|
|
533
|
-
) {
|
|
534
|
-
throw new TypeError("renderToSVG options must be a plain object.");
|
|
535
|
-
}
|
|
536
|
-
for (const key of Object.keys(options)) {
|
|
537
|
-
if (!SVG_OPTIONS.has(key)) {
|
|
538
|
-
throw new TypeError(`renderToSVG does not support option "${key}".`);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
536
|
+
validateRendererOptions(options, SVG_OPTIONS, "renderToSVG options");
|
|
541
537
|
for (const key of SVG_OPTIONS) {
|
|
542
538
|
if (
|
|
543
539
|
options[key] !== undefined &&
|
package/src/renderers/text.js
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const MAX_RENDERER_NUMERIC_FONT_WEIGHT = 900;
|
|
3
|
-
|
|
4
|
-
export function normalizeRendererFontWeight(fontWeight) {
|
|
5
|
-
if (typeof fontWeight !== "number") return fontWeight;
|
|
6
|
-
const rounded = Math.round(fontWeight / 100) * 100;
|
|
7
|
-
return Math.min(
|
|
8
|
-
MAX_RENDERER_NUMERIC_FONT_WEIGHT,
|
|
9
|
-
Math.max(MIN_RENDERER_NUMERIC_FONT_WEIGHT, rounded)
|
|
10
|
-
);
|
|
11
|
-
}
|
|
1
|
+
export { normalizeRendererFontWeight } from "../core/font.js";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { annotateError } from "../core/diagnostics.js";
|
|
2
|
+
|
|
1
3
|
export function findCoordinate(program, id) {
|
|
2
4
|
return program.semanticSpec.coordinates.find(coordinate => coordinate.id === id);
|
|
3
5
|
}
|
|
@@ -8,6 +10,6 @@ export function hasCoordinate(program, id) {
|
|
|
8
10
|
|
|
9
11
|
export function requireCoordinate(program, id) {
|
|
10
12
|
const coordinate = findCoordinate(program, id);
|
|
11
|
-
if (coordinate === undefined) throw new Error(`Unknown coordinate "${id}".`);
|
|
13
|
+
if (coordinate === undefined) throw annotateError(new Error(`Unknown coordinate "${id}".`), { code: "missing-resource", resourceId: id });
|
|
12
14
|
return coordinate;
|
|
13
15
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { annotateError } from "../core/diagnostics.js";
|
|
2
|
+
|
|
1
3
|
export function findDataset(program, id) {
|
|
2
4
|
return program.semanticSpec.datasets.find(dataset => dataset.id === id);
|
|
3
5
|
}
|
|
@@ -20,7 +22,7 @@ export function hasDatasetOwner(program, id) {
|
|
|
20
22
|
export function resolveDatasetReference(program, id, label = "Dataset") {
|
|
21
23
|
const matches = currentOwnerMatches(program, id);
|
|
22
24
|
if (matches.length > 1) {
|
|
23
|
-
throw new Error(`${label} logical owner "${id}" is ambiguous.`);
|
|
25
|
+
throw annotateError(new Error(`${label} logical owner "${id}" is ambiguous.`), { code: "ambiguous-resource", resourceId: id, candidates: matches.map(match => match.current) });
|
|
24
26
|
}
|
|
25
27
|
const resolved = matches.length === 1 ? matches[0].current : id;
|
|
26
28
|
const dataset = findDataset(program, resolved);
|
|
@@ -28,7 +30,7 @@ export function resolveDatasetReference(program, id, label = "Dataset") {
|
|
|
28
30
|
const kind = label.toLowerCase().includes("source")
|
|
29
31
|
? "source dataset"
|
|
30
32
|
: "dataset";
|
|
31
|
-
throw new Error(`Unknown ${kind} "${id}" does not exist.`);
|
|
33
|
+
throw annotateError(new Error(`Unknown ${kind} "${id}" does not exist.`), { code: "missing-resource", resourceId: id });
|
|
32
34
|
}
|
|
33
35
|
return dataset;
|
|
34
36
|
}
|
|
@@ -43,19 +45,19 @@ export function findDatasetConsumer(program, source) {
|
|
|
43
45
|
|
|
44
46
|
export function requireDataset(program, id, label = `Dataset "${id}"`) {
|
|
45
47
|
const dataset = findDataset(program, id);
|
|
46
|
-
if (dataset === undefined) throw new Error(`${label} does not exist.`);
|
|
48
|
+
if (dataset === undefined) throw annotateError(new Error(`${label} does not exist.`), { code: "missing-resource", resourceId: id });
|
|
47
49
|
return dataset;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export function requireMaterializedDataset(program, id) {
|
|
51
53
|
const dataset = resolveDatasetReference(program, id, "Dataset");
|
|
52
|
-
if (dataset === undefined) throw new Error(`Unknown dataset "${id}".`);
|
|
54
|
+
if (dataset === undefined) throw annotateError(new Error(`Unknown dataset "${id}".`), { code: "missing-resource", resourceId: id });
|
|
53
55
|
if (!Array.isArray(dataset.values)) {
|
|
54
|
-
throw new Error(
|
|
56
|
+
throw annotateError(new Error(
|
|
55
57
|
`Dataset "${id}" requires materialized values. ` +
|
|
56
58
|
"createDerivedData stores a definition only; use the corresponding " +
|
|
57
59
|
"value-producing data action before creating a chart or mark."
|
|
58
|
-
);
|
|
60
|
+
), { code: "incompatible-resource", resourceId: id });
|
|
59
61
|
}
|
|
60
62
|
return dataset;
|
|
61
63
|
}
|
package/src/selectors/layers.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { annotateError } from "../core/diagnostics.js";
|
|
2
|
+
|
|
1
3
|
export function findLayer(program, id) {
|
|
2
4
|
return program.semanticSpec.layers.find(layer => layer.id === id);
|
|
3
5
|
}
|
|
@@ -12,7 +14,7 @@ export function hasLayer(program, id) {
|
|
|
12
14
|
|
|
13
15
|
export function requireLayer(program, id, label = `Layer "${id}"`) {
|
|
14
16
|
const layer = findLayer(program, id);
|
|
15
|
-
if (layer === undefined) throw new Error(`${label} does not exist.`);
|
|
17
|
+
if (layer === undefined) throw annotateError(new Error(`${label} does not exist.`), { code: "missing-resource", resourceId: id });
|
|
16
18
|
return layer;
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -26,12 +28,12 @@ export function resolveEligibleLayer(program, {
|
|
|
26
28
|
const candidates = program.semanticSpec.layers.filter(predicate);
|
|
27
29
|
if (target !== undefined) {
|
|
28
30
|
const selected = candidates.find(layer => layer.id === target);
|
|
29
|
-
if (selected === undefined) throw new Error(`Unknown ${label} ${targetOption} "${target}".`);
|
|
31
|
+
if (selected === undefined) throw annotateError(new Error(`Unknown ${label} ${targetOption} "${target}".`), { code: findLayer(program, target) ? "incompatible-resource" : "missing-resource", resourceId: target, optionPath: targetOption });
|
|
30
32
|
return selected;
|
|
31
33
|
}
|
|
32
34
|
const selected = candidates.find(layer => layer.id === current);
|
|
33
35
|
if (selected !== undefined) return selected;
|
|
34
36
|
if (candidates.length === 1) return candidates[0];
|
|
35
|
-
if (candidates.length === 0) throw new Error(`${label} requires an eligible layer.`);
|
|
36
|
-
throw new Error(`${label} ${targetOption} is ambiguous; provide ${targetOption}.`);
|
|
37
|
+
if (candidates.length === 0) throw annotateError(new Error(`${label} requires an eligible layer.`), { code: "missing-resource", optionPath: targetOption });
|
|
38
|
+
throw annotateError(new Error(`${label} ${targetOption} is ambiguous; provide ${targetOption}.`), { code: "ambiguous-resource", optionPath: targetOption, candidates: candidates.map(layer => layer.id) });
|
|
37
39
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { findLayer } from "./layers.js";
|
|
2
|
+
|
|
3
|
+
export function ownedChildren(program, id) {
|
|
4
|
+
const config = program.markConfigs[id] ?? {};
|
|
5
|
+
return [
|
|
6
|
+
config.errorBar?.lowerCapId,
|
|
7
|
+
config.errorBar?.upperCapId,
|
|
8
|
+
config.errorBand?.lowerBoundaryId,
|
|
9
|
+
config.errorBand?.upperBoundaryId,
|
|
10
|
+
config.regression?.bandId,
|
|
11
|
+
config.regression?.lineId,
|
|
12
|
+
config.boxPlot?.whiskerId,
|
|
13
|
+
config.boxPlot?.medianId,
|
|
14
|
+
config.boxPlot?.outlierId,
|
|
15
|
+
config.gradientPlot?.centerId,
|
|
16
|
+
config.intervalPlot?.intervalId,
|
|
17
|
+
config.endpointPlot?.roles?.stemId,
|
|
18
|
+
config.endpointPlot?.roles?.startId,
|
|
19
|
+
config.endpointPlot?.roles?.connectorId,
|
|
20
|
+
...(config.raincloudPlot?.ownedChildIds ?? [])
|
|
21
|
+
].concat(
|
|
22
|
+
program.semanticSpec.layers
|
|
23
|
+
.filter(layer => layer.source === id)
|
|
24
|
+
.map(layer => layer.id)
|
|
25
|
+
).concat(
|
|
26
|
+
program.semanticSpec.layers
|
|
27
|
+
.filter(layer =>
|
|
28
|
+
program.markConfigs[layer.id]?.statisticalReference?.source === id
|
|
29
|
+
)
|
|
30
|
+
.map(layer => layer.id)
|
|
31
|
+
).filter(child => child !== undefined && child !== id && findLayer(program, child) !== undefined);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function ownership(program) {
|
|
35
|
+
const ownerByChild = new Map();
|
|
36
|
+
for (const layer of program.semanticSpec.layers) {
|
|
37
|
+
for (const child of ownedChildren(program, layer.id)) {
|
|
38
|
+
if (program.markConfigs[child]?.statisticalReference !== undefined) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
ownerByChild.set(child, layer.id);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return ownerByChild;
|
|
45
|
+
}
|
|
46
|
+
|
package/src/selectors/scales.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
+
import { annotateError } from "../core/diagnostics.js";
|
|
2
|
+
|
|
1
3
|
export function findSemanticScale(program, id) {
|
|
2
4
|
return program.semanticSpec.scales.find(scale => scale.id === id);
|
|
3
5
|
}
|
|
4
6
|
|
|
5
7
|
export function requireSemanticScale(program, id) {
|
|
6
8
|
const scale = findSemanticScale(program, id);
|
|
7
|
-
if (scale === undefined) throw new Error(`Unknown scale "${id}".`);
|
|
9
|
+
if (scale === undefined) throw annotateError(new Error(`Unknown scale "${id}".`), { code: "missing-resource", resourceId: id });
|
|
8
10
|
return scale;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export function requireResolvedScale(program, id, type) {
|
|
12
|
-
const scale = program.resolvedScales[id];
|
|
14
|
+
const scale = Object.hasOwn(program.resolvedScales, id) ? program.resolvedScales[id] : undefined;
|
|
13
15
|
if (scale === undefined || (type !== undefined && scale.type !== type)) {
|
|
14
|
-
throw new Error(
|
|
16
|
+
throw annotateError(new Error(
|
|
15
17
|
type === undefined
|
|
16
18
|
? `Unknown resolved scale "${id}".`
|
|
17
19
|
: `Expected resolved ${type} scale "${id}".`
|
|
18
|
-
);
|
|
20
|
+
), { code: scale === undefined ? "missing-resource" : "incompatible-resource", resourceId: id });
|
|
19
21
|
}
|
|
20
22
|
return scale;
|
|
21
23
|
}
|
package/src/theme/defaults.js
CHANGED
package/src/version.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ChartProgram } from "./program.js";
|
|
2
|
+
import type { BasicChartProgram } from "./basic.js";
|
|
3
|
+
|
|
4
|
+
export interface AccessibleColumn {
|
|
5
|
+
readonly key: string;
|
|
6
|
+
readonly role: string;
|
|
7
|
+
readonly component: string;
|
|
8
|
+
readonly field?: string;
|
|
9
|
+
readonly aggregate?: string;
|
|
10
|
+
readonly unit?: "utc-milliseconds";
|
|
11
|
+
}
|
|
12
|
+
export interface AccessibleRow {
|
|
13
|
+
readonly component: string;
|
|
14
|
+
readonly series: Readonly<Record<string, unknown>>;
|
|
15
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
16
|
+
}
|
|
17
|
+
export interface AccessibleOwnerView {
|
|
18
|
+
readonly ownerId: string;
|
|
19
|
+
readonly markType: string;
|
|
20
|
+
readonly columns: readonly AccessibleColumn[];
|
|
21
|
+
readonly rows: readonly AccessibleRow[];
|
|
22
|
+
readonly units: Readonly<Record<string, "utc-milliseconds">>;
|
|
23
|
+
}
|
|
24
|
+
export interface AccessibleChildView {
|
|
25
|
+
readonly ownerId: string;
|
|
26
|
+
readonly kind: "composition-child";
|
|
27
|
+
readonly title: string | null;
|
|
28
|
+
readonly facet?: Readonly<Record<string, unknown>>;
|
|
29
|
+
readonly views: readonly AccessibleView[];
|
|
30
|
+
}
|
|
31
|
+
export type AccessibleView = AccessibleOwnerView | AccessibleChildView;
|
|
32
|
+
export interface AccessibleData {
|
|
33
|
+
readonly schemaVersion: 1;
|
|
34
|
+
readonly title: string | null;
|
|
35
|
+
readonly views: readonly AccessibleView[];
|
|
36
|
+
}
|
|
37
|
+
export function exportAccessibleData(program: ChartProgram | BasicChartProgram, options?: { readonly target?: string }): AccessibleData;
|
package/types/basic.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChartProgram, BasicSeriesLayoutOptions } from "./program.js";
|
|
1
|
+
import type { ChartProgram, BasicSeriesLayoutOptions, CreateDataOptions } from "./program.js";
|
|
2
2
|
|
|
3
3
|
export type {
|
|
4
4
|
AxisLabelOptions,
|
|
@@ -17,6 +17,7 @@ export type {
|
|
|
17
17
|
CompleteAxisOptions,
|
|
18
18
|
CreateAxesOptions,
|
|
19
19
|
CreateBarPlotOptions,
|
|
20
|
+
CreateDataOptions,
|
|
20
21
|
CreateGridOptions,
|
|
21
22
|
CreateGuidesOptions,
|
|
22
23
|
CreateHeatmapOptions,
|
|
@@ -111,7 +112,8 @@ type RebindMethod<T> = T extends (...args: infer Args) => ChartProgram
|
|
|
111
112
|
|
|
112
113
|
export type BasicChartProgram =
|
|
113
114
|
Pick<ChartProgram, BasicStateKey> &
|
|
114
|
-
{ readonly [Key in BasicMethodKey]: RebindMethod<ChartProgram[Key]> } &
|
|
115
|
+
{ readonly [Key in Exclude<BasicMethodKey, "createData">]: RebindMethod<ChartProgram[Key]> } &
|
|
116
|
+
{ createData<Row extends object>(options: CreateDataOptions<Row>): BasicChartProgram } &
|
|
115
117
|
{ readonly layoutSeries: (options: BasicSeriesLayoutOptions) => BasicChartProgram };
|
|
116
118
|
|
|
117
119
|
export function chart(): BasicChartProgram;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ErrorCode = "invalid-option" | "invalid-value" | "missing-resource" |
|
|
2
|
+
"ambiguous-resource" | "incompatible-resource" | "resource-in-use" |
|
|
3
|
+
"resource-limit" | "unsupported-format" | "action-failed";
|
|
4
|
+
|
|
5
|
+
export interface ErrorDetails {
|
|
6
|
+
readonly code: ErrorCode;
|
|
7
|
+
readonly operation?: string;
|
|
8
|
+
readonly optionPath?: string;
|
|
9
|
+
readonly resourceId?: string;
|
|
10
|
+
readonly candidates?: readonly string[];
|
|
11
|
+
readonly limit?: number;
|
|
12
|
+
readonly actual?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getErrorDetails(error: unknown): ErrorDetails | undefined;
|
package/types/index.d.ts
CHANGED
package/types/pdf.d.ts
CHANGED
|
@@ -24,3 +24,12 @@ export function renderToPDF(
|
|
|
24
24
|
program: Pick<ChartProgram, "graphicSpec">,
|
|
25
25
|
options: PDFRenderOptions
|
|
26
26
|
): Promise<PDFRenderResult>;
|
|
27
|
+
|
|
28
|
+
export interface PDFBufferResult extends Omit<PDFRenderResult, "output"> {
|
|
29
|
+
readonly buffer: Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function renderToPDFBuffer(
|
|
33
|
+
program: Pick<ChartProgram, "graphicSpec">,
|
|
34
|
+
options?: { metadata?: PDFMetadata }
|
|
35
|
+
): Promise<PDFBufferResult>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ChartProgram } from "./program.js";
|
|
2
|
+
import type { BasicChartProgram } from "./basic.js";
|
|
3
|
+
|
|
4
|
+
export function serializeProgram(program: ChartProgram | BasicChartProgram): string;
|
|
5
|
+
export function deserializeProgram(text: string): ChartProgram;
|
|
6
|
+
export function serializeGraphic(program: Pick<ChartProgram, "graphicSpec">): string;
|
|
7
|
+
export function deserializeGraphic(text: string): Readonly<Pick<ChartProgram, "graphicSpec">>;
|