@popcorn245/cornfield 0.52.0 → 0.53.0
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/core/strings.js +2 -0
- package/explorer/css/node-panel.css +3 -1
- package/explorer/decision-model.js +2 -0
- package/explorer/engine/map-rect.js +8 -6
- package/explorer/engine/map-style.js +12 -6
- package/explorer/engine/player.js +17 -11
- package/explorer/engine/sheets.js +8 -0
- package/explorer/glyphs.js +14 -6
- package/explorer/instance.js +9 -1
- package/explorer/pieces/around.js +33 -4
- package/explorer/pieces/changes.js +32 -26
- package/explorer/pieces/decision.js +15 -8
- package/explorer/pieces/layers.js +4 -3
- package/explorer/pieces/map.js +6 -1
- package/explorer/pieces/proposal.js +41 -14
- package/explorer/pieces/scope-link.js +2 -2
- package/explorer/pieces/scope-proposal.js +158 -0
- package/explorer/pieces/scope.js +64 -1
- package/explorer/renderer-canvas2d.js +46 -12
- package/explorer/renderer-webgl.js +3 -1
- package/explorer/shaders.js +17 -6
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* labels are the label layer's (labels.js), one transparent canvas over the map for either renderer.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { CORE_RATIO, ARROW, END_SHAPES, SHAPE_SIZES, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, packetPoint } from './scene.js';
|
|
11
|
+
import { CORE_RATIO, ARROW, END_SHAPES, SHAPE_REACH, SHAPE_SIZES, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, packetPoint, parseColor } from './scene.js';
|
|
12
12
|
import { GLYPH_TOKEN, ICON_RATIO, PLAIN_STYLE, looksWith, styledScene } from './engine/map-style.js';
|
|
13
13
|
import { LETTER_RATIO, letterImage, showsLetters } from './kind-letters.js';
|
|
14
14
|
import { GLYPH_RATIO, glyphImage, glyphInk, showsGlyph } from './glyphs.js';
|
|
@@ -18,6 +18,17 @@ const TAU = Math.PI * 2;
|
|
|
18
18
|
const GLOW_MIN_PX = 1.5;
|
|
19
19
|
/** A scene with this many edges or fewer is drawn directly each frame; more, and its lines go into the layer while packets move */
|
|
20
20
|
export const LAYER_MIN_EDGES = 600;
|
|
21
|
+
const alphas = new Map();
|
|
22
|
+
/** The alpha of a node's colour (0..1; 1 for what is not read), remembered: it is asked for every glowing node of every frame */
|
|
23
|
+
function alphaOf(color) {
|
|
24
|
+
let a = alphas.get(color);
|
|
25
|
+
if (a === undefined) {
|
|
26
|
+
if (alphas.size > 512) alphas.clear();
|
|
27
|
+
a = parseColor(color)[3];
|
|
28
|
+
alphas.set(color, a);
|
|
29
|
+
}
|
|
30
|
+
return a;
|
|
31
|
+
}
|
|
21
32
|
const circle = (ctx, x, y, r) => { ctx.beginPath(); ctx.arc(x, y, r, 0, TAU); };
|
|
22
33
|
|
|
23
34
|
/**
|
|
@@ -25,29 +36,30 @@ const circle = (ctx, x, y, r) => { ctx.beginPath(); ctx.arc(x, y, r, 0, TAU); };
|
|
|
25
36
|
* a rounded square for data, a hexagon for what is outside, a square for where things run, a diamond for people. The WebGL node shader draws the same shapes
|
|
26
37
|
* with the same sizes (scene.js `SHAPE_SIZES`, shaders.js `sdShape`).
|
|
27
38
|
*/
|
|
28
|
-
export function silhouette(ctx, shape, x, y, r) {
|
|
39
|
+
export function silhouette(ctx, shape, x, y, r, add = false) {
|
|
40
|
+
const begin = () => { if (!add) ctx.beginPath(); }; // `add`: another piece of the path being built (a clip with a hole), not a new path
|
|
29
41
|
if (shape === 'rounded-square' || shape === 'square') {
|
|
30
42
|
const h = r * (shape === 'square' ? SHAPE_SIZES.squareHalf : SHAPE_SIZES.roundedHalf);
|
|
31
43
|
const c = r * (shape === 'square' ? SHAPE_SIZES.squareCorner : SHAPE_SIZES.roundedCorner);
|
|
32
|
-
|
|
44
|
+
begin();
|
|
33
45
|
if (ctx.roundRect) ctx.roundRect(x - h, y - h, h * 2, h * 2, c); else ctx.rect(x - h, y - h, h * 2, h * 2);
|
|
34
46
|
return;
|
|
35
47
|
}
|
|
36
48
|
if (shape === 'hexagon') {
|
|
37
49
|
const R = (r * SHAPE_SIZES.hexInradius) / Math.cos(Math.PI / 6); // flat top and bottom: the inradius is what the SDF takes
|
|
38
|
-
|
|
50
|
+
begin();
|
|
39
51
|
for (let i = 0; i < 6; i++) { const a = Math.PI / 6 + (i * Math.PI) / 3; const px = x + R * Math.cos(a), py = y + R * Math.sin(a); if (i) ctx.lineTo(px, py); else ctx.moveTo(px, py); }
|
|
40
52
|
ctx.closePath();
|
|
41
53
|
return;
|
|
42
54
|
}
|
|
43
55
|
if (shape === 'diamond') {
|
|
44
56
|
const h = r * SHAPE_SIZES.diamondHalf;
|
|
45
|
-
|
|
57
|
+
begin();
|
|
46
58
|
ctx.moveTo(x, y - h); ctx.lineTo(x + h, y); ctx.lineTo(x, y + h); ctx.lineTo(x - h, y);
|
|
47
59
|
ctx.closePath();
|
|
48
60
|
return;
|
|
49
61
|
}
|
|
50
|
-
circle(ctx, x, y, r);
|
|
62
|
+
if (add) { ctx.moveTo(x + r, y); ctx.arc(x, y, r, 0, TAU); } else circle(ctx, x, y, r);
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
// ---------------------------------------------------------------------------
|
|
@@ -276,7 +288,7 @@ function edgesInView(scene, camera, width, height) {
|
|
|
276
288
|
// ---------------------------------------------------------------------------
|
|
277
289
|
// Nodes
|
|
278
290
|
// ---------------------------------------------------------------------------
|
|
279
|
-
function drawNode(ctx, node, zoom, looks, style) {
|
|
291
|
+
function drawNode(ctx, node, zoom, looks, style, theme) {
|
|
280
292
|
ctx.save();
|
|
281
293
|
ctx.globalAlpha = node.alpha;
|
|
282
294
|
|
|
@@ -319,9 +331,31 @@ function drawNode(ctx, node, zoom, looks, style) {
|
|
|
319
331
|
// A soft disc behind the node, not `shadowBlur` (see drawEdge): one cheap fill instead of a blur pass
|
|
320
332
|
ctx.save();
|
|
321
333
|
ctx.globalAlpha = node.alpha * 0.28;
|
|
322
|
-
|
|
334
|
+
const reach = node.r + node.glow * 0.7;
|
|
323
335
|
ctx.fillStyle = node.color;
|
|
324
|
-
|
|
336
|
+
if (alphaOf(node.color) < 1) {
|
|
337
|
+
// Under a translucent fill the glow is left out, so the fill alone sets what shows through it; WebGL's node shader does the same.
|
|
338
|
+
// The shape inside the glow's disc (the usual case): the disc with the shape as a hole, filled even-odd. A square's corners or a diamond's
|
|
339
|
+
// points can reach past a small glow's disc (a theme's --corn-map-glow), and that fill would put them over the glow: then the disc is
|
|
340
|
+
// clipped to everything but the shape (a square round both, the shape cut out even-odd)
|
|
341
|
+
if (node.r * (SHAPE_REACH[node.shape] || 1) < reach) {
|
|
342
|
+
circle(ctx, node.x, node.y, reach);
|
|
343
|
+
silhouette(ctx, node.shape, node.x, node.y, node.r, true);
|
|
344
|
+
ctx.fill('evenodd');
|
|
345
|
+
} else {
|
|
346
|
+
const side = reach + node.r;
|
|
347
|
+
ctx.beginPath();
|
|
348
|
+
ctx.rect(node.x - side, node.y - side, side * 2, side * 2);
|
|
349
|
+
silhouette(ctx, node.shape, node.x, node.y, node.r, true);
|
|
350
|
+
ctx.clip('evenodd');
|
|
351
|
+
circle(ctx, node.x, node.y, reach);
|
|
352
|
+
ctx.fill();
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
// An opaque fill hides the glow under it: drawn as it always was
|
|
356
|
+
circle(ctx, node.x, node.y, reach);
|
|
357
|
+
ctx.fill();
|
|
358
|
+
}
|
|
325
359
|
ctx.restore();
|
|
326
360
|
silhouette(ctx, node.shape, node.x, node.y, node.r);
|
|
327
361
|
}
|
|
@@ -331,7 +365,7 @@ function drawNode(ctx, node, zoom, looks, style) {
|
|
|
331
365
|
// The glyph takes the core dot's place: drawn over it, the dot would fill the glyph's own shapes and blur it at the sizes nodes have
|
|
332
366
|
const image = node.icon && style.icons ? style.icons.get(node.icon) : null;
|
|
333
367
|
const letters = !image && showsLetters(node, zoom);
|
|
334
|
-
const glyph = !image && !letters && showsGlyph(node, zoom) ? glyphImage(node.glyph, glyphInk(node, style)) : null;
|
|
368
|
+
const glyph = !image && !letters && showsGlyph(node, zoom) ? glyphImage(node.glyph, glyphInk(node, style, theme)) : null;
|
|
335
369
|
if (!glyph) {
|
|
336
370
|
circle(ctx, node.x, node.y, node.r * CORE_RATIO);
|
|
337
371
|
ctx.fillStyle = looks.core;
|
|
@@ -460,7 +494,7 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
|
|
|
460
494
|
ctx.translate(camera.x, camera.y);
|
|
461
495
|
ctx.scale(camera.zoom, camera.zoom);
|
|
462
496
|
inView.forEach((edge) => { if (edge.packet) drawPacket(ctx, edge, timeMs, camera.zoom); });
|
|
463
|
-
scene.nodes.forEach((node) => drawNode(ctx, node, camera.zoom, looks, style));
|
|
497
|
+
scene.nodes.forEach((node) => drawNode(ctx, node, camera.zoom, looks, style, scene.theme));
|
|
464
498
|
ctx.restore();
|
|
465
499
|
return;
|
|
466
500
|
}
|
|
@@ -475,7 +509,7 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
|
|
|
475
509
|
if (decor.rings.length) drawRings(ctx, decor.rings);
|
|
476
510
|
|
|
477
511
|
inView.forEach((edge) => drawEdge(ctx, edge, timeMs, camera.zoom));
|
|
478
|
-
scene.nodes.forEach((node) => drawNode(ctx, node, camera.zoom, looks, style));
|
|
512
|
+
scene.nodes.forEach((node) => drawNode(ctx, node, camera.zoom, looks, style, scene.theme));
|
|
479
513
|
// No text here: every label (and the strike through a removed one) is drawn by the label layer (labels.js) over this canvas
|
|
480
514
|
|
|
481
515
|
ctx.restore();
|
|
@@ -226,7 +226,7 @@ export function packIcons(scene, has, style = null) {
|
|
|
226
226
|
let kind = n.icon && has(n.icon) ? n.icon : null;
|
|
227
227
|
let side = n.r * ICON_RATIO;
|
|
228
228
|
if (!kind && !n.icon && n.letters && has(letterKey(n.letters))) { kind = letterKey(n.letters); side = n.r * LETTER_RATIO; }
|
|
229
|
-
if (!kind && !n.icon && !n.letters && n.glyph) { const key = glyphKey(n.glyph, glyphInk(n, style)); if (has(key)) { kind = key; side = n.r * GLYPH_RATIO; } } // the type's own glyph, last (glyphs.js)
|
|
229
|
+
if (!kind && !n.icon && !n.letters && n.glyph) { const key = glyphKey(n.glyph, glyphInk(n, style, scene.theme)); if (has(key)) { kind = key; side = n.r * GLYPH_RATIO; } } // the type's own glyph, last (glyphs.js)
|
|
230
230
|
if (!kind) return;
|
|
231
231
|
if (!byKind.has(kind)) byKind.set(kind, { rows: [], minR: Infinity, maxR: 0 });
|
|
232
232
|
const group = byKind.get(kind);
|
|
@@ -458,6 +458,7 @@ export function createWebglRenderer(canvas, opts = {}) {
|
|
|
458
458
|
let packed = null;
|
|
459
459
|
let packedScene = null;
|
|
460
460
|
let packedVersion;
|
|
461
|
+
let packedGround = null; // the ground the icon rows were packed for: a translucent node's glyph ink depends on it (glyphs.js)
|
|
461
462
|
let lastArgs = null;
|
|
462
463
|
|
|
463
464
|
/** A pass only a theme asks for (EXTRA_PASSES), built the first time it is wanted */
|
|
@@ -527,6 +528,7 @@ export function createWebglRenderer(canvas, opts = {}) {
|
|
|
527
528
|
gpu.glyphInk = ink;
|
|
528
529
|
packedScene = null; // the icon rows are made again for the new ink
|
|
529
530
|
}
|
|
531
|
+
if (packedGround !== style.ground) { packedGround = style.ground; packedScene = null; } // another ground: a translucent node's glyph may take the other ink
|
|
530
532
|
if (scene !== packedScene || scene.version !== packedVersion) {
|
|
531
533
|
packed = { ...packScene(scene), strokes: packStrokes(scene), icons: packIcons(scene, (kind) => (isLetterKey(kind) ? !!letterImage(lettersOfKey(kind), ink) : isGlyphKey(kind) ? !!glyphImage(glyphOfKey(kind).type, glyphOfKey(kind).ink) : !!(style.icons && style.icons.get(kind))), style) };
|
|
532
534
|
packedScene = scene;
|
package/explorer/shaders.js
CHANGED
|
@@ -289,15 +289,26 @@ void main() {
|
|
|
289
289
|
over(acc, ring.rgb, ring.a * al * coverBand(abs(len - (rw + u_haloGeom[halo].y) * zoom), u_haloGeom[halo].z * zoom * 0.5, pix));
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
// Glow: a blurred copy of the disc under it (see glowDisc)
|
|
293
|
-
float glow = v_color.w;
|
|
294
|
-
if (glow > 0.0) over(acc, v_color.rgb, v_kind.z * al * glowDisc(len, R, glow * 0.5 / u_dpr));
|
|
295
|
-
|
|
296
|
-
// The silhouette, and its white core unless the type's glyph is drawn there (glyphs.js: the icon pass draws it once the node is wide enough)
|
|
297
292
|
int shapeCode = int(v_kind.w + 0.5);
|
|
298
293
|
bool glyph = shapeCode >= 8;
|
|
299
294
|
if (glyph) shapeCode -= 8;
|
|
300
|
-
|
|
295
|
+
float shapeCover = coverEdge(sdShape(v_local, R, shapeCode, len), pix); // how much of this pixel the silhouette covers
|
|
296
|
+
|
|
297
|
+
// Glow: a blurred copy of the disc under it (see glowDisc), then the silhouette. An opaque fill hides the glow under it: drawn as it always was.
|
|
298
|
+
// Under a translucent fill the glow is left out, so the fill alone sets what is seen through it, as renderer-canvas2d.js drawNode does (a clip).
|
|
299
|
+
// Glow and fill are the same colour, so that is ONE layer: the fill in the part of the pixel the silhouette covers, the glow in the rest. Two
|
|
300
|
+
// layers (the glow times 1 - cover, then the fill times cover) would let the ground through both at the edge: a dark line round a square or a
|
|
301
|
+
// diamond, whose sides lie inside the glow's disc
|
|
302
|
+
float glow = v_color.w;
|
|
303
|
+
if (v_kind.z < 1.0) {
|
|
304
|
+
float soft = glow > 0.0 ? glowDisc(len, R, glow * 0.5 / u_dpr) : 0.0;
|
|
305
|
+
over(acc, v_color.rgb, v_kind.z * al * mix(soft, 1.0, shapeCover));
|
|
306
|
+
} else {
|
|
307
|
+
if (glow > 0.0) over(acc, v_color.rgb, v_kind.z * al * glowDisc(len, R, glow * 0.5 / u_dpr));
|
|
308
|
+
over(acc, v_color.rgb, v_kind.z * al * shapeCover);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// The white core unless the type's glyph is drawn there (glyphs.js: the icon pass draws it once the node is wide enough)
|
|
301
312
|
if (!glyph || 2.0 * R < u_glyphMin) over(acc, u_core.rgb, u_core.a * al * coverEdge(len - R * u_coreRatio, pix));
|
|
302
313
|
|
|
303
314
|
// Mark: a ring with the look of its own mark (dashed when its dash is set: added), and for removed a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@popcorn245/cornfield",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
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)",
|