HTML representation of TuiML components for notebooks.
Renders a component, most usefully a Workflow: as a nested diagram of boxes, so a pipeline's structure is visible at a glance instead of buried in a long repr string.
Any object may control how it is drawn by implementing _tuiml_visual_block_() and returning a VisualBlock. Composite components (a pipeline, a column router) use this to expose their children, which are then drawn recursively.
The diagram is pure HTML + CSS, collapsible boxes use a hidden checkbox toggled by its , so no JavaScript is needed and the output renders in any notebook front end. The CSS is scoped to a unique container id so several diagrams on one page cannot affect each other.
Classes
How a component should be drawn.
__init__( self, kind: str, items: Any, *, names: Any = None, details: Any = None, title: Optional[str] = None, framed: bool = True, )
Parameters
kind
"single" draws one box. "serial" stacks children vertically (data flows top to bottom). "parallel" places children side by side (children each see the same input).
items
kind="single", otherwise its children.
names
"single", one per child otherwise.
details
repr).
title
kind is "serial" or "parallel".
framed
Functions
Return the VisualBlock describing how to draw component.
Parameters
component
_tuiml_visual_block_() control their own layout; anything else is drawn as a single box.
Returns
VisualBlock
>>> from tuiml.utils.html_repr import get_visual_block
>>> block = get_visual_block(42)
>>> block.kind, block.names, block.details
('single', 'int', '42')
>>> get_visual_block(None).names
'passthrough'
Build the HTML diagram for a component.
Parameters
component
Workflow).
Returns
str
<style> block, a plain-text fallback for front ends that strip CSS, and the diagram itself.
>>> from tuiml import Workflow
>>> from tuiml.preprocessing import StandardScaler
>>> from tuiml.algorithms.bayesian import NaiveBayesClassifier
>>> page = component_html_repr(
... Workflow([StandardScaler(), NaiveBayesClassifier()]))
>>> page.startswith("<style>")
True
>>> "NaiveBayesClassifier" in page
True