Diagramming
spytial.diagram() converts Python objects into a spatial diagram. It
works with built-in containers, dataclasses, custom classes, and
graph-like structures.
Basic usage
import spytial
spytial.diagram({"a": 1, "b": [1, 2, 3]})
Display options
spytial.diagram(data, method="browser") # open a new tab
spytial.diagram(data, method="file") # save as spytial_visualization.html
spytial.diagram(data, method="inline") # force notebook output
Sizing and title
spytial.diagram(data, width=900, height=600, title="My Diagram")
Passing annotations with as_type
Use AnnotatedType or typing.Annotated to attach spatial constraints
to a type. The object is then treated as that type.
from typing import Dict, List
from spytial import AnnotatedType, InferredEdge, Orientation, Tag
Graph = AnnotatedType(
Dict[int, List[int]],
InferredEdge(name="edge", selector="values"),
Orientation(selector="values", directions=["right"]),
Tag(toTag="univ", name="count", value="values"),
)
graph = {0: [1, 2], 1: [3]}
spytial.diagram(graph, as_type=Graph)
Common workflow
For complex objects, use the usual workflow:
- Call
spytial.evaluate(obj)to confirm the serialized atoms and relations. - Call
spytial.diagram(obj)to see the layout. - Add decorators or
AnnotatedType(...)annotations for more control over layout or styling.