pub use self::AlignType::*;
pub use self::ArrowheadType::*;
pub use self::AutoOption::*;
pub use self::BorderLocation2D::*;
pub use self::ContourStyle::*;
pub use self::DashType::*;
pub use self::FillPatternType::*;
pub use self::FillRegionType::*;
pub use self::LabelOption::*;
pub use self::LegendOption::*;
pub use self::MarginSide::*;
pub use self::PaletteType::*;
pub use self::PlotOption::*;
pub use self::Tick::*;
pub use self::TickOption::*;
pub use self::XAxis::*;
pub use self::YAxis::*;
use crate::util::OneWayOwned;
use crate::writer::Writer;
use crate::ColorType;
#[derive(Clone, Debug, PartialOrd, PartialEq)]
pub enum PlotOption<T>
{
PointSymbol(char),
PointSize(f64),
Caption(T),
LineWidth(f64),
Color(ColorType<T>),
BorderColor(ColorType<T>),
LineStyle(DashType),
FillAlpha(f64),
FillRegion(FillRegionType),
FillPattern(AutoOption<FillPatternType>),
ArrowType(ArrowheadType),
ArrowSize(f64),
WhiskerBars(f64),
Axes(XAxis, YAxis),
BoxWidth(Vec<f64>),
}
impl<'l> OneWayOwned for PlotOption<&'l str>
{
type Output = PlotOption<String>;
fn to_one_way_owned(&self) -> Self::Output
{
match *self
{
PointSymbol(v) => PointSymbol(v),
PointSize(v) => PointSize(v),
Caption(v) => Caption(v.into()),
LineWidth(v) => LineWidth(v),
Color(ref v) => Color(v.to_one_way_owned()),
BorderColor(ref v) => BorderColor(v.to_one_way_owned()),
LineStyle(v) => LineStyle(v),
FillAlpha(v) => FillAlpha(v),
FillRegion(v) => FillRegion(v),
ArrowType(v) => ArrowType(v),
ArrowSize(v) => ArrowSize(v),
WhiskerBars(v) => WhiskerBars(v),
FillPattern(v) => FillPattern(v),
Axes(x, y) => Axes(x, y),
BoxWidth(ref d) => BoxWidth(d.clone()),
}
}
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum XAxis
{
X1,
X2,
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum YAxis
{
Y1,
Y2,
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum FillRegionType
{
Above,
Below,
Between,
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum AlignType
{
AlignLeft,
AlignRight,
AlignCenter,
AlignTop,
AlignBottom,
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum DashType
{
Solid,
SmallDot,
Dot,
Dash,
DotDash,
DotDotDash,
}
impl DashType
{
pub fn to_int(&self) -> i32
{
match *self
{
Solid => 1,
SmallDot => 0,
Dash => 2,
Dot => 3,
DotDash => 4,
DotDotDash => 5,
}
}
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum ArrowheadType
{
Open,
Closed,
Filled,
NoArrow,
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum AutoOption<T>
{
Fix(T),
Auto,
}
impl<T> AutoOption<T>
{
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> AutoOption<U>
{
match self
{
Fix(v) => Fix(f(v)),
Auto => Auto,
}
}
}
impl<T: ToString> OneWayOwned for AutoOption<T>
{
type Output = AutoOption<String>;
fn to_one_way_owned(&self) -> Self::Output
{
match self
{
Fix(v) => Fix(v.to_string()),
Auto => Auto,
}
}
}
#[derive(Clone, Debug, PartialOrd, PartialEq)]
pub enum LabelOption<T>
{
TextOffset(f64, f64),
Font(T, f64),
TextColor(ColorType<T>),
Rotate(f64),
TextAlign(AlignType),
MarkerSymbol(char),
MarkerColor(ColorType<T>),
MarkerSize(f64),
}
impl<'l> OneWayOwned for LabelOption<&'l str>
{
type Output = LabelOption<String>;
fn to_one_way_owned(&self) -> Self::Output
{
match self.clone()
{
TextOffset(v1, v2) => TextOffset(v1, v2),
Font(v1, v2) => Font(v1.into(), v2),
TextColor(v) => TextColor(v.to_one_way_owned()),
Rotate(v) => Rotate(v),
TextAlign(v) => TextAlign(v),
MarkerSymbol(v) => MarkerSymbol(v),
MarkerColor(v) => MarkerColor(v.to_one_way_owned()),
MarkerSize(v) => MarkerSize(v),
}
}
}
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
pub enum TickOption<T>
{
OnAxis(bool),
Mirror(bool),
Inward(bool),
MinorScale(f64),
MajorScale(f64),
Format(T),
}
impl<'l> OneWayOwned for TickOption<&'l str>
{
type Output = TickOption<String>;
fn to_one_way_owned(&self) -> Self::Output
{
match *self
{
OnAxis(v) => OnAxis(v),
Mirror(v) => Mirror(v),
Inward(v) => Inward(v),
MinorScale(v) => MinorScale(v),
MajorScale(v) => MajorScale(v),
Format(v) => Format(v.into()),
}
}
}
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum Tick<T, S>
{
Major(T, AutoOption<S>),
Minor(T),
}
impl<'l, T: Clone, S: ToString> OneWayOwned for Tick<T, S>
{
type Output = Tick<T, String>;
fn to_one_way_owned(&self) -> Self::Output
{
match self
{
Minor(v) => Minor(v.clone()),
Major(v, s) => Major(v.clone(), s.to_one_way_owned()),
}
}
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum BorderLocation2D
{
Bottom = 1,
Left = 2,
Top = 4,
Right = 8,
}
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
pub enum MarginSide
{
MarginLeft(f32),
MarginRight(f32),
MarginTop(f32),
MarginBottom(f32),
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum LegendOption<T>
{
Reverse,
Invert,
Horizontal,
Placement(AlignType, AlignType),
Title(T),
MaxRows(u32),
MaxCols(u32),
}
impl<'l> OneWayOwned for LegendOption<&'l str>
{
type Output = LegendOption<String>;
fn to_one_way_owned(&self) -> Self::Output
{
match *self
{
Reverse => Reverse,
Invert => Invert,
Horizontal => Horizontal,
Placement(v1, v2) => Placement(v1, v2),
Title(v) => Title(v.into()),
MaxRows(v) => MaxRows(v),
MaxCols(v) => MaxCols(v),
}
}
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum ContourStyle
{
Linear,
Cubic(u32),
Spline(u32, u32),
}
#[derive(Clone, Debug, PartialOrd, PartialEq)]
pub enum PaletteType<T>
{
Gray(f32),
Formula(i32, i32, i32),
CubeHelix(f32, f32, f32, f32),
Custom(T),
}
impl<'l> OneWayOwned for PaletteType<&'l [(f32, f32, f32, f32)]>
{
type Output = PaletteType<Vec<(f32, f32, f32, f32)>>;
fn to_one_way_owned(&self) -> Self::Output
{
match *self
{
Gray(v) => Gray(v),
Formula(v1, v2, v3) => Formula(v1, v2, v3),
CubeHelix(v1, v2, v3, v4) => CubeHelix(v1, v2, v3, v4),
Custom(v) => Custom(v.into()),
}
}
}
pub const GRAY: PaletteType<&'static [(f32, f32, f32, f32)]> = Gray(1.0);
pub const COLOR: PaletteType<&'static [(f32, f32, f32, f32)]> = Formula(7, 5, 15);
pub const RAINBOW: PaletteType<&'static [(f32, f32, f32, f32)]> = Formula(33, 13, 10);
pub const HOT: PaletteType<&'static [(f32, f32, f32, f32)]> = Formula(34, 35, 36);
pub const HELIX: PaletteType<&'static [(f32, f32, f32, f32)]> = CubeHelix(0.5, -0.8, 2.0, 1.0);
impl PaletteType<Vec<(f32, f32, f32, f32)>>
{
pub fn write_out_commands(&self, w: &mut dyn Writer)
{
match *self
{
Gray(gamma) =>
{
assert!(gamma > 0.0, "Gamma must be positive");
writeln!(w, "set palette gray gamma {:.12e}", gamma);
}
Formula(r, g, b) =>
{
assert!(r >= -36 && r <= 36, "Invalid r formula!");
assert!(g >= -36 && g <= 36, "Invalid g formula!");
assert!(b >= -36 && b <= 36, "Invalid b formula!");
writeln!(w, "set palette rgbformulae {},{},{}", r, g, b);
}
CubeHelix(start, rev, sat, gamma) =>
{
assert!(sat >= 0.0, "Saturation must be non-negative");
assert!(gamma > 0.0, "Gamma must be positive");
writeln!(
w,
"set palette cubehelix start {:.12e} cycles {:.12e} saturation {:.12e} gamma {:.12e}",
start, rev, sat, gamma
);
}
Custom(ref entries) =>
{
if entries.len() < 2
{
panic!("Need at least 2 elements in a custom palette");
}
write!(w, "set palette defined (");
let mut first = true;
let mut old_x = 0.0;
for &(x, r, g, b) in entries
{
if first
{
old_x = x;
first = false;
}
else
{
write!(w, ",");
}
assert!(x >= old_x, "The gray levels must be non-decreasing!");
old_x = x;
write!(w, "{:.12e} {:.12e} {:.12e} {:.12e}", x, r, g, b);
}
writeln!(w, ")");
}
}
}
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub struct GnuplotVersion
{
pub major: i32,
pub minor: i32,
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum FillPatternType
{
Pattern0 = 0,
BigCrosses = 1,
SmallCrosses = 2,
Pattern3 = 3,
BigBackSlashes = 4,
BigForwardSlashes = 5,
SmallBackSlashes = 6,
SmallForwardSlashes = 7,
Pattern8 = 8,
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum MultiplotFillOrder
{
RowsFirst,
ColumnsFirst,
}
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub enum MultiplotFillDirection
{
Downwards,
Upwards,
}