pub trait Graph {
// Required method
fn graph_data(&self) -> GraphData;
// Provided methods
fn graph_config(&self) -> GraphConfig { ... }
fn to_plot(&self) -> Plot { ... }
fn write_png(&self, path: &Path) -> Result<(), GraphError> { ... }
fn write_html(&self, path: &Path) -> Result<(), GraphError> { ... }
fn write_svg(&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_png(&self, path: &Path) -> Result<(), GraphError>
fn write_png(&self, path: &Path) -> Result<(), GraphError>
Writes the chart to path as a PNG of graph_config().width x
graph_config().height pixels, creating the parent directory when it
is missing.
The image is drawn natively from Graph::graph_data and
Graph::graph_config: no browser, WebDriver, network or installed
font is involved, and concurrent exports, in threads or processes,
are independent. Since 0.23 it no longer goes through
Graph::to_plot, so an override of to_plot changes the HTML
outputs but not this image.
§Errors
GraphError::Iowhen the file or its directory cannot be written or the image cannot be encoded into it.GraphError::InvalidDimensionsfor a width or height of zero or above 16384 pixels;GraphError::TooSmallorGraphError::NoRoomwhen the figure cannot hold the chart.GraphError::LengthMismatch,GraphError::SurfaceLengthMismatch,GraphError::DegenerateSurface,GraphError::DuplicateSurfacePoint,GraphError::IncompleteSurfaceorGraphError::NotRepresentablefor data it cannot draw without inventing or dropping values.GraphError::InvalidLineWidthorGraphError::InvalidColorfor a series style it cannot reproduce.GraphError::MissingGlyphorGraphError::UnsupportedTextfor a label the bundled font cannot draw.GraphError::Renderwhen drawing fails.
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 write_svg(&self, path: &Path) -> Result<(), GraphError>
fn write_svg(&self, path: &Path) -> Result<(), GraphError>
Writes the chart to path as an SVG of graph_config().width x
graph_config().height user units, creating the parent directory
when it is missing.
Drawn natively like Graph::write_png, with real vector shapes.
Every label is drawn as glyph outlines of the bundled Open Sans, so
the file looks the same in every viewer and needs no font. Each label
keeps its text as an accessible name (<g role="img" aria-label>)
and the document carries a <title> and <desc>; the text can no
longer be selected, searched or edited as text.
§Errors
Everything Graph::write_png returns, and
GraphError::NotXmlText for a label, title or series name that
contains a character XML cannot carry.
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
A PNG or SVG target returns whatever Graph::write_png or
Graph::write_svg returns, unchanged; in a build without
static_export it is GraphError::Render. HTML and browser targets
return GraphError::Render when serialization fails and
GraphError::Io when the destination 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.