1
1
use crate :: coord:: Shift ;
2
2
use crate :: drawing:: { DrawingArea , IntoDrawingArea } ;
3
- use image:: { png:: PngEncoder , ImageBuffer , ImageError , Pixel , Rgb , RgbImage } ;
4
- use plotters_bitmap:: BitMapBackend ;
5
3
use plotters_svg:: SVGBackend ;
6
4
use plotters_backend:: DrawingBackend ;
7
- use std :: ops :: Deref ;
5
+ use plotters_bitmap :: BitMapBackend ;
8
6
9
7
/// The wrapper for the generated SVG
10
8
pub struct SVGWrapper ( String , String ) ;
@@ -73,20 +71,7 @@ impl std::fmt::Debug for BitMapWrapper {
73
71
}
74
72
}
75
73
76
- // #[cfg(feature = "evcxr_bitmap_figure")]
77
- #[ cfg( all( feature = "evcxr" , feature = "bitmap_backend" ) ) ]
78
- fn encode_png < P , Container > ( img : & ImageBuffer < P , Container > ) -> Result < Vec < u8 > , ImageError >
79
- where
80
- P : Pixel < Subpixel = u8 > + ' static ,
81
- Container : Deref < Target = [ P :: Subpixel ] > ,
82
- {
83
- let mut buf = Vec :: new ( ) ;
84
- let encoder = PngEncoder :: new ( & mut buf) ;
85
- encoder. encode ( img, img. width ( ) , img. height ( ) , P :: COLOR_TYPE ) ?;
86
- Ok ( buf)
87
- }
88
74
89
- // #[cfg(feature = "evcxr_bitmap_figure")]
90
75
/// Start drawing an evcxr figure
91
76
#[ cfg( all( feature = "evcxr" , feature = "bitmap_backend" ) ) ]
92
77
pub fn evcxr_bitmap_figure <
@@ -100,24 +85,11 @@ pub fn evcxr_bitmap_figure<
100
85
buf. resize ( ( size. 0 as usize ) * ( size. 1 as usize ) * pixel_size, 0 ) ;
101
86
let root = BitMapBackend :: with_buffer ( & mut buf, size) . into_drawing_area ( ) ;
102
87
draw ( root) . expect ( "Drawing failure" ) ;
103
- let img = RgbImage :: from_raw ( size. 0 , size. 1 , buf) . unwrap ( ) ;
104
88
let mut buffer = "" . to_string ( ) ;
105
- let svg_root = SVGBackend :: with_string ( & mut buffer, size) . into_drawing_area ( ) ;
106
- svg_root. blit_bitmap ( ( 0 , 0 ) , size, buf) . expect ( "Failure converting to SVG" ) ;
107
- // draw(svg_root).expect("Failure converting bitmap to SVG");
108
- // let enc_buf = encode_png(&img).unwrap();
109
- // let buffer = base64::encode(&enc_buf);
110
- SVGWrapper ( buffer, "" . to_string ( ) )
89
+ {
90
+ let mut svg_root = SVGBackend :: with_string ( & mut buffer, size) ;
91
+ svg_root. blit_bitmap ( ( 0 , 0 ) , size, & buf) . expect ( "Failure converting to SVG" ) ;
92
+ }
93
+ SVGWrapper ( buffer. clone ( ) , "" . to_string ( ) )
111
94
}
112
95
113
- // #[cfg(feature = "evcxr_bitmap_figure")]
114
- // pub fn evcxr_animation<
115
- // Draw: FnOnce(DrawingArea<SVGBackend, Shift>) -> Result<(), Box<dyn std::error::Error>>,
116
- // >(
117
- // drawing_area: &DrawingArea<SVGBackend, Shift>,
118
- // draws: Draw,
119
- // frames: usize,
120
- // interval: usize,
121
- // ) -> SVGWrapper {
122
- // todo!();
123
- // }
0 commit comments