@dxos/react-ui-plot 0.0.0 → 0.16.0-next-b440559823fb87ed1a4590dab21ae924d4d76c3a

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.
@@ -54,6 +54,16 @@ var toPlotDatums = ({ columns, rows }) => {
54
54
  //#region src/components/Plot/Plot.tsx
55
55
  var MARGIN = 40;
56
56
  var MIN_SIZE = 80;
57
+ var LABEL_CHAR_WIDTH = 6;
58
+ /** The width a label of `text` takes on an axis, with room for the tick. */
59
+ var labelWidth = (text) => text.length * LABEL_CHAR_WIDTH + MARGIN / 4;
60
+ /** The widest value an axis labels: the largest bar, which for stacked bars is a category's total. */
61
+ var maxBarValue = (datums, stacked) => {
62
+ if (!stacked) return Math.max(0, ...datums.map((datum) => datum.value));
63
+ const totals = /* @__PURE__ */ new Map();
64
+ for (const datum of datums) totals.set(datum.key, (totals.get(datum.key) ?? 0) + Math.max(0, datum.value));
65
+ return Math.max(0, ...totals.values());
66
+ };
57
67
  var TIP = {
58
68
  fill: "var(--color-modal-surface)",
59
69
  stroke: "var(--color-separator)"
@@ -102,7 +112,7 @@ var Plot = ({ classNames, data, options }) => {
102
112
  });
103
113
  };
104
114
  Plot.displayName = "Plot";
105
- var createPlot = (datums, { type, grid = true }, { label, ...size }) => {
115
+ var createPlot = (datums, { type, grid = true, horizontal = false, stacked = false }, { label, ...size }) => {
106
116
  const series = new Set(datums.map((datum) => datum.series));
107
117
  const keys = [...new Set(datums.map((datum) => datum.key))];
108
118
  const seriesOrder = [...series];
@@ -140,35 +150,81 @@ var createPlot = (datums, { type, grid = true }, { label, ...size }) => {
140
150
  })
141
151
  ]
142
152
  });
143
- default: return ObservablePlot.plot({
144
- ...options,
145
- ...series.size > 1 ? {
146
- fx: {
153
+ default: {
154
+ const grouped = series.size > 1 && !stacked;
155
+ if (horizontal) {
156
+ const marginLeft = Math.max(MARGIN, ...keys.map((key) => labelWidth(String(key))));
157
+ return ObservablePlot.plot({
158
+ ...options,
159
+ marginLeft,
160
+ x: { label: null },
161
+ ...grouped ? {
162
+ fy: {
163
+ label: null,
164
+ domain: keys,
165
+ axis: "left"
166
+ },
167
+ y: {
168
+ axis: null,
169
+ domain: seriesOrder
170
+ }
171
+ } : { y: {
172
+ label: null,
173
+ domain: keys
174
+ } },
175
+ marks: [ObservablePlot.ruleX([0]), grouped ? ObservablePlot.barX(datums, {
176
+ fy: "key",
177
+ y: "series",
178
+ x: "value",
179
+ fill: "series",
180
+ tip: TIP
181
+ }) : ObservablePlot.barX(datums, {
182
+ y: "key",
183
+ x: "value",
184
+ fill: "series",
185
+ tip: TIP
186
+ })]
187
+ });
188
+ }
189
+ const marginLeft = Math.max(MARGIN, labelWidth(Math.round(maxBarValue(datums, stacked)).toLocaleString()));
190
+ const longest = Math.max(0, ...keys.map((key) => labelWidth(String(key))));
191
+ const tilt = longest * keys.length > size.width - marginLeft;
192
+ const tickRotate = tilt ? -45 : 0;
193
+ const marginBottom = tilt ? Math.max(MARGIN, longest * Math.SQRT1_2 + MARGIN / 2) : MARGIN;
194
+ return ObservablePlot.plot({
195
+ ...options,
196
+ marginLeft,
197
+ marginBottom,
198
+ ...grouped ? {
199
+ fx: {
200
+ label: null,
201
+ domain: keys,
202
+ axis: "bottom",
203
+ tickRotate
204
+ },
205
+ x: {
206
+ axis: null,
207
+ domain: seriesOrder
208
+ }
209
+ } : { x: {
147
210
  label: null,
148
211
  domain: keys,
149
- axis: "bottom"
150
- },
151
- x: {
152
- axis: null,
153
- domain: seriesOrder
154
- }
155
- } : { x: {
156
- label: null,
157
- domain: keys
158
- } },
159
- marks: [ObservablePlot.ruleY([0]), series.size > 1 ? ObservablePlot.barY(datums, {
160
- fx: "key",
161
- x: "series",
162
- y: "value",
163
- fill: "series",
164
- tip: TIP
165
- }) : ObservablePlot.barY(datums, {
166
- x: "key",
167
- y: "value",
168
- fill: "series",
169
- tip: TIP
170
- })]
171
- });
212
+ tickRotate
213
+ } },
214
+ marks: [ObservablePlot.ruleY([0]), grouped ? ObservablePlot.barY(datums, {
215
+ fx: "key",
216
+ x: "series",
217
+ y: "value",
218
+ fill: "series",
219
+ tip: TIP
220
+ }) : ObservablePlot.barY(datums, {
221
+ x: "key",
222
+ y: "value",
223
+ fill: "series",
224
+ tip: TIP
225
+ })]
226
+ });
227
+ }
172
228
  }
