pub trait Graph {
// Required method
fn graph_data(&self) -> GraphData;
// Provided method
fn graph_config(&self) -> GraphConfig { ... }
}Expand description
A trait that defines the functionality for creating, configuring, and rendering graphical representations of data, along with support for various output formats.
The Graph trait abstracts away details involved in preparing graph data, applying
configurations, and rendering graphs in different formats such as PNG, SVG, PDF, or
directly displaying them in an interactive terminal.
§Required Methods
graph_data: Returns the raw data structure (GraphData) required for plotting.
§Optional Methods
graph_config: Provides configuration overrides for the graph, including dimensions, labels, legends, and other visual properties. Defaults toGraphConfig::default().
§Core Render Methods
to_gnuplot: Converts the instance into a sequence of gnuplot commands based on its data and configuration.
§Export and Viewing Methods
write_png: Exports the graph as a PNG image to a specified file.write_html: (For compatibility) Creates a self-contained HTML file with the image embedded.write_svg: Exports the graph as an SVG file.write_pdf: Exports the graph as a PDF file.show: Displays the graph interactively.render: A unified interface for rendering graphs in various formats.
§Advanced Features
to_interactive_html: (For compatibility) Creates an interactive HTML file with hover information and annotations.
Required Methods§
Sourcefn graph_data(&self) -> GraphData
fn graph_data(&self) -> GraphData
Return the raw data ready for plotting.
Provided Methods§
Sourcefn graph_config(&self) -> GraphConfig
fn graph_config(&self) -> GraphConfig
Optional per‑object configuration overrides.
Implementations on Foreign Types§
Implementors§
impl Graph for Curve
impl Graph for Options
impl Graph for Position
Implementation of the Graph trait for the Position struct, enabling graphical representation
of financial options positions.
This implementation provides methods to visualize the profit/loss (PnL) profile of an options position across different price levels of the underlying asset. It handles the generation of appropriate title, data values for plotting, and special chart elements like break-even points.
The visualization capabilities allow traders to analyze the potential outcomes of their options positions at expiration across various price scenarios.