Skip to main content

SpanTreeState

Struct SpanTreeState 

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

State for a SpanTree component.

Contains the root spans, selection state, expanded set, and layout configuration.

§Example

use envision::component::{SpanTreeState, SpanNode};

let root = SpanNode::new("r", "root", 0.0, 1000.0)
    .with_child(SpanNode::new("c", "child", 100.0, 500.0));
let state = SpanTreeState::new(vec![root]);

assert_eq!(state.roots().len(), 1);
assert_eq!(state.global_start(), 0.0);
assert_eq!(state.global_end(), 1000.0);
assert_eq!(state.selected_index(), Some(0));

Implementations§

Source§

impl SpanTreeState

Source

pub fn new(roots: Vec<SpanNode>) -> Self

Creates a new span tree state with the given root spans.

All nodes with children start expanded. The first node is selected if the tree is non-empty.

§Example
use envision::component::{SpanTreeState, SpanNode};

let root = SpanNode::new("r", "root", 0.0, 100.0)
    .with_child(SpanNode::new("c", "child", 10.0, 50.0));
let state = SpanTreeState::new(vec![root]);

assert_eq!(state.roots().len(), 1);
assert_eq!(state.selected_index(), Some(0));
assert_eq!(state.global_start(), 0.0);
assert_eq!(state.global_end(), 100.0);
Source

pub fn with_title(self, title: impl Into<String>) -> Self

Sets the title (builder pattern).

§Example
use envision::component::{SpanTreeState, SpanNode};

let state = SpanTreeState::new(vec![SpanNode::new("r", "root", 0.0, 10.0)])
    .with_title("Trace");
assert_eq!(state.title(), Some("Trace"));
Source

pub fn with_label_width(self, width: u16) -> Self

Sets the label column width (builder pattern).

§Example
use envision::component::{SpanTreeState, SpanNode};

let state = SpanTreeState::new(vec![SpanNode::new("r", "root", 0.0, 10.0)])
    .with_label_width(40);
assert_eq!(state.label_width(), 40);
Source

pub fn roots(&self) -> &[SpanNode]

Returns the root spans.

§Example
use envision::component::{SpanTreeState, SpanNode};

let state = SpanTreeState::new(vec![
    SpanNode::new("a", "svc-a", 0.0, 10.0),
    SpanNode::new("b", "svc-b", 5.0, 15.0),
]);
assert_eq!(state.roots().len(), 2);
Source

pub fn roots_mut(&mut self) -> &mut Vec<SpanNode>

Returns a mutable reference to the root spans.

This is safe because span nodes are simple data containers. The expanded set tracks nodes by string id, so mutating node data does not corrupt expand/collapse state.

§Example
use envision::component::{SpanTreeState, SpanNode};
use ratatui::style::Color;

let root = SpanNode::new("r", "root", 0.0, 100.0);
let mut state = SpanTreeState::new(vec![root]);
state.roots_mut()[0].set_color(Color::Red);
assert_eq!(state.roots()[0].color(), Color::Red);

Note: After modifying the collection, the scrollbar may be inaccurate until the next render. Prefer dedicated methods (e.g., push_event()) when available.

Source

pub fn set_roots(&mut self, roots: Vec<SpanNode>)

Replaces all root spans and recomputes global times.

§Example
use envision::component::{SpanTreeState, SpanNode};

let mut state = SpanTreeState::new(vec![SpanNode::new("old", "old", 0.0, 10.0)]);
state.set_roots(vec![SpanNode::new("new", "new", 5.0, 50.0)]);
assert_eq!(state.roots().len(), 1);
assert_eq!(state.global_start(), 5.0);
assert_eq!(state.global_end(), 50.0);
Source

pub fn selected_index(&self) -> Option<usize>

Returns the currently selected flat index.

§Example
use envision::component::{SpanTreeState, SpanNode};

let state = SpanTreeState::new(vec![SpanNode::new("r", "root", 0.0, 10.0)]);
assert_eq!(state.selected_index(), Some(0));

let empty = SpanTreeState::default();
assert_eq!(empty.selected_index(), None);
Source

pub fn selected_span(&self) -> Option<FlatSpan>

Returns the currently selected span in flattened view.

