@marimo-team/frontend 0.23.1 → 0.23.2-dev1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.html CHANGED
@@ -66,7 +66,7 @@
66
66
  <marimo-server-token data-token="{{ server_token }}" hidden></marimo-server-token>
67
67
  <!-- /TODO -->
68
68
  <title>{{ title }}</title>
69
- <script type="module" crossorigin src="./assets/index-y6osgSWB.js"></script>
69
+ <script type="module" crossorigin src="./assets/index-ThWddW3f.js"></script>
70
70
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-D2MJg03u.js">
71
71
  <link rel="modulepreload" crossorigin href="./assets/chunk-LvLJmgfZ.js">
72
72
  <link rel="modulepreload" crossorigin href="./assets/react-Bj1aDYRI.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/frontend",
3
- "version": "0.23.1",
3
+ "version": "0.23.2-dev1",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -112,6 +112,56 @@ describe("PlotlyPlugin", () => {
112
112
  });
113
113
  });
114
114
 
115
+ it("clicking a box element triggers onClick", async () => {
116
+ const setValue = vi.fn<Setter<unknown>>();
117
+
118
+ render(
119
+ <Suspense fallback={null}>
120
+ <PlotlyComponent
121
+ figure={{
122
+ data: [{ type: "box" }],
123
+ layout: {},
124
+ frames: null,
125
+ }}
126
+ value={undefined}
127
+ setValue={setValue}
128
+ host={document.createElement("div")}
129
+ config={{}}
130
+ />
131
+ </Suspense>,
132
+ );
133
+
134
+ await waitFor(() => {
135
+ expect(capturedPlotProps).not.toBeNull();
136
+ });
137
+
138
+ act(() => {
139
+ capturedPlotProps?.onClick?.({
140
+ points: [
141
+ {
142
+ data: { type: "box" },
143
+ x: "Group A",
144
+ y: 3,
145
+ pointIndex: 0,
146
+ pointNumber: 0,
147
+ curveNumber: 0,
148
+ },
149
+ ],
150
+ });
151
+ });
152
+
153
+ expect(setValue).toHaveBeenCalledTimes(1);
154
+ const updater = setValue.mock.calls[0][0] as (value: unknown) => unknown;
155
+ expect(updater({})).toEqual({
156
+ selections: [],
157
+ points: [
158
+ { x: "Group A", y: 3, curveNumber: 0, pointNumber: 0, pointIndex: 0 },
159
+ ],
160
+ indices: [0],
161
+ range: undefined,
162
+ });
163
+ });
164
+
115
165
  it("clicking a violin element triggers onClick", async () => {
116
166
  const setValue = vi.fn<Setter<unknown>>();
117
167
 
@@ -102,6 +102,14 @@ describe("shouldHandleClickSelection", () => {
102
102
  expect(shouldHandleClickSelection([heatmapPoint])).toBe(true);
103
103
  });
104
104
 
105
+ it("accepts box clicks", () => {
106
+ const boxPoint = createPlotDatum({
107
+ data: { type: "box" },
108
+ });
109
+
110
+ expect(shouldHandleClickSelection([boxPoint])).toBe(true);
111
+ });
112
+
105
113
  it("accepts violin clicks", () => {
106
114
  const violinPoint = createPlotDatum({
107
115
  data: { type: "violin" },
@@ -126,6 +134,22 @@ describe("shouldHandleClickSelection", () => {
126
134
  expect(shouldHandleClickSelection([linePoint])).toBe(true);
127
135
  });
128
136
 
137
+ it("accepts funnel clicks", () => {
138
+ const funnelPoint = createPlotDatum({
139
+ data: { type: "funnel" },
140
+ });
141
+
142
+ expect(shouldHandleClickSelection([funnelPoint])).toBe(true);
143
+ });
144
+
145
+ it("accepts funnelarea clicks", () => {
146
+ const funnelAreaPoint = createPlotDatum({
147
+ data: { type: "funnelarea" },
148
+ });
149
+
150
+ expect(shouldHandleClickSelection([funnelAreaPoint])).toBe(true);
151
+ });
152
+
129
153
  it("accepts waterfall clicks", () => {
130
154
  const waterfallPoint = createPlotDatum({
131
155
  data: { type: "waterfall" },
@@ -214,6 +238,64 @@ describe("extractPoints", () => {
214
238
  expect(extractPoints([point])).toEqual([{ x: 1, y: 2, z: 3 }]);
215
239
  });
216
240
 
241
+ it("returns funnel-specific fields for funnel traces", () => {
242
+ const point = createPlotDatum({
243
+ x: 1000,
244
+ y: "Visit",
245
+ label: "Visit",
246
+ value: 1000,
247
+ percentInitial: 1.0,
248
+ percentPrevious: 1.0,
249
+ percentTotal: 1.0,
250
+ curveNumber: 0,
251
+ pointIndex: 0,
252
+ pointNumber: 0,
253
+ data: { type: "funnel" },
254
+ });
255
+
256
+ expect(extractPoints([point])).toEqual([
257
+ {
258
+ x: 1000,
259
+ y: "Visit",
260
+ label: "Visit",
261
+ value: 1000,
262
+ percentInitial: 1.0,
263
+ percentPrevious: 1.0,
264
+ percentTotal: 1.0,
265
+ curveNumber: 0,
266
+ pointIndex: 0,
267
+ pointNumber: 0,
268
+ },
269
+ ]);
270
+ });
271
+
272
+ it("returns funnelarea-specific fields without x/y for funnelarea traces", () => {
273
+ const point = createPlotDatum({
274
+ label: "Stage A",
275
+ value: 500,
276
+ percentInitial: 0.5,
277
+ percentPrevious: 0.8,
278
+ percentTotal: 0.5,
279
+ curveNumber: 0,
280
+ pointNumber: 1,
281
+ x: 99,
282
+ y: 99,
283
+ data: { type: "funnelarea" },
284
+ });
285
+
286
+ expect(extractPoints([point])).toEqual([
287
+ {
288
+ label: "Stage A",
289
+ value: 500,
290
+ percentInitial: 0.5,
291
+ percentPrevious: 0.8,
292
+ percentTotal: 0.5,
293
+ curveNumber: 0,
294
+ pointNumber: 1,
295
+ },
296
+ ]);
297
+ });
298
+
217
299
  it("returns x/y/pointIndex for waterfall clicks", () => {
218
300
  const point = createPlotDatum({
219
301
  x: "Revenue",
@@ -24,6 +24,32 @@ const SUNBURST_DATA_KEYS: (keyof Plotly.SunburstPlotDatum)[] = [
24
24
  "value",
25
25
  ] as const;
26
26
 
27
+ // Fields emitted by go.Funnel click events: includes x/y coordinates plus
28
+ // funnel-specific percent metrics.
29
+ const FUNNEL_DATA_KEYS: string[] = [
30
+ "curveNumber",
31
+ "pointIndex",
32
+ "pointNumber",
33
+ "x",
34
+ "y",
35
+ "label",
36
+ "value",
37
+ "percentInitial",
38
+ "percentPrevious",
39
+ "percentTotal",
40
+ ] as const;
41
+
42
+ // Fields emitted by go.FunnelArea click events: sector-based, no x/y.
43
+ const FUNNEL_AREA_DATA_KEYS: string[] = [
44
+ "curveNumber",
45
+ "pointNumber",
46
+ "label",
47
+ "value",
48
+ "percentInitial",
49
+ "percentPrevious",
50
+ "percentTotal",
51
+ ] as const;
52
+
27
53
  const LINE_CLICK_TRACE_TYPES = new Set(["scatter", "scattergl"]);
28
54
 
29
55
  const STANDARD_POINT_KEYS: string[] = [
@@ -256,10 +282,13 @@ export function shouldHandleClickSelection(
256
282
  const type = getTraceSource(point).type;
257
283
  return (
258
284
  type === "bar" ||
285
+ type === "box" ||
286
+ type === "funnel" ||
287
+ type === "funnelarea" ||
259
288
  type === "heatmap" ||
260
289
  type === "histogram" ||
261
- type === "waterfall" ||
262
290
  type === "violin" ||
291
+ type === "waterfall" ||
263
292
  isLinePoint(point)
264
293
  );
265
294
  });
@@ -329,13 +358,43 @@ export function extractPoints(
329
358
  let parser: PlotlyTemplateParser | undefined;
330
359
 
331
360
  return points.map((point) => {
361
+ const trace = getTraceSource(point);
362
+
363
+ // FunnelArea: sector-based chart with no x/y coordinates.
364
+ // Pick funnel-area-specific keys, then merge any hovertemplate-parsed
365
+ // fields (e.g. customdata columns) so user-defined fields are preserved.
366
+ if (trace.type === "funnelarea") {
367
+ const base = pick(point, FUNNEL_AREA_DATA_KEYS);
368
+ const ht = Array.isArray(trace.hovertemplate)
369
+ ? trace.hovertemplate[0]
370
+ : trace.hovertemplate;
371
+ if (!ht) {
372
+ return base;
373
+ }
374
+ parser = parser ? parser.update(ht) : createParser(ht);
375
+ return { ...base, ...parser.parse(point) };
376
+ }
377
+
378
+ // Funnel: bar-like chart with x/y plus per-stage percent metrics.
379
+ // Pick funnel-specific keys, then merge hovertemplate-parsed fields so
380
+ // callers get both percentInitial et al. and any user-defined columns.
381
+ if (trace.type === "funnel") {
382
+ const base = pick(point, FUNNEL_DATA_KEYS);
383
+ const ht = Array.isArray(trace.hovertemplate)
384
+ ? trace.hovertemplate[0]
385
+ : trace.hovertemplate;
386
+ if (!ht) {
387
+ return base;
388
+ }
389
+ parser = parser ? parser.update(ht) : createParser(ht);
390
+ return { ...base, ...parser.parse(point) };
391
+ }
392
+
332
393
  const standardPointFields = withInferredXY(
333
394
  point,
334
395
  pick(point, STANDARD_POINT_KEYS),
335
396
  );
336
397
 
337
- const trace = getTraceSource(point);
338
-
339
398
  // Get the first hovertemplate
340
399
  const hovertemplate = Array.isArray(trace.hovertemplate)
341
400
  ? trace.hovertemplate[0]