Skip to main content

FlameGraphState

Struct FlameGraphState 

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

State for a FlameGraph component.

Contains the root flame node, zoom stack, selection state, and search configuration.

§Example

use envision::component::{FlameGraphState, FlameNode};

let root = FlameNode::new("main()", 500)
    .with_child(FlameNode::new("compute()", 300));
let state = FlameGraphState::with_root(root);

assert!(state.root().is_some());
assert_eq!(state.selected_depth(), 0);
assert_eq!(state.selected_index(), 0);

Implementations§

Source§

impl FlameGraphState

Source

pub fn new() -> Self

Creates an empty flame graph state.

§Example
use envision::component::FlameGraphState;

let state = FlameGraphState::new();
assert!(state.root().is_none());
Source

pub fn with_root(root: FlameNode) -> Self

Creates a flame graph state with the given root frame.

§Example
use envision::component::{FlameGraphState, FlameNode};

let root = FlameNode::new("main()", 500);
let state = FlameGraphState::with_root(root);
assert!(state.root().is_some());
assert_eq!(state.root().unwrap().label(), "main()");
Source

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

Sets the title (builder pattern).

§Example
use envision::component::{FlameGraphState, FlameNode};

let state = FlameGraphState::with_root(FlameNode::new("main()", 500))
    .with_title("CPU Profile");
assert_eq!(state.title(), Some("CPU Profile"));
Source

pub fn root(&self) -> Option<&FlameNode>

Returns the root frame, if any.

§Example
use envision::component::{FlameGraphState, FlameNode};

let state = FlameGraphState::with_root(FlameNode::new("main()", 500));
assert_eq!(state.root().unwrap().label(), "main()");
Source

pub fn root_mut(&mut self) -> Option<&mut FlameNode>

Returns a mutable reference to the root frame, if any.

This is safe because the flame node tree is simple data. The zoom stack references nodes by label, so mutating node values or children does not corrupt navigation state.

§Example
use envision::component::{FlameGraphState, FlameNode};
use ratatui::style::Color;

let root = FlameNode::new("main()", 500);
let mut state = FlameGraphState::with_root(root);
if let Some(r) = state.root_mut() {
    *r = r.clone().with_color(Color::Red);
}
assert!(state.root().is_some());
Source

pub fn set_root(&mut self, root: FlameNode)

Sets the root frame.

Resets zoom and selection state.

§Example
use envision::component::{FlameGraphState, FlameNode};

let mut state = FlameGraphState::new();
state.set_root(FlameNode::new("main()", 500));
assert!(state.root().is_some());
Source

pub fn clear(&mut self)

Clears the flame graph.

§Example
use envision::component::{FlameGraphState, FlameNode};

let mut state = FlameGraphState::with_root(FlameNode::new("main()", 500));
state.clear();
assert!(state.root().is_none());
Source

pub fn current_view_root(&self) -> Option<&FlameNode>

Returns the currently visible root (after zoom).

Follows the zoom stack to find the currently displayed subtree root.

§Example
use envision::component::{FlameGraphState, FlameNode};

let root = FlameNode::new("main()", 500)
    .with_child(FlameNode::new("compute()", 300));
let state = FlameGraphState::with_root(root);
assert_eq!(state.current_view_root().unwrap().label(), "main()");
Source

pub fn selected_frame(&self) -> Option<&FlameNode>

Returns the currently selected frame.

§Example
use envision::component::{FlameGraphState, FlameNode};

let root = FlameNode::new("main()", 500)
    .with_child(FlameNode::new("compute()", 300));
let state = FlameGraphState::with_root(root);
assert_eq!(state.selected_frame().unwrap().label(), "main()");
Source

pub fn zoom_stack(&self) -> &[String]

Returns the zoom stack.

§Example
use envision::component::FlameGraphState;

let state = FlameGraphState::new();
assert!(state.zoom_stack().is_empty());
Source

pub fn selected_depth(&self) -> usize

Returns the selected depth level.

§Example
use envision::component::FlameGraphState;

let state = FlameGraphState::new();
assert_eq!(state.selected_depth(), 0);
Source

pub fn selected_index(&self) -> usize

Returns the selected frame index at the current depth.

