tkmilan.diagram#

Models to store diagram information.

Implements Euclidian geometry figures in 2D, with discrete pixel coordinates (some functions accept or provide real numbers, when integer conversion is too lossy). Mostly implemented as dataclasses.

The coordinate system is common to several implementations, origin on the topleft corner, axes directed to the rigth and down. See canvas coordinate systems documentation. See also the correspoding SVG documentation, as example.

See also tkmilan.model.

Module Attributes

nround(n)

Round any number to integer.

nfloat(n)

Convert any number to floating point.

GeneratorElementT

Type-Checking variable type for Diagram drawing functions.

Functions

ArcCircleCenter(c, radius, **kwargs)

Draw a circle arc, from a center point and its radius.

ArcEllipse(**kwargs)

Draw a simple ellipse arc, parallel to the axes.

ArcEllipseCenter(c, a, b, **kwargs)

Draw a simple ellipse arc, from a center point to its axes.

CircleCenter(c, radius, **kwargs)

Draw a circle, from a center point and its radius.

DoubleMultiLine(*args, widthSmall[, deltaWidth])

Draw two MultiLine on the same location, with different sizes.

EllipseCenter(c, a, b, **kwargs)

Draw a simple ellipse, from a center point and its axes.

Line(p1, p2, **kwargs)

Draw a single line segment.

LineVector(p, v, **kwargs)

Draw a single line segment, from a point following a vector.

PieEllipse(**kwargs)

Draw a "pie" slice of a simple ellipse, parallel to the axes.

RectangleCenter(c, size_x, size_y, **kwargs)

Draw a simple rectangle, from a center point and its size.

SquareCenter(c, size, *args, **kwargs)

Draw a simple square, from a center point and its size.

VectorH(dx, *args, **kwargs)

An horizontal Vector.

VectorPolar(r, theta)

A "polar" Vector, defined by radius and angle.

VectorV(dy, *args, **kwargs)

A vertical Vector.

nfloat(n)

Convert any number to floating point.

nround(n)

Round any number to integer.

Classes

A([atBoth, atStart, atEnd, d1, d2, d3])

Arrow settings.

C([fill, outline])

Colour settings.

Cap(value)

Cap settings.

D(*pattern[, offset])

Dash settings.

Diagram()

Diagram generator class.

DiagramElement()

Common diagram element class.

DiagramElementMultiple(*items)

Aggregator for multiple DiagramElement objects.

DiagramElementSingle()

Common diagram single element class.

Ellipse(topleft, botright, color, width, ...)

Diagram Element: simple ellipse, parallel to the axes.

EllipseSection(topleft, botright, style, ...)

Diagram Element: part of a larger Ellipse.

EllipseSection_Style(value)

Style selection for EllipseSection.

GeometryLine(m, c0)

A geometric line (not an element like Line), for easing some calculations.

Join(value)

Join settings.

MultiLine(points, color, width, dash, arrow, ...)

Diagram Element: multi-segment line.

Polygon(points, color, width, dash, join, ...)

Diagram Element: polygon.

Rectangle(topleft, botright, color, width, ...)

Diagram Element: simple rectangle, parallel to the axes.

Smooth([algorithm, steps])

Line smoothing settings.

SmoothAlgorithm(value)

Line smoothing algorithm selection.

Text(point, text, color, anchor, angle, ...)

Diagram Element: text.

Vector(dx, dy)

A vector with integer coordinates.

XY(x, y)

A location with integer coordinates.

class tkmilan.diagram.A(atBoth: bool | None = None, *, atStart: bool | None = None, atEnd: bool | None = None, d1: int = 8, d2: int = 10, d3: int = 3)#

Bases: object

Arrow settings.

Check a visual representation of the arrow head shape on the arrowshape section in Tk NMU canvas create line.

Make sure to select one of atStart/atEnd, otherwise this represents no arrow at all.

Parameters:
  • d1 (int) – Arrow Head Shape: Distance along the line, from neck to tip.

  • d2 (int) – Arrow Head Shape: Distance along the line, from trailing points to tip.

  • d3 (int) – Arrow Head Shape: Distance normal from the line, from the outside edge to the trailing points.

  • atStart (bool) – Include an arrow head on the start of the line. Optional, defaults to False if no other at* settings are is given.

  • atEnd (bool) – Include an arrow head on the end of the line. Optional, defaults to True if no other at* settings are is given.

  • atBoth (bool | None) –

    Include an arrow head on start and end of the line. Optional, to be used like this:

    A(True)
    

