@marimo-team/frontend 0.22.6-dev1 → 0.22.6-dev12

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.
Files changed (37) hide show
  1. package/dist/assets/{add-cell-with-ai-CLklC7KS.js → add-cell-with-ai-3_AIzd22.js} +3 -3
  2. package/dist/assets/{agent-panel-CiMrqUfl.js → agent-panel-CdOqi3vb.js} +1 -1
  3. package/dist/assets/{ai-model-dropdown-CRtaHcCu.js → ai-model-dropdown-DWOGmhDj.js} +4 -4
  4. package/dist/assets/{app-config-button-CnX21edo.js → app-config-button-BxCSZCVS.js} +1 -1
  5. package/dist/assets/cell-editor-CuHdpTsy.js +22 -0
  6. package/dist/assets/{chat-display-BxDRpNsl.js → chat-display-DFUo2Riv.js} +1 -1
  7. package/dist/assets/{chat-panel-dBoLqgjH.js → chat-panel-Dl4jq1Dp.js} +2 -2
  8. package/dist/assets/{chat-ui-DdZo1L-v.js → chat-ui-CysJeVE6.js} +1 -1
  9. package/dist/assets/{command-palette-n6NnK6GP.js → command-palette-DaEVrXkC.js} +1 -1
  10. package/dist/assets/{edit-page-RhmoqI7E.js → edit-page-DOK2VJe6.js} +7 -7
  11. package/dist/assets/{home-page-BntiR5eS.js → home-page-CruHjoHv.js} +1 -1
  12. package/dist/assets/{index-CMEhtk8a.js → index-DW6VcSzY.js} +11 -11
  13. package/dist/assets/index-Dbq6ugUC.css +2 -0
  14. package/dist/assets/{packages-panel-5axf3DuF.js → packages-panel-DxS7zji3.js} +1 -1
  15. package/dist/assets/{scratchpad-panel-DkqxnSH6.js → scratchpad-panel-C8dGg-F9.js} +1 -1
  16. package/dist/assets/useNotebookActions-aodoqUGd.js +1 -0
  17. package/dist/index.html +2 -2
  18. package/package.json +1 -1
  19. package/src/components/app-config/user-config-form.tsx +25 -0
  20. package/src/components/editor/actions/pair-with-agent-modal.tsx +4 -1
  21. package/src/components/editor/cell/code/cell-editor.tsx +4 -0
  22. package/src/components/editor/package-alert.tsx +17 -0
  23. package/src/core/alerts/state.ts +1 -0
  24. package/src/core/codemirror/ai/resources.ts +1 -0
  25. package/src/core/codemirror/cm.ts +3 -1
  26. package/src/core/codemirror/completion/__tests__/keymap.test.ts +40 -1
  27. package/src/core/codemirror/completion/accept-on-enter-atom.ts +10 -0
  28. package/src/core/codemirror/completion/keymap.ts +16 -9
  29. package/src/plugins/impl/plotly/PlotlyPlugin.tsx +4 -2
  30. package/src/plugins/impl/plotly/__tests__/PlotlyPlugin.test.tsx +50 -0
  31. package/src/plugins/impl/plotly/__tests__/selection.test.ts +73 -0
  32. package/src/plugins/impl/plotly/__tests__/usePlotlyLayout.test.ts +104 -6
  33. package/src/plugins/impl/plotly/selection.ts +35 -3
  34. package/src/plugins/impl/plotly/usePlotlyLayout.ts +38 -4
  35. package/dist/assets/cell-editor-D7IQ3F4W.js +0 -22
  36. package/dist/assets/index-DBs2il8a.css +0 -2
  37. package/dist/assets/useNotebookActions-DihtSJ4g.js +0 -1
