@graview/pages 0.2.1 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"one-place-city.d.ts","sourceRoot":"","sources":["../src/one-place-city.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAmY,KAAK,SAAS,EAAc,MAAM,yBAAyB,CAAC;AACtc,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAwFxD,iGAAiG;AACjG,eAAO,MAAM,OAAO,MAAM,CAAC;AA6C3B,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,iBAAiB,+BAqrD1M;AAED,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,2IAA2I;AAC3I,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAI1D"}
1
+ {"version":3,"file":"one-place-city.d.ts","sourceRoot":"","sources":["../src/one-place-city.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAmY,KAAK,SAAS,EAAc,MAAM,yBAAyB,CAAC;AACtc,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAsGxD,iGAAiG;AACjG,eAAO,MAAM,OAAO,MAAM,CAAC;AA6C3B,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,iBAAiB,+BAkxD1M;AAED,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,2IAA2I;AAC3I,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAI1D"}
@@ -87,6 +87,20 @@ const zoomNowOf = (cam) => cam.zoom().toFixed(4);
87
87
  const MOST_LINES = 40;
88
88
  /** As many lines into one district as this, and they are one line into it with their count on it. */
89
89
  const GATHER = 4;
90
+ /** How far inside a phone's sheet a line goes up its side to the top edge: in the sheet's own margin, clear of its words. */
91
+ const SHEET_SIDE = 6;
92
+ /**
93
+ * The furthest from its row a line in a view runs along a gap. The page
94
+ * cannot read a view's words, so this is a guess at a row's own spacing (a
95
+ * pill's margin): words set closer under a row than this are crossed.
96
+ */
97
+ const FRAMED_GAP = 4;
98
+ /** And on a phone's page: a group's label stands a few pixels over its row of pills, and a line along the gap over the row passes under its words. */
99
+ const PHONE_GAP = 2.5;
100
+ /** How far inside the city's side the home keeps its views' districts while bringing the city to the middle: a district's edge never on the window's or the sheet's. */
101
+ const HOME_EDGE = 8;
102
+ /** How far from its own district a name may stand beside a page, edge to edge: a name's height and a little air. Past it, a name reads as another district's. */
103
+ const NAME_REACH = 32;
90
104
  /** What a district's "+n" is kept under among the picture's buildings: never a record's id. */
91
105
  const REST_KEY = "\u0000rest:";
92
106
  /** How long one level's move takes. A person who asked for less motion is cut straight there. */
@@ -517,6 +531,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
517
531
  key: board.key,
518
532
  kind: board.where.type === "record" ? board.where.kind : signKindOf(board.where),
519
533
  building: board.where.type === "record" && w.buildings.has(board.where.id) ? onScreen(w.buildings.get(board.where.id)) : null,
534
+ // Beside a page, where the city's side is narrow, the app's views stand before the kinds' own lists: a view whose district is in sight keeps its board. Under the page too, so a move from it to Nearby carries each board from a place in the same order, never a leap halfway.
535
+ first: lvl !== CITY && board.where.type === "place",
520
536
  }));
521
537
  const reserved = footNow().now.map((box) => ({ x: box.x - 6, y: box.y - 6, width: box.width + 12, height: box.height + 12 }));
522
538
  const round = (n) => Math.round(n / 2) * 2;
@@ -552,6 +568,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
552
568
  ...(lvl === PANEL ? { least: boardLeast(view) } : {}),
553
569
  // Beside the page the plaza is behind the city: only the views that stand on a district stand there.
554
570
  plaza: lvl !== PANEL,
571
+ // Beside a page (and under it, so a move to Nearby carries each name from a place found the same way) each district's name stands right after the views, before the kinds' lists, and beside its own district or nowhere.
572
+ ...(lvl !== CITY ? { namesFirst: true, nameReach: NAME_REACH } : {}),
555
573
  });
556
574
  kept = { key, origin, placed };
557
575
  }