class tkmilan.diagram.C(fill: str | None = None, outline: str | None = None)#

Bases: object

Colour settings.

The colours are arbitrary colours with the format #RRGGBB/#RGB, or the following recognized colour names.

Parameters:
  • fill (str | None) – The filling colour, for the internal element area. Optional.

  • outline (str | None) – The outline colour, for the line that marks the element boundary. Optional.

w(**kwargs: str | None) C#

Calculate a colour setting with different values.

Doesn’t make sense to create a new setting with both new colours, this is equivalent to create a new object. This is only useful to create a new setting changing only a single colour.

Parameters:
  • fill – The new filling colour. Optional.

  • outline – The new outline colour. Optional.

property reverse: C#

Calculate reversed colour settings.

To clarify, this is a setting when the filling colour is the outline colour, and vice versa.

class tkmilan.diagram.Cap(value)#

Bases: Enum

Cap settings.

Check a visual representation of the style in Tk NMT cap documentation.

BUTT = 'butt'#

The end of the line is cut off square at a line that passes through the endpoint.

PROJECTING = 'projecting'#

The end of the line is cut off square, but the cut line projects past the endpoint a distance equal to half the line’s width.

ROUND = 'round'#

The end describes a semicircle centered on the endpoint.

class tkmilan.diagram.D(*pattern: int, offset: int = 0)#

Bases: object

Dash settings.

The pattern is a tuple of distances to consider. Only odd-indexed pattern distances are drawn, the even-indexed distances are skipped (or “drawn” with transparent color). There’s also an initial offset, can even be negative.

Check as visual representation of the dash patterns in Tk NMT canvas dash patterns or canvas dash patterns documentation.

Parameters:
  • pattern (Tuple[int, ...]) – Tuple with distances to be considered. See the description above on how this is represented.

  • offset (int) – Offset on pattern start. Defaults to 0, no offset.

class tkmilan.diagram.Diagram#

Bases: ABC

Diagram generator class.

This should be subclassesed and it’s function implemented with iter that create the diagram itself, based on possible __init__ state, and also per-function arguments.

There are three available “layers” for elements, each built from a function, in order:

All functions are optional, they default to generate no elements.

This is only an abstract class, a common base class for all the possible diagrams.

setup_bg_b(*, cwidth: int, cheight: int) Generator[DiagramElement | Tuple[DiagramElement, str], int | None, None]#

Draw the Background Back layer.

Should be a generator creating a finite amount of GeneratorElementT. Sends the element identifier (an integer).

Note

For debug binaries, sends None if the render had a problem. On production binaries, this is an error.

setup_bg_f(*, cwidth: int, cheight: int) Generator[DiagramElement | Tuple[DiagramElement, str], int | None, None]#

Draw the Background Front layer.

Should be a generator creating a finite amount of GeneratorElementT. Sends the element identifier (an integer).

Note

For debug binaries, sends None if the render had a problem. On production binaries, this is an error.

setup_fg(*, cwidth: int, cheight: int) Generator[DiagramElement | Tuple[DiagramElement, str], int | None, None]#

Draw the Foreground layer.

Should be a generator creating a finite amount of GeneratorElementT. Sends the element identifier (an integer).

Note

For debug binaries, sends None if the render had a problem. On production binaries, this is an error.

BACKGROUND: str | None = None#

Canvas background colour.

Optional. See C for colour specification.

DISABLEDBACKGROUND: str | None = None#

Canvas background colour, when disabled.

Optional. See C for colour specification.

MIN_SIZE: Tuple[int | None, int | None] = (None, None)#

Canvas minimum size for rendering.

If the canvas size is smaller than any of the (non-None) sizes, rendering is skipped.

Optional.

class tkmilan.diagram.DiagramElement#

Bases: ABC

Common diagram element class.

This is only an abstract class, a common base class for all the possible diagram elements.

iterate() Iterator[DiagramElementSingle]#

Gather all constituent DiagramElementSingle objects, recursively.

class tkmilan.diagram.DiagramElementMultiple(*items: DiagramElement)#

Bases: DiagramElement

Aggregator for multiple DiagramElement objects.

Certain diagram elements only make sense together, group them here.

class tkmilan.diagram.DiagramElementSingle#

Bases: DiagramElement

Common diagram single element class.

All single element classes inherit from this.

