optionstratlib-visualization 0.22.1

Backend-neutral chart models, the Graph contract and its implementations for OptionStratLib types, with optional Plotly rendering and static export. Re-exported by the optionstratlib facade under its `visualization` feature.
Documentation
//! Target crate (ADR-0001 D6, roadmap M1-14): **visualization**. Owns `GraphError`.

use optionstratlib_backtest::error::BacktestError;
use optionstratlib_core::error::DecimalError;
use optionstratlib_math::error::{CurveError, SurfaceError};
use thiserror::Error;

/// Represents errors that can occur during graph generation and rendering operations.
///
/// This error type encapsulates failures that may happen when creating, rendering,
/// or saving graphical representations of financial data such as option chains,
/// volatility surfaces, or strategy payoffs.
#[derive(Error, Debug)]
pub enum GraphError {
    /// Represents errors that occur during the rendering process.
    /// Contains a descriptive message about what went wrong.
    #[error("Render error: {0}")]
    Render(String),

    /// Represents I/O errors that occur when reading from or writing to files
    /// (e.g., when saving graphs to disk).
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    /// Error from curve operations.
    #[error(transparent)]
    Curve(CurveError),

    /// Error from surface operations.
    #[error(transparent)]
    Surface(SurfaceError),

    /// A figure a report derives for display (a total, an average) left the
    /// representable `Decimal` range.
    #[error(transparent)]
    Decimal(Box<DecimalError>),

    /// The backtest figures a report shows could not be computed, for
    /// example when the statistics of a `SimulationStats` accumulator
    /// overflow `Decimal`.
    #[error(transparent)]
    Backtest(Box<BacktestError>),
}

impl From<BacktestError> for GraphError {
    #[cold]
    #[inline(never)]
    fn from(err: BacktestError) -> Self {
        GraphError::Backtest(Box::new(err))
    }
}

impl From<DecimalError> for GraphError {
    #[cold]
    #[inline(never)]
    fn from(err: DecimalError) -> Self {
        GraphError::Decimal(Box::new(err))
    }
}

impl From<CurveError> for GraphError {
    #[cold]
    #[inline(never)]
    fn from(err: CurveError) -> Self {
        GraphError::Curve(err)
    }
}

impl From<SurfaceError> for GraphError {
    #[cold]
    #[inline(never)]
    fn from(err: SurfaceError) -> Self {
        GraphError::Surface(err)
    }
}