Skip to content

Commit 3f81729

Browse files
authored
feat(colorbar): stack-order fix, stacking direction, and resizable panel (#884) (#901)
* fix(colorbar): keep stack order on update and add stacking direction (#884) Bump maplibre-gl-components to 0.25.2, which groups colorbars sharing a corner into one control so updating a colorbar no longer jumps it to the top of the stack, and adds a stacking-direction option (vertical or horizontal) for multiple colorbars. Mirror the new stackOrientation field in the saved project state so the choice round-trips on reopen. Fixes #884 * test(colorbar): guard stackOrientation round-trip in project state Export normalizeColorbarState and add unit tests that a horizontal stack choice persists, missing/unknown values fall back to vertical, and the state round-trips cleanly. Addresses review feedback on PR #901. * Address Claude review feedback - Add an explicit "vertical" pass-through test so the two valid stackOrientation values are isolated (a `=== "vertical"` typo would otherwise pass every existing case). - Use a non-empty customColors in the round-trip input so the normalizer's empty-string substitution no longer obscures the intent. - Trim the file header comment to a concise three lines. * Address Claude review feedback - Add an @internal JSDoc tag to normalizeColorbarState clarifying it is exported only for unit testing. - Add a test covering null/undefined/non-object input (the early-return branch). - Drop the file header comment; the describe label and test names cover it. * feat(colorbar): make the colorbar panel resizable with corner grips Bump maplibre-gl-components to 0.25.3, which adds two bottom-corner resize grips to the colorbar GUI panel (matching the HTML and data panels). Drag either grip to grow the panel toward the map interior.
1 parent 64f2f51 commit 3f81729

5 files changed

Lines changed: 81 additions & 11 deletions

File tree

apps/geolibre-desktop/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"maplibre-gl": "^5.24.0",
6060
"maplibre-gl-3d-tiles": "^0.5.3",
6161
"maplibre-gl-basemap-control": "^0.9.0",
62-
"maplibre-gl-components": "^0.25.1",
62+
"maplibre-gl-components": "^0.25.3",
6363
"maplibre-gl-duckdb": "^0.2.3",
6464
"maplibre-gl-earth-engine": "^0.4.2",
6565
"maplibre-gl-enviroatlas": "^0.1.1",

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugins/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"maplibre-gl": "^5.24.0",
3333
"maplibre-gl-3d-tiles": "^0.5.3",
3434
"maplibre-gl-basemap-control": "^0.9.0",
35-
"maplibre-gl-components": "^0.25.1",
35+
"maplibre-gl-components": "^0.25.3",
3636
"maplibre-gl-duckdb": "^0.2.3",
3737
"maplibre-gl-earth-engine": "^0.4.2",
3838
"maplibre-gl-enviroatlas": "^0.1.1",

packages/plugins/src/plugins/maplibre-components.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ interface ComponentColorbarGuiState extends ComponentColorbarGuiEntryState {
814814
hasColorbar: boolean;
815815
selectedColorbarIndex: number;
816816
colorbars: ComponentColorbarGuiEntryState[];
817+
stackOrientation: "horizontal" | "vertical";
817818
}
818819

819820
interface ComponentLegendItem {
@@ -1431,7 +1432,8 @@ function normalizeComponentsProjectState(
14311432
};
14321433
}
14331434

1434-
function normalizeColorbarState(
1435+
/** @internal Exported only so the project-state normalizer can be unit-tested. */
1436+
export function normalizeColorbarState(
14351437
state: unknown
14361438
): ComponentColorbarGuiState | undefined {
14371439
if (!state || typeof state !== "object") return undefined;
@@ -1452,6 +1454,8 @@ function normalizeColorbarState(
14521454
hasColorbar: colorbars.length > 0,
14531455
selectedColorbarIndex,
14541456
colorbars,
1457+
stackOrientation:
1458+
candidate.stackOrientation === "horizontal" ? "horizontal" : "vertical",
14551459
};
14561460
}
14571461

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import assert from "node:assert/strict";
2+
import { describe, it } from "node:test";
3+
import { normalizeColorbarState } from "../packages/plugins/src/plugins/maplibre-components.ts";
4+
5+
describe("normalizeColorbarState stackOrientation", () => {
6+
it("keeps a horizontal stack orientation", () => {
7+
const normalized = normalizeColorbarState({
8+
visible: true,
9+
colorbars: [],
10+
stackOrientation: "horizontal",
11+
});
12+
assert.equal(normalized?.stackOrientation, "horizontal");
13+
});
14+
15+
it("returns undefined for null/undefined/non-object input", () => {
16+
assert.equal(normalizeColorbarState(null), undefined);
17+
assert.equal(normalizeColorbarState(undefined), undefined);
18+
assert.equal(normalizeColorbarState("nope"), undefined);
19+
});
20+
21+
it("defaults missing stack orientation to vertical (backward compat)", () => {
22+
const normalized = normalizeColorbarState({ visible: true, colorbars: [] });
23+
assert.equal(normalized?.stackOrientation, "vertical");
24+
});
25+
26+
it("coerces an unknown stack orientation to vertical", () => {
27+
const normalized = normalizeColorbarState({
28+
visible: true,
29+
colorbars: [],
30+
stackOrientation: "diagonal",
31+
});
32+
assert.equal(normalized?.stackOrientation, "vertical");
33+
});
34+
35+
it("preserves an explicit vertical stack orientation", () => {
36+
const normalized = normalizeColorbarState({
37+
visible: true,
38+
colorbars: [],
39+
stackOrientation: "vertical",
40+
});
41+
assert.equal(normalized?.stackOrientation, "vertical");
42+
});
43+
44+
it("round-trips a horizontal choice through a second normalization", () => {
45+
const once = normalizeColorbarState({
46+
visible: true,
47+
colorbars: [
48+
{
49+
mode: "named",
50+
colormap: "viridis",
51+
customColors: "#440154, #31688e, #21918c, #90d743, #fde725",
52+
vmin: 0,
53+
vmax: 100,
54+
label: "Depth",
55+
units: "",
56+
orientation: "vertical",
57+
colorbarPosition: "bottom-right",
58+
},
59+
],
60+
stackOrientation: "horizontal",
61+
});
62+
const twice = normalizeColorbarState(once);
63+
assert.equal(twice?.stackOrientation, "horizontal");
64+
assert.deepEqual(twice, once);
65+
});
66+
});

0 commit comments

Comments
 (0)