From b7252ef4bb1b262e90b5fde5e3319c43d35d8277 Mon Sep 17 00:00:00 2001 From: Pavel Sountsov Date: Fri, 22 Mar 2024 20:54:24 -0700 Subject: [PATCH] Custom palettes need at least two elements, not at least one. Change the error check + documentation. Fixes #99 --- gnuplot/src/axes_common.rs | 4 ++-- gnuplot/src/options.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gnuplot/src/axes_common.rs b/gnuplot/src/axes_common.rs index c6db9968..2684d0c5 100644 --- a/gnuplot/src/axes_common.rs +++ b/gnuplot/src/axes_common.rs @@ -1395,9 +1395,9 @@ impl AxesCommonData } Custom(ref entries) => { - if entries.is_empty() + if entries.len() < 2 { - panic!("Need at least 1 element in a custom palette"); + panic!("Need at least 2 elements in a custom palette"); } write!(w, "set palette defined ("); diff --git a/gnuplot/src/options.rs b/gnuplot/src/options.rs index 1606d0f7..d3334016 100644 --- a/gnuplot/src/options.rs +++ b/gnuplot/src/options.rs @@ -421,7 +421,7 @@ pub enum PaletteType /// Use a cube helix palette, with a certain start (in radians), cycles, saturation and gamma. CubeHelix(f32, f32, f32, f32), /// A custom palette - /// is specified by a sequence of 4-tuples (with at least one element). The first + /// is specified by a sequence of 4-tuples (with at least two elements). The first /// element is the grayscale value that is mapped to the remaining three elements /// which specify the red, green and blue components of the color. /// The grayscale values must be non-decreasing. All values must range from 0 to 1.