@popcorn245/cornfield 0.51.2 → 0.51.3
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/engine/render.js +33 -1
- package/explorer/pieces/map.js +2 -8
- package/package.json +1 -1
|
@@ -104,14 +104,34 @@ export function createMap(inst, opts = {}) {
|
|
|
104
104
|
// -------------------------------------------------------------------------
|
|
105
105
|
function resize() {
|
|
106
106
|
const { canvas } = state;
|
|
107
|
+
const before = `${state.width}x${state.height}`;
|
|
107
108
|
state.width = canvas.parentElement.clientWidth;
|
|
108
109
|
state.height = canvas.parentElement.clientHeight;
|
|
109
110
|
getRenderer().resize(state.width, state.height, inst.dpr());
|
|
110
111
|
const labels = getLabelLayer();
|
|
111
112
|
if (labels) labels.resize(state.width, state.height, inst.dpr());
|
|
113
|
+
if (before !== `${state.width}x${state.height}`) fitToNewBox();
|
|
112
114
|
render();
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
/**
|
|
118
|
+
* The box the map's fit reads is not always final when the map is first fitted: the page's own box is laid out a moment after the topology arrives
|
|
119
|
+
* (an embedded pane sized after the page began loading), a component's stage is `display: none` or not yet sized. So the engine keeps what the last
|
|
120
|
+
* fit asked for (`memo.lastFit`: its arguments and the camera it set), and when the box changes while the camera is still exactly there, nobody has
|
|
121
|
+
* panned, zoomed or flown since, so the fit is made again for the box. Once anyone has moved the camera, a new box keeps their view.
|
|
122
|
+
* A fit asked for while the map has no box (a parent `display: none`, a box of no size) waits for one (`memo.waiting`): fitted to nothing,
|
|
123
|
+
* the camera would be lost.
|
|
124
|
+
*/
|
|
125
|
+
const memo = inst.slot('fit', () => ({ lastFit: null, waiting: null })); // on the instance: a page that made two maps over one state (page.js, then the map piece) has one memory
|
|
126
|
+
|
|
127
|
+
function fitToNewBox() {
|
|
128
|
+
if (!state.width || !state.height) return;
|
|
129
|
+
if (memo.waiting) { const { padding, only } = memo.waiting; fitGraphToViewport(padding === null ? fitPadding() : padding, only); return; }
|
|
130
|
+
const { camera } = state;
|
|
131
|
+
const last = memo.lastFit;
|
|
132
|
+
if (last && camera.x === last.x && camera.y === last.y && camera.zoom === last.zoom) fitGraphToViewport(last.auto ? fitPadding() : last.padding, last.only);
|
|
133
|
+
}
|
|
134
|
+
|
|
115
135
|
/**
|
|
116
136
|
* Draws again when the map's box changes size (in place of a listener on the window): a ResizeObserver on the canvas's parent. The first
|
|
117
137
|
* report, which every observer makes on `observe`, is skipped when the size is already the one the map has.
|
|
@@ -179,7 +199,12 @@ export function createMap(inst, opts = {}) {
|
|
|
179
199
|
|
|
180
200
|
/** Zoom and pan so every visible node (and its label) is on screen; `only` (a Set of ids) narrows it to those, when any are visible */
|
|
181
201
|
function fitGraphToViewport(padding = 40, only = null) {
|
|
182
|
-
const { width, camera } = state;
|
|
202
|
+
const { width, height, camera } = state;
|
|
203
|
+
if (!width || !height) { // no box yet: the fit is made when there is one (resize())
|
|
204
|
+
if (state.nodes.length) memo.waiting = { padding: padding === fitPadding() ? null : padding, only };
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
memo.waiting = null;
|
|
183
208
|
const t = fitTarget(padding, only);
|
|
184
209
|
if (!t) return;
|
|
185
210
|
const { minX, maxX, minY, maxY, mapHeight } = t;
|
|
@@ -188,6 +213,7 @@ export function createMap(inst, opts = {}) {
|
|
|
188
213
|
camera.zoom = targetZoom;
|
|
189
214
|
camera.x = width / 2 - ((minX + maxX) / 2) * targetZoom;
|
|
190
215
|
camera.y = mapHeight / 2 - ((minY + maxY) / 2) * targetZoom;
|
|
216
|
+
memo.lastFit = { padding, auto: padding === fitPadding(), only, x: camera.x, y: camera.y, zoom: camera.zoom };
|
|
191
217
|
render();
|
|
192
218
|
}
|
|
193
219
|
|
|
@@ -279,6 +305,12 @@ export function createMap(inst, opts = {}) {
|
|
|
279
305
|
for (const type of ACTIVITY) inst.listen(inst.root, type, onInput, { passive: true, capture: true });
|
|
280
306
|
}
|
|
281
307
|
inst.onShown(() => scheduler.shown());
|
|
308
|
+
// A page that loaded hidden (a background tab, a pane not yet shown) has had no frames, and a ResizeObserver reports nothing while it is hidden:
|
|
309
|
+
// the box is read again when it is shown (resize() fits the map again if nobody has moved the camera)
|
|
310
|
+
inst.onShown(() => {
|
|
311
|
+
const box = state.canvas && state.canvas.parentElement;
|
|
312
|
+
if (!ended && box && box.clientWidth && box.clientHeight && (box.clientWidth !== state.width || box.clientHeight !== state.height)) resize();
|
|
313
|
+
});
|
|
282
314
|
|
|
283
315
|
/** Ends the map: no frame is waiting, the renderer's GPU context and the label layer are released, nothing is called again */
|
|
284
316
|
function destroy() {
|
package/explorer/pieces/map.js
CHANGED
|
@@ -249,13 +249,8 @@ function mountOn(root, inst, options, privateScope) {
|
|
|
249
249
|
/** Where nodes sit for the current view (engine/topology.js) */
|
|
250
250
|
const applyLayout = () => layoutMap(inst);
|
|
251
251
|
|
|
252
|
-
/**
|
|
253
|
-
|
|
254
|
-
const fit = () => {
|
|
255
|
-
if (!state.nodes.length) return;
|
|
256
|
-
fitWhenSized = !state.width || !state.height;
|
|
257
|
-
if (!fitWhenSized) map.fitGraphToViewport(map.fitPadding());
|
|
258
|
-
};
|
|
252
|
+
/** The whole map in view. With no box yet the engine waits for one (engine/render.js), and fits again if the box changes before anyone moves the camera */
|
|
253
|
+
const fit = () => { if (state.nodes.length) map.fitGraphToViewport(map.fitPadding()); };
|
|
259
254
|
const nodeById = (id) => state.nodes.find((n) => n.id === id) || null;
|
|
260
255
|
|
|
261
256
|
// -- selection: one path for the page and a component ---------------------------------------------------------------------------------
|
|
@@ -302,7 +297,6 @@ function mountOn(root, inst, options, privateScope) {
|
|
|
302
297
|
|
|
303
298
|
// -- the first frame ---------------------------------------------------------------------------------------------------------------------
|
|
304
299
|
scope.own(map.onPaint(() => {
|
|
305
|
-
if (fitWhenSized && state.width && state.height) fit();
|
|
306
300
|
if (ready || !state.nodes.length) return;
|
|
307
301
|
ready = true;
|
|
308
302
|
if (options.onReady) options.onReady();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popcorn245/cornfield",
|
|
3
|
-
"version": "0.51.
|
|
3
|
+
"version": "0.51.3",
|
|
4
4
|
"description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "popcorn245 (https://github.com/popcorn245)",
|