@marimo-team/frontend 0.20.1 → 0.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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-DEPjuBkG.js"></script>
69
+ <script type="module" crossorigin src="./assets/index-xckvhXGM.js"></script>
70
70
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-reX6CfMN.js">
71
71
  <link rel="modulepreload" crossorigin href="./assets/clsx-nlQpVU_5.js">
72
72
  <link rel="modulepreload" crossorigin href="./assets/cn-BfqzeB_k.js">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/frontend",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -3,8 +3,14 @@ import { describe, expect, it } from "vitest";
3
3
  import type { Data } from "../matplotlib-renderer";
4
4
  import { visibleForTesting } from "../matplotlib-renderer";
5
5
 
6
- const { pixelToData, dataToPixel, pointInPolygon, clampToAxes, isPointInBox } =
7
- visibleForTesting;
6
+ const {
7
+ pixelToData,
8
+ dataToPixel,
9
+ pointInPolygon,
10
+ clampToAxes,
11
+ isPointInBox,
12
+ isInAxes,
13
+ } = visibleForTesting;
8
14
 
9
15
  // A simple axes geometry for testing:
10
16
  // axes occupy pixels [100, 50] to [500, 350] (400px wide, 300px tall)
@@ -150,3 +156,32 @@ describe("isPointInBox", () => {
150
156
  expect(isPointInBox({ x: 5, y: 30 }, boxEnd, boxStart)).toBe(false);
151
157
  });
152
158
  });
159
+
160
+ describe("isInAxes", () => {
161
+ it("returns true for a point inside the axes", () => {
162
+ expect(isInAxes({ x: 300, y: 200 }, LINEAR_AXES)).toBe(true);
163
+ });
164
+
165
+ it("returns true for a point on the boundary", () => {
166
+ expect(isInAxes({ x: 100, y: 50 }, LINEAR_AXES)).toBe(true); // top-left
167
+ expect(isInAxes({ x: 500, y: 350 }, LINEAR_AXES)).toBe(true); // bottom-right
168
+ expect(isInAxes({ x: 100, y: 350 }, LINEAR_AXES)).toBe(true); // bottom-left
169
+ expect(isInAxes({ x: 500, y: 50 }, LINEAR_AXES)).toBe(true); // top-right
170
+ });
171
+
172
+ it("returns false for a point left of axes", () => {
173
+ expect(isInAxes({ x: 99, y: 200 }, LINEAR_AXES)).toBe(false);
174
+ });
175
+
176
+ it("returns false for a point right of axes", () => {
177
+ expect(isInAxes({ x: 501, y: 200 }, LINEAR_AXES)).toBe(false);
178
+ });
179
+
180
+ it("returns false for a point above axes", () => {
181
+ expect(isInAxes({ x: 300, y: 49 }, LINEAR_AXES)).toBe(false);
182
+ });
183
+
184
+ it("returns false for a point below axes", () => {
185
+ expect(isInAxes({ x: 300, y: 351 }, LINEAR_AXES)).toBe(false);
186
+ });
187
+ });
@@ -257,6 +257,11 @@ function isPointInBox(
257
257
  return pt.x >= minX && pt.x <= maxX && pt.y >= minY && pt.y <= maxY;
258
258
  }
259
259
 
260
+ function isInAxes(pt: PixelPoint, g: AxesGeometry): boolean {
261
+ const [axLeft, axTop, axRight, axBottom] = g.axesPixelBounds;
262
+ return pt.x >= axLeft && pt.x <= axRight && pt.y >= axTop && pt.y <= axBottom;
263
+ }
264
+
260
265
  export const visibleForTesting = {
261
266
  createScale,
262
267
  pixelToData,
@@ -264,6 +269,7 @@ export const visibleForTesting = {
264
269
  pointInPolygon,
265
270
  clampToAxes,
266
271
  isPointInBox,
272
+ isInAxes,
267
273
  };
268
274
 
269
275
  export class MatplotlibRenderer {
@@ -568,6 +574,9 @@ export class MatplotlibRenderer {
568
574
 
569
575
  // Shift+click -> start lasso
570
576
  if (e.shiftKey) {
577
+ if (!isInAxes(pt, this.#state)) {
578
+ return;
579
+ }
571
580
  this.#interaction = {
572
581
  type: "lasso",
573
582
  points: [clampToAxes(pt, this.#state)],
@@ -620,7 +629,10 @@ export class MatplotlibRenderer {
620
629
  this.#clearSelection();
621
630
  }
622
631
 
623
- // Start new box selection
632
+ // Start new box selection (only inside axes)
633
+ if (!isInAxes(pt, this.#state)) {
634
+ return;
635
+ }
624
636
  const clamped = clampToAxes(pt, this.#state);
625
637
  this.#interaction = {
626
638
  type: "box",