Skip to content

capturegraph_ui

capturegraph_ui #

capturegraph_ui (cgui) — pages built from components, each rendering itself to HTML.

  1. Build. A page function under @cgui.PageBuilder() constructs components — Component subclasses whose annotated fields are their props — in document order; each attaches to the innermost open stack, with on a VStack or HStack nests them, and Title names the page. The standard vocabulary: VStack and HStack lay out, Divider and Padding separate; Markdown and Stat show words and figures; ImageViewer, Gallery and Timelapse show captured files; Scatter plots columns against each other, Rate how often events happened, Chart draws a specification in full and MapViewer maps; PageLink leads to the page of another value. The viewers are ImageViewer and MapViewer rather than Image and Map because those names belong to the cg types they display. A suite declares its own by subclassing Component and implementing html. The function returns a Page: the directory scalar that is the website folder, declared now and written when built.
  2. Render. When the page is built, each component writes its HTML through one Render context: files it shows are staged under files/ and browser libraries it needs under lib/. A link is a PageLink or an of entry, nothing else: PageLink(value) leads to the page of a value loaded from the target, Gallery.of, Timelapse.of and MapViewer.of link each derived item to its container entry, and a plain value renders with no link. Notebook is the same rendering for cg.logging: a sink that redraws a Jupyter cell with the log as HTML.
import capturegraph_ui as cgui


@cgui.PageBuilder()
def courtyard(target: Courtyard) -> None:
    cgui.Title("Courtyard")
    cgui.Markdown("# Courtyard")
    with cgui.HStack():
        cgui.Stat("Sessions", 12)
        cgui.Stat("Coverage", 0.8)
    cgui.Timelapse.of(target.sessions, lambda s: s.photo)
    cgui.PageLink(target.sessions.values()[-1], title="Latest session")