class tkmilan.diagram.Ellipse(topleft: ~tkmilan.diagram.XY, botright: ~tkmilan.diagram.XY, color: ~tkmilan.diagram.C = <factory>, width: int | None = None, dash: ~tkmilan.diagram.D | None = None, colorActive: ~tkmilan.diagram.C = <factory>, widthActive: int | None = None, dashActive: ~tkmilan.diagram.D | None = None, colorDisabled: ~tkmilan.diagram.C = <factory>, widthDisabled: int | None = None, dashDisabled: ~tkmilan.diagram.D | None = None, tags: ~typing.Sequence[str] = ())#

Bases: DiagramElementSingle

Diagram Element: simple ellipse, parallel to the axes.

Represent a simple ellipse, with sides parallel to the axes. Remember that a circle is a special case for an ellipse, see CircleCenter.

There is no Python documentation, see Tk canvas common options and canvas oval options. See also NMT create oval documentation.

Parameters:
  • topleft (XY) – The top left vertex (lower X and Y coordinates).

  • botright (XY) – The bottom right vertex (higher X and Y coordinates).

  • color (C) – Colour for outline and fill area, see C for colour specification.

  • width (int | None) – Width for outlines, in pixels. Optional, defaults to minimum line width.

  • dash (D | None) – Dashed outline setting. Optional, defaults to solid line.

  • colorActive (C) – color for active elements, that is, on mouse hover.

  • widthActive (int | None) – width for active elements, that is, on mouse hover.

  • dashActive (D | None) – dash for disabled elements. offset is not supported.

  • colorDisabled (C) – color for disabled elements.

  • widthDisabled (int | None) – width for disabled elements.

  • dashDisabled (D | None) – dash for disabled elements. offset is not supported.

  • tags (Sequence[str]) – Sequence of tags to apply to the element. Must not include any “internal tags”, starting with :.

foci() Tuple[XY, XY]#

Calculate both focus points of the ellipse

These are the points where any outline point is equidistant from both points.

Note that since integer coordinates are used, this might be off from the “real” foci by at most half pixel.

See also

The center is the midpoint between these two. They all coincide if the ellipse is a circle.

property center: XY#

Calculate the center of the ellipse.

Note that since integer coordinates are used, this might be off from the “real” center by at most half pixel.

property leccentricity: Real#

Calculate the linear eccentricity of the ellipse.

This is a measure of how closer is the ellipse to a circle. 0 means it’s a circle, any other number less than 1 means it’s an ellipse.

Returns:

The linear eccentricity of the ellipse, as a floating point number.

property radii: Tuple[Real, Real]#

Calculate the X and Y radii of the ellipse.

Returns:

A tuple with the radius along X (horizontal) and Y (vertical) axes, as floating point numbers.

class tkmilan.diagram.EllipseSection(topleft: ~tkmilan.diagram.XY, botright: ~tkmilan.diagram.XY, style: ~tkmilan.diagram.EllipseSection_Style, rng: ~typing.Tuple[~numbers.Real, ~numbers.Real], color: ~tkmilan.diagram.C = <factory>, width: int | None = None, dash: ~tkmilan.diagram.D | None = None, colorActive: ~tkmilan.diagram.C = <factory>, widthActive: int | None = None, dashActive: ~tkmilan.diagram.D | None = None, colorDisabled: ~tkmilan.diagram.C = <factory>, widthDisabled: int | None = None, dashDisabled: ~tkmilan.diagram.D | None = None, tags: ~typing.Sequence[str] = ())#

Bases: DiagramElementSingle

Diagram Element: part of a larger Ellipse.

Represent a section of a simple Ellipse.

There is no Python documentation, see Tk canvas common options and canvas arc options. See also NMT create arc documentation.

This is a “low level” diagram element, you should use one of its higher level elements: ArcEllipse or PieEllipse.

Parameters:
  • topleft (XY) – The top left vertex (lower X and Y coordinates).

  • botright (XY) – The bottom right vertex (higher X and Y coordinates).

  • style (EllipseSection_Style) – Section style.

  • rng (Tuple[Real, Real]) – Section range. The start and end angles for the section. The angles are expressed in degrees, in a range between -360 and 360.

  • color (C) – Colour for outline and fill area, see C for colour specification.

  • width (int | None) – Width for outlines, in pixels. Optional, defaults to minimum line width.

  • dash (D | None) – Dashed outline setting. Optional, defaults to solid line.

  • colorActive (C) – color for active elements, that is, on mouse hover.

  • widthActive (int | None) – width for active elements, that is, on mouse hover.

  • dashActive (D | None) – dash for disabled elements. offset is not supported.

  • colorDisabled (C) – color for disabled elements.

  • widthDisabled (int | None) – width for disabled elements.

  • dashDisabled (D | None) – dash for disabled elements. offset is not supported.

  • tags (Sequence[str]) – Sequence of tags to apply to the element. Must not include any “internal tags”, starting with :.

