pub struct Canvas { /* private fields */ }Expand description
A typed grid of independently configured charts rendered on one canvas.
Canvas owns one root theme, which defaults to Theme::publication. Plots
without an explicit theme inherit that root. Dimensions are derived from
content unless Self::width, Self::max_width or Self::size replaces
the sizing request. Clones share immutable placements until a placement edit
separates them. Terminal exports borrow the configuration and render a fresh
scene per call.
Implementations§
Source§impl Canvas
impl Canvas
Sourcepub fn elements(&self, query: ElementQuery) -> Result<Vec<ElementRef>>
pub fn elements(&self, query: ElementQuery) -> Result<Vec<ElementRef>>
Discover real scientific layers in the canvas or in an actual panel.
Sourcepub fn element_ref(&self, query: impl Into<ElementQuery>) -> Result<ElementRef>
pub fn element_ref(&self, query: impl Into<ElementQuery>) -> Result<ElementRef>
Select one actual layer in the canvas.
Sourcepub fn read_element(&self, reference: &ElementRef) -> Result<ElementSnapshot>
pub fn read_element(&self, reference: &ElementRef) -> Result<ElementSnapshot>
Read the owning declaration at its actual placed address.
Sourcepub fn data_roles(&self) -> Result<Vec<DataRoleInfo>>
pub fn data_roles(&self) -> Result<Vec<DataRoleInfo>>
Discover all original input roles of the actual independent placements.
Sourcepub fn data_roles_at(&self, target: &ElementRef) -> Result<Vec<DataRoleInfo>>
pub fn data_roles_at(&self, target: &ElementRef) -> Result<Vec<DataRoleInfo>>
Discover original inputs of one actual layer.
Sourcepub fn data_roles_in(&self, panel: &PanelPath) -> Result<Vec<DataRoleInfo>>
pub fn data_roles_in(&self, panel: &PanelPath) -> Result<Vec<DataRoleInfo>>
Discover original inputs of the actual layers in a panel.
Source§impl Canvas
impl Canvas
Sourcepub fn clear_title_style(self) -> Self
pub fn clear_title_style(self) -> Self
Remove the local root title appearance override without changing content/layout or child plots.
Sourcepub fn clear_title_layout(self) -> Self
pub fn clear_title_layout(self) -> Self
Remove the local root title layout request without changing content/style or child plots.
Source§impl Canvas
impl Canvas
Sourcepub fn clear_subtitle_style(self) -> Self
pub fn clear_subtitle_style(self) -> Self
Remove the local root subtitle appearance override without changing content/layout or child plots.
Sourcepub fn clear_subtitle_layout(self) -> Self
pub fn clear_subtitle_layout(self) -> Self
Remove the local root subtitle layout request without changing content/style or child plots.
Source§impl Canvas
impl Canvas
Sourcepub fn clear_caption_style(self) -> Self
pub fn clear_caption_style(self) -> Self
Remove the local root caption appearance override without changing content/layout or child plots.
Sourcepub fn clear_caption_layout(self) -> Self
pub fn clear_caption_layout(self) -> Self
Remove the local root caption layout request without changing content/style or child plots.
Source§impl Canvas
impl Canvas
Sourcepub fn guide_text_layout(self, role: GuideTextRole, layout: TextLayout) -> Self
pub fn guide_text_layout(self, role: GuideTextRole, layout: TextLayout) -> Self
Replace one Canvas-owned Shared guide role’s complete layout default.
Sourcepub fn grid(rows: usize, columns: usize) -> Result<Self, Error>
pub fn grid(rows: usize, columns: usize) -> Result<Self, Error>
Construct a non-empty panel grid.
Sourcepub fn contains_plot_anchor(&self, row: usize, column: usize) -> bool
pub fn contains_plot_anchor(&self, row: usize, column: usize) -> bool
Whether this cell is the top-left anchor of a placed Plot.
Covered cells, TextPanels, empty cells and out-of-range coordinates return false.
Sourcepub fn panel<K: ExactFamily>(
self,
row: usize,
column: usize,
plot: Plot<K>,
) -> Result<Self, Error>
pub fn panel<K: ExactFamily>( self, row: usize, column: usize, plot: Plot<K>, ) -> Result<Self, Error>
Place one exact-family chart in an unoccupied zero-based grid cell.
An already erased plot cannot be inserted:
use lichtung_plot::{Canvas, NumericValues, Plot};
let erased: Plot = Plot::scatter(
NumericValues::new("x", [1.0]),
NumericValues::new("y", [2.0]),
).erase();
let _ = Canvas::grid(1, 1).unwrap().panel(0, 0, erased);Sourcepub fn panel_span<K: ExactFamily>(
self,
row: usize,
column: usize,
row_span: usize,
column_span: usize,
plot: Plot<K>,
) -> Result<Self, Error>
pub fn panel_span<K: ExactFamily>( self, row: usize, column: usize, row_span: usize, column_span: usize, plot: Plot<K>, ) -> Result<Self, Error>
Place one Plot across a checked rectangle, including internal track gaps. Only the top-left anchor owns preparation, prose, guides and capture.
use lichtung_plot::{Canvas, NumericValues, Plot};
let plot = || Plot::scatter(NumericValues::new("x",[0.0,1.0]),NumericValues::new("y",[1.0,0.0]));
let canvas = Canvas::grid(2,2)?
.panel(0,0,plot())?.panel(1,0,plot())?
.panel_span(0,1,2,1,plot())?;Sourcepub fn set_panel<K: ExactFamily>(
self,
row: usize,
column: usize,
plot: Plot<K>,
) -> Result<Self, Error>
pub fn set_panel<K: ExactFamily>( self, row: usize, column: usize, plot: Plot<K>, ) -> Result<Self, Error>
Place a chart in one cell, removing every intersecting placement in full.
Cells outside this new footprint are freed if their old owner intersects it.
Use Self::panel instead to reject all overlap.
use lichtung_plot::{Canvas, NumericValues, Plot};
let plot = || Plot::scatter(NumericValues::new("x", [0., 1.]), NumericValues::new("y", [1., 2.]));
let canvas = Canvas::grid(2, 3)?.panel_span(0, 0, 2, 2, plot())?
.set_panel(1, 1, plot())?.panel(0, 0, plot())?;Sourcepub fn set_panel_span<K: ExactFamily>(
self,
row: usize,
column: usize,
row_span: usize,
column_span: usize,
plot: Plot<K>,
) -> Result<Self, Error>
pub fn set_panel_span<K: ExactFamily>( self, row: usize, column: usize, row_span: usize, column_span: usize, plot: Plot<K>, ) -> Result<Self, Error>
Replace an occupied region with one chart, removing whole intersecting Plot or TextPanel owners, even when their anchors lie outside the region. Edge-touching owners remain intact. Empty space permits ordinary insertion.
Footprint validation and fallible placement resources precede any removal. Grid dimensions, headers and explicit range-group requests are unchanged; their normal preflight checks apply to the resulting topology.
Sourcepub fn place_panel<K: ExactFamily>(
&mut self,
row: usize,
column: usize,
row_span: usize,
column_span: usize,
plot: Plot<K>,
overwrite: bool,
) -> Result<(), Error>
pub fn place_panel<K: ExactFamily>( &mut self, row: usize, column: usize, row_span: usize, column_span: usize, plot: Plot<K>, overwrite: bool, ) -> Result<(), Error>
Place an owned exact-family Plot without consuming this Canvas on error.
overwrite=false requires an entirely empty footprint; true removes
complete intersecting owners as documented by Self::set_panel_span.
Validation/resources precede mutation. Existing Canvas clones are unchanged,
and an unshared Canvas edits its placements without copying the owner set.
Consuming placement builders delegate to this same operation.
Sourcepub fn text_panel(
self,
row: usize,
column: usize,
panel: TextPanel,
) -> Result<Self, Error>
pub fn text_panel( self, row: usize, column: usize, panel: TextPanel, ) -> Result<Self, Error>
Place one validated text panel in an unoccupied zero-based grid cell.
Sourcepub fn place_text_panel(
&mut self,
row: usize,
column: usize,
panel: TextPanel,
) -> Result<(), Error>
pub fn place_text_panel( &mut self, row: usize, column: usize, panel: TextPanel, ) -> Result<(), Error>
Insert a strict single-cell TextPanel without consuming the Canvas on error. Other configuration copies and occupied placements remain unchanged on failure.
Sourcepub fn legend_policy(self, policy: CanvasLegendPolicy) -> Self
pub fn legend_policy(self, policy: CanvasLegendPolicy) -> Self
Set per-panel, shared, or hidden legend behavior.
Sourcepub const fn legend_composition(self, composition: LegendComposition) -> Self
pub const fn legend_composition(self, composition: LegendComposition) -> Self
Replace the semantic composition of a Shared discrete guide.
Combined is the default. Under Shared this selection owns every contribution; stored child selections remain unchanged. PerPlot, Hidden and all-continuous guides leave this value inactive. Theme, placement and legend-policy call order are independent.
use lichtung_plot::{Canvas, guides::{CanvasLegendPolicy, LegendComposition}};
let canvas = Canvas::grid(1, 2)?
.legend_composition(LegendComposition::Separate)
.legend_policy(CanvasLegendPolicy::Shared);Sourcepub const fn panel_title_alignment(self, alignment: TextAlignment) -> Self
pub const fn panel_title_alignment(self, alignment: TextAlignment) -> Self
Set the title alignment default for embedded Plots, independently of Canvas prose.
An explicit Plot title instruction wins; otherwise this wins over that Plot’s theme default. Start and End mean the physical left and right edges of each Plot’s inset content span. Headers and TextPanel text are unaffected.
use lichtung_plot::{Canvas, NumericValues, Plot, Theme, text::TextAlignment};
let canvas = Canvas::grid(1, 1)?
.panel_title_alignment(TextAlignment::Start)
.panel_subtitle_alignment(TextAlignment::End)
.theme(Theme::nature())
.panel(0, 0, Plot::scatter(
NumericValues::new("x", [1.0, 2.0]),
NumericValues::new("y", [2.0, 1.0]),
).title("Panel title").subtitle("Panel subtitle"))?;Sourcepub const fn panel_subtitle_alignment(self, alignment: TextAlignment) -> Self
pub const fn panel_subtitle_alignment(self, alignment: TextAlignment) -> Self
Set the subtitle alignment default for embedded Plots only.
An explicit Plot subtitle instruction wins; otherwise this wins over the optional Plot-theme subtitle default and final effective title alignment. Theme and alignment attachment order is independent. Canvas-owned prose and captions use their own Text instructions over their complete theme roles.
Sourcepub fn column_header(
self,
start_column: usize,
span: usize,
text: impl Into<Text>,
) -> Result<Self, Error>
pub fn column_header( self, start_column: usize, span: usize, text: impl Into<Text>, ) -> Result<Self, Error>
Add one measured header spanning contiguous canvas columns. Text can replace the complete Canvas header style and align its lines; the block remains centered over the declared span.
Sourcepub fn row_header(
self,
start_row: usize,
span: usize,
text: impl Into<Text>,
) -> Result<Self, Error>
pub fn row_header( self, start_row: usize, span: usize, text: impl Into<Text>, ) -> Result<Self, Error>
Add one measured header spanning contiguous canvas rows. Local Text style owns its font-relative padding. Line alignment defaults to Center inside the block positioned beside the declared rows.
Sourcepub fn row_title(self, row: usize, text: impl Into<Text>) -> Result<Self, Error>
pub fn row_title(self, row: usize, text: impl Into<Text>) -> Result<Self, Error>
Add one measured title centered above every panel in one canvas row. Text retains an independent complete style and line alignment, defaulting to the Canvas header role and Center.
Sourcepub const fn category_labels(self, policy: CanvasCategoryLabels) -> Self
pub const fn category_labels(self, policy: CanvasCategoryLabels) -> Self
Configure duplicate categorical-label handling across the grid.
Sourcepub fn x_range_group(
self,
cells: impl IntoIterator<Item = (usize, usize)>,
) -> Result<Self, Error>
pub fn x_range_group( self, cells: impl IntoIterator<Item = (usize, usize)>, ) -> Result<Self, Error>
Couple the automatic continuous horizontal range of explicit panel cells.
Grouped cells must contain configured plots without explicit x limits or categorical x domains.
Sourcepub const fn width(self, width: u32) -> Self
pub const fn width(self, width: u32) -> Self
Allocate exactly this width in CSS pixels and derive height from content.
This replaces the complete request, clearing any height set by
Self::size. Without a sizing call, both dimensions derive from content.
Zero is rejected during preflight, without a setter panic.
Sourcepub const fn max_width(self, maximum: u32) -> Self
pub const fn max_width(self, maximum: u32) -> Self
Cap the natural complete Canvas width; height remains content-driven.
This replaces any prior sizing request, retains declared topology and never fills a cap wider than natural content. Embedded Plot sizing requests remain ignored. Zero rejects during owning-root preflight.
Sourcepub const fn size(self, width: u32, height: u32) -> Self
pub const fn size(self, width: u32, height: u32) -> Self
Allocate exactly this width and height in CSS pixels.
This replaces the complete sizing request. All content must fit without changing either dimension; zero dimensions reject during preflight. Embedded Plots do not contribute standalone sizing requests.
Sourcepub fn size_with_unit(
self,
width: f64,
height: f64,
unit: SizeUnit,
) -> Result<Self>
pub fn size_with_unit( self, width: f64, height: f64, unit: SizeUnit, ) -> Result<Self>
Request an exact physical page size, using absolute publication units.
Layout uses the inward spatial budget of this page. Output retains the original size and exact CSS viewport, independently of the raster DPI.
Sourcepub fn title(self, title: impl Into<Text>) -> Self
pub fn title(self, title: impl Into<Text>) -> Self
Set one canvas-level title.
A plain string replaces content while retaining earlier local style and layout. Present Text instructions replace the complete style or layout; an explicit default layout restores owner defaults.
Sourcepub fn subtitle(self, subtitle: impl Into<Text>) -> Self
pub fn subtitle(self, subtitle: impl Into<Text>) -> Self
Set one canvas-level subtitle.
Content and instruction replacement follow Self::title.
Sourcepub fn caption(self, caption: impl Into<Text>) -> Self
pub fn caption(self, caption: impl Into<Text>) -> Self
Set one canvas-level caption.
Content and instruction replacement follow Self::title.
Sourcepub fn labels(self, labels: Labels) -> Self
pub fn labels(self, labels: Labels) -> Self
Apply one reusable automatic-label policy to every configured panel.
Sourcepub fn theme(self, theme: impl Into<Option<Theme>>) -> Self
pub fn theme(self, theme: impl Into<Option<Theme>>) -> Self
Set the Canvas root theme.
Plots without an explicit theme inherit this theme. A theme selected with
Plot::theme completely replaces it for that Plot. If this method is
omitted or cleared, the Canvas root uses its construction default or
Theme::publication.
Shared legend spacing is configured only in the complete theme:
let _ = lichtung_plot::Canvas::grid(1, 1).unwrap().shared_legend_gap(8.0);Sourcepub fn default_theme(self, theme: impl Into<Option<Theme>>) -> Self
pub fn default_theme(self, theme: impl Into<Option<Theme>>) -> Self
Set or clear the local construction default without changing the explicit slot.
Sourcepub fn get_default_theme(&self) -> Option<&Theme>
pub fn get_default_theme(&self) -> Option<&Theme>
Borrow the captured or explicitly set construction default, if any.
Sourcepub fn preflight(&self) -> Result<(), Error>
pub fn preflight(&self) -> Result<(), Error>
Validate the complete composed canvas without opening a backend or creating files.
This checks canvas and grid layout, every chart’s plot-specific data and representability preflight, channel and interval contracts, shared legend compatibility, and nested self-managed plot restrictions.
Sourcepub fn preflight_with_operation(
&self,
options: &OperationOptions,
) -> Result<(), Error>
pub fn preflight_with_operation( &self, options: &OperationOptions, ) -> Result<(), Error>
Preflight the composed canvas using this call’s operation options.
Sourcepub fn render(&self) -> Result<Output, Error>
pub fn render(&self) -> Result<Output, Error>
Prepare and freeze one complete composed scene without creating a file.
The returned output owns all resources needed for repeated publication.
Sourcepub fn render_with_operation(
&self,
options: &OperationOptions,
) -> Result<Output, Error>
pub fn render_with_operation( &self, options: &OperationOptions, ) -> Result<Output, Error>
Freeze the composed canvas using this call’s operation options.
Sourcepub fn render_with_results(&self) -> Result<RenderWithResults, Error>
pub fn render_with_results(&self) -> Result<RenderWithResults, Error>
Freeze the composed canvas and capture its same-operation scientific values.
Sourcepub fn render_with_results_with_operation(
&self,
options: &OperationOptions,
) -> Result<RenderWithResults, Error>
pub fn render_with_results_with_operation( &self, options: &OperationOptions, ) -> Result<RenderWithResults, Error>
Freeze its same-operation results with explicit resource options.
Sourcepub fn svg(&self, path: impl AsRef<Path>) -> Result<Output, Error>
pub fn svg(&self, path: impl AsRef<Path>) -> Result<Output, Error>
Render the composed canvas once and publish an outlined SVG.
Each call performs a new render and returns a reusable frozen output.
The output filename is completed with .svg after conversion.
Sourcepub fn svg_with_operation(
&self,
path: impl AsRef<Path>,
options: &OperationOptions,
) -> Result<Output, Error>
pub fn svg_with_operation( &self, path: impl AsRef<Path>, options: &OperationOptions, ) -> Result<Output, Error>
Render and publish SVG using this call’s operation options.
Sourcepub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> Result<Output, Error>
pub fn svg_preserve_text(&self, path: impl AsRef<Path>) -> Result<Output, Error>
Render once, publish SVG with selectable text, and return a reusable output.
The output filename is completed with .svg after rendering.
Sourcepub fn svg_preserve_text_with_operation(
&self,
path: impl AsRef<Path>,
options: &OperationOptions,
) -> Result<Output, Error>
pub fn svg_preserve_text_with_operation( &self, path: impl AsRef<Path>, options: &OperationOptions, ) -> Result<Output, Error>
Render and publish SVG using this call’s operation options.
Sourcepub fn png(&self, path: impl AsRef<Path>) -> Result<Output, Error>
pub fn png(&self, path: impl AsRef<Path>) -> Result<Output, Error>
Render once, publish a balanced 300-DPI PNG, and return a reusable output.
The output filename is completed with .png after rasterization.
Sourcepub fn png_with_operation(
&self,
path: impl AsRef<Path>,
options: &OperationOptions,
) -> Result<Output, Error>
pub fn png_with_operation( &self, path: impl AsRef<Path>, options: &OperationOptions, ) -> Result<Output, Error>
Render and publish PNG using this call’s operation options.
Sourcepub fn png_preview(&self, path: impl AsRef<Path>) -> Result<Output, Error>
pub fn png_preview(&self, path: impl AsRef<Path>) -> Result<Output, Error>
Render once, publish a balanced source-sized PNG without density metadata.
The output filename is completed with .png after rasterization.
Sourcepub fn png_preview_with_operation(
&self,
path: impl AsRef<Path>,
options: &OperationOptions,
) -> Result<Output, Error>
pub fn png_preview_with_operation( &self, path: impl AsRef<Path>, options: &OperationOptions, ) -> Result<Output, Error>
Render and publish PNG using this call’s operation options.
Sourcepub fn png_with_options(
&self,
path: impl AsRef<Path>,
options: PngOptions,
) -> Result<Output, Error>
pub fn png_with_options( &self, path: impl AsRef<Path>, options: PngOptions, ) -> Result<Output, Error>
Render once and publish a PNG using the exact caller-provided options.
The output filename is completed with .png after rasterization.
Sourcepub fn png_with_options_with_operation(
&self,
path: impl AsRef<Path>,
options: PngOptions,
operation: &OperationOptions,
) -> Result<Output, Error>
pub fn png_with_options_with_operation( &self, path: impl AsRef<Path>, options: PngOptions, operation: &OperationOptions, ) -> Result<Output, Error>
Render and publish PNG with device options and a single operation budget.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Canvas
impl !UnwindSafe for Canvas
impl Forget for Canvas
impl Freeze for Canvaswhere
*const ArcInner<()> is !null: Freeze,
PhantomData<ArcInner<()>>: Freeze,
*const ArcInner<TextInstructions> is !null: Freeze,
PhantomData<ArcInner<TextInstructions>>: Freeze,
*const ArcInner<Placements> is !null: Freeze,
PhantomData<ArcInner<Placements>>: Freeze,
*const ArcInner<Theme> is !null: Freeze,
PhantomData<ArcInner<Theme>>: Freeze,
*const ArcInner<String> is !null: Freeze,
PhantomData<ArcInner<String>>: Freeze,
*const ArcInner<Vec<FontFamily>> is !null: Freeze,
PhantomData<ArcInner<Vec<FontFamily>>>: Freeze,
*const ArcInner<BTreeMap<String, String>> is !null: Freeze,
PhantomData<ArcInner<BTreeMap<String, String>>>: Freeze,
*const ArcInner<BTreeMap<String, CapturedLabel>> is !null: Freeze,
PhantomData<ArcInner<BTreeMap<String, CapturedLabel>>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<CanvasHeader>: Freeze,
PhantomData<Vec<usize>>: Freeze,
impl Move for Canvas
impl Send for Canvas
impl Sync for Canvas
impl Unpin for Canvas
impl UnsafeUnpin for Canvaswhere
*const ArcInner<()> is !null: UnsafeUnpin,
PhantomData<ArcInner<()>>: UnsafeUnpin,
*const ArcInner<TextInstructions> is !null: UnsafeUnpin,
PhantomData<ArcInner<TextInstructions>>: UnsafeUnpin,
*const ArcInner<Placements> is !null: UnsafeUnpin,
PhantomData<ArcInner<Placements>>: UnsafeUnpin,
*const ArcInner<Theme> is !null: UnsafeUnpin,
PhantomData<ArcInner<Theme>>: UnsafeUnpin,
*const ArcInner<String> is !null: UnsafeUnpin,
PhantomData<ArcInner<String>>: UnsafeUnpin,
*const ArcInner<Vec<FontFamily>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Vec<FontFamily>>>: UnsafeUnpin,
*const ArcInner<BTreeMap<String, String>> is !null: UnsafeUnpin,
PhantomData<ArcInner<BTreeMap<String, String>>>: UnsafeUnpin,
*const ArcInner<BTreeMap<String, CapturedLabel>> is !null: UnsafeUnpin,
PhantomData<ArcInner<BTreeMap<String, CapturedLabel>>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<CanvasHeader>: UnsafeUnpin,
PhantomData<Vec<usize>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.