Widgets#
Diagram Widget#
- class ipyelk.Diagram(*args: t.Any, **kwargs: t.Any)#
An Elk diagramming widget to help coordinate the
ViewerandPipeAttributes#
- source:
MarkElementWidget input source to the diagram’s processing pipe. A source feeds one open diagram: a source of another open diagram is refused with
TraitError;source.diagramis that diagram. A diagram releases its source when it closes or gets a new one.- pipe:
Pipe processing pipe (that may contain sub-pipes). Pipes perform various tasks like adding x/y and width/height layouts or calculating text label sizes. The diagram owns its pipe and every pipe nested in it. A new pipe, or a stage added to a pipeline’s
pipes, is refused if any pipe in it is closed, owned by another open diagram, or part of the current pipe. A stage removed frompipesis released, not closed. Replacing the pipe or closing the diagram closes the pipe, its sub-pipes and the widgets they created (such as status views), but neversourceor an inlet/outlet passed in.- view:
Viewer output view that will render the pipe outlet; closed with the diagram. Pass it at construction: assigning a different view, or giving a closed view or a view of another open diagram, raises
TraitError.- tools: tuple
Tool list of tools that a user of the diagram might use to manipulate the state of the diagram; closed with the diagram. Tools and the toolbar belong to one open diagram. Remove a tool from
toolsbefore registering it on another diagram; give each diagram its own toolbar.- symbols:
SymbolSpec additional shape definitions that can be used in rendering the diagram. For example unique arrow head shapes or custom node shapes.
A closed diagram (
closedis True) raisesClosedErroronrefresh(),register_tool()and on settingsource,pipe,view,tools,toolbar,symbols,style,layoutorchildren.A construction that a check refuses (
TraitError) leaves the source, view and pipe that it was given open. A construction that fails after the checks, for example in a tool’son_done, closes the diagram asclose()does, with the view and pipe that it was given. Tools and the toolbar close only after the diagram has claimed them; a refused construction never closes another diagram’s widgets.- close()#
Close the diagram with its pipe, view, tools and toolbar.
sourceand any inlet or outlet passed to a pipe stay open. Closing again does nothing.
- property closed: bool#
Whether
close()was called; a closed diagram refuses calls.
- get_tool(tool_type)#
Get the tool that matches the given Tool type.
- refresh(sender=None)#
Create asynchronous refresh task which will update the view given any changes.
senderis ignored; it letsrefreshserve as a tool’son_donecallback (which receives the tool). ReturnsNonewhen no event loop is running (seePipe.schedule_run). The task resolves cancelled when the diagram is closed mid-run, so awaiting it then raisesCancelledError.- Return type:
Task|None
- register_tool(tool)#
Add a new tool to the diagram.
Each name in the tool’s
_dependenciesthat the diagram supplies is bound:diagram,pipe,viewand the view’sselection,hover,viewportandpainter. Any other dependency stays as it is, and the tool names it inmissing_dependencies()while it isNone. A progress bar stops getting the reports of a pipe from another diagram.
- source#
Syncs Elk JSON Elements
- source:
Viewer Widget#
- class ipyelk.diagram.Viewer(*args: t.Any, **kwargs: t.Any)#
Generic Viewer of ELK JSON diagrams. Currently only mainly used by
SprottyViewerAttributes#
- parameter source:
MarkElementWidgetinput source for rendering.- parameter selection:
Selectionmaintains selected ids and methods to resolve the python elements.- parameter hover:
Hovermaintains the hovered id.- parameter viewport:
Viewportthe camera (origin, zoom, canvas size, viewed ids) of the most recently reporting view, written by the browser. Move a view withset_viewport().- parameter painter:
Paintertemporary, view-only CSS classes per element id, applied in every view without touching the model.- parameter control_overlay:
ControlOverlayorNoneadditional JupyterLab widgets that can be rendered on top of the diagram based on the current selected states. Opt-in:None(the default) and an overlay withoutchildrenrender nothing.- parameter fit_on_first_layout:
bool opt-in (default
False): each view fits the whole diagram, in the browser, after its first layout, so a diagram displayed after it was laid out (when afit()message would have reached no view) does not open at 1:1 in the top-left corner. A view that is hidden then (a collapsed accordion, a background tab) fits the first time it is shown. Each view fits once: later layouts (a newsourceincluded), reveals and resizes keep its camera, and aset_viewportsent while it waits to be shown cancels its fit; afit()orcenter()sent then has no canvas to work on, and the first fit replaces it. Set it before a view’s first layout: a view that was already laid out is not fitted when it is turned on.- parameter fit_padding:
float padding around the diagram, in diagram units (scaled by the zoom on screen), for the first-layout fit and for
fit()calls that pass nopadding(default0).- parameter fit_max_zoom:
float or
Nonezoom limit for the first-layout fit and forfit()calls that pass nomax_zoom;None(the default) leaves only the viewer’s own limit (10), so a small diagram fills the view. A value above 10 acts as 10.- parameter cull_offscreen:
bool opt-in (default
False): each view renders only the elements that touch its canvas, which keeps selection, hover and panning cheap on a large diagram that is zoomed in. The SVG in the page is then not the whole diagram when the view is zoomed in, so code that reads the browser DOM must fit the view first or stay with the default. AnExporteris unaffected either way: it renders its export from the model, so it is complete at any zoom.
- center(model_ids=None, animate=None, retain_zoom=None)#
Center the view on
model_ids(the whole diagram if None).A
stris one id, never a sequence of characters. The generic viewer has no viewport of its own, so this does nothing; subclasses that render (SprottyViewer) implement it with the same signature.- Return type:
None
- close()#
Close the viewer and its tools, not
sourceorcontrol_overlay.
- fit(model_ids=None, animate=None, max_zoom=None, padding=None)#
Pan/zoom the view to focus on
model_ids(the whole diagram if None).A
stris one id, never a sequence of characters. The generic viewer has no viewport of its own, so this does nothing; subclasses that render (SprottyViewer) implement it with the same signature.- Return type:
None
- pan#
Removed in 3.0; raises DeprecatedAPIError throughout 3.x. Viewer.pan was removed in ipyelk 3.0: the Pan tool was a placeholder that nothing ever wrote. Read viewer.viewport.origin and viewer.viewport.canvas_size (the browser’s latest report, None until one arrives) and move a view with viewer.set_viewport(origin=(x, y)). No alias: this error is raised throughout 3.x.
- viewed#
Removed in 3.0; raises DeprecatedAPIError throughout 3.x. Viewer.viewed was removed in ipyelk 3.0: nothing ever wrote it. Read viewer.viewport.viewed_ids (the ids whose bounds touch the reporting view’s visible rectangle; None until the browser reports). No alias: this error is raised throughout 3.x.
- zoom#
removed names raise
DeprecatedAPIErrorthrough 3.x
- class ipyelk.diagram.SprottyViewer(*args: t.Any, **kwargs: t.Any)#
JupyterLab widget for displaying and interacting with views generated from ELK JSON.
Setting the instance’s value traitlet to valid Eclipse Layout Kernel JSON will call the elkjs layout method and display the returned mark_layout using sprotty.
- center(model_ids=None, animate=None, retain_zoom=None)#
Center Diagram View on specified model ids
- Parameters:
model_ids (
str|Sequence[str] |None) – one elk model id, or a sequence of them; None (default) centers the whole diagramanimate (
bool|None) – specify is the view animates to the given marksretain_zoom (
bool|None) – specify if the current zoom level is maintained
- Return type:
None
- fit(model_ids=None, animate=None, max_zoom=None, padding=None)#
Pan/Zoom the Diagram View to focus on particular model ids
- Parameters:
model_ids (
str|Sequence[str] |None) – one elk model id, or a sequence of them; None (default) fits the whole diagramanimate (
bool|None) – specify is the view animates to the given marksmax_zoom (
float|None) – specify if the max zoom level; None (default) usesfit_max_zoompadding (
float|None) – specify if the viewport padding around the marks; None (default) usesfit_padding
- Return type:
None
- set_viewport(*, origin=None, zoom=None, animate=True, view_id=None)#
Move the camera of the connected view(s).
A command, not state: the browser applies it and then reports the resulting camera through
viewport.- Parameters:
origin (
tuple[float,float] |None) – diagram coordinates for the canvas top-left corner;Nonekeeps the view’s current originzoom (
float|None) – CSS pixels per diagram unit;Nonekeeps the current zoomanimate (
bool) – animate the move (default) or jumpview_id (
str|None) – only the view with this id (seeipyelk.tools.Viewport.view_id);Nonemoves every connected view
- Return type:
None