§Example
use envision::component::FlameGraphState;

let state = FlameGraphState::new();
assert_eq!(state.selected_index(), 0);
Source

pub fn search_query(&self) -> &str

Returns the search query.

§Example
use envision::component::FlameGraphState;

let state = FlameGraphState::new();
assert_eq!(state.search_query(), "");
Source

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

Returns the search query as an Option<&str>, or None if empty.

§Example
use envision::component::{FlameGraphState, FlameNode};

let state = FlameGraphState::new();
assert_eq!(state.search(), None);

let mut state = FlameGraphState::with_root(FlameNode::new("main()", 500));
state.set_search("compute".to_string());
assert_eq!(state.search(), Some("compute"));

Sets the search query.

§Example
use envision::component::{FlameGraphState, FlameNode};

let mut state = FlameGraphState::with_root(FlameNode::new("main()", 500));
state.set_search("compute".to_string());
assert_eq!(state.search_query(), "compute");
Source

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

Returns the title, if set.

§Example
use envision::component::FlameGraphState;

let state = FlameGraphState::new();
assert_eq!(state.title(), None);
Source

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

Sets the title.

§Example
use envision::component::FlameGraphState;

let mut state = FlameGraphState::new();
state.set_title("CPU Profile");
assert_eq!(state.title(), Some("CPU Profile"));
Source

pub fn zoom_in(&mut self) -> bool

Zooms into the currently selected frame, making it the new view root.

Only zooms if the selected frame has children.

§Example
use envision::component::{FlameGraphState, FlameNode};

let root = FlameNode::new("main()", 500)
    .with_child(FlameNode::new("compute()", 300)
        .with_child(FlameNode::new("sort()", 200)));
let mut state = FlameGraphState::with_root(root);

// Select compute() (depth 1, index 0)
state.select_down();
// Zoom into compute()
let zoomed = state.zoom_in();
assert!(zoomed);
assert_eq!(state.current_view_root().unwrap().label(), "compute()");
Source

pub fn zoom_out(&mut self) -> bool

Zooms out one level.

§Example
use envision::component::{FlameGraphState, FlameNode};

let root = FlameNode::new("main()", 500)
    .with_child(FlameNode::new("compute()", 300)
        .with_child(FlameNode::new("sort()", 200)));
let mut state = FlameGraphState::with_root(root);
state.select_down();
state.zoom_in();
assert!(state.zoom_out());
assert_eq!(state.current_view_root().unwrap().label(), "main()");
Source

pub fn reset_zoom(&mut self)

Resets zoom to the original root.

§Example
use envision::component::{FlameGraphState, FlameNode};

let root = FlameNode::new("main()", 500)
    .with_child(FlameNode::new("compute()", 300)
        .with_child(FlameNode::new("sort()", 200)));
let mut state = FlameGraphState::with_root(root);
state.select_down();
state.zoom_in();
state.reset_zoom();
assert!(state.zoom_stack().is_empty());
assert_eq!(state.current_view_root().unwrap().label(), "main()");
Source

pub fn select_up(&mut self) -> bool

Moves selection up to parent depth.

Returns true if the selection changed.

Source

pub fn select_down(&mut self) -> bool

Moves selection down to child depth.

Selects the first child of the nearest ancestor that has children at the next depth level.

Returns true if the selection changed.

Source

pub fn select_left(&mut self) -> bool

Moves selection to the previous sibling at the current depth.

Returns true if the selection changed.

Source

pub fn select_right(&mut self) -> bool

Moves selection to the next sibling at the current depth.

Returns true if the selection changed.

Source

pub fn update(&mut self, msg: FlameGraphMessage) -> Option<FlameGraphOutput>

Updates the state with a message, returning any output.

Trait Implementations§

Source§

impl Clone for FlameGraphState

Source§

fn clone(&self) -> FlameGraphState

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 FlameGraphState

Source§

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

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

impl Default for FlameGraphState

Source§

fn default() -> FlameGraphState

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

impl<'de> Deserialize<'de> for FlameGraphState

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 FlameGraphState

Source§

fn eq(&self, other: &FlameGraphState) -> 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 FlameGraphState

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 FlameGraphState

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