ciesm-prism 1.0.1359 → 1.0.1362
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/package.json +2 -4
- package/plugins/metacube/MGS.2.GUI.js +147 -44
- package/plugins/metacube/MGS.2.js +3 -0
- package/plugins/metacube/index.js +33 -12
- package/plugins/metacube/mc-outline.js +239 -0
- package/plugins/metacube/plugin.js +2 -0
- package/src/ui/panels/OutlinerPanel.js +48 -6
- package/src/ui/panels/SpinoffPanel.js +4 -1
- package/src/version.json +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ciesm-prism",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1362",
|
|
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",
|
|
@@ -19,9 +19,7 @@
|
|
|
19
19
|
"url": "git+https://github.com/KavehR/PRISM.git"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"author":
|
|
23
|
-
"name": "Kaveh Rassoulzadegan, Mediterranean Science Commission (CIESM Monaco - Paris)"
|
|
24
|
-
},
|
|
22
|
+
"author": "Kaveh Rassoulzadegan, Mediterranean Science Commission, CIESM Monaco - Paris",
|
|
25
23
|
"type": "module",
|
|
26
24
|
"bin": {
|
|
27
25
|
"ciesm-prism": "bin/prism.mjs"
|
|
@@ -21,6 +21,7 @@ import { followSamples } from './mc-geo-markers.js';
|
|
|
21
21
|
import { reportHover } from './mc-raw-hover.js';
|
|
22
22
|
import { mcInteraction } from './mc-interaction.js';
|
|
23
23
|
import { openOrganismPanel } from './mc-organism-panel.js';
|
|
24
|
+
import * as outline from './mc-outline.js';
|
|
24
25
|
import { RenderPanel, RenderPanelManager, makeDockable } from './mc-render-panel.js';
|
|
25
26
|
import { projectManager } from '../../src/project/ProjectManager.js';
|
|
26
27
|
import { Dataset, DataSpec } from '../../src/project/Dataset.js';
|
|
@@ -1081,26 +1082,134 @@ export function createFileGUI() {
|
|
|
1081
1082
|
};
|
|
1082
1083
|
}
|
|
1083
1084
|
|
|
1085
|
+
// ── MetaCube's own Outliner nodes (MetaCube > Create, mc-outline.js) ─────────
|
|
1086
|
+
|
|
1087
|
+
// The nodes shown open after a change: the path to the node made or moved
|
|
1088
|
+
let _outlineOpen = new Set();
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* A name asked in MetaCube's dialog, the given one offered and selected
|
|
1092
|
+
* @param {string} title
|
|
1093
|
+
* @param {string} offered
|
|
1094
|
+
* @param {(name: string) => void} done - With the name, on OK or Enter
|
|
1095
|
+
*/
|
|
1096
|
+
function _askName(title, offered, done) {
|
|
1097
|
+
const input = document.createElement('input');
|
|
1098
|
+
input.type = 'text';
|
|
1099
|
+
input.value = offered;
|
|
1100
|
+
input.style.width = '100%';
|
|
1101
|
+
const label = document.createElement('label');
|
|
1102
|
+
label.textContent = 'Name';
|
|
1103
|
+
label.style.display = 'block';
|
|
1104
|
+
label.style.marginBottom = '6px';
|
|
1105
|
+
const body = document.createElement('div');
|
|
1106
|
+
body.append(label, input);
|
|
1107
|
+
_mcModal(title, body, {
|
|
1108
|
+
OK: (close) => {
|
|
1109
|
+
const name = input.value.trim();
|
|
1110
|
+
if (!name) return input.focus();
|
|
1111
|
+
close();
|
|
1112
|
+
done(name);
|
|
1113
|
+
},
|
|
1114
|
+
Cancel: (close) => close(),
|
|
1115
|
+
});
|
|
1116
|
+
input.focus();
|
|
1117
|
+
input.select();
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/** Where the Outliner's selected row puts a new node: inside a MetaCube node or an organism, else at the top */
|
|
1121
|
+
function _outlinerTarget() {
|
|
1122
|
+
const d = window.APP?.outlinerPanel?.fancytree?.getActiveNode?.()?.data;
|
|
1123
|
+
return _outlinePlace(d) || { top: true };
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
/**
|
|
1127
|
+
* A row of the Outliner as a place of the outline (mc-outline.js), or null where nothing goes: a pathway or
|
|
1128
|
+
* reaction read from a sample's data, another dataset's row
|
|
1129
|
+
*/
|
|
1130
|
+
function _outlinePlace(d) {
|
|
1131
|
+
if (!d || !MC.data._metadagDatasetId || d.datasetId !== MC.data._metadagDatasetId) return null;
|
|
1132
|
+
if (d.mcNode) return { node: d.metadagKey };
|
|
1133
|
+
if (d.metadagType === 'sample') return { sample: d.metadagKey };
|
|
1134
|
+
if (!d.metadagKey) return { top: true }; // the project's own row
|
|
1135
|
+
return null;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* The project's row shows the outline again (made when the project has none), the node changed selected in it
|
|
1140
|
+
* and the path to it open
|
|
1141
|
+
* @param {string|null} id - The node made, moved or renamed; null: one removed
|
|
1142
|
+
*/
|
|
1143
|
+
function _outlineChanged(id) {
|
|
1144
|
+
const project = MC.data.currentProject;
|
|
1145
|
+
_outlineOpen = new Set(id ? outline.pathTo(project, id) : []);
|
|
1146
|
+
const row = MC.data._metadagDatasetId && projectManager.getDataset(MC.data._metadagDatasetId);
|
|
1147
|
+
if (row) row.metadagMetadata = { hierarchy: _metaDAGHierarchy(project) };
|
|
1148
|
+
else _registerMetaDAGDataset(project.title);
|
|
1149
|
+
const panel = window.APP?.outlinerPanel;
|
|
1150
|
+
panel?.refresh();
|
|
1151
|
+
// Selected once a new row's own selection is through (plugin.js selects a row MetaCube adds, in a microtask)
|
|
1152
|
+
if (id) {
|
|
1153
|
+
setTimeout(() => {
|
|
1154
|
+
panel?.fancytree?.getNodeByKey(`${MC.data._metadagDatasetId}_md_${id}`)?.setActive(true, { noEvents: true });
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/** MetaCube > Create > a blank node of a kind, its name asked: inside the selected node when its kind may stand there */
|
|
1160
|
+
function _createBlank(kind) {
|
|
1161
|
+
const project = MC.data.currentProject;
|
|
1162
|
+
const target = _outlinerTarget();
|
|
1163
|
+
_askName(`New ${outline.KINDS[kind].label}`, outline.nextName(project, kind), (name) => {
|
|
1164
|
+
const node = outline.makeNode(kind, name);
|
|
1165
|
+
outline.addNode(project, node, target);
|
|
1166
|
+
_outlineChanged(node.id);
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
/**
|
|
1171
|
+
* Where an Outliner row of a MetaCube node may drop on another row (registration outliner.dropModes)
|
|
1172
|
+
* @returns {string[]|false}
|
|
1173
|
+
*/
|
|
1174
|
+
export function outlineDropModes(id, targetData) {
|
|
1175
|
+
const place = _outlinePlace(targetData);
|
|
1176
|
+
const modes = place ? outline.dropModes(MC.data.currentProject, id, place) : [];
|
|
1177
|
+
return modes.length ? modes : false;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
/** A MetaCube node dropped on a row (registration outliner.drop) */
|
|
1181
|
+
export function outlineDrop(id, targetData, mode) {
|
|
1182
|
+
const place = _outlinePlace(targetData);
|
|
1183
|
+
if (place && outline.moveNode(MC.data.currentProject, id, place, mode)) _outlineChanged(id);
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
/** A MetaCube node's right-click items: rename it, delete it with what it holds (registration outliner.menu) */
|
|
1187
|
+
export function outlineMenu(id) {
|
|
1188
|
+
const project = MC.data.currentProject;
|
|
1189
|
+
const at = outline.locate(project, id);
|
|
1190
|
+
if (!at) return [];
|
|
1191
|
+
return [
|
|
1192
|
+
{
|
|
1193
|
+
label: 'Rename…',
|
|
1194
|
+
action: () =>
|
|
1195
|
+
_askName(`Rename ${outline.KINDS[at.node.type]?.label || 'node'}`, at.node.name, (name) => {
|
|
1196
|
+
if (outline.renameNode(project, id, name)) _outlineChanged(id);
|
|
1197
|
+
}),
|
|
1198
|
+
},
|
|
1199
|
+
{
|
|
1200
|
+
label: 'Delete',
|
|
1201
|
+
icon: '×',
|
|
1202
|
+
action: () => {
|
|
1203
|
+
if (outline.removeNode(project, id)) _outlineChanged(null);
|
|
1204
|
+
},
|
|
1205
|
+
},
|
|
1206
|
+
];
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1084
1209
|
// Create menu action handlers (menu UI created in createMenuBar)
|
|
1085
1210
|
const _createActions = {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
_nameIn.type = 'text'; _nameIn.required = true;
|
|
1089
|
-
const _form = document.createElement('form');
|
|
1090
|
-
const _lbl = document.createElement('label');
|
|
1091
|
-
_lbl.textContent = 'Name: ';
|
|
1092
|
-
_form.append(_lbl, _nameIn);
|
|
1093
|
-
|
|
1094
|
-
_mcModal('New Metagenome', _form, {
|
|
1095
|
-
OK: (close) => {
|
|
1096
|
-
const name = _nameIn.value.trim();
|
|
1097
|
-
if (!name) { alert('Please enter a name'); return; }
|
|
1098
|
-
new Metagenome(name);
|
|
1099
|
-
close();
|
|
1100
|
-
},
|
|
1101
|
-
Cancel: (close) => close()
|
|
1102
|
-
});
|
|
1103
|
-
},
|
|
1211
|
+
// Blank nodes in the Outliner, nested in the biological order (mc-outline.js); an organism: its window
|
|
1212
|
+
metagenome: () => _createBlank('metagenome'),
|
|
1104
1213
|
organism: () => {
|
|
1105
1214
|
// A project without reactions: its MetaDAG window waits for an organism bringing some
|
|
1106
1215
|
if (!projectHasReactions()) {
|
|
@@ -1109,30 +1218,11 @@ const _createActions = {
|
|
|
1109
1218
|
}
|
|
1110
1219
|
openOrganismPanel(window.APP, { add: addOrganism });
|
|
1111
1220
|
},
|
|
1112
|
-
metabolism: () =>
|
|
1113
|
-
pathway: () =>
|
|
1114
|
-
reaction: () =>
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
const _form2 = document.createElement('form');
|
|
1118
|
-
const _lbl2 = document.createElement('label');
|
|
1119
|
-
_lbl2.textContent = 'reaction ID: ';
|
|
1120
|
-
_form2.append(_lbl2, _idIn);
|
|
1121
|
-
|
|
1122
|
-
_mcModal('New Reaction', _form2, {
|
|
1123
|
-
OK: (close) => {
|
|
1124
|
-
const id = _idIn.value.trim();
|
|
1125
|
-
if (!id) { alert('Please enter a name'); return; }
|
|
1126
|
-
const re = new bioModels.Reaction(id);
|
|
1127
|
-
MC.data.currentProject.addReaction(re);
|
|
1128
|
-
updateRender.createReactionsGeometry(re);
|
|
1129
|
-
close();
|
|
1130
|
-
},
|
|
1131
|
-
Cancel: (close) => close()
|
|
1132
|
-
});
|
|
1133
|
-
},
|
|
1134
|
-
enzyme: () => { /* … */ },
|
|
1135
|
-
enzymeSubType: () => { /* … */ }
|
|
1221
|
+
metabolism: () => _createBlank('metabolism'),
|
|
1222
|
+
pathway: () => _createBlank('pathway'),
|
|
1223
|
+
reaction: () => _createBlank('reaction'),
|
|
1224
|
+
enzyme: () => _createBlank('enzyme'),
|
|
1225
|
+
enzymeSubType: () => _createBlank('enzyme-sub'),
|
|
1136
1226
|
};
|
|
1137
1227
|
let guard = false;
|
|
1138
1228
|
// 6) when A changes
|
|
@@ -1565,7 +1655,9 @@ function _buildMetaDAGSubtree(children) {
|
|
|
1565
1655
|
|
|
1566
1656
|
/**
|
|
1567
1657
|
* MetaCube's project as the Outliner's tree: each sample, then its own children (a MetaDAG
|
|
1568
|
-
* import's pathways → reactions), else its pathways and their reactions from its rows
|
|
1658
|
+
* import's pathways → reactions), else its pathways and their reactions from its rows; MetaCube's
|
|
1659
|
+
* own nodes (MetaCube > Create, mc-outline.js) first under the organism they stand under, the
|
|
1660
|
+
* others after the samples
|
|
1569
1661
|
*/
|
|
1570
1662
|
function _metaDAGHierarchy(project) {
|
|
1571
1663
|
const hierarchy = [];
|
|
@@ -1583,7 +1675,14 @@ function _metaDAGHierarchy(project) {
|
|
|
1583
1675
|
});
|
|
1584
1676
|
}
|
|
1585
1677
|
}
|
|
1586
|
-
return hierarchy;
|
|
1678
|
+
if (!project) return hierarchy;
|
|
1679
|
+
const { under, top } = outline.outlineItems(project, new Set(hierarchy.map((s) => s.id)), _outlineOpen);
|
|
1680
|
+
for (const sample of hierarchy) {
|
|
1681
|
+
const own = under.get(sample.id);
|
|
1682
|
+
if (own) sample.children = [...own, ...sample.children];
|
|
1683
|
+
if (_outlineOpen.has(sample.id)) sample.expanded = true;
|
|
1684
|
+
}
|
|
1685
|
+
return [...hierarchy, ...top];
|
|
1587
1686
|
}
|
|
1588
1687
|
|
|
1589
1688
|
/**
|
|
@@ -4332,7 +4431,11 @@ const MENU_ACTIONS = {
|
|
|
4332
4431
|
'mc:file:export': () => fileGUIParameters.exportCompressed(),
|
|
4333
4432
|
'mc:create:metagenome': () => _createActions.metagenome(),
|
|
4334
4433
|
'mc:create:organism': () => _createActions.organism(),
|
|
4434
|
+
'mc:create:metabolism': () => _createActions.metabolism(),
|
|
4435
|
+
'mc:create:pathway': () => _createActions.pathway(),
|
|
4335
4436
|
'mc:create:reaction': () => _createActions.reaction(),
|
|
4437
|
+
'mc:create:enzyme': () => _createActions.enzyme(),
|
|
4438
|
+
'mc:create:enzyme-sub': () => _createActions.enzymeSubType(),
|
|
4336
4439
|
'mc:window:outliner': () => window.APP?.outlinerPanel?.toggle(),
|
|
4337
4440
|
'mc:window:controls': () => window.APP?.controlPanel?.toggle(),
|
|
4338
4441
|
'mc:window:rawdata': () => window.APP?.rawDataPanel?.toggle(),
|
|
@@ -110,6 +110,8 @@ export class MCProject {
|
|
|
110
110
|
this.folder = true;
|
|
111
111
|
this.expanded = true;
|
|
112
112
|
this.children = [];
|
|
113
|
+
// MetaCube's own Outliner nodes (MetaCube > Create), apart from the samples: mc-outline.js
|
|
114
|
+
this.outline = [];
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
reset() {
|
|
@@ -117,6 +119,7 @@ export class MCProject {
|
|
|
117
119
|
this.folder = true;
|
|
118
120
|
this.expanded = true;
|
|
119
121
|
this.children = [];
|
|
122
|
+
this.outline = [];
|
|
120
123
|
//console.log("New project");
|
|
121
124
|
}
|
|
122
125
|
|
|
@@ -135,8 +135,10 @@ typeRegistry.register({
|
|
|
135
135
|
outliner: {
|
|
136
136
|
icon: { char: '\u{1F30C}', color: '#ce93d8' },
|
|
137
137
|
tree: (ds) => (ds.metadagMetadata?.hierarchy ? { children: metaDAGChildren(ds), expanded: true } : null),
|
|
138
|
-
// MetaDAG node clicked — emit selection event (Shift adds, Alt removes, else it replaces)
|
|
138
|
+
// MetaDAG node clicked — emit selection event (Shift adds, Alt removes, else it replaces); MetaCube's own
|
|
139
|
+
// nodes are in no view: selected in the Outliner only (where MetaCube > Create puts the next one)
|
|
139
140
|
activate(d, node, event) {
|
|
141
|
+
if (d.mcNode) return;
|
|
140
142
|
const e = event?.originalEvent;
|
|
141
143
|
eventBus.emit('metadag:node:selected', {
|
|
142
144
|
datasetId: d.datasetId,
|
|
@@ -148,6 +150,7 @@ typeRegistry.register({
|
|
|
148
150
|
},
|
|
149
151
|
// MetaDAG node hovered — the MetaDAG view highlights it
|
|
150
152
|
hover(d, node, entering) {
|
|
153
|
+
if (d.mcNode) return;
|
|
151
154
|
eventBus.emit('metadag:node:hover', {
|
|
152
155
|
datasetId: d.datasetId,
|
|
153
156
|
nodeKey: d.metadagKey,
|
|
@@ -155,6 +158,12 @@ typeRegistry.register({
|
|
|
155
158
|
entering,
|
|
156
159
|
});
|
|
157
160
|
},
|
|
161
|
+
// MetaCube's own nodes move by drag and drop in the biological order, rename and delete by right click
|
|
162
|
+
// (mc-outline.js, through MetaCube once opened: its project holds them)
|
|
163
|
+
drag: (d) => !!d.mcNode,
|
|
164
|
+
dropModes: (d, target) => metaCube?.outlineDropModes(d.metadagKey, target.data) || false,
|
|
165
|
+
drop: (d, target, mode) => metaCube?.outlineDrop(d.metadagKey, target.data, mode),
|
|
166
|
+
menu: (d) => (d.mcNode && metaCube ? metaCube.outlineMenu(d.metadagKey) : []),
|
|
158
167
|
},
|
|
159
168
|
controls: () => [
|
|
160
169
|
{
|
|
@@ -406,7 +415,10 @@ function keggChildren(dataset) {
|
|
|
406
415
|
return catNodes;
|
|
407
416
|
}
|
|
408
417
|
|
|
409
|
-
/**
|
|
418
|
+
/**
|
|
419
|
+
* MetaDAG project hierarchy: sample → pathway → reaction (metadagMetadata.hierarchy), and MetaCube's own
|
|
420
|
+
* nodes (MetaCube > Create, `user`: mc-outline.js), which drag and drop in the biological order.
|
|
421
|
+
*/
|
|
410
422
|
function metaDAGChildren(dataset) {
|
|
411
423
|
const hierarchy = dataset.metadagMetadata.hierarchy;
|
|
412
424
|
const TYPE_FLAGS = {
|
|
@@ -416,24 +428,32 @@ function metaDAGChildren(dataset) {
|
|
|
416
428
|
};
|
|
417
429
|
const TYPE_ICONS = {
|
|
418
430
|
sample: { char: '\u{1F9EA}', color: '#a5d6a7' },
|
|
431
|
+
metagenome: { char: '\u{1F310}', color: '#80deea' },
|
|
432
|
+
metabolism: { char: '♻', color: '#c5e1a5' },
|
|
419
433
|
pathway: { char: '\u{1F6E4}', color: '#90caf9' },
|
|
420
434
|
reaction: { char: '⚗', color: '#ffcc80' },
|
|
435
|
+
enzyme: { char: '⚙', color: '#f48fb1' },
|
|
436
|
+
'enzyme-sub': { char: '⚙', color: '#ce93d8' },
|
|
421
437
|
};
|
|
422
438
|
const ITEM_ICON = { char: '•', color: '#b0bec5' };
|
|
423
439
|
|
|
424
440
|
const buildNodes = (items, dsId) => {
|
|
425
441
|
return items.map((item) => {
|
|
426
|
-
|
|
442
|
+
// MetaCube's own nodes carry no view's flag: no eye, no view to select in
|
|
443
|
+
const flag = item.user ? 'mcNode' : TYPE_FLAGS[item.type] || 'isMetaDAGItem';
|
|
427
444
|
const hasChildren = item.children && item.children.length > 0;
|
|
428
445
|
const childCount = hasChildren ? ` (${item.children.length})` : '';
|
|
429
446
|
return {
|
|
430
447
|
title: `${item.name}${childCount}`,
|
|
431
448
|
key: `${dsId}_md_${item.id}`,
|
|
432
|
-
expanded:
|
|
433
|
-
folder: hasChildren,
|
|
449
|
+
expanded: !!item.expanded,
|
|
450
|
+
folder: hasChildren || (!!item.user && item.type !== 'enzyme-sub'),
|
|
434
451
|
data: {
|
|
435
452
|
datasetId: dsId,
|
|
436
453
|
[flag]: true,
|
|
454
|
+
// Rows without an eye of their own (MetaCube's nodes, reactions) carry no buttons: the
|
|
455
|
+
// dataset row's trash and eye, which the Outliner gives an unmarked row, act on the whole project
|
|
456
|
+
noButtons: flag !== 'isMetaDAGSample' && flag !== 'isMetaDAGPathway',
|
|
437
457
|
metadagKey: item.id,
|
|
438
458
|
metadagType: item.type,
|
|
439
459
|
visible: item.visible !== false,
|
|
@@ -705,15 +725,16 @@ export const menuItems = {
|
|
|
705
725
|
{ id: 'mc-import', label: 'Import (MetaDAG) zip...', action: 'mc:file:import' },
|
|
706
726
|
{ id: 'mc-export', label: 'Export (MetaDAG) zip...', action: 'mc:file:export' },
|
|
707
727
|
],
|
|
708
|
-
// Organism: its window (mc-organism-panel.js)
|
|
728
|
+
// Organism: its window (mc-organism-panel.js); the others: a blank node of their kind in the Outliner, inside the
|
|
729
|
+
// selected one when the biological order allows it (MGS.2.GUI.js _createBlank, mc-outline.js)
|
|
709
730
|
create: [
|
|
710
|
-
{ id: 'mc-metagenome', label: 'Metagenome', action: 'mc:create:metagenome'
|
|
731
|
+
{ id: 'mc-metagenome', label: 'Metagenome', action: 'mc:create:metagenome' },
|
|
711
732
|
{ id: 'mc-organism', label: 'Organism', action: 'mc:create:organism' },
|
|
712
|
-
{ id: 'mc-metabolism', label: 'Metabolism', action: 'mc:create:metabolism'
|
|
713
|
-
{ id: 'mc-pathway', label: 'Pathway', action: 'mc:create:pathway'
|
|
714
|
-
{ id: 'mc-reaction', label: 'Reaction', action: 'mc:create:reaction'
|
|
715
|
-
{ id: 'mc-enzyme', label: 'Enzyme', action: 'mc:create:enzyme'
|
|
716
|
-
{ id: 'mc-enzyme-sub', label: 'Custom Enzyme SubType', action: 'mc:create:enzyme-sub'
|
|
733
|
+
{ id: 'mc-metabolism', label: 'Metabolism', action: 'mc:create:metabolism' },
|
|
734
|
+
{ id: 'mc-pathway', label: 'Pathway', action: 'mc:create:pathway' },
|
|
735
|
+
{ id: 'mc-reaction', label: 'Reaction', action: 'mc:create:reaction' },
|
|
736
|
+
{ id: 'mc-enzyme', label: 'Enzyme', action: 'mc:create:enzyme' },
|
|
737
|
+
{ id: 'mc-enzyme-sub', label: 'Custom Enzyme SubType', action: 'mc:create:enzyme-sub' },
|
|
717
738
|
],
|
|
718
739
|
examples: EXAMPLES.map((ex, i) => ({ id: `mc-example-${i}`, action: 'mc:example:load', ...ex })),
|
|
719
740
|
megaGraph: [
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mc-outline.js - MetaCube's own nodes in the Outliner: the blank Metagenome, Metabolism, Pathway, Reaction,
|
|
3
|
+
* Enzyme and Custom Enzyme SubType nodes MetaCube > Create adds, named by the user and nested by drag and drop
|
|
4
|
+
* in the biological order: a node stands inside any node of a higher rank (Metagenome > Organism > Metabolism >
|
|
5
|
+
* Pathway > Reaction > Enzyme > Custom Enzyme SubType), levels may be skipped. An organism is one of the
|
|
6
|
+
* project's samples: a root of the outline may stand under one (`under`, the sample's key).
|
|
7
|
+
*
|
|
8
|
+
* The nodes live in the project's `outline` (written in its .mgp), apart from the samples the 3-D views draw:
|
|
9
|
+
* no view reads them. Pure: no page, no PRISM.
|
|
10
|
+
*
|
|
11
|
+
* @license MIT
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** The kinds in their order: a node stands inside a node of a lower rank */
|
|
15
|
+
export const KINDS = Object.freeze({
|
|
16
|
+
metagenome: { rank: 1, label: 'Metagenome' },
|
|
17
|
+
sample: { rank: 2, label: 'Organism' },
|
|
18
|
+
metabolism: { rank: 3, label: 'Metabolism' },
|
|
19
|
+
pathway: { rank: 4, label: 'Pathway' },
|
|
20
|
+
reaction: { rank: 5, label: 'Reaction' },
|
|
21
|
+
enzyme: { rank: 6, label: 'Enzyme' },
|
|
22
|
+
'enzyme-sub': { rank: 7, label: 'Custom Enzyme SubType' },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether a node of a kind may stand in a place
|
|
27
|
+
* @param {string|null} holder - The holder's kind ('sample' for an organism), null for the project's top
|
|
28
|
+
* @param {string} kind
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
*/
|
|
31
|
+
export function mayHold(holder, kind) {
|
|
32
|
+
if (!KINDS[kind] || kind === 'sample') return false;
|
|
33
|
+
if (holder === null) return true;
|
|
34
|
+
return !!KINDS[holder] && KINDS[holder].rank < KINDS[kind].rank;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The project's outline (made for a project written before it) */
|
|
38
|
+
export function outlineOf(project) {
|
|
39
|
+
if (!Array.isArray(project.outline)) project.outline = [];
|
|
40
|
+
return project.outline;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let made = 0;
|
|
44
|
+
/**
|
|
45
|
+
* A blank node
|
|
46
|
+
* @param {string} kind - A key of KINDS but 'sample'
|
|
47
|
+
* @param {string} name
|
|
48
|
+
* @returns {{id: string, type: string, name: string, children: Object[]}}
|
|
49
|
+
*/
|
|
50
|
+
export function makeNode(kind, name) {
|
|
51
|
+
made += 1;
|
|
52
|
+
return { id: `mco-${Date.now().toString(36)}-${made.toString(36)}`, type: kind, name, children: [] };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The name a new node of a kind is offered: its kind and the next number */
|
|
56
|
+
export function nextName(project, kind) {
|
|
57
|
+
let count = 0;
|
|
58
|
+
walk(outlineOf(project), (node) => {
|
|
59
|
+
if (node.type === kind) count += 1;
|
|
60
|
+
});
|
|
61
|
+
return `${KINDS[kind]?.label || kind} ${count + 1}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function walk(list, visit) {
|
|
65
|
+
for (const node of list) {
|
|
66
|
+
visit(node);
|
|
67
|
+
walk(node.children || [], visit);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Where a node is
|
|
73
|
+
* @returns {{list: Object[], index: number, node: Object, parent: Object|null, under: string|null}|null} Its
|
|
74
|
+
* list and place there, its parent node (null: a root), the sample its root stands under
|
|
75
|
+
*/
|
|
76
|
+
export function locate(project, id) {
|
|
77
|
+
const find = (list, parent, under) => {
|
|
78
|
+
for (let index = 0; index < list.length; index++) {
|
|
79
|
+
const node = list[index];
|
|
80
|
+
const at = parent ? under : (node.under ?? null);
|
|
81
|
+
if (node.id === id) return { list, index, node, parent, under: at };
|
|
82
|
+
const found = find(node.children || [], node, at);
|
|
83
|
+
if (found) return found;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
};
|
|
87
|
+
return find(outlineOf(project), null, null);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Whether a node is the given one or holds it */
|
|
91
|
+
function holds(node, id) {
|
|
92
|
+
return node.id === id || (node.children || []).some((child) => holds(child, id));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The kind of what holds a node: its parent's, 'sample' for a root under an organism, null at the top */
|
|
96
|
+
function holderOf(at) {
|
|
97
|
+
if (at.parent) return at.parent.type;
|
|
98
|
+
return at.under ? 'sample' : null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Where a dragged node may go on a target: 'over' (inside it), 'before' and 'after' (beside it)
|
|
103
|
+
* @param {Object} project
|
|
104
|
+
* @param {string} id - The dragged node
|
|
105
|
+
* @param {{top?: true, sample?: string, node?: string}} target - The project's top, an organism, a node
|
|
106
|
+
* @returns {string[]} The modes allowed; none: refused
|
|
107
|
+
*/
|
|
108
|
+
export function dropModes(project, id, target) {
|
|
109
|
+
const at = locate(project, id);
|
|
110
|
+
if (!at) return [];
|
|
111
|
+
const kind = at.node.type;
|
|
112
|
+
if (target.top) return ['over'];
|
|
113
|
+
if (target.sample) return mayHold('sample', kind) ? ['over'] : [];
|
|
114
|
+
if (!target.node || holds(at.node, target.node)) return [];
|
|
115
|
+
const there = locate(project, target.node);
|
|
116
|
+
if (!there) return [];
|
|
117
|
+
const modes = [];
|
|
118
|
+
if (mayHold(there.node.type, kind)) modes.push('over');
|
|
119
|
+
if (mayHold(holderOf(there), kind)) modes.push('before', 'after');
|
|
120
|
+
return modes;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A node moved inside a target or beside it, as dropModes allows
|
|
125
|
+
* @returns {boolean} Whether it moved
|
|
126
|
+
*/
|
|
127
|
+
export function moveNode(project, id, target, mode) {
|
|
128
|
+
if (!dropModes(project, id, target).includes(mode)) return false;
|
|
129
|
+
const from = locate(project, id);
|
|
130
|
+
from.list.splice(from.index, 1);
|
|
131
|
+
const node = from.node;
|
|
132
|
+
delete node.under;
|
|
133
|
+
const roots = outlineOf(project);
|
|
134
|
+
if (target.top) {
|
|
135
|
+
roots.push(node);
|
|
136
|
+
} else if (target.sample) {
|
|
137
|
+
node.under = target.sample;
|
|
138
|
+
roots.push(node);
|
|
139
|
+
} else {
|
|
140
|
+
const there = locate(project, target.node);
|
|
141
|
+
if (mode === 'over') {
|
|
142
|
+
there.node.children.push(node);
|
|
143
|
+
} else {
|
|
144
|
+
// Beside a root under an organism: under it too
|
|
145
|
+
if (!there.parent && there.under) node.under = there.under;
|
|
146
|
+
there.list.splice(there.index + (mode === 'after' ? 1 : 0), 0, node);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A blank node added inside a target when its kind may stand there, else at the project's top
|
|
154
|
+
* @returns {{top?: true, sample?: string, node?: string}} Where it went
|
|
155
|
+
*/
|
|
156
|
+
export function addNode(project, node, target = { top: true }) {
|
|
157
|
+
const roots = outlineOf(project);
|
|
158
|
+
if (target.node) {
|
|
159
|
+
const there = locate(project, target.node);
|
|
160
|
+
if (there && mayHold(there.node.type, node.type)) {
|
|
161
|
+
there.node.children.push(node);
|
|
162
|
+
return { node: target.node };
|
|
163
|
+
}
|
|
164
|
+
} else if (target.sample && mayHold('sample', node.type)) {
|
|
165
|
+
node.under = target.sample;
|
|
166
|
+
roots.push(node);
|
|
167
|
+
return { sample: target.sample };
|
|
168
|
+
}
|
|
169
|
+
roots.push(node);
|
|
170
|
+
return { top: true };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** A node renamed; false when it is not there or the name is empty */
|
|
174
|
+
export function renameNode(project, id, name) {
|
|
175
|
+
const at = locate(project, id);
|
|
176
|
+
if (!at || !name) return false;
|
|
177
|
+
at.node.name = name;
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** A node and all it holds removed */
|
|
182
|
+
export function removeNode(project, id) {
|
|
183
|
+
const at = locate(project, id);
|
|
184
|
+
if (!at) return false;
|
|
185
|
+
at.list.splice(at.index, 1);
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* What must be open for a node to show: its ancestors and the organism its root stands under
|
|
191
|
+
* @returns {string[]} Their ids and key
|
|
192
|
+
*/
|
|
193
|
+
export function pathTo(project, id) {
|
|
194
|
+
const path = [];
|
|
195
|
+
const find = (list, trail) => {
|
|
196
|
+
for (const node of list) {
|
|
197
|
+
if (node.id === id) {
|
|
198
|
+
path.push(...trail);
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (find(node.children || [], [...trail, node.id])) return true;
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
};
|
|
205
|
+
for (const root of outlineOf(project)) {
|
|
206
|
+
if (find([root], root.under ? [root.under] : [])) break;
|
|
207
|
+
}
|
|
208
|
+
return path;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The outline as the Outliner's tree items: the roots under each organism shown, and the project's top (a root
|
|
213
|
+
* whose organism is gone shows there)
|
|
214
|
+
* @param {Object} project
|
|
215
|
+
* @param {Set<string>} samples - The keys of the organisms the Outliner shows
|
|
216
|
+
* @param {Set<string>} [open] - The nodes shown open
|
|
217
|
+
* @returns {{under: Map<string, Object[]>, top: Object[]}}
|
|
218
|
+
*/
|
|
219
|
+
export function outlineItems(project, samples, open = new Set()) {
|
|
220
|
+
const item = (node) => ({
|
|
221
|
+
id: node.id,
|
|
222
|
+
name: node.name,
|
|
223
|
+
type: node.type,
|
|
224
|
+
user: true,
|
|
225
|
+
expanded: open.has(node.id),
|
|
226
|
+
children: (node.children || []).map(item),
|
|
227
|
+
});
|
|
228
|
+
const under = new Map();
|
|
229
|
+
const top = [];
|
|
230
|
+
for (const root of outlineOf(project)) {
|
|
231
|
+
if (root.under && samples.has(root.under)) {
|
|
232
|
+
if (!under.has(root.under)) under.set(root.under, []);
|
|
233
|
+
under.get(root.under).push(item(root));
|
|
234
|
+
} else {
|
|
235
|
+
top.push(item(root));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return { under, top };
|
|
239
|
+
}
|
|
@@ -93,6 +93,8 @@ function follow(app, scope) {
|
|
|
93
93
|
|
|
94
94
|
/** A MetaCube menu action from PRISM's MetaCube menu */
|
|
95
95
|
export { runMenuAction };
|
|
96
|
+
// MetaCube's own Outliner nodes moved and edited (index.js registration's outliner hooks)
|
|
97
|
+
export { outlineDrop, outlineDropModes, outlineMenu } from './MGS.2.GUI.js';
|
|
96
98
|
|
|
97
99
|
/**
|
|
98
100
|
* The .mgp of MetaCube's open project, for its row: what a PRISM project file
|
|
@@ -435,6 +435,8 @@ export class OutlinerPanel {
|
|
|
435
435
|
|
|
436
436
|
.outliner-visibility-toggle.visible {
|
|
437
437
|
opacity: 1.0;
|
|
438
|
+
/* The open eye (U+FE0F): the system's colour emoji (Chrome keeps PRISM Symbols for it without this family) */
|
|
439
|
+
font-family: emoji;
|
|
438
440
|
}
|
|
439
441
|
|
|
440
442
|
/* Drag and drop indicators */
|
|
@@ -449,6 +451,12 @@ export class OutlinerPanel {
|
|
|
449
451
|
background: rgba(79, 195, 247, 0.1);
|
|
450
452
|
}
|
|
451
453
|
|
|
454
|
+
/* A child row dropped inside another (registration outliner.dropModes 'over') */
|
|
455
|
+
#outliner-tree .fancytree-drop-over > .fancytree-title {
|
|
456
|
+
outline: 1px dashed #4fc3f7;
|
|
457
|
+
background: rgba(79, 195, 247, 0.25);
|
|
458
|
+
}
|
|
459
|
+
|
|
452
460
|
#outliner-tree li {
|
|
453
461
|
position: relative;
|
|
454
462
|
}
|
|
@@ -577,7 +585,9 @@ export class OutlinerPanel {
|
|
|
577
585
|
|
|
578
586
|
// ── Helper: create eye toggle ──
|
|
579
587
|
const makeEye = (visible, title, onClick) => {
|
|
580
|
-
|
|
588
|
+
// The open eye in the system's colours (U+FE0F, and .visible's font-family emoji); the hidden one PRISM
|
|
589
|
+
// Symbols' slashed eye
|
|
590
|
+
const icon = visible ? '\uD83D\uDC41\uFE0F' : '\uD83D\uDC41\u200D\uD83D\uDDE8';
|
|
581
591
|
const $el = $(
|
|
582
592
|
`<span class="outliner-visibility-toggle ${visible ? 'visible' : ''}" title="${title}">${icon}</span>`
|
|
583
593
|
);
|
|
@@ -633,6 +643,8 @@ export class OutlinerPanel {
|
|
|
633
643
|
);
|
|
634
644
|
} else if (d.isKEGGCompound) {
|
|
635
645
|
// Compound leaves — selectable only, no visibility toggle
|
|
646
|
+
} else if (d.noButtons) {
|
|
647
|
+
// A child row its type gives no buttons: the dataset's own would act on the whole dataset
|
|
636
648
|
} else if (d.datasetId) {
|
|
637
649
|
// Dataset-level node (root folder): trash + eye
|
|
638
650
|
const dataset = projectManager.getDataset(d.datasetId);
|
|
@@ -673,12 +685,21 @@ export class OutlinerPanel {
|
|
|
673
685
|
preventNonNodes: true,
|
|
674
686
|
preventRecursion: true,
|
|
675
687
|
preventVoidMoves: true,
|
|
676
|
-
dragStart: (node
|
|
688
|
+
dragStart: (node) => {
|
|
677
689
|
// Allow dragging top-level nodes (groups or root datasets) for render order
|
|
678
690
|
if (node.data.isMetadata) return false;
|
|
679
|
-
|
|
691
|
+
if (node.getLevel() === 1) return true; // top-level tree nodes
|
|
692
|
+
// A dataset's child row, when its type moves it (registration outliner.drag)
|
|
693
|
+
return !!self._typeOutliner(node)?.drag?.(node.data, node);
|
|
680
694
|
},
|
|
681
695
|
dragEnter: (node, data) => {
|
|
696
|
+
const dragged = data.otherNode;
|
|
697
|
+
if (dragged && dragged.getLevel() > 1) {
|
|
698
|
+
// A child row: inside its own dataset, where its type says (registration
|
|
699
|
+
// outliner.dropModes: 'over', 'before', 'after', or false)
|
|
700
|
+
if (node.data?.datasetId !== dragged.data.datasetId) return false;
|
|
701
|
+
return self._typeOutliner(dragged)?.dropModes?.(dragged.data, node) || false;
|
|
702
|
+
}
|
|
682
703
|
if (node.getLevel() !== 1) return false;
|
|
683
704
|
if (node.data.isMetadata) return false;
|
|
684
705
|
if (data.otherNode === node) return false;
|
|
@@ -693,6 +714,11 @@ export class OutlinerPanel {
|
|
|
693
714
|
},
|
|
694
715
|
dragDrop: (node, data) => {
|
|
695
716
|
self._clearDropClasses();
|
|
717
|
+
// A child row: its type moves it (registration outliner.drop), then shows its tree again
|
|
718
|
+
if (data.otherNode && data.otherNode.getLevel() > 1) {
|
|
719
|
+
self._typeOutliner(data.otherNode)?.drop?.(data.otherNode.data, node, data.hitMode);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
696
722
|
// Handle reorder
|
|
697
723
|
self._onDatasetReorder(data.otherNode, node, data.hitMode);
|
|
698
724
|
},
|
|
@@ -818,7 +844,7 @@ export class OutlinerPanel {
|
|
|
818
844
|
color: ${dataset.visualization.visible ? '#4fc3f7' : '#666'};
|
|
819
845
|
`;
|
|
820
846
|
toggle.textContent = dataset.visualization.visible
|
|
821
|
-
? '\uD83D\uDC41'
|
|
847
|
+
? '\uD83D\uDC41\uFE0F'
|
|
822
848
|
: '\uD83D\uDC41\u200D\uD83D\uDDE8';
|
|
823
849
|
toggle.title = 'Toggle visibility';
|
|
824
850
|
toggle.addEventListener('click', (e) => {
|
|
@@ -1421,6 +1447,17 @@ export class OutlinerPanel {
|
|
|
1421
1447
|
* @param {Object} node — Fancytree node
|
|
1422
1448
|
* @private
|
|
1423
1449
|
*/
|
|
1450
|
+
/**
|
|
1451
|
+
* The outliner hooks of a row's type (its dataset's registration `outliner`)
|
|
1452
|
+
* @param {Object} node - A Fancytree node
|
|
1453
|
+
* @returns {Object|null}
|
|
1454
|
+
* @private
|
|
1455
|
+
*/
|
|
1456
|
+
_typeOutliner(node) {
|
|
1457
|
+
const dataset = node?.data?.datasetId ? projectManager.getDataset(node.data.datasetId) : null;
|
|
1458
|
+
return (dataset && typeRegistry.get(dataset.dataSpec)?.outliner) || null;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1424
1461
|
_showNodeContextMenu(x, y, node) {
|
|
1425
1462
|
const d = node.data;
|
|
1426
1463
|
if (!d?.datasetId || d.isMetadata) return;
|
|
@@ -1476,6 +1513,9 @@ export class OutlinerPanel {
|
|
|
1476
1513
|
action: () => terrain.use(dataset.id),
|
|
1477
1514
|
});
|
|
1478
1515
|
|
|
1516
|
+
// The row's own items, as its type gives them (registration outliner.menu(d, node): a child row's)
|
|
1517
|
+
for (const item of this._typeOutliner(node)?.menu?.(d, node) || []) items.push(item);
|
|
1518
|
+
|
|
1479
1519
|
// Only show if there are visible items
|
|
1480
1520
|
const visibleItems = items.filter((i) => i.visible !== false);
|
|
1481
1521
|
if (visibleItems.length) this._contextMenu.show(x, y, items);
|
|
@@ -1606,8 +1646,10 @@ export class OutlinerPanel {
|
|
|
1606
1646
|
_clearDropClasses() {
|
|
1607
1647
|
const tree = this.panel?.querySelector('#outliner-tree');
|
|
1608
1648
|
if (!tree) return;
|
|
1609
|
-
tree.querySelectorAll(
|
|
1610
|
-
|
|
1649
|
+
tree.querySelectorAll(
|
|
1650
|
+
'.fancytree-drop-before, .fancytree-drop-after, .fancytree-drop-target, .fancytree-drop-over'
|
|
1651
|
+
).forEach((el) => {
|
|
1652
|
+
el.classList.remove('fancytree-drop-before', 'fancytree-drop-after', 'fancytree-drop-target', 'fancytree-drop-over');
|
|
1611
1653
|
});
|
|
1612
1654
|
}
|
|
1613
1655
|
|
|
@@ -905,7 +905,10 @@ export class SpinoffPanel {
|
|
|
905
905
|
// Eye toggle (synced with Outliner)
|
|
906
906
|
const eyeBtn = document.createElement('span');
|
|
907
907
|
eyeBtn.style.cssText = 'cursor: pointer; margin-left: 6px; font-size: 12px; opacity: 0.7;';
|
|
908
|
-
|
|
908
|
+
// The open eye in the system's colours (U+FE0F in the emoji family), as the Outliner's; the hidden one PRISM
|
|
909
|
+
// Symbols' slashed eye
|
|
910
|
+
if (dataset.visualization.visible) eyeBtn.style.fontFamily = 'emoji';
|
|
911
|
+
eyeBtn.textContent = dataset.visualization.visible ? '\uD83D\uDC41\uFE0F' : '\uD83D\uDC41\u200D\uD83D\uDDE8';
|
|
909
912
|
eyeBtn.title = 'Toggle visibility';
|
|
910
913
|
eyeBtn.addEventListener('click', (e) => {
|
|
911
914
|
e.stopPropagation();
|