Note

For style=ARC style, there is no fill area. This is checked in debug mode.

at_angle(theta: Real) XY#

Calculate a point on the correspoding ellipse, for a particular angle from the center.

The angle is expressed in degrees, in a range between -360 and 360.

Note that since integer coordinates are used, this might be off from the “real” points by at most half pixel.

Note

This does not enforce the ellipse section range, it might produce points outside the element.

property center: XY#

Calculate the center of the corresponding ellipse, for this section.

Note that since integer coordinates are used, this might be off from the “real” center by at most half pixel.

property endpoints: Tuple[XY, XY]#

Calculate endpoints of the ellipse section.

Note that since integer coordinates are used, this might be off from the “real” points by at most half pixel.

Returns:

A tuple with the point corresponding to the first and second angles in rng.

property extent: Real#

Calculate the extent of the section.

This is the delta between start and end. Expressed in degrees, between 0 and 360.

property radii: Tuple[Real, Real]#

Calculate the X and Y radii of the corresponding ellipse, for this section.

Returns:

A tuple with the radius along X (horizontal) and Y (vertical) axes, as floating point numbers.

class tkmilan.diagram.EllipseSection_Style(value)#

Bases: Enum

Style selection for EllipseSection.

Check a visual representation of the style in Tk NMT create arc or canvas arc style documentation.

ARC = 'arc'#

Draw section as a simple arc.

This means drawing a line, just the arc itself. No area is defined.

CHORD = 'chord'#

Draw section as a chord.

This means the boundaries are defined by the arc itself, plus a single line segment between the arc endpoints.

PIESLICE = 'pieslice'#

Draw section as a pie slice.

This means the boundaries are defined by arc itself, plus two line segments, between the oval center and each of the arc endpoints.

class tkmilan.diagram.GeometryLine(m: int | float | Real | None, c0: int | float | Real)#

Bases: object

A geometric line (not an element like Line), for easing some calculations. Uses real parameters.

To create this object based on other inputs, see points and point_slope.

Parameters:
  • m (Real | None) – Line slope. None means a vertical line (equivalent to infinite slope).

  • c0 (Real) – For vertical lines, it’s the x coordinate for all points. For other lines, it’s the y coordinate at x=0. See equation for the complete picture.

See also

See other geometric constructs like XY, and Vector.

__contains__(obj: Any) bool#
__contains__(obj: XY)

Calculate if the given object is contained on this line.

Supported Object Types:

Use as xy in line.

intersect_line(other: GeometryLine) XY | None#

Calculate the intersection of this line with any other line.

Parameters:

other (GeometryLine) – The other line.

Returns:

Return the intersection point, if exists. Returns None when there is not intersection, or there is an infinite number of points.

Return type:

XY | None

See also

See intersect_x and intersect_y for calculating the intersection with special lines.

intersect_x(x: int) XY | None#

Calculate the intersection of this line with a vertical line.

Parameters:

x (int) – The x coordinate for the horizontal line.

Returns:

Return the intersection point, if exists. Returns None when there is not intersection, or there is an infinite number of points.

Return type:

XY | None

See also

See intersect_line for calculating the intersection with any line.

intersect_y(y: int) XY | None#

Calculate the intersection of this line with an horizontal line.

Parameters:

y (int) – The y coordinate for the horizontal line.

Returns:

Return the intersection point, if exists. Returns None when there is not intersection, or there is an infinite number of points.

Return type:

XY | None

See also

See intersect_line for calculating the intersection with any line.

parallel_point(p: XY) GeometryLine#

Calculate the parallel line that goes through a given point.

There is only a single line parallel to the current one that goes through an external point. If the point is already in the current line, returns itself.

Parameters:

p (XY) – A point on the new line.

perpendicular_point(p: XY) GeometryLine#

Calculate the perpendicular line that goes through a given point.

There is only a single line perpendicular to the current one that goes through any point.

Parameters:

p (XY) – A point on the new line.

