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 layout_report(&self) -> Result<crate::layout::LayoutReport, Error> {
14 self.layout_report_with_operation(&OperationOptions::default())
15 }
16
17 pub fn layout_report_with_operation(
19 &self,
20 options: &OperationOptions,
21 ) -> Result<crate::layout::LayoutReport, Error> {
22 operation::run(options, || {
23 super::layout_report(super::root::RootSource::Plot(self.description()))
24 })
25 }
26 pub fn render(&self) -> Result<Output, Error> {
31 self.render_with_operation(&OperationOptions::default())
32 }
33
34 pub fn render_with_operation(&self, options: &OperationOptions) -> Result<Output, Error> {
36 operation::run(options, || self.freeze())
37 }
38
39 pub fn render_with_results(&self) -> Result<crate::stats::RenderWithResults, Error> {
41 self.render_with_results_with_operation(&OperationOptions::default())
42 }
43
44 pub fn render_with_results_with_operation(
46 &self,
47 options: &OperationOptions,
48 ) -> Result<crate::stats::RenderWithResults, Error> {
49 operation::run(options, || {
50 super::render_scene_with_results(super::root::RootSource::Plot(self.description()))
51 })
52 }
53
54 pub(crate) fn freeze(&self) -> Result<Output, Error> {
55 Ok(Output::new(super::render_scene(
56 super::root::RootSource::Plot(self.description()),
57 )?))
58 }
59
60 pub fn svg(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
64 self.svg_with_operation(path, &OperationOptions::default())
65 }
66
67 pub fn svg_with_operation(
69 &self,
70 path: impl AsRef<Path>,
71 options: &OperationOptions,
72 ) -> Result<Output, Error> {
73 self.save_with_operation(path, crate::output::Format::svg(), options)
74 }
75
76 pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
79 self.svg_preserve_text_with_operation(path, &OperationOptions::default())
80 }
81
82 pub fn svg_preserve_text_with_operation(
84 &self,
85 path: impl AsRef<Path>,
86 options: &OperationOptions,
87 ) -> Result<Output, Error> {
88 self.save_with_operation(
89 path,
90 crate::output::Format::svg().preserve_text(true),
91 options,
92 )
93 }
94
95 pub fn png(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
98 self.png_with_operation(path, &OperationOptions::default())
99 }
100
101 pub fn png_with_operation(
103 &self,
104 path: impl AsRef<Path>,
105 options: &OperationOptions,
106 ) -> Result<Output, Error> {
107 self.png_with_options_with_operation(path, crate::output::PngOptions::default(), options)
108 }
109
110 pub fn png_preview(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
113 self.png_preview_with_operation(path, &OperationOptions::default())
114 }
115
116 pub fn png_preview_with_operation(
118 &self,
119 path: impl AsRef<Path>,
120 options: &OperationOptions,
121 ) -> Result<Output, Error> {
122 self.png_with_options_with_operation(
123 path,
124 crate::output::PngOptions {
125 sizing: crate::output::PngSizing::Source,
126 compression: crate::output::PngCompression::Balanced,
127 },
128 options,
129 )
130 }
131
132 pub fn png_with_options(
135 &self,
136 path: impl AsRef<Path>,
137 options: crate::output::PngOptions,
138 ) -> Result<Output, Error> {
139 self.png_with_options_with_operation(path, options, &OperationOptions::default())
140 }
141
142 pub fn png_with_options_with_operation(
144 &self,
145 path: impl AsRef<Path>,
146 options: crate::output::PngOptions,
147 operation: &OperationOptions,
148 ) -> Result<Output, Error> {
149 self.save_with_operation(path, options, operation)
150 }
151}