From e32ebf2f2406bce812fb2150fd10f6cfb2668c0e Mon Sep 17 00:00:00 2001 From: Will Cook <46428721+wcook04@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:11:17 +0000 Subject: [PATCH 1/2] Make the graph follow the passage being read, and open the paper beside its graph and Lean On a paper with many results the graph only moved on a click, so it stayed on the main theorem while the Lean followed the reading. It now shows the declaration under the reading line with what it uses, under the result the paper states. Choosing a card or result holds the graph until the reader asks it to follow again. Also: a fresh visit opens with the graph above the Lean (beside it on very wide screens); a closed proof pane reopens on the next visit; a draggable divider between the paper and the proof, after the Quartic Reader; one line with a menu in place of a wall of result buttons; the caption names the statement followed; a lone card says why nothing is drawn beneath it. Co-Authored-By: Claude Fable 5.2 --- README.md | 13 +++- tests/journey.py | 103 ++++++++++++++++++++++++- web/src/app/app.css | 36 ++++++++- web/src/paper/PaperPage.tsx | 5 +- web/src/paper/PaperSplit.tsx | 141 +++++++++++++++++++++++++++++++++++ web/src/proof/MapPane.tsx | 82 ++++++++++++++++---- web/src/proof/NearMap.tsx | 27 +++++-- web/src/proof/ProofPage.tsx | 18 +++-- 8 files changed, 386 insertions(+), 39 deletions(-) create mode 100644 web/src/paper/PaperSplit.tsx diff --git a/README.md b/README.md index 1840d4e..10703b2 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,16 @@ remains at `#/pcp-reading-guide`. The algebraic proof is due to Amireddy, Behera, Srinivasan, Sudan and Willumsgaard; Lee wrote the Lean formalization. AI agents wrote the three explanations under Will Cook's direction. -On a desktop, the paper is on the left and the proof diagram is on the right. -As you scroll, the diagram highlights the step linked to the passage you are -reading. Click a statement or diagram card to see its Lean code. Use **Back** +On a desktop, each visit opens with the paper on the left and the proof pane on +the right: the graph above the Lean, or beside it on a very wide screen. Drag +the divider between the paper and the proof to give either side more room, and +the handle between the graph and the Lean to share the pane; both are +remembered. Closing the proof pane lasts for that visit. +As you scroll, the proof pane follows the linked passage you are reading: the +Lean shows its declaration, and the graph shows that declaration with what it +uses. Choosing another card or result holds the graph there until you choose +**Follow the paper again**. Click a statement or diagram +card to see its Lean code. Use **Back** to return to the diagram without losing your place, or the **Graph / Lean** toggle to choose what stays beside the paper. diff --git a/tests/journey.py b/tests/journey.py index 1272d5b..c7f28b0 100644 --- a/tests/journey.py +++ b/tests/journey.py @@ -106,8 +106,8 @@ def lean_open(page: Page) -> bool: GRAPH_FIRST = """ try { - if (!localStorage.getItem('proof-reader-pane-2')) - localStorage.setItem('proof-reader-pane-2', JSON.stringify({graph: true, lean: false, share: 0, sideShare: 0})); + if (!localStorage.getItem('proof-reader-pane-3')) + localStorage.setItem('proof-reader-pane-3', JSON.stringify({graph: true, lean: false, share: 0, sideShare: 0})); } catch { /* a frame with no storage, such as the PDF's: nothing to set there */ } """ @@ -146,6 +146,93 @@ def opening(page: Page, url: str) -> None: check(page.evaluate("location.hash") == hashes[0], "and stays in the address bar") +def reopen_proof(page: Page, url: str) -> None: + """A previously closed proof pane must not hide the split on later visits.""" + print("Reopening the proof pane") + page.goto(f"{url}#/{SLUG}", wait_until="load") + page.locator(".proof").wait_for() + page.evaluate("""localStorage.setItem('proof-reader-pane-3', JSON.stringify({ + graph: false, lean: false, share: 0.3, sideShare: 0.4 + }))""") + for slug in ("pcp-exposition", "pcp-specialist", "pcp-full-argument", "pcp-reading-guide", SLUG): + page.goto(f"{url}#/{slug}", wait_until="load") + page.locator(".proof").wait_for() + paper = page.locator(".left").bounding_box() + proof = page.locator(".proof").bounding_box() + check(paper is not None and proof is not None + and proof["x"] >= paper["x"] + paper["width"] - 1 + and abs(proof["y"] - paper["y"]) <= 1, + f"{slug} opens beside its proof despite a saved closed pane") + check(not lean_open(page), "the saved Graph mode is preserved") + page.locator(".proof").get_by_role("button", name="Close", exact=True).click() + page.locator(".proof").wait_for(state="hidden") + check(True, "Close still hides the proof for the current visit") + page.reload(wait_until="load") + page.locator(".proof").wait_for() + check(True, "reloading opens the proof pane again") + check(page.evaluate("""() => { + const layout = JSON.parse(localStorage.getItem('proof-reader-pane-3')); + return layout.share === 0.3 && layout.sideShare === 0.4 && layout.lean === false + && !Object.hasOwn(layout, 'graph'); + }"""), "mode and split sizes persist without a saved closed pane") + + +def graph_follows(page: Page, url: str, shots: Path | None) -> None: + """A paper with many results: the graph shows the statement being read, and the + divider between paper and proof moves, is remembered and can be put back.""" + print("The graph follows the reading") + page.goto(f"{url}#/pcp-exposition", wait_until="load") + page.locator(".nearmap__card.is-head").first.wait_for() + head = lambda: page.eval_on_selector_all(".nearmap__card.is-head .nearmap__title", "els => els.map(e => e.textContent)") + check(page.locator(".proof__graph").bounding_box()["height"] > 150 and lean_open(page), + "a fresh visit opens with the graph above the Lean") + check(page.locator(".claims--many select").count() == 1, "many results share one line with a menu") + seen = set() + for _ in range(8): + page.mouse.move(400, 500) + page.mouse.wheel(0, 2200) + page.wait_for_timeout(700) + heads = head() + seen.add(tuple(heads)) + if "Following" in caption(page) and heads: + check(any(title in caption(page) for title in heads), f"the graph shows the statement being read: {heads[0]}") + check(len(seen) >= 4, f"the graph changed {len(seen)} times as the paper scrolled") + page.get_by_role("button", name="Next result").click() + page.wait_for_timeout(300) + held = head() + check(page.locator(".graph__paused").count() == 1, "choosing a result holds the graph there") + page.mouse.move(400, 500) + page.mouse.wheel(0, -4000) + page.wait_for_timeout(900) + check(head() == held, "a held graph stays put while the paper scrolls") + page.get_by_role("button", name="Follow the paper again").click() + wait_until(page, lambda: head() != held and page.locator(".graph__paused").count() == 0, "following again returns to the statement being read") + shot(page, shots, "05-graph-follows") + width = lambda: page.locator(".left").bounding_box()["width"] + start = width() + grip = page.locator(".papersplit").bounding_box() + page.mouse.move(grip["x"] + 13, 400) + page.mouse.down() + page.mouse.move(grip["x"] - 107, 400, steps=6) + page.mouse.up() + page.wait_for_timeout(300) + moved = width() + check(abs((start - moved) - 120) < 4, f"dragging the divider narrows the paper by the drag ({start:.0f} to {moved:.0f})") + page.reload(wait_until="load") + page.locator(".papersplit").wait_for() + page.wait_for_timeout(600) + check(abs(width() - moved) < 2, "the divider's place survives a reload") + page.locator(".papersplit").dblclick() + page.wait_for_timeout(300) + check(abs(width() - start) < 2, "a double click puts the divider back") + page.locator(".papersplit").focus() + page.keyboard.press("ArrowRight") + page.wait_for_timeout(200) + check(width() > start + 20, "the arrow keys move the divider") + page.keyboard.press("Home") + check(page.evaluate("document.documentElement.scrollWidth <= innerWidth"), "no sideways scroll after resizing") + + def active(page: Page) -> str: return page.evaluate("document.querySelector('[data-paper-pane] .q.is-active')?.dataset.p ?? ''") @@ -931,7 +1018,9 @@ def rested(want: dict, how: str) -> None: reload(page) page.wait_for_selector(".sheet__text .q", state="attached") page.wait_for_timeout(400) - check(page.locator(".proof").count() == 0, "and stays closed") + check(page.locator(".proof__graph").is_visible(), "a reload restores the side-by-side view") + page.locator(".proof__close").click() + page.locator(".proof").wait_for(state="hidden") page.locator(".bar__open").click() wait_until(page, lambda: page.locator(".proof__graph").is_visible(), "and opens again") @@ -1149,7 +1238,7 @@ def monitors(page: Page, url: str, shots: Path | None, size: tuple[int, int]) -> page.wait_for_selector(".decl") page.wait_for_timeout(1400) check(page.evaluate("document.documentElement.scrollWidth <= innerWidth"), "no sideways scroll") - check(page.locator(".proof[data-side]").count() == (1 if w >= 1920 else 0), "stacked or side by side by the room on the right page") + check(page.locator(".proof[data-side]").count() == (1 if w >= 2560 else 0), "stacked or side by side by the room on the right page") box = page.locator(".proof").bounding_box() check(box["width"] >= 500, f"the right page is {box['width']:.0f}px wide") shot(page, shots, f"30-{w}") @@ -1379,6 +1468,12 @@ def main() -> int: context = browser.new_context(viewport={"width": 1440, "height": 790}) opening(context.new_page(), url) context.close() + context = browser.new_context(viewport={"width": 1440, "height": 790}) + reopen_proof(context.new_page(), url) + context.close() + context = browser.new_context(viewport={"width": 1440, "height": 790}) + graph_follows(context.new_page(), url, args.shots) + context.close() context = graph_first(browser.new_context(viewport={"width": 1440, "height": 790})) journey(context.new_page(), url, args.shots) context.close() diff --git a/web/src/app/app.css b/web/src/app/app.css index 667840a..440d38c 100644 --- a/web/src/app/app.css +++ b/web/src/app/app.css @@ -99,7 +99,16 @@ button:disabled { cursor: default; } /* The open book */ .spread { --rail-width: 212px; position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); justify-content: center; background: var(--desk); } .spread.has-right { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } -.spread--reading.has-right { grid-template-columns: var(--rail-width) minmax(0, clamp(480px, calc(44vw - 26px), 1000px)) minmax(0, 1fr); column-gap: 0; } +.spread--reading { --paper-w: clamp(480px, calc(44vw - 26px), 1000px); } +.spread--reading.has-right { grid-template-columns: var(--rail-width) minmax(0, var(--paper-w)) minmax(0, 1fr); column-gap: 0; } +/* The divider stands in the gutter between the paper and the proof (after the Quartic Reader). */ +.papersplit { position: absolute; z-index: 13; top: 0; bottom: 0; left: calc(var(--rail-width) + var(--paper-w)); width: 26px; display: grid; place-items: center; cursor: col-resize; touch-action: none; } +.papersplit span { width: 3px; height: 44px; border-radius: 2px; background: var(--rule-strong); opacity: 0; transition: opacity var(--t-hover) var(--ease-out), background-color var(--t-hover) var(--ease-out); } +.spread:hover .papersplit span { opacity: 1; } +.papersplit:hover span, .papersplit:focus-visible span, .spread.is-resizing .papersplit span { opacity: 1; background: var(--thread); } +.papersplit:focus-visible { outline: 2px solid var(--thread); outline-offset: -4px; } +.spread.is-resizing { user-select: none; cursor: col-resize; } +.spread.is-resizing .threads { visibility: hidden; } .spread--reading.has-right .proof { margin-left: 26px; } .left { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; } .left > * { flex: 1; min-height: 0; } @@ -392,7 +401,7 @@ a.source__ref:hover { color: var(--lit); text-decoration: underline solid; } } @media (min-width: 2100px) { .spread { --rail-width: 260px; } - .spread--reading.has-right { grid-template-columns: var(--rail-width) minmax(0, 1000px) minmax(0, 1fr); } + .spread--reading { --paper-w: 1000px; } .lean-code { font-size: 0.875rem; } .rail { font-size: var(--fs-ui); } } @@ -457,3 +466,26 @@ a.source__ref:hover { color: var(--lit); text-decoration: underline solid; } .nearmap__key { margin: 0; padding: 6px 16px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs-sm); color: var(--ink-2); } .proof:has(.graph--near) .proof__key { display: none; } @media (prefers-reduced-motion: no-preference) { .nearmap__card, .nearmap__line { transition: opacity 120ms; } } + +/* Many results: one line names the result on show, with a menu and a step either way. */ +.claims--many { flex-wrap: nowrap; align-items: center; gap: 6px; padding: 5px 12px 5px 16px; border-bottom: 1px solid var(--rule); } +.claims__pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; } +.claims__count { flex: none; color: var(--ink-2); font-variant-numeric: tabular-nums; } +.claims__pick select { flex: 1; min-width: 0; min-height: 28px; padding: 0 28px 0 8px; font: inherit; font-weight: 600; color: var(--ink); text-overflow: ellipsis; background-color: var(--sheet); border: 1px solid var(--rule-control); border-radius: var(--radius-s); cursor: pointer; } +.claims__pick select:hover { border-color: var(--ink-3); } +.claims--many .claims__step { flex: none; min-width: 28px; padding: 0; font-size: var(--fs-base); line-height: 1; color: var(--ink); border: 1px solid var(--rule-control); } +.claims--many .claims__step:hover:not(:disabled) { border-color: var(--ink-3); } +.claims--many .claims__step:disabled { color: var(--ink-3); opacity: 0.5; cursor: default; } +.claims__pick select:focus-visible, .claims__step:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; } +/* The drawing changes with the statement being read: a short dissolve says it is a new drawing. */ +@media (prefers-reduced-motion: no-preference) { + .nearmap__world { animation: nearmap-arrive 180ms cubic-bezier(0.16, 1, 0.3, 1) backwards; } + @keyframes nearmap-arrive { from { opacity: 0; } } +} +/* A Lean name stays on one line inside its card; the whole name is in its tooltip and in the Lean. */ +.nearmap__raw { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.nearmap__key { display: flex; flex-wrap: wrap; gap: 2px 18px; white-space: normal; } +.nearmap__shapes { color: var(--ink-3); } +.nearmap__shapes .key-shape { margin-left: 10px; } +.nearmap__shapes .key-shape:first-child { margin-left: 0; } +.nearmap__alone { max-width: 46ch; margin: 4px auto 0; padding: 0 16px; text-align: center; font-size: var(--fs-sm); line-height: 1.45; color: var(--ink-2); text-wrap: pretty; } diff --git a/web/src/paper/PaperPage.tsx b/web/src/paper/PaperPage.tsx index caa35eb..959aaa2 100644 --- a/web/src/paper/PaperPage.tsx +++ b/web/src/paper/PaperPage.tsx @@ -24,6 +24,7 @@ import { ProofPage, readLayout, saveLayout, type Layout } from "../proof/ProofPa import { Contents } from "./Contents"; import { ReadingPane } from "./ReadingPane"; import { Threads } from "./Threads"; +import { PaperSplit } from "./PaperSplit"; import { DWELL_MS, type Follow, type PaperHandle, type Pointed, type Target, type Zone } from "./reading-line"; // The paper comes first. The PDF, the map and the Lean page each load when they are wanted. @@ -684,7 +685,8 @@ export function PaperPage({ edition }: { edition: Edition }) { if (shown.mode === "after") return <>{hereLabel ? `No statement in ${hereLabel} is linked to this Lean.` : "No statement here is linked to this Lean."} The linked statements are in {sectionLabel(firstTie)} to {sectionLabel(lastSection)}.; if (shown.mode === "between") return <>No statement at this line. The last was {name}.; if (shown.mode === "start") return <>Before the first statement, in {sectionLabel(firstTie)}. Showing the main claim.; - return <>Following the {noun(edition)}: {stepView.title}; + // The statement by its plain name and section; its exact place is under "In the paper". + return <>Following the {noun(edition)}: {name && stepView.passage ? `${name}, ${sectionLabel(stepView.passage.section)}` : stepView.title}; })(); const backButton = entry.back && ; @@ -908,6 +910,7 @@ export function PaperPage({ edition }: { edition: Edition }) { )} /> )} + {wide && showRight && edition.reading && } {wide && showRight && } diff --git a/web/src/paper/PaperSplit.tsx b/web/src/paper/PaperSplit.tsx new file mode 100644 index 0000000..3ad8f85 --- /dev/null +++ b/web/src/paper/PaperSplit.tsx @@ -0,0 +1,141 @@ +// The divider between the paper and the proof. Drag it, or use the arrow keys, to give +// either side more of the window; a double click puts it back. The choice is remembered. +// Adapted from the Quartic Reader's ReaderSplit (itself after ProofPage's handle here): +// pointer capture, one CSS property written while dragging, a persisted share. + +import { useLayoutEffect, useRef, useState } from "react"; + +const KEY = "proof-reader-paper-share-1"; +/** The narrowest either side may become, in pixels. */ +const MIN_PAPER = 420; +const MIN_PROOF = 420; +const GUTTER = 26; + +function stored(): number | null { + try { + const n = Number(localStorage.getItem(KEY)); + return n > 0.15 && n < 0.85 ? n : null; + } catch { + return null; + } +} + +export function PaperSplit() { + // The paper's share of the window; none until the reader chooses one. + const [share, setShare] = useState(stored); + const [now, setNow] = useState(44); + const handle = useRef(null); + // The open book this divider stands in. Read from the handle: a parent's ref is not yet + // set when this component's first layout effect runs. + const root = { get current() { return handle.current?.closest(".spread") ?? null; } }; + + const bounds = () => { + const el = root.current; + const width = el?.clientWidth || window.innerWidth; + const rail = el ? parseFloat(getComputedStyle(el).getPropertyValue("--rail-width")) || 0 : 0; + return { width, low: MIN_PAPER / width, high: Math.max(MIN_PAPER / width, (width - rail - GUTTER - MIN_PROOF) / width) }; + }; + const write = (value: number | null) => { + const el = root.current; + if (!el) return; + if (value === null) el.style.removeProperty("--paper-w"); + else el.style.setProperty("--paper-w", `${(value * 100).toFixed(2)}%`); + }; + const apply = (value: number | null, save = true) => { + const { low, high } = bounds(); + const next = value === null ? null : Math.min(high, Math.max(low, value)); + write(next); + setShare(next); + if (!save) return; + try { + if (next === null) localStorage.removeItem(KEY); + else localStorage.setItem(KEY, String(next)); + } catch { + /* storage unavailable: the choice lasts until the page closes */ + } + }; + /** Where the divider stands now, as a share of the window, whoever put it there. */ + const measured = () => { + const el = root.current; + const paper = el?.querySelector(".left"); + return el && paper ? paper.getBoundingClientRect().width / el.clientWidth : 0.44; + }; + + useLayoutEffect(() => { + const el = root.current; + if (!el) return; + apply(share, false); + const measure = () => setNow(Math.round(measured() * 100)); + measure(); + // A narrower window may no longer hold the stored share: clamp it again. + const observer = new ResizeObserver(() => { + const kept = stored(); + if (kept !== null) { + const { low, high } = bounds(); + write(Math.min(high, Math.max(low, kept))); + } + measure(); + }); + observer.observe(el); + return () => { + observer.disconnect(); + el.style.removeProperty("--paper-w"); + el.classList.remove("is-resizing"); + }; + // The stored share is applied once; dragging writes the same property. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + return ( +
apply(null)} + onKeyDown={(event) => { + if (!["ArrowLeft", "ArrowRight", "Home", "Enter"].includes(event.key)) return; + event.preventDefault(); + event.stopPropagation(); + if (event.key === "Home" || event.key === "Enter") apply(null); + else apply((share ?? measured()) + (event.key === "ArrowRight" ? 0.025 : -0.025)); + }} + onPointerDown={(event) => { + const el = root.current; + if (event.button !== 0 || !el) return; + event.preventDefault(); + const grip = event.currentTarget; + grip.setPointerCapture(event.pointerId); + el.classList.add("is-resizing"); + const rail = parseFloat(getComputedStyle(el).getPropertyValue("--rail-width")) || 0; + // Keep the point that was pressed under the pointer. + const grab = event.clientX - grip.getBoundingClientRect().left; + const move = (e: PointerEvent) => { + const box = el.getBoundingClientRect(); + apply((e.clientX - grab - box.left - rail) / box.width, false); + }; + const end = () => { + grip.removeEventListener("pointermove", move); + grip.removeEventListener("pointerup", end); + grip.removeEventListener("pointercancel", end); + el.classList.remove("is-resizing"); + // Save where the drag ended, or nothing if the press never moved. + const at = el.style.getPropertyValue("--paper-w"); + if (at) apply(parseFloat(at) / 100); + }; + grip.addEventListener("pointermove", move); + grip.addEventListener("pointerup", end); + grip.addEventListener("pointercancel", end); + }} + > +
+ ); +} diff --git a/web/src/proof/MapPane.tsx b/web/src/proof/MapPane.tsx index 4309c67..f2fda54 100644 --- a/web/src/proof/MapPane.tsx +++ b/web/src/proof/MapPane.tsx @@ -6,7 +6,7 @@ // camera back exactly. The reader stays in charge: moving the map pauses following. import { memo, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, type Ref } from "react"; -import { loadSource, type Edition } from "../app/edition"; +import { declEvidence, loadSource, type Edition } from "../app/edition"; import { ArgumentTree, type Insets, type MapViewHandle } from "../map/ArgumentTree"; import { NearMap } from "./NearMap"; import type { MapScene } from "../map/canvas/scene"; @@ -25,6 +25,8 @@ const BAND = 340; * pane narrower than LIST_BELOW shows the cards as a list. */ const MAP_LIMIT = 16; +/** More results than this, and the switch between them is one line with a menu. */ +const MANY_CLAIMS = 4; const LIST_BELOW = 440; /** Neighbourhood tiles are wider, and each is as tall as its title needs, up to four lines. */ const NEAR_W = 140; @@ -156,9 +158,15 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l const big = fullGraph.nodes.size - claims.length > MAP_LIMIT; const [whole, setWhole] = useState(!big); const [centre, setCentre] = useState(goal); - useEffect(() => { - setCentre(selected && selected !== goal && edition.declarations.some((d) => d.id === selected) ? selected : goal); - }, [selected, goal, edition]); + // Bring one declaration into view with what it uses. A result the paper states is drawn + // under its own claim, so the switch above the drawing names what is on show. + const show = useCallback((id: string) => { + const stated = claims.find((c) => c.lean.includes(id)); + if (stated) { + setGoal(stated.id); + setCentre(stated.id); + } else if (edition.declarations.some((d) => d.id === id)) setCentre(id); + }, [claims, edition]); const near = !whole; // The authors' Lean, for the order in which a statement names what it uses. const [files, setFiles] = useState | null>(null); @@ -190,10 +198,32 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l return () => observer.disconnect(); }, []); const claim = claims.find((c) => c.id === goal) ?? claims[0]; + // The card or cards at the top of the neighbourhood, and what to say when nothing hangs below. + const headIds = useMemo(() => (centre === goal ? (claims.find((c) => c.id === goal)?.lean ?? []).filter((id) => graph.nodes.has(id)) : [centre]), [centre, goal, claims, graph]); + const alone = useMemo(() => { + const heads = headIds.map((id) => edition.declarations.find((d) => d.id === id)).filter((d) => !!d); + if (!heads.length) return undefined; + return heads.every((d) => declEvidence(edition, d) === "lean") + ? "Lean reports no other declaration on this page in its statement or proof." + : "Nothing is drawn below it: Lean has not been run on this declaration here, so what it uses is not recorded. Its statement was read from the authors\u2019 source."; + }, [headIds, edition]); + const claimAt = Math.max(0, claims.findIndex((c) => c.id === claim?.id)); const [paused, setPaused] = useState(false); const pausedRef = useRef(false); + // The drawing follows the reading, as the whole map's camera does: the statement held + // open, or else the one under the reading line, comes into view. Looking around the graph + // pauses following the line; a statement the reader opens is always shown. + const followed = useMemo(() => lit.find((id) => edition.declarations.some((d) => d.id === id)) ?? null, [lit, edition]); + useEffect(() => { + if (selected) show(selected); + }, [selected, show]); + useEffect(() => { + if (!selected && followed && !paused) show(followed); + }, [selected, followed, paused, show]); const litIds = useMemo(() => (lit.length ? new Set(lit) : null), [lit]); const litKey = lit.join("|"); + const litRef = useRef(lit); + litRef.current = lit; const shelf = useRef(null); // The shelf is one line: bring a lit type into it. useEffect(() => { @@ -251,6 +281,14 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l onPauseChange(next); }, [onPauseChange]); + // The reader's own move through the graph: it stays where they put it until they ask + // it to follow the paper again. + const browse = useCallback((id: string) => { + if (claims.some((c) => c.id === id)) setGoal(id); + setCentre(id); + if (litRef.current.length) setPause(true); + }, [claims, setPause]); + const restoring = useRef(false); useImperativeHandle(ref, (): MapPaneHandle => ({ scene: () => tree.current?.getScene() ?? null, @@ -268,8 +306,6 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l }), []); // Every branch is drawn from the start, so following only frames; it never folds. - const litRef = useRef(lit); - litRef.current = lit; const opened = useRef(false); useEffect(() => { let again = 0; @@ -364,9 +400,9 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l const select = useCallback((id: string | null) => { if (!id) return; const head = centre === goal && (claims.find((c) => c.id === goal)?.lean ?? []).includes(id); - if (near && id !== centre && !head && fullGraph.nodes.get(id)?.kind !== "goal") setCentre(id); + if (near && id !== centre && !head && fullGraph.nodes.get(id)?.kind !== "goal") browse(id); else onSelect(id); - }, [near, centre, goal, claims, fullGraph, onSelect]); + }, [near, centre, goal, claims, fullGraph, onSelect, browse]); const onUserMove = useCallback(() => setPause(true), [setPause]); const noTrace = useCallback(() => undefined, []); @@ -403,17 +439,29 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l
{paused && (

- Paused while you move the graph. + The graph stays where you put it.

)} - {claims.length > 1 && ( -
+ {claims.length > 1 && claims.length <= MANY_CLAIMS && ( +
{claims.map((c) => ( - + ))}
)} + {claims.length > MANY_CLAIMS && ( +
+ + + +
+ )} {types.length > 0 && (
Types @@ -434,11 +482,11 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l {whole ? "Show one card and what it uses" : "Whole map"} )} - {near && !narrow && centre !== goal && } + {near && !narrow && centre !== goal && } {near && !narrow && centre !== goal && } {near && !narrow && usedBy.length > 0 && ( Used by{" "} - {usedBy.map((id) => )} + {usedBy.map((id) => )} )} {whole && big && !narrow && Point at a card to see its lines.} @@ -462,8 +510,10 @@ export const MapPane = memo(function MapPane({ ref, edition, graph: fullGraph, l ? ( c.id === goal)?.lean ?? []).filter((id) => graph.nodes.has(id)) : [centre]} - plate={centre === goal ? (claim?.title ?? null) : null} + heads={headIds} + plate={centre === goal && !(headIds.length === 1 && fullGraph.nodes.get(headIds[0])?.label === claim?.title) ? (claim?.title ?? null) : null} + alone={alone} + kicker={claims.length > 1 && claimAt > 0 ? `Result ${claimAt + 1} of ${claims.length}` : "Main result"} lit={lit} selected={selected} onCard={(id) => select(id)} diff --git a/web/src/proof/NearMap.tsx b/web/src/proof/NearMap.tsx index 5e67b08..2ea560c 100644 --- a/web/src/proof/NearMap.tsx +++ b/web/src/proof/NearMap.tsx @@ -94,12 +94,16 @@ export function reduce(ids: string[], edges: { from: string; to: string }[]): Se return new Set(edges.filter((e) => !reaches(e.from, e.to, e.to)).map((e) => `${e.from}→${e.to}`)); } -export function NearMap({ graph, heads, plate, lit, selected, onCard, onHover }: { +export function NearMap({ graph, heads, plate, kicker = "Main result", alone, lit, selected, onCard, onHover }: { graph: ArgGraph; /** The card or cards in view, drawn at the top. */ heads: string[]; /** The claim's title above the theorem, at the main result. */ plate: string | null; + /** Said under a card that stands alone: why nothing is drawn beneath it. */ + alone?: string; + /** The small line over the claim's title: which of the paper's results this is. */ + kicker?: string; lit: readonly string[]; selected: string | null; onCard(id: string): void; @@ -123,6 +127,11 @@ export function NearMap({ graph, heads, plate, lit, selected, onCard, onHover }: const [hot, setHot] = useState(null); // A new card in view starts with nothing pointed at, whatever lies under the pointer now. useEffect(() => setHot(null), [graph]); + // A new card in view is read from its top. + const headKey = heads.join("|"); + useEffect(() => { + if (frame.current) frame.current.scrollTop = 0; + }, [headKey]); const drawing = useMemo(() => { if (!width) return null; @@ -316,10 +325,10 @@ export function NearMap({ graph, heads, plate, lit, selected, onCard, onHover }:
{drawing && (
-
+
{plate && (
- Main result + {kicker} {plate}
)} @@ -361,11 +370,15 @@ export function NearMap({ graph, heads, plate, lit, selected, onCard, onHover }:
)} - {drawing && ( + {drawing && drawing.edges.length === 0 && alone &&

{alone}

} + {drawing && drawing.edges.length > 0 && (

- {drawing.kinds.size > 1 - ? "Lines run down to what a card uses; dashed: its statement only." - : "Each line runs down from a card to a declaration it uses."} + + {drawing.kinds.size > 1 + ? "Lines run down to what a card uses; dashed: its statement only." + : "Each line runs down from a card to a declaration it uses."} + +