pub trait Graph {
// Required method
fn graph_data(&self) -> GraphData;
// Provided methods
fn graph_config(&self) -> GraphConfig { ... }
fn to_plot(&self) -> Plot { ... }
fn write_html(&self, path: &Path) -> Result<(), GraphError> { ... }
fn show(&self) -> Result<(), GraphError> { ... }
fn render(&self, output: OutputType<'_>) -> Result<(), GraphError> { ... }
fn to_interactive_html(&self, path: &Path) -> Result<(), GraphError> { ... }
}Expand description
Chart contract of every type the library can draw: strategies, option chains’ curves and surfaces, options, positions and simulations.
The required items are the same on every feature surface: implementors
supply graph_data() and may override graph_config(). The backend
features add provided renderers on top: to_plot, write_html, show,
render and to_interactive_html under plotly, and write_png and
write_svg under static_export. None of them needs to be implemented.
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.
Sourcefn write_html(&self, path: &Path) -> Result<(), GraphError>
fn write_html(&self, path: &Path) -> Result<(), GraphError>
Writes the graph data to an HTML file at the specified path.
This method generates a plot representation of the graph and saves it as an HTML document. It ensures that the provided file path is prepared (i.e., directories are created if necessary) before writing the file.
§Arguments
path- A reference to astd::path::Pathspecifying the file path where the HTML file will be written.
§Returns
Ok(())if the HTML file is successfully written.Err(GraphError)if an error occurs during file preparation or writing.
§Errors
This method can return the following errors:
- A
GraphErrorif the file path preparation fails. - Any other error propagated from the
.to_plot().write_html()method.
§Notes
Ensure that the directory specified in the file path exists or can be created with appropriate permissions to avoid errors during file preparation.
Sourcefn show(&self) -> Result<(), GraphError>
fn show(&self) -> Result<(), GraphError>
Show the plot in browser
§Errors
Returns GraphError::Io when the page cannot be written to the
system temp directory or the platform’s opener (open, xdg-open,
explorer) cannot be started, as on a headless server, and
GraphError::Render on a platform with no default opener.
Sourcefn render(&self, output: OutputType<'_>) -> Result<(), GraphError>
fn render(&self, output: OutputType<'_>) -> Result<(), GraphError>
One‑stop rendering with error propagation.
§Errors
Returns GraphError::Render when the chosen OutputType
backend (PNG/SVG via static_export, HTML, etc.) fails to
serialize or render, or when a PNG or SVG is asked for in a build
without static_export, and GraphError::Io when the
destination path cannot be written.
Sourcefn to_interactive_html(&self, path: &Path) -> Result<(), GraphError>
fn to_interactive_html(&self, path: &Path) -> Result<(), GraphError>
Generate interactive HTML with hover info + annotations.
§Errors
Propagates any GraphError returned by
PlotlyChart::write_html, typically
GraphError::Io when the target file cannot be
created or written.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Graph for BearCallSpread
impl Graph for BearCallSpread
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for BearPutSpread
impl Graph for BearPutSpread
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for BullCallLadder
impl Graph for BullCallLadder
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for BullCallSpread
impl Graph for BullCallSpread
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for BullPutSpread
impl Graph for BullPutSpread
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for Collar
impl Graph for Collar
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for CoveredCall
impl Graph for CoveredCall
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for Curve
Graph adapter for a single Curve; lives in visualization because
the trait is visualization-owned and Curve is a math container
(ADR-0001 D2, M1-05).
impl Graph for Curve
Graph adapter for a single Curve; lives in visualization because
the trait is visualization-owned and Curve is a math container
(ADR-0001 D2, M1-05).
fn graph_data(&self) -> GraphData
Source§impl Graph for CustomStrategy
impl Graph for CustomStrategy
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for IronButterfly
impl Graph for IronButterfly
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for IronCondor
impl Graph for IronCondor
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for LongButterflySpread
impl Graph for LongButterflySpread
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for LongCall
impl Graph for LongCall
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for LongPut
impl Graph for LongPut
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for LongStraddle
impl Graph for LongStraddle
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for LongStrangle
impl Graph for LongStrangle
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for Options
impl Graph for Options
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for PoorMansCoveredCall
impl Graph for PoorMansCoveredCall
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for Position
Implementation of the Graph trait for the Position struct, enabling graphical representation
of financial options positions.
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.
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for ProtectivePut
impl Graph for ProtectivePut
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for ShortButterflySpread
impl Graph for ShortButterflySpread
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for ShortCall
impl Graph for ShortCall
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for ShortPut
impl Graph for ShortPut
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for ShortStraddle
impl Graph for ShortStraddle
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for ShortStrangle
impl Graph for ShortStrangle
fn graph_data(&self) -> GraphData
fn graph_config(&self) -> GraphConfig
Source§impl Graph for Surface
Graph adapter for a Surface; lives in visualization because the
trait is visualization-owned and Surface is a math container
(ADR-0001 D2, M1-05).
impl Graph for Surface
Graph adapter for a Surface; lives in visualization because the
trait is visualization-owned and Surface is a math container
(ADR-0001 D2, M1-05).
fn graph_data(&self) -> GraphData
Source§impl Graph for Vec<Curve>
Graph adapter for a family of curves drawn on one chart.
impl Graph for Vec<Curve>
Graph adapter for a family of curves drawn on one chart.