173
229
  };
174
230
  /** Observable Plot has no polar marks, so the pie is drawn directly with d3-shape; the first series is used. */
@@ -215,7 +271,11 @@ var PlotOptions = Schema.Struct({
215
271
  /** The first row holds the series names. */
216
272
  header: Schema.optional(Schema.Boolean.annotate({ title: "Header row" })),
217
273
  /** Draw grid lines (bar and xy). */
218
- grid: Schema.optional(Schema.Boolean.annotate({ title: "Grid lines" }))
274
+ grid: Schema.optional(Schema.Boolean.annotate({ title: "Grid lines" })),
275
+ /** Bars run along the x axis, categories down the y axis (bar). */
276
+ horizontal: Schema.optional(Schema.Boolean.annotate({ title: "Horizontal bars" })),
277
+ /** A category's series stack into one bar rather than standing side by side (bar). */
278
+ stacked: Schema.optional(Schema.Boolean.annotate({ title: "Stacked bars" }))
219
279
  });
220
280
  //#endregion
221
281
  export { PLOT_TYPES, Plot, PlotOptions, PlotType, toPlotData, toPlotDatums };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/util/data.ts","../../src/components/Plot/Plot.tsx","../../src/types.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { type PlotData, type PlotDatum, type PlotValue } from '../types.ts';\n\n/** Spreadsheet column letters for a zero-based index: A–Z, then AA, AB, … (bijective base 26). */\nconst columnName = (index: number): string => {\n let name = '';\n for (let remaining = index + 1; remaining > 0; remaining = Math.floor((remaining - 1) / 26)) {\n name = String.fromCharCode('A'.charCodeAt(0) + ((remaining - 1) % 26)) + name;\n }\n return name;\n};\n\nconst toNumber = (value: PlotValue): number | undefined => {\n if (typeof value === 'number') {\n return Number.isFinite(value) ? value : undefined;\n }\n\n if (typeof value === 'string' && value.trim() !== '') {\n const number = Number(value.replace(/[$,%]/g, ''));\n return Number.isFinite(number) ? number : undefined;\n }\n\n return undefined;\n};\n\nexport type ToPlotDataOptions = {\n /** The first row holds the series names. */\n header?: boolean;\n};\n\n/** Converts a 2D block of cell values (rows of columns) into `PlotData`. */\nexport const toPlotData = (values: PlotValue[][], { header = false }: ToPlotDataOptions = {}): PlotData => {\n const width = values.reduce((max, row) => Math.max(max, row.length), 0);\n const [first, ...rest] = values;\n const columns = Array.from({ length: width }, (_, index) =>\n header && first?.[index] != null ? String(first[index]) : columnName(index),\n );\n\n return { columns, rows: header ? rest : values };\n};\n\n/**\n * Flattens `PlotData` into long form. With a single column the row index is the key;\n * otherwise the first column is the key and each remaining column a series. Non-numeric values are dropped.\n */\nexport const toPlotDatums = ({ columns, rows }: PlotData): PlotDatum[] => {\n if (columns.length === 1) {\n return rows.flatMap((row, index) => {\n const value = toNumber(row[0]);\n return value === undefined ? [] : [{ key: index + 1, series: columns[0], value }];\n });\n }\n\n return rows.flatMap((row) =>\n columns.slice(1).flatMap((series, index) => {\n const value = toNumber(row[index + 1]);\n return value === undefined ? [] : [{ key: row[0], series, value }];\n }),\n );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as ObservablePlot from '@observablehq/plot';\nimport * as d3 from 'd3';\nimport React, { useEffect, useMemo } from 'react';\nimport { useResizeDetector } from 'react-resize-detector';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\n\nimport { type PlotData, type PlotDatum, type PlotOptions } from '../../types.ts';\nimport { toPlotDatums } from '../../util/index.ts';\n\nconst MARGIN = 40;\nconst MIN_SIZE = MARGIN * 2;\n\n// Plot's tip box defaults to a white fill, while its text follows the theme's currentColor.\nconst TIP = { fill: 'var(--color-modal-surface)', stroke: 'var(--color-separator)' };\n\nexport type PlotProps = ThemedClassName<{\n data: PlotData;\n options: PlotOptions;\n}>;\n\n/** Renders tabular data as a bar, pie, or xy chart sized to its container. */\nexport const Plot = ({ classNames, data, options }: PlotProps) => {\n const { ref: containerRef, width = 0, height = 0 } = useResizeDetector<HTMLDivElement>({ refreshRate: 100 });\n const datums = useMemo(() => toPlotDatums(data), [data]);\n\n useEffect(() => {\n const container = containerRef.current;\n // Below twice the margin the plot frame has a negative extent.\n if (!container || width < MIN_SIZE || height < MIN_SIZE || options.type === 'pie') {\n return;\n }\n\n const label = data.columns[0];\n let plot = createPlot(datums, options, { width, height, label });\n container.append(plot);\n\n // A legend is laid out above an SVG of the full height, pushing the x axis out of view; redraw shorter.\n const overflow = plot.getBoundingClientRect().height - height;\n if (overflow > 0) {\n plot.remove();\n plot = createPlot(datums, options, { width, height: height - overflow, label });\n container.append(plot);\n }\n\n return () => plot.remove();\n }, [data, datums, options, width, height]);\n\n return (\n <div ref={containerRef} role='img' className={mx('relative dx-fill overflow-hidden', classNames)}>\n {options.type === 'pie' && width >= MIN_SIZE && height >= MIN_SIZE && (\n <Pie datums={datums} width={width} height={height} />\n )}\n </div>\n );\n};\n\nPlot.displayName = 'Plot';\n\nconst createPlot = (\n datums: PlotDatum[],\n { type, grid = true }: PlotOptions,\n { label, ...size }: { width: number; height: number; label?: string },\n): SVGSVGElement | HTMLElement => {\n const series = new Set(datums.map((datum) => datum.series));\n // Ordinal scales sort by default; keep the sheet's row and column order.\n const keys = [...new Set(datums.map((datum) => datum.key))];\n const seriesOrder = [...series];\n const options = {\n ...size,\n grid,\n marginLeft: MARGIN,\n marginBottom: MARGIN,\n style: { background: 'transparent', color: 'currentColor' },\n color: { legend: series.size > 1, domain: seriesOrder },\n y: { label: null },\n };\n\n switch (type) {\n case 'xy':\n return ObservablePlot.plot({\n ...options,\n x: { label },\n marks: [\n ObservablePlot.ruleY([0]),\n ObservablePlot.line(datums, { x: 'key', y: 'value', stroke: 'series' }),\n ObservablePlot.dot(datums, { x: 'key', y: 'value', fill: 'series', r: 3 }),\n ],\n });\n\n case 'bar':\n default:\n return ObservablePlot.plot({\n ...options,\n ...(series.size > 1\n ? { fx: { label: null, domain: keys, axis: 'bottom' }, x: { axis: null, domain: seriesOrder } }\n : { x: { label: null, domain: keys } }),\n marks: [\n ObservablePlot.ruleY([0]),\n series.size > 1\n ? ObservablePlot.barY(datums, { fx: 'key', x: 'series', y: 'value', fill: 'series', tip: TIP })\n : ObservablePlot.barY(datums, { x: 'key', y: 'value', fill: 'series', tip: TIP }),\n ],\n });\n }\n};\n\ntype PieProps = {\n datums: PlotDatum[];\n width: number;\n height: number;\n};\n\n/** Observable Plot has no polar marks, so the pie is drawn directly with d3-shape; the first series is used. */\nconst Pie = ({ datums, width, height }: PieProps) => {\n const radius = Math.max(0, Math.min(width, height) / 2 - MARGIN / 2);\n const slices = useMemo(() => {\n const first = datums[0]?.series;\n const values = datums.filter((datum) => datum.series === first && datum.value > 0);\n return d3\n .pie<PlotDatum>()\n .sort(null)\n .value((datum) => datum.value)(values);\n }, [datums]);\n\n const arc = d3.arc<d3.PieArcDatum<PlotDatum>>().innerRadius(0).outerRadius(radius);\n const label = d3\n .arc<d3.PieArcDatum<PlotDatum>>()\n .innerRadius(radius * 0.65)\n .outerRadius(radius * 0.65);\n const color = d3.scaleOrdinal<string, string>(d3.schemeTableau10);\n\n return (\n <svg width={width} height={height} viewBox={`${-width / 2} ${-height / 2} ${width} ${height}`}>\n {slices.map((slice, index) => (\n <g key={index}>\n <path d={arc(slice) ?? undefined} fill={color(String(slice.data.key))} stroke='var(--color-base-surface)'>\n <title>{`${slice.data.key}: ${slice.data.value}`}</title>\n </path>\n <text\n transform={`translate(${label.centroid(slice)})`}\n textAnchor='middle'\n dominantBaseline='middle'\n fontSize={11}\n fill='white'\n >\n {String(slice.data.key)}\n </text>\n </g>\n ))}\n </svg>\n );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nexport const PlotType = Schema.Literals(['bar', 'pie', 'xy']);\nexport type PlotType = Schema.Schema.Type<typeof PlotType>;\n\nexport const PLOT_TYPES: readonly PlotType[] = PlotType.literals;\n\n/** Presentation options; persisted alongside the data source by the host. */\nexport const PlotOptions = Schema.Struct({\n type: PlotType.annotate({ title: 'Chart type' }),\n /** The first row holds the series names. */\n header: Schema.optional(Schema.Boolean.annotate({ title: 'Header row' })),\n /** Draw grid lines (bar and xy). */\n grid: Schema.optional(Schema.Boolean.annotate({ title: 'Grid lines' })),\n});\n\nexport type PlotOptions = Schema.Schema.Type<typeof PlotOptions>;\n\nexport type PlotValue = string | number | boolean | null;\n\n/**\n * Column-oriented table: the first column is the category (bar, pie) or the x axis (xy);\n * each remaining column is a series.\n */\nexport type PlotData = {\n columns: string[];\n rows: PlotValue[][];\n};\n\n/** One series value in long form, the shape Observable Plot marks consume. */\nexport type PlotDatum = {\n key: PlotValue;\n series: string;\n value: number;\n};\n"],"mappings":";;;;;;;;;AAOA,IAAM,cAAc,UAA0B;CAC5C,IAAI,OAAO;CACX,KAAK,IAAI,YAAY,QAAQ,GAAG,YAAY,GAAG,YAAY,KAAK,OAAO,YAAY,KAAK,EAAE,GACxF,OAAO,OAAO,aAAa,IAAI,WAAW,CAAC,KAAM,YAAY,KAAK,EAAG,IAAI;CAE3E,OAAO;AACT;AAEA,IAAM,YAAY,UAAyC;CACzD,IAAI,OAAO,UAAU,UACnB,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ,KAAA;CAG1C,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI;EACpD,MAAM,SAAS,OAAO,MAAM,QAAQ,UAAU,EAAE,CAAC;EACjD,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS,KAAA;CAC5C;AAGF;;AAQA,IAAa,cAAc,QAAuB,EAAE,SAAS,UAA6B,CAAC,MAAgB;CACzG,MAAM,QAAQ,OAAO,QAAQ,KAAK,QAAQ,KAAK,IAAI,KAAK,IAAI,MAAM,GAAG,CAAC;CACtE,MAAM,CAAC,OAAO,GAAG,QAAQ;CAKzB,OAAO;EAAE,SAJO,MAAM,KAAK,EAAE,QAAQ,MAAM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,EAAA,UAAA,CACE,oBAAC,QAAD;GAAM,GAAG,IAAI,KAAK,KAAK,KAAA;GAAW,MAAM,MAAM,OAAO,MAAM,KAAK,GAAG,CAAC;GAAG,QAAO;GAC5E,UAAA,oBAAC,SAAD,EAAA,UAAQ,GAAG,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,QAAe,CAAA;EACpD,CAAA,GACN,oBAAC,QAAD;GACE,WAAW,aAAa,MAAM,SAAS,KAAK,EAAE;GAC9C,YAAW;GACX,kBAAiB;GACjB,UAAU;GACV,MAAK;GAEJ,UAAA,OAAO,MAAM,KAAK,GAAG;EAClB,CAAA,CACL,EAAA,GAbK,KAaL,CACJ;CACE,CAAA;AAET;;;ACvJA,IAAa,WAAW,OAAO,SAAS;CAAC;CAAO;CAAO;AAAI,CAAC;AAG5D,IAAa,aAAkC,SAAS;;AAGxD,IAAa,cAAc,OAAO,OAAO;CACvC,MAAM,SAAS,SAAS,EAAE,OAAO,aAAa,CAAC;;CAE/C,QAAQ,OAAO,SAAS,OAAO,QAAQ,SAAS,EAAE,OAAO,aAAa,CAAC,CAAC;;CAExE,MAAM,OAAO,SAAS,OAAO,QAAQ,SAAS,EAAE,OAAO,aAAa,CAAC,CAAC;AACxE,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/util/data.ts","../../src/components/Plot/Plot.tsx","../../src/types.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { type PlotData, type PlotDatum, type PlotValue } from '../types.ts';\n\n/** Spreadsheet column letters for a zero-based index: A–Z, then AA, AB, … (bijective base 26). */\nconst columnName = (index: number): string => {\n let name = '';\n for (let remaining = index + 1; remaining > 0; remaining = Math.floor((remaining - 1) / 26)) {\n name = String.fromCharCode('A'.charCodeAt(0) + ((remaining - 1) % 26)) + name;\n }\n return name;\n};\n\nconst toNumber = (value: PlotValue): number | undefined => {\n if (typeof value === 'number') {\n return Number.isFinite(value) ? value : undefined;\n }\n\n if (typeof value === 'string' && value.trim() !== '') {\n const number = Number(value.replace(/[$,%]/g, ''));\n return Number.isFinite(number) ? number : undefined;\n }\n\n return undefined;\n};\n\nexport type ToPlotDataOptions = {\n /** The first row holds the series names. */\n header?: boolean;\n};\n\n/** Converts a 2D block of cell values (rows of columns) into `PlotData`. */\nexport const toPlotData = (values: PlotValue[][], { header = false }: ToPlotDataOptions = {}): PlotData => {\n const width = values.reduce((max, row) => Math.max(max, row.length), 0);\n const [first, ...rest] = values;\n const columns = Array.from({ length: width }, (_, index) =>\n header && first?.[index] != null ? String(first[index]) : columnName(index),\n );\n\n return { columns, rows: header ? rest : values };\n};\n\n/**\n * Flattens `PlotData` into long form. With a single column the row index is the key;\n * otherwise the first column is the key and each remaining column a series. Non-numeric values are dropped.\n */\nexport const toPlotDatums = ({ columns, rows }: PlotData): PlotDatum[] => {\n if (columns.length === 1) {\n return rows.flatMap((row, index) => {\n const value = toNumber(row[0]);\n return value === undefined ? [] : [{ key: index + 1, series: columns[0], value }];\n });\n }\n\n return rows.flatMap((row) =>\n columns.slice(1).flatMap((series, index) => {\n const value = toNumber(row[index + 1]);\n return value === undefined ? [] : [{ key: row[0], series, value }];\n }),\n );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as ObservablePlot from '@observablehq/plot';\nimport * as d3 from 'd3';\nimport React, { useEffect, useMemo } from 'react';\nimport { useResizeDetector } from 'react-resize-detector';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ThemedClassName } from '@dxos/ui-types';\n\nimport { type PlotData, type PlotDatum, type PlotOptions } from '../../types.ts';\nimport { toPlotDatums } from '../../util/index.ts';\n\nconst MARGIN = 40;\nconst MIN_SIZE = MARGIN * 2;\n\n// Approximate advance of Plot's default 10px sans-serif axis text.\nconst LABEL_CHAR_WIDTH = 6;\n\n/** The width a label of `text` takes on an axis, with room for the tick. */\nconst labelWidth = (text: string) => text.length * LABEL_CHAR_WIDTH + MARGIN / 4;\n\n/** The widest value an axis labels: the largest bar, which for stacked bars is a category's total. */\nconst maxBarValue = (datums: PlotDatum[], stacked: boolean): number => {\n if (!stacked) {\n return Math.max(0, ...datums.map((datum) => datum.value));\n }\n const totals = new Map<PlotDatum['key'], number>();\n for (const datum of datums) {\n totals.set(datum.key, (totals.get(datum.key) ?? 0) + Math.max(0, datum.value));\n }\n return Math.max(0, ...totals.values());\n};\n\n// Plot's tip box defaults to a white fill, while its text follows the theme's currentColor.\nconst TIP = { fill: 'var(--color-modal-surface)', stroke: 'var(--color-separator)' };\n\nexport type PlotProps = ThemedClassName<{\n data: PlotData;\n options: PlotOptions;\n}>;\n\n/** Renders tabular data as a bar, pie, or xy chart sized to its container. */\nexport const Plot = ({ classNames, data, options }: PlotProps) => {\n const { ref: containerRef, width = 0, height = 0 } = useResizeDetector<HTMLDivElement>({ refreshRate: 100 });\n const datums = useMemo(() => toPlotDatums(data), [data]);\n\n useEffect(() => {\n const container = containerRef.current;\n // Below twice the margin the plot frame has a negative extent.\n if (!container || width < MIN_SIZE || height < MIN_SIZE || options.type === 'pie') {\n return;\n }\n\n const label = data.columns[0];\n let plot = createPlot(datums, options, { width, height, label });\n container.append(plot);\n\n // A legend is laid out above an SVG of the full height, pushing the x axis out of view; redraw shorter.\n const overflow = plot.getBoundingClientRect().height - height;\n if (overflow > 0) {\n plot.remove();\n plot = createPlot(datums, options, { width, height: height - overflow, label });\n container.append(plot);\n }\n\n return () => plot.remove();\n }, [data, datums, options, width, height]);\n\n return (\n <div ref={containerRef} role='img' className={mx('relative dx-fill overflow-hidden', classNames)}>\n {options.type === 'pie' && width >= MIN_SIZE && height >= MIN_SIZE && (\n <Pie datums={datums} width={width} height={height} />\n )}\n </div>\n );\n};\n\nPlot.displayName = 'Plot';\n\nconst createPlot = (\n datums: PlotDatum[],\n { type, grid = true, horizontal = false, stacked = false }: PlotOptions,\n { label, ...size }: { width: number; height: number; label?: string },\n): SVGSVGElement | HTMLElement => {\n const series = new Set(datums.map((datum) => datum.series));\n // Ordinal scales sort by default; keep the sheet's row and column order.\n const keys = [...new Set(datums.map((datum) => datum.key))];\n const seriesOrder = [...series];\n const options = {\n ...size,\n grid,\n marginLeft: MARGIN,\n marginBottom: MARGIN,\n style: { background: 'transparent', color: 'currentColor' },\n color: { legend: series.size > 1, domain: seriesOrder },\n y: { label: null },\n };\n\n switch (type) {\n case 'xy':\n return ObservablePlot.plot({\n ...options,\n x: { label },\n marks: [\n ObservablePlot.ruleY([0]),\n ObservablePlot.line(datums, { x: 'key', y: 'value', stroke: 'series' }),\n ObservablePlot.dot(datums, { x: 'key', y: 'value', fill: 'series', r: 3 }),\n ],\n });\n\n case 'bar':\n default: {\n // Several series stand side by side in a facet per category, unless they stack into one bar.\n const grouped = series.size > 1 && !stacked;\n if (horizontal) {\n // Category labels sit left of the frame, so the margin grows with the longest one.\n const marginLeft = Math.max(MARGIN, ...keys.map((key) => labelWidth(String(key))));\n return ObservablePlot.plot({\n ...options,\n marginLeft,\n x: { label: null },\n ...(grouped\n ? { fy: { label: null, domain: keys, axis: 'left' }, y: { axis: null, domain: seriesOrder } }\n : { y: { label: null, domain: keys } }),\n marks: [\n ObservablePlot.ruleX([0]),\n grouped\n ? ObservablePlot.barX(datums, { fy: 'key', y: 'series', x: 'value', fill: 'series', tip: TIP })\n : // One bar per category; with several series, barX stacks them along it.\n ObservablePlot.barX(datums, { y: 'key', x: 'value', fill: 'series', tip: TIP }),\n ],\n });\n }\n\n // The value labels sit left of the frame, so the margin grows with the widest one (the axis groups thousands).\n const marginLeft = Math.max(MARGIN, labelWidth(Math.round(maxBarValue(datums, stacked)).toLocaleString()));\n // Category labels that would overlap side by side are tilted, and the bottom margin grows to hold them.\n const longest = Math.max(0, ...keys.map((key) => labelWidth(String(key))));\n const tilt = longest * keys.length > size.width - marginLeft;\n const tickRotate = tilt ? -45 : 0;\n const marginBottom = tilt ? Math.max(MARGIN, longest * Math.SQRT1_2 + MARGIN / 2) : MARGIN;\n return ObservablePlot.plot({\n ...options,\n marginLeft,\n marginBottom,\n ...(grouped\n ? {\n fx: { label: null, domain: keys, axis: 'bottom', tickRotate },\n x: { axis: null, domain: seriesOrder },\n }\n : { x: { label: null, domain: keys, tickRotate } }),\n marks: [\n ObservablePlot.ruleY([0]),\n grouped\n ? ObservablePlot.barY(datums, { fx: 'key', x: 'series', y: 'value', fill: 'series', tip: TIP })\n : ObservablePlot.barY(datums, { x: 'key', y: 'value', fill: 'series', tip: TIP }),\n ],\n });\n }\n }\n};\n\ntype PieProps = {\n datums: PlotDatum[];\n width: number;\n height: number;\n};\n\n/** Observable Plot has no polar marks, so the pie is drawn directly with d3-shape; the first series is used. */\nconst Pie = ({ datums, width, height }: PieProps) => {\n const radius = Math.max(0, Math.min(width, height) / 2 - MARGIN / 2);\n const slices = useMemo(() => {\n const first = datums[0]?.series;\n const values = datums.filter((datum) => datum.series === first && datum.value > 0);\n return d3\n .pie<PlotDatum>()\n .sort(null)\n .value((datum) => datum.value)(values);\n }, [datums]);\n\n const arc = d3.arc<d3.PieArcDatum<PlotDatum>>().innerRadius(0).outerRadius(radius);\n const label = d3\n .arc<d3.PieArcDatum<PlotDatum>>()\n .innerRadius(radius * 0.65)\n .outerRadius(radius * 0.65);\n const color = d3.scaleOrdinal<string, string>(d3.schemeTableau10);\n\n return (\n <svg width={width} height={height} viewBox={`${-width / 2} ${-height / 2} ${width} ${height}`}>\n {slices.map((slice, index) => (\n <g key={index}>\n <path d={arc(slice) ?? undefined} fill={color(String(slice.data.key))} stroke='var(--color-base-surface)'>\n <title>{`${slice.data.key}: ${slice.data.value}`}</title>\n </path>\n <text\n transform={`translate(${label.centroid(slice)})`}\n textAnchor='middle'\n dominantBaseline='middle'\n fontSize={11}\n fill='white'\n >\n {String(slice.data.key)}\n </text>\n </g>\n ))}\n </svg>\n );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nexport const PlotType = Schema.Literals(['bar', 'pie', 'xy']);\nexport type PlotType = Schema.Schema.Type<typeof PlotType>;\n\nexport const PLOT_TYPES: readonly PlotType[] = PlotType.literals;\n\n/** Presentation options; persisted alongside the data source by the host. */\nexport const PlotOptions = Schema.Struct({\n type: PlotType.annotate({ title: 'Chart type' }),\n /** The first row holds the series names. */\n header: Schema.optional(Schema.Boolean.annotate({ title: 'Header row' })),\n /** Draw grid lines (bar and xy). */\n grid: Schema.optional(Schema.Boolean.annotate({ title: 'Grid lines' })),\n /** Bars run along the x axis, categories down the y axis (bar). */\n horizontal: Schema.optional(Schema.Boolean.annotate({ title: 'Horizontal bars' })),\n /** A category's series stack into one bar rather than standing side by side (bar). */\n stacked: Schema.optional(Schema.Boolean.annotate({ title: 'Stacked bars' })),\n});\n\nexport type PlotOptions = Schema.Schema.Type<typeof PlotOptions>;\n\nexport type PlotValue = string | number | boolean | null;\n\n/**\n * Column-oriented table: the first column is the category (bar, pie) or the x axis (xy);\n * each remaining column is a series.\n */\nexport type PlotData = {\n columns: string[];\n rows: PlotValue[][];\n};\n\n/** One series value in long form, the shape Observable Plot marks consume. */\nexport type PlotDatum = {\n key: PlotValue;\n series: string;\n value: number;\n};\n"],"mappings":";;;;;;;;;AAOA,IAAM,cAAc,UAA0B;CAC5C,IAAI,OAAO;CACX,KAAK,IAAI,YAAY,QAAQ,GAAG,YAAY,GAAG,YAAY,KAAK,OAAO,YAAY,KAAK,EAAE,GACxF,OAAO,OAAO,aAAa,IAAI,WAAW,CAAC,KAAM,YAAY,KAAK,EAAG,IAAI;CAE3E,OAAO;AACT;AAEA,IAAM,YAAY,UAAyC;CACzD,IAAI,OAAO,UAAU,UACnB,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ,KAAA;CAG1C,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,IAAI;EACpD,MAAM,SAAS,OAAO,MAAM,QAAQ,UAAU,EAAE,CAAC;EACjD,OAAO,OAAO,SAAS,MAAM,IAAI,SAAS,KAAA;CAC5C;AAGF;;AAQA,IAAa,cAAc,QAAuB,EAAE,SAAS,UAA6B,CAAC,MAAgB;CACz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,EAAE,OAAO,kBAAkB,CAAC,CAAC;;CAEjF,SAAS,OAAO,SAAS,OAAO,QAAQ,SAAS,EAAE,OAAO,eAAe,CAAC,CAAC;AAC7E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Plot.d.ts","sourceRoot":"","sources":["../../../../../src/components/Plot/Plot.tsx"],"names":[],"mappings":"AAMA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAIlD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,KAAK,QAAQ,EAAkB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AASjF,MAAM,MAAM,SAAS,GAAG,eAAe,CAAC;IACtC,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;CACtB,CAAC,CAAC;6BAGkB,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,SAAS"}
1
+ {"version":3,"file":"Plot.d.ts","sourceRoot":"","sources":["../../../../../src/components/Plot/Plot.tsx"],"names":[],"mappings":"AAMA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAIlD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,KAAK,QAAQ,EAAkB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA2BjF,MAAM,MAAM,SAAS,GAAG,eAAe,CAAC;IACtC,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;CACtB,CAAC,CAAC;6BAGkB,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,SAAS"}
@@ -1,7 +1,7 @@
1
1
  import { type StoryObj } from '@storybook/react-vite';
2
2
  import React from 'react';
3
3
  import { type PlotOptions } from '../../types.ts';
4
- type StoryArgs = Pick<PlotOptions, 'type' | 'grid'>;
4
+ type StoryArgs = Pick<PlotOptions, 'type' | 'grid' | 'horizontal' | 'stacked'>;
5
5
  declare const DefaultStory: (options: StoryArgs) => React.JSX.Element;
6
6
  declare const meta: {
7
7
  title: string;
@@ -24,6 +24,8 @@ declare const meta: {
24
24
  export default meta;
25
25
  type Story = StoryObj<typeof meta>;
26
26
  export declare const Default: Story;
27
+ export declare const Horizontal: Story;
28
+ export declare const Stacked: Story;
27
29
  export declare const Pie: Story;
28
30
  export declare const XY: Story;
29
31
  //# sourceMappingURL=Plot.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Plot.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Plot/Plot.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAe9D,KAAK,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAEpD,QAAA,MAAM,YAAY,YAAa,SAAS,sBAAkE,CAAC;AAE3G,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;QAMM,MAAM;;CACK,CAAC;eAEb,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC;AAEjC,eAAO,MAAM,GAAG,EAAE,KAAiC,CAAC;AAEpD,eAAO,MAAM,EAAE,EAAE,KAAgC,CAAC"}
1
+ {"version":3,"file":"Plot.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Plot/Plot.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAe9D,KAAK,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC,CAAC;AAE/E,QAAA,MAAM,YAAY,YAAa,SAAS,sBAAkE,CAAC;AAE3G,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;QAMM,MAAM;;CACK,CAAC;eAEb,IAAI;AAEnB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC;AAEjC,eAAO,MAAM,UAAU,EAAE,KAIxB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,KAKrB,CAAC;AAEF,eAAO,MAAM,GAAG,EAAE,KAIjB,CAAC;AAEF,eAAO,MAAM,EAAE,EAAE,KAIhB,CAAC"}
@@ -9,6 +9,10 @@ export declare const PlotOptions: Schema.Struct<{
9
9
  readonly header: Schema.optional<Schema.Boolean>;
10
10
  /** Draw grid lines (bar and xy). */
11
11
  readonly grid: Schema.optional<Schema.Boolean>;
12
+ /** Bars run along the x axis, categories down the y axis (bar). */
13
+ readonly horizontal: Schema.optional<Schema.Boolean>;
14
+ /** A category's series stack into one bar rather than standing side by side (bar). */
15
+ readonly stacked: Schema.optional<Schema.Boolean>;
12
16
  }>;
13
17
  export type PlotOptions = Schema.Schema.Type<typeof PlotOptions>;
14
18
  export type PlotValue = string | number | boolean | null;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,eAAO,MAAM,QAAQ,gDAAwC,CAAC;AAC9D,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC,CAAC;AAE3D,eAAO,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAsB,CAAC;AAEjE,6EAA6E;AAC7E,eAAO,MAAM,WAAW;;IAEtB,4CAA4C;;IAE5C,oCAAoC;;EAEpC,CAAC;AAE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