cornfield 0.46.1 → 0.46.2
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/explorer/capped.js +3 -2
- package/explorer/engine/feedback.js +49 -0
- package/explorer/engine/flow-ui.js +39 -0
- package/explorer/engine/fly.js +54 -0
- package/explorer/engine/hint.js +97 -0
- package/explorer/engine/keyboard.js +156 -0
- package/explorer/engine/layers.js +280 -0
- package/explorer/engine/layout.js +378 -0
- package/explorer/engine/map-style.js +547 -0
- package/explorer/engine/piece.js +142 -0
- package/explorer/engine/render.js +331 -0
- package/explorer/engine/search-status.js +59 -0
- package/explorer/engine/selection.js +42 -0
- package/explorer/engine/sheets.js +417 -0
- package/explorer/engine/strings.js +63 -0
- package/explorer/feedback.js +11 -45
- package/explorer/flow-style.js +28 -0
- package/explorer/flows.js +10 -51
- package/explorer/fly.js +11 -43
- package/explorer/hint.js +15 -88
- package/explorer/index.html +38 -75
- package/explorer/input.js +190 -177
- package/explorer/instance-state.js +172 -0
- package/explorer/instance.js +267 -0
- package/explorer/keyboard.js +14 -206
- package/explorer/labels.js +3 -3
- package/explorer/layers.js +34 -445
- package/explorer/layout.js +14 -372
- package/explorer/main.js +4 -226
- package/explorer/map-style.js +27 -525
- package/explorer/mockups-model.js +3 -3
- package/explorer/page-pieces.js +61 -0
- package/explorer/page.js +232 -0
- package/explorer/panels.js +29 -409
- package/explorer/pieces/layers.js +325 -0
- package/explorer/pieces/node-panel.js +536 -0
- package/explorer/pieces/search.js +454 -0
- package/explorer/proposal-model.js +1 -1
- package/explorer/proposal.js +1 -0
- package/explorer/render.js +37 -267
- package/explorer/renderer-canvas2d.js +4 -4
- package/explorer/renderer-webgl.js +21 -8
- package/explorer/renderer.js +11 -9
- package/explorer/scene.js +3 -2
- package/explorer/search-status.js +8 -47
- package/explorer/search.js +26 -324
- package/explorer/selection-view.js +17 -19
- package/explorer/sheets.js +31 -379
- package/explorer/state.js +38 -173
- package/explorer/strings.js +17 -60
- package/explorer/view.js +4 -5
- package/package.json +1 -1
package/explorer/layout.js
CHANGED
|
@@ -1,379 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/layout
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - the lane layout of the data-flow preset (one column per tier, left to right).
|
|
7
|
-
* Positions are exact: no physics pass, so the same topology always draws the same map.
|
|
8
|
-
* Plus the freeform mode, where the owner drags nodes and the positions are remembered.
|
|
4
|
+
* A bridge (spec 0011 D2, step 1): where every node sits is now laid out by engine/layout.js, on an instance. This file keeps the old
|
|
5
|
+
* names for the modules that are not yet on one (view.js, keyboard.js), bound to the page's instance.
|
|
9
6
|
*/
|
|
10
7
|
|
|
11
|
-
import {
|
|
8
|
+
import { pageInstance } from './state.js';
|
|
9
|
+
import * as L from './engine/layout.js';
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
// Degree centrality: hubs a little larger, leaves a little smaller
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
export function computeDegreeCentrality() {
|
|
17
|
-
touchScene(); // node radii change
|
|
18
|
-
const degreeMap = {};
|
|
19
|
-
state.nodes.forEach((n) => {
|
|
20
|
-
degreeMap[n.id] = 0;
|
|
21
|
-
if (n.baseR === undefined) n.baseR = n.r;
|
|
22
|
-
});
|
|
23
|
-
state.edges.forEach((e) => {
|
|
24
|
-
if (degreeMap[e.from] !== undefined) degreeMap[e.from]++;
|
|
25
|
-
if (degreeMap[e.to] !== undefined) degreeMap[e.to]++;
|
|
26
|
-
});
|
|
27
|
-
state.nodes.forEach((n) => {
|
|
28
|
-
const d = degreeMap[n.id] || 0;
|
|
29
|
-
n.degree = d;
|
|
30
|
-
// Leaf nodes slightly smaller (-3px), hub nodes slightly larger (up to +7px)
|
|
31
|
-
const delta = Math.max(-3, Math.min(7, (Math.sqrt(d) - 1.4) * 2.2));
|
|
32
|
-
n.r = Math.max(12, Math.round(n.baseR + delta));
|
|
33
|
-
n.scaleDelta = delta;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
11
|
+
export { STORAGE_KEY } from './engine/layout.js';
|
|
36
12
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return w;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// Orbital layout
|
|
51
|
-
// 1. The data tier (stores, tables, ROM stages) rings the root, grouped by kind.
|
|
52
|
-
// 2. A hub's children fill concentric rings around it; the spacing along a ring
|
|
53
|
-
// comes from that cluster's own label widths, so labels never collide.
|
|
54
|
-
// 3. Hubs with children are packed round the core, largest first (ties by label), each in the free place nearest it,
|
|
55
|
-
// searched from the top clockwise (spec 0008 D1); a cluster's place depends only on the ones placed before it.
|
|
56
|
-
// 4. Childless hubs (leaf apps, tools, packages) sit on an outer ring.
|
|
57
|
-
// ---------------------------------------------------------------------------
|
|
58
|
-
const DATA_TYPES = ['store', 'table', 'rom'];
|
|
59
|
-
const CHILD_TYPE_ORDER = ['core', 'atom', 'molecule', 'token', 'page', 'service', 'external', 'stack', 'table', 'store', 'tool', 'app', 'pkg'];
|
|
60
|
-
|
|
61
|
-
/** Concentric rings of `items` around (0, 0): returns the offsets and the radii used */
|
|
62
|
-
function ringPack(items, { first = 110, gap = 76, spacing = 90 } = {}) {
|
|
63
|
-
const offsets = [];
|
|
64
|
-
const radii = [];
|
|
65
|
-
let i = 0, ring = 0;
|
|
66
|
-
while (i < items.length) {
|
|
67
|
-
const r = first + ring * gap;
|
|
68
|
-
const capacity = Math.max(1, Math.floor((2 * Math.PI * r) / spacing));
|
|
69
|
-
const count = Math.min(capacity, items.length - i);
|
|
70
|
-
// Keep the slot under the hub free for the hub's label: turn the ring half a step if one lands there
|
|
71
|
-
const landsBelow = (s) => Array.from({ length: count }, (_, j) => -Math.PI / 2 + s + (j / count) * Math.PI * 2)
|
|
72
|
-
.some((a) => Math.abs(Math.atan2(Math.sin(a - Math.PI / 2), Math.cos(a - Math.PI / 2))) < 0.35);
|
|
73
|
-
let shift = ring % 2 ? Math.PI / count : 0;
|
|
74
|
-
if (landsBelow(shift)) shift += Math.PI / count;
|
|
75
|
-
for (let j = 0; j < count; j++) {
|
|
76
|
-
const a = -Math.PI / 2 + shift + (j / count) * Math.PI * 2;
|
|
77
|
-
offsets.push({ x: Math.cos(a) * r, y: Math.sin(a) * r });
|
|
78
|
-
}
|
|
79
|
-
radii.push(r);
|
|
80
|
-
i += count;
|
|
81
|
-
ring++;
|
|
82
|
-
}
|
|
83
|
-
return { offsets, radii };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* A cluster's whole pack: `children` in rings around the centre, and a child that has children of its own (a store
|
|
88
|
-
* owning 46 outside services) gets its own rings, placed on an outer ring of this cluster with room for them.
|
|
89
|
-
* `kidsOf(node)` says who hangs under a node. Returns `{ children, offsets, radii, subs, extent }`: `subs[i]` is the
|
|
90
|
-
* child i's own pack (or null), `extent` how far the whole thing reaches from the centre.
|
|
91
|
-
*/
|
|
92
|
-
function packTree(children, kidsOf, spacingOf, byOrder, seen = new Set()) {
|
|
93
|
-
const withSub = [];
|
|
94
|
-
const plain = [];
|
|
95
|
-
children.forEach((c) => {
|
|
96
|
-
const kids = seen.has(c.id) ? [] : kidsOf(c);
|
|
97
|
-
if (!kids.length) { plain.push(c); return; }
|
|
98
|
-
seen.add(c.id);
|
|
99
|
-
const sub = packTree(kids.sort(byOrder), kidsOf, spacingOf, byOrder, seen);
|
|
100
|
-
withSub.push({ c, sub, fp: sub.extent });
|
|
101
|
-
});
|
|
102
|
-
withSub.sort((a, b) => b.fp - a.fp);
|
|
103
|
-
const pack = ringPack(plain, { spacing: spacingOf(children) });
|
|
104
|
-
const out = {
|
|
105
|
-
children: [...plain], offsets: [...pack.offsets], radii: pack.radii, subs: plain.map(() => null),
|
|
106
|
-
extent: pack.radii.length ? pack.radii[pack.radii.length - 1] + 40 : 0,
|
|
107
|
-
};
|
|
108
|
-
if (withSub.length) {
|
|
109
|
-
const lastR = pack.radii.length ? pack.radii[pack.radii.length - 1] : 0;
|
|
110
|
-
const fpMax = withSub[0].fp;
|
|
111
|
-
const arc = withSub.reduce((sum, w) => sum + 2 * w.fp + 30, 0);
|
|
112
|
-
// Each takes arc in proportion to its size; two of them are a chord apart, not an arc, so the ring is as wide as
|
|
113
|
-
// the closest pair needs (for three or more large ones, more than the arc says)
|
|
114
|
-
const mids = [];
|
|
115
|
-
let a = -Math.PI / 2;
|
|
116
|
-
withSub.forEach((w) => { const share = ((2 * w.fp + 30) / arc) * Math.PI * 2; mids.push(a + share / 2); a += share; });
|
|
117
|
-
let r = Math.max(110, lastR + fpMax + 40, arc / (2 * Math.PI));
|
|
118
|
-
for (let i = 0; i < withSub.length; i++) {
|
|
119
|
-
for (let j = i + 1; j < withSub.length; j++) {
|
|
120
|
-
const half = Math.sin(Math.abs(mids[j] - mids[i]) / 2);
|
|
121
|
-
if (half > 1e-6) r = Math.max(r, (withSub[i].fp + withSub[j].fp + 30) / (2 * half));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
withSub.forEach((w, i) => {
|
|
125
|
-
out.children.push(w.c);
|
|
126
|
-
out.offsets.push({ x: Math.cos(mids[i]) * r, y: Math.sin(mids[i]) * r });
|
|
127
|
-
out.subs.push(w.sub);
|
|
128
|
-
});
|
|
129
|
-
out.bigRadius = r;
|
|
130
|
-
out.extent = Math.max(out.extent, r + fpMax);
|
|
131
|
-
}
|
|
132
|
-
return out;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Puts a pack's children (and theirs) around (ox, oy); a child's own rings are added to `clusters` */
|
|
136
|
-
function placePack(pack, ox, oy, clusters) {
|
|
137
|
-
pack.children.forEach((c, i) => {
|
|
138
|
-
c.x = ox + pack.offsets[i].x;
|
|
139
|
-
c.y = oy + pack.offsets[i].y;
|
|
140
|
-
const sub = pack.subs[i];
|
|
141
|
-
if (sub) {
|
|
142
|
-
clusters.push({ x: c.x, y: c.y, radii: sub.radii });
|
|
143
|
-
placePack(sub, c.x, c.y, clusters);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* The free place nearest (0, 0) for a disc of radius `r` among `discs` (`{ x, y, r }`, each already holding its own gap),
|
|
151
|
-
* searched along rays from the top clockwise every STEP degrees: on each ray the nearest point where the disc touches
|
|
152
|
-
* none, and of the rays the nearest of all, the first in the search order winning a tie. Exact and deterministic.
|
|
153
|
-
*/
|
|
154
|
-
const PACK_STEP_DEG = 2;
|
|
155
|
-
function nearestFreePlace(discs, r) {
|
|
156
|
-
let best = null;
|
|
157
|
-
for (let deg = 0; deg < 360; deg += PACK_STEP_DEG) {
|
|
158
|
-
const a = -Math.PI / 2 + (deg * Math.PI) / 180;
|
|
159
|
-
const dx = Math.cos(a), dy = Math.sin(a);
|
|
160
|
-
// The stretches of this ray where the disc would touch another (open intervals of the distance along it)
|
|
161
|
-
const blocked = [];
|
|
162
|
-
for (const d of discs) {
|
|
163
|
-
const along = dx * d.x + dy * d.y;
|
|
164
|
-
const reach = d.r + r;
|
|
165
|
-
const disc = along * along - (d.x * d.x + d.y * d.y) + reach * reach;
|
|
166
|
-
if (disc > 0) blocked.push([along - Math.sqrt(disc), along + Math.sqrt(disc)]);
|
|
167
|
-
}
|
|
168
|
-
blocked.sort((p, q) => p[0] - q[0]);
|
|
169
|
-
let at = 0;
|
|
170
|
-
for (const [lo, hi] of blocked) if (lo < at + 1e-9 && hi > at) at = hi;
|
|
171
|
-
if (!best || at < best.at - 1e-6) best = { at, x: dx * at, y: dy * at };
|
|
172
|
-
}
|
|
173
|
-
return best;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function computeOrbitalLayout() {
|
|
177
|
-
touchScene(); // positions and rings change
|
|
178
|
-
const { nodes, edges } = state;
|
|
179
|
-
if (nodes.length === 0) return;
|
|
180
|
-
state.rings = { rings: [], clusters: [] };
|
|
181
|
-
const LAYOUT = state.rings;
|
|
182
|
-
|
|
183
|
-
const ids = new Set(nodes.map((n) => n.id));
|
|
184
|
-
const parentMap = {};
|
|
185
|
-
edges.forEach((e) => {
|
|
186
|
-
// A parent that is not on the map (an edge a proposal left behind) is no parent: the node would sit on the centre
|
|
187
|
-
if (!e.dashed && !e.kind && e.from && e.to && ids.has(e.from) && e.from !== e.to && !parentMap[e.to]) parentMap[e.to] = e.from;
|
|
188
|
-
});
|
|
189
|
-
// Nor is a parent that is its own ancestor: the first node of a loop loses its parent, so the loop hangs from it
|
|
190
|
-
nodes.forEach((n) => {
|
|
191
|
-
const path = new Set([n.id]);
|
|
192
|
-
for (let p = parentMap[n.id]; p; p = parentMap[p]) {
|
|
193
|
-
if (path.has(p)) { delete parentMap[p]; break; }
|
|
194
|
-
path.add(p);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// topology.json stores no positions; a node the passes below do not place starts at the centre
|
|
199
|
-
nodes.forEach((n) => { n.x = 0; n.y = 0; });
|
|
200
|
-
const root = nodes.find((n) => n.id === 'root');
|
|
201
|
-
if (root) { root.x = 0; root.y = 0; }
|
|
202
|
-
|
|
203
|
-
const isData = (n) => DATA_TYPES.includes(n.type);
|
|
204
|
-
const hasChildren = new Set(Object.values(parentMap));
|
|
205
|
-
const parentsOfNonData = new Set(nodes.filter((k) => parentMap[k.id] && !isData(k)).map((k) => parentMap[k.id]));
|
|
206
|
-
// A data store with children of its own (tables, outside services) is a cluster like an app; other data rings the root
|
|
207
|
-
// and so is any node with no parent but children of its own (its children need somewhere to go)
|
|
208
|
-
const isHub = (n) => n.id !== 'root' && (isData(n)
|
|
209
|
-
? hasChildren.has(n.id) && (!parentMap[n.id] || parentMap[n.id] === 'root')
|
|
210
|
-
&& (n.type === 'store' || parentsOfNonData.has(n.id))
|
|
211
|
-
: parentMap[n.id] === 'root' || (!parentMap[n.id] && (hasChildren.has(n.id) || ['app', 'pkg', 'tool', 'external', 'stack'].includes(n.type))));
|
|
212
|
-
const firstHubs = new Set(nodes.filter(isHub).map((h) => h.id));
|
|
213
|
-
// A data node that would ring the root (its parent is no hub) but has other nodes under it is a cluster too: the
|
|
214
|
-
// data ring has no room for them
|
|
215
|
-
const hubs = nodes.filter((n) => firstHubs.has(n.id)
|
|
216
|
-
|| (n.id !== 'root' && isData(n) && parentsOfNonData.has(n.id) && !firstHubs.has(parentMap[n.id])));
|
|
217
|
-
const hubIds = new Set(hubs.map((h) => h.id));
|
|
218
|
-
const typeRank = (n) => { const i = CHILD_TYPE_ORDER.indexOf(n.type); return i < 0 ? 99 : i; };
|
|
219
|
-
const byTypeThenLabel = (a, b) => typeRank(a) - typeRank(b) || String(a.label).localeCompare(String(b.label));
|
|
220
|
-
|
|
221
|
-
// 1. Data core
|
|
222
|
-
const data = nodes.filter((n) => isData(n) && !hubIds.has(n.id) && !hubIds.has(parentMap[n.id]))
|
|
223
|
-
.sort((a, b) => DATA_TYPES.indexOf(a.type) - DATA_TYPES.indexOf(b.type) || String(a.label).localeCompare(String(b.label)));
|
|
224
|
-
const dataSpacing = Math.max(110, ...data.map((n) => labelWidth(n) + 24));
|
|
225
|
-
const dataR = Math.max(150, (data.length * dataSpacing) / (2 * Math.PI));
|
|
226
|
-
data.forEach((n, i) => {
|
|
227
|
-
const a = -Math.PI / 2 + (i / Math.max(1, data.length)) * Math.PI * 2;
|
|
228
|
-
n.x = Math.cos(a) * dataR;
|
|
229
|
-
n.y = Math.sin(a) * dataR;
|
|
230
|
-
});
|
|
231
|
-
const coreExtent = data.length ? dataR + 50 : 60;
|
|
232
|
-
if (data.length) LAYOUT.rings.push({ x: 0, y: 0, r: dataR });
|
|
233
|
-
|
|
234
|
-
// 2. Pack each hub's children (relative to the hub). A child with children of its own (a store that owns the
|
|
235
|
-
// outside services) gets rings of its own, and they count in the cluster's extent.
|
|
236
|
-
const kidsOf = (n) => (n.id === 'root' ? [] : nodes.filter((k) => parentMap[k.id] === n.id && !hubIds.has(k.id) && !isData(k) && k.id !== 'root'));
|
|
237
|
-
const spacingOf = (list) => Math.min(170, Math.max(84, ...list.map((c) => labelWidth(c) * 0.8 + 26)));
|
|
238
|
-
const packs = new Map();
|
|
239
|
-
hubs.forEach((hub) => {
|
|
240
|
-
const children = nodes.filter((n) => parentMap[n.id] === hub.id && !hubIds.has(n.id)).sort(byTypeThenLabel);
|
|
241
|
-
if (!children.length) return;
|
|
242
|
-
packs.set(hub.id, packTree(children, kidsOf, spacingOf, byTypeThenLabel, new Set([hub.id])));
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// 3. Hubs with children, packed (spec 0008 D1): the largest cluster first (ties by label) takes the free place nearest
|
|
246
|
-
// the core, searched from the top clockwise, GAP from every cluster already placed. No physics: the same map
|
|
247
|
-
// always draws the same, and a cluster's place depends only on the ones placed before it.
|
|
248
|
-
const GAP = 70;
|
|
249
|
-
const big = hubs.filter((h) => packs.has(h.id))
|
|
250
|
-
.sort((a, b) => packs.get(b.id).extent - packs.get(a.id).extent || String(a.label).localeCompare(String(b.label)));
|
|
251
|
-
const discs = [{ x: 0, y: 0, r: coreExtent }];
|
|
252
|
-
let hubReach = coreExtent; // how far from the centre the packed clusters reach
|
|
253
|
-
big.forEach((hub) => {
|
|
254
|
-
const pack = packs.get(hub.id);
|
|
255
|
-
const at = nearestFreePlace(discs, pack.extent + GAP / 2);
|
|
256
|
-
hub.x = at.x;
|
|
257
|
-
hub.y = at.y;
|
|
258
|
-
discs.push({ x: hub.x, y: hub.y, r: pack.extent + GAP / 2 });
|
|
259
|
-
hubReach = Math.max(hubReach, Math.hypot(hub.x, hub.y) + pack.extent);
|
|
260
|
-
LAYOUT.clusters.push({ x: hub.x, y: hub.y, radii: pack.radii });
|
|
261
|
-
placePack(pack, hub.x, hub.y, LAYOUT.clusters);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// 4. Childless hubs on an outer ring, and with them any node that has no parent and is none of the above
|
|
265
|
-
// (it would otherwise sit on the centre, under whatever else is there)
|
|
266
|
-
const homeless = nodes.filter((n) => n.id !== 'root' && !parentMap[n.id] && !isData(n) && !hubIds.has(n.id));
|
|
267
|
-
const leaves = [...hubs.filter((h) => !packs.has(h.id)), ...homeless].sort(byTypeThenLabel);
|
|
268
|
-
const leafSpacing = Math.max(120, ...leaves.map((n) => labelWidth(n) + 30));
|
|
269
|
-
const leafR = Math.max(hubReach + 90, (leaves.length * leafSpacing) / (2 * Math.PI));
|
|
270
|
-
leaves.forEach((n, i) => {
|
|
271
|
-
const a = -Math.PI / 2 + (i / Math.max(1, leaves.length)) * Math.PI * 2;
|
|
272
|
-
n.x = Math.cos(a) * leafR;
|
|
273
|
-
n.y = Math.sin(a) * leafR;
|
|
274
|
-
});
|
|
275
|
-
if (leaves.length) LAYOUT.rings.push({ x: 0, y: 0, r: leafR });
|
|
276
|
-
|
|
277
|
-
// Anything still on the centre is a child of a node the passes above did not pack (a child of a data node on the
|
|
278
|
-
// core ring, say): it goes in rings around its parent, with its own children in rings around it, never on one point
|
|
279
|
-
const placedAt = (n) => n.id === 'root' || n.x !== 0 || n.y !== 0;
|
|
280
|
-
const stuckUnder = new Map();
|
|
281
|
-
nodes.forEach((n) => {
|
|
282
|
-
const pid = parentMap[n.id];
|
|
283
|
-
if (placedAt(n) || !pid) return;
|
|
284
|
-
(stuckUnder.get(pid) || stuckUnder.set(pid, []).get(pid)).push(n);
|
|
285
|
-
});
|
|
286
|
-
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
287
|
-
stuckUnder.forEach((list, pid) => {
|
|
288
|
-
const p = byId.get(pid);
|
|
289
|
-
if (!p || !placedAt(p)) return; // its parent is stuck too: it is placed with it, in the parent's pack
|
|
290
|
-
if (list.every(placedAt)) return; // placed already, in a pack higher up
|
|
291
|
-
const pack = packTree(list.sort(byTypeThenLabel), kidsOf, spacingOf, byTypeThenLabel, new Set([pid]));
|
|
292
|
-
LAYOUT.clusters.push({ x: p.x, y: p.y, radii: pack.radii });
|
|
293
|
-
placePack(pack, p.x, p.y, LAYOUT.clusters);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// ---------------------------------------------------------------------------
|
|
298
|
-
// Lane layout: the data-flow preset, one column per tier, left to right
|
|
299
|
-
// A tier with many nodes (tables, services) fills several sub-columns top to bottom.
|
|
300
|
-
// ---------------------------------------------------------------------------
|
|
301
|
-
const LANE_ROW = 50; // vertical distance between two nodes in a column
|
|
302
|
-
const LANE_GAP = 110; // between tiers
|
|
303
|
-
const LANE_MAX_ROWS = 15; // a tall tier wraps into another sub-column
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Places the nodes of `flow.tiers` and sets `flow.headers` (one title per tier, with the x range
|
|
307
|
-
* it spans). Tiers are `{ key, title, nodes }`; the nodes get their x and y.
|
|
308
|
-
*/
|
|
309
|
-
export function computeLaneLayout(flow) {
|
|
310
|
-
touchScene(); // positions and headers change
|
|
311
|
-
let x = 0;
|
|
312
|
-
flow.headers = [];
|
|
313
|
-
const placed = [];
|
|
314
|
-
flow.tiers.forEach((tier) => {
|
|
315
|
-
if (!tier.nodes.length) return;
|
|
316
|
-
const subCols = Math.ceil(tier.nodes.length / LANE_MAX_ROWS);
|
|
317
|
-
const rows = Math.ceil(tier.nodes.length / subCols);
|
|
318
|
-
const colWidth = Math.max(70, ...tier.nodes.map((n) => labelWidth(n) + 30));
|
|
319
|
-
const start = x;
|
|
320
|
-
tier.nodes.forEach((n, i) => {
|
|
321
|
-
const col = Math.floor(i / rows);
|
|
322
|
-
const row = i % rows;
|
|
323
|
-
n.x = start + col * colWidth + colWidth / 2;
|
|
324
|
-
n.y = (row - (rows - 1) / 2) * LANE_ROW;
|
|
325
|
-
placed.push(n);
|
|
326
|
-
});
|
|
327
|
-
const span = subCols * colWidth;
|
|
328
|
-
flow.headers.push({ title: tier.title, note: tier.note, x: start + span / 2, left: start, right: start + span, rows });
|
|
329
|
-
x += span + LANE_GAP;
|
|
330
|
-
});
|
|
331
|
-
// Where the tier titles sit: just above the tallest tier
|
|
332
|
-
flow.top = -((Math.max(1, ...flow.headers.map((h) => h.rows)) - 1) / 2) * LANE_ROW - 70;
|
|
333
|
-
// Centre the whole thing on x = 0
|
|
334
|
-
const shift = (x - LANE_GAP) / 2;
|
|
335
|
-
placed.forEach((n) => { n.x -= shift; });
|
|
336
|
-
flow.headers.forEach((h) => { h.x -= shift; h.left -= shift; h.right -= shift; });
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// ---------------------------------------------------------------------------
|
|
340
|
-
// Freeform mode: dragged positions, remembered between visits
|
|
341
|
-
// ---------------------------------------------------------------------------
|
|
342
|
-
export const STORAGE_KEY = 'cornfield-freeform-positions';
|
|
343
|
-
|
|
344
|
-
export function loadFreeformPositions() {
|
|
345
|
-
try {
|
|
346
|
-
const saved = localStorage.getItem(STORAGE_KEY);
|
|
347
|
-
if (saved) state.freeformPositions = JSON.parse(saved);
|
|
348
|
-
} catch { /* storage blocked: start with none */ }
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
export function saveFreeformPositions() {
|
|
352
|
-
try {
|
|
353
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(state.freeformPositions));
|
|
354
|
-
} catch { /* storage blocked: the drag still works for this visit */ }
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
export function clearFreeformPositions() {
|
|
358
|
-
state.freeformPositions = {};
|
|
359
|
-
try {
|
|
360
|
-
localStorage.removeItem(STORAGE_KEY);
|
|
361
|
-
} catch { /* nothing to clear */ }
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/** Puts every remembered position on its node; false when there were none */
|
|
365
|
-
export function applyFreeformPositions() {
|
|
366
|
-
touchScene(); // positions change
|
|
367
|
-
let applied = 0;
|
|
368
|
-
state.nodes.forEach((n) => {
|
|
369
|
-
const p = state.freeformPositions[n.id];
|
|
370
|
-
if (p) { n.x = p.x; n.y = p.y; applied++; }
|
|
371
|
-
});
|
|
372
|
-
return applied > 0;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/** The orbit positions, with the owner's dragged ones on top when freeform is on */
|
|
376
|
-
export function layoutOrbit() {
|
|
377
|
-
computeOrbitalLayout();
|
|
378
|
-
if (state.isFreeform) applyFreeformPositions();
|
|
379
|
-
}
|
|
13
|
+
export const computeDegreeCentrality = () => L.computeDegreeCentrality(pageInstance());
|
|
14
|
+
export const labelWidth = (node) => L.labelWidth(pageInstance(), node);
|
|
15
|
+
export const computeOrbitalLayout = () => L.computeOrbitalLayout(pageInstance());
|
|
16
|
+
export const computeLaneLayout = (flow) => L.computeLaneLayout(pageInstance(), flow);
|
|
17
|
+
export const loadFreeformPositions = () => L.loadFreeformPositions(pageInstance());
|
|
18
|
+
export const saveFreeformPositions = () => L.saveFreeformPositions(pageInstance());
|
|
19
|
+
export const clearFreeformPositions = () => L.clearFreeformPositions(pageInstance());
|
|
20
|
+
export const applyFreeformPositions = () => L.applyFreeformPositions(pageInstance());
|
|
21
|
+
export const layoutOrbit = () => L.layoutOrbit(pageInstance());
|
package/explorer/main.js
CHANGED
|
@@ -1,232 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module explorer/main
|
|
3
3
|
*
|
|
4
|
-
* The topology explorer's entry point (explorer/index.html loads only this module):
|
|
5
|
-
*
|
|
6
|
-
* loads topology.json, then the sources the repo's config names (plugins.js).
|
|
7
|
-
*
|
|
8
|
-
* state.js the shared state layout.js where nodes sit (orbit, lanes, freeform)
|
|
9
|
-
* render.js the camera and the loop flows.js flow styling, legend, the data-flow preset
|
|
10
|
-
* scene.js what is drawn (contract) renderer.js how it is drawn: renderer-webgl.js or renderer-canvas2d.js
|
|
11
|
-
* layers.js the Layers menu panels.js the node panel
|
|
12
|
-
* view.js loading and view switching input.js mouse and touch
|
|
13
|
-
* proposal.js the proposal overlay (picker, Before / Diff / After); proposal-model.js its pure half
|
|
14
|
-
* whatif.js what-if edits on an open proposal (add, remove, draw, steps, undo); whatif-model.js its pure half
|
|
15
|
-
* review.js approve a proposal or send it back with a note and the edits; review-model.js its pure half
|
|
16
|
-
* deep-link.js ?run=, ?issue= and ?proposal=…&start=1 land on a run, an issue and a Start dialog
|
|
17
|
-
* scenario.js the player's pure core scenario-ui.js its bar, keys and camera
|
|
18
|
-
* bench.js /?bench=1 stopwatch and /?fixture=5k (the generated topology, from the server)
|
|
19
|
-
* keyboard.js the map by keyboard and the screen reader's announcer; keyboard-model.js its pure half
|
|
20
|
-
* search.js search: the count, the list by type and the stepping; search-model.js its pure half (what it reads and the rank)
|
|
21
|
-
* live.js the live layer: the chip, polling, laying a live source's answer over the map; live-model.js its pure half
|
|
22
|
-
* review-tokens.js review tokens for the review API, when somebody is signed in: make one (shown once), list, revoke; review-tokens-model.js its pure half
|
|
23
|
-
* forge-panel.js the issues and PRs panel, when the config names a forge: a PR lights the nodes it changes; forge-panel-model.js its pure half
|
|
24
|
-
* theme.js light or dark: the system setting and the header toggle; theme-model.js the colours (theme-boot.js before the first paint)
|
|
4
|
+
* The topology explorer's entry point (explorer/index.html loads only this module). cornfield's own page is explorer/page.js: it makes
|
|
5
|
+
* the one instance of the engine for the document and starts everything (spec 0011 D2).
|
|
25
6
|
*/
|
|
26
7
|
|
|
27
|
-
import {
|
|
28
|
-
import { initSearch, setQuery, stepMatch } from './search.js';
|
|
29
|
-
import { render, resize, fitGraphToViewport, fitPadding, isNodeVisible, setRenderer, getRenderer, ensureFlowLoop, renderNow, holdFrames } from './render.js';
|
|
30
|
-
import { createRenderer } from './renderer.js';
|
|
31
|
-
import { clearFreeformPositions, layoutOrbit, loadFreeformPositions } from './layout.js';
|
|
32
|
-
import { clickWithLegendMenu, setProjectLayers, toggleAllLayers, toggleLayer, toggleLayerKinds, toggleLegendMenu } from './layers.js';
|
|
33
|
-
import { closeDrawer, copySpec, selectNode, startRun } from './panels.js';
|
|
34
|
-
import { initScenarioUi, maybeStartDemo, playOutage } from './scenario-ui.js';
|
|
35
|
-
import { initSheets } from './sheets.js';
|
|
36
|
-
import { initReviewColumn } from './review-column.js';
|
|
37
|
-
import { loadTopology, setView, syncViewUi } from './view.js';
|
|
38
|
-
import { bindCanvasInput } from './input.js';
|
|
39
|
-
import { initProposals } from './proposal.js';
|
|
40
|
-
import { followDeepLink } from './deep-link.js';
|
|
41
|
-
import { initWhatIf } from './whatif.js';
|
|
42
|
-
import { initReview } from './review.js';
|
|
43
|
-
import { initMockups } from './mockups.js';
|
|
44
|
-
import { benchMeta, measureParams, readoutLines, resultLine, runBench, showReadout } from './bench.js';
|
|
45
|
-
import { initLive } from './live.js';
|
|
46
|
-
import { initHouse } from './house.js';
|
|
47
|
-
import { houseOffered } from './house-model.js';
|
|
48
|
-
import { initChecks } from './check.js';
|
|
49
|
-
import { frameThem, initKeyboard } from './keyboard.js';
|
|
50
|
-
import { initForgePanel } from './forge-panel.js';
|
|
51
|
-
import { initReviewTokens } from './review-tokens.js';
|
|
52
|
-
import { loadClientConfig, loadSources, applyBranding } from './plugins.js';
|
|
53
|
-
import { initTheme, setThemeChoice } from './theme.js';
|
|
54
|
-
import { initAccountMenu } from './account-menu.js';
|
|
55
|
-
import { watchHeaderFit } from './header-fit.js';
|
|
56
|
-
import { watchHint } from './hint.js';
|
|
57
|
-
import { watchFocusRoom } from './focus-room.js';
|
|
58
|
-
import { applyMapTheme, onMapStyleChange, watchMapStyle } from './map-style.js';
|
|
59
|
-
|
|
60
|
-
const $ = (id) => document.getElementById(id);
|
|
61
|
-
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
// Freeform mode: orbit clustering (locked) or dragging nodes anywhere
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
function updateFreeformUI() {
|
|
66
|
-
const on = state.isFreeform;
|
|
67
|
-
$('freeform-toggle-btn').setAttribute('aria-checked', String(on));
|
|
68
|
-
$('reset-positions-btn').hidden = !on;
|
|
69
|
-
syncViewUi();
|
|
70
|
-
state.canvas.style.cursor = on ? 'default' : 'grab';
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function toggleFreeformMode() {
|
|
74
|
-
setView('orbit'); // positions are only draggable on the full map
|
|
75
|
-
state.isFreeform = !state.isFreeform;
|
|
76
|
-
layoutOrbit();
|
|
77
|
-
updateFreeformUI();
|
|
78
|
-
render();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function resetFreeformPositions() {
|
|
82
|
-
clearFreeformPositions();
|
|
83
|
-
layoutOrbit();
|
|
84
|
-
updateFreeformUI();
|
|
85
|
-
render();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// ---------------------------------------------------------------------------
|
|
89
|
-
// Search
|
|
90
|
-
// ---------------------------------------------------------------------------
|
|
91
|
-
function toggleMobileSearch(open) {
|
|
92
|
-
const bar = $('mobile-search-bar');
|
|
93
|
-
const input = $('mobile-node-search');
|
|
94
|
-
const willOpen = open !== undefined ? open : bar.hidden;
|
|
95
|
-
bar.hidden = !willOpen;
|
|
96
|
-
if (willOpen) {
|
|
97
|
-
input.value = state.searchQuery;
|
|
98
|
-
setTimeout(() => input.focus(), 60);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
// One click handler for everything with a data-action
|
|
104
|
-
// ---------------------------------------------------------------------------
|
|
105
|
-
const ACTIONS = {
|
|
106
|
-
'reset-view': () => fitGraphToViewport(fitPadding()),
|
|
107
|
-
'fit': () => fitGraphToViewport(fitPadding()),
|
|
108
|
-
'toggle-layers-menu': () => toggleLegendMenu(),
|
|
109
|
-
'layers-all': () => toggleAllLayers(true, { viewer: true }),
|
|
110
|
-
'layers-none': () => toggleAllLayers(false, { viewer: true }),
|
|
111
|
-
'toggle-layer': (el) => toggleLayer(el.dataset.layer, { viewer: true }),
|
|
112
|
-
'toggle-layer-kinds': (el) => toggleLayerKinds(el.dataset.layer),
|
|
113
|
-
'toggle-freeform': () => toggleFreeformMode(),
|
|
114
|
-
'reset-positions': () => resetFreeformPositions(),
|
|
115
|
-
'preset-map': () => {
|
|
116
|
-
closeDrawer();
|
|
117
|
-
setView('orbit');
|
|
118
|
-
},
|
|
119
|
-
'preset-dataflow': () => {
|
|
120
|
-
closeDrawer();
|
|
121
|
-
setView(state.view === 'dataflow' ? 'orbit' : 'dataflow');
|
|
122
|
-
},
|
|
123
|
-
'toggle-mobile-search': () => toggleMobileSearch(),
|
|
124
|
-
'close-mobile-search': () => toggleMobileSearch(false),
|
|
125
|
-
'clear-search': () => { setQuery(''); const field = $('node-search'); const bar = $('mobile-search-bar'); (bar && !bar.hidden ? $('mobile-node-search') : field).focus(); },
|
|
126
|
-
'search-prev': () => stepMatch(-1),
|
|
127
|
-
'search-next': () => stepMatch(1),
|
|
128
|
-
'close-drawer': () => closeDrawer(),
|
|
129
|
-
'copy-spec': (el) => copySpec(el),
|
|
130
|
-
'start-run': () => startRun(),
|
|
131
|
-
'select-node': (el) => selectNode(nodeById(el.dataset.id), { frame: true }), // a link or a list row: the camera follows (spec 0008 D6)
|
|
132
|
-
'frame-selection': () => frameThem(),
|
|
133
|
-
'play-outage': (el) => playOutage(el.dataset.id), // the cloud panel's Play button (spec 0031 section 8)
|
|
134
|
-
'retry': () => loadTopology(),
|
|
135
|
-
'set-theme': (el) => setThemeChoice(el.dataset.choice),
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// Any click outside the Layers menu closes it; a click on one of its rows does not (layers.js clickWithLegendMenu reads which before the action)
|
|
139
|
-
document.addEventListener('click', (e) => clickWithLegendMenu(e.target, () => {
|
|
140
|
-
const target = e.target.closest('[data-action]');
|
|
141
|
-
if (target) {
|
|
142
|
-
const action = ACTIONS[target.dataset.action];
|
|
143
|
-
if (action) action(target);
|
|
144
|
-
}
|
|
145
|
-
}));
|
|
146
|
-
|
|
147
|
-
// ---------------------------------------------------------------------------
|
|
148
|
-
// /?bench=1: the scripted pan-and-zoom of bench.js on the map as loaded
|
|
149
|
-
// ---------------------------------------------------------------------------
|
|
150
|
-
async function runPageBench(frames, zoomFactor, sync) {
|
|
151
|
-
fitGraphToViewport(fitPadding());
|
|
152
|
-
const { camera, width, height } = state;
|
|
153
|
-
const base = { zoom: camera.zoom, cx: (width / 2 - camera.x) / camera.zoom, cy: (height / 2 - camera.y) / camera.zoom, width, height, zoomFactor };
|
|
154
|
-
const result = await runBench({
|
|
155
|
-
frames,
|
|
156
|
-
base,
|
|
157
|
-
setCamera: (c) => { camera.x = c.x; camera.y = c.y; camera.zoom = c.zoom; },
|
|
158
|
-
// renderNow draws this instant (and the labels with it), so a measured frame is a whole one
|
|
159
|
-
draw: () => {
|
|
160
|
-
renderNow();
|
|
161
|
-
// ?sync=1: wait for the GPU, so the time in draw is the whole frame's and not just the hand-over
|
|
162
|
-
if (sync) { const gl = state.canvas.getContext('webgl2'); if (gl) gl.finish(); }
|
|
163
|
-
},
|
|
164
|
-
// The page's own frames (a packet loop, a pending draw) would add draws the script does not count:
|
|
165
|
-
// hold them while the run lasts, then let go, so the run draws what a viewer sees
|
|
166
|
-
before: () => holdFrames(true),
|
|
167
|
-
after: () => { holdFrames(false); fitGraphToViewport(fitPadding()); ensureFlowLoop(); },
|
|
168
|
-
});
|
|
169
|
-
const meta = benchMeta({
|
|
170
|
-
nodes: state.nodes.length, edges: state.edges.length, view: state.view, renderer: getRenderer().kind,
|
|
171
|
-
zoomFactor, width, height, dpr: window.devicePixelRatio, search: window.location.search,
|
|
172
|
-
});
|
|
173
|
-
const line = resultLine(result, meta);
|
|
174
|
-
console.log(line);
|
|
175
|
-
window.__bench = { result, meta, line };
|
|
176
|
-
showReadout(document, readoutLines(result, meta));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// ---------------------------------------------------------------------------
|
|
180
|
-
// Start
|
|
181
|
-
// ---------------------------------------------------------------------------
|
|
182
|
-
initTheme(); // light or dark, before the first scene is built (theme.js)
|
|
183
|
-
watchMapStyle(document); // the map reads --corn-map-* from the theme, and again when it changes (map-style.js)
|
|
184
|
-
onMapStyleChange(() => render());
|
|
185
|
-
state.canvas = $('graph-canvas');
|
|
186
|
-
state.labelCanvas = $('label-canvas');
|
|
187
|
-
// A 2d context that only measures text (layout.js labelWidth): the map canvas may be WebGL, and a
|
|
188
|
-
// canvas that gave a WebGL context can never give a 2d one
|
|
189
|
-
state.ctx = document.createElement('canvas').getContext('2d');
|
|
190
|
-
setRenderer(createRenderer(state.canvas)); // WebGL2, or Canvas 2D when it is missing or ?renderer=canvas2d
|
|
191
|
-
loadFreeformPositions();
|
|
192
|
-
bindCanvasInput();
|
|
193
|
-
initKeyboard(); // the map, the panel, the search and the Layers menu by keyboard (keyboard.js)
|
|
194
|
-
initAccountMenu(); // the one menu at the right of the header (account-menu.js)
|
|
195
|
-
initSheets();
|
|
196
|
-
initScenarioUi();
|
|
197
|
-
initReviewColumn(); // the review column: the changes, and the personas with their scenarios (review-column.js)
|
|
198
|
-
window.addEventListener('resize', resize);
|
|
199
|
-
initSearch(); // the count, the list and the stepping of both search fields (search.js)
|
|
8
|
+
import { startPage } from './page.js';
|
|
200
9
|
|
|
201
|
-
|
|
202
|
-
syncViewUi();
|
|
203
|
-
// /?proposal=<slug> opens a proposal over the map, /?view=dataflow the data-flow preset: both have a link
|
|
204
|
-
const configReady = loadClientConfig().then((config) => { applyBranding(document, config); watchHeaderFit(document); watchHint(document); watchFocusRoom(document); applyMapTheme(document, config.theme); setProjectLayers(config.layers); syncViewUi(); return config; }); // the brand, then the theme's icons for the map; the hint again, in the repo's words
|
|
205
|
-
loadTopology().then(async (ok) => {
|
|
206
|
-
if (!ok) return;
|
|
207
|
-
// The sources the repo's cornfield.config.js names (plugins.js): a live layer, a house, devices, a checker; each optional
|
|
208
|
-
const config = await configReady;
|
|
209
|
-
state.forge = config.forge || null;
|
|
210
|
-
const { liveSource, floorRenderer, checker, houseSource } = await loadSources(config);
|
|
211
|
-
const forgeOn = initForgePanel(config); // issues and PRs: only when the config names a forge (forge-panel.js)
|
|
212
|
-
initReviewTokens(config); // review tokens for the review API: only for somebody signed in (review-tokens.js)
|
|
213
|
-
initWhatIf(); // before a proposal can open, so its edits come with it
|
|
214
|
-
initReview(); // after it: the review controls sit under the edit controls on the bar
|
|
215
|
-
initMockups(); // a proposal's screens open from the node they name
|
|
216
|
-
const proposalOpened = await initProposals();
|
|
217
|
-
// The live layer (live.js): loads only once a live layer goes on in the Layers menu; with no source it stays off
|
|
218
|
-
initLive({ source: liveSource, onSelectionGone: closeDrawer });
|
|
219
|
-
// The House view (house.js): a source's floor renderer draws the plan under the map (plain room boxes without one); /?view=house opens it
|
|
220
|
-
initHouse({ floor: floorRenderer, offered: houseOffered(houseSource, state.nodes) }); // no house source and no house in the map: no House button
|
|
221
|
-
initChecks({ checker }); // scenarios ask the source's checker, when there is one (check.js)
|
|
222
|
-
if (new URLSearchParams(window.location.search).get("view") === "dataflow") setView("dataflow");
|
|
223
|
-
// /?run=, /?issue= and /?proposal=…&start=1 land on a run, an issue's Start button and a proposal's Start dialog (deep-link.js)
|
|
224
|
-
followDeepLink({ proposalOpened, forgeOn }).catch((err) => console.error('Following the link failed', err));
|
|
225
|
-
// /?scenario-demo=1 plays a small scenario over real nodes, to look at the player
|
|
226
|
-
maybeStartDemo();
|
|
227
|
-
// /?bench=1 runs the stopwatch (bench.js) once the map is up
|
|
228
|
-
const { benchFrames, benchZoom, benchSync } = measureParams(window.location.search);
|
|
229
|
-
if (benchFrames) {
|
|
230
|
-
try { await runPageBench(benchFrames, benchZoom, benchSync); } catch (err) { console.error("The bench failed", err); }
|
|
231
|
-
}
|
|
232
|
-
});
|
|
10
|
+
startPage();
|