pub trait Primitive: Send {
// Provided methods
fn draw(
&self,
painter: &Painter,
view: &PrimitiveView<'_>,
pass: PrimitivePass,
) { ... }
fn draw_merged(
&self,
painter: &Painter,
view: &PrimitiveView<'_>,
pass: PrimitivePass,
factor: usize,
) { ... }
fn price_axis_labels(&self, view: &PrimitiveView<'_>) -> Vec<PriceAxisLabel> { ... }
fn time_axis_labels(&self, view: &PrimitiveView<'_>) -> Vec<TimeAxisLabel> { ... }
fn draw_price_axis(
&self,
painter: &Painter,
axis: Rect,
view: &PrimitiveView<'_>,
) { ... }
fn draw_time_axis(
&self,
painter: &Painter,
axis: Rect,
view: &PrimitiveView<'_>,
) { ... }
fn autoscale(
&self,
bars: &[Bar],
visible: Range<usize>,
) -> Option<(f64, f64)> { ... }
fn hit_test(
&self,
pos: Pos2,
view: &PrimitiveView<'_>,
) -> Option<CursorIcon> { ... }
fn attached(&mut self, ctx: &Context, series: SeriesId) { ... }
fn detached(&mut self) { ... }
fn data_changed(&mut self, bars: &[Bar]) { ... }
}Expand description
Host drawing attached to a series, called by the chart while it draws each frame.
The chart calls the drawing hooks only while the series is visible. A primitive attached to the main series, an added bar series or an overlay study draws in the main pane; one attached to a study in a pane of its own draws in that pane. See the module documentation.
Provided Methods§
Sourcefn draw(&self, painter: &Painter, view: &PrimitiveView<'_>, pass: PrimitivePass)
fn draw(&self, painter: &Painter, view: &PrimitiveView<'_>, pass: PrimitivePass)
Draws in pass with painter, clipped to the plot area of the pane.
Sourcefn draw_merged(
&self,
painter: &Painter,
view: &PrimitiveView<'_>,
pass: PrimitivePass,
factor: usize,
)
fn draw_merged( &self, painter: &Painter, view: &PrimitiveView<'_>, pass: PrimitivePass, factor: usize, )
Draws with factor consecutive source slots per physical pixel group, one while
zoomed in. Override this for custom point aggregation; use
PrimitiveView::point_groups to visit the aligned ranges. Cache aggregates in
data_changed when visiting all source values would be costly.
The default preserves draw for existing renderers.
Sourcefn price_axis_labels(&self, view: &PrimitiveView<'_>) -> Vec<PriceAxisLabel>
fn price_axis_labels(&self, view: &PrimitiveView<'_>) -> Vec<PriceAxisLabel>
Labels for the price axis of the pane, placed at their prices next to the chart’s own tags. A label off the scale or without room is left out.
Sourcefn time_axis_labels(&self, view: &PrimitiveView<'_>) -> Vec<TimeAxisLabel>
fn time_axis_labels(&self, view: &PrimitiveView<'_>) -> Vec<TimeAxisLabel>
Labels for the time axis, centred at their times. Axis labels they cover are left out.
The time axis is shared by every pane, so the view of a primitive in a study pane maps prices on the main pane here.
Sourcefn draw_price_axis(
&self,
painter: &Painter,
axis: Rect,
view: &PrimitiveView<'_>,
)
fn draw_price_axis( &self, painter: &Painter, axis: Rect, view: &PrimitiveView<'_>, )
Draws inside axis, the price axis of the pane, behind its labels.
Sourcefn draw_time_axis(
&self,
painter: &Painter,
axis: Rect,
view: &PrimitiveView<'_>,
)
fn draw_time_axis( &self, painter: &Painter, axis: Rect, view: &PrimitiveView<'_>, )
Draws inside axis, the time axis, behind its labels. The view is as in
time_axis_labels.
Sourcefn autoscale(&self, bars: &[Bar], visible: Range<usize>) -> Option<(f64, f64)>
fn autoscale(&self, bars: &[Bar], visible: Range<usize>) -> Option<(f64, f64)>
The lowest and highest price the scale of the series must show while it fits itself to
the bars in view, visible indexing bars as in PrimitiveView. None adds nothing.
An overlay study on an independent scale fits that scale to its own values only.
Sourcefn hit_test(&self, pos: Pos2, view: &PrimitiveView<'_>) -> Option<CursorIcon>
fn hit_test(&self, pos: Pos2, view: &PrimitiveView<'_>) -> Option<CursorIcon>
Whether the pointer at pos is over the primitive, and the cursor to show there.
A hit is the pointer target of chart events. Drawings come first, then primitives, the latest attached first, then the series and studies.
Sourcefn attached(&mut self, ctx: &Context, series: SeriesId)
fn attached(&mut self, ctx: &Context, series: SeriesId)
Called once, at the first frame after the primitive was attached to series. ctx is
the chart’s egui context; keep a clone to request repaints, from any thread.
Sourcefn detached(&mut self)
fn detached(&mut self)
Called once when the primitive is detached, directly or by removing its series. Undoing the removal of a study restores the study without its primitives.
Sourcefn data_changed(&mut self, bars: &[Bar])
fn data_changed(&mut self, bars: &[Bar])
Called after attached and at every frame after the bars of the series
changed, before anything is drawn. bars are the series’ own bars, oldest first; for a
study they are the main series bars the study is computed from.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".