Skip to content

Commit 7aa5bb2

Browse files
committed
fix: Scale improvements
- Categorical Scales now maintain their order, - Fixed some outdated documentation
1 parent d317501 commit 7aa5bb2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/models/common.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<X, Y> From<(X, Y)> for Point<X, Y> {
2222
/// Determines how points on the scale are handled
2323
///
2424
///
25-
/// Points on a [`ScaleKind::Text`] are treated categorically with all duplicates removed and in an arbitary order. Points on other [`ScaleKind`] are treated numerically as a range
25+
/// Points on a [`ScaleKind::Categorical`] are treated categorically with all duplicates removed and in an arbitary order. Points on other [`ScaleKind`] are treated numerically as a range
2626
#[derive(Debug, Clone, Copy, PartialEq)]
2727
pub(crate) enum ScaleKind {
2828
Number,
@@ -77,14 +77,20 @@ pub struct Scale {
7777

7878
impl Scale {
7979
/// Returns a new scale of the specified type from the given points.
80-
/// If the scale type specified cannot be created from the points, a [`ScaleKind::Text`] is
80+
/// If the scale type specified cannot be created from the points, a [`ScaleKind::Categorical`] is
8181
/// created instead.
8282
pub(crate) fn new(points: impl IntoIterator<Item = impl Into<Data>>, kind: ScaleKind) -> Self {
8383
let points = points.into_iter().map(Into::into);
8484
match kind {
8585
ScaleKind::Categorical => {
86-
let values = points.collect::<HashSet<Data>>();
87-
let values = values.into_iter().collect::<Vec<Data>>();
86+
let mut values = Vec::default();
87+
88+
for point in points {
89+
if !values.iter().any(|pnt| pnt == &point) {
90+
values.push(point);
91+
}
92+
}
93+
8894
let length = values.len();
8995
let values = ScaleValues::Categorical(values);
9096

0 commit comments

Comments
 (0)