### Configure a P-P Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/qq.rs.html Example showing how to initialize a PPPlot and configure its appearance using builder methods. ```rust # use velociplot::prelude::*; # use velociplot::plots::qq::{PPPlot, Distribution}; let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let pp = PPPlot::new(&data, Distribution::Normal) .show_reference_line(true) .color(Color::from_hex("#3498db").unwrap()) .label("P-P Plot"); ``` -------------------------------- ### Initialize Legend Source: https://docs.rs/velociplot/latest/src/velociplot/legend/mod.rs.html Example of creating a new legend instance and setting its position. ```rust use velociplot::legend::{Legend, LegendPosition}; let legend = Legend::new() .position(LegendPosition::UpperRight); ``` -------------------------------- ### Initialize a Basic Stacked Bar Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/stacked_bar.rs.html Shows the minimal setup required to create a new StackedBarPlot instance. ```rust # use velociplot::prelude::*; let categories = vec!["Jan", "Feb", "Mar"]; let sales = vec![100.0, 120.0, 110.0]; let costs = vec![60.0, 70.0, 65.0]; let stacked = StackedBarPlot::new(categories, vec![sales, costs]); ``` -------------------------------- ### Unwrap or Else Example Source: https://docs.rs/velociplot/latest/velociplot/error/type.Result.html Demonstrates using unwrap_or_else to provide a fallback value. ```rust assert_eq!(Ok(2).unwrap_or_else(count), 2); assert_eq!(Err("foo").unwrap_or_else(count), 3); ``` -------------------------------- ### Parse Hex Strings Source: https://docs.rs/velociplot/latest/velociplot/color/struct.Color.html Example of creating a Color instance from a hex string. ```rust let red = Color::from_hex("#FF0000").unwrap(); let blue = Color::from_hex("#0000FF").unwrap(); let with_alpha = Color::from_hex("#FF0000AA").unwrap(); ``` -------------------------------- ### FromIterator Implementation Examples Source: https://docs.rs/velociplot/latest/velociplot/error/type.Result.html Demonstrates how FromIterator handles Result types, stopping at the first Err encountered. ```rust let v = vec![1, 2]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_add(1).ok_or("Overflow!") ).collect(); assert_eq!(res, Ok(vec![2, 3])); ``` ```rust let v = vec![1, 2, 0]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_sub(1).ok_or("Underflow!") ).collect(); assert_eq!(res, Err("Underflow!")); ``` ```rust let v = vec![3, 2, 1, 10]; let mut shared = 0; let res: Result, &'static str> = v.iter().map(|x: &u32| { shared += x; x.checked_sub(2).ok_or("Underflow!") }).collect(); assert_eq!(res, Err("Underflow!")); assert_eq!(shared, 6); ``` -------------------------------- ### Quick Start Plotting Source: https://docs.rs/velociplot/latest/src/velociplot/lib.rs.html Demonstrates the basic usage of the velociplot fluent API to create a line plot and save it to a file. ```APIDOC ## Basic Plotting ### Description Use the `plot()` function to initialize a new figure, add data series, configure axes labels, and save the output. ### Example ```rust use velociplot::prelude::*; // Simple line plot plot() .line(x, y) .xlabel("Time (s)") .ylabel("Temperature (K)") .save("figure.png")?; ``` ``` -------------------------------- ### IntoIterator Implementation Examples Source: https://docs.rs/velociplot/latest/velociplot/error/type.Result.html Demonstrates converting a Result into an iterator that yields the contained value if Ok, or nothing if Err. ```rust let x: Result = Ok(5); let v: Vec = x.into_iter().collect(); assert_eq!(v, [5]); let x: Result = Err("nothing!"); let v: Vec = x.into_iter().collect(); assert_eq!(v, []); ``` -------------------------------- ### Interpolate Between Colors Source: https://docs.rs/velociplot/latest/velociplot/color/struct.Color.html Example of performing linear interpolation between two colors. ```rust let red = Color::RED; let blue = Color::BLUE; let purple = red.lerp(&blue, 0.5); // 50% between red and blue ``` -------------------------------- ### Create and Configure a Q-Q Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/qq.rs.html Demonstrates initializing a QQPlot with data and a distribution, then chaining configuration methods. ```rust # use velociplot::prelude::*; # use velociplot::plots::qq::{QQPlot, Distribution}; let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let qq = QQPlot::new(&data, Distribution::Normal) .show_reference_line(true) .color(Color::from_hex("#e74c3c").unwrap()) .label("Q-Q Plot"); ``` -------------------------------- ### Import the prelude Source: https://docs.rs/velociplot/latest/src/velociplot/lib.rs.html Shows how to import the core traits and types for convenient access to the library's functionality. ```rust use velociplot::prelude::*; ``` -------------------------------- ### Create and Configure a Histogram Source: https://docs.rs/velociplot/latest/src/velociplot/plots/histogram.rs.html Demonstrates initializing a histogram with data and chaining configuration methods for bins, color, and labels. ```rust # use velociplot::prelude::*; # use velociplot::plots::histogram::{Histogram, BinStrategy}; let data = vec![1.0, 2.0, 2.5, 3.0, 3.2, 3.5, 4.0, 5.0, 5.5, 6.0]; let hist = Histogram::new(&data) .bins(10) .color(Color::from_hex("#2ecc71").unwrap()) .label("Distribution"); ``` -------------------------------- ### Initialize and Configure a BarLegend Source: https://docs.rs/velociplot/latest/src/velociplot/legend/bar_legend.rs.html Create a new BarLegend instance and optionally set a label for the color scale. ```rust # use velociplot::prelude::*; # use velociplot::legend::bar_legend::BarLegend; let bar_legend = BarLegend::new(0.0, 100.0, Colormap::viridis()) .label("Temperature (°C)"); ``` -------------------------------- ### Initialize a New Timeline Source: https://docs.rs/velociplot/latest/src/velociplot/plots/timeline.rs.html Create an empty timeline instance using the default configuration. ```rust # use velociplot::prelude::*; let timeline = Timeline::new(); ``` -------------------------------- ### Get Histogram Bounds Source: https://docs.rs/velociplot/latest/src/velociplot/plots/histogram.rs.html Calculates the bounding box for the histogram based on bin edges and maximum count. ```rust #[must_use] pub fn bounds(&self) -> Option { if self.data.is_empty() { return None; } let edges = self.calculate_bin_edges(); let counts = self.calculate_counts(); let x_min = edges.first().copied().unwrap_or(0.0); let x_max = edges.last().copied().unwrap_or(1.0); let y_max = counts.iter().max().copied().unwrap_or(1) as f64; Some(Bounds::new(x_min, x_max, 0.0, y_max)) } ``` -------------------------------- ### Create and Configure a Heatmap Source: https://docs.rs/velociplot/latest/src/velociplot/plots/heatmap.rs.html Initialize a heatmap with 2D data and apply a specific colormap. ```rust # use velociplot::prelude::*; let data = vec![ vec![1.0, 2.0, 3.0], vec![4.0, 5.0, 6.0], vec![7.0, 8.0, 9.0], ]; let heatmap = Heatmap::new(data).unwrap() .colormap(Colormap::viridis()); ``` -------------------------------- ### MathNotation::new Source: https://docs.rs/velociplot/latest/velociplot/text/math/struct.MathNotation.html Creates a new, empty instance of MathNotation. ```APIDOC ## pub fn new() -> Self ### Description Creates an empty instance of MathNotation. ### Signature `pub fn new() -> Self` ``` -------------------------------- ### Unwrap Unchecked Examples Source: https://docs.rs/velociplot/latest/velociplot/error/type.Result.html Demonstrates the use of unwrap_unchecked, which is unsafe and causes undefined behavior if called on an Err variant. ```rust let x: Result = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2); ``` ```rust let x: Result = Err("emergency failure"); unsafe { x.unwrap_unchecked() }; // Undefined behavior! ``` -------------------------------- ### Create a new Timeline Source: https://docs.rs/velociplot/latest/src/velociplot/plots/timeline.rs.html Initializes an empty timeline instance. ```rust #[test] fn test_timeline_creation() { let timeline = Timeline::new(); assert_eq!(timeline.events.len(), 0); } ``` -------------------------------- ### Unwrap Err Unchecked Examples Source: https://docs.rs/velociplot/latest/velociplot/error/type.Result.html Demonstrates the use of unwrap_err_unchecked, which is unsafe and causes undefined behavior if called on an Ok variant. ```rust let x: Result = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior! ``` ```rust let x: Result = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure"); ``` -------------------------------- ### Create and Populate a Timeline Source: https://docs.rs/velociplot/latest/src/velociplot/plots/timeline.rs.html Initialize a new timeline and add multiple events with labels and descriptions. ```rust # use velociplot::prelude::*; let mut timeline = Timeline::new(); timeline.add_event(2020.0, "Launch", Some("Product launched".to_string())); timeline.add_event(2021.0, "Series A", Some("Funding round".to_string())); timeline.add_event(2022.0, "Expansion", Some("International expansion".to_string())); ``` -------------------------------- ### Create and Configure a Bubble Chart Source: https://docs.rs/velociplot/latest/src/velociplot/plots/bubble.rs.html Initialize a new bubble chart with data vectors and apply styling options like color and labels. ```rust # use velociplot::prelude::*; let x = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let y = vec![2.0, 4.0, 3.0, 5.0, 4.0]; let sizes = vec![10.0, 20.0, 15.0, 25.0, 18.0]; let bubble = BubbleChart::new(x, y, sizes).unwrap() .color(Color::from_hex("#3498db").unwrap()) .label("Sales Data"); ``` -------------------------------- ### Run Alignment Test Source: https://docs.rs/velociplot/latest/src/velociplot/legend/mod.rs.html Command to execute the alignment test example for visual comparison of different vertical alignment values. ```bash cargo run --example legend_alignment_test ``` -------------------------------- ### Create a New BarLegend Instance Source: https://docs.rs/velociplot/latest/src/velociplot/legend/bar_legend.rs.html Initialize a basic BarLegend with minimum and maximum values and a specified colormap. ```rust # use velociplot::prelude::*; # use velociplot::legend::bar_legend::BarLegend; let bar = BarLegend::new(0.0, 100.0, Colormap::viridis()); ``` -------------------------------- ### Configure a Violin Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/violin.rs.html Demonstrates how to initialize a ViolinPlot with data and customize its appearance using builder methods. ```rust # use velociplot::prelude::*; # use velociplot::plots::violin::{ViolinPlot, Kernel}; let data = vec![1.0, 2.0, 2.5, 3.0, 3.2, 3.5, 4.0, 5.0]; let violin = ViolinPlot::new(&data, 0.5) // position at x=0.5 .show_box(true) .color(Color::from_hex("#9b59b6").unwrap()) .label("Distribution"); ``` -------------------------------- ### Plotting Unit Tests Source: https://docs.rs/velociplot/latest/src/velociplot/plots/qq.rs.html Verification tests for normal distribution functions, QQ/PP plot initialization, and bounds calculation. ```rust #[cfg(test)] mod tests { use super::*; #[test] fn test_normal_cdf() { // Test known values assert!((normal_cdf(0.0) - 0.5).abs() < 0.001); assert!((normal_cdf(1.0) - 0.8413).abs() < 0.01); assert!((normal_cdf(-1.0) - 0.1587).abs() < 0.01); } #[test] fn test_normal_quantile() { assert!((normal_quantile(0.5) - 0.0).abs() < 0.001); assert!((normal_quantile(0.8413) - 1.0).abs() < 0.01); assert!((normal_quantile(0.1587) - (-1.0)).abs() < 0.01); } #[test] fn test_qq_plot_creation() { let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let qq = QQPlot::new(&data, Distribution::Normal); assert_eq!(qq.data.len(), 5); assert!(qq.show_reference); } #[test] fn test_pp_plot_creation() { let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let pp = PPPlot::new(&data, Distribution::Normal); assert_eq!(pp.data.len(), 5); assert!(pp.show_reference); } #[test] fn test_qq_bounds() { let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let qq = QQPlot::new(&data, Distribution::Normal); let bounds = qq.bounds(); assert!(bounds.is_some()); } #[test] fn test_pp_bounds() { let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let pp = PPPlot::new(&data, Distribution::Normal); let bounds = pp.bounds().unwrap(); assert_eq!(bounds.x_min, 0.0); assert_eq!(bounds.x_max, 1.0); } } ``` -------------------------------- ### Treemap::new Source: https://docs.rs/velociplot/latest/velociplot/plots/treemap/index.html Initializes a new instance of a Treemap visualization. ```APIDOC ## Treemap::new ### Description Creates a new, empty Treemap instance for hierarchical data visualization. ### Signature `pub fn new() -> Treemap` ``` -------------------------------- ### Timeline::new Source: https://docs.rs/velociplot/latest/velociplot/plots/timeline/struct.Timeline.html Creates a new, empty timeline instance. ```APIDOC ## pub fn new() -> Self ### Description Creates a new empty timeline. ### Example ```rust let timeline = Timeline::new(); ``` ``` -------------------------------- ### Treemap::new Source: https://docs.rs/velociplot/latest/src/velociplot/plots/treemap.rs.html Creates a new, empty Treemap instance with default configuration settings. ```APIDOC ## Treemap::new ### Description Initializes a new Treemap object with default values for labels, border settings, and padding. ### Signature `pub fn new() -> Self` ``` -------------------------------- ### Create and Verify Bounds Source: https://docs.rs/velociplot/latest/src/velociplot/core/bounds.rs.html Initialize a new Bounds instance and verify its dimensions. ```rust # use velociplot::prelude::*; let bounds = Bounds::new(0.0, 10.0, 0.0, 5.0); assert_eq!(bounds.width(), 10.0); assert_eq!(bounds.height(), 5.0); ``` -------------------------------- ### Configure a Scatter Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/scatter.rs.html Demonstrates how to initialize a ScatterPlot with a data series and apply various styling options like marker shape, size, color, and labels. ```rust # use velociplot::prelude::*; # use velociplot::plots::scatter::{ScatterPlot, MarkerShape, MarkerStyle}; let data = Series::from_function(0.0, 10.0, 20, |x| x * x); let scatter = ScatterPlot::new(data) .marker_shape(MarkerShape::Circle) .marker_size(6.0) .color(Color::from_hex("#e74c3c").unwrap()) .label("Data points"); ``` -------------------------------- ### Test LinePlot creation and configuration Source: https://docs.rs/velociplot/latest/src/velociplot/plots/line.rs.html Verify that a LinePlot can be instantiated and configured with custom properties. ```rust #[test] fn test_line_plot_creation() { let data = Series::from_tuples(&[(0.0, 0.0), (1.0, 1.0), (2.0, 4.0)]); let plot = LinePlot::new(data) .color(Color::RED) .line_width(3.0) .label("Test"); assert_eq!(plot.line_width, 3.0); assert_eq!(plot.label, Some("Test".to_string())); } ``` -------------------------------- ### Calculate Product of Result Items Source: https://docs.rs/velociplot/latest/velociplot/error/type.Result.html Demonstrates using the product method to multiply numbers parsed from strings, returning an Err if any parsing fails. ```rust let nums = vec!["5", "10", "1", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert_eq!(total, Ok(100)); let nums = vec!["5", "10", "one", "2"]; let total: Result = nums.iter().map(|w| w.parse::()).product(); assert!(total.is_err()); ``` -------------------------------- ### Create a new Point2D instance Source: https://docs.rs/velociplot/latest/src/velociplot/core/point.rs.html Initializes a new 2D point with specified x and y coordinates. ```rust # use velociplot::prelude::*; let point = Point2D::new(1.0, 2.0); assert_eq!(point.x, 1.0); assert_eq!(point.y, 2.0); ``` -------------------------------- ### Basic Plotting Workflow Source: https://docs.rs/velociplot/latest/velociplot/index.html Demonstrates the standard workflow for creating a simple line plot using the velociplot prelude. ```APIDOC ## Rust Plotting Workflow ### Description Create a simple line plot by initializing a plot, adding data, labeling axes, and saving to a file. ### Usage ```rust use velociplot::prelude::*; // Simple line plot plot() .line(x, y) .xlabel("Time (s)") .ylabel("Temperature (K)") .save("figure.png")?; ``` ``` -------------------------------- ### Create a New Treemap Instance Source: https://docs.rs/velociplot/latest/src/velociplot/plots/treemap.rs.html Initialize an empty Treemap with default configuration settings. ```rust # use velociplot::prelude::*; let treemap = Treemap::new(); ``` -------------------------------- ### BarLegend Configuration Methods Source: https://docs.rs/velociplot/latest/velociplot/legend/bar_legend/struct.BarLegend.html Methods to configure the appearance and behavior of the BarLegend. ```APIDOC ## Configuration Methods - **label(label: impl Into)** - Set the label for the color bar - **position(position: BarLegendPosition)** - Set the position of the color bar - **orientation(orientation: BarOrientation)** - Set the orientation of the color bar - **dimensions(width: f32, height: f32)** - Set the dimensions (width and height for vertical, swapped for horizontal) - **num_ticks(num: usize)** - Set the number of tick marks - **show_ticks(show: bool)** - Set whether to show tick marks - **show_values(show: bool)** - Set whether to show values - **show_border(show: bool)** - Set whether to show border ``` -------------------------------- ### Create New Bounds Source: https://docs.rs/velociplot/latest/velociplot/core/struct.Bounds.html Initialize a new Bounds instance. ```rust let bounds = Bounds::new(0.0, 10.0, 0.0, 5.0); assert_eq!(bounds.width(), 10.0); assert_eq!(bounds.height(), 5.0); ``` -------------------------------- ### Legend::new Source: https://docs.rs/velociplot/latest/src/velociplot/legend/mod.rs.html Creates a new empty legend instance with default configuration. ```APIDOC ## Legend::new ### Description Creates a new empty legend instance with default settings, including a default position of Below(HorizontalAlignment::Center). ### Signature `pub fn new() -> Self` ### Example ```rust use velociplot::legend::{Legend, LegendPosition}; let legend = Legend::new() .position(LegendPosition::UpperRight); ``` ``` -------------------------------- ### Initialize and validate BarPlot bounds Source: https://docs.rs/velociplot/latest/src/velociplot/plots/bar.rs.html Demonstrates creating a BarPlot and verifying that the y-axis bounds correctly include the zero baseline. ```rust let bar = BarPlot::new(data); let bounds = bar.bounds().unwrap(); assert_eq!(bounds.y_min, 0.0); // Should include zero baseline assert_eq!(bounds.y_max, 10.0); } ``` -------------------------------- ### Create a simple area plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/area.rs.html Demonstrates how to initialize an AreaPlot and configure its visual properties like color and opacity. ```rust # use velociplot::prelude::*; // Simple area plot let x = vec![0.0, 1.0, 2.0, 3.0, 4.0]; let y = vec![1.0, 3.0, 2.0, 4.0, 3.0]; let area = AreaPlot::new(x, y).unwrap() .color(Color::from_hex("#3498db").unwrap()) .opacity(0.6); ``` -------------------------------- ### Create a simple line plot with velociplot Source: https://docs.rs/velociplot/latest/index.html Use the prelude to access plotting functions and save the resulting figure to a file. ```rust use velociplot::prelude::*; // Simple line plot plot() .line(x, y) .xlabel("Time (s)") .ylabel("Temperature (K)") .save("figure.png")?; ``` -------------------------------- ### Create and Configure a Stacked Bar Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/stacked_bar.rs.html Demonstrates initializing a plot with multiple data series and customizing labels and colors. ```rust # use velociplot::prelude::*; let categories = vec!["Q1", "Q2", "Q3", "Q4"]; let series1 = vec![10.0, 15.0, 12.0, 18.0]; // Product A let series2 = vec![8.0, 12.0, 10.0, 14.0]; // Product B let series3 = vec![5.0, 7.0, 6.0, 9.0]; // Product C let stacked = StackedBarPlot::new(categories, vec![series1, series2, series3]).unwrap() .labels(vec!["Product A", "Product B", "Product C"]) .colors(vec![ Color::from_hex("#3498db").unwrap(), Color::from_hex("#e74c3c").unwrap(), Color::from_hex("#2ecc71").unwrap(), ]); ``` -------------------------------- ### Colormap::new Source: https://docs.rs/velociplot/latest/velociplot/color/struct.Colormap.html Creates a new colormap instance from a name and a list of colors. ```APIDOC ## pub fn new(name: impl Into, colors: Vec) -> Self ### Description Creates a new colormap from a list of colors. ### Parameters - **name** (impl Into) - The name of the colormap. - **colors** (Vec) - A vector of colors to define the map. ``` -------------------------------- ### Initialize and Populate a Treemap Source: https://docs.rs/velociplot/latest/src/velociplot/plots/treemap.rs.html Create a new Treemap instance and add multiple items with labels, values, and colors. ```rust # use velociplot::prelude::*; let mut treemap = Treemap::new(); treemap.add_item("Technology", 45.0, Color::from_hex("#3498db").unwrap()); treemap.add_item("Healthcare", 32.0, Color::from_hex("#2ecc71").unwrap()); treemap.add_item("Finance", 28.0, Color::from_hex("#e74c3c").unwrap()); ``` -------------------------------- ### Initialize a Basic BoxPlot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/boxplot.rs.html Creates a new box plot instance using default configuration settings. ```rust # use velociplot::prelude::*; let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let boxplot = BoxPlot::new(data); ``` -------------------------------- ### Initialize a New Q-Q Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/qq.rs.html Basic instantiation of a QQPlot using a data slice and a target distribution. ```rust # use velociplot::plots::qq::{QQPlot, Distribution}; let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let qq = QQPlot::new(&data, Distribution::Normal); ``` -------------------------------- ### Configure Timeline Properties Source: https://docs.rs/velociplot/latest/src/velociplot/plots/timeline.rs.html Methods for setting marker size, label visibility, label offsets, and alternating side layout for timeline events. ```rust pub fn marker_size(mut self, size: f32) -> Self { self.marker_default_size = size.max(1.0); self } /// Set whether to show event descriptions #[must_use] pub fn show_descriptions(mut self, show: bool) -> Self { self.show_descriptions = show; self } /// Set label offset from timeline #[must_use] pub fn label_offset(mut self, offset: f64) -> Self { self.label_offset = offset.max(0.0); self } /// Set whether to alternate labels on both sides of the timeline #[must_use] pub fn alternating_sides(mut self, alternating: bool) -> Self { self.alternating_sides = alternating; self } ``` -------------------------------- ### Create and Configure a BoxPlot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/boxplot.rs.html Initializes a new box plot with data and applies styling options such as color and labels. ```rust # use velociplot::prelude::*; let data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]; let boxplot = BoxPlot::new(data) .color(Color::from_hex("#3498db").unwrap()) .label("Sample Data"); ``` -------------------------------- ### Colormap Implementation Source: https://docs.rs/velociplot/latest/src/velociplot/color/mod.rs.html Structure and methods for continuous data visualization using colormaps. ```rust /// Colormap for continuous data visualization #[derive(Debug, Clone)] pub struct Colormap { colors: Vec, name: String, } impl Colormap { /// Create a new colormap from a list of colors #[must_use] pub fn new(name: impl Into, colors: Vec) -> Self { Self { name: name.into(), colors, } } /// Get the name of this colormap #[must_use] pub fn name(&self) -> &str { &self.name } /// Get color at normalized position (0.0 to 1.0) #[must_use] pub fn get(&self, t: f32) -> Color { let t = t.clamp(0.0, 1.0); if self.colors.is_empty() { return Color::BLACK; } if self.colors.len() == 1 { return self.colors[0]; } // Map t to color array index let scaled = t * (self.colors.len() - 1) as f32; let index = scaled.floor() as usize; let frac = scaled - index as f32; if index >= self.colors.len() - 1 { return self.colors[self.colors.len() - 1]; } // Linear interpolation between adjacent colors self.colors[index].lerp(&self.colors[index + 1], frac) } /// Viridis colormap (perceptually uniform, colorblind-friendly) #[must_use] pub fn viridis() -> Self { Self::new( "viridis", vec![ Color::from_hex("#440154").unwrap(), Color::from_hex("#482878").unwrap(), Color::from_hex("#3e4989").unwrap(), Color::from_hex("#31688e").unwrap(), Color::from_hex("#26828e").unwrap(), Color::from_hex("#1f9e89").unwrap(), Color::from_hex("#35b779").unwrap(), Color::from_hex("#6ece58").unwrap(), Color::from_hex("#b5de2b").unwrap(), Color::from_hex("#fde725").unwrap(), ], ) } /// Plasma colormap (perceptually uniform) #[must_use] pub fn plasma() -> Self { Self::new( "plasma", vec![ Color::from_hex("#0d0887").unwrap(), Color::from_hex("#46039f").unwrap(), Color::from_hex("#7201a8").unwrap(), Color::from_hex("#9c179e").unwrap(), Color::from_hex("#bd3786").unwrap(), Color::from_hex("#d8576b").unwrap(), Color::from_hex("#ed7953").unwrap(), Color::from_hex("#fb9f3a").unwrap(), Color::from_hex("#fdca26").unwrap(), Color::from_hex("#f0f921").unwrap(), ], ) } /// Inferno colormap (perceptually uniform) #[must_use] pub fn inferno() -> Self { Self::new( "inferno", vec![ Color::from_hex("#000004").unwrap(), Color::from_hex("#1b0c41").unwrap(), Color::from_hex("#4a0c6b").unwrap(), ``` -------------------------------- ### QQPlot Configuration Methods Source: https://docs.rs/velociplot/latest/velociplot/plots/qq/struct.QQPlot.html Methods for configuring the appearance and properties of the Q-Q plot. ```APIDOC ## Configuration Methods ### pub fn color(self, color: Color) -> Self Sets the point color for the plot. ### pub fn show_reference_line(self, show: bool) -> Self Sets whether to display the reference line (y=x). ### pub fn label(self, label: impl Into) -> Self Sets the label for the legend. ``` -------------------------------- ### Timeline Configuration Methods Source: https://docs.rs/velociplot/latest/velociplot/plots/timeline/struct.Timeline.html Methods for configuring the visual appearance of the timeline. ```APIDOC ## Configuration Methods - **orientation(self, orientation: TimelineOrientation) -> Self**: Set timeline orientation - **line_color(self, color: Color) -> Self**: Set the main timeline line color - **line_width(self, width: f32) -> Self**: Set the timeline line width - **marker_color(self, color: Color) -> Self**: Set the default marker color for events - **marker_size(self, size: f32) -> Self**: Set the default marker size - **show_descriptions(self, show: bool) -> Self**: Set whether to show event descriptions - **label_offset(self, offset: f64) -> Self**: Set label offset from timeline - **alternating_sides(self, alternating: bool) -> Self**: Set whether to alternate labels on both sides of the timeline ``` -------------------------------- ### Initialize a Heatmap Source: https://docs.rs/velociplot/latest/src/velociplot/plots/heatmap.rs.html Create a new Heatmap instance from a 2D vector of floating-point numbers. ```rust # use velociplot::prelude::*; let data = vec![ vec![1.0, 2.0, 3.0], vec![4.0, 5.0, 6.0], ]; let heatmap = Heatmap::new(data); ``` -------------------------------- ### BubbleChart Configuration Methods Source: https://docs.rs/velociplot/latest/src/velociplot/plots/bubble.rs.html Fluent builder methods to configure the appearance and behavior of the bubble chart. ```APIDOC ## Configuration Methods ### color(color: Color) -> Self Sets the color for all bubbles in the chart. ### marker_shape(shape: MarkerShape) -> Self Sets the geometric shape of the markers. ### marker_style(style: MarkerStyle) -> Self Sets the style of the markers (e.g., filled or outline). ### size_scale(scale: f32) -> Self Sets the global size scale factor for the bubbles. ### min_size(size: f32) -> Self Sets the minimum marker size in pixels. ### max_size(size: f32) -> Self Sets the maximum marker size in pixels. ### size_range(min: f32, max: f32) -> Self Sets both the minimum and maximum marker size constraints. ### opacity(opacity: f32) -> Self Sets the transparency of the bubbles (0.0 to 1.0). ### label(label: impl Into) -> Self Sets the label used for the legend entry. ``` -------------------------------- ### Palette::new Source: https://docs.rs/velociplot/latest/velociplot/color/struct.Palette.html Creates a new Palette instance from a vector of colors. ```APIDOC ### pub fn new(colors: Vec) -> Self Creates a new palette from a provided vector of colors. ``` -------------------------------- ### Heatmap::new Source: https://docs.rs/velociplot/latest/velociplot/plots/heatmap/index.html Initializes a new Heatmap instance from a 2D matrix of values. ```APIDOC ## Heatmap::new ### Description Creates a new Heatmap instance to visualize a 2D matrix of data. ### Usage ```rust let data = vec![ vec![1.0, 2.0, 3.0], vec![4.0, 5.0, 6.0], vec![7.0, 8.0, 9.0], ]; let heatmap = Heatmap::new(data).unwrap(); ``` ``` -------------------------------- ### Create Colors from Components Source: https://docs.rs/velociplot/latest/src/velociplot/color/mod.rs.html Use the rgba and rgb methods to instantiate a new Color object. ```rust # use velociplot::prelude::*; let red = Color::rgb(255, 0, 0); let semi_transparent_blue = Color::rgba(0, 0, 255, 128); ``` -------------------------------- ### Calculate Statistics and KDE Source: https://docs.rs/velociplot/latest/src/velociplot/plots/violin.rs.html Internal methods for computing box plot statistics and kernel density estimation for violin shapes. ```rust let q3 = percentile(&sorted, 75.0); let iqr = q3 - q1; // Whiskers extend to 1.5 * IQR or to data extremes let lower_fence = q1 - 1.5 * iqr; let upper_fence = q3 + 1.5 * iqr; let lower_whisker = sorted .iter() .find(|&&x| x >= lower_fence) .copied() .unwrap_or(min); let upper_whisker = sorted .iter() .rev() .find(|&&x| x <= upper_fence) .copied() .unwrap_or(max); Stats { min, max, q1, median, q3, lower_whisker, upper_whisker, } } /// Calculate kernel density estimate fn calculate_kde(&self) -> Vec<(f64, f64)> { if self.data.is_empty() { return Vec::new(); } let stats = self.calculate_stats(); let range = stats.max - stats.min; // Extend range slightly for better visualization let y_min = stats.min - 0.1 * range; let y_max = stats.max + 0.1 * range; // Calculate bandwidth using Scott's rule if not provided let bandwidth = self.bandwidth.unwrap_or_else(|| { let n = self.data.len() as f64; let std_dev = calculate_std_dev(&self.data); 1.06 * std_dev * n.powf(-0.2) }); let mut kde_points = Vec::with_capacity(self.n_points); for i in 0..self.n_points { let y = y_min + (i as f64 / (self.n_points - 1) as f64) * (y_max - y_min); // Calculate density at this point let density: f64 = self .data .iter() .map(|&x| { let u = (y - x) / bandwidth; self.kernel.evaluate(u) }) .sum::() / (self.data.len() as f64 * bandwidth); kde_points.push((y, density)); } // Normalize to maximum density for scaling if let Some(&(_, max_density)) = kde_points .iter() .max_by(|a, b| a.1.partial_cmp(&b.1).unwrap_or(std::cmp::Ordering::Equal)) { if max_density > 0.0 { for (_, density) in &mut kde_points { *density /= max_density; } } } kde_points } ``` -------------------------------- ### Initialize a Bubble Chart Source: https://docs.rs/velociplot/latest/src/velociplot/plots/bubble.rs.html Basic instantiation of a BubbleChart using three vectors of equal length. ```rust # use velociplot::prelude::*; let x = vec![1.0, 2.0, 3.0]; let y = vec![2.0, 4.0, 3.0]; let sizes = vec![10.0, 20.0, 15.0]; let bubble = BubbleChart::new(x, y, sizes); ``` -------------------------------- ### Create a new LinePlot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/line.rs.html Initialize a new line plot using a data series. ```rust # use velociplot::prelude::*; let data = Series::from_tuples(&[(0.0, 0.0), (1.0, 1.0), (2.0, 4.0)]); let plot = LinePlot::new(data); ``` -------------------------------- ### Initialize a New Violin Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/violin.rs.html Shows the basic instantiation of a ViolinPlot using a data slice and an X-axis position. ```rust # use velociplot::plots::violin::ViolinPlot; let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let violin = ViolinPlot::new(&data, 1.0); ``` -------------------------------- ### BarPlot::new Source: https://docs.rs/velociplot/latest/src/velociplot/plots/bar.rs.html Initializes a new BarPlot instance from a data series. ```APIDOC ## BarPlot::new(data: impl DataSeries + 'static) -> Self ### Description Creates a new bar plot instance using the provided data series. The plot defaults to vertical orientation with a bar width of 0.8 and a blue color. ### Parameters - **data** (impl DataSeries) - Required - The data series containing the points to be plotted. ``` -------------------------------- ### Treemap::new Source: https://docs.rs/velociplot/latest/velociplot/plots/treemap/struct.Treemap.html Creates a new, empty Treemap instance. ```APIDOC ## pub fn new() -> Self ### Description Creates a new empty treemap instance. ### Example ```rust let treemap = Treemap::new(); ``` ``` -------------------------------- ### Initialize a New Histogram Source: https://docs.rs/velociplot/latest/src/velociplot/plots/histogram.rs.html Shows the basic instantiation of a Histogram object from a slice of f64 data. ```rust # use velociplot::plots::histogram::Histogram; let data = vec![1.0, 2.0, 3.0, 2.5, 3.5, 4.0]; let hist = Histogram::new(&data); ``` -------------------------------- ### BubbleChart::new Source: https://docs.rs/velociplot/latest/src/velociplot/plots/bubble.rs.html Initializes a new BubbleChart instance with x, y, and size data vectors. All vectors must be of equal length and size values must be non-negative. ```APIDOC ## BubbleChart::new(x: Vec, y: Vec, sizes: Vec) -> Result ### Description Creates a new bubble chart instance. Validates that input vectors are non-empty, have matching lengths, and contain no negative size values. ### Parameters - **x** (Vec) - Required - X-axis coordinate values. - **y** (Vec) - Required - Y-axis coordinate values. - **sizes** (Vec) - Required - Size values for each point, which will be scaled to visual marker sizes. ### Returns - **Result** - Returns the initialized BubbleChart or an Error if validation fails. ``` -------------------------------- ### Create a legend-only canvas Source: https://docs.rs/velociplot/latest/src/velociplot/backend/skia.rs.html Demonstrates how to initialize a SkiaCanvas specifically for rendering legends with minimal margins. ```rust let bounds = Bounds::new(0.0, 0.0, 10.0, 10.0); let mut legend_canvas = SkiaCanvas::new_legend_canvas(800, 100, bounds)?; legend_canvas.fill_background(&Color::WHITE.to_rgba())?; let legend = Legend::new() .position(LegendPosition::Custom(400, 50)); legend.draw(&mut legend_canvas)?; legend_canvas.save_png("legend_only.png")?; ``` -------------------------------- ### Create a DateListPlot with a single series Source: https://docs.rs/velociplot/latest/src/velociplot/plots/datelistplot.rs.html Demonstrates initializing a plot with time and value vectors. ```rust # use velociplot::prelude::*; let times = vec![0.0, 1.0, 2.0, 3.0, 4.0]; let values = vec![10.0, 15.0, 12.0, 18.0, 14.0]; let plot = DateListPlot::new(times, values).unwrap() .label("Temperature"); ``` ```rust # use velociplot::prelude::*; let times = vec![0.0, 1.0, 2.0, 3.0]; let values = vec![5.0, 8.0, 6.0, 9.0]; let plot = DateListPlot::new(times, values).unwrap(); ``` -------------------------------- ### Palette Management Methods Source: https://docs.rs/velociplot/latest/src/velociplot/color/mod.rs.html Methods for creating and accessing color palettes, including default and colorblind-safe presets. ```rust /// Create a new palette from colors #[must_use] pub fn new(colors: Vec) -> Self { Self { colors } } /// Get color at index (wraps around) #[must_use] pub fn get(&self, index: usize) -> Color { self.colors[index % self.colors.len()] } /// Default matplotlib-like color cycle #[must_use] pub fn default() -> Self { Self::new(vec![ Color::from_hex("#1f77b4").unwrap(), // blue Color::from_hex("#ff7f0e").unwrap(), // orange Color::from_hex("#2ca02c").unwrap(), // green Color::from_hex("#d62728").unwrap(), // red Color::from_hex("#9467bd").unwrap(), // purple Color::from_hex("#8c564b").unwrap(), // brown Color::from_hex("#e377c2").unwrap(), // pink Color::from_hex("#7f7f7f").unwrap(), // gray ]) } /// Okabe-Ito colorblind-friendly palette #[must_use] pub fn colorblind_safe() -> Self { Self::new(vec![ Color::from_hex("#E69F00").unwrap(), // orange Color::from_hex("#56B4E9").unwrap(), // sky blue Color::from_hex("#009E73").unwrap(), // bluish green Color::from_hex("#F0E442").unwrap(), // yellow Color::from_hex("#0072B2").unwrap(), // blue Color::from_hex("#D55E00").unwrap(), // vermillion Color::from_hex("#CC79A7").unwrap(), // reddish purple ]) } } impl Default for Palette { fn default() -> Self { Self::default() } } ``` -------------------------------- ### DateListPlot Configuration Methods Source: https://docs.rs/velociplot/latest/src/velociplot/plots/datelistplot.rs.html Methods for configuring the first series of a DateListPlot, including labels, colors, styles, and line/point dimensions. ```APIDOC ## Method: label ### Description Sets the label for the first series in the plot. ### Signature `pub fn label(mut self, label: impl Into) -> Self` ## Method: color ### Description Sets the color for the first series in the plot. ### Signature `pub fn color(mut self, color: Color) -> Self` ## Method: style ### Description Sets the plotting style (e.g., Line, LinePoints) for the first series. ### Signature `pub fn style(mut self, style: DateListStyle) -> Self` ## Method: line_width ### Description Sets the line width for the first series. Values less than 0.0 are clamped to 0.0. ### Signature `pub fn line_width(mut self, width: f32) -> Self` ## Method: point_size ### Description Sets the point size for the first series. Values less than 0.0 are clamped to 0.0. ### Signature `pub fn point_size(mut self, size: f32) -> Self` ## Method: show_grid ### Description Configures whether to display the grid on the plot. ### Signature `pub fn show_grid(mut self, show: bool) -> Self` ``` -------------------------------- ### Initialize a New Bar Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/bar.rs.html Instantiate a basic bar plot using a data series. ```rust # use velociplot::prelude::*; # use velociplot::plots::bar::BarPlot; let data = Series::from_tuples(&[(1.0, 10.0), (2.0, 20.0), (3.0, 15.0)]); let bar_plot = BarPlot::new(data); ``` -------------------------------- ### Create a new SkiaCanvas Source: https://docs.rs/velociplot/latest/src/velociplot/backend/skia.rs.html Initialize a new canvas with specific dimensions and coordinate bounds. ```rust # #[cfg(feature = "raster")] # { use velociplot::backend::SkiaCanvas; use velociplot::core::Bounds; let bounds = Bounds::new(0.0, 10.0, 0.0, 5.0); let canvas = SkiaCanvas::new(800, 600, bounds).unwrap(); # } ``` -------------------------------- ### Initialize a new P-P Plot Source: https://docs.rs/velociplot/latest/src/velociplot/plots/qq.rs.html Basic instantiation of a PPPlot with data and a distribution type. ```rust # use velociplot::plots::qq::{PPPlot, Distribution}; let data = vec![1.0, 2.0, 3.0, 4.0, 5.0]; let pp = PPPlot::new(&data, Distribution::Normal); ``` -------------------------------- ### ViolinPlot Configuration Methods Source: https://docs.rs/velociplot/latest/src/velociplot/plots/violin.rs.html Methods to configure the appearance and behavior of the violin plot. ```APIDOC ## Configuration Methods ### width(width: f64) Sets the maximum width of the violin. ### color(color: Color) Sets the color of the violin plot. ### show_box(show: bool) Sets whether to show the box plot overlay. ### show_median(show: bool) Sets whether to show the median line. ### kernel(kernel: Kernel) Sets the kernel function (Gaussian, Epanechnikov, or Uniform) for density estimation. ### bandwidth(h: f64) Sets a custom bandwidth for density estimation. If not set, Scott's rule is used. ### label(label: impl Into) Sets the label for the legend. ``` -------------------------------- ### Histogram Configuration Methods Source: https://docs.rs/velociplot/latest/src/velociplot/plots/histogram.rs.html Methods for configuring the appearance and binning behavior of the histogram. ```APIDOC ## Configuration Methods ### .bins(count: usize) -> Self Sets the number of bins explicitly. ### .bin_edges(edges: Vec) -> Self Sets custom bin edges for the histogram. ### .bin_strategy(strategy: BinStrategy) -> Self Sets the binning strategy (Auto, SquareRoot, Rice, or Scott). ### .color(color: Color) -> Self Sets the primary color of the histogram bars. ### .show_outline(show: bool) -> Self Configures whether to display outlines around the histogram bars. ### .label(label: impl Into) -> Self Sets the label for the histogram, typically used in legends. ```