classmethod point_slope(p: XY, m: Real | None) GeometryLine#

Create the line that goes through a point with the given slope.

Parameters:
  • p (XY) – One of the points in the line.

  • m (Real | None) – Line slope. None means infinite slope, that is, a vertical line.

classmethod points(p1: XY, p2: XY) GeometryLine#

Create the line that goes through both points.

If both points refer to the same location, this is an error.

Parameters:
  • p1 (XY) – One of the points in the line.

  • p2 (XY) – One of the points in the line.

property equation: str#

Derive an equation for the line.

This uses the Slope-intercept form.

class tkmilan.diagram.Join(value)#

Bases: Enum

Join settings.

Check a visual representation of the style in Tk NMT join documentation.

BEVEL = 'bevel'#

A flat facet is drawn at an angle intermediate between the angles of the adjacent lines.

MITER = 'miter'#

The edges of the adjacent line segments are continued to meet at a sharp point.

ROUND = 'round'#

The join is a circle centered on the point where the adjacent line segments meet.

class tkmilan.diagram.MultiLine(points: ~typing.Sequence[~tkmilan.diagram.XY], color: ~tkmilan.diagram.C = <factory>, width: int | None = None, dash: ~tkmilan.diagram.D | None = None, arrow: ~tkmilan.diagram.A | None = None, cap: ~tkmilan.diagram.Cap = Cap.BUTT, join: ~tkmilan.diagram.Join = Join.ROUND, smooth: ~tkmilan.diagram.Smooth | None = None, colorActive: ~tkmilan.diagram.C = <factory>, widthActive: int | None = None, dashActive: ~tkmilan.diagram.D | None = None, colorDisabled: ~tkmilan.diagram.C = <factory>, widthDisabled: int | None = None, dashDisabled: ~tkmilan.diagram.D | None = None, tags: ~typing.Sequence[str] = (), forceJoin: dataclasses.InitVar[bool] = False)#

Bases: DiagramElementSingle

Diagram Element: multi-segment line.

Represent multiple line segments with common points: line segment between first and second, second and third, etc…

There is no Python documentation, see Tk canvas common options and canvas line options. See also NMT create line documentation.

Parameters:
  • points (Sequence[XY]) – Sequence of points to draw the line segments. Must have at least two points.

  • color (C) – Colour for line segments, see C for colour specification. Considers only outline.

  • width (int | None) – Width for line segments, in pixels. Optional, defaults to minimum line width.

  • dash (D | None) – Dashed line segments setting. Optional, defaults to solid line.

  • arrow (A | None) – Arrow line settings. Optional, defaults to no arrows anywhere.

  • cap (Cap) – Line capping setting. Defaults to Cap.BUTT.

  • join (Join) – Line join setting. Defaults to Join.ROUND, or Join.BEVEL when dash is set.

  • smooth (Smooth | None) – Line smoothing setting. Optional, defaults to straight line.

  • colorActive (C) – color for active elements, that is, on mouse hover.

  • widthActive (int | None) – width for active elements, that is, on mouse hover.

  • dashActive (D | None) – dash for disabled elements. offset is not supported.

  • colorDisabled (C) – color for disabled elements.

  • widthDisabled (int | None) – width for disabled elements.

  • dashDisabled (D | None) – dash for disabled elements. offset is not supported.

  • tags (Sequence[str]) – Sequence of tags to apply to the element. Must not include any “internal tags”, starting with :.

Warning

When setting dash:

  • cap is incompatible, don’t set it or keep the default.

  • join must be set to Join.BEVEL, this is forced.

class tkmilan.diagram.Polygon(points: ~typing.Sequence[~tkmilan.diagram.XY], color: ~tkmilan.diagram.C = <factory>, width: int | None = None, dash: ~tkmilan.diagram.D | None = None, join: ~tkmilan.diagram.Join = Join.ROUND, smooth: ~tkmilan.diagram.Smooth | None = None, colorActive: ~tkmilan.diagram.C = <factory>, widthActive: int | None = None, dashActive: ~tkmilan.diagram.D | None = None, colorDisabled: ~tkmilan.diagram.C = <factory>, widthDisabled: int | None = None, dashDisabled: ~tkmilan.diagram.D | None = None, tags: ~typing.Sequence[str] = ())#

Bases: DiagramElementSingle

Diagram Element: polygon.

Represent a single regular polygon.

There is no Python documentation, see Tk canvas common options and canvas polygon options. See also NMT create polygon documentation.

