@@ -4,7 +4,7 @@ use std::marker::PhantomData;
4
4
use std:: ops:: Range ;
5
5
6
6
/// The trait for the type that is able to be presented in the log scale.
7
- /// This trait is primarily used by [LogRange ](struct.LogRange .html).
7
+ /// This trait is primarily used by [LogRangeExt ](struct.LogRangeExt .html).
8
8
pub trait LogScalable : Clone {
9
9
/// Make the conversion from the type to the floating point number
10
10
fn as_f64 ( & self ) -> f64 ;
@@ -47,11 +47,20 @@ impl_log_scalable!(i, u16);
47
47
impl_log_scalable ! ( i, u32 ) ;
48
48
impl_log_scalable ! ( i, u64 ) ;
49
49
50
+ impl_log_scalable ! ( i, i8 ) ;
51
+ impl_log_scalable ! ( i, i16 ) ;
52
+ impl_log_scalable ! ( i, i32 ) ;
53
+ impl_log_scalable ! ( i, i64 ) ;
54
+
50
55
impl_log_scalable ! ( f, f32 ) ;
51
56
impl_log_scalable ! ( f, f64 ) ;
52
57
58
+ /// Convert a range to a log scale coordinate spec
53
59
pub trait IntoLogRange {
60
+ /// The type of the value
54
61
type ValueType : LogScalable ;
62
+
63
+ /// Make the log scale coordinate
55
64
fn log_scale ( self ) -> LogRangeExt < Self :: ValueType > ;
56
65
}
57
66
@@ -68,9 +77,6 @@ impl<T: LogScalable> IntoLogRange for Range<T> {
68
77
69
78
/// The logarithmic coodinate decorator.
70
79
/// This decorator is used to make the axis rendered as logarithmically.
71
- #[ derive( Clone ) ]
72
- pub struct LogRange < V : LogScalable > ( pub Range < V > ) ;
73
-
74
80
#[ derive( Clone ) ]
75
81
pub struct LogRangeExt < V : LogScalable > {
76
82
range : Range < V > ,
@@ -79,6 +85,8 @@ pub struct LogRangeExt<V: LogScalable> {
79
85
}
80
86
81
87
impl < V : LogScalable > LogRangeExt < V > {
88
+ /// Set the zero point of the log scale coordinate. Zero point is the point where we map -inf
89
+ /// of the axis to the coordinate
82
90
pub fn zero_point ( mut self , value : V ) -> Self
83
91
where
84
92
V : PartialEq ,
@@ -92,6 +100,7 @@ impl<V: LogScalable> LogRangeExt<V> {
92
100
self
93
101
}
94
102
103
+ /// Set the base multipler
95
104
pub fn base ( mut self , base : f64 ) -> Self {
96
105
if self . base > 1.0 {
97
106
self . base = base;
@@ -100,12 +109,6 @@ impl<V: LogScalable> LogRangeExt<V> {
100
109
}
101
110
}
102
111
103
- impl < V : LogScalable > From < LogRange < V > > for LogCoord < V > {
104
- fn from ( range : LogRange < V > ) -> LogCoord < V > {
105
- range. 0 . log_scale ( ) . into ( )
106
- }
107
- }
108
-
109
112
impl < V : LogScalable > From < LogRangeExt < V > > for LogCoord < V > {
110
113
fn from ( spec : LogRangeExt < V > ) -> LogCoord < V > {
111
114
let zero_point = spec. zero ;
@@ -140,11 +143,6 @@ impl<V: LogScalable> From<LogRangeExt<V>> for LogCoord<V> {
140
143
}
141
144
}
142
145
143
- impl < V : LogScalable > AsRangedCoord for LogRange < V > {
144
- type CoordDescType = LogCoord < V > ;
145
- type Value = V ;
146
- }
147
-
148
146
impl < V : LogScalable > AsRangedCoord for LogRangeExt < V > {
149
147
type CoordDescType = LogCoord < V > ;
150
148
type Value = V ;
@@ -201,8 +199,6 @@ impl<V: LogScalable> Ranged for LogCoord<V> {
201
199
let base = self . base ;
202
200
let base_ln = base. ln ( ) ;
203
201
204
- /*let mut start = self.//self.value_to_f64(&self.logic.start);
205
- let mut end = self.value_to_f64(&self.logic.end);*/
206
202
let Range { mut start, mut end } = self . normalized ;
207
203
208
204
if start > end {
@@ -257,6 +253,26 @@ impl<V: LogScalable> Ranged for LogCoord<V> {
257
253
self . logic . clone ( )
258
254
}
259
255
}
256
+
257
+ /// The logarithmic coodinate decorator.
258
+ /// This decorator is used to make the axis rendered as logarithmically.
259
+ #[ deprecated( note = "LogRange is deprecated, use IntoLogRange trait method instead" ) ]
260
+ #[ derive( Clone ) ]
261
+ pub struct LogRange < V : LogScalable > ( pub Range < V > ) ;
262
+
263
+ #[ allow( deprecated) ]
264
+ impl < V : LogScalable > AsRangedCoord for LogRange < V > {
265
+ type CoordDescType = LogCoord < V > ;
266
+ type Value = V ;
267
+ }
268
+
269
+ #[ allow( deprecated) ]
270
+ impl < V : LogScalable > From < LogRange < V > > for LogCoord < V > {
271
+ fn from ( range : LogRange < V > ) -> LogCoord < V > {
272
+ range. 0 . log_scale ( ) . into ( )
273
+ }
274
+ }
275
+
260
276
#[ cfg( test) ]
261
277
mod test {
262
278
use super :: * ;
0 commit comments