BarChart

Struct BarChart 

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

Bar chart component.

Implementations§

Source§

impl BarChart

Source

pub fn new() -> Self

Create a new bar chart.

Examples found in repository?
examples/03_molecules.rs (line 149)
25fn main() {
26    // Test Select
27    let select = Select::new()
28        .items(["Option 1", "Option 2", "Option 3"])
29        .selected(1)
30        .open(true)
31        .build();
32
33    println!("Select: {:?}\n", matches!(select, VNode::Box(_)));
34
35    // Test RadioGroup
36    let radio = RadioGroup::new()
37        .items(["Small", "Medium", "Large"])
38        .selected(1)
39        .label("Size")
40        .build();
41
42    println!("RadioGroup: {:?}\n", matches!(radio, VNode::Box(_)));
43
44    // Test Autocomplete
45    let autocomplete = Autocomplete::new()
46        .suggestions([
47            Suggestion::new("Rust").description("Systems programming"),
48            Suggestion::new("Python").description("Scripting"),
49            Suggestion::new("JavaScript").description("Web development"),
50        ])
51        .value("Ru")
52        .open(true)
53        .build();
54
55    println!("Autocomplete: {:?}\n", matches!(autocomplete, VNode::Box(_)));
56
57    // Test Table
58    let table = Table::new()
59        .columns([
60            Column::new("Name").width(20),
61            Column::new("Age").width(10).align(Align::Right),
62            Column::new("City").width(15),
63        ])
64        .rows([
65            vec!["Alice".to_string(), "30".to_string(), "NYC".to_string()],
66            vec!["Bob".to_string(), "25".to_string(), "LA".to_string()],
67            vec!["Carol".to_string(), "35".to_string(), "SF".to_string()],
68        ])
69        .build();
70
71    println!("Table: {:?}\n", matches!(table, VNode::Box(_)));
72
73    // Test Tree
74    let tree = Tree::new()
75        .nodes([
76            TreeNode::folder("src")
77                .expanded(true)
78                .children([
79                    TreeNode::file("main.rs"),
80                    TreeNode::file("lib.rs"),
81                    TreeNode::folder("core")
82                        .children([
83                            TreeNode::file("app.rs"),
84                            TreeNode::file("signals.rs"),
85                        ]),
86                ]),
87            TreeNode::file("Cargo.toml"),
88        ])
89        .build();
90
91    println!("Tree: {:?}\n", matches!(tree, VNode::Box(_)));
92
93    // Test Calendar
94    let calendar = Calendar::new()
95        .date(2025, 1)
96        .selected(15)
97        .today(2025, 1, 24)
98        .build();
99
100    println!("Calendar: {:?}\n", matches!(calendar, VNode::Box(_)));
101
102    // Test Tabs
103    let tabs = Tabs::new()
104        .tabs([
105            Tab::new("Overview"),
106            Tab::new("Details").disabled(),
107            Tab::new("Settings"),
108        ])
109        .active(0)
110        .build();
111
112    println!("Tabs: {:?}\n", matches!(tabs, VNode::Box(_)));
113
114    // Test CodeBlock
115    let code = CodeBlock::new(r#"
116fn main() {
117    println!("Hello, Tuiuiu!");
118}
119"#)
120        .rust()
121        .highlight([2])
122        .build();
123
124    println!("CodeBlock: {:?}\n", matches!(code, VNode::Box(_)));
125
126    // Test Markdown
127    let md = Markdown::new(r#"
128# Title
129## Subtitle
130
131- Item 1
132- Item 2
133
134> A quote
135
136`code`
137"#).build();
138
139    println!("Markdown: {:?}\n", matches!(md, VNode::Box(_)));
140
141    // Test Sparkline
142    let sparkline = Sparkline::new()
143        .data([1.0, 4.0, 2.0, 8.0, 5.0, 7.0, 3.0, 6.0])
144        .build();
145
146    println!("Sparkline: {:?}\n", matches!(sparkline, VNode::Box(_)));
147
148    // Test BarChart
149    let bar_chart = BarChart::new()
150        .items([
151            BarItem::new("A", 30.0),
152            BarItem::new("B", 50.0),
153            BarItem::new("C", 20.0),
154        ])
155        .build();
156
157    println!("BarChart: {:?}\n", matches!(bar_chart, VNode::Box(_)));
158
159    // Test Gauge (returns Text node, not Box)
160    let gauge = Gauge::new()
161        .value(75.0)
162        .max(100.0)
163        .label("Progress")
164        .build();
165
166    println!("Gauge: {:?}\n", matches!(gauge, VNode::Text(_)));
167
168    println!("✅ All molecules compiled and instantiated successfully!");
169}
Source

pub fn items<I>(self, items: I) -> Self
where I: IntoIterator<Item = BarItem>,

Set bar items.

Examples found in repository?
examples/03_molecules.rs (lines 150-154)
25fn main() {
26    // Test Select
27    let select = Select::new()
28        .items(["Option 1", "Option 2", "Option 3"])
29        .selected(1)
30        .open(true)
31        .build();
32
33    println!("Select: {:?}\n", matches!(select, VNode::Box(_)));
34
35    // Test RadioGroup
36    let radio = RadioGroup::new()
37        .items(["Small", "Medium", "Large"])
38        .selected(1)
39        .label("Size")
40        .build();
41
42    println!("RadioGroup: {:?}\n", matches!(radio, VNode::Box(_)));
43
44    // Test Autocomplete
45    let autocomplete = Autocomplete::new()
46        .suggestions([
47            Suggestion::new("Rust").description("Systems programming"),
48            Suggestion::new("Python").description("Scripting"),
49            Suggestion::new("JavaScript").description("Web development"),
50        ])
51        .value("Ru")
52        .open(true)
53        .build();
54
55    println!("Autocomplete: {:?}\n", matches!(autocomplete, VNode::Box(_)));
56
57    // Test Table
58    let table = Table::new()
59        .columns([
60            Column::new("Name").width(20),
61            Column::new("Age").width(10).align(Align::Right),
62            Column::new("City").width(15),
63        ])
64        .rows([
65            vec!["Alice".to_string(), "30".to_string(), "NYC".to_string()],
66            vec!["Bob".to_string(), "25".to_string(), "LA".to_string()],
67            vec!["Carol".to_string(), "35".to_string(), "SF".to_string()],
68        ])
69        .build();
70
71    println!("Table: {:?}\n", matches!(table, VNode::Box(_)));
72
73    // Test Tree
74    let tree = Tree::new()
75        .nodes([
76            TreeNode::folder("src")
77                .expanded(true)
78                .children([
79                    TreeNode::file("main.rs"),
80                    TreeNode::file("lib.rs"),
81                    TreeNode::folder("core")
82                        .children([
83                            TreeNode::file("app.rs"),
84                            TreeNode::file("signals.rs"),
85                        ]),
86                ]),
87            TreeNode::file("Cargo.toml"),
88        ])
89        .build();
90
91    println!("Tree: {:?}\n", matches!(tree, VNode::Box(_)));
92
93    // Test Calendar
94    let calendar = Calendar::new()
95        .date(2025, 1)
96        .selected(15)
97        .today(2025, 1, 24)
98        .build();
99
100    println!("Calendar: {:?}\n", matches!(calendar, VNode::Box(_)));
101
102    // Test Tabs
103    let tabs = Tabs::new()
104        .tabs([
105            Tab::new("Overview"),
106            Tab::new("Details").disabled(),
107            Tab::new("Settings"),
108        ])
109        .active(0)
110        .build();
111
112    println!("Tabs: {:?}\n", matches!(tabs, VNode::Box(_)));
113
114    // Test CodeBlock
115    let code = CodeBlock::new(r#"
116fn main() {
117    println!("Hello, Tuiuiu!");
118}
119"#)
120        .rust()
121        .highlight([2])
122        .build();
123
124    println!("CodeBlock: {:?}\n", matches!(code, VNode::Box(_)));
125
126    // Test Markdown
127    let md = Markdown::new(r#"
128# Title
129## Subtitle
130
131- Item 1
132- Item 2
133
134> A quote
135
136`code`
137"#).build();
138
139    println!("Markdown: {:?}\n", matches!(md, VNode::Box(_)));
140
141    // Test Sparkline
142    let sparkline = Sparkline::new()
143        .data([1.0, 4.0, 2.0, 8.0, 5.0, 7.0, 3.0, 6.0])
144        .build();
145
146    println!("Sparkline: {:?}\n", matches!(sparkline, VNode::Box(_)));
147
148    // Test BarChart
149    let bar_chart = BarChart::new()
150        .items([
151            BarItem::new("A", 30.0),
152            BarItem::new("B", 50.0),
153            BarItem::new("C", 20.0),
154        ])
155        .build();
156
157    println!("BarChart: {:?}\n", matches!(bar_chart, VNode::Box(_)));
158
159    // Test Gauge (returns Text node, not Box)
160    let gauge = Gauge::new()
161        .value(75.0)
162        .max(100.0)
163        .label("Progress")
164        .build();
165
166    println!("Gauge: {:?}\n", matches!(gauge, VNode::Text(_)));
167
168    println!("✅ All molecules compiled and instantiated successfully!");
169}
Source

pub fn data<I, S>(self, data: I) -> Self
where I: IntoIterator<Item = (S, f64)>, S: Into<String>,

Set data from label-value pairs.

Source

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

Set chart width.

Source

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

Set bar width (height in horizontal mode).

Source

pub fn orientation(self, orientation: BarOrientation) -> Self

Set orientation.

Source

pub fn horizontal(self) -> Self

Use horizontal bars.

Source

pub fn vertical(self) -> Self

Use vertical bars.

Source

pub fn color(self, color: Color) -> Self

Set default color.

Source

pub fn show_values(self, show: bool) -> Self

Show values on bars.

Source

pub fn max(self, max: f64) -> Self

Set maximum value (for scaling).

Source

pub fn build(self) -> VNode

Build the VNode.

Examples found in repository?
examples/03_molecules.rs (line 155)
25fn main() {
26    // Test Select
27    let select = Select::new()
28        .items(["Option 1", "Option 2", "Option 3"])
29        .selected(1)
30        .open(true)
31        .build();
32
33    println!("Select: {:?}\n", matches!(select, VNode::Box(_)));
34
35    // Test RadioGroup
36    let radio = RadioGroup::new()
37        .items(["Small", "Medium", "Large"])
38        .selected(1)
39        .label("Size")
40        .build();
41
42    println!("RadioGroup: {:?}\n", matches!(radio, VNode::Box(_)));
43
44    // Test Autocomplete
45    let autocomplete = Autocomplete::new()
46        .suggestions([
47            Suggestion::new("Rust").description("Systems programming"),
48            Suggestion::new("Python").description("Scripting"),
49            Suggestion::new("JavaScript").description("Web development"),
50        ])
51        .value("Ru")
52        .open(true)
53        .build();
54
55    println!("Autocomplete: {:?}\n", matches!(autocomplete, VNode::Box(_)));
56
57    // Test Table
58    let table = Table::new()
59        .columns([
60            Column::new("Name").width(20),
61            Column::new("Age").width(10).align(Align::Right),
62            Column::new("City").width(15),
63        ])
64        .rows([
65            vec!["Alice".to_string(), "30".to_string(), "NYC".to_string()],
66            vec!["Bob".to_string(), "25".to_string(), "LA".to_string()],
67            vec!["Carol".to_string(), "35".to_string(), "SF".to_string()],
68        ])
69        .build();
70
71    println!("Table: {:?}\n", matches!(table, VNode::Box(_)));
72
73    // Test Tree
74    let tree = Tree::new()
75        .nodes([
76            TreeNode::folder("src")
77                .expanded(true)
78                .children([
79                    TreeNode::file("main.rs"),
80                    TreeNode::file("lib.rs"),
81                    TreeNode::folder("core")
82                        .children([
83                            TreeNode::file("app.rs"),
84                            TreeNode::file("signals.rs"),
85                        ]),
86                ]),
87            TreeNode::file("Cargo.toml"),
88        ])
89        .build();
90
91    println!("Tree: {:?}\n", matches!(tree, VNode::Box(_)));
92
93    // Test Calendar
94    let calendar = Calendar::new()
95        .date(2025, 1)
96        .selected(15)
97        .today(2025, 1, 24)
98        .build();
99
100    println!("Calendar: {:?}\n", matches!(calendar, VNode::Box(_)));
101
102    // Test Tabs
103    let tabs = Tabs::new()
104        .tabs([
105            Tab::new("Overview"),
106            Tab::new("Details").disabled(),
107            Tab::new("Settings"),
108        ])
109        .active(0)
110        .build();
111
112    println!("Tabs: {:?}\n", matches!(tabs, VNode::Box(_)));
113
114    // Test CodeBlock
115    let code = CodeBlock::new(r#"
116fn main() {
117    println!("Hello, Tuiuiu!");
118}
119"#)
120        .rust()
121        .highlight([2])
122        .build();
123
124    println!("CodeBlock: {:?}\n", matches!(code, VNode::Box(_)));
125
126    // Test Markdown
127    let md = Markdown::new(r#"
128# Title
129## Subtitle
130
131- Item 1
132- Item 2
133
134> A quote
135
136`code`
137"#).build();
138
139    println!("Markdown: {:?}\n", matches!(md, VNode::Box(_)));
140
141    // Test Sparkline
142    let sparkline = Sparkline::new()
143        .data([1.0, 4.0, 2.0, 8.0, 5.0, 7.0, 3.0, 6.0])
144        .build();
145
146    println!("Sparkline: {:?}\n", matches!(sparkline, VNode::Box(_)));
147
148    // Test BarChart
149    let bar_chart = BarChart::new()
150        .items([
151            BarItem::new("A", 30.0),
152            BarItem::new("B", 50.0),
153            BarItem::new("C", 20.0),
154        ])
155        .build();
156
157    println!("BarChart: {:?}\n", matches!(bar_chart, VNode::Box(_)));
158
159    // Test Gauge (returns Text node, not Box)
160    let gauge = Gauge::new()
161        .value(75.0)
162        .max(100.0)
163        .label("Progress")
164        .build();
165
166    println!("Gauge: {:?}\n", matches!(gauge, VNode::Text(_)));
167
168    println!("✅ All molecules compiled and instantiated successfully!");
169}

Trait Implementations§

Source§

impl Clone for BarChart

Source§

fn clone(&self) -> BarChart

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 BarChart

Source§

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

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

impl Default for BarChart

Source§

fn default() -> Self

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

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