use std::path::Path;
use crate::builder::Plot;
use crate::{
operation::{self, OperationOptions},
Error, Output,
};
impl<K: crate::kind::Marker> Plot<K> {
pub fn render(&self) -> Result<Output, Error> {
self.render_with_operation(&OperationOptions::default())
}
pub fn render_with_operation(&self, options: &OperationOptions) -> Result<Output, Error> {
operation::run(options, || self.freeze())
}
pub fn render_with_results(&self) -> Result<crate::stats::RenderWithResults, Error> {
self.render_with_results_with_operation(&OperationOptions::default())
}
pub fn render_with_results_with_operation(
&self,
options: &OperationOptions,
) -> Result<crate::stats::RenderWithResults, Error> {
operation::run(options, || {
super::render_scene_with_results(super::root::RootSource::Plot(self.description()))
})
}
fn freeze(&self) -> Result<Output, Error> {
Ok(Output::new(super::render_scene(
super::root::RootSource::Plot(self.description()),
)?))
}
pub fn svg(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
self.svg_with_operation(path, &OperationOptions::default())
}
pub fn svg_with_operation(
&self,
path: impl AsRef<Path>,
options: &OperationOptions,
) -> Result<Output, Error> {
operation::run(options, || self.freeze()?.publish_svg(path, false))
}
pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
self.svg_preserve_text_with_operation(path, &OperationOptions::default())
}
pub fn svg_preserve_text_with_operation(
&self,
path: impl AsRef<Path>,
options: &OperationOptions,
) -> Result<Output, Error> {
operation::run(options, || self.freeze()?.publish_svg(path, true))
}
pub fn png(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
self.png_with_operation(path, &OperationOptions::default())
}
pub fn png_with_operation(
&self,
path: impl AsRef<Path>,
options: &OperationOptions,
) -> Result<Output, Error> {
self.png_with_options_with_operation(path, crate::output::PngOptions::default(), options)
}
pub fn png_preview(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
self.png_preview_with_operation(path, &OperationOptions::default())
}
pub fn png_preview_with_operation(
&self,
path: impl AsRef<Path>,
options: &OperationOptions,
) -> Result<Output, Error> {
self.png_with_options_with_operation(
path,
crate::output::PngOptions {
sizing: crate::output::PngSizing::Source,
compression: crate::output::PngCompression::Balanced,
},
options,
)
}
pub fn png_with_options(
&self,
path: impl AsRef<Path>,
options: crate::output::PngOptions,
) -> Result<Output, Error> {
self.png_with_options_with_operation(path, options, &OperationOptions::default())
}
pub fn png_with_options_with_operation(
&self,
path: impl AsRef<Path>,
options: crate::output::PngOptions,
operation: &OperationOptions,
) -> Result<Output, Error> {
operation::run(operation, || self.freeze()?.publish_png(path, &options))
}
}