Trait plotters_iced::Chart

source ·
pub trait Chart<Message> {
    type State: Default + 'static;

    fn build_chart<DB: DrawingBackend>(
        &self,
        state: &Self::State,
        builder: ChartBuilder<'_, '_, DB>
    ); fn draw_chart<DB: DrawingBackend>(
        &self,
        state: &Self::State,
        root: DrawingArea<DB, Shift>
    ) { ... } fn draw<F: Fn(&mut Frame)>(&self, size: Size, f: F) -> Geometry { ... } fn update(
        &self,
        state: &mut Self::State,
        event: Event,
        bounds: Rectangle,
        cursor: Cursor
    ) -> (Status, Option<Message>) { ... } fn mouse_interaction(
        &self,
        state: &Self::State,
        bounds: Rectangle,
        cursor: Cursor
    ) -> Interaction { ... } }
Expand description

Chart View Model

Example

use plotters::prelude::*;
use plotters_iced::{Chart,ChartWidget};
struct MyChart;
impl Chart<Message> for MyChart {
    type State = ();
    fn build_chart<DB:DrawingBackend>(&self, state: &Self::State, builder: ChartBuilder<DB>) {
        //build your chart here, please refer to plotters for more details
    }
}

impl MyChart {
    fn view(&mut self)->Element<Message> {
        ChartWidget::new(self)
            .width(Length::Unit(200))
            .height(Length::Unit(200))
            .into()
    }
}

Required Associated Types§

state data of chart

Required Methods§

draw chart with ChartBuilder

for simple chart, you impl this method

Provided Methods§

override this method if you want more freedom of drawing area

Example
use plotters::prelude::*;
use plotters_iced::{Chart,ChartWidget};

struct MyChart{}

impl Chart<Message> for MyChart {
    // leave it empty
    fn build_chart<DB: DrawingBackend>(&self, state: &Self::State, builder: ChartBuilder<DB>){}
    fn draw_chart<DB: DrawingBackend>(&self, state: &Self::State, root: DrawingArea<DB, Shift>){
         let children = root.split_evenly((3,3));
         for (area, color) in children.into_iter().zip(0..) {
               area.fill(&Palette99::pick(color)).unwrap();
         }
     }
}

draw on [iced_graphics::canvas::Canvas]

override this method if you want to use [iced_graphics::canvas::Cache]

Example

impl Chart<Message> for CpuUsageChart {

      #[inline]
      fn draw<F: Fn(&mut Frame)>(&self, bounds: Size, draw_fn: F) -> Geometry {
           self.cache.draw(bounds, draw_fn)
      }
     //...
}

react on event

Returns the current mouse interaction of the Chart

Implementations on Foreign Types§

Implementors§