Skip to main content

Plottable

Trait Plottable 

Source
pub trait Plottable {
    // Required method
    fn plot(&self) -> PlotBuilder<Self>
       where Self: Sized + Graph;
}
Expand description

Trait for defining objects that can be visualized as plots.

The Plottable trait provides a standardized interface for types that can be represented graphically. It enables visualization of data structures through a fluent builder pattern, allowing for customizable plot creation.

Implementers of this trait can be visualized using the plotting system with configurable options for appearance, labels, colors, and other visual attributes.

Building a plot cannot fail; rendering and export are the fallible steps, and they return GraphError whatever the plotted type, so the trait carries no error type of its own.

Required Methods§

Source

fn plot(&self) -> PlotBuilder<Self>
where Self: Sized + Graph,

Creates a plot builder for configuring and generating visualizations.

Returns a PlotBuilder instance that provides a fluent interface for customizing plot appearance and behavior before rendering.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Plottable for Curve

Plottable implementation for single Curve

Source§

fn plot(&self) -> PlotBuilder<Self>
where Self: Sized,

Source§

impl Plottable for Surface

Plottable implementation for single Surface

Source§

fn plot(&self) -> PlotBuilder<Self>
where Self: Sized,

Source§

impl Plottable for Vec<Curve>

Implementation of the Plottable trait for Vec<Curve>.

This implementation enables a vector of Curve instances to be plotted using the plot method. The method creates a PlotBuilder instance, which allows for flexible and configurable visualization of the curves.

§Overview

By implementing the Plottable trait, a vector of Curve objects gains the ability to leverage plot-building functionality. The plot method clones the data (to ensure immutability of the original input) and pairs it with default plotting options (PlotOptions) for further configuration and rendering.

The PlotBuilder struct, which is returned by this implementation, acts as a pipeline for customizing and generating the final plot. Once the plot is fully configured in terms of styling and layout, it can be saved to a file, rendered in memory, or manipulated further depending on the builder’s available methods.

§Method Details

  • plot:
    • Creates a PlotBuilder instance containing the data from the Vec<Curve> and populates it with default plot options.
    • Returns a configurable tool for building curve visualizations.

§Considerations

  • This implementation assumes that it is appropriate to clone the data from the vector of Curve instances. If the cloning behavior is expensive or not necessary, further optimization may be required.
  • PlotOptions default values provide a reasonable starting point, but most real-world applications will override some of these values for more customization.

§Example Behavior

A vector of Curve objects can be passed to the plot method to generate a plot tailored to the desired styling and configuration. Methods available on PlotBuilder can then be chained to adjust plot dimensions, colors, titles, labels, and more.

§Returns

  • A PlotBuilder instance configured with the cloned curve data (self.clone()) and fully initialized with default PlotOptions.

§Default Settings

  • The default PlotOptions, as used in this implementation, include:
    • White background
    • Line width of 2 pixels
    • Default dimensions (800x600 pixels)
    • No title or axis labels
    • No default line colors

§Errors

  • While creating a PlotBuilder instance does not directly raise errors, subsequent operations (e.g., saving a plot or generating a view) may encounter runtime issues related to file I/O, data validity, or plot rendering.

§See Also

  • Plottable: The trait allowing generalized plotting functionality.
  • PlotBuilder: The plot generation and configuration builder.

§Modules

This implementation works in conjunction with the Curve struct, PlotBuilder, and PlotOptions. These modules provide the functionality required to create, configure, and render curve plots.

Source§

fn plot(&self) -> PlotBuilder<Self>
where Self: Sized,

Implementors§