pub struct Header { /* private fields */ }Expand description
A structure representing header formatting for tables.
The Header struct allows customization of table headers including custom values,
height, alignment, font, and fill color.
§Example
use plotlars::{Table, Header, Plot, Text, Rgb};
use polars::prelude::*;
let dataset = df![
"name" => &["Alice", "Bob", "Charlie"],
"age" => &[25, 30, 35],
"city" => &["New York", "London", "Tokyo"]
]
.unwrap();
let header = Header::new()
.values(vec!["Full Name", "Years", "Location"])
.height(40.0)
.align("center")
.font("Arial")
.fill(Rgb(200, 200, 200));
Table::builder()
.data(&dataset)
.columns(vec!["name", "age", "city"])
.header(&header)
.plot_title(Text::from("Employee Information"))
.build()
.plot();
Implementations§
Source§impl Header
impl Header
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Header instance with default values.
Examples found in repository?
examples/table.rs (line 14)
5fn main() {
6 let dataset = df![
7 "name" => &["Alice Johnson", "Bob Smith", "Charlie Davis", "Diana Martinez", "Eva Wilson"],
8 "department" => &["Engineering", "Marketing", "Engineering", "Sales", "Marketing"],
9 "salary" => &[95000, 78000, 102000, 85000, 82000],
10 "years" => &[5, 3, 7, 4, 2]
11 ]
12 .unwrap();
13
14 let header = Header::new()
15 .values(vec![
16 "Employee Name",
17 "Department",
18 "Annual Salary ($)",
19 "Years of Service",
20 ])
21 .align("center")
22 .font("Arial Bold")
23 .fill(Rgb(70, 130, 180));
24
25 let cell = Cell::new()
26 .align("center")
27 .height(25.0)
28 .font("Arial")
29 .fill(Rgb(240, 248, 255));
30
31 Table::builder()
32 .data(&dataset)
33 .columns(vec!["name", "department", "salary", "years"])
34 .header(&header)
35 .cell(&cell)
36 .plot_title(
37 Text::from("Employee Data")
38 .font("Arial")
39 .size(20)
40 .color(Rgb(25, 25, 112)),
41 )
42 .build()
43 .plot();
44}Sourcepub fn values(self, values: Vec<&str>) -> Self
pub fn values(self, values: Vec<&str>) -> Self
Sets custom header values.
§Argument
values- A vector of string slices representing custom header names.
Examples found in repository?
examples/table.rs (lines 15-20)
5fn main() {
6 let dataset = df![
7 "name" => &["Alice Johnson", "Bob Smith", "Charlie Davis", "Diana Martinez", "Eva Wilson"],
8 "department" => &["Engineering", "Marketing", "Engineering", "Sales", "Marketing"],
9 "salary" => &[95000, 78000, 102000, 85000, 82000],
10 "years" => &[5, 3, 7, 4, 2]
11 ]
12 .unwrap();
13
14 let header = Header::new()
15 .values(vec![
16 "Employee Name",
17 "Department",
18 "Annual Salary ($)",
19 "Years of Service",
20 ])
21 .align("center")
22 .font("Arial Bold")
23 .fill(Rgb(70, 130, 180));
24
25 let cell = Cell::new()
26 .align("center")
27 .height(25.0)
28 .font("Arial")
29 .fill(Rgb(240, 248, 255));
30
31 Table::builder()
32 .data(&dataset)
33 .columns(vec!["name", "department", "salary", "years"])
34 .header(&header)
35 .cell(&cell)
36 .plot_title(
37 Text::from("Employee Data")
38 .font("Arial")
39 .size(20)
40 .color(Rgb(25, 25, 112)),
41 )
42 .build()
43 .plot();
44}Sourcepub fn align(self, align: impl Into<String>) -> Self
pub fn align(self, align: impl Into<String>) -> Self
Sets the alignment of the header text.
§Argument
align- A string specifying the alignment (left, center, right).
Examples found in repository?
examples/table.rs (line 21)
5fn main() {
6 let dataset = df![
7 "name" => &["Alice Johnson", "Bob Smith", "Charlie Davis", "Diana Martinez", "Eva Wilson"],
8 "department" => &["Engineering", "Marketing", "Engineering", "Sales", "Marketing"],
9 "salary" => &[95000, 78000, 102000, 85000, 82000],
10 "years" => &[5, 3, 7, 4, 2]
11 ]
12 .unwrap();
13
14 let header = Header::new()
15 .values(vec![
16 "Employee Name",
17 "Department",
18 "Annual Salary ($)",
19 "Years of Service",
20 ])
21 .align("center")
22 .font("Arial Bold")
23 .fill(Rgb(70, 130, 180));
24
25 let cell = Cell::new()
26 .align("center")
27 .height(25.0)
28 .font("Arial")
29 .fill(Rgb(240, 248, 255));
30
31 Table::builder()
32 .data(&dataset)
33 .columns(vec!["name", "department", "salary", "years"])
34 .header(&header)
35 .cell(&cell)
36 .plot_title(
37 Text::from("Employee Data")
38 .font("Arial")
39 .size(20)
40 .color(Rgb(25, 25, 112)),
41 )
42 .build()
43 .plot();
44}Sourcepub fn font(self, font: &str) -> Self
pub fn font(self, font: &str) -> Self
Sets the font family of the header text.
§Argument
font- A string slice specifying the font family name.
Examples found in repository?
examples/table.rs (line 22)
5fn main() {
6 let dataset = df![
7 "name" => &["Alice Johnson", "Bob Smith", "Charlie Davis", "Diana Martinez", "Eva Wilson"],
8 "department" => &["Engineering", "Marketing", "Engineering", "Sales", "Marketing"],
9 "salary" => &[95000, 78000, 102000, 85000, 82000],
10 "years" => &[5, 3, 7, 4, 2]
11 ]
12 .unwrap();
13
14 let header = Header::new()
15 .values(vec![
16 "Employee Name",
17 "Department",
18 "Annual Salary ($)",
19 "Years of Service",
20 ])
21 .align("center")
22 .font("Arial Bold")
23 .fill(Rgb(70, 130, 180));
24
25 let cell = Cell::new()
26 .align("center")
27 .height(25.0)
28 .font("Arial")
29 .fill(Rgb(240, 248, 255));
30
31 Table::builder()
32 .data(&dataset)
33 .columns(vec!["name", "department", "salary", "years"])
34 .header(&header)
35 .cell(&cell)
36 .plot_title(
37 Text::from("Employee Data")
38 .font("Arial")
39 .size(20)
40 .color(Rgb(25, 25, 112)),
41 )
42 .build()
43 .plot();
44}Sourcepub fn fill(self, fill: Rgb) -> Self
pub fn fill(self, fill: Rgb) -> Self
Examples found in repository?
examples/table.rs (line 23)
5fn main() {
6 let dataset = df![
7 "name" => &["Alice Johnson", "Bob Smith", "Charlie Davis", "Diana Martinez", "Eva Wilson"],
8 "department" => &["Engineering", "Marketing", "Engineering", "Sales", "Marketing"],
9 "salary" => &[95000, 78000, 102000, 85000, 82000],
10 "years" => &[5, 3, 7, 4, 2]
11 ]
12 .unwrap();
13
14 let header = Header::new()
15 .values(vec![
16 "Employee Name",
17 "Department",
18 "Annual Salary ($)",
19 "Years of Service",
20 ])
21 .align("center")
22 .font("Arial Bold")
23 .fill(Rgb(70, 130, 180));
24
25 let cell = Cell::new()
26 .align("center")
27 .height(25.0)
28 .font("Arial")
29 .fill(Rgb(240, 248, 255));
30
31 Table::builder()
32 .data(&dataset)
33 .columns(vec!["name", "department", "salary", "years"])
34 .header(&header)
35 .cell(&cell)
36 .plot_title(
37 Text::from("Employee Data")
38 .font("Arial")
39 .size(20)
40 .color(Rgb(25, 25, 112)),
41 )
42 .build()
43 .plot();
44}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnwindSafe for Header
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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> ⓘ
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 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> ⓘ
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 moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().