Skip to main content

Canvas

Struct Canvas 

Source
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

Source

pub fn elements(&self, query: ElementQuery) -> Result<Vec<ElementRef>>

Discover real scientific layers in the canvas or in an actual panel.

Source

pub fn element_ref(&self, query: impl Into<ElementQuery>) -> Result<ElementRef>

Select one actual layer in the canvas.

Source

pub fn read_element(&self, reference: &ElementRef) -> Result<ElementSnapshot>

Read the owning declaration at its actual placed address.

Source

pub fn data_roles(&self) -> Result<Vec<DataRoleInfo>>

Discover all original input roles of the actual independent placements.

Source

pub fn data_roles_at(&self, target: &ElementRef) -> Result<Vec<DataRoleInfo>>

Discover original inputs of one actual layer.

Source

pub fn data_roles_in(&self, panel: &PanelPath) -> Result<Vec<DataRoleInfo>>

Discover original inputs of the actual layers in a panel.

Source

pub fn data(&self, selector: impl Into<DataSelector>) -> Result<DataValue>

Read an original role in the unique primary layer, or use its actual reference.

Source§

impl Canvas

Source

pub fn clear_title_style(self) -> Self

Remove the local root title appearance override without changing content/layout or child plots.

Source

pub fn clear_title_layout(self) -> Self

Remove the local root title layout request without changing content/style or child plots.

Source§

impl Canvas

Source

pub fn clear_subtitle_style(self) -> Self

Remove the local root subtitle appearance override without changing content/layout or child plots.

Source

pub fn clear_subtitle_layout(self) -> Self

Remove the local root subtitle layout request without changing content/style or child plots.

Source§

impl Canvas

Source

pub fn clear_caption_style(self) -> Self

Remove the local root caption appearance override without changing content/layout or child plots.

Source

pub fn clear_caption_layout(self) -> Self

Remove the local root caption layout request without changing content/style or child plots.

Source§

impl Canvas

Source

pub fn guide_text_layout(self, role: GuideTextRole, layout: TextLayout) -> Self

Replace one Canvas-owned Shared guide role’s complete layout default.

Source

pub fn grid(rows: usize, columns: usize) -> Result<Self, Error>

Construct a non-empty panel grid.

Source

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.

Source

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);
Source

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())?;
Source

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())?;
Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn legend_policy(self, policy: CanvasLegendPolicy) -> Self

Set per-panel, shared, or hidden legend behavior.

Source

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);
Source

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"))?;
Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn category_labels(self, policy: CanvasCategoryLabels) -> Self

Configure duplicate categorical-label handling across the grid.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn subtitle(self, subtitle: impl Into<Text>) -> Self

Set one canvas-level subtitle. Content and instruction replacement follow Self::title.

Source

pub fn caption(self, caption: impl Into<Text>) -> Self

Set one canvas-level caption. Content and instruction replacement follow Self::title.

Source

pub fn labels(self, labels: Labels) -> Self

Apply one reusable automatic-label policy to every configured panel.

Source

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);
Source

pub fn default_theme(self, theme: impl Into<Option<Theme>>) -> Self

Set or clear the local construction default without changing the explicit slot.

Source

pub fn get_theme(&self) -> Option<&Theme>

Borrow the explicitly selected root theme, if any.

Source

pub fn get_default_theme(&self) -> Option<&Theme>

Borrow the captured or explicitly set construction default, if any.

Source

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.

Source

pub fn preflight_with_operation( &self, options: &OperationOptions, ) -> Result<(), Error>

Preflight the composed canvas using this call’s operation options.

Source

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.

Source

pub fn render_with_operation( &self, options: &OperationOptions, ) -> Result<Output, Error>

Freeze the composed canvas using this call’s operation options.

Source

pub fn render_with_results(&self) -> Result<RenderWithResults, Error>

Freeze the composed canvas and capture its same-operation scientific values.

Source

pub fn render_with_results_with_operation( &self, options: &OperationOptions, ) -> Result<RenderWithResults, Error>

Freeze its same-operation results with explicit resource options.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Canvas

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Canvas

§

impl !UnwindSafe for Canvas

§

impl Forget for Canvas

§

impl Freeze for Canvas
where *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
where Arc<()>: Send, Arc<TextInstructions>: Send, Arc<Placements>: Send, Arc<Theme>: Send, Arc<String>: Send, Arc<Vec<FontFamily>>: Send, Arc<BTreeMap<String, String>>: Send, Arc<BTreeMap<String, CapturedLabel>>: Send, RawVecInner: Send,

§

impl Sync for Canvas
where Arc<()>: Sync, Arc<TextInstructions>: Sync, Arc<Placements>: Sync, Arc<Theme>: Sync, Arc<String>: Sync, Arc<Vec<FontFamily>>: Sync, Arc<BTreeMap<String, String>>: Sync, Arc<BTreeMap<String, CapturedLabel>>: Sync, RawVecInner: Sync,

§

impl Unpin for Canvas
where Arc<()>: Unpin, Arc<TextInstructions>: Unpin, Arc<Placements>: Unpin, Arc<Theme>: Unpin, Arc<String>: Unpin, Arc<Vec<FontFamily>>: Unpin, Arc<BTreeMap<String, String>>: Unpin, Arc<BTreeMap<String, CapturedLabel>>: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Canvas
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V