Trait plotters_iced::Chart[][src]

pub trait Chart<Message> {
    fn build_chart<DB: DrawingBackend>(&self, builder: ChartBuilder<'_, '_, DB>);

    fn draw_chart<DB: DrawingBackend>(&self, root: DrawingArea<DB, Shift>) { ... }
fn draw<F: Fn(&mut Frame)>(&self, size: Size, f: F) -> Geometry { ... }
fn update(
        &mut self,
        event: Event,
        bounds: Rectangle,
        cursor: Cursor
    ) -> (Status, Option<Message>) { ... } }
Expand description

Chart View Model

use it with [ChartWidget].

Example

use plotters::prelude::*;
use plotters_iced::{Chart,ChartWidget};
struct MyChart;
impl Chart<Message> for MyChart {
    fn build_chart<DB:DrawingBackend>(&self, 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 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, builder: ChartBuilder<DB>){}
    fn draw_chart<DB: DrawingBackend>(&self, 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

Implementations on Foreign Types

Implementors