Skip to main content

TreeLayout

Struct TreeLayout 

Source
pub struct TreeLayout { /* private fields */ }
Expand description

Hierarchical area chart. Squarified layout (Bruls / van Wijk).

Implementations§

Source§

impl TreeLayout

Source

pub fn try_new(root: TreeNode) -> Result<Self, Error>

Root must have positive finite mass.

§Errors

Error::InvalidGrid when mass is not > 0.

Examples found in repository?
examples/gallery.rs (lines 652-675)
651fn demo_tree() -> Result<TreeLayout, sealed_surface::Error> {
652    TreeLayout::try_new(TreeNode::branch(
653        0,
654        "catalog",
655        vec![
656            TreeNode::branch(
657                1,
658                "apparel",
659                vec![
660                    TreeNode::leaf(2, "shirts", 42.0),
661                    TreeNode::leaf(3, "pants", 18.0),
662                    TreeNode::leaf(4, "hats", 9.0),
663                ],
664            ),
665            TreeNode::branch(
666                5,
667                "home",
668                vec![
669                    TreeNode::leaf(6, "lamps", 21.0),
670                    TreeNode::leaf(7, "rugs", 14.0),
671                ],
672            ),
673            TreeNode::leaf(8, "other", 7.0),
674        ],
675    ))
676}
More examples
Hide additional examples
examples/treemap.rs (lines 16-39)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16    let layout = TreeLayout::try_new(TreeNode::branch(
17        0,
18        "catalog",
19        vec![
20            TreeNode::branch(
21                1,
22                "apparel",
23                vec![
24                    TreeNode::leaf(2, "shirts", 42.0),
25                    TreeNode::leaf(3, "pants", 18.0),
26                    TreeNode::leaf(4, "hats", 9.0),
27                ],
28            ),
29            TreeNode::branch(
30                5,
31                "home",
32                vec![
33                    TreeNode::leaf(6, "lamps", 21.0),
34                    TreeNode::leaf(7, "rugs", 14.0),
35                ],
36            ),
37            TreeNode::leaf(8, "other", 7.0),
38        ],
39    ))?;
40
41    let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/renders");
42    fs::create_dir_all(&dir)?;
43
44    let mut sealed = Surface::new(SurfaceMode::Sealed, LicenseLens::open());
45    let vp = Viewport::window(520, 280);
46    let rest = FrameRequest::full(vp).caption("catalog");
47    let idle = sealed.render_tree(&layout, &rest)?;
48    fs::write(dir.join("tm_sealed.png"), &idle.png)?;
49    fs::write(dir.join("readme_tree.png"), &idle.png)?;
50
51    let hit = sealed.render_tree(&layout, &rest.clone().pointer(Pointer::new(80, 90)))?;
52    fs::write(dir.join("tm_hover.png"), &hit.png)?;
53    if let Some(tip) = &hit.tooltip_png {
54        fs::write(dir.join("tm_tooltip.png"), tip)?;
55    }
56    println!(
57        "sealed tree audit={:?} hits={} tooltip={}",
58        hit.host.audit_text(),
59        hit.hits.len(),
60        hit.tooltip_png.as_ref().map_or(0, Vec::len)
61    );
62
63    sealed.set_mode(SurfaceMode::Copyable);
64    let copy = sealed.render_tree(&layout, &rest)?;
65    fs::write(dir.join("tm_copyable.png"), &copy.png)?;
66    println!(
67        "copyable TSV (120): {:?}",
68        copy.host.audit_text().chars().take(120).collect::<String>()
69    );
70
71    let trial = Surface::new(
72        SurfaceMode::Sealed,
73        LicenseLens::from_tier(AccessTier::Trial),
74    );
75    let t = trial.render_tree(&layout, &rest)?;
76    fs::write(dir.join("tm_trial_lens.png"), &t.png)?;
77    println!(
78        "wrote treemap renders; trial viewed rows={}",
79        t.viewed.rows.len()
80    );
81    Ok(())
82}
Source

pub fn root(&self) -> &TreeNode

Root as supplied (pre-lens).

Source

pub fn render( &self, surface: &Surface, request: &FrameRequest, ) -> Result<Frame, Error>

Paint on surface (same PNG / host contract as tables).

§Errors

Raster failure.

Trait Implementations§

Source§

impl Clone for TreeLayout

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
Source§

impl Debug for TreeLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TreeLayout

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TreeLayout

Auto Trait Implementations§

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<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> 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.