Parameters:
  • points (Sequence[XY]) – Sequence of points to draw the polygon. Must have at least three points.

  • color (C) – Colour for outline and fill area, see C for colour specification.

  • width (int | None) – Width for outlines, in pixels. Optional, defaults to minimum line width.

  • dash (D | None) – Dashed outline setting. Optional, defaults to solid line.

  • join (Join) – Outline join setting. Defaults to Join.ROUND.

  • smooth (Smooth | None) – Outline smoothing setting. Optional, defaults to straight line.

  • colorActive (C) – color for active elements, that is, on mouse hover.

  • widthActive (int | None) – width for active elements, that is, on mouse hover.

  • dashActive (D | None) – dash for disabled elements. offset is not supported.

  • colorDisabled (C) – color for disabled elements.

  • widthDisabled (int | None) – width for disabled elements.

  • dashDisabled (D | None) – dash for disabled elements. offset is not supported.

  • tags (Sequence[str]) – Sequence of tags to apply to the element. Must not include any “internal tags”, starting with :.

class tkmilan.diagram.Rectangle(topleft: ~tkmilan.diagram.XY, botright: ~tkmilan.diagram.XY, color: ~tkmilan.diagram.C = <factory>, width: int | None = None, dash: ~tkmilan.diagram.D | None = None, colorActive: ~tkmilan.diagram.C = <factory>, widthActive: int | None = None, dashActive: ~tkmilan.diagram.D | None = None, colorDisabled: ~tkmilan.diagram.C = <factory>, widthDisabled: int | None = None, dashDisabled: ~tkmilan.diagram.D | None = None, tags: ~typing.Sequence[str] = ())#

Bases: DiagramElementSingle

Diagram Element: simple rectangle, parallel to the axes.

Represent a simple rectangle, with sides parallel to the axes. If you need a rotated rectangle, use a Polygon.

There is no Python documentation, see Tk canvas common options and canvas rectangle options. See also NMT create rectangle documentation.

Parameters:
  • topleft (XY) – The top left vertex (lower X and Y coordinates).

  • botright (XY) – The bottom right vertex (higher X and Y coordinates).

  • color (C) – Colour for outline and fill area, see C for colour specification.

  • width (int | None) – Width for outlines, in pixels. Optional, defaults to minimum line width.

  • dash (D | None) – Dashed outline setting. Optional, defaults to solid line.

  • colorActive (C) – color for active elements, that is, on mouse hover.

  • widthActive (int | None) – width for active elements, that is, on mouse hover.

  • dashActive (D | None) – dash for disabled elements. offset is not supported.

  • colorDisabled (C) – color for disabled elements.

  • widthDisabled (int | None) – width for disabled elements.

  • dashDisabled (D | None) – dash for disabled elements. offset is not supported.

  • tags (Sequence[str]) – Sequence of tags to apply to the element. Must not include any “internal tags”, starting with :.

property center: XY#

Calculate the center of the rectangle.

Note that since integer coordinates are used, this might be off from the “real” center by at most half pixel.

property h: int#

Calculate the rectangle height.

property w: int#

Calculate the rectangle width.

Note

Not to be confused with width, the line width.

class tkmilan.diagram.Smooth(algorithm: SmoothAlgorithm = SmoothAlgorithm.BEZIER3, steps: int = 12)#

Bases: object

Line smoothing settings.

There is no Python documentation, see Tk canvas line smooth documentation.

Parameters:
  • algorithm (SmoothAlgorithm) – Line smoothing algorithm. Defaults to cubic Bézier curves.

  • steps (int) – The curve is rendered as a series of line segments. This is the amount of lines to render. Defaults to 12.

class tkmilan.diagram.SmoothAlgorithm(value)#

Bases: Enum

Line smoothing algorithm selection.

There is no Python documentation, see Tk canvas line smooth documentation.

See also

See Smooth for the usable line smoothing settings.

BEZIER2 = 'bezier'#

Draw line as series of quadratic Bézier curves.

See Wikipedia quadratic Bézier curves information.

BEZIER3 = 'raw'#

Draw line as series of cubic Bézier curves.

See Wikipedia cubic Bézier curves information.

class tkmilan.diagram.Text(point: ~tkmilan.diagram.XY, text: str, color: ~tkmilan.diagram.C = <factory>, anchor: ~tkmilan.model.CP = CP.center, angle: ~numbers.Real = 0.0, justify: ~tkmilan.model.Justification = Justification.Left, font: ~typing.Any | None = None, colorActive: ~tkmilan.diagram.C = <factory>, colorDisabled: ~tkmilan.diagram.C = <factory>, tags: ~typing.Sequence[str] = ())#

