lichtung_plot/orchestrator/
output.rs1use std::path::Path;
4
5use crate::builder::Plot;
6use crate::{
7 operation::{self, OperationOptions},
8 Error, Output,
9};
10
11impl<K: crate::kind::Marker> Plot<K> {
12 pub fn render(&self) -> Result<Output, Error> {
17 self.render_with_operation(&OperationOptions::default())
18 }
19
20 pub fn render_with_operation(&self, options: &OperationOptions) -> Result<Output, Error> {
22 operation::run(options, || self.freeze())
23 }
24
25 pub fn render_with_results(&self) -> Result<crate::stats::RenderWithResults, Error> {
27 self.render_with_results_with_operation(&OperationOptions::default())
28 }
29
30 pub fn render_with_results_with_operation(
32 &self,
33 options: &OperationOptions,
34 ) -> Result<crate::stats::RenderWithResults, Error> {
35 operation::run(options, || {
36 super::render_scene_with_results(super::root::RootSource::Plot(self.description()))
37 })
38 }
39
40 fn freeze(&self) -> Result<Output, Error> {
41 Ok(Output::new(super::render_scene(
42 super::root::RootSource::Plot(self.description()),
43 )?))
44 }
45
46 pub fn svg(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
50 self.svg_with_operation(path, &OperationOptions::default())
51 }
52
53 pub fn svg_with_operation(
55 &self,
56 path: impl AsRef<Path>,
57 options: &OperationOptions,
58 ) -> Result<Output, Error> {
59 operation::run(options, || self.freeze()?.publish_svg(path, false))
60 }
61
62 pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
65 self.svg_preserve_text_with_operation(path, &OperationOptions::default())
66 }
67
68 pub fn svg_preserve_text_with_operation(
70 &self,
71 path: impl AsRef<Path>,
72 options: &OperationOptions,
73 ) -> Result<Output, Error> {
74 operation::run(options, || self.freeze()?.publish_svg(path, true))
75 }
76
77 pub fn png(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
80 self.png_with_operation(path, &OperationOptions::default())
81 }
82
83 pub fn png_with_operation(
85 &self,
86 path: impl AsRef<Path>,
87 options: &OperationOptions,
88 ) -> Result<Output, Error> {
89 self.png_with_options_with_operation(path, crate::output::PngOptions::default(), options)
90 }
91
92 pub fn png_preview(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
95 self.png_preview_with_operation(path, &OperationOptions::default())
96 }
97
98 pub fn png_preview_with_operation(
100 &self,
101 path: impl AsRef<Path>,
102 options: &OperationOptions,
103 ) -> Result<Output, Error> {
104 self.png_with_options_with_operation(
105 path,
106 crate::output::PngOptions {
107 sizing: crate::output::PngSizing::Source,
108 compression: crate::output::PngCompression::Balanced,
109 },
110 options,
111 )
112 }
113
114 pub fn png_with_options(
117 &self,
118 path: impl AsRef<Path>,
119 options: crate::output::PngOptions,
120 ) -> Result<Output, Error> {
121 self.png_with_options_with_operation(path, options, &OperationOptions::default())
122 }
123
124 pub fn png_with_options_with_operation(
126 &self,
127 path: impl AsRef<Path>,
128 options: crate::output::PngOptions,
129 operation: &OperationOptions,
130 ) -> Result<Output, Error> {
131 operation::run(operation, || self.freeze()?.publish_png(path, &options))
132 }
133}