Skip to content
This repository was archived by the owner on Dec 9, 2018. It is now read-only.

Commit 4253d31

Browse files
author
Jorge Aparicio
committed
fix(lib): enums are now namespaced + refactor
See rust-lang/rust#18973 - The `linspace` and `logspace` functions have been moved into their own crate - The `color` module has been removed, the `Color` enum is now in the root of the crate - The following enums have been moved into the root of the crate: `Axis`, `Grid` and `Scale` - Renames: - `HorizontalPosition` -> `Horizontal` - `LeftJustified/RightJustified` -> `Justification::{Left, Right}` - `Vertical::Middle` -> `Vertical::Center` - `VerticalPosition` -> `Vertical` [breaking-change]
1 parent 8d6f127 commit 4253d31

11 files changed

+338
-446
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ authors = ["Jorge Aparicio <[email protected]>"]
66

77
[dev-dependencies.complex]
88
git = "https://github.com/japaric/complex.rs"
9+
10+
[dev-dependencies.space]
11+
git = "https://github.com/japaric/space.rs"

src/axis.rs

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
use std::collections::TreeMap;
22
use std::str::MaybeOwned;
33

4-
use {Data, Script, grid};
5-
use display::Display;
4+
use {Axis, Data, Default, Display, Grid, Scale, Script, grid};
65

76
#[deriving(Clone)]
87
pub struct Properties {
9-
grids: TreeMap<grid::Grid, grid::Properties>,
8+
grids: TreeMap<Grid, grid::Properties>,
109
hidden: bool,
1110
label: Option<MaybeOwned<'static>>,
1211
logarithmic: bool,
1312
range: Option<(f64, f64)>,
1413
tics: Option<String>,
1514
}
1615

17-
impl Properties {
18-
// NB I dislike the visibility rules within the same crate
19-
#[doc(hidden)]
20-
pub fn _new() -> Properties {
16+
impl Default for Properties {
17+
fn default() -> Properties {
2118
Properties {
2219
grids: TreeMap::new(),
2320
hidden: false,
@@ -27,7 +24,9 @@ impl Properties {
2724
tics: None,
2825
}
2926
}
27+
}
3028

29+
impl Properties {
3130
/// Autoscales the range of the axis to show all the plot elements
3231
///
3332
/// **Note** All axes are auto-scaled by default
@@ -39,13 +38,13 @@ impl Properties {
3938
/// Configures the gridlines
4039
pub fn grid(
4140
&mut self,
42-
which: grid::Grid,
41+
which: Grid,
4342
configure: for<'a> |&'a mut grid::Properties| -> &'a mut grid::Properties,
4443
) -> &mut Properties {
4544
if self.grids.contains_key(&which) {
4645
configure(self.grids.get_mut(&which).unwrap());
4746
} else {
48-
let mut properties = grid::Properties::_new();
47+
let mut properties = Default::default();
4948
configure(&mut properties);
5049
self.grids.insert(which, properties);
5150
}
@@ -79,8 +78,8 @@ impl Properties {
7978
pub fn scale(&mut self, scale: Scale) -> &mut Properties {
8079
self.hidden = false;
8180
match scale {
82-
Linear => self.logarithmic = false,
83-
Logarithmic => self.logarithmic = true,
81+
Scale::Linear => self.logarithmic = false,
82+
Scale::Logarithmic => self.logarithmic = true,
8483
}
8584
self
8685
}
@@ -148,28 +147,3 @@ impl<'a, 'b> Script for (&'a Axis, &'b Properties) {
148147
script
149148
}
150149
}
151-
152-
#[deriving(Clone, Eq, Ord, PartialEq, PartialOrd)]
153-
pub enum Axis {
154-
BottomX,
155-
LeftY,
156-
RightY,
157-
TopX,
158-
}
159-
160-
#[doc(hidden)]
161-
impl Display<&'static str> for Axis {
162-
fn display(&self) -> &'static str {
163-
match *self {
164-
BottomX => "x",
165-
LeftY => "y",
166-
RightY => "y2",
167-
TopX => "x2",
168-
}
169-
}
170-
}
171-
172-
pub enum Scale {
173-
Linear,
174-
Logarithmic,
175-
}

src/candlestick.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::str::MaybeOwned;
22

3-
use color::Color;
4-
use display::Display;
5-
use {LineType, Script, Solid};
3+
use {Color, Default, Display, LineType, Script};
64

75
pub struct Properties {
86
color: Option<Color>,
@@ -11,17 +9,18 @@ pub struct Properties {
119
linewidth: Option<f64>,
1210
}
1311

14-
impl Properties {
15-
#[doc(hidden)]
16-
pub fn _new() -> Properties {
12+
impl Default for Properties {
13+
fn default() -> Properties {
1714
Properties {
1815
color: None,
1916
label: None,
20-
line_type: Solid,
17+
line_type: LineType::Solid,
2118
linewidth: None,
2219
}
2320
}
21+
}
2422

23+
impl Properties {
2524
/// Sets the line color
2625
pub fn color(&mut self, color: Color) -> &mut Properties {
2726
self.color = Some(color);

src/color.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/curve.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use std::str::MaybeOwned;
22

3-
use Script;
4-
use color::Color;
5-
use display::Display;
6-
use {Axes, LineType, PointType, Solid};
3+
use {Axes, Color, CurveDefault, Display, LineType, PointType, Script};
74

85
pub struct Properties {
96
axes: Option<Axes>,
@@ -16,22 +13,22 @@ pub struct Properties {
1613
style: Style,
1714
}
1815

19-
impl Properties {
20-
// NB I dislike the visibility rules within the same crate
21-
#[doc(hidden)]
22-
pub fn _new(style: Style) -> Properties {
16+
impl CurveDefault for Properties {
17+
fn default(style: Style) -> Properties {
2318
Properties {
2419
axes: None,
2520
color: None,
2621
label: None,
27-
line_type: Solid,
22+
line_type: LineType::Solid,
2823
linewidth: None,
2924
point_size: None,
3025
point_type: None,
3126
style: style,
3227
}
3328
}
29+
}
3430

31+
impl Properties {
3532
/// Select the axes to plot against
3633
///
3734
/// **Note** By default, the `BottomXLeftY` axes are used
@@ -91,7 +88,6 @@ impl Properties {
9188
}
9289
}
9390

94-
#[doc(hidden)]
9591
impl Script for Properties {
9692
fn script(&self) -> String {
9793
let mut script = if let Some(axes) = self.axes {
@@ -139,17 +135,3 @@ pub enum Style {
139135
Points,
140136
Steps,
141137
}
142-
143-
#[doc(hidden)]
144-
impl Display<&'static str> for Style {
145-
fn display(&self) -> &'static str {
146-
match *self {
147-
Dots => "dots",
148-
Impulses => "impulses",
149-
Lines => "lines",
150-
LinesPoints => "linespoints",
151-
Points => "points",
152-
Steps => "steps",
153-
}
154-
}
155-
}

0 commit comments

Comments
 (0)