Skip to main content

lichtung_plot/orchestrator/
output.rs

1//! Plot terminal output rendering.
2
3use std::path::Path;
4
5use crate::builder::Plot;
6use crate::{Error, Output};
7
8impl<K: crate::kind::Marker> Plot<K> {
9    /// Borrow this configuration, render once and publish an outlined SVG.
10    /// Each call performs a new render and returns a reusable frozen output.
11    /// The output filename is completed with `.svg` after conversion.
12    pub fn svg(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
13        let output = Output::new(super::render_scene(super::root::RootSource::Plot(
14            self.description(),
15        ))?);
16        output.svg(path)
17    }
18
19    /// Render once, publish SVG with selectable text, and return a reusable output.
20    /// The output filename is completed with `.svg` after rendering.
21    pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
22        let output = Output::new(super::render_scene(super::root::RootSource::Plot(
23            self.description(),
24        ))?);
25        output.svg_preserve_text(path)
26    }
27
28    /// Render once, publish a balanced 300-DPI PNG, and return a reusable output.
29    /// The output filename is completed with `.png` after rasterization.
30    pub fn png(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
31        let output = Output::new(super::render_scene(super::root::RootSource::Plot(
32            self.description(),
33        ))?);
34        output.png(path)
35    }
36
37    /// Render once, publish a balanced source-sized PNG without density metadata.
38    /// The output filename is completed with `.png` after rasterization.
39    pub fn png_preview(&self, path: impl AsRef<Path>) -> Result<Output, Error> {
40        let output = Output::new(super::render_scene(super::root::RootSource::Plot(
41            self.description(),
42        ))?);
43        output.png_preview(path)
44    }
45
46    /// Render once and publish a PNG using the exact caller-provided options.
47    /// The output filename is completed with `.png` after rasterization.
48    pub fn png_with_options(
49        &self,
50        path: impl AsRef<Path>,
51        options: crate::PngOptions,
52    ) -> Result<Output, Error> {
53        let output = Output::new(super::render_scene(super::root::RootSource::Plot(
54            self.description(),
55        ))?);
56        output.png_with_options(path, options)
57    }
58}