Skip to content

Commit aa5b9fb

Browse files
committed
Make LogRange deprecated
1 parent fed49e0 commit aa5b9fb

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

examples/two-scales.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1111
.right_y_label_area_size(40)
1212
.margin(5)
1313
.caption("Dual Y-Axis Example", ("sans-serif", 50.0).into_font())
14-
.build_cartesian_2d(0f32..10f32, LogRange(0.1f32..1e10f32))?
14+
.build_cartesian_2d(0f32..10f32, (0.1f32..1e10f32).log_scale())?
1515
.set_secondary_coord(0f32..10f32, -1.0f32..1.0f32);
1616

1717
chart

src/coord/ranged1d/combinators/logarithmic.rs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::marker::PhantomData;
44
use std::ops::Range;
55

66
/// 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).
88
pub trait LogScalable: Clone {
99
/// Make the conversion from the type to the floating point number
1010
fn as_f64(&self) -> f64;
@@ -47,11 +47,20 @@ impl_log_scalable!(i, u16);
4747
impl_log_scalable!(i, u32);
4848
impl_log_scalable!(i, u64);
4949

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+
5055
impl_log_scalable!(f, f32);
5156
impl_log_scalable!(f, f64);
5257

58+
/// Convert a range to a log scale coordinate spec
5359
pub trait IntoLogRange {
60+
/// The type of the value
5461
type ValueType: LogScalable;
62+
63+
/// Make the log scale coordinate
5564
fn log_scale(self) -> LogRangeExt<Self::ValueType>;
5665
}
5766

@@ -68,9 +77,6 @@ impl<T: LogScalable> IntoLogRange for Range<T> {
6877

6978
/// The logarithmic coodinate decorator.
7079
/// This decorator is used to make the axis rendered as logarithmically.
71-
#[derive(Clone)]
72-
pub struct LogRange<V: LogScalable>(pub Range<V>);
73-
7480
#[derive(Clone)]
7581
pub struct LogRangeExt<V: LogScalable> {
7682
range: Range<V>,
@@ -79,6 +85,8 @@ pub struct LogRangeExt<V: LogScalable> {
7985
}
8086

8187
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
8290
pub fn zero_point(mut self, value: V) -> Self
8391
where
8492
V: PartialEq,
@@ -92,6 +100,7 @@ impl<V: LogScalable> LogRangeExt<V> {
92100
self
93101
}
94102

103+
/// Set the base multipler
95104
pub fn base(mut self, base: f64) -> Self {
96105
if self.base > 1.0 {
97106
self.base = base;
@@ -100,12 +109,6 @@ impl<V: LogScalable> LogRangeExt<V> {
100109
}
101110
}
102111

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-
109112
impl<V: LogScalable> From<LogRangeExt<V>> for LogCoord<V> {
110113
fn from(spec: LogRangeExt<V>) -> LogCoord<V> {
111114
let zero_point = spec.zero;
@@ -140,11 +143,6 @@ impl<V: LogScalable> From<LogRangeExt<V>> for LogCoord<V> {
140143
}
141144
}
142145

143-
impl<V: LogScalable> AsRangedCoord for LogRange<V> {
144-
type CoordDescType = LogCoord<V>;
145-
type Value = V;
146-
}
147-
148146
impl<V: LogScalable> AsRangedCoord for LogRangeExt<V> {
149147
type CoordDescType = LogCoord<V>;
150148
type Value = V;
@@ -201,8 +199,6 @@ impl<V: LogScalable> Ranged for LogCoord<V> {
201199
let base = self.base;
202200
let base_ln = base.ln();
203201

204-
/*let mut start = self.//self.value_to_f64(&self.logic.start);
205-
let mut end = self.value_to_f64(&self.logic.end);*/
206202
let Range { mut start, mut end } = self.normalized;
207203

208204
if start > end {
@@ -257,6 +253,26 @@ impl<V: LogScalable> Ranged for LogCoord<V> {
257253
self.logic.clone()
258254
}
259255
}
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+
260276
#[cfg(test)]
261277
mod test {
262278
use super::*;

src/coord/ranged1d/combinators/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ mod linspace;
88
pub use linspace::{IntoLinspace, Linspace};
99

1010
mod logarithmic;
11-
pub use logarithmic::{IntoLogRange, LogCoord, LogRange, LogScalable};
11+
pub use logarithmic::{IntoLogRange, LogCoord, LogScalable};
12+
13+
#[allow(deprecated)]
14+
pub use logarithmic::LogRange;
1215

1316
mod nested;
1417
pub use nested::{BuildNestedCoord, NestedRange, NestedValue};

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,16 @@ pub mod prelude {
751751
cartesian::Cartesian2d,
752752
combinators::{
753753
make_partial_axis, BindKeyPointMethod, BindKeyPoints, BuildNestedCoord, GroupBy,
754-
IntoLinspace, IntoLogRange, IntoPartialAxis, Linspace, LogCoord, LogRange, LogScalable,
754+
IntoLinspace, IntoLogRange, IntoPartialAxis, Linspace, LogCoord, LogScalable,
755755
NestedRange, NestedValue, ToGroupByRange,
756756
},
757757
ranged1d::{DiscreteRanged, IntoSegmentedCoord, Ranged, SegmentValue},
758758
CoordTranslate,
759759
};
760760

761+
#[allow(deprecated)]
762+
pub use crate::coord::combinators::LogRange;
763+
761764
#[cfg(feature = "chrono")]
762765
pub use crate::coord::types::{
763766
IntoMonthly, IntoYearly, RangedDate, RangedDateTime, RangedDuration,

0 commit comments

Comments
 (0)