plotters-statistical 0.1.0

Statistical chart primitives (box, violin, ROC, PR, regularization-path, residual) as native plotters series
Documentation
//! Figure-level builders: charts that own their own axes / multi-panel layout
//! and render onto a whole `DrawingArea`, rather than plugging into a single
//! `draw_series` call.
//!
//! * [`CorrelationHeatmap`] — labeled correlation matrix + colorbar.
//! * [`MissingnessHeatmap`] — data-quality present/absent map for EDA.
//! * [`PairPlot`] — scatterplot matrix with distribution diagonals.

pub mod colorbar;
pub mod correlation_heatmap;
pub mod missingness_heatmap;
pub mod pair_plot;

pub use correlation_heatmap::CorrelationHeatmap;
pub use missingness_heatmap::MissingnessHeatmap;
pub use pair_plot::{Diagonal, PairPlot};

use plotters::prelude::*;
use plotters::style::text_anchor::{HPos, Pos, VPos};

/// Build an anchored `sans-serif` [`TextStyle`]. The color is borrowed, so pass
/// a `&color` that lives at least as long as the returned style is used (a
/// temporary in the same `draw(...)` statement is fine).
pub(crate) fn text_style<'a>(h: HPos, v: VPos, size: i32, color: &'a RGBColor) -> TextStyle<'a> {
    TextStyle::from(("sans-serif", size).into_font())
        .color(color)
        .pos(Pos::new(h, v))
}

/// Pick black or white for legible text over a background color.
pub(crate) fn contrast_text(bg: RGBColor) -> RGBColor {
    let l = 0.299 * bg.0 as f64 + 0.587 * bg.1 as f64 + 0.114 * bg.2 as f64;
    if l > 140.0 {
        RGBColor(0, 0, 0)
    } else {
        RGBColor(255, 255, 255)
    }
}