@mark1russell7/visuals 0.3.5 → 0.3.6
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/README.md +86 -1
- package/build/graph.d.ts +451 -58
- package/build/graph.d.ts.map +1 -1
- package/build/graph.js +887 -20
- package/build/graph.js.map +1 -1
- package/package.json +2 -2
package/build/graph.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { a as partAt, c as highlightOf, f as KEY_ZOOM, l as isClick, n as easeInOut, r as lessMotion, s as NO_HIGHLIGHTS, u as KEY_PART } from "./motion-VS13e4Pw.js";
|
|
1
|
+
import { a as partAt, c as highlightOf, f as KEY_ZOOM, l as isClick, n as easeInOut, r as lessMotion, s as NO_HIGHLIGHTS, t as approach, u as KEY_PART } from "./motion-VS13e4Pw.js";
|
|
2
|
+
import { grow, overlapOf, pathBounds, pathEnd, pathStart, pictureBounds, pointPolylineDistance, pointRegionDistance, rectCenter, samplePath, translate } from "@mark1russell7/layout-contract";
|
|
2
3
|
// src/graph/camera.ts
|
|
3
4
|
/** The default limits of the zoom. */
|
|
4
5
|
const ZOOM_LIMITS = {
|
|
@@ -123,16 +124,6 @@ function freeArea(size, insets = {}) {
|
|
|
123
124
|
}
|
|
124
125
|
/** The default distance between a rectangle that a camera shows and each edge of the area, in CSS pixels. */
|
|
125
126
|
const FIT_PADDING = 24;
|
|
126
|
-
/**
|
|
127
|
-
* This function gives the middle of a rectangle.
|
|
128
|
-
* The home of this function is `@mark1russell7/layout-contract`, which does not have it. It moves there with the records of a picture.
|
|
129
|
-
*/
|
|
130
|
-
function middleOf(rect) {
|
|
131
|
-
return {
|
|
132
|
-
x: rect.x + rect.w / 2,
|
|
133
|
-
y: rect.y + rect.h / 2
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
127
|
/** This function gives the zoom at which a rectangle of the picture fills an area of the screen, with a padding at each edge. */
|
|
137
128
|
function fillZoom(rect, area, padding) {
|
|
138
129
|
const width = Math.max(area.w - 2 * padding, 1);
|
|
@@ -146,7 +137,7 @@ function fillZoom(rect, area, padding) {
|
|
|
146
137
|
function fitRect(rect, area, options = {}) {
|
|
147
138
|
const limits = options.limits ?? ZOOM_LIMITS;
|
|
148
139
|
const k = clampZoom(Math.min(options.most ?? limits.max, fillZoom(rect, area, options.padding ?? 24)), limits);
|
|
149
|
-
return viewAt(
|
|
140
|
+
return viewAt(rectCenter(rect), rectCenter(area), k);
|
|
150
141
|
}
|
|
151
142
|
/**
|
|
152
143
|
* This function gives the limits of the zoom for a picture with the bounds `bounds`.
|
|
@@ -204,7 +195,7 @@ function frameRects(rects, area, options) {
|
|
|
204
195
|
}
|
|
205
196
|
const last = rects.at(-1);
|
|
206
197
|
if (last === void 0) return void 0;
|
|
207
|
-
return viewAt(
|
|
198
|
+
return viewAt(rectCenter(last), rectCenter(area), clampZoom(options.least, options.limits));
|
|
208
199
|
}
|
|
209
200
|
/**
|
|
210
201
|
* This function tells if a view shows all of a rectangle of the picture in an area of the screen.
|
|
@@ -293,6 +284,867 @@ function aimReveal(rects, options) {
|
|
|
293
284
|
limits: options.limits ?? frame.limits
|
|
294
285
|
});
|
|
295
286
|
}
|
|
287
|
+
// src/graph/draw.ts
|
|
288
|
+
const TURN = 2 * Math.PI;
|
|
289
|
+
/** This function adds a path of the picture to the path of a context. */
|
|
290
|
+
function tracePath(context, path) {
|
|
291
|
+
for (const segment of path) switch (segment.kind) {
|
|
292
|
+
case "move":
|
|
293
|
+
context.moveTo(segment.to.x, segment.to.y);
|
|
294
|
+
break;
|
|
295
|
+
case "line":
|
|
296
|
+
context.lineTo(segment.to.x, segment.to.y);
|
|
297
|
+
break;
|
|
298
|
+
case "cubic":
|
|
299
|
+
context.bezierCurveTo(segment.c1.x, segment.c1.y, segment.c2.x, segment.c2.y, segment.to.x, segment.to.y);
|
|
300
|
+
break;
|
|
301
|
+
case "arc": context.arc(segment.center.x, segment.center.y, segment.radius, segment.start, segment.start + segment.sweep, segment.sweep < 0);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/** This function makes the path of an outline in a context. */
|
|
305
|
+
function trace(context, outline) {
|
|
306
|
+
context.beginPath();
|
|
307
|
+
switch (outline.kind) {
|
|
308
|
+
case "rect":
|
|
309
|
+
if (outline.radius > 0 && typeof context.roundRect === "function") context.roundRect(outline.x, outline.y, outline.w, outline.h, outline.radius);
|
|
310
|
+
else context.rect(outline.x, outline.y, outline.w, outline.h);
|
|
311
|
+
break;
|
|
312
|
+
case "ellipse":
|
|
313
|
+
context.ellipse(outline.cx, outline.cy, outline.rx, outline.ry, 0, 0, TURN);
|
|
314
|
+
break;
|
|
315
|
+
case "polygon":
|
|
316
|
+
for (const ring of outline.rings) {
|
|
317
|
+
ring.forEach(([x, y], i) => i === 0 ? context.moveTo(x, y) : context.lineTo(x, y));
|
|
318
|
+
context.closePath();
|
|
319
|
+
}
|
|
320
|
+
break;
|
|
321
|
+
case "path": tracePath(context, outline.path);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* This function draws a paint list on a canvas, in the order of the list. `paintPicture` makes the list.
|
|
326
|
+
*
|
|
327
|
+
* The unit of the context is the CSS pixel, as a flat stage gives it: the function applies the view of the camera.
|
|
328
|
+
* The function keeps the state of the context: after it, the context has the transform and the styles that it had before.
|
|
329
|
+
*/
|
|
330
|
+
function drawShapes(context, shapes, view) {
|
|
331
|
+
if (shapes.length === 0) return;
|
|
332
|
+
context.save();
|
|
333
|
+
context.transform(view.k, 0, 0, view.k, view.x, view.y);
|
|
334
|
+
context.lineJoin = "round";
|
|
335
|
+
context.lineCap = "round";
|
|
336
|
+
context.textBaseline = "middle";
|
|
337
|
+
/** This value is true while the context has dashes. Most shapes have none, so the function sets them only at a change. */
|
|
338
|
+
let dashed = false;
|
|
339
|
+
for (const shape of shapes) {
|
|
340
|
+
context.globalAlpha = shape.opacity;
|
|
341
|
+
if (shape.type === "text") {
|
|
342
|
+
context.font = shape.font;
|
|
343
|
+
context.textAlign = shape.align;
|
|
344
|
+
if (shape.halo !== void 0) {
|
|
345
|
+
if (dashed) {
|
|
346
|
+
context.setLineDash([]);
|
|
347
|
+
dashed = false;
|
|
348
|
+
}
|
|
349
|
+
context.strokeStyle = shape.halo.color;
|
|
350
|
+
context.lineWidth = shape.halo.width;
|
|
351
|
+
context.strokeText(shape.text, shape.x, shape.y);
|
|
352
|
+
}
|
|
353
|
+
context.fillStyle = shape.fill;
|
|
354
|
+
context.fillText(shape.text, shape.x, shape.y);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
trace(context, shape.outline);
|
|
358
|
+
if (shape.fill !== void 0) {
|
|
359
|
+
context.fillStyle = shape.fill;
|
|
360
|
+
context.fill("evenodd");
|
|
361
|
+
}
|
|
362
|
+
if (shape.stroke !== void 0 && shape.lineWidth !== void 0 && shape.lineWidth > 0) {
|
|
363
|
+
const dash = shape.dash;
|
|
364
|
+
const next = dash !== void 0 && dash.length > 0;
|
|
365
|
+
if (next || dashed) {
|
|
366
|
+
context.setLineDash(next ? [...dash] : []);
|
|
367
|
+
dashed = next;
|
|
368
|
+
}
|
|
369
|
+
context.strokeStyle = shape.stroke;
|
|
370
|
+
context.lineWidth = shape.lineWidth;
|
|
371
|
+
context.stroke();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
context.restore();
|
|
375
|
+
}
|
|
376
|
+
// src/graph/focus.ts
|
|
377
|
+
/** The share of the color that a record keeps at each focus level. */
|
|
378
|
+
const FOCUS_OPACITY = {
|
|
379
|
+
all: 1,
|
|
380
|
+
in: 1,
|
|
381
|
+
beside: .55,
|
|
382
|
+
out: .2
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* This function gives the focus of a list of records, or `undefined` when the picture has none of them.
|
|
386
|
+
*
|
|
387
|
+
* - A box brings each box below it in the tree.
|
|
388
|
+
* - Each route at one of these boxes is in the focus, with the box at its other end.
|
|
389
|
+
* - A route brings its two boxes.
|
|
390
|
+
* - Each box of the focus brings each box above it in the tree, so the card of a row stays clear.
|
|
391
|
+
*/
|
|
392
|
+
function focusOf(index, seeds) {
|
|
393
|
+
const boxes = /* @__PURE__ */ new Set();
|
|
394
|
+
const routes = /* @__PURE__ */ new Set();
|
|
395
|
+
/** The boxes of the list, and each box below them. */
|
|
396
|
+
const own = [];
|
|
397
|
+
const addRoute = (route) => {
|
|
398
|
+
routes.add(route.id);
|
|
399
|
+
if (index.boxes.has(route.source)) boxes.add(route.source);
|
|
400
|
+
if (index.boxes.has(route.target)) boxes.add(route.target);
|
|
401
|
+
};
|
|
402
|
+
const seedRoutes = [];
|
|
403
|
+
for (const seed of seeds) {
|
|
404
|
+
const route = index.routes.get(seed);
|
|
405
|
+
if (route !== void 0) seedRoutes.push(route);
|
|
406
|
+
if (!index.boxes.has(seed)) continue;
|
|
407
|
+
const stack = [seed];
|
|
408
|
+
for (let id = stack.pop(); id !== void 0; id = stack.pop()) {
|
|
409
|
+
if (boxes.has(id)) continue;
|
|
410
|
+
boxes.add(id);
|
|
411
|
+
own.push(id);
|
|
412
|
+
for (const child of index.children.get(id) ?? []) stack.push(child.id);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
for (const id of own) for (const route of index.routesAt.get(id) ?? []) addRoute(route);
|
|
416
|
+
for (const route of seedRoutes) addRoute(route);
|
|
417
|
+
for (const id of [...boxes]) for (let parent = index.boxes.get(id)?.parent; parent !== void 0 && index.boxes.has(parent) && !boxes.has(parent); parent = index.boxes.get(parent)?.parent) boxes.add(parent);
|
|
418
|
+
return boxes.size === 0 && routes.size === 0 ? void 0 : {
|
|
419
|
+
boxes,
|
|
420
|
+
routes
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/** This function gives the focus level of a box. */
|
|
424
|
+
function boxFocus(focus, box) {
|
|
425
|
+
if (focus === void 0) return "all";
|
|
426
|
+
if (focus.boxes.has(box.id)) return "in";
|
|
427
|
+
return box.parent !== void 0 && focus.boxes.has(box.parent) ? "beside" : "out";
|
|
428
|
+
}
|
|
429
|
+
/** This function gives the focus level of a route: `all`, `in` or `out`. */
|
|
430
|
+
function routeFocus(focus, route) {
|
|
431
|
+
if (focus === void 0) return "all";
|
|
432
|
+
return focus.routes.has(route.id) ? "in" : "out";
|
|
433
|
+
}
|
|
434
|
+
// src/graph/records.ts
|
|
435
|
+
/** This function adds a value to the list of a key. */
|
|
436
|
+
function add(lists, key, value) {
|
|
437
|
+
const list = lists.get(key);
|
|
438
|
+
if (list === void 0) lists.set(key, [value]);
|
|
439
|
+
else list.push(value);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* This function makes the tables of a picture. It does not examine the picture: `checkPicture` of `@mark1russell7/layout-contract` does that.
|
|
443
|
+
* For an id that two boxes have, the table has the last box. A label that names a record that the picture does not have is in no table.
|
|
444
|
+
* Thus a page that removes a route from a picture can keep the label of the route.
|
|
445
|
+
*/
|
|
446
|
+
function indexPicture(picture) {
|
|
447
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
448
|
+
const routes = /* @__PURE__ */ new Map();
|
|
449
|
+
const children = /* @__PURE__ */ new Map();
|
|
450
|
+
const routesAt = /* @__PURE__ */ new Map();
|
|
451
|
+
const boxLabels = /* @__PURE__ */ new Map();
|
|
452
|
+
const routeLabels = /* @__PURE__ */ new Map();
|
|
453
|
+
const freeLabels = [];
|
|
454
|
+
for (const box of picture.boxes) {
|
|
455
|
+
boxes.set(box.id, box);
|
|
456
|
+
if (box.parent !== void 0) add(children, box.parent, box);
|
|
457
|
+
}
|
|
458
|
+
for (const route of picture.routes) {
|
|
459
|
+
routes.set(route.id, route);
|
|
460
|
+
add(routesAt, route.source, route);
|
|
461
|
+
if (route.target !== route.source) add(routesAt, route.target, route);
|
|
462
|
+
}
|
|
463
|
+
for (const label of picture.labels) if (label.box !== void 0) {
|
|
464
|
+
if (boxes.has(label.box)) add(boxLabels, label.box, label);
|
|
465
|
+
} else if (label.route !== void 0) {
|
|
466
|
+
if (routes.has(label.route)) add(routeLabels, label.route, label);
|
|
467
|
+
} else freeLabels.push(label);
|
|
468
|
+
return {
|
|
469
|
+
picture,
|
|
470
|
+
boxes,
|
|
471
|
+
routes,
|
|
472
|
+
children,
|
|
473
|
+
routesAt,
|
|
474
|
+
boxLabels,
|
|
475
|
+
routeLabels,
|
|
476
|
+
freeLabels
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
const lines = /* @__PURE__ */ new WeakMap();
|
|
480
|
+
/**
|
|
481
|
+
* This function gives the line of a route, or `undefined` for a route with an empty path.
|
|
482
|
+
* It keeps the line of each route, so a second question about a route costs nothing.
|
|
483
|
+
*/
|
|
484
|
+
function routeLine(route) {
|
|
485
|
+
if (route.path.length === 0) return void 0;
|
|
486
|
+
const known = lines.get(route);
|
|
487
|
+
if (known !== void 0) return known;
|
|
488
|
+
const line = {
|
|
489
|
+
bounds: pathBounds(route.path),
|
|
490
|
+
points: samplePath(route.path)
|
|
491
|
+
};
|
|
492
|
+
lines.set(route, line);
|
|
493
|
+
return line;
|
|
494
|
+
}
|
|
495
|
+
// src/graph/hit.ts
|
|
496
|
+
/** This function gives the distance from a point to a box, and 0 for a point in the box. A box with a `shape` is that region. */
|
|
497
|
+
function boxDistance(box, point) {
|
|
498
|
+
if (box.shape === void 0) return pointRegionDistance(point, {
|
|
499
|
+
kind: "rect",
|
|
500
|
+
x: box.x,
|
|
501
|
+
y: box.y,
|
|
502
|
+
w: box.w,
|
|
503
|
+
h: box.h
|
|
504
|
+
});
|
|
505
|
+
return pointRegionDistance({
|
|
506
|
+
x: point.x - box.x,
|
|
507
|
+
y: point.y - box.y
|
|
508
|
+
}, box.shape);
|
|
509
|
+
}
|
|
510
|
+
const boxesOnly$1 = (record) => record.type === "box";
|
|
511
|
+
/**
|
|
512
|
+
* This function gives the record of a picture below a point, or `undefined` for no record.
|
|
513
|
+
*
|
|
514
|
+
* - A box with no child comes first: the top box at the point, then the nearest box in the slack.
|
|
515
|
+
* - A route comes next: the nearest route in the slack. A route is thin, so it comes before a container.
|
|
516
|
+
* - A box with children comes last: the top one at the point, then the nearest one in the slack.
|
|
517
|
+
*
|
|
518
|
+
* The last record of a list of the picture is the top one. The distance to a route has an error of 0.5 units or less.
|
|
519
|
+
*/
|
|
520
|
+
function pickRecord(index, point, options = {}) {
|
|
521
|
+
const slack = Math.max(0, options.slack ?? 0);
|
|
522
|
+
const picks = options.picks ?? boxesOnly$1;
|
|
523
|
+
let leaf;
|
|
524
|
+
let nearLeaf;
|
|
525
|
+
let nearLeafAt = 1e400;
|
|
526
|
+
let container;
|
|
527
|
+
let nearContainer;
|
|
528
|
+
let nearContainerAt = 1e400;
|
|
529
|
+
for (const box of index.picture.boxes) {
|
|
530
|
+
if (point.x < box.x - slack || point.x > box.x + box.w + slack || point.y < box.y - slack || point.y > box.y + box.h + slack) continue;
|
|
531
|
+
const distance = boxDistance(box, point);
|
|
532
|
+
if (distance > slack) continue;
|
|
533
|
+
const record = {
|
|
534
|
+
type: "box",
|
|
535
|
+
id: box.id,
|
|
536
|
+
box
|
|
537
|
+
};
|
|
538
|
+
if (!picks(record)) continue;
|
|
539
|
+
if (index.children.has(box.id)) {
|
|
540
|
+
if (distance === 0) container = record;
|
|
541
|
+
else if (distance <= nearContainerAt) {
|
|
542
|
+
nearContainer = record;
|
|
543
|
+
nearContainerAt = distance;
|
|
544
|
+
}
|
|
545
|
+
} else if (distance === 0) leaf = record;
|
|
546
|
+
else if (distance <= nearLeafAt) {
|
|
547
|
+
nearLeaf = record;
|
|
548
|
+
nearLeafAt = distance;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (leaf !== void 0) return leaf;
|
|
552
|
+
if (nearLeaf !== void 0) return nearLeaf;
|
|
553
|
+
let found;
|
|
554
|
+
let foundAt = 1e400;
|
|
555
|
+
for (const route of index.picture.routes) {
|
|
556
|
+
const line = routeLine(route);
|
|
557
|
+
if (line === void 0) continue;
|
|
558
|
+
const { bounds } = line;
|
|
559
|
+
if (point.x < bounds.x - slack || point.x > bounds.x + bounds.w + slack || point.y < bounds.y - slack || point.y > bounds.y + bounds.h + slack) continue;
|
|
560
|
+
const record = {
|
|
561
|
+
type: "route",
|
|
562
|
+
id: route.id,
|
|
563
|
+
route
|
|
564
|
+
};
|
|
565
|
+
if (!picks(record)) continue;
|
|
566
|
+
const distance = pointPolylineDistance(point, line.points);
|
|
567
|
+
if (distance > slack || distance > foundAt) continue;
|
|
568
|
+
found = record;
|
|
569
|
+
foundAt = distance;
|
|
570
|
+
}
|
|
571
|
+
return found ?? container ?? nearContainer;
|
|
572
|
+
}
|
|
573
|
+
// src/graph/looks.ts
|
|
574
|
+
/**
|
|
575
|
+
* This function gives the size of one unit of a look, in the unit of the picture.
|
|
576
|
+
* The widths of the lines, the dashes and the sizes of the signs of a look are in this unit.
|
|
577
|
+
*
|
|
578
|
+
* At the zoom 1 or less, one unit is one CSS pixel. Thus a thin line stays clear in a small picture.
|
|
579
|
+
* Above the zoom 1, one unit is one unit of the picture. Thus a line grows with its box.
|
|
580
|
+
*/
|
|
581
|
+
function lookUnit(zoom) {
|
|
582
|
+
return zoom > 0 && zoom < 1 ? 1 / zoom : 1;
|
|
583
|
+
}
|
|
584
|
+
/** The colors of a plain picture on a light page. */
|
|
585
|
+
const LIGHT_PICTURE_THEME = {
|
|
586
|
+
box: "#ffffff",
|
|
587
|
+
boxLine: "#454f67",
|
|
588
|
+
container: "#eef1f6",
|
|
589
|
+
containerLine: "#aeb6c7",
|
|
590
|
+
text: "#151c2e",
|
|
591
|
+
mutedText: "#5f6880",
|
|
592
|
+
route: "#7a8399",
|
|
593
|
+
accent: "#2346c4",
|
|
594
|
+
paper: "#f5f6f9"
|
|
595
|
+
};
|
|
596
|
+
/** The colors of a plain picture on a dark page. */
|
|
597
|
+
const DARK_PICTURE_THEME = {
|
|
598
|
+
box: "#151a2b",
|
|
599
|
+
boxLine: "#b3bad0",
|
|
600
|
+
container: "#1c2236",
|
|
601
|
+
containerLine: "#46507a",
|
|
602
|
+
text: "#e6e9f3",
|
|
603
|
+
mutedText: "#949cb3",
|
|
604
|
+
route: "#6f7aa3",
|
|
605
|
+
accent: "#93abff",
|
|
606
|
+
paper: "#0e1220"
|
|
607
|
+
};
|
|
608
|
+
/** The smallest height of a line of text on the screen that a person can read, in CSS pixels. A smaller line is a bar in a plain picture. */
|
|
609
|
+
const SMALLEST_TEXT_LINE = 11;
|
|
610
|
+
/** The smallest height of a line of text on the screen that a plain picture shows as a bar, in CSS pixels. */
|
|
611
|
+
const SMALLEST_BAR_LINE = 2.5;
|
|
612
|
+
/**
|
|
613
|
+
* This function gives the looks of a plain picture: boxes with a border, routes as lines and the text of the labels.
|
|
614
|
+
*
|
|
615
|
+
* - A record below the pointer has the color `accent`. The selected record has a wider line too.
|
|
616
|
+
* - A box with children has the colors of a container, and its label has the muted color.
|
|
617
|
+
* - The label of a route has a line of the color `paper` around its letters.
|
|
618
|
+
* - A text that is too small to read is a row of bars. A text that is smaller than a bar has no paint.
|
|
619
|
+
*/
|
|
620
|
+
function plainLooks(options = {}) {
|
|
621
|
+
const radius = options.radius ?? 6;
|
|
622
|
+
return {
|
|
623
|
+
box(_box, state, theme) {
|
|
624
|
+
const plain = state.container ? theme.containerLine : theme.boxLine;
|
|
625
|
+
return {
|
|
626
|
+
fill: state.container ? theme.container : theme.box,
|
|
627
|
+
stroke: state.highlight > 0 ? theme.accent : plain,
|
|
628
|
+
width: state.highlight === 2 ? 2 : 1,
|
|
629
|
+
radius
|
|
630
|
+
};
|
|
631
|
+
},
|
|
632
|
+
route(_route, state, theme) {
|
|
633
|
+
return {
|
|
634
|
+
stroke: state.highlight > 0 ? theme.accent : theme.route,
|
|
635
|
+
width: state.highlight === 2 ? 2 : 1.25,
|
|
636
|
+
end: options.end
|
|
637
|
+
};
|
|
638
|
+
},
|
|
639
|
+
label(label, state, theme, of) {
|
|
640
|
+
const tall = label.lineHeight * state.zoom;
|
|
641
|
+
if (tall < 2.5) return void 0;
|
|
642
|
+
if (tall < 11) return {
|
|
643
|
+
color: theme.containerLine,
|
|
644
|
+
as: "bars"
|
|
645
|
+
};
|
|
646
|
+
if (of?.type === "route") return {
|
|
647
|
+
color: theme.text,
|
|
648
|
+
halo: theme.paper
|
|
649
|
+
};
|
|
650
|
+
return { color: state.container ? theme.mutedText : theme.text };
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
// src/graph/paint.ts
|
|
655
|
+
/** The key of the labels that name no record, for `fade`. */
|
|
656
|
+
const FREE_LABELS = "labels";
|
|
657
|
+
/** The distance out of the view at which a record keeps its shapes, in units of a look. A ring, a sign or a wide line can be this far from its record. */
|
|
658
|
+
const VIEW_MARGIN = 24;
|
|
659
|
+
/** The height of a bar of a label, as a share of the height of its line. */
|
|
660
|
+
const BAR_HEIGHT = .42;
|
|
661
|
+
/** The width of the line around the letters of a label, as a share of the height of its line. */
|
|
662
|
+
const HALO_WIDTH = .25;
|
|
663
|
+
/** The half width of an arrow at the end of a route, as a share of its length. */
|
|
664
|
+
const ARROW_SPREAD = .45;
|
|
665
|
+
/** This function gives the key of a record for `fade`: its type, a colon and its id. A box and a route with the same id have different keys. */
|
|
666
|
+
function recordKey(type, id) {
|
|
667
|
+
return `${type}:${id}`;
|
|
668
|
+
}
|
|
669
|
+
/** This function gives the state of a box for its look. */
|
|
670
|
+
function boxState(index, box, state) {
|
|
671
|
+
return {
|
|
672
|
+
highlight: state.highlight(box.id),
|
|
673
|
+
focus: boxFocus(state.focus, box),
|
|
674
|
+
zoom: state.zoom,
|
|
675
|
+
container: index.children.has(box.id)
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
/** This function gives the state of a route for its look. */
|
|
679
|
+
function routeState(route, state) {
|
|
680
|
+
return {
|
|
681
|
+
highlight: state.highlight(route.id),
|
|
682
|
+
focus: routeFocus(state.focus, route),
|
|
683
|
+
zoom: state.zoom,
|
|
684
|
+
container: false
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
/** This function gives the outline of a box, larger by `more` at each side. A polygon does not become larger. */
|
|
688
|
+
function outlineOf(box, radius, more) {
|
|
689
|
+
const region = box.shape === void 0 ? {
|
|
690
|
+
kind: "rect",
|
|
691
|
+
x: box.x,
|
|
692
|
+
y: box.y,
|
|
693
|
+
w: box.w,
|
|
694
|
+
h: box.h
|
|
695
|
+
} : translate(box.shape, box.x, box.y);
|
|
696
|
+
switch (region.kind) {
|
|
697
|
+
case "rect": {
|
|
698
|
+
const w = Math.max(0, region.w + 2 * more);
|
|
699
|
+
const h = Math.max(0, region.h + 2 * more);
|
|
700
|
+
return {
|
|
701
|
+
kind: "rect",
|
|
702
|
+
x: region.x - more,
|
|
703
|
+
y: region.y - more,
|
|
704
|
+
w,
|
|
705
|
+
h,
|
|
706
|
+
radius: Math.max(0, Math.min(radius + more, w / 2, h / 2))
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
case "circle": return {
|
|
710
|
+
kind: "ellipse",
|
|
711
|
+
cx: region.cx,
|
|
712
|
+
cy: region.cy,
|
|
713
|
+
rx: Math.max(0, region.r + more),
|
|
714
|
+
ry: Math.max(0, region.r + more)
|
|
715
|
+
};
|
|
716
|
+
case "ellipse": return {
|
|
717
|
+
kind: "ellipse",
|
|
718
|
+
cx: region.cx,
|
|
719
|
+
cy: region.cy,
|
|
720
|
+
rx: Math.max(0, region.rx + more),
|
|
721
|
+
ry: Math.max(0, region.ry + more)
|
|
722
|
+
};
|
|
723
|
+
case "polygon": return {
|
|
724
|
+
kind: "polygon",
|
|
725
|
+
rings: region.holes === void 0 ? [region.points] : [region.points, ...region.holes]
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
/** This function gives the lengths of a dash in the unit of the picture. */
|
|
730
|
+
function dashOf(dash, unit) {
|
|
731
|
+
return dash === void 0 || dash.length === 0 ? void 0 : dash.map((length) => length * unit);
|
|
732
|
+
}
|
|
733
|
+
/** This function adds the shapes of a box: its ring, its inside and border, and its signs. */
|
|
734
|
+
function addBox(shapes, box, look, unit, share) {
|
|
735
|
+
const opacity = Math.min(1, (look.opacity ?? 1) * share);
|
|
736
|
+
if (!(opacity > 0)) return;
|
|
737
|
+
const radius = look.radius ?? 0;
|
|
738
|
+
if (look.ring !== void 0) {
|
|
739
|
+
const more = (look.ring.gap + look.ring.width / 2) * unit;
|
|
740
|
+
shapes.push({
|
|
741
|
+
type: "shape",
|
|
742
|
+
outline: outlineOf(box, radius, more),
|
|
743
|
+
stroke: look.ring.color,
|
|
744
|
+
lineWidth: look.ring.width * unit,
|
|
745
|
+
opacity
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
if (look.fill !== void 0 || look.stroke !== void 0) {
|
|
749
|
+
const line = look.stroke === void 0 ? void 0 : (look.width ?? 1) * unit;
|
|
750
|
+
shapes.push({
|
|
751
|
+
type: "shape",
|
|
752
|
+
outline: outlineOf(box, radius, 0),
|
|
753
|
+
fill: look.fill,
|
|
754
|
+
stroke: look.stroke,
|
|
755
|
+
lineWidth: line,
|
|
756
|
+
dash: dashOf(look.dash, unit),
|
|
757
|
+
opacity
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
for (const mark of look.marks ?? []) {
|
|
761
|
+
const r = Math.max(0, mark.radius * unit);
|
|
762
|
+
const outline = {
|
|
763
|
+
kind: "ellipse",
|
|
764
|
+
cx: box.x + mark.x,
|
|
765
|
+
cy: box.y + mark.y,
|
|
766
|
+
rx: r,
|
|
767
|
+
ry: r
|
|
768
|
+
};
|
|
769
|
+
if (mark.shape === "dot") shapes.push({
|
|
770
|
+
type: "shape",
|
|
771
|
+
outline,
|
|
772
|
+
fill: mark.color,
|
|
773
|
+
opacity
|
|
774
|
+
});
|
|
775
|
+
else shapes.push({
|
|
776
|
+
type: "shape",
|
|
777
|
+
outline,
|
|
778
|
+
stroke: mark.color,
|
|
779
|
+
lineWidth: (mark.width ?? 1.5) * unit,
|
|
780
|
+
opacity
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
/** This function adds the shapes of a label: one text or one bar for each line that is not empty. */
|
|
785
|
+
function addLabel(shapes, label, look, share, measure) {
|
|
786
|
+
if (look === void 0) return;
|
|
787
|
+
const opacity = Math.min(1, (look.opacity ?? 1) * share);
|
|
788
|
+
if (!(opacity > 0)) return;
|
|
789
|
+
const align = label.align ?? "left";
|
|
790
|
+
const left = align === "left" ? 0 : align === "center" ? .5 : 1;
|
|
791
|
+
for (let i = 0; i < label.lines.length; i++) {
|
|
792
|
+
const text = label.lines[i];
|
|
793
|
+
if (text.trim() === "") continue;
|
|
794
|
+
const y = label.y + (i + .5) * label.lineHeight;
|
|
795
|
+
if (look.as !== "bars") {
|
|
796
|
+
const halo = look.halo === void 0 ? void 0 : {
|
|
797
|
+
color: look.halo,
|
|
798
|
+
width: label.lineHeight * HALO_WIDTH
|
|
799
|
+
};
|
|
800
|
+
shapes.push({
|
|
801
|
+
type: "text",
|
|
802
|
+
text,
|
|
803
|
+
x: label.x + left * label.w,
|
|
804
|
+
y,
|
|
805
|
+
font: label.font,
|
|
806
|
+
align,
|
|
807
|
+
fill: look.color,
|
|
808
|
+
halo,
|
|
809
|
+
opacity
|
|
810
|
+
});
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
813
|
+
const measured = measure === void 0 ? label.w : measure(label.font, text);
|
|
814
|
+
const wide = label.w > 0 ? Math.min(measured, label.w) : measured;
|
|
815
|
+
if (!(wide > 0)) continue;
|
|
816
|
+
const tall = label.lineHeight * BAR_HEIGHT;
|
|
817
|
+
const outline = {
|
|
818
|
+
kind: "rect",
|
|
819
|
+
x: label.x + left * (label.w - wide),
|
|
820
|
+
y: y - tall / 2,
|
|
821
|
+
w: wide,
|
|
822
|
+
h: tall,
|
|
823
|
+
radius: Math.min(tall, wide) / 2
|
|
824
|
+
};
|
|
825
|
+
shapes.push({
|
|
826
|
+
type: "shape",
|
|
827
|
+
outline,
|
|
828
|
+
fill: look.color,
|
|
829
|
+
opacity
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
/** This function adds the sign at one end of a route. `out` is 1 at the target and -1 at the source: an arrow points out of the route. */
|
|
834
|
+
function addEnd(shapes, at, out, end, stroke, lineWidth, unit, opacity) {
|
|
835
|
+
const size = end.size * unit;
|
|
836
|
+
if (!(size > 0)) return;
|
|
837
|
+
const { point } = at;
|
|
838
|
+
if (end.shape === "dot") {
|
|
839
|
+
shapes.push({
|
|
840
|
+
type: "shape",
|
|
841
|
+
outline: {
|
|
842
|
+
kind: "ellipse",
|
|
843
|
+
cx: point.x,
|
|
844
|
+
cy: point.y,
|
|
845
|
+
rx: size,
|
|
846
|
+
ry: size
|
|
847
|
+
},
|
|
848
|
+
fill: stroke,
|
|
849
|
+
opacity
|
|
850
|
+
});
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const dx = at.direction.x * out;
|
|
854
|
+
const dy = at.direction.y * out;
|
|
855
|
+
if (dx === 0 && dy === 0) return;
|
|
856
|
+
const backX = point.x - dx * size;
|
|
857
|
+
const backY = point.y - dy * size;
|
|
858
|
+
const half = size * ARROW_SPREAD;
|
|
859
|
+
const path = [
|
|
860
|
+
{
|
|
861
|
+
kind: "move",
|
|
862
|
+
to: {
|
|
863
|
+
x: backX - dy * half,
|
|
864
|
+
y: backY + dx * half
|
|
865
|
+
}
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
kind: "line",
|
|
869
|
+
to: point
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
kind: "line",
|
|
873
|
+
to: {
|
|
874
|
+
x: backX + dy * half,
|
|
875
|
+
y: backY - dx * half
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
];
|
|
879
|
+
shapes.push({
|
|
880
|
+
type: "shape",
|
|
881
|
+
outline: {
|
|
882
|
+
kind: "path",
|
|
883
|
+
path
|
|
884
|
+
},
|
|
885
|
+
stroke,
|
|
886
|
+
lineWidth,
|
|
887
|
+
opacity
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
/** This function adds the shapes of a route: its line, and the signs at its ends. */
|
|
891
|
+
function addRoute(shapes, route, look, unit, share) {
|
|
892
|
+
const opacity = Math.min(1, (look.opacity ?? 1) * share);
|
|
893
|
+
if (!(opacity > 0)) return;
|
|
894
|
+
const lineWidth = (look.width ?? 1.25) * unit;
|
|
895
|
+
shapes.push({
|
|
896
|
+
type: "shape",
|
|
897
|
+
outline: {
|
|
898
|
+
kind: "path",
|
|
899
|
+
path: route.path
|
|
900
|
+
},
|
|
901
|
+
stroke: look.stroke,
|
|
902
|
+
lineWidth,
|
|
903
|
+
dash: dashOf(look.dash, unit),
|
|
904
|
+
opacity
|
|
905
|
+
});
|
|
906
|
+
if (look.start !== void 0) addEnd(shapes, pathStart(route.path), -1, look.start, look.stroke, lineWidth, unit, opacity);
|
|
907
|
+
if (look.end !== void 0) addEnd(shapes, pathEnd(route.path), 1, look.end, look.stroke, lineWidth, unit, opacity);
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* This function gives the paint list of a picture: the shapes that a renderer draws, in the order of the paint.
|
|
911
|
+
* The function is pure, so a test examines a picture with no browser. `drawShapes` draws the list on a canvas.
|
|
912
|
+
*
|
|
913
|
+
* The layers are, from the back:
|
|
914
|
+
*
|
|
915
|
+
* - The boxes with children, each with its labels.
|
|
916
|
+
* - The routes. The routes of the focus and those with a highlight are after the others.
|
|
917
|
+
* - The boxes with no child, each with its labels.
|
|
918
|
+
* - The labels of the routes, then the labels that name no record.
|
|
919
|
+
*
|
|
920
|
+
* In a layer, the records are in the order of the picture. A label has the state of the record that it names.
|
|
921
|
+
* The focus of the picture decreases the color of each record out of it (`FOCUS_OPACITY`).
|
|
922
|
+
*/
|
|
923
|
+
function paintPicture(index, looks, theme, state) {
|
|
924
|
+
const { picture } = index;
|
|
925
|
+
const unit = lookUnit(state.zoom);
|
|
926
|
+
const margin = 24 * unit;
|
|
927
|
+
const { visible, measure } = state;
|
|
928
|
+
const inView = (rect) => {
|
|
929
|
+
if (visible === void 0) return true;
|
|
930
|
+
const overlap = overlapOf(grow(rect, margin), visible);
|
|
931
|
+
return overlap.x >= 0 && overlap.y >= 0;
|
|
932
|
+
};
|
|
933
|
+
const shareOf = (key, level) => {
|
|
934
|
+
const goal = FOCUS_OPACITY[level];
|
|
935
|
+
return state.fade === void 0 ? goal : state.fade(key, goal);
|
|
936
|
+
};
|
|
937
|
+
const containers = [];
|
|
938
|
+
const leaves = [];
|
|
939
|
+
for (const box of picture.boxes) {
|
|
940
|
+
const labels = index.boxLabels.get(box.id) ?? [];
|
|
941
|
+
const shown = inView(box);
|
|
942
|
+
if (!shown && !labels.some(inView)) continue;
|
|
943
|
+
const boxIs = boxState(index, box, state);
|
|
944
|
+
const look = looks.box(box, boxIs, theme);
|
|
945
|
+
if (look === void 0) continue;
|
|
946
|
+
const share = shareOf(recordKey("box", box.id), boxIs.focus);
|
|
947
|
+
const shapes = boxIs.container ? containers : leaves;
|
|
948
|
+
if (shown) addBox(shapes, box, look, unit, share);
|
|
949
|
+
const record = {
|
|
950
|
+
type: "box",
|
|
951
|
+
id: box.id,
|
|
952
|
+
box
|
|
953
|
+
};
|
|
954
|
+
for (const label of labels) if (inView(label)) addLabel(shapes, label, looks.label(label, boxIs, theme, record), share, measure);
|
|
955
|
+
}
|
|
956
|
+
const back = [];
|
|
957
|
+
const front = [];
|
|
958
|
+
const routeLabels = [];
|
|
959
|
+
for (const route of picture.routes) {
|
|
960
|
+
const line = routeLine(route);
|
|
961
|
+
if (line === void 0) continue;
|
|
962
|
+
const labels = index.routeLabels.get(route.id) ?? [];
|
|
963
|
+
const shown = inView(line.bounds);
|
|
964
|
+
if (!shown && !labels.some(inView)) continue;
|
|
965
|
+
const routeIs = routeState(route, state);
|
|
966
|
+
const look = looks.route(route, routeIs, theme);
|
|
967
|
+
if (look === void 0) continue;
|
|
968
|
+
const share = shareOf(recordKey("route", route.id), routeIs.focus);
|
|
969
|
+
if (shown) addRoute(routeIs.focus === "in" || routeIs.highlight > 0 ? front : back, route, look, unit, share);
|
|
970
|
+
const record = {
|
|
971
|
+
type: "route",
|
|
972
|
+
id: route.id,
|
|
973
|
+
route
|
|
974
|
+
};
|
|
975
|
+
for (const label of labels) if (inView(label)) addLabel(routeLabels, label, looks.label(label, routeIs, theme, record), share, measure);
|
|
976
|
+
}
|
|
977
|
+
const free = [];
|
|
978
|
+
if (index.freeLabels.length > 0) {
|
|
979
|
+
const level = state.focus === void 0 ? "all" : "out";
|
|
980
|
+
const labelIs = {
|
|
981
|
+
highlight: 0,
|
|
982
|
+
focus: level,
|
|
983
|
+
zoom: state.zoom,
|
|
984
|
+
container: false
|
|
985
|
+
};
|
|
986
|
+
const share = shareOf(FREE_LABELS, level);
|
|
987
|
+
for (const label of index.freeLabels) if (inView(label)) addLabel(free, label, looks.label(label, labelIs, theme, void 0), share, measure);
|
|
988
|
+
}
|
|
989
|
+
return containers.concat(back, front, leaves, routeLabels, free);
|
|
990
|
+
}
|
|
991
|
+
// src/graph/content.ts
|
|
992
|
+
/** The time in which the color of a record goes most of the way to its goal after a change of the focus, in seconds. */
|
|
993
|
+
const FOCUS_FADE = .08;
|
|
994
|
+
/** The bounds of a picture with no record. */
|
|
995
|
+
const NO_BOUNDS = {
|
|
996
|
+
x: 0,
|
|
997
|
+
y: 0,
|
|
998
|
+
w: 0,
|
|
999
|
+
h: 0
|
|
1000
|
+
};
|
|
1001
|
+
/** The largest number of text widths that a content keeps. */
|
|
1002
|
+
const MOST_WIDTHS = 4e3;
|
|
1003
|
+
const NO_SEEDS = [];
|
|
1004
|
+
const boxesOnly = (record) => record.type === "box";
|
|
1005
|
+
/**
|
|
1006
|
+
* This function makes the content of a flat stage from a picture: its boxes, its routes and its labels.
|
|
1007
|
+
*
|
|
1008
|
+
* - The looks give the colors, the lines and the signs of each record from its state.
|
|
1009
|
+
* - A person points at the top box below the pointer, or at a route that the option `picks` permits.
|
|
1010
|
+
* - A change of the focus changes the colors in a short time.
|
|
1011
|
+
* - The content makes shapes only for the records in view.
|
|
1012
|
+
*
|
|
1013
|
+
* The picture must be good (`checkPicture` of `@mark1russell7/layout-contract`). The content does not change it.
|
|
1014
|
+
*/
|
|
1015
|
+
function createPictureContent(picture, options) {
|
|
1016
|
+
const { looks } = options;
|
|
1017
|
+
const permits = options.picks ?? boxesOnly;
|
|
1018
|
+
const bySelection = (options.focus ?? "selection") === "selection";
|
|
1019
|
+
let index = indexPicture(picture);
|
|
1020
|
+
let bounds = pictureBounds(picture) ?? NO_BOUNDS;
|
|
1021
|
+
/** The records of `setFocus`, or `undefined` for the focus of the options. */
|
|
1022
|
+
let asked;
|
|
1023
|
+
/** The names from which the focus of the last picture came. */
|
|
1024
|
+
let seeds = NO_SEEDS;
|
|
1025
|
+
let focus;
|
|
1026
|
+
/** This value is true until the first picture of a picture. The first focus has no change with time. */
|
|
1027
|
+
let fresh = true;
|
|
1028
|
+
/** The color share of each record whose share changes, by the key of the record. */
|
|
1029
|
+
const fades = /* @__PURE__ */ new Map();
|
|
1030
|
+
/** The theme and the state of the last picture. A person cannot point at a record that the last picture did not show. */
|
|
1031
|
+
let last;
|
|
1032
|
+
/** The width of each text that the content measured, by its font and its text. */
|
|
1033
|
+
const widths = /* @__PURE__ */ new Map();
|
|
1034
|
+
const widthOf = (context, font, text) => {
|
|
1035
|
+
const key = `${font}\n${text}`;
|
|
1036
|
+
const known = widths.get(key);
|
|
1037
|
+
if (known !== void 0) return known;
|
|
1038
|
+
const before = context.font;
|
|
1039
|
+
context.font = font;
|
|
1040
|
+
const width = context.measureText(text).width;
|
|
1041
|
+
context.font = before;
|
|
1042
|
+
if (widths.size >= MOST_WIDTHS) widths.clear();
|
|
1043
|
+
widths.set(key, width);
|
|
1044
|
+
return width;
|
|
1045
|
+
};
|
|
1046
|
+
/** This function gives the names from which the focus comes. */
|
|
1047
|
+
const seedsOf = (highlight) => {
|
|
1048
|
+
if (asked !== void 0) return asked;
|
|
1049
|
+
if (!bySelection) return NO_SEEDS;
|
|
1050
|
+
const out = [];
|
|
1051
|
+
for (const id of index.boxes.keys()) if (highlight(id) === 2) out.push(id);
|
|
1052
|
+
for (const id of index.routes.keys()) if (!index.boxes.has(id) && highlight(id) === 2) out.push(id);
|
|
1053
|
+
return out;
|
|
1054
|
+
};
|
|
1055
|
+
/** This function starts the change of the color of each record whose focus level changes. A change that continues starts from its value. */
|
|
1056
|
+
const fadeTo = (next) => {
|
|
1057
|
+
const add = (key, from, goal) => {
|
|
1058
|
+
const value = fades.get(key)?.value ?? from;
|
|
1059
|
+
if (value === goal) fades.delete(key);
|
|
1060
|
+
else fades.set(key, {
|
|
1061
|
+
value,
|
|
1062
|
+
goal
|
|
1063
|
+
});
|
|
1064
|
+
};
|
|
1065
|
+
for (const box of index.picture.boxes) add(recordKey("box", box.id), FOCUS_OPACITY[boxFocus(focus, box)], FOCUS_OPACITY[boxFocus(next, box)]);
|
|
1066
|
+
for (const route of index.picture.routes) add(recordKey("route", route.id), FOCUS_OPACITY[routeFocus(focus, route)], FOCUS_OPACITY[routeFocus(next, route)]);
|
|
1067
|
+
if (index.freeLabels.length > 0) add(FREE_LABELS, FOCUS_OPACITY[focus === void 0 ? "all" : "out"], FOCUS_OPACITY[next === void 0 ? "all" : "out"]);
|
|
1068
|
+
};
|
|
1069
|
+
return {
|
|
1070
|
+
get bounds() {
|
|
1071
|
+
return bounds;
|
|
1072
|
+
},
|
|
1073
|
+
has: (record) => index.boxes.has(record) || index.routes.has(record),
|
|
1074
|
+
pick(at) {
|
|
1075
|
+
const known = last;
|
|
1076
|
+
const state = known === void 0 ? void 0 : {
|
|
1077
|
+
...known.state,
|
|
1078
|
+
zoom: at.view.k
|
|
1079
|
+
};
|
|
1080
|
+
const shown = (record) => {
|
|
1081
|
+
if (!permits(record)) return false;
|
|
1082
|
+
if (known === void 0 || state === void 0) return true;
|
|
1083
|
+
if (record.type === "box") return looks.box(record.box, boxState(index, record.box, state), known.theme) !== void 0;
|
|
1084
|
+
return looks.route(record.route, routeState(record.route, state), known.theme) !== void 0;
|
|
1085
|
+
};
|
|
1086
|
+
const record = pickRecord(index, at.point, {
|
|
1087
|
+
slack: at.slack / at.view.k,
|
|
1088
|
+
picks: shown
|
|
1089
|
+
});
|
|
1090
|
+
return record === void 0 ? void 0 : {
|
|
1091
|
+
record: record.id,
|
|
1092
|
+
value: record
|
|
1093
|
+
};
|
|
1094
|
+
},
|
|
1095
|
+
draw(context, frame, theme, highlight) {
|
|
1096
|
+
const { view } = frame;
|
|
1097
|
+
const from = seedsOf(highlight);
|
|
1098
|
+
if (fresh || from.length !== seeds.length || from.some((id, i) => id !== seeds[i])) {
|
|
1099
|
+
const next = from.length === 0 ? void 0 : focusOf(index, from);
|
|
1100
|
+
if (fresh || frame.settle) fades.clear();
|
|
1101
|
+
else fadeTo(next);
|
|
1102
|
+
seeds = from;
|
|
1103
|
+
focus = next;
|
|
1104
|
+
fresh = false;
|
|
1105
|
+
}
|
|
1106
|
+
if (frame.settle) fades.clear();
|
|
1107
|
+
for (const [key, fade] of fades) {
|
|
1108
|
+
fade.value = approach(fade.value, fade.goal, frame.seconds, FOCUS_FADE);
|
|
1109
|
+
if (fade.value === fade.goal) fades.delete(key);
|
|
1110
|
+
}
|
|
1111
|
+
const state = {
|
|
1112
|
+
zoom: view.k,
|
|
1113
|
+
highlight,
|
|
1114
|
+
focus,
|
|
1115
|
+
visible: {
|
|
1116
|
+
x: (0 - view.x) / view.k,
|
|
1117
|
+
y: (0 - view.y) / view.k,
|
|
1118
|
+
w: frame.width / view.k,
|
|
1119
|
+
h: frame.height / view.k
|
|
1120
|
+
},
|
|
1121
|
+
measure: (font, text) => widthOf(context, font, text),
|
|
1122
|
+
fade: fades.size === 0 ? void 0 : (key, goal) => fades.get(key)?.value ?? goal
|
|
1123
|
+
};
|
|
1124
|
+
last = {
|
|
1125
|
+
theme,
|
|
1126
|
+
state
|
|
1127
|
+
};
|
|
1128
|
+
drawShapes(context, paintPicture(index, looks, theme, state), view);
|
|
1129
|
+
return fades.size > 0;
|
|
1130
|
+
},
|
|
1131
|
+
setPicture(next) {
|
|
1132
|
+
index = indexPicture(next);
|
|
1133
|
+
bounds = pictureBounds(next) ?? NO_BOUNDS;
|
|
1134
|
+
fades.clear();
|
|
1135
|
+
fresh = true;
|
|
1136
|
+
last = void 0;
|
|
1137
|
+
},
|
|
1138
|
+
setFocus(records) {
|
|
1139
|
+
asked = records === void 0 ? void 0 : [...records];
|
|
1140
|
+
},
|
|
1141
|
+
dispose() {
|
|
1142
|
+
fades.clear();
|
|
1143
|
+
widths.clear();
|
|
1144
|
+
last = void 0;
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
296
1148
|
// src/graph/keys.ts
|
|
297
1149
|
/**
|
|
298
1150
|
* This function gives the action of a key on a flat picture, or `undefined` for a key with no action.
|
|
@@ -304,7 +1156,7 @@ function aimReveal(rects, options) {
|
|
|
304
1156
|
*/
|
|
305
1157
|
function pictureKeyAction(key, now, area, options) {
|
|
306
1158
|
const step = Math.min(area.w, area.h) * KEY_PART;
|
|
307
|
-
const middle =
|
|
1159
|
+
const middle = rectCenter(area);
|
|
308
1160
|
switch (key) {
|
|
309
1161
|
case "ArrowLeft": return {
|
|
310
1162
|
type: "move",
|
|
@@ -554,13 +1406,16 @@ function createPictureStage(container, options) {
|
|
|
554
1406
|
const setCursor = () => {
|
|
555
1407
|
canvas.style.cursor = dragging ? "grabbing" : highlights.hovered === void 0 ? "grab" : "pointer";
|
|
556
1408
|
};
|
|
1409
|
+
/** The bounds of the content at the last `setArea`. `refresh` finds a change of the bounds with them. */
|
|
1410
|
+
let fitted = content.bounds;
|
|
557
1411
|
/** This function sets the free area and the limits of the zoom, from the size, the insets and the content. */
|
|
558
1412
|
const setArea = () => {
|
|
559
1413
|
area = freeArea({
|
|
560
1414
|
width,
|
|
561
1415
|
height
|
|
562
1416
|
}, insets);
|
|
563
|
-
|
|
1417
|
+
fitted = content.bounds;
|
|
1418
|
+
limits = zoomLimitsFor(fitted, area, baseLimits);
|
|
564
1419
|
};
|
|
565
1420
|
const aimFrame = () => ({
|
|
566
1421
|
bounds: content.bounds,
|
|
@@ -595,7 +1450,7 @@ function createPictureStage(container, options) {
|
|
|
595
1450
|
*/
|
|
596
1451
|
const hold = (base) => {
|
|
597
1452
|
const k = clampZoom(base.k, limits);
|
|
598
|
-
const middle =
|
|
1453
|
+
const middle = rectCenter(area);
|
|
599
1454
|
move = void 0;
|
|
600
1455
|
view = keepRect(k === base.k ? base : viewAt(toPicture(base, middle), middle, k), content.bounds, area);
|
|
601
1456
|
invalidate();
|
|
@@ -633,7 +1488,7 @@ function createPictureStage(container, options) {
|
|
|
633
1488
|
return;
|
|
634
1489
|
}
|
|
635
1490
|
const base = move?.to ?? view;
|
|
636
|
-
hold(viewAt(toPicture(base,
|
|
1491
|
+
hold(viewAt(toPicture(base, rectCenter(before)), rectCenter(area), base.k));
|
|
637
1492
|
};
|
|
638
1493
|
function tick(now) {
|
|
639
1494
|
frame = 0;
|
|
@@ -822,7 +1677,7 @@ function createPictureStage(container, options) {
|
|
|
822
1677
|
area: () => area,
|
|
823
1678
|
zoomBy(factor, animate = true) {
|
|
824
1679
|
moved = true;
|
|
825
|
-
glide(keepRect(zoomView(move?.to ?? view,
|
|
1680
|
+
glide(keepRect(zoomView(move?.to ?? view, rectCenter(area), factor, limits), content.bounds, area), animate);
|
|
826
1681
|
},
|
|
827
1682
|
highlight(records) {
|
|
828
1683
|
highlights = {
|
|
@@ -838,7 +1693,19 @@ function createPictureStage(container, options) {
|
|
|
838
1693
|
};
|
|
839
1694
|
invalidate();
|
|
840
1695
|
},
|
|
841
|
-
refresh
|
|
1696
|
+
refresh() {
|
|
1697
|
+
if (disposed) return;
|
|
1698
|
+
if (highlights.hovered !== void 0 && !content.has(highlights.hovered)) setHover(void 0);
|
|
1699
|
+
const bounds = content.bounds;
|
|
1700
|
+
if (bounds.x !== fitted.x || bounds.y !== fitted.y || bounds.w !== fitted.w || bounds.h !== fitted.h) {
|
|
1701
|
+
setArea();
|
|
1702
|
+
if (sized) {
|
|
1703
|
+
if (moved) hold(move?.to ?? view);
|
|
1704
|
+
else goTo(aim, true);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
invalidate();
|
|
1708
|
+
},
|
|
842
1709
|
dispose() {
|
|
843
1710
|
if (disposed) return;
|
|
844
1711
|
disposed = true;
|
|
@@ -850,6 +1717,6 @@ function createPictureStage(container, options) {
|
|
|
850
1717
|
}
|
|
851
1718
|
};
|
|
852
1719
|
}
|
|
853
|
-
export { DOUBLE_CLICK_ZOOM, FIT_PADDING, KEEP_IN_VIEW, NO_POINTERS, PICK_SLACK, SMALLEST_AREA, TOUCH_CLICK_DISTANCE, TOUCH_PICK_SLACK, UNIT_VIEW, WHEEL_LINE, WHEEL_PINCH, WHEEL_SPEED, ZOOM_LIMITS, aimAll, aimRects, aimReveal, clampZoom, createPictureStage, fitRect, frameRects, freeArea, keepRect, panView, pictureKeyAction, pictureMoveAt, pinchView, pointerCancel, pointerDown, pointerMove, pointerUp, rectToScreen, revealRects, showsRect, stackPictureContents, toPicture, toScreen, viewAt, viewBetween, wheelFactor, zoomLimitsFor, zoomView };
|
|
1720
|
+
export { ARROW_SPREAD, BAR_HEIGHT, DARK_PICTURE_THEME, DOUBLE_CLICK_ZOOM, FIT_PADDING, FOCUS_FADE, FOCUS_OPACITY, FREE_LABELS, HALO_WIDTH, KEEP_IN_VIEW, LIGHT_PICTURE_THEME, NO_POINTERS, PICK_SLACK, SMALLEST_AREA, SMALLEST_BAR_LINE, SMALLEST_TEXT_LINE, TOUCH_CLICK_DISTANCE, TOUCH_PICK_SLACK, UNIT_VIEW, VIEW_MARGIN, WHEEL_LINE, WHEEL_PINCH, WHEEL_SPEED, ZOOM_LIMITS, aimAll, aimRects, aimReveal, boxDistance, boxFocus, boxState, clampZoom, createPictureContent, createPictureStage, drawShapes, fitRect, focusOf, frameRects, freeArea, indexPicture, keepRect, lookUnit, paintPicture, panView, pickRecord, pictureKeyAction, pictureMoveAt, pinchView, plainLooks, pointerCancel, pointerDown, pointerMove, pointerUp, recordKey, rectToScreen, revealRects, routeFocus, routeLine, routeState, showsRect, stackPictureContents, toPicture, toScreen, viewAt, viewBetween, wheelFactor, zoomLimitsFor, zoomView };
|
|
854
1721
|
|
|
855
1722
|
//# sourceMappingURL=graph.js.map
|