(
&self,
path: impl Into<String>,
width: usize,
height: usize,
scale: f64,
)
| 100 | feature = "export-default" |
| 101 | ))] |
| 102 | fn write_image( |
| 103 | &self, |
| 104 | path: impl Into<String>, |
| 105 | width: usize, |
| 106 | height: usize, |
| 107 | scale: f64, |
| 108 | ) -> Result<(), Box<dyn std::error::Error + 'static>> { |
| 109 | let path_string = path.into(); |
| 110 | let result = build_plotly_result(self); |
| 111 | |
| 112 | // Image export uses plotly.rs directly; layout overrides are not |
| 113 | // applicable here because the plotly.js static exporter only reads |
| 114 | // the standard Layout fields. For scene/polar faceted plots the |
| 115 | // JSON override path should be used for HTML output only. |
| 116 | if let Some((filename, extension)) = path_string.rsplit_once('.') { |
| 117 | let format = match extension { |
| 118 | "png" => plotly::ImageFormat::PNG, |
| 119 | "jpg" | "jpeg" => plotly::ImageFormat::JPEG, |
| 120 | "webp" => plotly::ImageFormat::WEBP, |
| 121 | "svg" => plotly::ImageFormat::SVG, |
| 122 | _ => return Err(format!("Unsupported image format: {extension}").into()), |
| 123 | }; |
| 124 | result |
| 125 | .plot |
| 126 | .write_image(filename, format, width, height, scale)?; |
| 127 | } else { |
| 128 | return Err("No extension provided for image.".into()); |
| 129 | } |
| 130 | |
| 131 | Ok(()) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | #[cfg(test)] |
no test coverage detected