Upload script.js with huggingface_hub
Browse files
script.js
CHANGED
|
@@ -8,20 +8,40 @@ const INDEX_URL = IS_LOCAL
|
|
| 8 |
: 'https://huggingface.co/datasets/maxxxzdn/mosaic-demo-cache/resolve/main/examples_index.json';
|
| 9 |
const COAST_URL = 'coastlines.json';
|
| 10 |
const HEADER_BYTES = 512;
|
| 11 |
-
//
|
| 12 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
const PLOTLY_CMAP = {
|
| 14 |
-
RdBu_r
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
cividis: 'cividis',
|
| 23 |
-
plasma: 'plasma',
|
| 24 |
-
inferno: 'inferno',
|
| 25 |
};
|
| 26 |
const R = 1.0;
|
| 27 |
const COAST_R = 1.010;
|
|
@@ -326,7 +346,7 @@ function mkCbar(x, units) {
|
|
| 326 |
function drawFigure() {
|
| 327 |
const m = app.meta, g = app.geom, c = app.coastXYZ, { t } = app;
|
| 328 |
const cmapKey = getCmapForVar(app.currentVar) || m.cmap;
|
| 329 |
-
const cmap = PLOTLY_CMAP[cmapKey] ||
|
| 330 |
const diff = app.rightMode === 'diff';
|
| 331 |
|
| 332 |
const rl = document.getElementById('right-label');
|
|
@@ -358,7 +378,7 @@ function drawFigure() {
|
|
| 358 |
surf('scene', app.meanFrames[t], cmap, vmin, vmax, cbar0),
|
| 359 |
coast('scene'),
|
| 360 |
surf('scene2', app.rightFrames[t],
|
| 361 |
-
diff ?
|
| 362 |
diff ? -m.diff_abs_max : vmin, diff ? m.diff_abs_max : vmax, cbar2),
|
| 363 |
coast('scene2'),
|
| 364 |
];
|
|
|
|
| 8 |
: 'https://huggingface.co/datasets/maxxxzdn/mosaic-demo-cache/resolve/main/examples_index.json';
|
| 9 |
const COAST_URL = 'coastlines.json';
|
| 10 |
const HEADER_BYTES = 512;
|
| 11 |
+
// Custom colorscale arrays — avoid any Plotly.js named-scale lookup entirely.
|
| 12 |
+
// Each array: [[position 0-1, hex], ...], 0=vmin, 1=vmax.
|
| 13 |
+
|
| 14 |
+
// RdBu_r: blue(cold/negative) → white → red(warm/positive)
|
| 15 |
+
const CS_RDBU_R = [
|
| 16 |
+
[0,'#053061'],[0.125,'#2166ac'],[0.25,'#4393c3'],[0.375,'#92c5de'],
|
| 17 |
+
[0.5,'#f7f7f7'],[0.625,'#f4a582'],[0.75,'#d6604d'],[0.875,'#b2182b'],[1,'#67001f'],
|
| 18 |
+
];
|
| 19 |
+
// Magma: black → deep purple → red-orange → pale yellow (pops on dark bg)
|
| 20 |
+
const CS_MAGMA = [
|
| 21 |
+
[0,'#000004'],[0.125,'#1d1147'],[0.25,'#51127c'],[0.375,'#832681'],
|
| 22 |
+
[0.5,'#b5367a'],[0.625,'#d9555e'],[0.75,'#f17c4a'],[0.875,'#fbb938'],[1,'#fcfdbf'],
|
| 23 |
+
];
|
| 24 |
+
// Turbo: dark-blue → cyan → green → yellow → orange → dark-red
|
| 25 |
+
const CS_TURBO = [
|
| 26 |
+
[0,'#30123b'],[0.125,'#3e47c9'],[0.25,'#21bdbb'],[0.375,'#60ff56'],
|
| 27 |
+
[0.5,'#c1f334'],[0.625,'#fba40a'],[0.75,'#f05b12'],[0.875,'#c81a0c'],[1,'#7a0403'],
|
| 28 |
+
];
|
| 29 |
+
// Viridis: deep purple → teal → bright yellow
|
| 30 |
+
const CS_VIRIDIS = [
|
| 31 |
+
[0,'#440154'],[0.125,'#482878'],[0.25,'#3e4989'],[0.375,'#31688e'],
|
| 32 |
+
[0.5,'#26828e'],[0.625,'#35b779'],[0.75,'#6dcd59'],[0.875,'#b4de2c'],[1,'#fde725'],
|
| 33 |
+
];
|
| 34 |
+
|
| 35 |
+
// Keys must match exactly what getCmapForVar returns or what m.cmap may contain.
|
| 36 |
const PLOTLY_CMAP = {
|
| 37 |
+
'RdBu_r': CS_RDBU_R,
|
| 38 |
+
'magma': CS_MAGMA,
|
| 39 |
+
'turbo': CS_TURBO,
|
| 40 |
+
'viridis': CS_VIRIDIS,
|
| 41 |
+
// precomputed-cmap fallbacks (from binary headers)
|
| 42 |
+
'RdBu': CS_RDBU_R, // treat plain RdBu as _r since we want blue=cold
|
| 43 |
+
'YlGnBu': CS_VIRIDIS, // fallback for humidity if label doesn't match
|
| 44 |
+
'viridis_r': CS_VIRIDIS, // just in case
|
|
|
|
|
|
|
|
|
|
| 45 |
};
|
| 46 |
const R = 1.0;
|
| 47 |
const COAST_R = 1.010;
|
|
|
|
| 346 |
function drawFigure() {
|
| 347 |
const m = app.meta, g = app.geom, c = app.coastXYZ, { t } = app;
|
| 348 |
const cmapKey = getCmapForVar(app.currentVar) || m.cmap;
|
| 349 |
+
const cmap = PLOTLY_CMAP[cmapKey] || CS_VIRIDIS;
|
| 350 |
const diff = app.rightMode === 'diff';
|
| 351 |
|
| 352 |
const rl = document.getElementById('right-label');
|
|
|
|
| 378 |
surf('scene', app.meanFrames[t], cmap, vmin, vmax, cbar0),
|
| 379 |
coast('scene'),
|
| 380 |
surf('scene2', app.rightFrames[t],
|
| 381 |
+
diff ? CS_RDBU_R : cmap,
|
| 382 |
diff ? -m.diff_abs_max : vmin, diff ? m.diff_abs_max : vmax, cbar2),
|
| 383 |
coast('scene2'),
|
| 384 |
];
|