API Reference / utils /

html_repr.py

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

VisualBlock

class utils.html_repr.VisualBlock

How a component should be drawn.

Constructor
__init__(
    self,
    kind: str,
    items: Any,
    *,
    names: Any = None,
    details: Any = None,
    title: Optional[str] = None,
    framed: bool = True,
)

Parameters

kind
{"single", "serial", "parallel"}
"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
object or list of object
The component itself when kind="single", otherwise its children.
names
str or list of str
Box captions, a single name for "single", one per child otherwise.
details
str or list of str
Text revealed when a box is expanded (typically the child's repr).
title
str
Caption for the frame drawn around the children. Only used when kind is "serial" or "parallel".
framed
bool = True
Whether to draw a dashed frame around the children.

Functions

Func

get_visual_block

Line 79
get_visual_block(component: Any) -> VisualBlock

Return the VisualBlock describing how to draw component.

Parameters

component
object
Any component. Objects implementing _tuiml_visual_block_() control their own layout; anything else is drawn as a single box.

Returns

VisualBlock
The layout description.
python
>>> 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'
Func

component_html_repr

Line 183
component_html_repr(component: Any) -> str

Build the HTML diagram for a component.

Parameters

component
object
The component to draw (typically a Workflow).

Returns

str
Self-contained HTML: a scoped <style> block, a plain-text fallback for front ends that strip CSS, and the diagram itself.
python
>>> 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