Skip to content

Commit 3d1f213

Browse files
committed
Add TextColor functions
1 parent eca6c4f commit 3d1f213

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

gnuplot/examples/color.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn example(c: Common)
5353
x.clone(),
5454
iter::repeat((n_colors - 1) - i),
5555
iter::repeat(0.4),
56-
iter::repeat(0.2), //x.clone().map(|x| (((3 + x) as f64) / 3.0).rem(0.8)),
56+
iter::repeat(0.2),
5757
&[
5858
Caption(&color_name(&color)),
5959
LineWidth(1.0),
@@ -84,6 +84,12 @@ fn example(c: Common)
8484
],
8585
);
8686

87+
// any of the forms used for Color can also be used with TextColor and BorderColor
88+
ax.set_x_label(
89+
"Labels can be colored using the TextColor function",
90+
&[TextColor((128, 0, 255))],
91+
);
92+
8793
c.show(&mut fg, "rgb_color");
8894
}
8995

gnuplot/examples/multiple_axes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ fn example(c: Common)
2020
[-5.0f32, 0.0, 5.0].iter(),
2121
&[Axes(X1, Y2), Color("red")],
2222
)
23-
.set_y_ticks(Some((Auto, 0)), &[Mirror(false)], &[]) // Make Y1 not mirror.
24-
.set_y2_ticks(Some((Auto, 0)), &[Mirror(false)], &[]) // Make Y2 not mirror, and visible.
25-
.set_y_label("Blue", &[])
26-
.set_y2_label("Red", &[])
23+
.set_y_ticks(Some((Auto, 0)), &[Mirror(false)], &[TextColor("blue")]) // Make Y1 not mirror.
24+
.set_y2_ticks(Some((Auto, 0)), &[Mirror(false)], &[TextColor("red")]) // Make Y2 not mirror, and visible.
25+
.set_y_label("Blue", &[TextColor("blue")])
26+
.set_y2_label("Red", &[TextColor("red")])
2727
.label("Blue Label", Axis(1.), Axis(0.), &[TextColor("blue"), TextAlign(AlignRight)])
2828
.label("Red Label", Axis(2.0), Axis2(2.5), &[TextColor("red")]);
2929

gnuplot/src/axes2d.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ impl LegendData
102102
}
103103
}
104104
first_opt! {self.text_options,
105-
TextColor(ref s) =>
105+
TextColorOpt(ref s) =>
106106
{
107-
w.write_str(" textcolor rgb \"");
108-
w.write_str(&escape(s));
109-
w.write_str("\"");
107+
write!(w, " textcolor {} ", s.command());
110108
}
111109
}
112110
first_opt! {self.text_options,

gnuplot/src/axes_common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ pub fn write_out_label_options(
455455
}
456456

457457
first_opt! {options,
458-
TextColor(ref s) =>
458+
TextColorOpt(ref s) =>
459459
{
460-
write!(w, r#" tc rgb "{}""#, s);
460+
write!(w, r#" tc {}"#, s.command());
461461
}
462462
}
463463

gnuplot/src/options.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub enum LabelOption<T>
240240
Font(T, f64),
241241
/// Sets the color of the label text. The passed string can be a color name
242242
/// (e.g. "black" works), or an HTML color specifier (e.g. "#FFFFFF" is white)
243-
TextColor(T),
243+
TextColorOpt(ColorType<T>),
244244
/// Rotates the label by a certain number of degrees
245245
Rotate(f64),
246246
/// Sets the horizontal alignment of the label text (default is left alignment). See AlignType.
@@ -278,7 +278,7 @@ impl<'l> OneWayOwned for LabelOption<&'l str>
278278
{
279279
TextOffset(v1, v2) => TextOffset(v1, v2),
280280
Font(v1, v2) => Font(v1.into(), v2),
281-
TextColor(v) => TextColor(v.into()),
281+
TextColorOpt(v) => TextColorOpt(v.to_one_way_owned()),
282282
Rotate(v) => Rotate(v),
283283
TextAlign(v) => TextAlign(v),
284284
MarkerSymbol(v) => MarkerSymbol(v),
@@ -288,6 +288,13 @@ impl<'l> OneWayOwned for LabelOption<&'l str>
288288
}
289289
}
290290

291+
#[allow(non_snake_case)]
292+
/// TODO
293+
pub fn TextColor<'l, T: IntoColor<&'l str>>(c: T) -> LabelOption<&'l str>
294+
{
295+
TextColorOpt(c.into())
296+
}
297+
291298
/// An enumeration of axis tick options
292299
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
293300
pub enum TickOption<T>

0 commit comments

Comments
 (0)