Bases: DiagramElementSingle

Diagram Element: text.

Represent a text string anchored on a specific coordinate, possibly rotated.

There is no Python documentation, see Tk canvas common options and canvas text options. See also NMT create text documentation.

Parameters:
  • point (XY) – Anchor point to locate the text

  • text (str) – The text to draw

  • color (C) – Text colour, see C for colour specification. Considers only fill.

  • anchor (CP) – Where to anchor the text, related to point.

  • angle (Real) – Rotate the text, in degrees. Defaults to no rotation.

  • justify (Justification) – How to justify multi-line text. See model.Justification.

  • colorActive (C) – color for active elements, that is, on mouse hover.

  • colorDisabled (C) – color for disabled elements.

class tkmilan.diagram.Vector(dx: int, dy: int)#

Bases: object

A vector with integer coordinates.

Parameters:
  • dx (int) – The x coordinate.

  • dy (int) – The y coordinate.

__neg__() Vector#

Calculate the negated vector.

Use as -vector.

Returns:

A new Vector with negated coordinates.

Return type:

Vector

Note

This should be similar to vector.scale(-1).

See also

See other geometric constructs like XY, and GeometryLine.

scale(both: Real | None = None, *, sx: Real | None = None, sy: Real | None = None) Vector#

Calculate a scaled vector.

Note the scaling factors do not need to be integers, they are coerced to integers after the calculation using nround.

Choose to either scale both coordinates by the same factor using both, or individually using sx/sy. Do not combine both methods, or results might be unpredictable. When not given, the other coordinates remain the same.

Parameters:
  • both (Real | None) – Scale both coordinates by this factor.

  • sx (Real | None) – Scale the x coordinate.

  • sy (Real | None) – Scale the y coordinate.

Returns:

A new Vector object.

Return type:

Vector

size() Real#

Calculate the vector magnitude, that it, it’s length.

Returns:

The vector magnitude, a real number.

Return type:

Real

property tuple: Tuple[int, int]#

Represent the vector as a coordinate tuple.

Useful to actually pass this information to most functions.

class tkmilan.diagram.XY(x: int, y: int)#

Bases: object

A location with integer coordinates.

Parameters:
  • x (int) – The x coordinate.

  • y (int) – The y coordinate.

__add__(obj: Any)#
__add__(obj: Vector)

Calculate the sum of the given object with this location.

Supported Object Types:

Use as xy + vector.

__sub__(obj: Any)#
__sub__(obj: Vector)

Calculate the subtraction of the given object with this location.

Supported Object Types:

Use as xy - vector.

See also

See other geometric constructs like Vector, and GeometryLine.

edistance(other: XY) Real#

Calculate the Euclidian distance between this and other point.

Returns:

The distance between both points, as a floating point number.

Return type:

Real

vto(other: XY) Vector#

Calculate the Vector joining this and other point.

The result is a vector that when added to this point, results in the other point.

Parameters:

other (XY) – The other XY, see the description above.

Returns:

A new Vector object.

Return type:

Vector

property tuple: Tuple[int, int]#

Represent the vector as a coordinate tuple.

Useful to actually pass this information to most functions.

tkmilan.diagram.ArcCircleCenter(c: XY, radius: int, **kwargs) EllipseSection#

Draw a circle arc, from a center point and its radius.

Note that since integer coordinates are used, this might be off from the “real” radius by at most half pixel.

Parameters:
  • c (XY) – Center point

  • radius (int) – Circle radius.

  • kwargs – Passed to ArcEllipse.

tkmilan.diagram.ArcEllipse(**kwargs) EllipseSection#

Draw a simple ellipse arc, parallel to the axes.

The arguments are similar to Ellipse. Uses an EllipseSection with a static style (ARC).

Parameters:

kwargs – Passed to EllipseSection

tkmilan.diagram.ArcEllipseCenter(c: XY, a: int, b: int, **kwargs) EllipseSection#

Draw a simple ellipse arc, from a center point to its axes.

Parameters:
  • c (XY) – Center point.

  • a (int) – Semi-Axis parallel to X.

  • b (int) – Semi-Axis parallel to Y.

  • kwargs – Passed to ArcEllipse.

