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

Commit

Permalink
fix(lib): enums are now namespaced + refactor
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
Jorge Aparicio committed Nov 19, 2014
1 parent 8d6f127 commit 4253d31
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 446 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ authors = ["Jorge Aparicio <japaric@linux.com>"]

[dev-dependencies.complex]
git = "https://github.com/japaric/complex.rs"

[dev-dependencies.space]
git = "https://github.com/japaric/space.rs"
46 changes: 10 additions & 36 deletions src/axis.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
use std::collections::TreeMap;
use std::str::MaybeOwned;

use {Data, Script, grid};
use display::Display;
use {Axis, Data, Default, Display, Grid, Scale, Script, grid};

#[deriving(Clone)]
pub struct Properties {
grids: TreeMap<grid::Grid, grid::Properties>,
grids: TreeMap<Grid, grid::Properties>,
hidden: bool,
label: Option<MaybeOwned<'static>>,
logarithmic: bool,
range: Option<(f64, f64)>,
tics: Option<String>,
}

impl Properties {
// NB I dislike the visibility rules within the same crate
#[doc(hidden)]
pub fn _new() -> Properties {
impl Default for Properties {
fn default() -> Properties {
Properties {
grids: TreeMap::new(),
hidden: false,
Expand All @@ -27,7 +24,9 @@ impl Properties {
tics: None,
}
}
}

impl Properties {
/// Autoscales the range of the axis to show all the plot elements
///
/// **Note** All axes are auto-scaled by default
Expand All @@ -39,13 +38,13 @@ impl Properties {
/// Configures the gridlines
pub fn grid(
&mut self,
which: grid::Grid,
which: Grid,
configure: for<'a> |&'a mut grid::Properties| -> &'a mut grid::Properties,
) -> &mut Properties {
if self.grids.contains_key(&which) {
configure(self.grids.get_mut(&which).unwrap());
} else {
let mut properties = grid::Properties::_new();
let mut properties = Default::default();
configure(&mut properties);
self.grids.insert(which, properties);
}
Expand Down Expand Up @@ -79,8 +78,8 @@ impl Properties {
pub fn scale(&mut self, scale: Scale) -> &mut Properties {
self.hidden = false;
match scale {
Linear => self.logarithmic = false,
Logarithmic => self.logarithmic = true,
Scale::Linear => self.logarithmic = false,
Scale::Logarithmic => self.logarithmic = true,
}
self
}
Expand Down Expand Up @@ -148,28 +147,3 @@ impl<'a, 'b> Script for (&'a Axis, &'b Properties) {
script
}
}

#[deriving(Clone, Eq, Ord, PartialEq, PartialOrd)]
pub enum Axis {
BottomX,
LeftY,
RightY,
TopX,
}

#[doc(hidden)]
impl Display<&'static str> for Axis {
fn display(&self) -> &'static str {
match *self {
BottomX => "x",
LeftY => "y",
RightY => "y2",
TopX => "x2",
}
}
}

pub enum Scale {
Linear,
Logarithmic,
}
13 changes: 6 additions & 7 deletions src/candlestick.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::str::MaybeOwned;

use color::Color;
use display::Display;
use {LineType, Script, Solid};
use {Color, Default, Display, LineType, Script};

pub struct Properties {
color: Option<Color>,
Expand All @@ -11,17 +9,18 @@ pub struct Properties {
linewidth: Option<f64>,
}

impl Properties {
#[doc(hidden)]
pub fn _new() -> Properties {
impl Default for Properties {
fn default() -> Properties {
Properties {
color: None,
label: None,
line_type: Solid,
line_type: LineType::Solid,
linewidth: None,
}
}
}

impl Properties {
/// Sets the line color
pub fn color(&mut self, color: Color) -> &mut Properties {
self.color = Some(color);
Expand Down
39 changes: 0 additions & 39 deletions src/color.rs

This file was deleted.

30 changes: 6 additions & 24 deletions src/curve.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::str::MaybeOwned;

use Script;
use color::Color;
use display::Display;
use {Axes, LineType, PointType, Solid};
use {Axes, Color, CurveDefault, Display, LineType, PointType, Script};

pub struct Properties {
axes: Option<Axes>,
Expand All @@ -16,22 +13,22 @@ pub struct Properties {
style: Style,
}

impl Properties {
// NB I dislike the visibility rules within the same crate
#[doc(hidden)]
pub fn _new(style: Style) -> Properties {
impl CurveDefault for Properties {
fn default(style: Style) -> Properties {
Properties {
axes: None,
color: None,
label: None,
line_type: Solid,
line_type: LineType::Solid,
linewidth: None,
point_size: None,
point_type: None,
style: style,
}
}
}

impl Properties {
/// Select the axes to plot against
///
/// **Note** By default, the `BottomXLeftY` axes are used
Expand Down Expand Up @@ -91,7 +88,6 @@ impl Properties {
}
}

#[doc(hidden)]
impl Script for Properties {
fn script(&self) -> String {
let mut script = if let Some(axes) = self.axes {
Expand Down Expand Up @@ -139,17 +135,3 @@ pub enum Style {
Points,
Steps,
}

#[doc(hidden)]
impl Display<&'static str> for Style {
fn display(&self) -> &'static str {
match *self {
Dots => "dots",
Impulses => "impulses",
Lines => "lines",
LinesPoints => "linespoints",
Points => "points",
Steps => "steps",
}
}
}
Loading

0 comments on commit 4253d31

Please sign in to comment.