@@ -5,6 +5,7 @@ import { describe, expect, it, vi } from "vitest";
5
5
  import {
6
6
  extractIndices,
7
7
  extractPoints,
8
+ hasAreaTrace,
8
9
  hasPureLineTrace,
9
10
  lineSelectionButtons,
10
11
  type ModeBarButton,
@@ -101,6 +102,14 @@ describe("shouldHandleClickSelection", () => {
101
102
  expect(shouldHandleClickSelection([heatmapPoint])).toBe(true);
102
103
  });
103
104
 
105
+ it("accepts violin clicks", () => {
106
+ const violinPoint = createPlotDatum({
107
+ data: { type: "violin" },
108
+ });
109
+
110
+ expect(shouldHandleClickSelection([violinPoint])).toBe(true);
111
+ });
112
+
104
113
  it("accepts histogram clicks", () => {
105
114
  const histogramPoint = createPlotDatum({
106
115
  data: { type: "histogram" },
@@ -219,3 +228,67 @@ describe("extractPoints", () => {
219
228
  ]);
220
229
  });
221
230
  });
231
+
232
+ describe("hasAreaTrace", () => {
233
+ it("detects scatter trace with tozeroy fill", () => {
234
+ expect(
235
+ hasAreaTrace([createTrace({ type: "scatter", fill: "tozeroy" })]),
236
+ ).toBe(true);
237
+ });
238
+
239
+ it("detects scatter trace with tonexty fill", () => {
240
+ expect(
241
+ hasAreaTrace([createTrace({ type: "scatter", fill: "tonexty" })]),
242
+ ).toBe(true);
243
+ });
244
+
245
+ it("detects scatter trace with stackgroup (px.area pattern)", () => {
246
+ expect(
247
+ hasAreaTrace([
248
+ createTrace({ type: "scatter", mode: "lines", stackgroup: "one" }),
249
+ ]),
250
+ ).toBe(true);
251
+ });
252
+
253
+ it("detects area traces with mode=none (fill-only, no visible line)", () => {
254
+ expect(
255
+ hasAreaTrace([
256
+ createTrace({ type: "scatter", fill: "tozeroy", mode: "none" }),
257
+ ]),
258
+ ).toBe(true);
259
+ });
260
+
261
+ it("ignores scatter traces with no fill and no stackgroup", () => {
262
+ expect(
263
+ hasAreaTrace([
264
+ createTrace({ type: "scatter", mode: "lines" }),
265
+ createTrace({ type: "scatter", mode: "markers" }),
266
+ ]),
267
+ ).toBe(false);
268
+ });
269
+
270
+ it("ignores scatter traces with fill=none", () => {
271
+ expect(hasAreaTrace([createTrace({ type: "scatter", fill: "none" })])).toBe(
272
+ false,
273
+ );
274
+ });
275
+
276
+ it("ignores scatter traces with fill=empty string", () => {
277
+ expect(
278
+ hasAreaTrace([createTrace({ type: "scatter", fill: "" as "none" })]),
279
+ ).toBe(false);
280
+ });
281
+
282
+ it("ignores non-scatter traces", () => {
283
+ expect(
284
+ hasAreaTrace([
285
+ createTrace({ type: "bar" }),
286
+ createTrace({ type: "heatmap" }),
287
+ ]),
288
+ ).toBe(false);
289
+ });
290
+
291
+ it("returns false for undefined data", () => {
292
+ expect(hasAreaTrace(undefined)).toBe(false);
293
+ });
294
+ });
@@ -8,11 +8,15 @@ import {
8
8
  computeLayoutUpdate,
9
9
  computeOmitKeys,
10
10
  createInitialLayout,
11
+ hasCompatibleTraces,
11
12
  } from "../usePlotlyLayout";
12
13
 
13
- function createFigure(layoutOverrides: Partial<Plotly.Layout> = {}): Figure {
14
+ function createFigure(
15
+ layoutOverrides: Partial<Plotly.Layout> = {},
16
+ data: Plotly.Data[] = [],
17
+ ): Figure {
14
18
  return {
15
- data: [],
19
+ data,
16
20
  layout: { ...layoutOverrides } as Plotly.Layout,
17
21
  frames: null,
18
22
  };
@@ -35,9 +39,46 @@ describe("createInitialLayout", () => {
35
39
  });
36
40
  });
37
41
 
42
+ describe("hasCompatibleTraces", () => {
43
+ it("returns true for same trace types", () => {
44
+ const a = createFigure({}, [{ type: "scatter" } as Plotly.Data]);
45
+ const b = createFigure({}, [{ type: "scatter" } as Plotly.Data]);
46
+ expect(hasCompatibleTraces(a, b)).toBe(true);
47
+ });
48
+
49
+ it("returns true for default scatter types (undefined type)", () => {
50
+ const a = createFigure({}, [{} as Plotly.Data]);
51
+ const b = createFigure({}, [{ type: "scatter" } as Plotly.Data]);
52
+ expect(hasCompatibleTraces(a, b)).toBe(true);
53
+ });
54
+
55
+ it("returns false for different trace types", () => {
56
+ const a = createFigure({}, [{ type: "scatter" } as Plotly.Data]);
57
+ const b = createFigure({}, [{ type: "histogram" } as Plotly.Data]);
58
+ expect(hasCompatibleTraces(a, b)).toBe(false);
59
+ });
60
+
61
+ it("returns false for different number of traces", () => {
62
+ const a = createFigure({}, [{ type: "scatter" } as Plotly.Data]);
63
+ const b = createFigure({}, [
64
+ { type: "scatter" } as Plotly.Data,
65
+ { type: "scatter" } as Plotly.Data,
66
+ ]);
67
+ expect(hasCompatibleTraces(a, b)).toBe(false);
68
+ });
69
+
70
+ it("returns true for empty data arrays", () => {
71
+ const a = createFigure({}, []);
72
+ const b = createFigure({}, []);
73
+ expect(hasCompatibleTraces(a, b)).toBe(true);
74
+ });
75
+ });
76
+
38
77
  describe("computeLayoutOnFigureChange", () => {
39
- it("preserves only dragmode/xaxis/yaxis from previous layout (#7964)", () => {
40
- const nextFigure = createFigure({ title: { text: "New" } });
78
+ it("preserves only dragmode/xaxis/yaxis from previous layout for compatible traces (#7964)", () => {
79
+ const scatterData = [{ type: "scatter" } as Plotly.Data];
80
+ const prevFigure = createFigure({}, scatterData);
81
+ const nextFigure = createFigure({ title: { text: "New" } }, scatterData);
41
82
  const prevLayout: Partial<Plotly.Layout> = {
42
83
  dragmode: "zoom",
43
84
  xaxis: { range: [0, 10] },
@@ -46,7 +87,11 @@ describe("computeLayoutOnFigureChange", () => {
46
87
  annotations: [{ text: "Old", x: 0, y: 0 }],
47
88
  };
48
89
 
49
- const result = computeLayoutOnFigureChange(nextFigure, prevLayout);
90
+ const result = computeLayoutOnFigureChange(
91
+ nextFigure,
92
+ prevFigure,
93
+ prevLayout,
94
+ );
50
95
 
51
96
  // Preserved from prev
52
97
  expect(result.dragmode).toBe("zoom");
@@ -59,15 +104,68 @@ describe("computeLayoutOnFigureChange", () => {
59
104
  expect(result.annotations).toBeUndefined();
60
105
  });
61
106
 
107
+ it("resets axis settings when trace types change (#5898)", () => {
108
+ const prevFigure = createFigure({}, [{ type: "histogram" } as Plotly.Data]);
109
+ const nextFigure = createFigure({ title: { text: "Bar" } }, [
110
+ { type: "bar" } as Plotly.Data,
111
+ ]);
112
+ const prevLayout: Partial<Plotly.Layout> = {
113
+ dragmode: "zoom",
114
+ xaxis: { range: [-3, 3] },
115
+ yaxis: { range: [0, 200] },
116
+ };
117
+
118
+ const result = computeLayoutOnFigureChange(
119
+ nextFigure,
120
+ prevFigure,
121
+ prevLayout,
122
+ );
123
+
124
+ // Dragmode is still preserved
125
+ expect(result.dragmode).toBe("zoom");
126
+ // Axis settings are NOT preserved — they come from the new figure's layout
127
+ expect(result.xaxis).toBeUndefined();
128
+ expect(result.yaxis).toBeUndefined();
129
+ // New figure's layout is applied
130
+ expect(result.title).toEqual({ text: "Bar" });
131
+ });
132
+
133
+ it("preserves nextFigure dragmode when prevLayout has no dragmode", () => {
134
+ const prevFigure = createFigure({}, [{ type: "histogram" } as Plotly.Data]);
135
+ const nextFigure = createFigure({ dragmode: "lasso" }, [
136
+ { type: "bar" } as Plotly.Data,
137
+ ]);
138
+ const prevLayout: Partial<Plotly.Layout> = {
139
+ xaxis: { range: [0, 10] },
140
+ };
141
+
142
+ const result = computeLayoutOnFigureChange(
143
+ nextFigure,
144
+ prevFigure,
145
+ prevLayout,
146
+ );
147
+
148
+ // nextFigure.layout.dragmode should be preserved via base, not overwritten
149
+ expect(result.dragmode).toBe("lasso");
150
+ // Axis settings are NOT preserved for incompatible traces
151
+ expect(result.xaxis).toBeUndefined();
152
+ expect(result.yaxis).toBeUndefined();
153
+ });
154
+
62
155
  it("uses shapes from new figure, not previous layout", () => {
63
156
  const nextFigure = createFigure({
64
157
  shapes: [{ type: "circle", x0: 0, x1: 1, y0: 0, y1: 1 }],
65
158
  });
159
+ const prevFigure = createFigure({});
66
160
  const prevLayout: Partial<Plotly.Layout> = {
67
161
  shapes: [{ type: "rect", x0: 0, x1: 1, y0: 0, y1: 1 }],
68
162
  };
69
163
 
70
- const result = computeLayoutOnFigureChange(nextFigure, prevLayout);
164
+ const result = computeLayoutOnFigureChange(
165
+ nextFigure,
166
+ prevFigure,
167
+ prevLayout,
168
+ );
71
169
 
72
170
  expect(result.shapes).toHaveLength(1);
73
171
  expect(result.shapes?.[0].type).toBe("circle");
@@ -141,13 +141,44 @@ export function hasPureLineTrace(
141
141
  }
142
142
 
143
143
  return data.some((trace) => {
144
- const traceType = (trace as { type?: unknown }).type;
144
+ const t = trace as Record<string, unknown>;
145
145
  const isScatterLike =
146
- traceType === undefined || LINE_CLICK_TRACE_TYPES.has(String(traceType));
146
+ t.type === undefined || LINE_CLICK_TRACE_TYPES.has(String(t.type));
147
147
  if (!isScatterLike) {
148
148
  return false;
149
149
  }
150
- return isPureLineMode((trace as { mode?: unknown }).mode);
150
+ return isPureLineMode(t.mode);
151
+ });
152
+ }
153
+
154
+ /**
155
+ * Return true when any scatter/scattergl trace has a non-empty fill or a
156
+ * stackgroup, i.e. it is an area chart.
157
+ *
158
+ * Area traces built with `mode="none"` have no visible line or markers, so
159
+ * `hasPureLineTrace` returns false for them even though they need select/lasso
160
+ * buttons just as much as `mode="lines"` area charts. This function covers
161
+ * that gap and is OR-ed with `hasPureLineTrace` in the config builder.
162
+ */
163
+ export function hasAreaTrace(
164
+ data: readonly Plotly.Data[] | undefined,
165
+ ): boolean {
166
+ if (!data) {
167
+ return false;
168
+ }
169
+
170
+ return data.some((trace) => {
171
+ const t = trace as Record<string, unknown>;
172
+ // Only scatter/scattergl can be area traces.
173
+ if (t.type !== undefined && !LINE_CLICK_TRACE_TYPES.has(String(t.type))) {
174
+ return false;
175
+ }
176
+ // A trace is an area trace when fill is a non-empty string other than
177
+ // "none", OR it belongs to a stackgroup (px.area always sets stackgroup).
178
+ return (
179
+ (typeof t.fill === "string" && t.fill !== "" && t.fill !== "none") ||
180
+ t.stackgroup != null
181
+ );
151
182
  });
152
183
  }
153
184
 
@@ -228,6 +259,7 @@ export function shouldHandleClickSelection(
228
259
  type === "heatmap" ||
229
260
  type === "histogram" ||
230
261
  type === "waterfall" ||
262
+ type === "violin" ||
231
263
  isLinePoint(point)
232
264
  );
233
265
  });
@@ -3,7 +3,7 @@
3
3
  import { usePrevious } from "@uidotdev/usehooks";
4
4
  import { dequal as isEqual } from "dequal";
5
5
  import type * as Plotly from "plotly.js";
6
- import { useEffect, useState } from "react";
6
+ import { useEffect, useRef, useState } from "react";
7
7
  import { Objects } from "@/utils/objects";
8
8
  import type { Figure } from "./Plot";
9
9
 
@@ -39,18 +39,46 @@ export function createInitialLayout(figure: Figure): Partial<Plotly.Layout> {
39
39
  };
40
40
  }
41
41
 
42
+ /**
43
+ * Returns true if two figures have compatible trace types.
44
+ * When traces are incompatible (different types, count, or order), axis settings
45
+ * from the old figure should not be preserved as they would distort the
46
+ * new chart. See https://github.com/marimo-team/marimo/issues/5898
47
+ */
48
+ export function hasCompatibleTraces(prev: Figure, next: Figure): boolean {
49
+ if (prev.data.length !== next.data.length) {
50
+ return false;
51
+ }
52
+ return prev.data.every(
53
+ (trace, i) =>
54
+ (trace.type ?? "scatter") === (next.data[i]?.type ?? "scatter"),
55
+ );
56
+ }
57
+
42
58
  /**
43
59
  * Computes the updated layout when the figure changes.
44
60
  * Preserves user-interaction values (dragmode, xaxis, yaxis) while
45
61
  * taking everything else from the new figure's layout.
62
+ *
63
+ * When trace types change, only dragmode is preserved — axis settings
64
+ * are reset to let Plotly auto-compute ranges for the new chart type.
46
65
  */
47
66
  export function computeLayoutOnFigureChange(
48
67
  nextFigure: Figure,
68
+ prevFigure: Figure,
49
69
  prevLayout: Partial<Plotly.Layout>,
50
70
  ): Partial<Plotly.Layout> {
71
+ const base = createInitialLayout(nextFigure);
72
+ if (hasCompatibleTraces(prevFigure, nextFigure)) {
73
+ return {
74
+ ...base,
75
+ ...Objects.pick(prevLayout, PERSISTED_LAYOUT_KEYS),
76
+ };
77
+ }
78
+ // Incompatible traces — only preserve dragmode, not axis settings
51
79
  return {
52
- ...createInitialLayout(nextFigure),
53
- ...Objects.pick(prevLayout, PERSISTED_LAYOUT_KEYS),
80
+ ...base,
81
+ ...("dragmode" in prevLayout ? { dragmode: prevLayout.dragmode } : {}),
54
82
  };
55
83
  }
56
84
 
@@ -121,6 +149,9 @@ export function usePlotlyLayout({
121
149
  return structuredClone(originalFigure);
122
150
  });
123
151
 
152
+ // Track the previous figure to detect trace type changes
153
+ const prevFigureRef = useRef(figure);
154
+
124
155
  const [layout, setLayout] = useState<Partial<Plotly.Layout>>(() => {
125
156
  return {
126
157
  ...createInitialLayout(figure),
@@ -132,12 +163,15 @@ export function usePlotlyLayout({
132
163
  // Update figure and layout when originalFigure changes
133
164
  useEffect(() => {
134
165
  const nextFigure = structuredClone(originalFigure);
166
+ const prevFig = prevFigureRef.current;
167
+ prevFigureRef.current = nextFigure;
135
168
  setFigure(nextFigure);
136
169
  // Start with the new figure's layout, then only preserve user-interaction
137
170
  // values (dragmode, xaxis, yaxis) from the previous layout.
138
171
  // We don't want to preserve other properties like `shapes` from the previous
139
172
  // layout, as they should be fully controlled by the figure prop.
140
- setLayout((prev) => computeLayoutOnFigureChange(nextFigure, prev));
173
+ // When trace types change, axis settings are reset to avoid distortion (#5898).
174
+ setLayout((prev) => computeLayoutOnFigureChange(nextFigure, prevFig, prev));
141
175
  }, [originalFigure, isScriptLoaded]);
142
176
 
143
177
  const prevFigure = usePrevious(figure) ?? figure;