capturegraph_ui
capturegraph_ui
#
capturegraph_ui (cgui) — pages built from components, each rendering itself to HTML.
- Build. A page function under
@cgui.PageBuilder()constructs components —Componentsubclasses whose annotated fields are their props — in document order; each attaches to the innermost open stack,withon aVStackorHStacknests them, andTitlenames the page. The standard vocabulary:VStackandHStacklay out,DividerandPaddingseparate;MarkdownandStatshow words and figures;ImageViewer,GalleryandTimelapseshow captured files;Scatterplots columns against each other,Ratehow often events happened,Chartdraws a specification in full andMapViewermaps;PageLinkleads to the page of another value. The viewers areImageViewerandMapViewerrather thanImageandMapbecause those names belong to thecgtypes they display. A suite declares its own by subclassingComponentand implementinghtml. The function returns aPage: the directory scalar that is the website folder, declared now and written when built. - Render. When the page is built, each component writes its HTML through
one
Rendercontext: files it shows are staged underfiles/and browser libraries it needs underlib/. A link is aPageLinkor anofentry, nothing else:PageLink(value)leads to the page of a value loaded from the target,Gallery.of,Timelapse.ofandMapViewer.oflink each derived item to its container entry, and a plain value renders with no link.Notebookis the same rendering forcg.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")