ciesm-prism 1.0.1362 → 1.0.1363

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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "format": "prism-tutorials/v1",
3
+ "items": [
4
+ {
5
+ "id": "tutorials-medsea-temperature",
6
+ "label": "MEDSEA Temperature: a volume",
7
+ "name": "medsea-temperature"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,123 @@
1
+ {
2
+ "format": "prism-tutorial/v1",
3
+ "title": "MEDSEA Temperature: opacity, colours, clipping",
4
+ "start": { "example": "medsea-temperature" },
5
+ "intro": "The Mediterranean Sea temperature of the CMEMS reanalysis as 3-D volumes. Where to select a volume, change its opacity and its colour ramp, and cut it with the geographic clipping.",
6
+ "end": "Each volume has its controls in Visualization Controls once its row is selected in the Outliner. Edit > Undo takes these steps back one by one.",
7
+ "steps": [
8
+ {
9
+ "id": "s1",
10
+ "kind": "eye",
11
+ "label": "Hide MEDSEA Daily Temperature (2024-2025)",
12
+ "rows": [
13
+ {
14
+ "id": "01a24b50-5c38-73be-a7c7-337b6c89d77c",
15
+ "name": "MEDSEA Daily Temperature (2024-2025)",
16
+ "bundle": "medseaDaily"
17
+ }
18
+ ],
19
+ "before": { "01a24b50-5c38-73be-a7c7-337b6c89d77c": true },
20
+ "after": { "01a24b50-5c38-73be-a7c7-337b6c89d77c": false },
21
+ "view": {
22
+ "camera": { "position": [0, 1.02, 1.12], "target": [0, -0.06, 0.06], "up": [0, 1, 0] },
23
+ "viewport": { "lonMin": -6.25, "lonMax": 36.25, "latMin": 30.25, "latMax": 46.25 },
24
+ "currentView": "persp",
25
+ "currentProjection": "planar",
26
+ "isOrthographic": false,
27
+ "elevationExaggerationSurface": 40,
28
+ "elevationExaggerationDepth": 40,
29
+ "clipping": { "west": -180, "east": 180, "south": -90, "north": 90 }
30
+ },
31
+ "caption": "Hide MEDSEA Daily Temperature (2024-2025)"
32
+ },
33
+ {
34
+ "id": "s2",
35
+ "kind": "control",
36
+ "control": "opacity",
37
+ "label": "Opacity: 80% → 40% (MEDSEA Monthly Temperature)",
38
+ "rows": [{ "id": "01a24b50-59ed-7597-89d0-2b4c6c0aff22", "name": "MEDSEA Monthly Temperature", "bundle": "medsea" }],
39
+ "before": 0.8,
40
+ "after": 0.4,
41
+ "view": {
42
+ "camera": { "position": [0, 1.02, 1.12], "target": [0, -0.06, 0.06], "up": [0, 1, 0] },
43
+ "viewport": { "lonMin": -6.25, "lonMax": 36.25, "latMin": 30.25, "latMax": 46.25 },
44
+ "currentView": "persp",
45
+ "currentProjection": "planar",
46
+ "isOrthographic": false,
47
+ "elevationExaggerationSurface": 40,
48
+ "elevationExaggerationDepth": 40,
49
+ "clipping": { "west": -180, "east": 180, "south": -90, "north": 90 }
50
+ },
51
+ "caption": "Set MEDSEA Monthly Temperature's Opacity to 40 %"
52
+ },
53
+ {
54
+ "id": "s3",
55
+ "kind": "gradient",
56
+ "label": "Color Ramp thermal (MEDSEA Monthly Temperature)",
57
+ "rows": [{ "id": "01a24b50-59ed-7597-89d0-2b4c6c0aff22", "name": "MEDSEA Monthly Temperature", "bundle": "medsea" }],
58
+ "before": {
59
+ "css": "linear-gradient(90deg, rgb(0,0,179) 0%, rgb(128,102,255) 14%, rgb(102,204,230) 29%, rgb(179,255,230) 43%, rgb(255,242,153) 57%, rgb(255,153,77) 71%, rgb(255,26,0) 100%)",
60
+ "colorRamp": { "name": "Rainbow PRISM" }
61
+ },
62
+ "after": {
63
+ "css": "linear-gradient(90deg, rgb(4,35,51) 0%, rgb(31,52,134) 14%, rgb(101,66,151) 29%, rgb(150,87,138) 43%, rgb(203,103,116) 57%, rgb(244,133,75) 71%, rgb(232,250,91) 100%)",
64
+ "colorRamp": { "name": "thermal" }
65
+ },
66
+ "view": {
67
+ "camera": { "position": [0, 1.02, 1.12], "target": [0, -0.06, 0.06], "up": [0, 1, 0] },
68
+ "viewport": { "lonMin": -6.25, "lonMax": 36.25, "latMin": 30.25, "latMax": 46.25 },
69
+ "currentView": "persp",
70
+ "currentProjection": "planar",
71
+ "isOrthographic": false,
72
+ "elevationExaggerationSurface": 40,
73
+ "elevationExaggerationDepth": 40,
74
+ "clipping": { "west": -180, "east": 180, "south": -90, "north": 90 }
75
+ },
76
+ "caption": "Set MEDSEA Monthly Temperature's Color Ramp to thermal"
77
+ },
78
+ {
79
+ "id": "s4",
80
+ "kind": "clip",
81
+ "field": "west",
82
+ "userField": "userWest",
83
+ "bucket": "shared",
84
+ "rows": [],
85
+ "label": "Clipping West (°): -180.00° → 15.00°",
86
+ "before": -180,
87
+ "after": 15,
88
+ "view": {
89
+ "camera": { "position": [0, 1.02, 1.12], "target": [0, -0.06, 0.06], "up": [0, 1, 0] },
90
+ "viewport": { "lonMin": -6.25, "lonMax": 36.25, "latMin": 30.25, "latMax": 46.25 },
91
+ "currentView": "persp",
92
+ "currentProjection": "planar",
93
+ "isOrthographic": false,
94
+ "elevationExaggerationSurface": 40,
95
+ "elevationExaggerationDepth": 40,
96
+ "clipping": { "west": 15, "east": 180, "south": -90, "north": 90 }
97
+ },
98
+ "caption": "Set the clipping's West edge to 15.00°"
99
+ },
100
+ {
101
+ "id": "s5",
102
+ "kind": "clip",
103
+ "field": "north",
104
+ "userField": "userNorth",
105
+ "bucket": "shared",
106
+ "rows": [],
107
+ "label": "Clipping North (°): 90.00° → 40.00°",
108
+ "before": 90,
109
+ "after": 40,
110
+ "view": {
111
+ "camera": { "position": [0, 1.02, 1.12], "target": [0, -0.06, 0.06], "up": [0, 1, 0] },
112
+ "viewport": { "lonMin": -6.25, "lonMax": 36.25, "latMin": 30.25, "latMax": 46.25 },
113
+ "currentView": "persp",
114
+ "currentProjection": "planar",
115
+ "isOrthographic": false,
116
+ "elevationExaggerationSurface": 40,
117
+ "elevationExaggerationDepth": 40,
118
+ "clipping": { "west": 15, "east": 180, "south": -90, "north": 40 }
119
+ },
120
+ "caption": "Set the clipping's North edge to 40.00°"
121
+ }
122
+ ]
123
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ciesm-prism",
3
- "version": "1.0.1362",
3
+ "version": "1.0.1363",
4
4
  "description": "PRISM: ocean and Earth data in one interactive 3-D view, in the web browser. Run it with npx ciesm-prism, or copy it to any web server.",
5
5
  "keywords": [
6
6
  "ocean",
package/prism-app.html CHANGED
@@ -188,7 +188,7 @@
188
188
  import { createApp, createVolumeEngine, linkProject, linkViewport } from './src/app/App.js';
189
189
  import { BUNDLED, bundledDataset, isBundled } from './src/app/BundledData.js';
190
190
  import { exampleStates } from './src/project/ExampleFile.js';
191
- import { PRISM, applyView, select } from './src/app/Prism.js';
191
+ import { PRISM, applyView, captureView, select } from './src/app/Prism.js';
192
192
  import { createCameraMotion } from './src/app/CameraMotion.js';
193
193
  import { createControlFolders } from './src/app/ControlFolders.js';
194
194
  import { createPanelDock } from './src/app/PanelDock.js';
@@ -202,6 +202,11 @@
202
202
  // PRISM History (Undo/Redo): the project's one history
203
203
  import { projectHistory } from './src/history/ProjectHistory.js';
204
204
 
205
+ // Tutorials: the history converted, played in the page (?tutorial=<name>, the Tutorials menu)
206
+ import { tutorialsMenu } from './src/tutorial/Tutorial.js';
207
+ import { playTutorialNamed, readTutorialsIndex } from './src/tutorial/TutorialPlayer.js';
208
+ import { openTutorialWindow } from './src/tutorial/TutorialWindow.js';
209
+
205
210
  // PRISM Project System
206
211
  import { projectManager, ProjectEvents } from './src/project/ProjectManager.js';
207
212
  import { Dataset, DataSpec } from './src/project/Dataset.js';
@@ -416,12 +421,14 @@
416
421
  // scenario URLs so the heavy datasets don't compete for the slot
417
422
  // pool the example wants to use. Explicit `?autoload=...` overrides.
418
423
  const _exampleKey = _urlParamsAutoload.get('example') || null;
424
+ // `?tutorial=<name>` plays data/tutorials/<name>.json once the page is up (it opens its own start)
425
+ const _tutorialName = _urlParamsAutoload.get('tutorial') || null;
419
426
  const AUTOLOAD_MODE =
420
427
  _autoloadRaw === 'full' ? 'full' :
421
428
  (_autoloadRaw === 'false' || _autoloadRaw === 'none') ? 'none' :
422
429
  _autoloadRaw === 'bare' ? 'bare' :
423
430
  _autoloadRaw === 'minimal' ? 'minimal' :
424
- _exampleKey ? 'bare' :
431
+ (_exampleKey || _tutorialName) ? 'bare' :
425
432
  'minimal'; // coastlines + GEBCO only — lean dev baseline
426
433
  APP.autoloadMode = AUTOLOAD_MODE;
427
434
  APP.exampleKey = _exampleKey;
@@ -487,7 +494,8 @@
487
494
 
488
495
  splash.setProgress(95, 'Setting up menu bar...');
489
496
  // The menu bar and the optional panels, each hidden until opened
490
- initPanels(await _readExamplesIndex());
497
+ const [examples, tutorials] = await Promise.all([_readExamplesIndex(), readTutorialsIndex()]);
498
+ initPanels(examples, tutorials);
491
499
  await sleep(100);
492
500
 
493
501
  // The Outliner and the dock, with the page's own panels
@@ -571,6 +579,8 @@
571
579
  splash.setProgress(100, 'Ready!');
572
580
  await sleep(300);
573
581
  await splash.hide();
582
+ // A tutorial asked by the address plays now (src/tutorial/TutorialPlayer.js)
583
+ if (_tutorialName) playTutorialNamed(APP, _tutorialName);
574
584
  },
575
585
  },
576
586
  frame: {
@@ -1298,11 +1308,13 @@
1298
1308
  let panels = null;
1299
1309
 
1300
1310
  /** The optional panels and the menu bar, with the menu actions only this page has */
1301
- function initPanels(examples) {
1311
+ function initPanels(examples, tutorials) {
1302
1312
  panels = createPanels(APP, {
1303
- // The app's Examples (with the plugins' submenus they name) and the plugins' menus (before About)
1313
+ // The app's Examples (with the plugins' submenus they name), its Tutorials and the plugins' menus
1314
+ // (before About)
1304
1315
  menus: {
1305
1316
  ...(examples && { examples: examplesMenu(examples, EXAMPLES_PATH, APP.plugins) }),
1317
+ tutorials: tutorialsMenu(tutorials),
1306
1318
  ...pluginMenus(APP.plugins),
1307
1319
  },
1308
1320
  actions: {
@@ -1321,6 +1333,9 @@
1321
1333
  'window:remote-data': () => APP.remoteDataPanel?.toggle(),
1322
1334
  'window:console': () => APP.consolePanel?.toggle(),
1323
1335
  'create:spinoff': () => APP.spinoffPanel?.show(),
1336
+ // The history's steps as a tutorial (File menu, History window), a tutorial played
1337
+ 'file:convert-tutorial': () => openTutorialWindow(APP, { examples }),
1338
+ 'tutorials:play': (item) => item?.tutorial && playTutorialNamed(APP, item.tutorial),
1324
1339
  'about:shortcuts': () => _toggleShortcutHelp(),
1325
1340
  // Every Examples entry: `item.file` points at a
1326
1341
  // `data/examples/<key>.prism` file; `APP.handleExampleLoad`
@@ -1857,29 +1872,8 @@
1857
1872
  // The stations load again with their bundle
1858
1873
  APP._tsLoadComplete = false;
1859
1874
  },
1860
- onSerializeView: () => {
1861
- // Capture live camera + projection + viewport state for .prism save: the camera the user
1862
- // moves (on the globe the scene is drawn with its twin: GlobeCamera.js)
1863
- const cam = APP.userCamera ?? APP.camera;
1864
- const ctrl = APP.controls;
1865
- if (!cam || !ctrl) return null;
1866
- return {
1867
- camera: {
1868
- position: [cam.position.x, cam.position.y, cam.position.z],
1869
- target: [ctrl.target.x, ctrl.target.y, ctrl.target.z],
1870
- up: [cam.up.x, cam.up.y, cam.up.z],
1871
- },
1872
- viewport: viewportManager.getEffectiveLatLonRange(),
1873
- currentView: APP.currentView || 'persp',
1874
- currentProjection: APP.currentProjection || 'planar',
1875
- isOrthographic: APP.isOrthographic || false,
1876
- elevationExaggerationSurface: APP.elevationExaggerationSurface,
1877
- elevationExaggerationDepth: APP.elevationExaggerationDepth,
1878
- clipping: clippingManager.box(),
1879
- // Saved on the globe, its data viewport: centre, turn, box width (Kaveh 2026-11-14, "Save it")
1880
- globe: APP.currentProjection === 'spherical' ? viewportManager.globe.state() : undefined,
1881
- };
1882
- },
1875
+ // The live view for a .prism save (Prism.js captureView: camera, projection, viewport, clipping)
1876
+ onSerializeView: () => captureView(APP),
1883
1877
 
1884
1878
  onApplyView: _applyView,
1885
1879
  });
package/src/app/Panels.js CHANGED
@@ -153,7 +153,12 @@ export function createPanels(app, page = {}) {
153
153
  if (has.dataAnalysis) app.dataAnalysisPanel = new DataAnalysisPanel(document.body, { APP: app });
154
154
  if (has.legend) app.legendPanel = new LegendPanel(document.body);
155
155
  if (has.rawData) app.rawDataPanel = new RawDataPanel(document.body, { APP: app });
156
- if (has.history) app.historyPanel = new HistoryPanel(document.body);
156
+ // With its Convert to Tutorial button where the page converts (prism-app)
157
+ if (has.history) {
158
+ app.historyPanel = new HistoryPanel(document.body, projectHistory, {
159
+ onConvert: actions['file:convert-tutorial'] ?? null,
160
+ });
161
+ }
157
162
 
158
163
  return {
159
164
  /** A rendered frame: the Data Analysis sting gizmo keeps its size on screen */
package/src/app/Prism.js CHANGED
@@ -66,8 +66,10 @@ async function boot(manifest, page) {
66
66
  const app = page.app;
67
67
  const steps = page.steps ?? {};
68
68
  const progress = page.progress ?? (() => {});
69
- // The start is no step of the project's history (an example it runs neither)
69
+ // The start is no step of the project's history (an example it runs neither); each step keeps the view of its
70
+ // moment (a tutorial flies the camera there: src/tutorial/)
70
71
  const recording = projectHistory.hold();
72
+ projectHistory.setView(() => captureView(app));
71
73
 
72
74
  // Dataset layers (src/layers): one per dataset whose type registers createLayer
73
75
  app.layers = new LayerList(createHost(app));
@@ -254,6 +256,37 @@ export function applyView(app, view) {
254
256
  app.syncCamera?.();
255
257
  }
256
258
 
259
+ /**
260
+ * The view now in the saved-project format (applyView's twin: what File > Save writes, what each step of the project's
261
+ * history keeps): the camera the user moves (on the globe the scene is drawn with its twin: GlobeCamera.js), the data
262
+ * viewport, the named view, the projection, the orthographic camera, both exaggerations, the shared clipping box and,
263
+ * on the globe, its data viewport (centre, turn, box).
264
+ * @param {Object} app
265
+ * @returns {Object|null} null before the page has its camera and orbit
266
+ */
267
+ export function captureView(app) {
268
+ const cam = app.userCamera ?? app.camera;
269
+ const ctrl = app.controls;
270
+ const vm = app.viewportManager;
271
+ if (!cam || !ctrl || !vm) return null;
272
+ return {
273
+ camera: {
274
+ position: [cam.position.x, cam.position.y, cam.position.z],
275
+ target: [ctrl.target.x, ctrl.target.y, ctrl.target.z],
276
+ up: [cam.up.x, cam.up.y, cam.up.z],
277
+ },
278
+ viewport: vm.getEffectiveLatLonRange(),
279
+ currentView: app.currentView || 'persp',
280
+ currentProjection: app.currentProjection || 'planar',
281
+ isOrthographic: app.isOrthographic || false,
282
+ elevationExaggerationSurface: app.elevationExaggerationSurface,
283
+ elevationExaggerationDepth: app.elevationExaggerationDepth,
284
+ clipping: app.clippingManager?.box(),
285
+ // On the globe, its data viewport: centre, turn, box width
286
+ globe: app.currentProjection === 'spherical' ? vm.globe?.state() : undefined,
287
+ };
288
+ }
289
+
257
290
  /**
258
291
  * Select a dataset of the project: by its id, or the bundled dataset of that
259
292
  * key (BundledData).
@@ -19,8 +19,11 @@
19
19
  * within MERGE_MS, joins it (a slider stepped by its arrow keys, a value
20
20
  * typed then nudged). The steps are saved with the project (`serialize`,
21
21
  * `restore`); a kind that cannot be (`saved: false`: a removed row's data)
22
- * saves a stub the history stops at. Their data is what a tutorial will
23
- * replay (Kaveh: "Ready now, build after").
22
+ * saves a stub the history stops at. Their data is what a tutorial replays
23
+ * (src/tutorial/): each step also keeps the view of its moment (`view`: the
24
+ * camera, the projection, the data viewport, as a saved project keeps its
25
+ * view), never put back by undo or redo, where a tutorial flies the camera
26
+ * before the step's action.
24
27
  *
25
28
  * @license MIT
26
29
  */
@@ -54,12 +57,25 @@ const same = (a, b) => {
54
57
  }
55
58
  };
56
59
 
60
+ /** A view as a step keeps it: plain data (a copy: the page's own objects change), none when it cannot be read */
61
+ function viewCopy(read) {
62
+ if (!read) return undefined;
63
+ try {
64
+ const view = read();
65
+ return view ? JSON.parse(JSON.stringify(view)) : undefined;
66
+ } catch (err) {
67
+ log.warn('view not kept with the step:', err.message);
68
+ return undefined;
69
+ }
70
+ }
71
+
57
72
  /**
58
73
  * @param {Object} [options]
59
74
  * @param {number} [options.max] - The newest steps kept
60
75
  * @param {Function} [options.now] - The clock (ms), for tests
76
+ * @param {Function} [options.view] - The view of the moment (Prism.js captureView), kept with each step recorded
61
77
  */
62
- export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {}) {
78
+ export function createHistory({ max = MAX_STEPS, now = () => Date.now(), view = null } = {}) {
63
79
  /** @type {Object[]} */
64
80
  let steps = [];
65
81
  /** The last step done (-1: none) */
@@ -67,6 +83,7 @@ export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {})
67
83
  let quiet = 0;
68
84
  let applying = false;
69
85
  let nextId = 1;
86
+ let readView = view;
70
87
  /** Undo / redo one after another: a kind may put its value back asynchronously (a row added again) */
71
88
  let queue = Promise.resolve();
72
89
  const kinds = new Map();
@@ -87,7 +104,7 @@ export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {})
87
104
  }
88
105
 
89
106
  /**
90
- * A change the user made.
107
+ * A change the user made, with the view of its moment (the joined step: the view at its last nudge).
91
108
  * @param {{kind: string, label: string, before: *, after: *, rows?: Object[], merge?: string}} step
92
109
  * @returns {Object|null} The step recorded, null when none (quiet, putting a step back, no change)
93
110
  */
@@ -103,6 +120,8 @@ export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {})
103
120
  last.after = step.after;
104
121
  last.label = step.label;
105
122
  last.time = time;
123
+ const seen = viewCopy(readView);
124
+ if (seen) last.view = seen;
106
125
  if (same(last.before, last.after)) {
107
126
  steps.pop();
108
127
  index--;
@@ -112,7 +131,8 @@ export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {})
112
131
  }
113
132
  if (same(step.before, step.after)) return null;
114
133
  steps.length = index + 1;
115
- const recorded = { ...step, id: `s${nextId++}`, time };
134
+ const seen = viewCopy(readView);
135
+ const recorded = { ...step, id: `s${nextId++}`, time, ...(seen && { view: seen }) };
116
136
  steps.push(recorded);
117
137
  if (steps.length > max) steps.splice(0, steps.length - max);
118
138
  index = steps.length - 1;
@@ -120,12 +140,12 @@ export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {})
120
140
  return recorded;
121
141
  }
122
142
 
123
- function put(step, side) {
143
+ function put(step, side, value = step[side]) {
124
144
  const kind = kinds.get(step.kind);
125
145
  applying = true;
126
146
  let done;
127
147
  try {
128
- done = kind.apply(step, step[side], side);
148
+ done = kind.apply(step, value, side);
129
149
  } catch (err) {
130
150
  applying = false;
131
151
  throw err;
@@ -141,6 +161,18 @@ export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {})
141
161
  return run;
142
162
  };
143
163
 
164
+ /**
165
+ * A value put through a step's kind as undo and redo put theirs, recording nothing, the history's place unmoved: a
166
+ * tutorial's slider on its way to the step's value (src/tutorial/TutorialPlayer.js)
167
+ * @param {Object} step
168
+ * @param {*} value
169
+ * @returns {Promise<void>}
170
+ */
171
+ function show(step, value) {
172
+ if (!kinds.has(step.kind)) return Promise.resolve();
173
+ return queued(() => put(step, 'after', value));
174
+ }
175
+
144
176
  /** @returns {Promise<boolean>} Whether a step was undone */
145
177
  function undo() {
146
178
  return queued(async () => {
@@ -256,11 +288,20 @@ export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {})
256
288
  changed();
257
289
  }
258
290
 
291
+ /**
292
+ * What gives the view each step recorded keeps (the page's: Prism.js captureView)
293
+ * @param {Function|null} fn - () => the view, null: none kept
294
+ */
295
+ function setView(fn) {
296
+ readView = typeof fn === 'function' ? fn : null;
297
+ }
298
+
259
299
  return {
260
300
  define,
261
301
  record,
262
302
  undo,
263
303
  redo,
304
+ show,
264
305
  jumpTo,
265
306
  remove,
266
307
  clear,
@@ -268,6 +309,7 @@ export function createHistory({ max = MAX_STEPS, now = () => Date.now() } = {})
268
309
  hold,
269
310
  serialize,
270
311
  restore,
312
+ setView,
271
313
  state,
272
314
  /** Whether a step is being put back (its kind's apply runs) */
273
315
  get applying() {