pygfx.objects.Ruler
- class pygfx.objects.Ruler(*, start_pos=(0, 0, 0), end_pos=(0, 0, 0), start_value=0.0, ticks=None, tick_format='0.4g', tick_side='left', min_tick_distance=50, ticks_at_end_points=False)
Bases:
WorldObject
An object to represent a ruler with tickmarks.
Can be used to measure distances in a scene, or as an axis in a plot.
Usage:
Use the properties (most notably
start_pos
andend_pos
).Call
update()
on each draw.
- property line
The line object that shows the ruler’s path.
- property points
The points object that shows the ruler’s tickmarks.
- property start_pos
The start posision of the ruler, in model space.
Note that the ruler’s transform also affects positioning, but should generally not be used.
- property end_pos
The end posision of the ruler, in model space.
- property start_value
The value of the ruler at the start position (i.e. the offset).
- property end_value
The value at the end of the ruler (read-only).
- property ticks
The ticks to show.
None
for automatic ticks.dict
for explicit ticks. Values can be str or float. If float, they are formatted withtick_format
.list
/tuple
/ndarray
for a list of values.
- property tick_format
The format to display the tick values.
A string to use as the second arg in
format()
, default “0.4g”.“km” to use mili/Kilo/Mega/Giga suffixes.
A function that maps (value, min_value, max_value) to a str.
- property tick_side
Whether the ticks are on the ‘left’ or ‘right’ of the line.
Imagine standing on the start position, with the line in front of you.
- property min_tick_distance
The minimal distance between ticks in screen pixels, when using auto-ticks.
- property ticks_at_end_points
Whether to show tickmarks at the end-points.
- update(camera, canvas_size)
Update the ruler.
This must be called on every draw, right before rendering.
Returns a dictionary with the following fields:
“tick_step”: the calculated auto-tick-step.
“tick_values”: the tick values that will be shown.