Save the chart to a file
(self, path: P)
| 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 | } |