@@ -54,7 +54,6 @@ pub enum ImageFormat {
54
54
EPS ,
55
55
}
56
56
57
-
58
57
/// A struct that implements `Trace` can be serialized to json format that is understood by Plotly.js.
59
58
pub trait Trace {
60
59
fn serialize ( & self ) -> String ;
@@ -120,7 +119,6 @@ plot.save("filename", ImageFormat::PNG, width, height, scale);
120
119
See https://igiagkiozis.github.io/plotly/content/getting_started.html for further details.
121
120
"# ;
122
121
123
-
124
122
impl Plot {
125
123
/// Create a new `Plot`.
126
124
pub fn new ( ) -> Plot {
@@ -164,10 +162,13 @@ impl Plot {
164
162
let rendered = rendered. as_bytes ( ) ;
165
163
let mut temp = env:: temp_dir ( ) ;
166
164
167
- let mut plot_name = rand:: thread_rng ( )
168
- . sample_iter ( & rand:: distributions:: Alphanumeric )
169
- . take ( 22 )
170
- . collect :: < String > ( ) ;
165
+ let mut plot_name = String :: from_utf8 (
166
+ thread_rng ( )
167
+ . sample_iter ( & Alphanumeric )
168
+ . take ( 22 )
169
+ . collect :: < Vec < u8 > > ( ) ,
170
+ )
171
+ . unwrap ( ) ;
171
172
plot_name. push_str ( ".html" ) ;
172
173
plot_name = format ! ( "plotly_{}" , plot_name) ;
173
174
@@ -191,10 +192,13 @@ impl Plot {
191
192
let rendered = rendered. as_bytes ( ) ;
192
193
let mut temp = env:: temp_dir ( ) ;
193
194
194
- let mut plot_name = rand:: thread_rng ( )
195
- . sample_iter ( & rand:: distributions:: Alphanumeric )
196
- . take ( 22 )
197
- . collect :: < String > ( ) ;
195
+ let mut plot_name = String :: from_utf8 (
196
+ thread_rng ( )
197
+ . sample_iter ( & Alphanumeric )
198
+ . take ( 22 )
199
+ . collect :: < Vec < u8 > > ( ) ,
200
+ )
201
+ . unwrap ( ) ;
198
202
plot_name. push_str ( ".html" ) ;
199
203
200
204
temp. push ( plot_name) ;
@@ -217,10 +221,13 @@ impl Plot {
217
221
let rendered = rendered. as_bytes ( ) ;
218
222
let mut temp = env:: temp_dir ( ) ;
219
223
220
- let mut plot_name = rand:: thread_rng ( )
221
- . sample_iter ( & rand:: distributions:: Alphanumeric )
222
- . take ( 22 )
223
- . collect :: < String > ( ) ;
224
+ let mut plot_name: String = String :: from_utf8 (
225
+ thread_rng ( )
226
+ . sample_iter ( & Alphanumeric )
227
+ . take ( 22 )
228
+ . collect :: < Vec < u8 > > ( ) ,
229
+ )
230
+ . unwrap ( ) ;
224
231
plot_name. push_str ( ".html" ) ;
225
232
226
233
temp. push ( plot_name) ;
@@ -260,14 +267,26 @@ impl Plot {
260
267
match plot_div_id {
261
268
Some ( id) => self . render_inline ( id. as_ref ( ) ) ,
262
269
None => {
263
- let rand_id: String = thread_rng ( ) . sample_iter ( & Alphanumeric ) . take ( 20 ) . collect ( ) ;
270
+ let rand_id = String :: from_utf8 (
271
+ thread_rng ( )
272
+ . sample_iter ( & Alphanumeric )
273
+ . take ( 20 )
274
+ . collect :: < Vec < u8 > > ( ) ,
275
+ )
276
+ . unwrap ( ) ;
264
277
self . render_inline ( rand_id. as_str ( ) )
265
278
}
266
279
}
267
280
}
268
281
269
282
fn to_jupyter_notebook_html ( & self ) -> String {
270
- let plot_div_id: String = thread_rng ( ) . sample_iter ( & Alphanumeric ) . take ( 20 ) . collect ( ) ;
283
+ let plot_div_id = String :: from_utf8 (
284
+ thread_rng ( )
285
+ . sample_iter ( & Alphanumeric )
286
+ . take ( 20 )
287
+ . collect :: < Vec < u8 > > ( ) ,
288
+ )
289
+ . unwrap ( ) ;
271
290
let plot_data = self . render_plot_data ( ) ;
272
291
273
292
let tmpl = JupyterNotebookPlotTemplate {
@@ -280,7 +299,10 @@ impl Plot {
280
299
/// Display plot in Jupyter Notebook.
281
300
pub fn notebook_display ( & self ) {
282
301
let plot_data = self . to_jupyter_notebook_html ( ) ;
283
- println ! ( "EVCXR_BEGIN_CONTENT text/html\n {}\n EVCXR_END_CONTENT" , plot_data) ;
302
+ println ! (
303
+ "EVCXR_BEGIN_CONTENT text/html\n {}\n EVCXR_END_CONTENT" ,
304
+ plot_data
305
+ ) ;
284
306
}
285
307
286
308
/// Display plot in Jupyter Lab.
0 commit comments