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
|
Round any number to integer. |
|
Convert any number to floating point. |
Type-Checking variable type for |
Functions
|
Draw a circle arc, from a center point and its radius. |
|
Draw a simple ellipse arc, parallel to the axes. |
|
Draw a simple ellipse arc, from a center point to its axes. |
|
Draw a circle, from a center point and its radius. |
|
Draw two |
|
Draw a simple ellipse, from a center point and its axes. |
|
Draw a single line segment. |
|
Draw a single line segment, from a point following a vector. |
|
Draw a "pie" slice of a simple ellipse, parallel to the axes. |
|
Draw a simple rectangle, from a center point and its size. |
|
Draw a simple square, from a center point and its size. |
|
An horizontal |
|
A "polar" |
|
A vertical |
|
Convert any number to floating point. |
|
Round any number to integer. |
Classes
|
Arrow settings. |
|
Colour settings. |
|
Cap settings. |
|
Dash settings. |
|
Diagram generator class. |
Common diagram element class. |
|
|
Aggregator for multiple |
Common diagram single element class. |
|
|
Diagram Element: simple ellipse, parallel to the axes. |
|
Diagram Element: part of a larger |
|
Style selection for |
|
A geometric line (not an element like |
|
Join settings. |
|
Diagram Element: multi-segment line. |
|
Diagram Element: polygon. |
|
Diagram Element: simple rectangle, parallel to the axes. |
|
Line smoothing settings. |
|
Line smoothing algorithm selection. |
|
Diagram Element: text. |
|
A vector with integer coordinates. |
|
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:
objectArrow settings.
Check a visual representation of the arrow head shape on the
arrowshapesection inTkNMU 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
Falseif no otherat*settings are is given.atEnd (bool) – Include an arrow head on the end of the line. Optional, defaults to
Trueif no otherat*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:
objectColour 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.
- class tkmilan.diagram.Cap(value)#
Bases:
EnumCap settings.
Check a visual representation of the style in
TkNMT 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:
objectDash settings.
The
patternis 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 initialoffset, can even be negative.Check as visual representation of the dash patterns in
TkNMT 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:
ABCDiagram generator class.
This should be subclassesed and it’s function implemented with
iterthat 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:
setup_bg_b: Background Back (z=-1).setup_fg: Foreground (z=0)setup_bg_f: Background Front (z=1).
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
Noneif 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
Noneif 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
Noneif the render had a problem. On production binaries, this is an error.
- DISABLEDBACKGROUND: str | None = None#
Canvas background colour, when disabled.
Optional. See
Cfor 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:
ABCCommon 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
DiagramElementSingleobjects, recursively.
- class tkmilan.diagram.DiagramElementMultiple(*items: DiagramElement)#
Bases:
DiagramElementAggregator for multiple
DiagramElementobjects.Certain diagram elements only make sense together, group them here.
- class tkmilan.diagram.DiagramElementSingle#
Bases:
DiagramElementCommon 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:
DiagramElementSingleDiagram 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
Tkcanvas 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
Cfor 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) –
colorfor active elements, that is, on mouse hover.widthActive (int | None) –
widthfor active elements, that is, on mouse hover.dashActive (D | None) –
dashfor disabled elements.offsetis not supported.colorDisabled (C) –
colorfor disabled elements.widthDisabled (int | None) –
widthfor disabled elements.dashDisabled (D | None) –
dashfor disabled elements.offsetis 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
centeris 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.
0means it’s a circle, any other number less than1means 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:
DiagramElementSingleDiagram Element: part of a larger
Ellipse.Represent a section of a simple
Ellipse.There is no Python documentation, see
Tkcanvas 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:
ArcEllipseorPieEllipse.- 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
-360and360.color (C) – Colour for outline and fill area, see
Cfor 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) –
colorfor active elements, that is, on mouse hover.widthActive (int | None) –
widthfor active elements, that is, on mouse hover.dashActive (D | None) –
dashfor disabled elements.offsetis not supported.colorDisabled (C) –
colorfor disabled elements.widthDisabled (int | None) –
widthfor disabled elements.dashDisabled (D | None) –
dashfor disabled elements.offsetis not supported.tags (Sequence[str]) – Sequence of tags to apply to the element. Must not include any “internal tags”, starting with
:.
Note
For
style=ARCstyle, 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
-360and360.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
0and360.
- 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:
EnumStyle selection for
EllipseSection.Check a visual representation of the style in
TkNMT 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:
objectA geometric line (not an element like
Line), for easing some calculations. Uses real parameters.To create this object based on other inputs, see
pointsandpoint_slope.- Parameters:
m (Real | None) – Line slope.
Nonemeans a vertical line (equivalent to infinite slope).c0 (Real) – For vertical lines, it’s the
xcoordinate for all points. For other lines, it’s theycoordinate atx=0. Seeequationfor the complete picture.
- __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
Nonewhen there is not intersection, or there is an infinite number of points.- Return type:
XY | None
See also
See
intersect_xandintersect_yfor 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
xcoordinate for the horizontal line.- Returns:
Return the intersection point, if exists. Returns
Nonewhen there is not intersection, or there is an infinite number of points.- Return type:
XY | None
See also
See
intersect_linefor 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
ycoordinate for the horizontal line.- Returns:
Return the intersection point, if exists. Returns
Nonewhen there is not intersection, or there is an infinite number of points.- Return type:
XY | None
See also
See
intersect_linefor 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.
Nonemeans 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.
- property equation: str#
Derive an equation for the line.
This uses the Slope-intercept form.
- class tkmilan.diagram.Join(value)#
Bases:
EnumJoin settings.
Check a visual representation of the style in
TkNMT 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:
DiagramElementSingleDiagram 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
Tkcanvas 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
Cfor colour specification. Considers onlyoutline.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.
join (Join) – Line join setting. Defaults to
Join.ROUND, orJoin.BEVELwhendashis set.smooth (Smooth | None) – Line smoothing setting. Optional, defaults to straight line.
colorActive (C) –
colorfor active elements, that is, on mouse hover.widthActive (int | None) –
widthfor active elements, that is, on mouse hover.dashActive (D | None) –
dashfor disabled elements.offsetis not supported.colorDisabled (C) –
colorfor disabled elements.widthDisabled (int | None) –
widthfor disabled elements.dashDisabled (D | None) –
dashfor disabled elements.offsetis 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:capis incompatible, don’t set it or keep the default.joinmust be set toJoin.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:
DiagramElementSingleDiagram Element: polygon.
Represent a single regular polygon.
There is no Python documentation, see
Tkcanvas 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
Cfor 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) –
colorfor active elements, that is, on mouse hover.widthActive (int | None) –
widthfor active elements, that is, on mouse hover.dashActive (D | None) –
dashfor disabled elements.offsetis not supported.colorDisabled (C) –
colorfor disabled elements.widthDisabled (int | None) –
widthfor disabled elements.dashDisabled (D | None) –
dashfor disabled elements.offsetis 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:
DiagramElementSingleDiagram 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
Tkcanvas 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
Cfor 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) –
colorfor active elements, that is, on mouse hover.widthActive (int | None) –
widthfor active elements, that is, on mouse hover.dashActive (D | None) –
dashfor disabled elements.offsetis not supported.colorDisabled (C) –
colorfor disabled elements.widthDisabled (int | None) –
widthfor disabled elements.dashDisabled (D | None) –
dashfor disabled elements.offsetis 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:
objectLine smoothing settings.
There is no Python documentation, see
Tkcanvas 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:
EnumLine smoothing algorithm selection.
There is no Python documentation, see
Tkcanvas line smooth documentation.See also
See
Smoothfor 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:
DiagramElementSingleDiagram Element: text.
Represent a text string anchored on a specific coordinate, possibly rotated.
There is no Python documentation, see
Tkcanvas 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
Cfor colour specification. Considers onlyfill.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) –
colorfor active elements, that is, on mouse hover.colorDisabled (C) –
colorfor disabled elements.
- class tkmilan.diagram.Vector(dx: int, dy: int)#
Bases:
objectA vector with integer coordinates.
- Parameters:
dx (int) – The
xcoordinate.dy (int) – The
ycoordinate.
- __neg__() Vector#
Calculate the negated vector.
Use as
-vector.Note
This should be similar to
vector.scale(-1).
See also
See other geometric constructs like
XY, andGeometryLine.- 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 usingsx/sy. Do not combine both methods, or results might be unpredictable. When not given, the other coordinates remain the same.
- 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:
objectA location with integer coordinates.
- Parameters:
x (int) – The
xcoordinate.y (int) – The
ycoordinate.
- __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, andGeometryLine.- edistance(other: XY) Real#
Calculate the Euclidian distance between this and
otherpoint.- Returns:
The distance between both points, as a floating point number.
- Return type:
Real
- vto(other: XY) Vector#
Calculate the
Vectorjoining this andotherpoint.The result is a vector that when added to this point, results in the
otherpoint.
- 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 anEllipseSectionwith 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.
- tkmilan.diagram.DoubleMultiLine(*args, widthSmall: int, deltaWidth: int = 2, colorBig: C, colorSmall: C, **kwargs) DiagramElementMultiple#
Draw two
MultiLineon the same location, with different sizes.The “big” one is drawn first (on the back), with a larger
deltaWidthsize.The size can be controlled using
widthSmallanddeltaWidth.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.
- tkmilan.diagram.LineVector(p: XY, v: Vector, **kwargs) MultiLine#
Draw a single line segment, from a point following a vector.
- tkmilan.diagram.PieEllipse(**kwargs) EllipseSection#
Draw a “pie” slice of a simple ellipse, parallel to the axes.
The arguments are similar to
Ellipse. Uses anEllipseSectionwith 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.
- 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.
- tkmilan.diagram.VectorH(dx: int, *args, **kwargs) Vector#
An horizontal
Vector.Requires only the
xcoordinate.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
ycoordinate.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
Diagramdrawing functions.Can be a
DiagramElement, or a tuple ofDiagramElementandstr, used as a marker for the element in the renderer.alias of
Union[DiagramElement,Tuple[DiagramElement,str]]