Skip to content

Commit 102dd89

Browse files
committed
Add documentation to convenience functions
1 parent 3d1f213 commit 102dd89

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

gnuplot/src/color.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ pub enum ColorType<T = String>
5757
),
5858
/// Vector of tuples of `u8` (as per `RGBColor`), but instead of a single color for the whole
5959
/// plot, the vector should contain a separte color for each data point.
60-
VariableRGBIntegers(Vec<RGBInts>),
60+
VariableRGBInteger(Vec<RGBInts>),
6161
/// Vector of tuples of `u8` (as per `ARGBColor`), but as with `VariableRGBColor`, a separate
6262
/// color value is given for each data point.
63-
VariableARGBIntegers(Vec<ARGBInts>),
63+
VariableARGBInteger(Vec<ARGBInts>),
6464
/// TODO
6565
PaletteFracColor(f32),
6666
/// TODO
@@ -98,8 +98,8 @@ impl<T: Display> ColorType<T>
9898
RGBString(s) => format!(r#"rgb "{}""#, s),
9999
RGBInteger(r, g, b) => format!(r#"rgb {}"#, from_argb(0, *r, *g, *b)),
100100
ARGBInteger(a, r, g, b) => format!(r#"rgb {}"#, from_argb(*a, *r, *g, *b)),
101-
VariableRGBIntegers(_) => String::from("rgb variable"),
102-
VariableARGBIntegers(_) => String::from("rgb variable"),
101+
VariableRGBInteger(_) => String::from("rgb variable"),
102+
VariableARGBInteger(_) => String::from("rgb variable"),
103103
PaletteFracColor(_) => todo!(),
104104
PaletteCBColor(_) => todo!(),
105105
VariablePaletteColor(_) => String::from("palette z"),
@@ -118,11 +118,11 @@ impl<T: Display> ColorType<T>
118118
RGBString(_) => panic!("data() called on non-variable color type."),
119119
RGBInteger(_, _, _) => panic!("data() called on non-variable color type."),
120120
ARGBInteger(_, _, _, _) => panic!("data() called on non-variable color type."),
121-
VariableRGBIntegers(items) => items
121+
VariableRGBInteger(items) => items
122122
.iter()
123123
.map(|(r, g, b)| from_argb(0, *r, *g, *b) as f64)
124124
.collect(),
125-
VariableARGBIntegers(items) => items
125+
VariableARGBInteger(items) => items
126126
.into_iter()
127127
.map(|(a, r, g, b)| from_argb(*a, *r, *g, *b) as f64)
128128
.collect(),
@@ -141,8 +141,8 @@ impl<T: Display> ColorType<T>
141141
{
142142
match self
143143
{
144-
VariableRGBIntegers(_)
145-
| VariableARGBIntegers(_)
144+
VariableRGBInteger(_)
145+
| VariableARGBInteger(_)
146146
| VariableIndex(_)
147147
| VariablePaletteColor(_)
148148
| SavedColorMap(_, _) => true,
@@ -170,7 +170,7 @@ impl<T: Display> ColorType<T>
170170
false
171171
}
172172
}
173-
ARGBInteger(_, _, _, _) | VariableARGBIntegers(_) => true,
173+
ARGBInteger(_, _, _, _) | VariableARGBInteger(_) => true,
174174
_ => false,
175175
}
176176
}
@@ -275,15 +275,23 @@ impl<T> Into<ColorType<T>> for Vec<RGBInts>
275275
{
276276
fn into(self) -> ColorType<T>
277277
{
278-
ColorType::VariableRGBIntegers(self)
278+
ColorType::VariableRGBInteger(self)
279279
}
280280
}
281281

282282
impl<T> Into<ColorType<T>> for Vec<ARGBInts>
283283
{
284284
fn into(self) -> ColorType<T>
285285
{
286-
ColorType::VariableARGBIntegers(self)
286+
ColorType::VariableARGBInteger(self)
287+
}
288+
}
289+
290+
impl<T> Into<ColorType<T>> for ColorIndex
291+
{
292+
fn into(self) -> ColorType<T>
293+
{
294+
ColorType::Index(self)
287295
}
288296
}
289297

@@ -305,7 +313,7 @@ impl<T: Display> OneWayOwned for ColorType<T>
305313
{
306314
RGBString(s) => RGBString(s.to_string()),
307315
RGBInteger(r, g, b) => RGBInteger(*r, *g, *b),
308-
VariableRGBIntegers(d) => VariableRGBIntegers(d.clone()),
316+
VariableRGBInteger(d) => VariableRGBInteger(d.clone()),
309317
PaletteFracColor(_) => todo!(),
310318
PaletteCBColor(_) => todo!(),
311319
VariablePaletteColor(d) => VariablePaletteColor(d.clone()),
@@ -315,7 +323,7 @@ impl<T: Display> OneWayOwned for ColorType<T>
315323
Index(n) => Index(*n),
316324
Black => Black,
317325
ARGBInteger(a, r, g, b) => ARGBInteger(*a, *r, *g, *b),
318-
VariableARGBIntegers(d) => VariableARGBIntegers(d.clone()),
326+
VariableARGBInteger(d) => VariableARGBInteger(d.clone()),
319327
}
320328
}
321329
}
@@ -328,14 +336,14 @@ impl ColorType<String>
328336
{
329337
RGBString(s) => RGBString(s),
330338
RGBInteger(r, g, b) => RGBInteger(*r, *g, *b),
331-
VariableRGBIntegers(d) => VariableRGBIntegers(d.to_vec()),
332-
VariableARGBIntegers(d) => VariableARGBIntegers(d.to_vec()),
339+
VariableRGBInteger(d) => VariableRGBInteger(d.to_vec()),
340+
VariableARGBInteger(d) => VariableARGBInteger(d.to_vec()),
333341
PaletteFracColor(_) => todo!(),
334342
PaletteCBColor(_) => todo!(),
335343
VariablePaletteColor(d) => VariablePaletteColor(d.to_vec()),
336344
SavedColorMap(s, d) => SavedColorMap(s, d.to_vec()),
337345
VariableIndex(d) => VariableIndex(d.to_vec()),
338-
Background => todo!(),
346+
Background => Background,
339347
Index(n) => Index(*n),
340348
Black => Black,
341349
ARGBInteger(a, r, g, b) => ARGBInteger(*a, *r, *g, *b),

gnuplot/src/options.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,25 @@ pub enum PlotOption<T>
7878
}
7979

