crisol-plot-core 1.16.1

Crisol plot core: the egui-free math behind the plot, axis ticks, analysis, filters, and decimation.
Documentation
use super::*;

#[test]
fn a_minimal_spec_is_valid() {
    let spec = PlotSpec::new(320, 200).series(SeriesSpec::line("v", vec![[0.0, 1.0], [1.0, 2.0]]));
    assert_eq!(spec.validate(), Ok(()));
    assert_eq!(spec.version, PLOT_SPEC_VERSION);
}

#[test]
fn invalid_specs_are_rejected() {
    let mut spec = PlotSpec::new(0, 200);
    assert_eq!(spec.validate(), Err(SpecError::Size));
    spec.width = 20_000;
    assert!(matches!(spec.validate(), Err(SpecError::TooLarge { .. })));
    spec.width = 200;
    spec.x_range = Some([2.0, 1.0]);
    assert!(matches!(spec.validate(), Err(SpecError::Range(_))));
    spec.x_range = None;
    spec.series.push(SeriesSpec::default());
    assert!(matches!(spec.validate(), Err(SpecError::EmptySeries(_))));
}

#[test]
fn page_presets_scale_with_dpi() {
    assert_eq!(PagePreset::SingleColumn.pixels(300), (1050, 750));
    assert_eq!(PagePreset::DoubleColumn.pixels(300), (2148, 1350));
    assert_eq!(PlotSpec::new(1, 1).preset(PagePreset::Letter, 72).width, 612);
}

#[test]
fn the_palette_wraps() {
    let theme = PlotTheme::default();
    assert_eq!(theme.series_color(0), theme.palette[0]);
    assert_eq!(theme.series_color(theme.palette.len()), theme.palette[0]);
}

#[cfg(feature = "serde")]
#[test]
fn a_spec_round_trips_through_json() {
    let spec = PlotSpec::new(640, 360)
        .title("Signal")
        .series(SeriesSpec::scatter("s", vec![[0.0, 1.0], [1.0, 2.0]]));
    let json = serde_json::to_string(&spec).expect("serialize");
    let restored: PlotSpec = serde_json::from_str(&json).expect("deserialize");
    assert_eq!(restored, spec);
}