§Example
use envision::component::{SpanTreeState, SpanNode};

let root = SpanNode::new("r", "root", 0.0, 100.0);
let state = SpanTreeState::new(vec![root]);
let selected = state.selected_span().unwrap();
assert_eq!(selected.id(), "r");
assert_eq!(selected.label(), "root");
Source

pub fn global_start(&self) -> f64

Returns the earliest start time across all spans.

Source

pub fn global_end(&self) -> f64

Returns the latest end time across all spans.

Source

pub fn label_width(&self) -> u16

Returns the label column width.

Source

pub fn title(&self) -> Option<&str>

Returns the title, if set.

Source

pub fn set_title(&mut self, title: impl Into<String>)

Sets the title.

§Example
use envision::component::SpanTreeState;

let mut state = SpanTreeState::default();
state.set_title("Trace View");
assert_eq!(state.title(), Some("Trace View"));
Source

pub fn is_empty(&self) -> bool

Returns true if the tree is empty.

§Example
use envision::component::SpanTreeState;

assert!(SpanTreeState::default().is_empty());
Source

pub fn expanded_ids(&self) -> &HashSet<String>

Returns the set of expanded node IDs.

Source

pub fn expand(&mut self, id: &str)

Expands a node by its ID.

§Example
use envision::component::{SpanTreeState, SpanNode};

let root = SpanNode::new("r", "root", 0.0, 100.0)
    .with_child(SpanNode::new("c", "child", 10.0, 50.0));
let mut state = SpanTreeState::new(vec![root]);
state.collapse("r");
assert!(!state.expanded_ids().contains("r"));
state.expand("r");
assert!(state.expanded_ids().contains("r"));
Source

pub fn collapse(&mut self, id: &str)

Collapses a node by its ID.

§Example
use envision::component::{SpanTreeState, SpanNode};

let root = SpanNode::new("r", "root", 0.0, 100.0)
    .with_child(SpanNode::new("c", "child", 10.0, 50.0));
let mut state = SpanTreeState::new(vec![root]);
state.collapse("r");
assert!(!state.expanded_ids().contains("r"));
Source

pub fn expand_all(&mut self)

Expands all nodes.

§Example
use envision::component::{SpanTreeState, SpanNode};

let root = SpanNode::new("r", "root", 0.0, 100.0)
    .with_child(SpanNode::new("c", "child", 10.0, 50.0));
let mut state = SpanTreeState::new(vec![root]);
state.collapse_all();
state.expand_all();
assert!(state.expanded_ids().contains("r"));
Source

pub fn collapse_all(&mut self)

Collapses all nodes.

§Example
use envision::component::{SpanTreeState, SpanNode};

let root = SpanNode::new("r", "root", 0.0, 100.0)
    .with_child(SpanNode::new("c", "child", 10.0, 50.0));
let mut state = SpanTreeState::new(vec![root]);
state.collapse_all();
assert!(state.expanded_ids().is_empty());
Source

pub fn flatten(&self) -> Vec<FlatSpan>

Flattens the visible hierarchy into a list of FlatSpan items.

Only expanded nodes have their children included. The order is depth-first, matching the visual tree order.

§Example
use envision::component::{SpanTreeState, SpanNode};

let root = SpanNode::new("r", "root", 0.0, 100.0)
    .with_child(SpanNode::new("c1", "child-1", 10.0, 50.0))
    .with_child(SpanNode::new("c2", "child-2", 50.0, 90.0));
let state = SpanTreeState::new(vec![root]);
let flat = state.flatten();
assert_eq!(flat.len(), 3);
assert_eq!(flat[0].id(), "r");
assert_eq!(flat[0].depth(), 0);
assert_eq!(flat[1].id(), "c1");
assert_eq!(flat[1].depth(), 1);
Source

pub fn update(&mut self, msg: SpanTreeMessage) -> Option<SpanTreeOutput>

Updates the state with a message, returning any output.

Trait Implementations§

Source§

impl Clone for SpanTreeState

Source§

fn clone(&self) -> SpanTreeState

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SpanTreeState

Source§

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

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

impl Default for SpanTreeState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SpanTreeState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for SpanTreeState

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for SpanTreeState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SpanTreeState

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> StateExt for T

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,