cellular_raza_concepts/
plotting.rs1use plotters::backend::DrawingBackend;
2use plotters::coord::cartesian::Cartesian2d;
3use plotters::coord::types::RangedCoordf64;
4use plotters::prelude::BitMapBackend;
5use plotters::prelude::DrawingArea;
6use plotters::prelude::SVGBackend;
7
8use crate::errors::DrawingError;
9
10pub trait CreatePlottingRoot {
14 fn create_bitmap_root<'a, T>(
16 &self,
17 image_size: u32,
18 filename: &'a T,
19 ) -> Result<
20 DrawingArea<BitMapBackend<'a>, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
21 DrawingError,
22 >
23 where
24 T: AsRef<std::path::Path> + ?Sized;
25 }
35
36pub trait PlotSelf {
39 fn plot_self<Db>(
41 &self,
42 root: &mut DrawingArea<Db, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
43 ) -> Result<(), DrawingError>
44 where
45 Db: DrawingBackend;
46
47 fn plot_self_bitmap(
50 &self,
51 root: &mut DrawingArea<BitMapBackend, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
52 ) -> Result<(), DrawingError> {
53 self.plot_self(root)
54 }
55
56 fn plot_self_svg(
59 &self,
60 root: &mut DrawingArea<SVGBackend, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
61 ) -> Result<(), DrawingError> {
62 self.plot_self(root)
63 }
64}
65
66use crate::cell::CellBox;
67use serde::{Deserialize, Serialize};
68
69impl<Cel> PlotSelf for CellBox<Cel>
70where
71 Cel: PlotSelf + Serialize + for<'a> Deserialize<'a>,
72{
73 fn plot_self<Db>(
74 &self,
75 root: &mut DrawingArea<Db, Cartesian2d<RangedCoordf64, RangedCoordf64>>,
76 ) -> Result<(), DrawingError>
77 where
78 Db: DrawingBackend,
79 {
80 self.cell.plot_self(root)
81 }
82}