pub trait ChartBackend {
// Required methods
fn kind(&self) -> BackendKind;
fn resize(&mut self, width: f64, height: f64, dpr: f64);
fn render(&mut self, list: &DisplayList, shaper: &mut TextShaper);
fn dispose(&mut self);
}Expand description
A rendering backend for the chart.
The three backends — WebGPU, WebGL2, and Canvas2D — all replay the same display list, so the chart model never has to know which one is in use. That is what keeps the public API identical across backends.
Required Methods§
Sourcefn kind(&self) -> BackendKind
fn kind(&self) -> BackendKind
Sourcefn resize(&mut self, width: f64, height: f64, dpr: f64)
fn resize(&mut self, width: f64, height: f64, dpr: f64)
Prepares the backend for a canvas of the given CSS size, at the given device pixel ratio.
The backends size their drawing buffer to width * dpr by
height * dpr physical pixels and scale their coordinate system
accordingly, so the model always works in CSS pixels.
§Arguments
f64- A 64-bit float (f64).
Sourcefn render(&mut self, list: &DisplayList, shaper: &mut TextShaper)
fn render(&mut self, list: &DisplayList, shaper: &mut TextShaper)
Replays the display list onto the canvas.
The backend is free to cache whatever it can: the display list is retained between frames, so a chart that has not changed should cost close to nothing to draw.
§Arguments
&DisplayList- Shared reference to aDisplayList.&mut TextShaper- Mutable reference to aTextShaper(mutated in place).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl ChartBackend for Canvas2dChartBackend
Implements ChartBackend for Canvas2dChartBackend.
impl ChartBackend for WebGl2ChartBackend
Implements ChartBackend for WebGl2ChartBackend.
impl ChartBackend for WebGpuChartBackend
Implements ChartBackend for WebGpuChartBackend.