Skip to content

Commit 1923227

Browse files
committed
Remove (hacky) convenience functions in favour of clear explicit .into() calls
1 parent f2612e9 commit 1923227

20 files changed

+113
-135
lines changed

gnuplot/examples/box_and_whisker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn example(c: Common)
2727
[0.5f32, 0.25, 0.125].iter(),
2828
&[
2929
WhiskerBars(0.5),
30-
Color("blue"),
30+
Color("blue".into()),
3131
LineWidth(2.0),
3232
LineStyle(SmallDot),
3333
FillAlpha(0.5),

gnuplot/examples/box_xy_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn example(c: Common)
2525
[-1.5f32, 4.5, 3.0].iter(),
2626
[0.5f32, 4.75, 0.125].iter(),
2727
&[
28-
Color("blue"),
28+
Color("blue".into()),
2929
LineWidth(2.0),
3030
LineStyle(SmallDot),
3131
FillAlpha(0.5),

gnuplot/examples/color.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod common;
88

99
fn color_name<T: Debug>(color: &PlotOption<T>) -> String
1010
{
11-
let s = format!("{:?}", color).replace("ColorOpt(", "");
11+
let s = format!("{:?}", color).replace("Color(", "");
1212
let mut chars = s.chars();
1313
chars.next_back();
1414
chars.as_str().to_string()
@@ -19,22 +19,22 @@ fn example(c: Common)
1919
let x = 0..5;
2020

2121
let colors = [
22-
Color("black"), // Conversion to RGBString is implicit
23-
Color(ColorType::RGBString("black")), // Explicit use of RGBString
24-
Color("red"), // Conversion to RGBString is implicit
25-
Color(RGBString("#ff0000")), // red using Hex coded RRGGBB
26-
Color(RGBString("#00ff0000")), // red using Hex coded AARRGGBB
27-
Color("#ff8888"), // pink using Hex coded RRGGBB. Conversion to RGBString is implict
28-
Color("#88ff0000"), // pink using Hex coded AARRGGBB. Conversion to RGBString is implict
22+
Color("black".into()), // Conversion to RGBString is implicit
23+
Color(ColorType::RGBString("black")), // Explicit use of RGBString
24+
Color("red".into()), // Conversion to RGBString is implicit
25+
Color(RGBString("#ff0000")), // red using Hex coded RRGGBB
26+
Color(RGBString("#00ff0000")), // red using Hex coded AARRGGBB
27+
Color("#ff8888".into()), // pink using Hex coded RRGGBB. Conversion to RGBString is implict
28+
Color("#88ff0000".into()), // pink using Hex coded AARRGGBB. Conversion to RGBString is implict
2929
Color(ColorType::RGBString("#ffff0000")), // transparent using Hex coded AARRGGBB
30-
Color((128, 0, 255)), // purple using implict RGBInteger
30+
Color((128, 0, 255).into()), // purple using implict RGBInteger
3131
Color(RGBInteger(128, 0, 255)), // purple using explict RGBInteger
32-
Color((0.5, 0.0, 1.0)), // purple using implict float to int conversion
33-
Color(floats_to_rgb(0.5, 0.0, 1.0)), // purple using explicit float to int conversion
34-
Color((128, 128, 0, 255)), // pale purple using implict ARGBInteger
32+
Color((0.5, 0.0, 1.0).into()), // purple using implict float to int conversion
33+
Color(floats_to_rgb(0.5, 0.0, 1.0).into()), // purple using explicit float to int conversion
34+
Color((128, 128, 0, 255).into()), // pale purple using implict ARGBInteger
3535
Color(ARGBInteger(128, 128, 0, 255)), // pale purple using explict ARGBInteger
36-
Color((0.5, 0.5, 0.0, 1.0)), // pale purple using implict float to int conversion
37-
Color(floats_to_argb(0.5, 0.5, 0.0, 1.0)), // pale purple using explicit float to int conversion
36+
Color((0.5, 0.5, 0.0, 1.0).into()), // pale purple using implict float to int conversion
37+
Color(floats_to_argb(0.5, 0.5, 0.0, 1.0).into()), // pale purple using explicit float to int conversion
3838
];
3939

4040
let mut fg = Figure::new();
@@ -57,7 +57,7 @@ fn example(c: Common)
5757
&[
5858
Caption(&color_name(&color)),
5959
LineWidth(1.0),
60-
BorderColor("black"),
60+
BorderColor("black".into()),
6161
color,
6262
],
6363
);
@@ -70,7 +70,7 @@ fn example(c: Common)
7070
&[
7171
LineWidth(7.0),
7272
Color(Black),
73-
Caption(&color_name(&Color(Black))),
73+
Caption(&color_name::<String>(&Color(Black))),
7474
],
7575
);
7676

@@ -80,14 +80,14 @@ fn example(c: Common)
8080
&[
8181
LineWidth(7.0),
8282
Color(Background),
83-
Caption(&color_name(&Color(Background))),
83+
Caption(&color_name::<String>(&Color(Background))),
8484
],
8585
);
8686

