1
1
use crate :: coord:: Shift ;
2
2
use crate :: drawing:: { DrawingArea , IntoDrawingArea } ;
3
+ use base64;
3
4
use plotters_svg:: SVGBackend ;
5
+ use plotters_bitmap:: BitMapBackend ;
4
6
5
7
/// The wrapper for the generated SVG
6
8
pub struct SVGWrapper ( String , String ) ;
@@ -40,3 +42,53 @@ pub fn evcxr_figure<
40
42
draw ( root) . expect ( "Drawing failure" ) ;
41
43
SVGWrapper ( buffer, "" . to_string ( ) )
42
44
}
45
+
46
+ pub struct BitmapWrapper ( String , String ) ;
47
+
48
+ impl BitmapWrapper {
49
+ pub fn evcxr_display ( & self ) {
50
+ println ! ( "{:?}" , self ) ;
51
+ }
52
+
53
+ pub fn style < S : Into < String > > ( mut self , style : S ) -> Self {
54
+ self . 1 = style. into ( ) ;
55
+ self
56
+ }
57
+ }
58
+
59
+ impl std:: fmt:: Debug for BitmapWrapper {
60
+ fn fmt ( & self , formatter : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
61
+ let svg = self . 0 . as_str ( ) ;
62
+ write ! (
63
+ formatter,
64
+ "EVCXR_BEGIN_CONTENT text/html\n <img style=\" {}\" src=\" data:image/png;base64,{}\" />\n EVCXR_END_CONTENT" ,
65
+ self . 1 , svg
66
+ )
67
+ }
68
+ }
69
+
70
+ /// Start drawing an evcxr figure
71
+ pub fn evcxr_bitmap_figure <
72
+ Draw : FnOnce ( DrawingArea < BitMapBackend , Shift > ) -> Result < ( ) , Box < dyn std:: error:: Error > > ,
73
+ > (
74
+ size : ( u32 , u32 ) ,
75
+ draw : Draw ,
76
+ ) -> SVGWrapper {
77
+ let pixel_size = plotters_bitmap:: bitmap_pixel:: RGBPixel :: PIXEL_SIZE ;
78
+ let mut buf = [ u8; ( size. 0 as usize ) * ( size. 1 as usize ) * pixel_size] ;
79
+ let root = BitMapBackend :: with_buffer ( & buf, size) . into_drawing_area ( ) ;
80
+ let buffer = base64:: encode ( & buf) ;
81
+ draw ( root) . expect ( "Drawing failure" ) ;
82
+ BitmapWrapper ( buffer, "" . to_string ( ) )
83
+ }
84
+
85
+ pub fn evcxr_animation <
86
+ Draw : FnOnce ( DrawingArea < SVGBackend , Shift > ) -> Result < ( ) , Box < dyn std:: error:: Error > > ,
87
+ > (
88
+ drawing_area : & DrawingArea < SVGBackend , Shift > ,
89
+ draws : Draw ,
90
+ frames : usize ,
91
+ interval : usize ,
92
+ ) -> SVGWrapper {
93
+ todo ! ( ) ;
94
+ }
0 commit comments