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
impl FlameGraphState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty flame graph state.
§Example
use envision::component::FlameGraphState;
let state = FlameGraphState::new();
assert!(state.root().is_none());Sourcepub fn with_root(root: FlameNode) -> Self
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()");Sourcepub fn with_title(self, title: impl Into<String>) -> Self
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"));Sourcepub fn root(&self) -> Option<&FlameNode>
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()");Sourcepub fn root_mut(&mut self) -> Option<&mut FlameNode>
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());Sourcepub fn set_root(&mut self, root: FlameNode)
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());Sourcepub fn clear(&mut self)
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());Sourcepub fn current_view_root(&self) -> Option<&FlameNode>
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()");Sourcepub fn selected_frame(&self) -> Option<&FlameNode>
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()");Sourcepub fn zoom_stack(&self) -> &[String]
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());Sourcepub fn selected_depth(&self) -> usize
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);Sourcepub fn selected_index(&self) -> usize
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);Sourcepub fn search_query(&self) -> &str
pub fn search_query(&self) -> &str
Returns the search query.
§Example
use envision::component::FlameGraphState;
let state = FlameGraphState::new();
assert_eq!(state.search_query(), "");Sourcepub fn search(&self) -> Option<&str>
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"));Sourcepub fn set_search(&mut self, query: String)
pub fn set_search(&mut self, query: String)
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");Sourcepub fn title(&self) -> Option<&str>
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);Sourcepub fn set_title(&mut self, title: impl Into<String>)
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"));Sourcepub fn zoom_in(&mut self) -> bool
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()");Sourcepub fn zoom_out(&mut self) -> bool
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()");Sourcepub fn reset_zoom(&mut self)
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()");Sourcepub fn select_up(&mut self) -> bool
pub fn select_up(&mut self) -> bool
Moves selection up to parent depth.
Returns true if the selection changed.
Sourcepub fn select_down(&mut self) -> bool
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.
Sourcepub fn select_left(&mut self) -> bool
pub fn select_left(&mut self) -> bool
Moves selection to the previous sibling at the current depth.
Returns true if the selection changed.
Sourcepub fn select_right(&mut self) -> bool
pub fn select_right(&mut self) -> bool
Moves selection to the next sibling at the current depth.
Returns true if the selection changed.
Sourcepub fn update(&mut self, msg: FlameGraphMessage) -> Option<FlameGraphOutput>
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
impl Clone for FlameGraphState
Source§fn clone(&self) -> FlameGraphState
fn clone(&self) -> FlameGraphState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FlameGraphState
impl Debug for FlameGraphState
Source§impl Default for FlameGraphState
impl Default for FlameGraphState
Source§fn default() -> FlameGraphState
fn default() -> FlameGraphState
Source§impl<'de> Deserialize<'de> for FlameGraphState
impl<'de> Deserialize<'de> for FlameGraphState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for FlameGraphState
impl PartialEq for FlameGraphState
Source§impl Serialize for FlameGraphState
impl Serialize for FlameGraphState
impl StructuralPartialEq for FlameGraphState
Auto Trait Implementations§
impl Freeze for FlameGraphState
impl RefUnwindSafe for FlameGraphState
impl Send for FlameGraphState
impl Sync for FlameGraphState
impl Unpin for FlameGraphState
impl UnsafeUnpin for FlameGraphState
impl UnwindSafe for FlameGraphState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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