@@ -703,15 +721,21 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
703
721
  return plot ? [plot] : [];
704
722
  }));
705
723
  const what = own ?? city;
724
+ /*
725
+ * THE CITY AS NEAR THE MIDDLE OF ITS SIDE AS ITS VIEWS' DISTRICTS
726
+ * LET IT, they in the side whole: at the zoom that fits them where
727
+ * they fit on their own (a small phone's strip over the sheet), else
728
+ * as far out as the camera goes. Fitted on them alone, the city stood
729
+ * off to one side of a narrow strip with room to come to its middle.
730
+ */
706
731
  const close = fitCamera(what, shown, 16, s);
707
- if (close.s >= least)
708
- return close;
709
- // As far out as the camera goes: the city as near the middle of its side as its views' districts let it, they in the side whole.
710
- const held = cameraPutting(middle(city), middle(shown), least);
732
+ const held = cameraPutting(middle(city), middle(shown), Math.max(close.s, least));
711
733
  const lo = project(held, { x: what.x, y: what.y });
712
734
  const hi = project(held, { x: what.x + what.width, y: what.y + what.height });
713
735
  const shift = (low, high, from, to) => (low < from ? from - low : high > to ? to - high : 0);
714
- return { s: held.s, x: held.x + shift(lo.x, hi.x, shown.x, shown.x + shown.width), y: held.y + shift(lo.y, hi.y, shown.y, shown.y + shown.height) };
736
+ // Kept a little off the side's edge, as the fit is: never so far in that the city could come nearer the middle than it does.
737
+ const keep = HOME_EDGE;
738
+ return { s: held.s, x: held.x + shift(lo.x, hi.x, shown.x + keep, shown.x + shown.width - keep), y: held.y + shift(lo.y, hi.y, shown.y + keep, shown.y + shown.height - keep) };
715
739
  }
716
740
  }
717
741
  if (lvl === CITY || now.where.type === "home" || now.where.type === "overview") {
@@ -1334,7 +1358,8 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1334
1358
  const asked = [];
1335
1359
  /** Every part's box on the page in sight: what a line inside the page goes round. */
1336
1360
  const words = [];
1337
- const offer = (target, part, visible, partBox) => {
1361
+ // `framed`: drawn by a view (a worker view, a frame), whose words between its records the page cannot read.
1362
+ const offer = (target, part, visible, partBox, framed = false) => {
1338
1363
  const key = target.type === "record" ? target.id : `kind:${target.kind}`;
1339
1364
  // Only what is in sight on the page: a part scrolled past, or under the page's own edge, draws none.
1340
1365
  if (part.x < visible.left || part.x > visible.right || part.y < visible.top || part.y > visible.bottom)
@@ -1347,7 +1372,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1347
1372
  if (!end)
1348
1373
  return;
1349
1374
  taken.add(key);
1350
- asked.push({ key, target, part, box: partBox, visible, end });
1375
+ asked.push({ key, target, part, box: partBox, visible, end, framed });
1351
1376
  };
1352
1377
  /* The record page drawn by a view that names no other record: where its one line to the record leaves from. */
1353
1378
  let aboutPart = null;
@@ -1384,7 +1409,7 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1384
1409
  continue;
1385
1410
  }
1386
1411
  named = true;
1387
- offer({ type: "record", id: box.id }, part, visible, partBox);
1412
+ offer({ type: "record", id: box.id }, part, visible, partBox, true);
1388
1413
  }
