enarratio-astro 0.4.1 → 0.4.2

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 CHANGED
@@ -7,6 +7,18 @@ every such change is listed here.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.2] - 2026-11-03
11
+
12
+ ### Changed
13
+
14
+ - Draws with Enarratio 0.7.3: charts no longer move the page when the enhancement layer loads. The redraw keeps the
15
+ height the server drawing showed, a legend entry has its button's box before it is a button, and an interactive
16
+ chart's figure holds the controls the layer adds (Show table, Play as sound, the downloads), inert until it
17
+ arrives.
18
+ - A chart that is not interactive leaves those controls out (Enarratio's `controls: false`), since no layer ever
19
+ makes them work. `renderChart` takes a second argument, `{ interactive }`, for this; it defaults to true, as
20
+ Enarratio does.
21
+
10
22
  ## [0.4.1] - 2026-11-03
11
23
 
12
24
  ### Changed
package/dist/chart.d.ts CHANGED
@@ -63,10 +63,19 @@ export type ChartResult = {
63
63
  readonly ok: false;
64
64
  readonly error: string;
65
65
  };
66
+ /** How a chart is drawn, beside what it shows. */
67
+ export interface RenderOptions {
68
+ /**
69
+ * Whether the page enhances the chart (`<Chart interactive>`). An enhanced chart's figure holds
70
+ * the controls the enhancement layer adds, inert until it arrives, so the page does not move;
71
+ * a chart that is never enhanced leaves them out. Defaults to true, as Enarratio does.
72
+ */
73
+ readonly interactive?: boolean | undefined;
74
+ }
66
75
  /**
67
76
  * Draws a chart. Bar, line and area charts come from `enarratio/lite`, which builds the SVG as a
68
77
  * string with no DOM, the cheapest render on a Worker; scatter plots and heatmaps load
69
78
  * `enarratio/plot` (Observable Plot and linkedom) only when a page has one. Never throws: a chart
70
79
  * that cannot be drawn returns the reason instead, so one mistake cannot break a page.
71
80
  */
72
- export declare function renderChart(spec: ChartSpec): Promise<ChartResult>;
81
+ export declare function renderChart(spec: ChartSpec, options?: RenderOptions): Promise<ChartResult>;
package/dist/chart.js CHANGED
@@ -22,8 +22,8 @@ function numeric(table, name) {
22
22
  if (bad)
23
23
  throw new Error(`The column "${name}" should hold numbers, but has "${bad[name]}".`);
24
24
  }
25
- /** The options every chart type shares: text, the data table and the id. */
26
- function figure(spec) {
25
+ /** The options every chart type shares: text, the data table, the id and the pending controls. */
26
+ function figure(spec, options) {
27
27
  const alt = text(spec.alt);
28
28
  if (!alt)
29
29
  throw new Error("Add a description (alt): one sentence on what the chart shows.");
@@ -43,14 +43,15 @@ function figure(spec) {
43
43
  ...(source ? { source: sourceHref ? { name: source, href: sourceHref } : source } : {}),
44
44
  ...(id ? { id } : {}),
45
45
  dataTable: spec.dataTable === "visually-hidden" ? "visually-hidden" : "details",
46
+ ...(options.interactive === false ? { controls: false } : {}),
46
47
  };
47
48
  }
48
- async function draw(spec) {
49
+ async function draw(spec, options) {
49
50
  const type = (text(spec.type) ?? "bar").toLowerCase();
50
51
  if (!CHART_TYPES.includes(type)) {
51
52
  throw new Error(`There is no chart type "${spec.type}". Use one of: ${CHART_TYPES.join(", ")}.`);
52
53
  }
53
- const common = figure(spec);
54
+ const common = figure(spec, options);
54
55
  const table = typeof spec.data === "string" ? parseTable(spec.data) : tableFromRows(spec.data);
55
56
  const x = column(table, spec.x, "x axis");
56
57
  const seriesName = text(spec.series) ? column(table, spec.series, "series") : undefined;
@@ -109,9 +110,9 @@ async function draw(spec) {
109
110
  * `enarratio/plot` (Observable Plot and linkedom) only when a page has one. Never throws: a chart
110
111
  * that cannot be drawn returns the reason instead, so one mistake cannot break a page.
111
112
  */
112
- export async function renderChart(spec) {
113
+ export async function renderChart(spec, options = {}) {
113
114
  try {
114
- return { ok: true, html: await draw(spec) };
115
+ return { ok: true, html: await draw(spec, options) };
115
116
  }
116
117
  catch (error) {
117
118
  return { ok: false, error: error instanceof Error ? error.message : String(error) };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */
8
- export { CHART_TYPES, type ChartResult, type ChartSpec, type ChartType, renderChart, } from "./chart.js";
8
+ export { CHART_TYPES, type ChartResult, type ChartSpec, type ChartType, type RenderOptions, renderChart, } from "./chart.js";
9
9
  export { type Cell, parseTable, type Table, tableFromRows } from "./data.js";
10
10
  export { chartMarkup } from "./figure.js";
11
11
  export { chartStyles, type StyleOptions, type Styles } from "./styles.js";
package/dist/markdown.js CHANGED
@@ -69,7 +69,7 @@ async function chartHtml(source, first, options) {
69
69
  let markup;
70
70
  try {
71
71
  const { interactive, ...spec } = parseChartBlock(source);
72
- const result = await renderChart(spec);
72
+ const result = await renderChart(spec, { interactive });
73
73
  if (!result.ok)
74
74
  console.warn(`[enarratio-astro] Markdown chart not drawn: ${result.error}`);
75
75
  markup = chartMarkup(result, interactive);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enarratio-astro",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Accessible charts for Astro: a Chart component and charts in Markdown, drawn on the server by Enarratio",
5
5
  "keywords": [
6
6
  "astro",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@observablehq/plot": "0.6.17",
59
- "enarratio": "0.7.2",
59
+ "enarratio": "0.7.3",
60
60
  "linkedom": "0.18.14"
61
61
  },
62
62
  "publishConfig": {
package/src/Chart.astro CHANGED
@@ -21,7 +21,7 @@ interface Props extends ChartSpec, StyleOptions {
21
21
  }
22
22
 
23
23
  const { interactive = false, styles, theme, stylesheetOptions, ...spec } = Astro.props;
24
- const result = await renderChart(spec);
24
+ const result = await renderChart(spec, { interactive });
25
25
  const css = firstOnPage(Astro.request) ? chartStyles({ styles, theme, stylesheetOptions }) : "";
26
26
  if (!result.ok) console.warn(`[enarratio-astro] chart ${spec.id ?? ""} not drawn: ${result.error}`);
27
27
  ---
package/src/chart.ts CHANGED
@@ -88,8 +88,18 @@ function numeric(table: Table, name: string): void {
88
88
  if (bad) throw new Error(`The column "${name}" should hold numbers, but has "${bad[name]}".`);
89
89
  }
90
90
 
91
- /** The options every chart type shares: text, the data table and the id. */
92
- function figure(spec: ChartSpec) {
91
+ /** How a chart is drawn, beside what it shows. */
92
+ export interface RenderOptions {
93
+ /**
94
+ * Whether the page enhances the chart (`<Chart interactive>`). An enhanced chart's figure holds
95
+ * the controls the enhancement layer adds, inert until it arrives, so the page does not move;
96
+ * a chart that is never enhanced leaves them out. Defaults to true, as Enarratio does.
97
+ */
98
+ readonly interactive?: boolean | undefined;
99
+ }
100
+
101
+ /** The options every chart type shares: text, the data table, the id and the pending controls. */
102
+ function figure(spec: ChartSpec, options: RenderOptions) {
93
103
  const alt = text(spec.alt);
94
104
  if (!alt) throw new Error("Add a description (alt): one sentence on what the chart shows.");
95
105
  const title = text(spec.title);
@@ -111,17 +121,18 @@ function figure(spec: ChartSpec) {
111
121
  ...(id ? { id } : {}),
112
122
  dataTable:
113
123
  spec.dataTable === "visually-hidden" ? ("visually-hidden" as const) : ("details" as const),
124
+ ...(options.interactive === false ? { controls: false } : {}),
114
125
  };
115
126
  }
116
127
 
117
- async function draw(spec: ChartSpec): Promise<string> {
128
+ async function draw(spec: ChartSpec, options: RenderOptions): Promise<string> {
118
129
  const type = (text(spec.type) ?? "bar").toLowerCase();
119
130
  if (!CHART_TYPES.includes(type as ChartType)) {
120
131
  throw new Error(
121
132
  `There is no chart type "${spec.type}". Use one of: ${CHART_TYPES.join(", ")}.`,
122
133
  );
123
134
  }
124
- const common = figure(spec);
135
+ const common = figure(spec, options);
125
136
  const table = typeof spec.data === "string" ? parseTable(spec.data) : tableFromRows(spec.data);
126
137
  const x = column(table, spec.x, "x axis");
127
138
  const seriesName = text(spec.series) ? column(table, spec.series, "series") : undefined;
@@ -186,9 +197,12 @@ async function draw(spec: ChartSpec): Promise<string> {
186
197
  * `enarratio/plot` (Observable Plot and linkedom) only when a page has one. Never throws: a chart
187
198
  * that cannot be drawn returns the reason instead, so one mistake cannot break a page.
188
199
  */
189
- export async function renderChart(spec: ChartSpec): Promise<ChartResult> {
200
+ export async function renderChart(
201
+ spec: ChartSpec,
202
+ options: RenderOptions = {},
203
+ ): Promise<ChartResult> {
190
204
  try {
191
- return { ok: true, html: await draw(spec) };
205
+ return { ok: true, html: await draw(spec, options) };
192
206
  } catch (error) {
193
207
  return { ok: false, error: error instanceof Error ? error.message : String(error) };
194
208
  }
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export {
10
10
  type ChartResult,
11
11
  type ChartSpec,
12
12
  type ChartType,
13
+ type RenderOptions,
13
14
  renderChart,
14
15
  } from "./chart.js";
15
16
  export { type Cell, parseTable, type Table, tableFromRows } from "./data.js";
package/src/markdown.ts CHANGED
@@ -78,7 +78,7 @@ async function chartHtml(
78
78
  let markup: string;
79
79
  try {
80
80
  const { interactive, ...spec } = parseChartBlock(source);
81
- const result = await renderChart(spec);
81
+ const result = await renderChart(spec, { interactive });
82
82
  if (!result.ok) console.warn(`[enarratio-astro] Markdown chart not drawn: ${result.error}`);
83
83
  markup = chartMarkup(result, interactive);
84
84
  } catch (error) {