@pixerate/editor-react 0.36.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chart/index.cjs +22 -13
- package/dist/chart/index.cjs.map +1 -1
- package/dist/chart/index.d.cts +13 -6
- package/dist/chart/index.d.ts +13 -6
- package/dist/chart/index.js +58 -712
- package/dist/chart/index.js.map +1 -1
- package/dist/chunk-IH5ZIOK3.js +710 -0
- package/dist/chunk-IH5ZIOK3.js.map +1 -0
- package/dist/index.cjs +674 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -2
- package/dist/index.d.ts +28 -2
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
// src/chart/useChartEditor.ts
|
|
2
|
+
import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import {
|
|
4
|
+
ChartController,
|
|
5
|
+
ChartDirector,
|
|
6
|
+
ChartPresence,
|
|
7
|
+
createChartCommands,
|
|
8
|
+
createChartRasterizer,
|
|
9
|
+
createChartToolProvider,
|
|
10
|
+
layoutChart
|
|
11
|
+
} from "@pixerate/editor/chart";
|
|
12
|
+
function useChartController(options = {}) {
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
if (!ref.current) ref.current = new ChartController(options);
|
|
15
|
+
return ref.current;
|
|
16
|
+
}
|
|
17
|
+
function useChartState(controller) {
|
|
18
|
+
return useSyncExternalStore(controller.subscribe, controller.getState, controller.getState);
|
|
19
|
+
}
|
|
20
|
+
function useChartEditor(controllerOrOptions = {}) {
|
|
21
|
+
const own = useRef(null);
|
|
22
|
+
let controller;
|
|
23
|
+
if (controllerOrOptions instanceof ChartController) controller = controllerOrOptions;
|
|
24
|
+
else {
|
|
25
|
+
if (!own.current) own.current = new ChartController(controllerOrOptions);
|
|
26
|
+
controller = own.current;
|
|
27
|
+
}
|
|
28
|
+
const state = useChartState(controller);
|
|
29
|
+
const actions = useMemo(
|
|
30
|
+
() => ({
|
|
31
|
+
update: (patch) => controller.update(patch),
|
|
32
|
+
setType: (type) => controller.setType(type),
|
|
33
|
+
setValue: (seriesId, index, value) => controller.setValue(seriesId, index, value),
|
|
34
|
+
select: (selection) => controller.select(selection),
|
|
35
|
+
undo: () => void controller.undo(),
|
|
36
|
+
redo: () => void controller.redo()
|
|
37
|
+
}),
|
|
38
|
+
[controller]
|
|
39
|
+
);
|
|
40
|
+
return { controller, state, spec: state.spec, selection: state.selection, ...actions };
|
|
41
|
+
}
|
|
42
|
+
function useChartCommands(registry, controller, options = {}) {
|
|
43
|
+
const { prefix, group, scope } = options;
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!registry) return;
|
|
46
|
+
return registry.register(createChartCommands(controller, { prefix, group, scope }));
|
|
47
|
+
}, [registry, controller, prefix, group, scope]);
|
|
48
|
+
}
|
|
49
|
+
function useChartToolProvider(registry, controller, options = {}) {
|
|
50
|
+
const latest = useRef(options);
|
|
51
|
+
latest.current = options;
|
|
52
|
+
const { id, namespace } = options;
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!registry) return;
|
|
55
|
+
const { rasterize, ...rest } = latest.current;
|
|
56
|
+
return registry.register(createChartToolProvider(controller, { ...rest, id, namespace, rasterize: rasterize === false ? void 0 : rasterize ?? createChartRasterizer() }));
|
|
57
|
+
}, [registry, controller, id, namespace]);
|
|
58
|
+
}
|
|
59
|
+
function useChartDirector(controller, options = {}) {
|
|
60
|
+
const sceneRef = useRef(null);
|
|
61
|
+
const ref = useRef(null);
|
|
62
|
+
if (!ref.current) {
|
|
63
|
+
const presence = new ChartPresence();
|
|
64
|
+
const size = options.size ?? { width: 640, height: 400 };
|
|
65
|
+
const director = new ChartDirector(controller, presence, { scene: () => sceneRef.current ?? layoutChart(controller.getSpec(), size), speed: options.speed });
|
|
66
|
+
ref.current = { presence, director };
|
|
67
|
+
}
|
|
68
|
+
return { ...ref.current, sceneRef };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/chart/ChartCanvas.tsx
|
|
72
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
73
|
+
import {
|
|
74
|
+
CSS_VARIABLE_CHART_THEME,
|
|
75
|
+
chartClientToScene,
|
|
76
|
+
chartTextBaseline,
|
|
77
|
+
chartTextTransform,
|
|
78
|
+
describeChartSelection,
|
|
79
|
+
handleChartKey,
|
|
80
|
+
layoutChart as layoutChart2,
|
|
81
|
+
startChartPointDrag
|
|
82
|
+
} from "@pixerate/editor/chart";
|
|
83
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
84
|
+
function renderChartMark(mark, fontFamily, interactive) {
|
|
85
|
+
const common = {
|
|
86
|
+
"data-role": mark.role,
|
|
87
|
+
"data-chart-key": mark.target ? mark.key : void 0,
|
|
88
|
+
"data-selected": mark.selected ? "" : void 0,
|
|
89
|
+
opacity: mark.opacity,
|
|
90
|
+
pointerEvents: mark.role === "selection" || mark.role === "drag-readout" || !mark.target && mark.role !== "background" ? "none" : void 0,
|
|
91
|
+
cursor: interactive && mark.target && mark.role !== "background" ? "pointer" : void 0
|
|
92
|
+
};
|
|
93
|
+
switch (mark.kind) {
|
|
94
|
+
case "rect":
|
|
95
|
+
return /* @__PURE__ */ jsx("rect", { ...common, x: mark.x, y: mark.y, width: mark.width, height: mark.height, rx: mark.radius, style: { fill: mark.fill, stroke: mark.stroke, strokeWidth: mark.strokeWidth } }, mark.key);
|
|
96
|
+
case "path":
|
|
97
|
+
return /* @__PURE__ */ jsx(
|
|
98
|
+
"path",
|
|
99
|
+
{
|
|
100
|
+
...common,
|
|
101
|
+
d: mark.d,
|
|
102
|
+
strokeLinejoin: "round",
|
|
103
|
+
strokeLinecap: "round",
|
|
104
|
+
strokeDasharray: mark.dash,
|
|
105
|
+
style: { fill: mark.fill ?? "none", stroke: mark.stroke, strokeWidth: mark.strokeWidth }
|
|
106
|
+
},
|
|
107
|
+
mark.key
|
|
108
|
+
);
|
|
109
|
+
case "circle":
|
|
110
|
+
return /* @__PURE__ */ jsx("circle", { ...common, cx: mark.cx, cy: mark.cy, r: mark.r, style: { fill: mark.fill, stroke: mark.stroke, strokeWidth: mark.strokeWidth } }, mark.key);
|
|
111
|
+
case "line":
|
|
112
|
+
return /* @__PURE__ */ jsx("line", { ...common, x1: mark.x1, y1: mark.y1, x2: mark.x2, y2: mark.y2, strokeDasharray: mark.dash, style: { stroke: mark.stroke, strokeWidth: mark.strokeWidth } }, mark.key);
|
|
113
|
+
case "text":
|
|
114
|
+
return /* @__PURE__ */ jsx(
|
|
115
|
+
"text",
|
|
116
|
+
{
|
|
117
|
+
...common,
|
|
118
|
+
x: mark.x,
|
|
119
|
+
y: mark.y,
|
|
120
|
+
textAnchor: mark.anchor,
|
|
121
|
+
dominantBaseline: chartTextBaseline(mark.baseline),
|
|
122
|
+
transform: chartTextTransform(mark),
|
|
123
|
+
style: { fill: mark.fill, fontSize: mark.size, fontWeight: mark.weight, fontFamily, userSelect: "none" },
|
|
124
|
+
children: mark.text
|
|
125
|
+
},
|
|
126
|
+
mark.key
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function ChartPresenceLayer({ presence }) {
|
|
131
|
+
const { actors } = useSyncExternalStore2(presence.subscribe, presence.getState, presence.getState);
|
|
132
|
+
return /* @__PURE__ */ jsx("g", { "data-chart-presence": "", pointerEvents: "none", children: actors.map((a) => /* @__PURE__ */ jsxs("g", { transform: `translate(${a.x} ${a.y})`, "data-actor": a.id, children: [
|
|
133
|
+
/* @__PURE__ */ jsx("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 }, transform: a.pressed ? "scale(0.9)" : void 0 }),
|
|
134
|
+
/* @__PURE__ */ jsxs("g", { transform: "translate(13 16)", children: [
|
|
135
|
+
/* @__PURE__ */ jsx("rect", { x: 0, y: 0, rx: 4, height: 18, width: Math.max(28, (a.message ?? a.name).length * 6.4 + 12), style: { fill: a.color } }),
|
|
136
|
+
/* @__PURE__ */ jsx("text", { x: 6, y: 9, dominantBaseline: "central", style: { fill: "#ffffff", fontSize: 11, fontWeight: 600, fontFamily: "inherit" }, children: a.message ?? a.name })
|
|
137
|
+
] })
|
|
138
|
+
] }, a.id)) });
|
|
139
|
+
}
|
|
140
|
+
function ChartSceneSvg({ scene, label, className }) {
|
|
141
|
+
return /* @__PURE__ */ jsx("svg", { width: scene.width, height: scene.height, viewBox: `0 0 ${scene.width} ${scene.height}`, role: "img", "aria-label": label, className: `block max-w-full ${className ?? ""}`, children: scene.marks.map((m) => renderChartMark(m, scene.theme.fontFamily, false)) });
|
|
142
|
+
}
|
|
143
|
+
function ChartCanvas({ controller, width = 640, height = 400, responsive = true, theme, editable = true, measureText, emptyMessage, className, presence, sceneRef }) {
|
|
144
|
+
const state = useChartState(controller);
|
|
145
|
+
const wrapper = useRef2(null);
|
|
146
|
+
const svg = useRef2(null);
|
|
147
|
+
const drag = useRef2(null);
|
|
148
|
+
const [measured, setMeasured] = useState(null);
|
|
149
|
+
const [frozen, setFrozen] = useState(null);
|
|
150
|
+
useEffect2(() => {
|
|
151
|
+
const el = wrapper.current;
|
|
152
|
+
if (!responsive || !el || typeof ResizeObserver === "undefined") return;
|
|
153
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
154
|
+
const w = Math.round(entry.contentRect.width);
|
|
155
|
+
if (w > 0) setMeasured(w);
|
|
156
|
+
});
|
|
157
|
+
observer.observe(el);
|
|
158
|
+
return () => observer.disconnect();
|
|
159
|
+
}, [responsive]);
|
|
160
|
+
const sceneWidth = responsive && measured || width;
|
|
161
|
+
const fullTheme = useMemo2(() => ({ ...CSS_VARIABLE_CHART_THEME, ...theme }), [theme]);
|
|
162
|
+
const scene = useMemo2(
|
|
163
|
+
() => layoutChart2(state.spec, {
|
|
164
|
+
width: sceneWidth,
|
|
165
|
+
height,
|
|
166
|
+
theme: fullTheme,
|
|
167
|
+
selection: editable ? state.selection : null,
|
|
168
|
+
measureText,
|
|
169
|
+
emptyMessage,
|
|
170
|
+
valueDomain: frozen?.valueDomain,
|
|
171
|
+
valueDomain2: frozen?.valueDomain2,
|
|
172
|
+
xDomain: frozen?.xDomain,
|
|
173
|
+
readout: frozen?.readout
|
|
174
|
+
}),
|
|
175
|
+
[state.spec, state.selection, sceneWidth, height, fullTheme, editable, measureText, emptyMessage, frozen]
|
|
176
|
+
);
|
|
177
|
+
if (sceneRef) sceneRef.current = scene;
|
|
178
|
+
const byKey = useMemo2(() => new Map(scene.marks.map((m) => [m.key, m])), [scene]);
|
|
179
|
+
useEffect2(() => () => drag.current?.end(), []);
|
|
180
|
+
const scenePoint = (e) => chartClientToScene(scene, svg.current.getBoundingClientRect(), e.clientX, e.clientY);
|
|
181
|
+
const onPointerDown = (e) => {
|
|
182
|
+
if (!editable || e.button !== 0) return;
|
|
183
|
+
const key = e.target.closest?.("[data-chart-key]")?.getAttribute("data-chart-key");
|
|
184
|
+
const target = key ? byKey.get(key)?.target : void 0;
|
|
185
|
+
controller.select(target ?? null);
|
|
186
|
+
drag.current = startChartPointDrag(controller, scene, target, scenePoint(e));
|
|
187
|
+
if (drag.current) {
|
|
188
|
+
const d = drag.current;
|
|
189
|
+
setFrozen({ valueDomain: d.valueDomain, valueDomain2: d.valueDomain2 ?? null, xDomain: d.xDomain ?? null, readout: d.target });
|
|
190
|
+
svg.current?.setPointerCapture?.(e.pointerId);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const onPointerMove = (e) => {
|
|
194
|
+
if (drag.current) drag.current.move(scenePoint(e), { fine: e.altKey, lockAxis: e.shiftKey, noSnap: e.ctrlKey || e.metaKey });
|
|
195
|
+
};
|
|
196
|
+
const endDrag = () => {
|
|
197
|
+
drag.current?.end();
|
|
198
|
+
drag.current = null;
|
|
199
|
+
setFrozen(null);
|
|
200
|
+
};
|
|
201
|
+
const onKeyDown = (e) => {
|
|
202
|
+
if (drag.current && e.key === "Escape") {
|
|
203
|
+
drag.current.cancel();
|
|
204
|
+
drag.current = null;
|
|
205
|
+
setFrozen(null);
|
|
206
|
+
e.preventDefault();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (editable && handleChartKey(controller, scene, e)) e.preventDefault();
|
|
210
|
+
};
|
|
211
|
+
const label = state.spec.title || "Chart";
|
|
212
|
+
return /* @__PURE__ */ jsx("div", { ref: wrapper, className: `w-full ${className ?? ""}`, "data-chart-canvas": "", children: /* @__PURE__ */ jsxs(
|
|
213
|
+
"svg",
|
|
214
|
+
{
|
|
215
|
+
ref: svg,
|
|
216
|
+
width: sceneWidth,
|
|
217
|
+
height,
|
|
218
|
+
viewBox: `0 0 ${scene.width} ${scene.height}`,
|
|
219
|
+
role: "img",
|
|
220
|
+
"aria-label": editable ? `${label}. ${describeChartSelection(controller, state.selection)}` : label,
|
|
221
|
+
tabIndex: editable ? 0 : void 0,
|
|
222
|
+
className: "block max-w-full touch-none select-none rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",
|
|
223
|
+
onPointerDown,
|
|
224
|
+
onPointerMove,
|
|
225
|
+
onPointerUp: endDrag,
|
|
226
|
+
onPointerCancel: endDrag,
|
|
227
|
+
onKeyDown,
|
|
228
|
+
children: [
|
|
229
|
+
scene.marks.map((m) => renderChartMark(m, scene.theme.fontFamily, editable)),
|
|
230
|
+
presence && /* @__PURE__ */ jsx(ChartPresenceLayer, { presence })
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
) });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/chart/styles.ts
|
|
237
|
+
var chartInputClass = "h-7 w-full min-w-0 rounded-md border border-input bg-background px-2 text-xs text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50";
|
|
238
|
+
var chartButtonClass = "inline-flex h-7 items-center justify-center gap-1 rounded-md border border-input bg-background px-2 text-xs text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50";
|
|
239
|
+
var chartIconButtonClass = "inline-flex h-6 w-6 shrink-0 items-center justify-center rounded text-xs text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-40";
|
|
240
|
+
var chartSegmentClass = (active) => `inline-flex h-7 flex-1 items-center justify-center rounded px-2 text-xs focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary ${active ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`;
|
|
241
|
+
var chartLabelClass = "text-[11px] font-medium text-muted-foreground";
|
|
242
|
+
var chartSectionClass = "space-y-2 border-b border-border pb-3 last:border-b-0";
|
|
243
|
+
var chartCellClass = "h-7 w-full min-w-[4.5rem] bg-transparent px-2 text-right text-xs tabular-nums text-foreground focus-visible:bg-background focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-primary";
|
|
244
|
+
|
|
245
|
+
// src/chart/ChartDataGrid.tsx
|
|
246
|
+
import { useEffect as useEffect3, useRef as useRef3, useState as useState2 } from "react";
|
|
247
|
+
import { chartColorInputValue, chartSeriesColor, formatChartNumber } from "@pixerate/editor/chart";
|
|
248
|
+
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
249
|
+
function ChartCommitInput({ value, onCommit, onKeyDown, onBlur, ...rest }) {
|
|
250
|
+
const [draft, setDraft] = useState2(value);
|
|
251
|
+
const typing = useRef3(false);
|
|
252
|
+
useEffect3(() => {
|
|
253
|
+
if (!typing.current) setDraft(value);
|
|
254
|
+
}, [value]);
|
|
255
|
+
const commit = () => {
|
|
256
|
+
if (!typing.current) return;
|
|
257
|
+
typing.current = false;
|
|
258
|
+
if (draft === value) return;
|
|
259
|
+
if (onCommit(draft) === false) setDraft(value);
|
|
260
|
+
};
|
|
261
|
+
return /* @__PURE__ */ jsx2(
|
|
262
|
+
"input",
|
|
263
|
+
{
|
|
264
|
+
...rest,
|
|
265
|
+
value: draft,
|
|
266
|
+
onChange: (e) => {
|
|
267
|
+
typing.current = true;
|
|
268
|
+
setDraft(e.currentTarget.value);
|
|
269
|
+
},
|
|
270
|
+
onBlur: (e) => {
|
|
271
|
+
onBlur?.(e);
|
|
272
|
+
commit();
|
|
273
|
+
},
|
|
274
|
+
onKeyDown: (e) => {
|
|
275
|
+
onKeyDown?.(e);
|
|
276
|
+
if (e.defaultPrevented) return;
|
|
277
|
+
if (e.key === "Enter") {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
commit();
|
|
280
|
+
} else if (e.key === "Escape") {
|
|
281
|
+
typing.current = false;
|
|
282
|
+
setDraft(value);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
function ChartDataGrid({ controller, categoryHeader = "Category", readOnly = false, className }) {
|
|
289
|
+
const { spec, selection } = useChartState(controller);
|
|
290
|
+
const paste = (row, column) => (e) => {
|
|
291
|
+
const text = e.clipboardData?.getData("text/plain") ?? "";
|
|
292
|
+
if (!/[\t\n]/.test(text.replace(/\n$/, ""))) return;
|
|
293
|
+
e.preventDefault();
|
|
294
|
+
controller.pasteCells(row, column, text);
|
|
295
|
+
};
|
|
296
|
+
return /* @__PURE__ */ jsxs2("div", { className: `overflow-auto rounded-md border border-border ${className ?? ""}`, "data-chart-grid": "", children: [
|
|
297
|
+
/* @__PURE__ */ jsxs2("table", { className: "w-full border-collapse text-xs", children: [
|
|
298
|
+
/* @__PURE__ */ jsx2("thead", { className: "bg-muted/50", children: /* @__PURE__ */ jsxs2("tr", { children: [
|
|
299
|
+
/* @__PURE__ */ jsx2("th", { className: "border-b border-r border-border px-2 py-1 text-left font-medium text-muted-foreground", children: categoryHeader }),
|
|
300
|
+
spec.series.map((s, si) => {
|
|
301
|
+
const color = chartSeriesColor(spec, si);
|
|
302
|
+
const selected = selection?.kind === "series" && selection.seriesId === s.id;
|
|
303
|
+
return /* @__PURE__ */ jsx2("th", { "data-series-id": s.id, className: `border-b border-r border-border px-1 py-1 font-medium ${selected ? "bg-primary/10" : ""}`, children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-1", children: [
|
|
304
|
+
/* @__PURE__ */ jsx2(
|
|
305
|
+
"input",
|
|
306
|
+
{
|
|
307
|
+
type: "color",
|
|
308
|
+
"aria-label": `${s.name} colour`,
|
|
309
|
+
value: chartColorInputValue(color),
|
|
310
|
+
disabled: readOnly,
|
|
311
|
+
onPointerDown: () => controller.beginGesture(`color:${s.id}`),
|
|
312
|
+
onChange: (e) => controller.updateSeries(s.id, { color: e.currentTarget.value }),
|
|
313
|
+
onBlur: () => controller.endGesture(),
|
|
314
|
+
className: "h-5 w-5 shrink-0 cursor-pointer rounded border-0 bg-transparent p-0"
|
|
315
|
+
}
|
|
316
|
+
),
|
|
317
|
+
/* @__PURE__ */ jsx2(
|
|
318
|
+
ChartCommitInput,
|
|
319
|
+
{
|
|
320
|
+
value: s.name,
|
|
321
|
+
"aria-label": "Series name",
|
|
322
|
+
onFocus: () => controller.select({ kind: "series", seriesId: s.id }),
|
|
323
|
+
onCommit: (name) => void controller.updateSeries(s.id, { name }),
|
|
324
|
+
className: `${chartInputClass} h-6 min-w-[5rem] border-transparent bg-transparent font-medium ${s.hidden ? "text-muted-foreground line-through" : ""}`
|
|
325
|
+
}
|
|
326
|
+
),
|
|
327
|
+
!readOnly && /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
328
|
+
/* @__PURE__ */ jsx2(
|
|
329
|
+
"button",
|
|
330
|
+
{
|
|
331
|
+
type: "button",
|
|
332
|
+
className: chartIconButtonClass,
|
|
333
|
+
title: s.hidden ? "Show series" : "Hide series",
|
|
334
|
+
"aria-label": s.hidden ? `Show ${s.name}` : `Hide ${s.name}`,
|
|
335
|
+
"aria-pressed": !s.hidden,
|
|
336
|
+
"data-action": "toggle-series",
|
|
337
|
+
onClick: () => controller.toggleSeries(s.id),
|
|
338
|
+
children: s.hidden ? "\u25CB" : "\u25CF"
|
|
339
|
+
}
|
|
340
|
+
),
|
|
341
|
+
/* @__PURE__ */ jsx2("button", { type: "button", className: chartIconButtonClass, title: "Delete series", "aria-label": `Delete ${s.name}`, "data-action": "remove-series", onClick: () => controller.removeSeries(s.id), children: "\xD7" })
|
|
342
|
+
] })
|
|
343
|
+
] }) }, s.id);
|
|
344
|
+
}),
|
|
345
|
+
!readOnly && /* @__PURE__ */ jsx2("th", { className: "w-8 border-b border-border px-1", children: /* @__PURE__ */ jsx2("button", { type: "button", className: chartIconButtonClass, title: "Add series", "aria-label": "Add series", "data-action": "add-series", onClick: () => controller.addSeries(), children: "+" }) })
|
|
346
|
+
] }) }),
|
|
347
|
+
/* @__PURE__ */ jsx2("tbody", { children: spec.categories.map((category, i) => {
|
|
348
|
+
const rowSelected = selection?.kind === "category" && selection.index === i;
|
|
349
|
+
return /* @__PURE__ */ jsxs2("tr", { "data-category-index": i, className: rowSelected ? "bg-primary/10" : void 0, children: [
|
|
350
|
+
/* @__PURE__ */ jsx2("th", { className: "border-b border-r border-border p-0 text-left font-normal", children: /* @__PURE__ */ jsx2(
|
|
351
|
+
ChartCommitInput,
|
|
352
|
+
{
|
|
353
|
+
value: category,
|
|
354
|
+
"aria-label": `Category ${i + 1}`,
|
|
355
|
+
onFocus: () => controller.select({ kind: "category", index: i }),
|
|
356
|
+
onPaste: paste(i, -1),
|
|
357
|
+
onCommit: (label) => void controller.renameCategory(i, label),
|
|
358
|
+
className: `${chartCellClass} text-left`
|
|
359
|
+
}
|
|
360
|
+
) }),
|
|
361
|
+
spec.series.map((s) => {
|
|
362
|
+
const value = s.values[i];
|
|
363
|
+
const selected = selection?.kind === "point" && selection.seriesId === s.id && selection.index === i;
|
|
364
|
+
return /* @__PURE__ */ jsx2("td", { className: `border-b border-r border-border p-0 ${selected ? "bg-primary/10" : ""}`, children: /* @__PURE__ */ jsx2(
|
|
365
|
+
ChartCommitInput,
|
|
366
|
+
{
|
|
367
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
368
|
+
inputMode: "decimal",
|
|
369
|
+
"aria-label": `${s.name}, ${category}`,
|
|
370
|
+
title: value === null ? void 0 : formatChartNumber(value, spec.yAxis.format),
|
|
371
|
+
"data-cell": `${s.id}:${i}`,
|
|
372
|
+
onFocus: () => controller.select({ kind: "point", seriesId: s.id, index: i }),
|
|
373
|
+
onPaste: paste(i, spec.series.indexOf(s)),
|
|
374
|
+
onCommit: (text) => controller.setValue(s.id, i, text).ok,
|
|
375
|
+
className: chartCellClass
|
|
376
|
+
}
|
|
377
|
+
) }, s.id);
|
|
378
|
+
}),
|
|
379
|
+
!readOnly && /* @__PURE__ */ jsx2("td", { className: "border-b border-border px-1", children: /* @__PURE__ */ jsx2("button", { type: "button", className: chartIconButtonClass, title: "Delete category", "aria-label": `Delete ${category}`, "data-action": "remove-category", onClick: () => controller.removeCategory(i), children: "\xD7" }) })
|
|
380
|
+
] }, i);
|
|
381
|
+
}) })
|
|
382
|
+
] }),
|
|
383
|
+
!readOnly && /* @__PURE__ */ jsx2("div", { className: "p-1", children: /* @__PURE__ */ jsx2("button", { type: "button", className: `${chartButtonClass} h-6 border-dashed`, "data-action": "add-category", onClick: () => controller.addCategory(), children: "+ Add category" }) })
|
|
384
|
+
] });
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// src/chart/ChartInspector.tsx
|
|
388
|
+
import { useId } from "react";
|
|
389
|
+
import {
|
|
390
|
+
CHART_COLOR_SCHEMES,
|
|
391
|
+
CHART_LABEL_POSITIONS,
|
|
392
|
+
CHART_LAYOUT_PRESETS,
|
|
393
|
+
CHART_MARKERS,
|
|
394
|
+
CHART_TRENDLINE_TYPES,
|
|
395
|
+
checkChartColors,
|
|
396
|
+
chartFamily,
|
|
397
|
+
chartSupportsTrendlines,
|
|
398
|
+
chartTrendlineName,
|
|
399
|
+
CHART_CURVES,
|
|
400
|
+
CHART_LEGEND_POSITIONS,
|
|
401
|
+
CHART_NUMBER_STYLES,
|
|
402
|
+
CHART_SERIES_TYPES,
|
|
403
|
+
CHART_STACKINGS,
|
|
404
|
+
CHART_TYPE_LABELS,
|
|
405
|
+
CHART_TYPES,
|
|
406
|
+
chartColorInputValue as chartColorInputValue2,
|
|
407
|
+
chartSeriesColor as chartSeriesColor2,
|
|
408
|
+
chartSeriesType,
|
|
409
|
+
isCartesianChart
|
|
410
|
+
} from "@pixerate/editor/chart";
|
|
411
|
+
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
412
|
+
var cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
413
|
+
function Field({ label, htmlFor, children }) {
|
|
414
|
+
return /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2", children: [
|
|
415
|
+
/* @__PURE__ */ jsx3("label", { htmlFor, className: `${chartLabelClass} w-20 shrink-0`, children: label }),
|
|
416
|
+
/* @__PURE__ */ jsx3("div", { className: "min-w-0 flex-1", children })
|
|
417
|
+
] });
|
|
418
|
+
}
|
|
419
|
+
function Toggle({ label, checked, onChange, name }) {
|
|
420
|
+
return /* @__PURE__ */ jsxs3("label", { className: "flex cursor-pointer items-center gap-2 text-xs text-foreground", children: [
|
|
421
|
+
/* @__PURE__ */ jsx3("input", { type: "checkbox", className: "h-3.5 w-3.5 accent-primary", checked, "data-option": name, onChange: (e) => onChange(e.currentTarget.checked) }),
|
|
422
|
+
label
|
|
423
|
+
] });
|
|
424
|
+
}
|
|
425
|
+
function Select({ id, value, options, onChange, name, labels }) {
|
|
426
|
+
return /* @__PURE__ */ jsx3("select", { id, className: chartInputClass, value, "data-option": name, onChange: (e) => onChange(e.currentTarget.value), children: options.map((o) => /* @__PURE__ */ jsx3("option", { value: o, children: labels?.[o] ?? cap(o) }, o)) });
|
|
427
|
+
}
|
|
428
|
+
function AxisSection({ controller, axis, value, idBase, horizontal, numeric = false }) {
|
|
429
|
+
const set = (patch) => controller.setAxis(axis, patch);
|
|
430
|
+
const setFormat = (patch) => set({ format: { ...value.format, ...patch } });
|
|
431
|
+
const bound = (key2) => /* @__PURE__ */ jsx3(
|
|
432
|
+
ChartCommitInput,
|
|
433
|
+
{
|
|
434
|
+
id: `${idBase}-${axis}-${key2}`,
|
|
435
|
+
value: value[key2] === null ? "" : String(value[key2]),
|
|
436
|
+
placeholder: "Auto",
|
|
437
|
+
inputMode: "decimal",
|
|
438
|
+
"data-option": `${axis}Axis.${key2}`,
|
|
439
|
+
className: chartInputClass,
|
|
440
|
+
onCommit: (text) => set({ [key2]: text.trim() === "" ? null : Number(text) }).ok
|
|
441
|
+
}
|
|
442
|
+
);
|
|
443
|
+
const name = axis === "x" ? numeric ? "X axis" : "Category axis" : axis === "y" ? "Value axis" : "Secondary axis";
|
|
444
|
+
const valueAxis = axis !== "x" || numeric;
|
|
445
|
+
const key = axis === "y2" ? "yAxis2" : `${axis}Axis`;
|
|
446
|
+
return /* @__PURE__ */ jsxs3("div", { className: chartSectionClass, "data-section": `axis-${axis}`, children: [
|
|
447
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between", children: [
|
|
448
|
+
/* @__PURE__ */ jsxs3("h4", { className: "text-xs font-semibold text-foreground", children: [
|
|
449
|
+
name,
|
|
450
|
+
/* @__PURE__ */ jsxs3("span", { className: "ml-1 font-normal text-muted-foreground", children: [
|
|
451
|
+
"(",
|
|
452
|
+
axis === "x" ? horizontal ? "left" : "bottom" : axis === "y2" ? horizontal ? "top" : "right" : horizontal ? "bottom" : "left",
|
|
453
|
+
")"
|
|
454
|
+
] })
|
|
455
|
+
] }),
|
|
456
|
+
/* @__PURE__ */ jsx3(Toggle, { label: "Show", name: `${axis}Axis.show`, checked: value.show, onChange: (show) => set({ show }) })
|
|
457
|
+
] }),
|
|
458
|
+
/* @__PURE__ */ jsx3(Field, { label: "Title", htmlFor: `${idBase}-${axis}-title`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-${axis}-title`, value: value.title, "data-option": `${axis}Axis.title`, className: chartInputClass, onCommit: (title) => void set({ title }) }) }),
|
|
459
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
460
|
+
/* @__PURE__ */ jsx3(Toggle, { label: "Grid lines", name: `${key}.gridlines`, checked: value.gridlines, onChange: (gridlines) => set({ gridlines }) }),
|
|
461
|
+
axis === "x" && !numeric && /* @__PURE__ */ jsx3(Toggle, { label: "Dates", name: "xAxis.kind", checked: value.kind === "date", onChange: (dates) => set({ kind: dates ? "date" : void 0 }) })
|
|
462
|
+
] }),
|
|
463
|
+
valueAxis && /* @__PURE__ */ jsx3(Field, { label: "Step", htmlFor: `${idBase}-${axis}-step`, children: /* @__PURE__ */ jsx3(
|
|
464
|
+
ChartCommitInput,
|
|
465
|
+
{
|
|
466
|
+
id: `${idBase}-${axis}-step`,
|
|
467
|
+
value: value.step === null ? "" : String(value.step),
|
|
468
|
+
placeholder: "Auto",
|
|
469
|
+
inputMode: "decimal",
|
|
470
|
+
"data-option": `${key}.step`,
|
|
471
|
+
className: chartInputClass,
|
|
472
|
+
onCommit: (text) => set({ step: text.trim() === "" ? null : Number(text) }).ok
|
|
473
|
+
}
|
|
474
|
+
) }),
|
|
475
|
+
valueAxis && /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
476
|
+
/* @__PURE__ */ jsx3(Field, { label: "Min / max", children: /* @__PURE__ */ jsxs3("div", { className: "flex gap-1", children: [
|
|
477
|
+
bound("min"),
|
|
478
|
+
bound("max")
|
|
479
|
+
] }) }),
|
|
480
|
+
/* @__PURE__ */ jsx3(Field, { label: "Format", htmlFor: `${idBase}-${axis}-format`, children: /* @__PURE__ */ jsxs3("div", { className: "flex gap-1", children: [
|
|
481
|
+
/* @__PURE__ */ jsx3(Select, { id: `${idBase}-${axis}-format`, name: `${key}.format.style`, value: value.format.style ?? "number", options: CHART_NUMBER_STYLES, onChange: (style) => setFormat({ style }) }),
|
|
482
|
+
/* @__PURE__ */ jsx3(
|
|
483
|
+
ChartCommitInput,
|
|
484
|
+
{
|
|
485
|
+
value: value.format.decimals === void 0 ? "" : String(value.format.decimals),
|
|
486
|
+
placeholder: "Auto",
|
|
487
|
+
"aria-label": "Decimals",
|
|
488
|
+
title: "Decimals",
|
|
489
|
+
inputMode: "numeric",
|
|
490
|
+
"data-option": `${key}.format.decimals`,
|
|
491
|
+
className: `${chartInputClass} w-14 shrink-0`,
|
|
492
|
+
onCommit: (text) => {
|
|
493
|
+
const format = { ...value.format };
|
|
494
|
+
if (text.trim() === "") delete format.decimals;
|
|
495
|
+
else format.decimals = Number(text);
|
|
496
|
+
return set({ format }).ok;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
)
|
|
500
|
+
] }) }),
|
|
501
|
+
value.format.style === "currency" && /* @__PURE__ */ jsx3(Field, { label: "Currency", htmlFor: `${idBase}-${axis}-currency`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-${axis}-currency`, value: value.format.currency ?? "USD", "data-option": `${key}.format.currency`, className: chartInputClass, onCommit: (currency) => void setFormat({ currency: currency.toUpperCase() }) }) }),
|
|
502
|
+
/* @__PURE__ */ jsx3(Field, { label: "Code", htmlFor: `${idBase}-${axis}-code`, children: /* @__PURE__ */ jsx3(
|
|
503
|
+
ChartCommitInput,
|
|
504
|
+
{
|
|
505
|
+
id: `${idBase}-${axis}-code`,
|
|
506
|
+
value: value.format.code ?? "",
|
|
507
|
+
placeholder: 'e.g. #,##0.0,,"M"',
|
|
508
|
+
"data-option": `${key}.format.code`,
|
|
509
|
+
className: chartInputClass,
|
|
510
|
+
onCommit: (code) => {
|
|
511
|
+
const format = { ...value.format };
|
|
512
|
+
if (code.trim()) format.code = code.trim();
|
|
513
|
+
else delete format.code;
|
|
514
|
+
return set({ format }).ok;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
) })
|
|
518
|
+
] })
|
|
519
|
+
] });
|
|
520
|
+
}
|
|
521
|
+
function ChartInspector({ controller, sections, className }) {
|
|
522
|
+
const { spec, selectedSeries } = useChartState(controller);
|
|
523
|
+
const idBase = useId();
|
|
524
|
+
const show = (section) => !sections || sections.includes(section);
|
|
525
|
+
const cartesian = isCartesianChart(spec.type);
|
|
526
|
+
const family = chartFamily(spec);
|
|
527
|
+
const hasAxes = family === "cartesian" || family === "xy" || family === "waterfall" || family === "histogram" || family === "box";
|
|
528
|
+
const types = spec.series.map((s) => chartSeriesType(spec, s));
|
|
529
|
+
const usesSecondary = family === "cartesian" && spec.series.some((s) => s.axis === "secondary" && !s.hidden);
|
|
530
|
+
const colorCheck = checkChartColors(spec.series.filter((s) => !s.hidden).map((s) => chartSeriesColor2(spec, spec.series.indexOf(s))));
|
|
531
|
+
const hasBars = cartesian && types.includes("bar");
|
|
532
|
+
const hasLines = cartesian && types.some((t) => t === "line" || t === "area");
|
|
533
|
+
const seriesIndex = selectedSeries ? spec.series.findIndex((s) => s.id === selectedSeries.id) : -1;
|
|
534
|
+
return /* @__PURE__ */ jsxs3("div", { className: `space-y-3 text-xs ${className ?? ""}`, "data-chart-inspector": "", children: [
|
|
535
|
+
show("type") && /* @__PURE__ */ jsx3("div", { className: chartSectionClass, "data-section": "type", children: /* @__PURE__ */ jsx3("div", { className: "grid grid-cols-3 gap-0.5 rounded-md bg-muted p-0.5", role: "radiogroup", "aria-label": "Chart type", children: CHART_TYPES.map((type) => /* @__PURE__ */ jsx3("button", { type: "button", role: "radio", "aria-checked": spec.type === type, "data-chart-type": type, className: chartSegmentClass(spec.type === type), onClick: () => controller.setType(type), children: CHART_TYPE_LABELS[type] }, type)) }) }),
|
|
536
|
+
show("style") && /* @__PURE__ */ jsxs3("div", { className: chartSectionClass, "data-section": "style", children: [
|
|
537
|
+
/* @__PURE__ */ jsx3(Field, { label: "Layout", htmlFor: `${idBase}-layout`, children: /* @__PURE__ */ jsxs3("select", { id: `${idBase}-layout`, className: chartInputClass, value: "", "data-option": "preset.layout", onChange: (e) => e.currentTarget.value && controller.applyPreset({ layout: e.currentTarget.value }), children: [
|
|
538
|
+
/* @__PURE__ */ jsx3("option", { value: "", children: "Quick layout\u2026" }),
|
|
539
|
+
CHART_LAYOUT_PRESETS.map((p) => /* @__PURE__ */ jsx3("option", { value: p.id, title: p.description, children: p.label }, p.id))
|
|
540
|
+
] }) }),
|
|
541
|
+
/* @__PURE__ */ jsx3(Field, { label: "Colours", htmlFor: `${idBase}-colors`, children: /* @__PURE__ */ jsxs3("select", { id: `${idBase}-colors`, className: chartInputClass, value: CHART_COLOR_SCHEMES.find((c) => c.palette.join() === spec.palette.join())?.id ?? "", "data-option": "preset.colors", onChange: (e) => e.currentTarget.value && controller.applyPreset({ colors: e.currentTarget.value }), children: [
|
|
542
|
+
/* @__PURE__ */ jsx3("option", { value: "", children: "Custom" }),
|
|
543
|
+
CHART_COLOR_SCHEMES.map((c) => /* @__PURE__ */ jsx3("option", { value: c.id, title: c.description, children: c.label }, c.id))
|
|
544
|
+
] }) }),
|
|
545
|
+
!colorCheck.ok && /* @__PURE__ */ jsx3("p", { className: "text-[11px] leading-snug text-amber-600 dark:text-amber-400", "data-chart-color-warning": "", children: colorCheck.issues[0] }),
|
|
546
|
+
/* @__PURE__ */ jsx3("button", { type: "button", className: chartButtonClass, "data-action": "transpose", onClick: () => controller.transpose(), children: "Switch rows and columns" })
|
|
547
|
+
] }),
|
|
548
|
+
show("titles") && /* @__PURE__ */ jsxs3("div", { className: chartSectionClass, "data-section": "titles", children: [
|
|
549
|
+
/* @__PURE__ */ jsx3(Field, { label: "Title", htmlFor: `${idBase}-title`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-title`, value: spec.title, "data-option": "title", className: chartInputClass, onCommit: (title) => void controller.setTitle(title) }) }),
|
|
550
|
+
/* @__PURE__ */ jsx3(Field, { label: "Subtitle", htmlFor: `${idBase}-subtitle`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-subtitle`, value: spec.subtitle, "data-option": "subtitle", className: chartInputClass, onCommit: (subtitle) => void controller.setSubtitle(subtitle) }) })
|
|
551
|
+
] }),
|
|
552
|
+
show("options") && /* @__PURE__ */ jsxs3("div", { className: chartSectionClass, "data-section": "options", children: [
|
|
553
|
+
cartesian && /* @__PURE__ */ jsx3(Field, { label: "Stacking", htmlFor: `${idBase}-stacking`, children: /* @__PURE__ */ jsx3(Select, { id: `${idBase}-stacking`, name: "stacking", value: spec.stacking, options: CHART_STACKINGS, labels: { none: "None", stacked: "Stacked", percent: "100%" }, onChange: (stacking) => controller.update({ stacking }) }) }),
|
|
554
|
+
hasBars && /* @__PURE__ */ jsx3(Field, { label: "Bars", children: /* @__PURE__ */ jsx3("div", { className: "flex gap-0.5 rounded-md bg-muted p-0.5", children: ["vertical", "horizontal"].map((o) => /* @__PURE__ */ jsx3("button", { type: "button", "aria-pressed": spec.orientation === o, "data-option": `orientation.${o}`, className: chartSegmentClass(spec.orientation === o), onClick: () => controller.update({ orientation: o }), children: cap(o) }, o)) }) }),
|
|
555
|
+
hasLines && /* @__PURE__ */ jsx3(Field, { label: "Lines", htmlFor: `${idBase}-curve`, children: /* @__PURE__ */ jsx3(Select, { id: `${idBase}-curve`, name: "curve", value: spec.curve, options: CHART_CURVES, onChange: (curve) => controller.update({ curve }) }) }),
|
|
556
|
+
spec.type === "donut" && /* @__PURE__ */ jsx3(Field, { label: "Hole", htmlFor: `${idBase}-hole`, children: /* @__PURE__ */ jsx3(
|
|
557
|
+
"input",
|
|
558
|
+
{
|
|
559
|
+
id: `${idBase}-hole`,
|
|
560
|
+
type: "range",
|
|
561
|
+
min: 0,
|
|
562
|
+
max: 0.9,
|
|
563
|
+
step: 0.05,
|
|
564
|
+
value: spec.innerRadius,
|
|
565
|
+
"data-option": "innerRadius",
|
|
566
|
+
className: "w-full accent-primary",
|
|
567
|
+
onPointerDown: () => controller.beginGesture("innerRadius"),
|
|
568
|
+
onPointerUp: () => controller.endGesture(),
|
|
569
|
+
onChange: (e) => controller.update({ innerRadius: Number(e.currentTarget.value) })
|
|
570
|
+
}
|
|
571
|
+
) }),
|
|
572
|
+
hasBars && /* @__PURE__ */ jsx3(Field, { label: "Spacing", htmlFor: `${idBase}-gap`, children: /* @__PURE__ */ jsx3(
|
|
573
|
+
"input",
|
|
574
|
+
{
|
|
575
|
+
id: `${idBase}-gap`,
|
|
576
|
+
type: "range",
|
|
577
|
+
min: 0,
|
|
578
|
+
max: 0.9,
|
|
579
|
+
step: 0.02,
|
|
580
|
+
value: spec.gapWidth,
|
|
581
|
+
"data-option": "gapWidth",
|
|
582
|
+
className: "w-full accent-primary",
|
|
583
|
+
onPointerDown: () => controller.beginGesture("gapWidth"),
|
|
584
|
+
onPointerUp: () => controller.endGesture(),
|
|
585
|
+
onChange: (e) => controller.update({ gapWidth: Number(e.currentTarget.value) })
|
|
586
|
+
}
|
|
587
|
+
) }),
|
|
588
|
+
spec.dataLabels && hasBars && /* @__PURE__ */ jsx3(Field, { label: "Labels", htmlFor: `${idBase}-label-position`, children: /* @__PURE__ */ jsx3(Select, { id: `${idBase}-label-position`, name: "labelPosition", value: spec.labelPosition, options: CHART_LABEL_POSITIONS, onChange: (labelPosition) => controller.update({ labelPosition }) }) }),
|
|
589
|
+
spec.type === "histogram" && /* @__PURE__ */ jsx3(Field, { label: "Bins", htmlFor: `${idBase}-bins`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-bins`, value: spec.bins === null ? "" : String(spec.bins), placeholder: "Auto", inputMode: "numeric", "data-option": "bins", className: chartInputClass, onCommit: (text) => controller.update({ bins: text.trim() === "" ? null : Number(text) }).ok }) }),
|
|
590
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap gap-x-4 gap-y-1", children: [
|
|
591
|
+
spec.type === "waterfall" && /* @__PURE__ */ jsx3(Toggle, { label: "Total bar", name: "showTotal", checked: spec.showTotal, onChange: (showTotal) => controller.update({ showTotal }) }),
|
|
592
|
+
hasLines && /* @__PURE__ */ jsx3(Toggle, { label: "Points", name: "points", checked: spec.points, onChange: (points) => controller.update({ points }) }),
|
|
593
|
+
/* @__PURE__ */ jsx3(Toggle, { label: "Data labels", name: "dataLabels", checked: spec.dataLabels, onChange: (dataLabels) => controller.update({ dataLabels }) })
|
|
594
|
+
] })
|
|
595
|
+
] }),
|
|
596
|
+
show("legend") && /* @__PURE__ */ jsxs3("div", { className: chartSectionClass, "data-section": "legend", children: [
|
|
597
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between", children: [
|
|
598
|
+
/* @__PURE__ */ jsx3("h4", { className: "text-xs font-semibold text-foreground", children: "Legend" }),
|
|
599
|
+
/* @__PURE__ */ jsx3(Toggle, { label: "Show", name: "legend.show", checked: spec.legend.show, onChange: (v) => controller.setLegend({ show: v }) })
|
|
600
|
+
] }),
|
|
601
|
+
spec.legend.show && /* @__PURE__ */ jsx3("div", { className: "flex gap-0.5 rounded-md bg-muted p-0.5", children: CHART_LEGEND_POSITIONS.map((p) => /* @__PURE__ */ jsx3("button", { type: "button", "aria-pressed": spec.legend.position === p, "data-option": `legend.${p}`, className: chartSegmentClass(spec.legend.position === p), onClick: () => controller.setLegend({ position: p }), children: cap(p) }, p)) })
|
|
602
|
+
] }),
|
|
603
|
+
show("axes") && hasAxes && /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
604
|
+
family !== "box" && family !== "histogram" && /* @__PURE__ */ jsx3(AxisSection, { controller, axis: "x", value: spec.xAxis, idBase, horizontal: spec.orientation === "horizontal", numeric: family === "xy" }),
|
|
605
|
+
/* @__PURE__ */ jsx3(AxisSection, { controller, axis: "y", value: spec.yAxis, idBase, horizontal: spec.orientation === "horizontal" }),
|
|
606
|
+
usesSecondary && /* @__PURE__ */ jsx3(AxisSection, { controller, axis: "y2", value: spec.yAxis2, idBase, horizontal: spec.orientation === "horizontal" })
|
|
607
|
+
] }),
|
|
608
|
+
show("series") && selectedSeries && /* @__PURE__ */ jsxs3("div", { className: chartSectionClass, "data-section": "series", "data-series-id": selectedSeries.id, children: [
|
|
609
|
+
/* @__PURE__ */ jsx3("h4", { className: "text-xs font-semibold text-foreground", children: "Series" }),
|
|
610
|
+
/* @__PURE__ */ jsx3(Field, { label: "Name", htmlFor: `${idBase}-series-name`, children: /* @__PURE__ */ jsx3(ChartCommitInput, { id: `${idBase}-series-name`, value: selectedSeries.name, "data-option": "series.name", className: chartInputClass, onCommit: (name) => void controller.updateSeries(selectedSeries.id, { name }) }) }),
|
|
611
|
+
/* @__PURE__ */ jsx3(Field, { label: "Colour", htmlFor: `${idBase}-series-color`, children: /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-1", children: [
|
|
612
|
+
/* @__PURE__ */ jsx3(
|
|
613
|
+
"input",
|
|
614
|
+
{
|
|
615
|
+
id: `${idBase}-series-color`,
|
|
616
|
+
type: "color",
|
|
617
|
+
value: chartColorInputValue2(chartSeriesColor2(spec, seriesIndex)),
|
|
618
|
+
"data-option": "series.color",
|
|
619
|
+
className: "h-7 w-9 shrink-0 cursor-pointer rounded border border-input bg-background p-0.5",
|
|
620
|
+
onPointerDown: () => controller.beginGesture(`color:${selectedSeries.id}`),
|
|
621
|
+
onBlur: () => controller.endGesture(),
|
|
622
|
+
onChange: (e) => controller.updateSeries(selectedSeries.id, { color: e.currentTarget.value })
|
|
623
|
+
}
|
|
624
|
+
),
|
|
625
|
+
selectedSeries.color && /* @__PURE__ */ jsx3("button", { type: "button", className: chartButtonClass, "data-action": "reset-color", onClick: () => controller.updateSeries(selectedSeries.id, { color: null }), children: "Palette" })
|
|
626
|
+
] }) }),
|
|
627
|
+
cartesian && /* @__PURE__ */ jsx3(Field, { label: "Draw as", htmlFor: `${idBase}-series-type`, children: /* @__PURE__ */ jsxs3(
|
|
628
|
+
"select",
|
|
629
|
+
{
|
|
630
|
+
id: `${idBase}-series-type`,
|
|
631
|
+
className: chartInputClass,
|
|
632
|
+
value: selectedSeries.type ?? "",
|
|
633
|
+
"data-option": "series.type",
|
|
634
|
+
onChange: (e) => controller.updateSeries(selectedSeries.id, { type: e.currentTarget.value || null }),
|
|
635
|
+
children: [
|
|
636
|
+
/* @__PURE__ */ jsx3("option", { value: "", children: "Chart type" }),
|
|
637
|
+
CHART_SERIES_TYPES.map((t) => /* @__PURE__ */ jsx3("option", { value: t, children: CHART_TYPE_LABELS[t] }, t))
|
|
638
|
+
]
|
|
639
|
+
}
|
|
640
|
+
) }),
|
|
641
|
+
(cartesian || family === "xy") && ["line", "area", "scatter"].includes(chartSeriesType(spec, selectedSeries)) && /* @__PURE__ */ jsx3(Field, { label: "Marker", htmlFor: `${idBase}-series-marker`, children: /* @__PURE__ */ jsxs3(
|
|
642
|
+
"select",
|
|
643
|
+
{
|
|
644
|
+
id: `${idBase}-series-marker`,
|
|
645
|
+
className: chartInputClass,
|
|
646
|
+
value: selectedSeries.marker ?? "",
|
|
647
|
+
"data-option": "series.marker",
|
|
648
|
+
onChange: (e) => controller.updateSeries(selectedSeries.id, { marker: e.currentTarget.value || null }),
|
|
649
|
+
children: [
|
|
650
|
+
/* @__PURE__ */ jsx3("option", { value: "", children: "Default" }),
|
|
651
|
+
CHART_MARKERS.map((m) => /* @__PURE__ */ jsx3("option", { value: m, children: cap(m) }, m))
|
|
652
|
+
]
|
|
653
|
+
}
|
|
654
|
+
) }),
|
|
655
|
+
chartSupportsTrendlines(spec.type, spec.stacking) && /* @__PURE__ */ jsxs3("div", { className: "space-y-1", "data-section": "trendlines", children: [
|
|
656
|
+
(selectedSeries.trendlines ?? []).map((t, i) => /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-1", "data-trendline": i, children: [
|
|
657
|
+
/* @__PURE__ */ jsx3("span", { className: "flex-1 truncate text-muted-foreground", children: chartTrendlineName(t, selectedSeries.name) }),
|
|
658
|
+
/* @__PURE__ */ jsx3(Toggle, { label: "R\xB2", name: `trendline.${i}.showR2`, checked: !!t.showR2, onChange: (showR2) => controller.updateTrendline(selectedSeries.id, i, { showR2 }) }),
|
|
659
|
+
/* @__PURE__ */ jsx3("button", { type: "button", className: chartButtonClass, "aria-label": "Delete trendline", "data-action": "trendline-delete", onClick: () => controller.removeTrendline(selectedSeries.id, i), children: "\xD7" })
|
|
660
|
+
] }, i)),
|
|
661
|
+
/* @__PURE__ */ jsxs3(
|
|
662
|
+
"select",
|
|
663
|
+
{
|
|
664
|
+
className: chartInputClass,
|
|
665
|
+
value: "",
|
|
666
|
+
"aria-label": "Add trendline",
|
|
667
|
+
"data-option": "trendline.add",
|
|
668
|
+
onChange: (e) => e.currentTarget.value && controller.addTrendline(selectedSeries.id, { type: e.currentTarget.value }),
|
|
669
|
+
children: [
|
|
670
|
+
/* @__PURE__ */ jsx3("option", { value: "", children: "Add trendline\u2026" }),
|
|
671
|
+
CHART_TRENDLINE_TYPES.map((t) => /* @__PURE__ */ jsx3("option", { value: t, children: cap(t.replace("-", " ")) }, t))
|
|
672
|
+
]
|
|
673
|
+
}
|
|
674
|
+
)
|
|
675
|
+
] }),
|
|
676
|
+
/* @__PURE__ */ jsxs3("div", { className: "flex flex-wrap items-center gap-1", children: [
|
|
677
|
+
/* @__PURE__ */ jsx3(Toggle, { label: "Hidden", name: "series.hidden", checked: !!selectedSeries.hidden, onChange: (hidden) => controller.updateSeries(selectedSeries.id, { hidden }) }),
|
|
678
|
+
family === "cartesian" && /* @__PURE__ */ jsx3(Toggle, { label: "Secondary axis", name: "series.axis", checked: selectedSeries.axis === "secondary", onChange: (secondary) => controller.updateSeries(selectedSeries.id, { axis: secondary ? "secondary" : null }) }),
|
|
679
|
+
/* @__PURE__ */ jsx3("span", { className: "flex-1" }),
|
|
680
|
+
/* @__PURE__ */ jsx3("button", { type: "button", className: chartButtonClass, disabled: seriesIndex <= 0, "aria-label": "Move series earlier", "data-action": "series-up", onClick: () => controller.moveSeries(selectedSeries.id, seriesIndex - 1), children: "\u2191" }),
|
|
681
|
+
/* @__PURE__ */ jsx3("button", { type: "button", className: chartButtonClass, disabled: seriesIndex >= spec.series.length - 1, "aria-label": "Move series later", "data-action": "series-down", onClick: () => controller.moveSeries(selectedSeries.id, seriesIndex + 1), children: "\u2193" }),
|
|
682
|
+
/* @__PURE__ */ jsx3("button", { type: "button", className: `${chartButtonClass} text-destructive`, "data-action": "series-delete", onClick: () => controller.removeSeries(selectedSeries.id), children: "Delete" })
|
|
683
|
+
] })
|
|
684
|
+
] })
|
|
685
|
+
] });
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
export {
|
|
689
|
+
useChartController,
|
|
690
|
+
useChartState,
|
|
691
|
+
useChartEditor,
|
|
692
|
+
useChartCommands,
|
|
693
|
+
useChartToolProvider,
|
|
694
|
+
useChartDirector,
|
|
695
|
+
renderChartMark,
|
|
696
|
+
ChartPresenceLayer,
|
|
697
|
+
ChartSceneSvg,
|
|
698
|
+
ChartCanvas,
|
|
699
|
+
chartInputClass,
|
|
700
|
+
chartButtonClass,
|
|
701
|
+
chartIconButtonClass,
|
|
702
|
+
chartSegmentClass,
|
|
703
|
+
chartLabelClass,
|
|
704
|
+
chartSectionClass,
|
|
705
|
+
chartCellClass,
|
|
706
|
+
ChartCommitInput,
|
|
707
|
+
ChartDataGrid,
|
|
708
|
+
ChartInspector
|
|
709
|
+
};
|
|
710
|
+
//# sourceMappingURL=chunk-IH5ZIOK3.js.map
|