tkmilan.drender#
Renderer for diagrams.
Can support multiple backends, only one implemented so far.
Functions
|
Generate SVG class arguments, if exists. |
|
Generate related |
|
Generate related |
|
Generate related |
|
Generate related |
|
Generate related |
|
Generate related |
|
Generate |
|
Generate |
Classes
|
Export object for SVG format, version |
|
Renderer object for the |
- class tkmilan.drender.Exporter_SVG(diagram: Diagram, *, widget: Optional[mixin.MixinWidget] = None)#
Bases:
objectExport object for SVG format, version
1.1.The
exportfunction is the primary API.The
widgetinstance is an optional context provider for Tk-related operations (such as color resolution and size queries). It should be used to improve the render quality.The produced file has has up to four groups:
World (identified as
world)Background (back layer) (
setup_bg_b)Foreground (
setup_fg)Background (front layer) (
setup_bg_f)
Each is included in order, according to the diagram instructions. The
worldgroup includes the diagram background, the rest are the diagram “layers”, seediagram.Diagram.To implement line arrows, the SVG
defssection is used to produce reusable SVG definitions. This should keep the size of the file down, even in very complex diagrams with a lot of similar arrows. This is only included if necessary.- Parameters:
diagram (Diagram) – The diagram to render.
widget (Optional[mixin.MixinWidget]) – A
widgetused as rendering context, see above. Optional.
- export(outfile: Path, *, width: int | None = None, height: int | None = None, pretty: bool = True) None#
Export the diagram to an SVG file.
- Parameters:
outfile (Path) – Path to the output SVG file.
width (int | None) – SVG viewport width. Optional, defaults to the current widget width. If the current widget is not defined, this is required.
height (int | None) – SVG viewport height. Optional, defaults to the current widget height. If the current widget is not defined, this is required.
pretty (bool) – Whether to pretty-print the XML with indentation. Defaults to True.
- render(de: DiagramElement, *, extratags: Sequence[str] = ()) Element | None#
- render(de: MultiLine, *, extratags: Sequence[str] = ()) Element | None
- render(de: Polygon, *, extratags: Sequence[str] = ()) Element | None
- render(de: Rectangle, *, extratags: Sequence[str] = ()) Element | None
- render(de: Ellipse, *, extratags: Sequence[str] = ()) Element | None
- render(de: Text, *, extratags: Sequence[str] = ()) Element | None
- render(de: EllipseSection, *, extratags: Sequence[str] = ()) Element | None
Render a diagram element, with some internal
extratags.This function is defined as a
single dispatch methodfor each supported diagram element.- Parameters:
de (DiagramElement) – The diagram element to render. Supported for the given diagram element types.
extratags (Sequence[str]) – Additional internal tags to consider, besides the element tags.
- class tkmilan.drender.Renderer_TkCanvas(canvas: Canvas, diagram: Diagram, *, saveElements: bool | None = None)#
Bases:
objectRenderer object for the
Tkcanvas backend.This is just a holding for the rendering process. No “automatic” draws happens when creating this object, all must go through the
redrawfunction.The possible values for the
saveElementsargument are:True: Save markers and element as a tupleFalse: Save only markersNone: Disable saving elements or markers
- Parameters:
- getElement(eid: int) DiagramElement | None#
Get a saved element, if exists.
- Parameters:
eid (int) – The element to consider.
- Returns:
Return the
DiagramElement, if saved.- Return type:
DiagramElement | None
- getMarker(eid: int) str | None#
Get a saved marker string, if exists.
- Parameters:
eid (int) – The element to consider.
- Returns:
Return the marker
str, if exists.- Return type:
str | None
- redraw(_a1: Any | None = None, _a2: Any | None = None, *, width: int | None = None, height: int | None = None, force: bool = False)#
Redraw the canvas.
The canvas consists in three layers, as explained in
diagram.Diagram.If the canvas size changed, all layers are redrawn. Othewise, only the foreground is redrawn. Note that redrawing implies removing the old elements and creating new ones, this is done automatically.
When the foreground is redrawn, it is pushed behing the background front layer.
Unless
forceis given, the first “weird” event (when width and height are both1) is skipped, since this does not make sense to redraw.- Parameters:
width (int | None) – Use this canvas width, instead of getting this information from the
canvasobject.height (int | None) – Use this canvas height, instead of getting this information from the
canvasobject.force (bool) – Force redrawing of background and foreground elements.
_a1 (Any | None) – Optional, unused. This exists for API compatibility with bindings.
_a2 (Any | None) – Optional, unused. This exists for API compatibility with traces.
- render(de: DiagramElement, *, extratags: Sequence[str] = ()) int#
- render(de: MultiLine, *, extratags: Sequence[str] = ()) int
- render(de: Polygon, *, extratags: Sequence[str] = ()) int
- render(de: Rectangle, *, extratags: Sequence[str] = ()) int
- render(de: Ellipse, *, extratags: Sequence[str] = ()) int
- render(de: Text, *, extratags: Sequence[str] = ()) int
- render(de: EllipseSection, *, extratags: Sequence[str] = ()) int
Render a diagram element, with some internal
extratags.This function is defined as a
single dispatch methodfor each supported diagram element.- Parameters:
de (DiagramElement) – The diagram element to render. Supported for the given diagram element types.
extratags (Sequence[str]) – Additional internal tags to consider, besides the element tags.
- eids: MutableMapping[int, str | None | Tuple[str | None, DiagramElementSingle]] | None#
Map element ids to the corresponding
strmarker (if given), and optionally including theDiagramElementas a tuple.Optional, this can be controlled with the
saveElementsparameter.
- tkmilan.drender.svg_class(de_tags: Sequence[str], extratags: Sequence[str]) Mapping#
Generate SVG class arguments, if exists.
- Parameters:
de_tags (Sequence[str]) –
DiagramElementtagsextratags (Sequence[str]) – Extra tags, for rendering
- tkmilan.drender.svg_text_anchor(anchor: CP) Mapping#
Generate related
diagram.ASVG text anchor arguments.
- tkmilan.drender.tkcanvas_arrow(option: A | None) Mapping#
Generate related
diagram.ATkcanvas arrow arguments
- tkmilan.drender.tkcanvas_colors(noprefix: C, cnames: Mapping[str, str] | None = None, **poptions: C) Mapping#
Generate related
diagram.CTkcanvas color arguments.
- tkmilan.drender.tkcanvas_dash(**options: D | None) Mapping#
Generate related
diagram.DTkcanvas dash arguments
- tkmilan.drender.tkcanvas_smooth(option: Smooth | None) Mapping#
Generate related
diagram.SmoothTkcanvas smooth arguments
- tkmilan.drender.tkcanvas_text_angle(angle: Real) Mapping#
Generate
TkTextanglearguments.This feature is only supported on later Tk versions.
- Parameters:
angle (Real) – The angle value. Required.
- tkmilan.drender.tkcanvas_width(**options: int | None) Mapping#
Generate
Tkcanvas width arguments