8787
// any of the forms used for Color can also be used with TextColor and BorderColor
8888
ax.set_x_label(
8989
"Labels can be colored using the TextColor function",
90-
&[TextColor((128, 0, 255))],
90+
&[TextColor((128, 0, 255).into())],
9191
);
9292

9393
c.show(&mut fg, "rgb_color");
@@ -112,7 +112,7 @@ fn example(c: Common)
112112
&[
113113
Caption(&color_name(&frac_color)),
114114
LineWidth(1.0),
115-
BorderColor("black"),
115+
BorderColor("black".into()),
116116
frac_color,
117117
],
118118
)
@@ -124,7 +124,7 @@ fn example(c: Common)
124124
&[
125125
Caption(&color_name(&cb_range_color)),
126126
LineWidth(1.0),
127-
BorderColor("black"),
127+
BorderColor("black".into()),
128128
cb_range_color,
129129
],
130130
);

gnuplot/examples/dash_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn example(c: Common)
2222
x.clone().map(|v| v * 2 + 2 * i),
2323
&[
2424
LineWidth(2.),
25-
Color("black"),
25+
Color("black".into()),
2626
LineStyle(dt),
2727
Caption(&format!("{:?}", dt)),
2828
],

gnuplot/examples/example1.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,26 @@ fn example(c: Common)
5656
ArrowType(Closed),
5757
ArrowSize(0.1),
5858
LineWidth(2.0),
59-
Color("black"),
59+
Color("black".into()),
6060
],
6161
)
6262
.label("Here", Axis(5.7912), Axis(3.1), &[TextAlign(AlignCenter)])
6363
.fill_between(
6464
x,
6565
y1.map(|&y| y * 0.85 - 1.0),
6666
y1.map(|&y| y * 1.15 + 1.0),
67-
&[Color("#aaaaff")],
67+
&[Color("#aaaaff".into())],
6868
)
6969
.lines(
7070
x,
7171
y1,
72-
&[Caption("(x - 4)^2 - 5"), LineWidth(1.5), Color("black")],
72+
&[Caption("(x - 4)^2 - 5"), LineWidth(1.5), Color("black".into())],
7373
)
7474
.y_error_lines(
7575
x,
7676
y2,
7777
repeat(1.0f32),
78-
&[Caption("-(x - 4)^2 + 5"), LineWidth(1.5), Color("red")],
78+
&[Caption("-(x - 4)^2 + 5"), LineWidth(1.5), Color("red".into())],
7979
)
8080
.lines_points(
8181
x,
@@ -85,7 +85,7 @@ fn example(c: Common)
8585
PointSymbol('t'),
8686
LineWidth(1.5),
8787
LineStyle(Dash),
88-
Color("#11ff11"),
88+
Color("#11ff11".into()),
8989
],
9090
);
9191

@@ -95,7 +95,7 @@ fn example(c: Common)
9595

9696
fg.axes2d()
9797
.set_pos_grid(2, 2, 0)
98-
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet")])
98+
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet".into())])
9999
.set_title("Plot1 fg1.2", &[]);
100100

101101
fg.axes2d()
@@ -106,7 +106,7 @@ fn example(c: Common)
106106
&[
107107
Caption("Points"),
108108
PointSymbol('D'),
109-
Color("#ffaa77"),
109+
Color("#ffaa77".into()),
110110
PointSize(2.0),
111111
],
112112
)
@@ -117,7 +117,7 @@ fn example(c: Common)
117117
let mut fg = Figure::new();
118118

119119
fg.axes2d()
120-
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet")]);
120+
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet".into())]);
121121

122122
fg.axes2d()
123123
.set_pos(0.2, 0.4)
@@ -126,7 +126,7 @@ fn example(c: Common)
126126
.points(
127127
x,
128128
y2,
129-
&[Caption("Points"), PointSymbol('T'), Color("#ffaa77")],
129+
&[Caption("Points"), PointSymbol('T'), Color("#ffaa77".into())],
130130
)
131131
.set_title("Inset fg1.3", &[]);
132132