8080
#[allow(non_snake_case)]
81-
/// TODO
81+
/// Convience function to allow construction of color options implicitly from a wide range of inputs.
82+
///
83+
/// Currently these are:
84+
/// * `String` or `&str` - produces a [ColorType::RGBString]
85+
/// * `(u8, u8, u8)` - produces a [ColorType::RGBInteger]
86+
/// * `(u8, u8, u8, u8)` - produces a [ColorType::ARGBInteger]
87+
/// * `Vec<((u8, u8, u8))>` or `Vec<(u8, u8, u8, u8)>` - produces a
88+
/// [ColorType::VariableRGBInteger] or [ColorType::VariableARGBInteger] respectively
89+
/// * `u8` or `Vec<u8>` produces a [ColorType::Index] or [ColorType::VariableIndex] respectively
90+
///
91+
/// See `examples/color.rs` for usage of this function
8292
pub fn Color<'l, T: IntoColor<&'l str>>(c: T) -> PlotOption<&'l str>
8393
{
8494
ColorOpt(c.into())
8595
}
8696

8797
#[allow(non_snake_case)]
98+
/// Convience function to allow construction of border color options implicitly from a wide range of inputs.
99+
/// Format and possible inputs are the same as [Color]
88100
pub fn BorderColor<'l, T: IntoColor<&'l str>>(c: T) -> PlotOption<&'l str>
89101
{
90102
BorderColorOpt(c.into())
@@ -289,7 +301,8 @@ impl<'l> OneWayOwned for LabelOption<&'l str>
289301
}
290302

291303
#[allow(non_snake_case)]
292-
/// TODO
304+
/// Convience function to allow construction of text color options implicitly from a wide range of inputs.
305+
/// Format and possible inputs are the same as [Color]
293306
pub fn TextColor<'l, T: IntoColor<&'l str>>(c: T) -> LabelOption<&'l str>
294307
{
295308
TextColorOpt(c.into())

0 commit comments

Comments
 (0)