1389
1414
  if (!named && subjectId !== null && aboutPart === null) {
1390
1415
  // From the middle of what is in sight of it, or the record's own part where it drew one.
@@ -1424,47 +1449,127 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1424
1449
  * into the gap above or below its row — the one toward where it is
1425
1450
  * going first — runs along it to the edge, and goes on from there.
1426
1451
  * Lines along one gap stand a pixel or two apart.
1452
+ *
1453
+ * ON A PHONE THE SAME, toward the sheet's top edge: along the gap to
1454
+ * the sheet's side, clear of its words, and up that side to the top —
1455
+ * never straight up across the rows above.
1456
+ *
1457
+ * IN A VIEW (a worker view, a frame) the page cannot read the words
1458
+ * between its records: the middle of a gap between two rows may be a
1459
+ * paragraph (Graview Cloud's Family tree, where the lines from a pill
1460
+ * row rose into the paragraph above it and drew a box through it). A
1461
+ * line there takes the gap below its row first, and keeps to its
1462
+ * row's own edge — never further from it than the rows' own spacing —
1463
+ * so it never runs along a gap that holds words. On a phone it never
1464
+ * goes straight up through them either.
1427
1465
  */
1428
1466
  const hits = (a, b, own) => words.some((o) => o !== own && Math.max(a.x, b.x) > o.x + 1 && Math.min(a.x, b.x) < o.x + o.width - 1 && Math.max(a.y, b.y) > o.y + 1 && Math.min(a.y, b.y) < o.y + o.height - 1);
1429
1467
  const edgeX = pageRect.x;
1468
+ /** Something standing on the sheet's top edge there (the control riding on it): a line up that side would leave the edge somewhere else. */
1469
+ const standsOnTheEdge = (x) => reserved.some((box) => x >= box.x - 3 && x <= box.x + box.width + 3 && box.y + box.height >= pageRect.y - 43 && box.y - 3 <= pageRect.y);
1470
+ const districtOf = (target) => (target.type === "record" ? (store.graph.getNode(target.id)?.kind ?? null) : target.kind);
1471
+ /*
1472
+ * ON A PHONE, ONE RISER A DISTRICT (Graview Cloud's Deep Time, the
1473
+ * Cretaceous at 390: each row's line rose up the sheet's edge on its
1474
+ * own, ten verticals side by side). Every line into one district runs
1475
+ * along its row to the same place in the sheet's margin and goes up
1476
+ * as one. The district whose lines start lowest goes up outermost, so
1477
+ * no run along a row above crosses another district's riser.
1478
+ */
1479
+ const risers = new Map();
1480
+ if (phone) {
1481
+ const right = pageRect.x + pageRect.width;
1482
+ const onRight = !standsOnTheEdge(right - SHEET_SIDE) || standsOnTheEdge(pageRect.x + SHEET_SIDE);
1483
+ const lowest = new Map();
1484
+ for (const one of asked) {
1485
+ const kind = districtOf(one.target);
1486
+ if (kind)
1487
+ lowest.set(kind, Math.max(lowest.get(kind) ?? -Infinity, one.part.y));
1488
+ }
1489
+ const order = [...lowest.keys()].sort((p, q) => lowest.get(q) - lowest.get(p));
1490
+ const apart = order.length > 1 ? Math.min(3, (2 * SHEET_SIDE - 2) / (order.length - 1)) : 0;
1491
+ order.forEach((kind, rank) => risers.set(kind, onRight ? right - 2 - rank * apart : pageRect.x + 2 + rank * apart));
1492
+ }
1430
1493
  const wayIn = (one) => {
1431
1494
  const b = one.box;
1432
1495
  const from = leaveFrom(one.part, pageRect, phone);
1433
1496
  const straight = phone ? { x: one.part.x, y: Math.max(b.y, one.visible.top, from.y) } : { x: Math.max(b.x, one.visible.left, from.x), y: one.part.y };
1434
- if (phone || !hits(straight, from, b))
1435
- return { via: [straight, from], gap: null };
1436
- const beside = words.filter((o) => o !== b && o.x < b.x + b.width && o.x + o.width > edgeX);
1437
- const above = beside.filter((o) => o.y + o.height <= b.y + 1).reduce((most, o) => Math.max(most, o.y + o.height), -Infinity);
1438
- const below = beside.filter((o) => o.y >= b.y + b.height - 1).reduce((least, o) => Math.min(least, o.y), Infinity);
1439
- const gaps = [
1440
- { y: Number.isFinite(above) ? (above + b.y) / 2 : b.y - 4, leave: b.y },
1441
- { y: Number.isFinite(below) ? (b.y + b.height + below) / 2 : b.y + b.height + 4, leave: b.y + b.height },
1442
- ].filter((g) => g.y > one.visible.top && g.y < one.visible.bottom);
1443
- // Toward where it is going first: up for a building above the part, down for one below.
1444
- if (one.end.at.y > one.part.y)
1445
- gaps.reverse();
1497
+ const plain = { via: [straight, from], gap: null };
1498
+ // On a phone never straight up: the page's own words over a row (a group's label, a heading) are not parts it can go round.
1499
+ if (!phone && !hits(straight, from, b))
1500
+ return plain;
1501
+ // The row it stands in: every part level with it and of a row's size, never a view's whole box.
1502
+ const level = words.filter((o) => o !== b && o.height <= b.height * 2 + 8 && o.y < b.y + b.height - 1 && o.y + o.height > b.y + 1);
1503
+ const rowTop = Math.min(b.y, ...level.map((o) => o.y));
1504
+ const rowBottom = Math.max(b.y + b.height, ...level.map((o) => o.y + o.height));
1446
1505
  const x = b.x + Math.min(10, b.width / 2);
1447
- for (const gap of gaps) {
1448
- const leave = { x, y: gap.leave };
1449
- const down = { x, y: gap.y };
1450
- const out = { x: edgeX, y: gap.y };
1451
- if (!hits(leave, down, b) && !hits(down, out, b))
1452
- return { via: [leave, down, out], gap: Math.round(gap.y) };
1506
+ const kind = districtOf(one.target);
1507
+ const ends = phone ? [(kind !== null ? risers.get(kind) : undefined) ?? pageRect.x + pageRect.width - 2] : [edgeX];
1508
+ for (const end of ends) {
1509
+ // What stands across the way along the gap: between the part and the edge it runs to.
1510
+ const lo = Math.min(end, b.x);
1511
+ const hi = Math.max(end, b.x + b.width);
1512
+ const beside = words.filter((o) => o !== b && o.x < hi && o.x + o.width > lo);
1513
+ const above = beside.filter((o) => o.y + o.height <= rowTop + 1).reduce((most, o) => Math.max(most, o.y + o.height), -Infinity);
1514
+ const below = beside.filter((o) => o.y >= rowBottom - 1).reduce((least, o) => Math.min(least, o.y), Infinity);
1515
+ // In a view, and on a phone, no further from the row than its own spacing: what lies past that (a view's words, a group's label) the page does not go round.
1516
+ const off = (room) => (one.framed ? Math.min(Number.isFinite(room) ? room / 2 : FRAMED_GAP, FRAMED_GAP) : phone ? Math.min(Number.isFinite(room) ? room / 2 : PHONE_GAP, PHONE_GAP) : Number.isFinite(room) ? room / 2 : 4);
1517
+ const gaps = [
1518
+ { y: rowTop - off(rowTop - above), leave: b.y },
1519
+ { y: rowBottom + off(below - rowBottom), leave: b.y + b.height },
1520
+ ].filter((g) => g.y > one.visible.top && g.y < one.visible.bottom);
1521
+ // On a phone the gap above first, toward the sheet's top edge; in a view the gap below first; on a desk's page toward where it is going first — up for a building above the part, down for one below.
1522
+ if (one.framed || (!phone && one.end.at.y > one.part.y))
1523
+ gaps.reverse();
1524
+ const wayAlong = (gap) => {
1525
+ const leave = { x, y: gap.leave };
1526
+ const down = { x, y: gap.y };
1527
+ const out = { x: end, y: gap.y };
1528
+ return { via: phone ? [leave, down, out, { x: end, y: pageRect.y }] : [leave, down, out], gap: Math.round(gap.y) };
1529
+ };
1530
+ for (const gap of gaps) {
1531
+ const way = wayAlong(gap);
1532
+ if (!way.via.some((p, i) => i > 0 && hits(way.via[i - 1], p, b)))
1533
+ return way;
1534
+ }
1535
+ // A phone's line goes along its row's gap all the same: across a part there, never up across the words over it.
1536
+ if (phone && gaps.length > 0)
1537
+ return wayAlong(gaps[0]);
1453
1538
  }
1454
- return { via: [straight, from], gap: null };
1539
+ return plain;
1455
1540
  };
1456
1541
  const ways = asked.map(wayIn);
1457
- // Lines along one gap: a pixel and a half apart, about its middle.
1542
+ // Lines along one gap: a pixel and a half apart, about its middle. On a phone those into one district run along it as one, into their riser.
1458
1543
  const along = new Map();
1459
1544
  ways.forEach((way, at) => {
1460
- if (way.gap !== null)
1461
- along.set(way.gap, [...(along.get(way.gap) ?? []), at]);
1545
+ if (way.gap === null)
1546
+ return;
1547
+ const key = phone ? `${way.gap}|${districtOf(asked[at].target) ?? ""}` : String(way.gap);
1548
+ along.set(key, [...(along.get(key) ?? []), at]);
1462
1549
  });
1550
+ if (phone) {
1551
+ // One shift a district along a gap that several districts' lines share.
1552
+ const byGap = new Map();
1553
+ for (const key of along.keys()) {
1554
+ const [gap] = key.split("|");
1555
+ byGap.set(gap, [...(byGap.get(gap) ?? []), key]);
1556
+ }
1557
+ for (const keys of byGap.values()) {
1558
+ keys.forEach((key, nth) => {
1559
+ const shift = (nth - (keys.length - 1) / 2) * 1;
1560
+ for (const at of along.get(key)) {
1561
+ const via = ways[at].via;
1562
+ ways[at] = { ...ways[at], via: via.map((p, i) => (i === 0 || i === via.length - 1 ? p : { x: p.x, y: p.y + shift })) };
1563
+ }
1564
+ });
1565
+ }
1566
+ along.clear();
1567
+ }
1463
1568
  for (const ats of along.values()) {
1464
1569
  ats.forEach((at, nth) => {
1465
1570
  const shift = (nth - (ats.length - 1) / 2) * 1.5;
1466
1571
  const via = ways[at].via;
1467
- ways[at] = { ...ways[at], via: [via[0], ...via.slice(1).map((p) => ({ x: p.x, y: p.y + shift }))] };
1572
+ ways[at] = { ...ways[at], via: via.map((p, i) => (i === 0 ? p : { x: p.x, y: p.y + shift })) };
1468
1573
  });
1469
1574
  }
1470
1575
  asked.forEach((one, at) => {
@@ -1493,7 +1598,9 @@ export function OnePlaceCity({ where, out, sheet, connected, boards, current, bo
1493
1598
  if (!end)
1494
1599
  continue;
1495
1600
  const parts = ats.map((at) => found[at].part);
1496
- const meet = leaveFrom({ x: parts.reduce((sum, p) => sum + p.x, 0) / parts.length, y: parts.reduce((sum, p) => sum + p.y, 0) / parts.length }, pageRect, phone);
1601
+ // On a phone they meet where their riser reaches the sheet's top edge.
1602
+ const riser = phone ? risers.get(kind) : undefined;
1603
+ const meet = riser !== undefined ? { x: riser, y: pageRect.y } : leaveFrom({ x: parts.reduce((sum, p) => sum + p.x, 0) / parts.length, y: parts.reduce((sum, p) => sum + p.y, 0) / parts.length }, pageRect, phone);
1497
1604
  const route = routeLine(meet, end.at, area, phone, reserved);
1498
1605
  if (!route)
1499
1606
  continue;