MCPcopy Index your code
hub / github.com/askanium/rustplotlib / save

Method save

src/chart.rs:253–274  ·  view source on GitHub ↗

Save the chart to a file

(self, path: P)

Source from the content-addressed store, hash-verified

251
252 /// Save the chart to a file
253 pub fn save<P>(self, path: P) -> Result<(), String> where
254 P: AsRef<Path>
255 {
256 match path.as_ref().extension().and_then(OsStr::to_str) {
257 Some("svg") => {
258 match self.to_svg() {
259 Ok(svg_content) => {
260 let document = svg::Document::new()
261 .set("width", self.width)
262 .set("height", self.height)
263 .set("viewBox", (0, 0, self.width, self.height))
264 .add(svg_content);
265
266 svg::save(path, &document).unwrap()
267 },
268 Err(e) => return Err(format!("Encountered an error while saving the chart: {:?}", e)),
269 }
270 },
271 _ => {},
272 };
273 Ok(())
274 }
275}

Callers 8

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 1

to_svgMethod · 0.45

Tested by

no test coverage detected