1pub use self::AlignType::*;
6pub use self::ArrowheadType::*;
7pub use self::AutoOption::*;
8pub use self::BorderLocation2D::*;
9pub use self::ContourStyle::*;
10pub use self::DashType::*;
11pub use self::FillPatternType::*;
12pub use self::FillRegionType::*;
13pub use self::LabelOption::*;
14pub use self::LegendOption::*;
15pub use self::MarginSide::*;
16pub use self::PaletteType::*;
17pub use self::PlotOption::*;
18pub use self::Tick::*;
19pub use self::TickOption::*;
20pub use self::XAxis::*;
21pub use self::YAxis::*;
22use crate::util::OneWayOwned;
23use crate::writer::Writer;
24use crate::ColorType;
25
26#[derive(Clone, Debug, PartialOrd, PartialEq)]
29pub enum PlotOption<T>
30{
31 PointSymbol(char),
48 PointSize(f64),
50 Caption(T),
52 LineWidth(f64),
54 Color(ColorType<T>),
57 BorderColor(ColorType<T>),
60 LineStyle(DashType),
62 FillAlpha(f64),
64 FillRegion(FillRegionType),
66 FillPattern(AutoOption<FillPatternType>),
69 ArrowType(ArrowheadType),
71 ArrowSize(f64),
73 WhiskerBars(f64),
75 Axes(XAxis, YAxis),
77 BoxWidth(Vec<f64>),
79}
80
81impl<'l> OneWayOwned for PlotOption<&'l str>
82{
83 type Output = PlotOption<String>;
84 fn to_one_way_owned(&self) -> Self::Output
85 {
86 match *self
87 {
88 PointSymbol(v) => PointSymbol(v),
89 PointSize(v) => PointSize(v),
90 Caption(v) => Caption(v.into()),
91 LineWidth(v) => LineWidth(v),
92 Color(ref v) => Color(v.to_one_way_owned()),
93 BorderColor(ref v) => BorderColor(v.to_one_way_owned()),
94 LineStyle(v) => LineStyle(v),
95 FillAlpha(v) => FillAlpha(v),
96 FillRegion(v) => FillRegion(v),
97 ArrowType(v) => ArrowType(v),
98 ArrowSize(v) => ArrowSize(v),
99 WhiskerBars(v) => WhiskerBars(v),
100 FillPattern(v) => FillPattern(v),
101 Axes(x, y) => Axes(x, y),
102 BoxWidth(ref d) => BoxWidth(d.clone()),
103 }
104 }
105}
106
107#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
109pub enum XAxis
110{
111 X1,
112 X2,
113}
114
115#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
117pub enum YAxis
118{
119 Y1,
120 Y2,
121}
122
123#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
125pub enum FillRegionType
126{
127 Above,
128 Below,
129 Between,
130}
131
132#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
134pub enum AlignType
135{
136 AlignLeft,
137 AlignRight,
138 AlignCenter,
139 AlignTop,
140 AlignBottom,
141}
142
143#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
145pub enum DashType
146{
147 Solid,
148 SmallDot,
149 Dot,
150 Dash,
151 DotDash,
152 DotDotDash,
153}
154
155impl DashType
156{
157 pub fn to_int(&self) -> i32
158 {
159 match *self
160 {
161 Solid => 1,
162 SmallDot => 0,
163 Dash => 2,
164 Dot => 3,
165 DotDash => 4,
166 DotDotDash => 5,
167 }
168 }
169}
170
171#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
173pub enum ArrowheadType
174{
175 Open,
177 Closed,
179 Filled,
181 NoArrow,
183}
184
185#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
188pub enum AutoOption<T>
189{
190 Fix(T),
192 Auto,
194}
195
196impl<T> AutoOption<T>
197{
198 pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> AutoOption<U>
200 {
201 match self
202 {
203 Fix(v) => Fix(f(v)),
204 Auto => Auto,
205 }
206 }
207}
208
209impl<T: ToString> OneWayOwned for AutoOption<T>
210{
211 type Output = AutoOption<String>;
212 fn to_one_way_owned(&self) -> Self::Output
213 {
214 match self
215 {
216 Fix(v) => Fix(v.to_string()),
217 Auto => Auto,
218 }
219 }
220}
221
222#[derive(Clone, Debug, PartialOrd, PartialEq)]
224pub enum LabelOption<T>
225{
226 TextOffset(f64, f64),
228 Font(T, f64),
230 TextColor(ColorType<T>),
233 Rotate(f64),
235 TextAlign(AlignType),
237 MarkerSymbol(char),
254 MarkerColor(ColorType<T>),
257 MarkerSize(f64),
259}
260
261impl<'l> OneWayOwned for LabelOption<&'l str>
262{
263 type Output = LabelOption<String>;
264 fn to_one_way_owned(&self) -> Self::Output
265 {
266 match self.clone()
267 {
268 TextOffset(v1, v2) => TextOffset(v1, v2),
269 Font(v1, v2) => Font(v1.into(), v2),
270 TextColor(v) => TextColor(v.to_one_way_owned()),
271 Rotate(v) => Rotate(v),
272 TextAlign(v) => TextAlign(v),
273 MarkerSymbol(v) => MarkerSymbol(v),
274 MarkerColor(v) => MarkerColor(v.to_one_way_owned()),
275 MarkerSize(v) => MarkerSize(v),
276 }
277 }
278}
279
280#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
282pub enum TickOption<T>
283{
284 OnAxis(bool),
286 Mirror(bool),
288 Inward(bool),
290 MinorScale(f64),
292 MajorScale(f64),
294 Format(T),
296}
297
298impl<'l> OneWayOwned for TickOption<&'l str>
299{
300 type Output = TickOption<String>;
301 fn to_one_way_owned(&self) -> Self::Output
302 {
303 match *self
304 {
305 OnAxis(v) => OnAxis(v),
306 Mirror(v) => Mirror(v),
307 Inward(v) => Inward(v),
308 MinorScale(v) => MinorScale(v),
309 MajorScale(v) => MajorScale(v),
310 Format(v) => Format(v.into()),
311 }
312 }
313}
314
315#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
317pub enum Tick<T, S>
318{
319 Major(T, AutoOption<S>),
321 Minor(T),
323}
324
325impl<'l, T: Clone, S: ToString> OneWayOwned for Tick<T, S>
326{
327 type Output = Tick<T, String>;
328 fn to_one_way_owned(&self) -> Self::Output
329 {
330 match self
331 {
332 Minor(v) => Minor(v.clone()),
333 Major(v, s) => Major(v.clone(), s.to_one_way_owned()),
334 }
335 }
336}
337
338#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
340pub enum BorderLocation2D
341{
342 Bottom = 1,
343 Left = 2,
344 Top = 4,
345 Right = 8,
346}
347
348#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
350pub enum MarginSide
351{
352 MarginLeft(f32),
353 MarginRight(f32),
354 MarginTop(f32),
355 MarginBottom(f32),
356}
357
358#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
360pub enum LegendOption<T>
361{
362 Reverse,
364 Invert,
366 Horizontal,
368 Placement(AlignType, AlignType),
371 Title(T),
373 MaxRows(u32),
375 MaxCols(u32),
377}
378
379impl<'l> OneWayOwned for LegendOption<&'l str>
380{
381 type Output = LegendOption<String>;
382 fn to_one_way_owned(&self) -> Self::Output
383 {
384 match *self
385 {
386 Reverse => Reverse,
387 Invert => Invert,
388 Horizontal => Horizontal,
389 Placement(v1, v2) => Placement(v1, v2),
390 Title(v) => Title(v.into()),
391 MaxRows(v) => MaxRows(v),
392 MaxCols(v) => MaxCols(v),
393 }
394 }
395}
396
397#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
399pub enum ContourStyle
400{
401 Linear,
403 Cubic(u32),
408 Spline(u32, u32),
415}
416
417#[derive(Clone, Debug, PartialOrd, PartialEq)]
419pub enum PaletteType<T>
420{
421 Gray(f32),
423 Formula(i32, i32, i32),
426 CubeHelix(f32, f32, f32, f32),
428 Custom(T),
434}
435
436impl<'l> OneWayOwned for PaletteType<&'l [(f32, f32, f32, f32)]>
437{
438 type Output = PaletteType<Vec<(f32, f32, f32, f32)>>;
439 fn to_one_way_owned(&self) -> Self::Output
440 {
441 match *self
442 {
443 Gray(v) => Gray(v),
444 Formula(v1, v2, v3) => Formula(v1, v2, v3),
445 CubeHelix(v1, v2, v3, v4) => CubeHelix(v1, v2, v3, v4),
446 Custom(v) => Custom(v.into()),
447 }
448 }
449}
450
451pub const GRAY: PaletteType<&'static [(f32, f32, f32, f32)]> = Gray(1.0);
453pub const COLOR: PaletteType<&'static [(f32, f32, f32, f32)]> = Formula(7, 5, 15);
455pub const RAINBOW: PaletteType<&'static [(f32, f32, f32, f32)]> = Formula(33, 13, 10);
457pub const HOT: PaletteType<&'static [(f32, f32, f32, f32)]> = Formula(34, 35, 36);
459pub const HELIX: PaletteType<&'static [(f32, f32, f32, f32)]> = CubeHelix(0.5, -0.8, 2.0, 1.0);
461
462impl PaletteType<Vec<(f32, f32, f32, f32)>>
463{
464 pub fn write_out_commands(&self, w: &mut dyn Writer)
465 {
466 match *self
467 {
468 Gray(gamma) =>
469 {
470 assert!(gamma > 0.0, "Gamma must be positive");
471 writeln!(w, "set palette gray gamma {:.12e}", gamma);
472 }
473 Formula(r, g, b) =>
474 {
475 assert!(r >= -36 && r <= 36, "Invalid r formula!");
476 assert!(g >= -36 && g <= 36, "Invalid g formula!");
477 assert!(b >= -36 && b <= 36, "Invalid b formula!");
478 writeln!(w, "set palette rgbformulae {},{},{}", r, g, b);
479 }
480 CubeHelix(start, rev, sat, gamma) =>
481 {
482 assert!(sat >= 0.0, "Saturation must be non-negative");
483 assert!(gamma > 0.0, "Gamma must be positive");
484 writeln!(
485 w,
486 "set palette cubehelix start {:.12e} cycles {:.12e} saturation {:.12e} gamma {:.12e}",
487 start, rev, sat, gamma
488 );
489 }
490 Custom(ref entries) =>
491 {
492 if entries.len() < 2
493 {
494 panic!("Need at least 2 elements in a custom palette");
495 }
496 write!(w, "set palette defined (");
497
498 let mut first = true;
499 let mut old_x = 0.0;
500 for &(x, r, g, b) in entries
501 {
502 if first
503 {
504 old_x = x;
505 first = false;
506 }
507 else
508 {
509 write!(w, ",");
510 }
511 assert!(x >= old_x, "The gray levels must be non-decreasing!");
512 old_x = x;
513
514 write!(w, "{:.12e} {:.12e} {:.12e} {:.12e}", x, r, g, b);
515 }
516 writeln!(w, ")");
517 }
518 }
519 }
520}
521
522#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
525pub struct GnuplotVersion
526{
527 pub major: i32,
528 pub minor: i32,
529}
530
531#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
537pub enum FillPatternType
538{
539 Pattern0 = 0,
540 BigCrosses = 1,
541 SmallCrosses = 2,
542 Pattern3 = 3,
543 BigBackSlashes = 4,
544 BigForwardSlashes = 5,
545 SmallBackSlashes = 6,
546 SmallForwardSlashes = 7,
547 Pattern8 = 8,
548}
549
550#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
552pub enum MultiplotFillOrder
553{
554 RowsFirst,
556 ColumnsFirst,
558}
559
560#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
562pub enum MultiplotFillDirection
563{
564 Downwards,
566 Upwards,
568}