Skip to content

Commit d407f42

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

20 files changed

+149
-136
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: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,34 @@ 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+
&[
73+
Caption("(x - 4)^2 - 5"),
74+
LineWidth(1.5),
75+
Color("black".into()),
76+
],
7377
)
7478
.y_error_lines(
7579
x,
7680
y2,
7781
repeat(1.0f32),
78-
&[Caption("-(x - 4)^2 + 5"), LineWidth(1.5), Color("red")],
82+
&[
83+
Caption("-(x - 4)^2 + 5"),
84+
LineWidth(1.5),
85+
Color("red".into()),
86+
],
7987
)
8088
.lines_points(
8189
x,
@@ -85,7 +93,7 @@ fn example(c: Common)
8593
PointSymbol('t'),
8694
LineWidth(1.5),
8795
LineStyle(Dash),
88-
Color("#11ff11"),
96+
Color("#11ff11".into()),
8997
],
9098
);
9199

@@ -95,7 +103,11 @@ fn example(c: Common)
95103

96104
fg.axes2d()
97105
.set_pos_grid(2, 2, 0)
98-
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet")])
106+
.lines(
107+
x,
108+
y1,
109+
&[Caption("Lines"), LineWidth(3.0), Color("violet".into())],
110+
)
99111
.set_title("Plot1 fg1.2", &[]);
100112

101113
fg.axes2d()
@@ -106,7 +118,7 @@ fn example(c: Common)
106118
&[
107119
Caption("Points"),
108120
PointSymbol('D'),
109-
Color("#ffaa77"),
121+
Color("#ffaa77".into()),
110122
PointSize(2.0),
111123
],
112124
)
@@ -116,8 +128,11 @@ fn example(c: Common)
116128

117129
let mut fg = Figure::new();
118130

119-
fg.axes2d()
120-
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet")]);
131+
fg.axes2d().lines(
132+
x,
133+
y1,
134+
&[Caption("Lines"), LineWidth(3.0), Color("violet".into())],
135+
);
121136

122137
fg.axes2d()
123138
.set_pos(0.2, 0.4)
@@ -126,7 +141,7 @@ fn example(c: Common)
126141
.points(
127142
x,
128143
y2,
129-
&[Caption("Points"), PointSymbol('T'), Color("#ffaa77")],
144+
&[Caption("Points"), PointSymbol('T'), Color("#ffaa77".into())],
130145
)
131146
.set_title("Inset fg1.3", &[]);
132147

@@ -135,7 +150,11 @@ fn example(c: Common)
135150
let mut fg = Figure::new();
136151

137152
fg.axes2d()
138-
.lines(x, y1, &[Caption("Lines"), LineWidth(3.0), Color("violet")])
153+
.lines(
154+
x,
155+
y1,
156+
&[Caption("Lines"), LineWidth(3.0), Color("violet".into())],
157+
)
139158
.set_y_range(Fix(-30.0), Auto)
140159
.set_y_label("This axis is manually scaled on the low end", &[])
141160
.set_title("Range fg1.4", &[]);
@@ -153,7 +172,7 @@ fn example(c: Common)
153172
Caption(r"x\_error\_lines"),
154173
LineWidth(2.0),
155174
PointSymbol('O'),
156-
Color("red"),
175+
Color("red".into()),
157176
],
158177
)
159178
.y_error_lines(
@@ -164,20 +183,28 @@ fn example(c: Common)
164183
Caption(r"y\_error\_lines"),
165184
LineWidth(2.0),
166185
PointSymbol('S'),
167-
Color("blue"),
186+
Color("blue".into()),
168187
],
169188
)
170189
.x_error_bars(
171190
x,
172191
y3,
173192
x_err,
174-
&[Caption(r"x\_error\_bars"), PointSymbol('T'), Color("cyan")],
193+
&[
194+
Caption(r"x\_error\_bars"),
195+
PointSymbol('T'),
196+
Color("cyan".into()),
197+
],
175198
)
176199
.y_error_bars(
177200
x,
178201
y4,
179202
y_err,
180-
&[Caption(r"y\_error\_bars"), PointSymbol('R'), Color("green")],
203+
&[
204+
Caption(r"y\_error\_bars"),
205+
PointSymbol('R'),
206+
Color("green".into()),
207+
],
181208
)
182209
.set_title("Error fg1.5", &[]);
183210

@@ -193,7 +220,7 @@ fn example(c: Common)
193220
y1,
194221
y3,
195222
&[
196-
Color("red"),
223+
Color("red".into()),
197224
FillAlpha(0.5),
198225
FillRegion(Above),
199226
Caption("A > B"),
@@ -204,7 +231,7 @@ fn example(c: Common)
204231
y1,
205232
y3,
206233
&[
207-
Color("green"),
234+
Color("green".into()),
208235
FillAlpha(0.5),
209236
FillRegion(Below),
210237
Caption("A < B"),
@@ -215,7 +242,7 @@ fn example(c: Common)
215242
y2,
216243
y3,
217244
&[
218-
Color("blue"),
245+
Color("blue".into()),
219246
FillAlpha(0.5),
220247
FillRegion(Between),
221248
Caption("Between C and B"),
@@ -225,18 +252,22 @@ fn example(c: Common)
225252
x,
226253
y1,
227254
&[
228-
Color("black"),
255+
Color("black".into()),
229256
LineWidth(2.0),
230257
LineStyle(Dash),
231258
Caption("A"),
232259
],
233260
)
234-
.lines(x, y2, &[Color("black"), LineWidth(2.0), Caption("C")])
261+
.lines(
262+
x,
263+
y2,
264+
&[Color("black".into()), LineWidth(2.0), Caption("C")],
265+
)
235266
.lines(
236267
x,
237268
y3,
238269
&[
239-
Color("black"),
270+
Color("black".into()),
240271
LineWidth(2.0),
241272
LineStyle(DotDotDash),
242273
Caption("B"),
@@ -267,7 +298,7 @@ fn example(c: Common)
267298
&[
268299
Caption("(x - 4)^2 - 5"),
269300
LineWidth(3.0),
270-
Color("violet"),
301+
Color("violet".into()),
271302
LineStyle(DotDash),
272303
],
273304
)
@@ -277,7 +308,7 @@ fn example(c: Common)
277308
&[
278309
Caption("-(x - 4)^2 + 5"),
279310
PointSymbol('S'),
280-
Color("#ffaa77"),
311+
Color("#ffaa77".into()),
281312
],
282313
)
283314
.lines_points(
@@ -286,13 +317,13 @@ fn example(c: Common)
286317
&[
287318
Caption("x - 4"),
288319
PointSymbol('O'),
289-
Color("black"),
320+
Color("black".into()),
290321
LineStyle(SmallDot),
291322
],
292323
)
293324
.set_x_label(
294325
"X Label",
295-
&[Font("Arial", 24.0), TextColor("red"), Rotate(45.0)],
326+
&[Font("Arial", 24.0), TextColor("red".into()), Rotate(45.0)],
296327
)
297328
.set_y_label("Y Label", &[Rotate(0.0)])
298329
.set_title(

0 commit comments

Comments
 (0)