1 use crate::coord::Shift;
2 use crate::drawing::{DrawingArea, IntoDrawingArea};
3 use plotters_svg::SVGBackend;
4
5 /// The wrapper for the generated SVG
6 pub struct SVGWrapper(String, String);
7
8 impl SVGWrapper {
evcxr_display(&self)9 pub fn evcxr_display(&self) {
10 println!("{:?}", self);
11 }
12
style<S: Into<String>>(mut self, style: S) -> Self13 pub fn style<S: Into<String>>(mut self, style: S) -> Self {
14 self.1 = style.into();
15 self
16 }
17 }
18
19 impl std::fmt::Debug for SVGWrapper {
fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result20 fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
21 let svg = self.0.as_str();
22 write!(
23 formatter,
24 "EVCXR_BEGIN_CONTENT text/html\n<div style=\"{}\">{}</div>\nEVCXR_END_CONTENT",
25 self.1, svg
26 )
27 }
28 }
29
30 /// Start drawing an evcxr figure
evcxr_figure< Draw: FnOnce(DrawingArea<SVGBackend, Shift>) -> Result<(), Box<dyn std::error::Error>>, >( size: (u32, u32), draw: Draw, ) -> SVGWrapper31 pub fn evcxr_figure<
32 Draw: FnOnce(DrawingArea<SVGBackend, Shift>) -> Result<(), Box<dyn std::error::Error>>,
33 >(
34 size: (u32, u32),
35 draw: Draw,
36 ) -> SVGWrapper {
37 let mut buffer = "".to_string();
38 let root = SVGBackend::with_string(&mut buffer, size).into_drawing_area();
39 draw(root).expect("Drawing failure");
40 SVGWrapper(buffer, "".to_string())
41 }
42