Skip to content

Commit 559f607

Browse files
Actual fix
1 parent d328431 commit 559f607

1 file changed

Lines changed: 66 additions & 12 deletions

File tree

static/js/generate.js

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
function catToColour(cat = -999, accessible = true) {
1+
function catToColour(cat = -999, accessible = true, type = "tropical") {
2+
const normalizeType = (t) => {
3+
if (!t) return "tropical";
4+
const s = String(t).toLowerCase();
5+
if (s.startsWith("sub")) return "subtropical";
6+
if (s.startsWith("extra")) return "extratropical";
7+
return "tropical";
8+
};
29
const scaleName = currentScale === "default" ? (accessible ? "accessible" : "default") : currentScale;
3-
const colorMap = getScaleMap(scaleName);
4-
return colorMap.get(cat) || "#C0C0C0";
10+
// use per-type map directly
11+
const map = getScaleMap(scaleName, normalizeType(type));
12+
return (map.get(cat) || "#C0C0C0");
513
}
614

715
const SCALE_STORAGE_KEY = "trackgen_custom_scales";
@@ -12,9 +20,11 @@ function getScaleList() {
1220
return ["default", "accessible", ...Object.keys(customScales)];
1321
}
1422

15-
function getScaleMap(scaleName) {
23+
// returns an object of three independent maps
24+
function getScaleMaps(scaleName) {
25+
const cloneMap = (src) => new Map(Array.from(src.entries()));
1626
if (scaleName === "default") {
17-
return new Map([
27+
const base = new Map([
1828
[-999, "#C0C0C0"],
1929
[-2, "#5EBAFF"],
2030
[-1, "#00FAF4"],
@@ -24,9 +34,14 @@ function getScaleMap(scaleName) {
2434
[4, "#FF8F20"],
2535
[5, "#FF6060"],
2636
]);
37+
return {
38+
tropical: cloneMap(base),
39+
subtropical: cloneMap(base),
40+
extratropical: cloneMap(base),
41+
};
2742
}
2843
if (scaleName === "accessible") {
29-
return new Map([
44+
const base = new Map([
3045
[-999, "#C0C0C0"],
3146
[-2, "#6ec1ea"],
3247
[-1, "#4dffff"],
@@ -36,13 +51,37 @@ function getScaleMap(scaleName) {
3651
[4, "#ff738a"],
3752
[5, "#a188fc"],
3853
]);
54+
return {
55+
tropical: cloneMap(base),
56+
subtropical: cloneMap(base),
57+
extratropical: cloneMap(base),
58+
};
3959
}
40-
// custom scale
60+
const normalizeType = (t) => {
61+
if (!t) return "tropical";
62+
const s = String(t).toLowerCase();
63+
if (s.startsWith("sub")) return "subtropical";
64+
if (s.startsWith("extra")) return "extratropical";
65+
return "tropical";
66+
};
4167
const scale = customScales[scaleName];
42-
if (!scale) return getScaleMap("default");
43-
const map = new Map();
44-
scale.forEach(entry => map.set(Number(entry.cat), entry.color));
45-
return map;
68+
if (!scale) return getScaleMaps("default");
69+
const maps = { tropical: new Map(), subtropical: new Map(), extratropical: new Map() };
70+
scale.forEach(entry => {
71+
const t = normalizeType(entry.type);
72+
maps[t].set(Number(entry.cat), entry.color);
73+
});
74+
return maps;
75+
}
76+
77+
// returns a single Map, optional type selects which map; default to tropical for legacy callers
78+
function getScaleMap(scaleName, type) {
79+
const maps = getScaleMaps(scaleName);
80+
if (!type) return maps.tropical;
81+
const key = String(type).toLowerCase().startsWith("sub") ? "subtropical"
82+
: String(type).toLowerCase().startsWith("extra") ? "extratropical"
83+
: "tropical";
84+
return maps[key] || maps.tropical;
4685
}
4786

4887
function saveCustomScale(name, entries) {
@@ -513,6 +552,21 @@ function normalizeLongitude(lng) {
513552
return ((lng + 180) % 360 + 360) % 360 - 180;
514553
}
515554

555+
// determine point type (tropical/subtropical/extratropical) from available fields
556+
function getPointType(point) {
557+
const normalizeType = (t) => {
558+
if (!t) return "tropical";
559+
const s = String(t).toLowerCase();
560+
if (s.startsWith("sub")) return "subtropical";
561+
if (s.startsWith("extra")) return "extratropical";
562+
return "tropical";
563+
};
564+
// prefer explicit type, then stage text, fallback to tropical
565+
if (point.type) return normalizeType(point.type);
566+
if (point.stage) return normalizeType(point.stage);
567+
return "tropical";
568+
}
569+
516570
function createMap(data, accessible) {
517571
const elements = mapManager.state.domElements;
518572
const output = elements.output;
@@ -670,7 +724,7 @@ function createMap(data, accessible) {
670724
}, {});
671725

672726
const pointGroups = adjustedData.reduce((map, point) => {
673-
const key = `${catToColour(point.category, accessible)}|${point.shape}`;
727+
const key = `${catToColour(point.category, accessible, getPointType(point))}|${point.shape}`;
674728
if (!map.has(key)) {
675729
map.set(key, []);
676730
}

0 commit comments

Comments
 (0)