class

Function class 

Source
pub fn class(str: &str) -> Option<StyleAttr>
Expand description

Creates a new StyleAttr with the specified class. This function is a convenience method to create a StyleAttr instance with the class field set.

§Arguments

  • str - A string slice representing the CSS class to be assigned.

§Returns

An Option<StyleAttr> containing the new StyleAttr with the class set, or None if the class is empty.

Examples found in repository?
examples/sine_curve.rs (line 22)
5pub fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let pi = std::f64::consts::PI;
7    let pi2 = 2.0 * pi;
8
9    const N: i32 = 100;
10    let sin: Vec<(f64, f64)> = (0..N)
11        .map(|i| {
12            let x = i as f64 * pi2 / (N as f64 - 1.0);
13            (x, x.sin())
14        })
15        .collect();
16
17    let chart = XYChart::new((600, 300), (..pi2, -1.1..1.1))
18        .x_labels(1.0, 10, None)
19        .y_labels(0.5, 10, None)
20        .x_axis_description("x", None)
21        .y_axis_description("sin(x)", None)
22        .plot_grid(0.2, 0.1, class("fine-grid"))
23        .plot_grid(1.0, 0.5, class("grid"))
24        .plot_poly_line(sin, class("curve"))
25        .plot_poly_line(vec![(0.0, 0.0), (pi2, 0.0)], class("base-line"));
26
27    SvgDocument::new()
28        .append_scss(STYLE)
29        .add_plot(Box::new(chart))
30        .save("docs/img/sine_curve.svg")
31}
More examples
Hide additional examples
examples/xy_gamut_plots.rs (line 26)
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21    let observer = Observer::Cie1931; // Use the CIE 1931 observer
22                                      // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24    // Create an XYChromaticity chart with the specified observer and ranges
25    let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26        .ticks(0.01, 0.01, 5, class("fine-grid"))
27        .ticks(0.1, 0.1, 10, class("grid"))
28        .x_labels(0.1, 10, None)
29        .x_axis_description(&format!("{} x", observer.name()), None)
30        .y_labels(0.1, 10, class("y-labels"))
31        .y_axis_description(&format!("{} y", observer.name()), None)
32        .plot_spectral_locus(class("spectral-locus"))
33        .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34        .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35        .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36        .plot_rgb_gamut(space, None)
37        .plot_planckian_locus(class("planckian"))
38        .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39        .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40        .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41        .plot_grid(0.01, 0.01, class("fine-grid"))
42        .plot_grid(0.1, 0.1, class("grid"));
43
44    // create the plot
45    SvgDocument::new()
46        .append_scss(STYLE)
47        .add_plot(Box::new(xy_chromaticity))
48        .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49    Ok(())
50}