1 use std::borrow::Cow;
2 
3 use crate::key::{Horizontal, Justification, Order, Stacked, Vertical};
4 use crate::{Axes, Axis, Color, Display, Grid, LineType, PointType, Terminal};
5 
6 impl Display<&'static str> for Axis {
display(&self) -> &'static str7     fn display(&self) -> &'static str {
8         match *self {
9             Axis::BottomX => "x",
10             Axis::LeftY => "y",
11             Axis::RightY => "y2",
12             Axis::TopX => "x2",
13         }
14     }
15 }
16 
17 impl Display<&'static str> for Axes {
display(&self) -> &'static str18     fn display(&self) -> &'static str {
19         match *self {
20             Axes::BottomXLeftY => "x1y1",
21             Axes::BottomXRightY => "x1y2",
22             Axes::TopXLeftY => "x2y1",
23             Axes::TopXRightY => "x2y2",
24         }
25     }
26 }
27 
28 impl Display<Cow<'static, str>> for Color {
display(&self) -> Cow<'static, str>29     fn display(&self) -> Cow<'static, str> {
30         match *self {
31             Color::Black => Cow::from("black"),
32             Color::Blue => Cow::from("blue"),
33             Color::Cyan => Cow::from("cyan"),
34             Color::DarkViolet => Cow::from("dark-violet"),
35             Color::ForestGreen => Cow::from("forest-green"),
36             Color::Gold => Cow::from("gold"),
37             Color::Gray => Cow::from("gray"),
38             Color::Green => Cow::from("green"),
39             Color::Magenta => Cow::from("magenta"),
40             Color::Red => Cow::from("red"),
41             Color::Rgb(r, g, b) => Cow::from(format!("#{:02x}{:02x}{:02x}", r, g, b)),
42             Color::White => Cow::from("white"),
43             Color::Yellow => Cow::from("yellow"),
44         }
45     }
46 }
47 
48 impl Display<&'static str> for Grid {
display(&self) -> &'static str49     fn display(&self) -> &'static str {
50         match *self {
51             Grid::Major => "",
52             Grid::Minor => "m",
53         }
54     }
55 }
56 
57 impl Display<&'static str> for Horizontal {
display(&self) -> &'static str58     fn display(&self) -> &'static str {
59         match *self {
60             Horizontal::Center => "center",
61             Horizontal::Left => "left",
62             Horizontal::Right => "right",
63         }
64     }
65 }
66 
67 impl Display<&'static str> for Justification {
display(&self) -> &'static str68     fn display(&self) -> &'static str {
69         match *self {
70             Justification::Left => "Left",
71             Justification::Right => "Right",
72         }
73     }
74 }
75 
76 impl Display<&'static str> for LineType {
display(&self) -> &'static str77     fn display(&self) -> &'static str {
78         match *self {
79             LineType::Dash => "2",
80             LineType::Dot => "3",
81             LineType::DotDash => "4",
82             LineType::DotDotDash => "5",
83             LineType::SmallDot => "0",
84             LineType::Solid => "1",
85         }
86     }
87 }
88 
89 impl Display<&'static str> for Order {
display(&self) -> &'static str90     fn display(&self) -> &'static str {
91         match *self {
92             Order::TextSample => "noreverse",
93             Order::SampleText => "reverse",
94         }
95     }
96 }
97 
98 impl Display<&'static str> for PointType {
display(&self) -> &'static str99     fn display(&self) -> &'static str {
100         match *self {
101             PointType::Circle => "6",
102             PointType::FilledCircle => "7",
103             PointType::FilledSquare => "5",
104             PointType::FilledTriangle => "9",
105             PointType::Plus => "1",
106             PointType::Square => "4",
107             PointType::Star => "3",
108             PointType::Triangle => "8",
109             PointType::X => "2",
110         }
111     }
112 }
113 
114 impl Display<&'static str> for Stacked {
display(&self) -> &'static str115     fn display(&self) -> &'static str {
116         match *self {
117             Stacked::Horizontally => "horizontal",
118             Stacked::Vertically => "vertical",
119         }
120     }
121 }
122 
123 impl Display<&'static str> for Terminal {
display(&self) -> &'static str124     fn display(&self) -> &'static str {
125         match *self {
126             Terminal::Svg => "svg dynamic",
127         }
128     }
129 }
130 
131 impl Display<&'static str> for Vertical {
display(&self) -> &'static str132     fn display(&self) -> &'static str {
133         match *self {
134             Vertical::Bottom => "bottom",
135             Vertical::Center => "center",
136             Vertical::Top => "top",
137         }
138     }
139 }
140