@@ -135,7 +135,7 @@ fn example(c: Common)
135135
let mut fg = Figure::new();
136136

137137
fg.axes2d()
138-
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet")])
138+
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet".into())])
139139
.set_y_range(Fix(-30.0), Auto)
140140
.set_y_label("This axis is manually scaled on the low end", &[])
141141
.set_title("Range fg1.4", &[]);
@@ -153,7 +153,7 @@ fn example(c: Common)
153153
Caption(r"x\_error\_lines"),
154154
LineWidth(2.0),
155155
PointSymbol('O'),
156-
Color("red"),
156+
Color("red".into()),
157157
],
158158
)
159159
.y_error_lines(
@@ -164,20 +164,20 @@ fn example(c: Common)
164164
Caption(r"y\_error\_lines"),
165165
LineWidth(2.0),
166166
PointSymbol('S'),
167-
Color("blue"),
167+
Color("blue".into()),
168168
],
169169
)
170170
.x_error_bars(
171171
x,
172172
y3,
173173
x_err,
174-
&[Caption(r"x\_error\_bars"), PointSymbol('T'), Color("cyan")],
174+
&[Caption(r"x\_error\_bars"), PointSymbol('T'), Color("cyan".into())],
175175
)
176176
.y_error_bars(
177177
x,
178178
y4,
179179
y_err,
180-
&[Caption(r"y\_error\_bars"), PointSymbol('R'), Color("green")],
180+
&[Caption(r"y\_error\_bars"), PointSymbol('R'), Color("green".into())],
181181
)
182182
.set_title("Error fg1.5", &[]);
183183

@@ -193,7 +193,7 @@ fn example(c: Common)
193193
y1,
194194
y3,
195195
&[
196-
Color("red"),
196+
Color("red".into()),
197197
FillAlpha(0.5),
198198
FillRegion(Above),
199199
Caption("A > B"),
@@ -204,7 +204,7 @@ fn example(c: Common)
204204
y1,
205205
y3,
206206
&[
207-
Color("green"),
207+
Color("green".into()),
208208
FillAlpha(0.5),
209209
FillRegion(Below),
210210
Caption("A < B"),
@@ -215,7 +215,7 @@ fn example(c: Common)
215215
y2,
216216
y3,
217217
&[
218-
Color("blue"),
218+
Color("blue".into()),
219219
FillAlpha(0.5),
220220
FillRegion(Between),
221221
Caption("Between C and B"),
@@ -225,18 +225,18 @@ fn example(c: Common)
225225
x,
226226
y1,
227227
&[
228-
Color("black"),
228+
Color("black".into()),
229229
LineWidth(2.0),
230230
LineStyle(Dash),
231231
Caption("A"),
232232
],
233233
)
234-
.lines(x, y2, &[Color("black"), LineWidth(2.0), Caption("C")])
234+
.lines(x, y2, &[Color("black".into()), LineWidth(2.0), Caption("C")])
235235
.lines(
236236
x,
237237
y3,
238238
&[
239-
Color("black"),
239+
Color("black".into()),
240240
LineWidth(2.0),
241241
LineStyle(DotDotDash),
242242
Caption("B"),
@@ -267,7 +267,7 @@ fn example(c: Common)
267267
&[
268268
Caption("(x - 4)^2 - 5"),
269269
LineWidth(3.0),
270-
Color("violet"),
270+
Color("violet".into()),
271271
LineStyle(DotDash),
272272
],
273273
)
@@ -277,7 +277,7 @@ fn example(c: Common)
277277
&[
278278
Caption("-(x - 4)^2 + 5"),
279279
PointSymbol('S'),
280-
Color("#ffaa77"),
280+
Color("#ffaa77".into()),
281281
],
282282
)
283283
.lines_points(
@@ -286,13 +286,13 @@ fn example(c: Common)
286286
&[
287287
Caption("x - 4"),
288288
PointSymbol('O'),
289-
Color("black"),
289+
Color("black".into()),
290290
LineStyle(SmallDot),
291291
],
292292
)
293293
.set_x_label(
294294
"X Label",
295-
&[Font("Arial", 24.0), TextColor("red"), Rotate(45.0)],
295+
&[Font("Arial", 24.0), TextColor("red".into()), Rotate(45.0)],
296296
)
297297
.set_y_label("Y Label", &[Rotate(0.0)])
298298
.set_title(

0 commit comments

Comments
 (0)