tkmilan.diagram.CircleCenter(c: XY, radius: int, **kwargs) Ellipse#

Draw a circle, from a center point and its radius.

Note that since integer coordinates are used, this might be off from the “real” radius by at most half pixel.

Parameters:
  • c (XY) – Center point

  • radius (int) – Circle radius.

  • kwargs – Passed to Ellipse.

tkmilan.diagram.DoubleMultiLine(*args, widthSmall: int, deltaWidth: int = 2, colorBig: C, colorSmall: C, **kwargs) DiagramElementMultiple#

Draw two MultiLine on the same location, with different sizes.

The “big” one is drawn first (on the back), with a larger deltaWidth size.

The size can be controlled using widthSmall and deltaWidth.

It’s equivalent to three lines, like this:

-------------
BIG  size=w/D
-------------
small  size=w
-------------
BIG  size=w/D
-------------

This is their relation:

w = widthSmall
widthBig = deltaWidth * w
D = 2 / (deltaWidth - 1)

Examples:

d = 2 ==> D = 2
d = 3 ==> D = 1
d = 4 ==> D = 2/3
tkmilan.diagram.EllipseCenter(c: XY, a: int, b: int, **kwargs) Ellipse#

Draw a simple ellipse, from a center point and its axes.

Parameters:
  • c (XY) – Center point.

  • a (int) – Semi-Axis parallel to X.

  • b (int) – Semi-Axis parallel to Y.

  • kwargs – Passed to Ellipse.

tkmilan.diagram.Line(p1: XY, p2: XY, **kwargs) MultiLine#

Draw a single line segment.

Parameters:
  • p1 (XY) – First line segment vertex.

  • p2 (XY) – Second line segment vertex.

  • kwargs – Passed to MultiLine.

tkmilan.diagram.LineVector(p: XY, v: Vector, **kwargs) MultiLine#

Draw a single line segment, from a point following a vector.

Parameters:
  • p (XY) – First line segment vertex.

  • v (Vector) – Vector to sum to p, to obtain the second line segment vertex.

  • kwargs – Passed to MultiLine.

tkmilan.diagram.PieEllipse(**kwargs) EllipseSection#

Draw a “pie” slice of a simple ellipse, parallel to the axes.

The arguments are similar to Ellipse. Uses an EllipseSection with a static style (PIESLICE).

Parameters:

kwargs – Passed to EllipseSection

tkmilan.diagram.RectangleCenter(c: XY, size_x: int, size_y: int, **kwargs) Rectangle#

Draw a simple rectangle, from a center point and its size.

Note that since integer coordinates are used, this might be off from the “real” center by at most half pixel.

Parameters:
  • c (XY) – Center point.

  • size_x (int) – Size of rectangle, side parallel to X axis.

  • size_y (int) – Size of rectangle, side parallel to Y axis.

  • kwargs – Passed to Rectangle.

tkmilan.diagram.SquareCenter(c: XY, size: int, *args, **kwargs) Rectangle#

Draw a simple square, from a center point and its size.

Note that since integer coordinates are used, this might be off from the “real” center by at most half pixel.

Parameters:
  • c (XY) – Center point.

  • size (int) – Side of the square.

  • kwargs – Passed to Rectangle.

tkmilan.diagram.VectorH(dx: int, *args, **kwargs) Vector#

An horizontal Vector.

Requires only the x coordinate.

See also

Wrapper for Vector.

tkmilan.diagram.VectorPolar(r: Real, theta: Real) Vector#

A “polar” Vector, defined by radius and angle.

See Wikipedia polar coordinates information.

Parameters:
  • r (Real) – Radius

  • theta (Real) – Vector angle, in degrees.

tkmilan.diagram.VectorV(dy: int, *args, **kwargs) Vector#

A vertical Vector.

Requires only the y coordinate.

See also

Wrapper for Vector.

tkmilan.diagram.nfloat(n: SupportsInt | SupportsFloat | SupportsComplex) float#

Convert any number to floating point.

For production binaries, this is just float.

tkmilan.diagram.nround(n: SupportsInt | SupportsFloat | SupportsComplex) int#

Round any number to integer.

For production binaries, this is just int.

tkmilan.diagram.GeneratorElementT#

Type-Checking variable type for Diagram drawing functions.

Can be a DiagramElement, or a tuple of DiagramElement and str, used as a marker for the element in the renderer.

alias of Union[DiagramElement, Tuple[DiagramElement, str]]