Defining Styles
How an arrow should be drawn. |
|
How a 2D bounding box should be drawn." |
|
How a line/contour should be drawn. |
|
How a marker/keypoint should be drawn. |
|
How text should be rendered. |
Arrow Style
- class viren2d.ArrowStyle
Bases:
LineStyleHow an arrow should be drawn.
Example
>>> style = viren2d.ArrowStyle( >>> width=5, color='black', >>> tip_length=0.3, tip_angle=20, >>> tip_closed=True, double_headed=False, >>> dash_pattern=[], dash_offset=0.0, >>> cap='round', join='miter')
Methods:
Checks for equality.
Creates a customized arrow style.
Checks for inequality.
ArrowStyleinstances can be pickled.Returns a dictionary representation.
Returns a deep copy.
Returns a verbose string representation to facilitate debugging.
Checks if this style contains a dash stroke pattern.
Checks if the style would lead to a drawable arrow.
Returns the length of the arrow head for the given shaft length.
Attributes:
How to render the endpoints" of the line (or dash strokes).
Color of the line.
Offset into the pattern at which the dash stroke begins.
Dash pattern defined as list of on/off strokes.
If
True, arrow heads will be drawn on both ends.How to render the junctions of the line segments.
Interior angle (in degrees) between shaft and tip.
If
True, the arrow head will be filled.Length of the arrow tip.
Width/thickness in pixels.
- __eq__(self: viren2d.ArrowStyle, arg0: viren2d.ArrowStyle) bool
Checks for equality.
- __getstate__(self: viren2d.ArrowStyle) tuple
- __init__(self: viren2d.ArrowStyle, width: float = 2.0, color: viren2d.Color = viren2d.Color(red=0, green=0.5, blue=1, alpha=1), tip_length: float = 0.2, tip_angle: float = 20.0, tip_closed: bool = False, double_headed: bool = False, dash_pattern: List[float] = [], dash_offset: float = 0.0, cap: viren2d.LineCap = <LineCap.Round>, join: viren2d.LineJoin = <LineJoin.Miter>) None
Creates a customized arrow style.
- Parameters:
width – Width in pixels as
float.color – Arrow color as
Color.tip_length – Length of the arrow tip as
float. If it is between[0, 1], it is interpreted as percentage of the shaft length. Otherwise, it represents the absolute length in pixels.tip_angle – Interior angle between shaft and tip, specified in degrees as
float.tip_closed – Set
Trueto fill the tip (typebool).double_headed – Set True to draw arrow tips on both ends of the shaft (type
bool).dash_pattern – Dash pattern defined as
listoffloat, specifying the on/off strokes. Refer to the documentation of the class memberdash_patternfor details.dash_offset – Optional offset (length as
float) into the pattern, at which the dash stroke begins. Refer to the class memberdash_offsetfor details.cap – A
LineCapenum, specifying how to render the line endpoints. This parameter can also be set using the corresponding string representation, e.g.'round'.join – A
LineJoinenum, specifying how to render the junctions of multi-segment lines. This parameter can also be set using the corresponding string representation, e.g.'miter'.
- __ne__(self: viren2d.ArrowStyle, arg0: viren2d.ArrowStyle) bool
Checks for inequality.
- __setstate__(self: viren2d.ArrowStyle, arg0: tuple) None
ArrowStyleinstances can be pickled.
- as_dict(self: viren2d.ArrowStyle) dict
Returns a dictionary representation.
- property cap
How to render the endpoints” of the line (or dash strokes).
In addition to the enumeration values, you can use the corresponding string representation to set this member:
>>> style.cap = viren2d.LineCap.Round >>> style.cap = 'round'
- Type:
- property color
Color of the line.
Example:
>>> style.color = viren2d.Color(1, 0, 1) >>> style.color = viren2d.RGBa(255, 0, 255) >>> style.color = 'magenta'
- Type:
- copy(self: viren2d.ArrowStyle) viren2d.ArrowStyle
Returns a deep copy.
Corresponding C++ API: Copy constructor of
viren2d::ArrowStyle.
- property dash_offset
Offset into the pattern at which the dash stroke begins.
If the strokes of a
dash_patterndo not align nicely, adjust this offset (measured in pixels).- Type:
- property dash_pattern
Dash pattern defined as list of on/off strokes.
A dash pattern is a list of positive values. Each value defines the length (in pixels) of alternating on and off segments of the line. For solid lines, this list must be empty.
>>> style.dash_pattern = [20, 30, 40, 10] # Would result in: '__ ____ __ ____ __ ____ __ ____ __ ____ __ ____ ...'
- detailed_str(self: viren2d.LineStyle) str
Returns a verbose string representation to facilitate debugging.
- is_dashed(self: viren2d.LineStyle) bool
Checks if this style contains a dash stroke pattern.
- is_valid(self: viren2d.ArrowStyle) bool
Checks if the style would lead to a drawable arrow.
- property join
How to render the junctions of the line segments.
In addition to the enumeration values, you can use the corresponding string representation to set this member:
>>> style.join = viren2d.LineJoin.Miter >>> style.cap = 'miter'
- Type:
- property tip_length
Length of the arrow tip.
If the value is between
[0, 1], it is interpreted as percentage of the arrow’s shaft length. Otherwise, it represents the absolute length in pixels.- Type:
- tip_length_for_shaft(self: viren2d.ArrowStyle, shaft_length: float) float
Returns the length of the arrow head for the given shaft length.
Bounding Box Style
Warning
TODO documentation + cheat sheet
- class viren2d.BoundingBox2DStyle
How a 2D bounding box should be drawn.”
Example
>>> line_style = viren2d.LineStyle( >>> width=7, color='navy-blue', >>> dash_pattern=[], dash_offset=0.0, >>> cap='round', join='miter') >>> text_style = viren2d.TextStyle( >>> family='monospace', size=18, >>> color='navy-blue', bold=True, >>> italic=False, line_spacing=1.1, >>> halign='left', valign='top') >>> box_style = viren2d.BoundingBox2DStyle( >>> line_style=line_style, text_style=text_style, >>> box_fill_color='same!20', text_fill_color='white!60', >>> clip_label=True)
Methods:
Checks for equality.
Creates a customized bounding box style.
Checks for inequality.
BoundingBox2DStyleinstances can be pickled.Returns a deep copy.
Returns
Trueif the style allows rendering a 2D bounding box.Attributes:
Fill color of the bounding box.
Set to
Trueto clip the label at the bounding box edges.Padding between bounding box edges and label text.
How to draw the bounding box contour.
Fill color of the text box, i.e. the label background.
How to render the label.
- __eq__(self: viren2d.BoundingBox2DStyle, arg0: viren2d.BoundingBox2DStyle) bool
Checks for equality.
- __getstate__(self: viren2d.BoundingBox2DStyle) tuple
- __init__(self: viren2d.BoundingBox2DStyle, line_style: viren2d.LineStyle = <LineStyle(2.0px, #007fff, solid)>, text_style: viren2d.TextStyle = <TextStyle("monospace", 16px, ls=1.2, left, top, #000000)>, box_fill_color: viren2d.Color = viren2d.Color.Same.with_alpha(0.1), text_fill_color: viren2d.Color = viren2d.Color.Same.with_alpha(0.5), label_padding: viren2d.Vec2d = viren2d.Vec2d(5, 5), clip_label: bool = True) None
Creates a customized bounding box style.
- Parameters:
line_style – A
LineStylespecifying how to render the box outline.text_style – A
TextStylespecifying how to render the label text.box_fill_color – Optional
Colorto fill the box.text_fill_color – Optional
Colorto fill the background of the label.label_padding – Padding between the nearest bounding box edges and the label as
Vec2d.clip_label – If
True, the label will be clipped if it exceeds the bounding box.
- __ne__(self: viren2d.BoundingBox2DStyle, arg0: viren2d.BoundingBox2DStyle) bool
Checks for inequality.
- __setstate__(self: viren2d.BoundingBox2DStyle, arg0: tuple) None
BoundingBox2DStyleinstances can be pickled.
- copy(self: viren2d.BoundingBox2DStyle) viren2d.BoundingBox2DStyle
Returns a deep copy.
Corresponding C++ API: Copy constructor of
viren2d::BoundingBox2DStyle.
- is_valid(self: viren2d.BoundingBox2DStyle) bool
Returns
Trueif the style allows rendering a 2D bounding box.
Line Style
- class viren2d.LineStyle
How a line/contour should be drawn.
Note that several
draw_xxxmethods of thePainteralso accept the special memberLineStyle.Invalid, which indicates that a shape should only be filled, but it’s contour should not be drawn. Alternatively,Nonewill also be implicitly converted toLineStyle.Invalidwherever a LineStyle object is expected.Set the line
widthto an odd value to avoid anti-aliasing effects.Example
>>> style = viren2d.LineStyle( >>> width=7, color='crimson', >>> dash_pattern=[20, 10], dash_offset=0.0, >>> cap='round', join='miter')
Note that depending on the selected
cap(orjoin), the corresponding line (or joints) may start/end not exactly where you specified. If you want pixel-accurate start/end in combination with a particular cap/join, usecap_offset()(orjoin_offset()). For example:>>> # Choose a cap which results in an offset: >>> line_style = viren2d.LineStyle(cap='round') >>> >>> # Endpoints of our line: >>> start = viren2d.Vec2d(10, 10) >>> end = viren2d.Vec2d(100, 100) >>> >>> # Now, to draw a line exactly from `start` to `end`, >>> # we adjust the endpoints: >>> unit_dir = start.direction_vector(end).unit_vector() >>> start += line_style.cap_offset() * unit_dir >>> end -= line_style.cap_offset() * unit_dir
Methods:
Checks for equality.
Overloaded function.
Checks for inequality.
LineStyleinstances can be pickled.Returns a dictionary representation.
Computes how much the line cap will extend the line's start/end.
Returns a deep copy.
Returns a verbose string representation to facilitate debugging.
Checks if this style contains a dash stroke pattern.
Checks if the style would lead to a drawable line.
Computes how much a line join will extend the joint.
Attributes:
How to render the endpoints" of the line (or dash strokes).
Color of the line.
Offset into the pattern at which the dash stroke begins.
Dash pattern defined as list of on/off strokes.
How to render the junctions of the line segments.
Width/thickness in pixels.
- __eq__(self: viren2d.LineStyle, arg0: viren2d.LineStyle) bool
Checks for equality.
- __getstate__(self: viren2d.LineStyle) tuple
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: viren2d.LineStyle, width: float = 2.0, color: viren2d.Color = viren2d.Color(red=0, green=0.5, blue=1, alpha=1), dash_pattern: List[float] = [], dash_offset: float = 0.0, cap: viren2d.LineCap = <LineCap.Butt>, join: viren2d.LineJoin = <LineJoin.Miter>) -> None
Creates a customized line style.
- Parameters:
width – Width in pixels as
float.color – Line color as
Color.dash_pattern – Dash pattern defined as
list[float]of on/off strokes, refer to the class memberdash_patternfor details.dash_offset – Optional offset into the pattern, at which the dash stroke begins (as
float). Refer to the class memberdash_offsetfor details.cap – A
LineCapenum, specifying how to render the line endpoints. This parameter can also be set using the corresponding string representation, e.g.'round'.join – A
LineJoinenum, specifying how to render the junctions of multi-segment lines. This parameter can also be set using the corresponding string representation, e.g.'miter'.
__init__(self: viren2d.LineStyle, none: None) -> None
Overloaded constructor to implicitly convert
Nonetoviren2d.LineStyle.Invalid.Several drawing methods of the
Paintersupport skipping the contour and only filling a shape. For example:>>> painter.draw_rect(rect, line_style=None, fill_color='blue!40')
- __ne__(self: viren2d.LineStyle, arg0: viren2d.LineStyle) bool
Checks for inequality.
- __setstate__(self: viren2d.LineStyle, arg0: tuple) None
LineStyleinstances can be pickled.
- as_dict(self: viren2d.LineStyle) dict
Returns a dictionary representation.
Convenience method to initialize an
ArrowStylefrom aLineStylevia dictionary unpacking (aka splat operator):>>> arrow_style = viren2d.ArrowStyle( >>> **line_style.as_dict(), >>> tip_length=0.3)
- property cap
How to render the endpoints” of the line (or dash strokes).
In addition to the enumeration values, you can use the corresponding string representation to set this member:
>>> style.cap = viren2d.LineCap.Round >>> style.cap = 'round'
- Type:
- cap_offset(self: viren2d.LineStyle) float
Computes how much the line cap will extend the line’s start/end.
- property color
Color of the line.
Example:
>>> style.color = viren2d.Color(1, 0, 1) >>> style.color = viren2d.RGBa(255, 0, 255) >>> style.color = 'magenta'
- Type:
- copy(self: viren2d.LineStyle) viren2d.LineStyle
Returns a deep copy.
Corresponding C++ API: Copy constructor of
viren2d::LineStyle.
- property dash_offset
Offset into the pattern at which the dash stroke begins.
If the strokes of a
dash_patterndo not align nicely, adjust this offset (measured in pixels).- Type:
- property dash_pattern
Dash pattern defined as list of on/off strokes.
A dash pattern is a list of positive values. Each value defines the length (in pixels) of alternating on and off segments of the line. For solid lines, this list must be empty.
>>> style.dash_pattern = [20, 30, 40, 10] # Would result in: '__ ____ __ ____ __ ____ __ ____ __ ____ __ ____ ...'
- detailed_str(self: viren2d.LineStyle) str
Returns a verbose string representation to facilitate debugging.
- is_dashed(self: viren2d.LineStyle) bool
Checks if this style contains a dash stroke pattern.
- is_valid(self: viren2d.LineStyle) bool
Checks if the style would lead to a drawable line.
- property join
How to render the junctions of the line segments.
In addition to the enumeration values, you can use the corresponding string representation to set this member:
>>> style.join = viren2d.LineJoin.Miter >>> style.cap = 'miter'
- Type:
- join_offset(self: viren2d.LineStyle, interior_angle: float, miter_limit: float = 10.0) float
Computes how much a line join will extend the joint.
The
interior_angleis the angle between two line segments in degrees. This method needs to know themiter_limitbecause Cairo switches fromMITERtoBEVELif themiter_limitis exceeded. Refer to the Cairo documentation for details.
Marker Style
- class viren2d.MarkerStyle
How a marker/keypoint should be drawn.
Example
>>> style = viren2d.MarkerStyle( >>> marker='*', size=10, color='navy-blue!80', >>> thickness=1, filled=True, >>> cap='round', join='miter')
Methods:
Checks for equality.
Creates a customized marker style.
Checks for inequality.
MarkerStyleinstances can be pickled.Computes how much the line cap will extend the start/end of the lines.
Returns a deep copy.
Returns
Trueif this marker would be filled.Checks if this style would lead to a drawable marker.
Computes how much a line join will extend the joint.
Attributes:
Can be used to improve the contrast of the marker.
Can be used to improve the contrast, see
bg_border.How to render the endpoints of the marker's contour.
Color of the marker's contour or fill (depending on
filled).If
True, the marker should be filled withcolor.How to render the junctions of the marker's contour.
Marker shape.
Marker size in pixels.
Thickness of the marker's contour.
- __eq__(self: viren2d.MarkerStyle, arg0: viren2d.MarkerStyle) bool
Checks for equality.
- __getstate__(self: viren2d.MarkerStyle) tuple
- __init__(self: viren2d.MarkerStyle, marker: viren2d.Marker = viren2d.Marker('o'), size: float = 10.0, thickness: float = 3.0, color: viren2d.Color = viren2d.Color(red=0, green=0.5, blue=1, alpha=1), filled: bool = False, bg_border: float = 0.0, bg_color: viren2d.Color = viren2d.Color.Invalid, cap: viren2d.LineCap = <LineCap.Round>, join: viren2d.LineJoin = <LineJoin.Miter>) None
Creates a customized marker style.
- Parameters:
marker – Shape as
Markerenumeration value or its character representation.size – Marker size in pixels as
float.thickness – Width/thickness of the contour in pixels as
float.color – The
Colorused for drawing its contour or filling.filled – If
True(and the shape allwos), the marker will be filled.bg_border – Can be used to improve the contrast of the marker. If
bg_coloris valid, a circle (or square for's') will be drawn behind the actual marker. Size of this circle will besize + 2 * bg_border.bg_color – The
Colorto improve the contrast, seebg_thickness.cap – A
LineCapenum, specifying how to render the line endpoints. This parameter can also be set via the corresponding string representation, e.g.'round'.join – A
LineJoinenum, specifying how to render the junctions of multi-segment lines. This parameter can also be set via the corresponding string representation, e.g.'miter'.
- __ne__(self: viren2d.MarkerStyle, arg0: viren2d.MarkerStyle) bool
Checks for inequality.
- __setstate__(self: viren2d.MarkerStyle, arg0: tuple) None
MarkerStyleinstances can be pickled.
- property bg_border
Can be used to improve the contrast of the marker. If
bg_coloris valid, a circle (or square for's') will be drawn behind the actual marker. Size of this circle will besize+ 2 *bg_border.- Type:
- property cap
How to render the endpoints of the marker’s contour.
In addition to the enumeration values, you can use the corresponding string representation to set this member:
>>> style.cap = viren2d.LineCap.Round >>> style.cap = 'round'
- Type:
- cap_offset(self: viren2d.MarkerStyle) float
Computes how much the line cap will extend the start/end of the lines.
- copy(self: viren2d.MarkerStyle) viren2d.MarkerStyle
Returns a deep copy.
Corresponding C++ API: Copy constructor of
viren2d::MarkerStyle.
- property filled
If
True, the marker should be filled withcolor.Note that some marker shapes cannot be filled (e.g
'+'or'o'), whereas some shapes must be filled (e.g.'.'). For such shapes, the value offilledwill be ignored.- Type:
- is_filled(self: viren2d.MarkerStyle) bool
Returns
Trueif this marker would be filled.Note that this may differ from its
filledmember: Some marker shapes cannot be filled (e.g'+'or'o'), whereas some shapes must be filled (e.g.'.').
- is_valid(self: viren2d.MarkerStyle) bool
Checks if this style would lead to a drawable marker.
- property join
How to render the junctions of the marker’s contour.
In addition to the enumeration values, you can use the corresponding string representation to set this member:
>>> style.join = viren2d.LineJoin.Miter >>> style.join = 'miter'
- Type:
- join_offset(self: viren2d.MarkerStyle, interior_angle: float, miter_limit: float = 10.0) float
Computes how much a line join will extend the joint.
The
interior_angleis the angle between two line segments in degrees. This method needs to know themiter_limitbecause Cairo switches fromMITERtoBEVELif themiter_limitis exceeded. Refer to the Cairo documentation for details.
- property marker
Marker shape.
In addition to the enumeration values, you can use the character codes to set this member:
>>> style.marker = viren2d.Marker.Cross >>> style.marker = 'x'
- Type:
Text Style
Cheat Sheet for Anchor:
- class viren2d.TextStyle
How text should be rendered.
Corresponding C++ API:
viren2d::TextStyle.Example
>>> text_style = viren2d.TextStyle( >>> family='monospace', size=18, >>> color='navy-blue', bold=True, >>> italic=False, line_spacing=1.1, >>> halign='left', valign='top')
Methods:
Checks for equality.
Creates a customized text style.
Checks for inequality.
TextStyleinstances can be pickled.Returns a deep copy.
Returns
Trueif the style allows rendering text.Attributes:
If
True, the font weight will be bold.Color of the text glyphs.
Name of the font family.
Horizontal alignment of multi-line text.
If
True, the font slant will be italic.Scaling factor of the vertical distance between consecutive lines of text.
Font size in pixels.
Vertical alignment of multi-line text.
- __eq__(self: viren2d.TextStyle, arg0: viren2d.TextStyle) bool
Checks for equality.
- __getstate__(self: viren2d.TextStyle) tuple
- __init__(self: viren2d.TextStyle, size: int = 16, family: str = 'monospace', color: viren2d.Color = viren2d.Color(red=0, green=0, blue=0, alpha=1), bold: bool = False, italic: bool = False, line_spacing: float = 1.2, halign: viren2d.HorizontalAlignment = viren2d.HorizontalAlignment('left'), valign: object = viren2d.VerticalAlignment('top')) None
Creates a customized text style.
- Parameters:
size – Font size in pixels as
float.family – Name of the font family. Refer to the class member
familyfor details.color – Text color as
Color.bold – If
True, the font weight will be bold (typebool).italic – If
True, the font slant will be italic (typebool).line_spacing – Scaling factor of the vertical distance between consecutive lines of text.
halign – Horizontal alignment of multi-line text as
HorizontalAlignmentenum. This parameter also accepts the corresponding string representation.valign – Vertical alignment of multi-line text as
VerticalAlignmentenum. This parameter also accepts the corresponding string representation. Only affects alignment of fixed-size text boxes, seedraw_text_box().
- __ne__(self: viren2d.TextStyle, arg0: viren2d.TextStyle) bool
Checks for inequality.
- __setstate__(self: viren2d.TextStyle, arg0: tuple) None
TextStyleinstances can be pickled.
- property bold
If
True, the font weight will be bold.Corresponding C++ API:
viren2d::TextStyle::bold.- Type:
- property color
Color of the text glyphs.
Corresponding C++ API:
viren2d::TextStyle::color.- Type:
- copy(self: viren2d.TextStyle) viren2d.TextStyle
Returns a deep copy.
Corresponding C++ API: Copy constructor of
viren2d::TextStyle.
- property family
Name of the font family.
Most available fonts on the system should be supported. If you experience issues, try the generic CSS2 family names first, e.g.
serif,sans-serif, ormonospace. Refer to the Cairo documentation for more details.Corresponding C++ API:
viren2d::TextStyle::family.- Type:
- property halign
Horizontal alignment of multi-line text.
In addition to the enumeration values, you can use the string representations (
left|west,center|middle,right|east) to set this member:>>> style.halign = viren2d.HorizontalAlignment.Center >>> style.halign = 'center'
Corresponding C++ API:
viren2d::TextStyle::halign.- Type:
- is_valid(self: viren2d.TextStyle) bool
Returns
Trueif the style allows rendering text.Corresponding C++ API:
viren2d::TextStyle::IsValid.
- property italic
If
True, the font slant will be italic.Corresponding C++ API:
viren2d::TextStyle::italic.- Type:
- property line_spacing
Scaling factor of the vertical distance between consecutive lines of text.
Corresponding C++ API:
viren2d::TextStyle::line_spacing.- Type:
- property valign
Vertical alignment of multi-line text. Will only affect the output of fixed-size text boxes, see
draw_text_box().In addition to the enumeration values, you can use the string representations (
top|north,center|middle,bottom|south) to set this member:>>> style.valign = viren2d.VerticalAlignment.Center >>> style.valign = 'center'
Corresponding C++ API:
viren2d::TextStyle::valign.- Type:



