1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use super::{category::Value, Axis, Category, SingleValueBinInterval};
use std::fmt::{Debug, Display};
#[derive(Clone, PartialEq, Debug)]
pub struct CategoryNoFlow<T>
where
T: Value,
{
axis: Category<T>,
}
impl<T: Value> CategoryNoFlow<T> {
pub fn new<I: IntoIterator<Item = T>>(values: I) -> Self {
Self {
axis: Category::new(values),
}
}
}
impl<T: Value> Axis for CategoryNoFlow<T> {
type Coordinate = T;
type BinInterval = SingleValueBinInterval<T>;
fn index(&self, coordinate: &Self::Coordinate) -> Option<usize> {
let index = self.axis.index(coordinate)?;
if index == self.axis.numbins() - 1 {
return None;
}
Some(index)
}
fn numbins(&self) -> usize {
self.axis.numbins() - 1
}
fn bin(&self, index: usize) -> Option<Self::BinInterval> {
let bin = self.axis.bin(index)?;
match bin {
SingleValueBinInterval::Overflow => None,
SingleValueBinInterval::Bin { value: _ } => Some(bin),
}
}
}
impl<'a, T: Value> IntoIterator for &'a CategoryNoFlow<T> {
type Item = (usize, <Category<T> as Axis>::BinInterval);
type IntoIter = Box<dyn Iterator<Item = Self::Item> + 'a>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl<T: Display + Value> Display for CategoryNoFlow<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.axis)
}
}