Skip to content

Commit dd57bf6

Browse files
mchantandrei-ng
authored andcommitted
added get_b64 fn
1 parent 7aecfa7 commit dd57bf6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

plotly/src/plot.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,28 @@ impl Plot {
417417
.unwrap_or_else(|_| panic!("failed to export plot to {:?}", filename.as_ref()));
418418
}
419419

420+
// similar to write_image, but returns b64 string
421+
#[cfg(feature = "kaleido")]
422+
pub fn get_b64(
423+
&self,
424+
format: ImageFormat,
425+
width: usize,
426+
height: usize,
427+
scale: f64,
428+
) -> String {
429+
let kaleido = plotly_kaleido::Kaleido::new();
430+
let output = kaleido
431+
.to_b64(
432+
&serde_json::to_value(self).unwrap(),
433+
&format.to_string(),
434+
width,
435+
height,
436+
scale,
437+
)
438+
.unwrap_or_else(|_| panic!("failed to generate b64"));
439+
output
440+
}
441+
420442
fn render(&self) -> String {
421443
let tmpl = PlotTemplate {
422444
plot: self,

0 commit comments

Comments
 (0)