#[derive(Clone, Debug)]
pub struct DataValue {
/// Optional index.
- ///
- /// This is always `None` as initially decoded.
- pub index: Option<f64>,
+ pub index: Option<usize>,
/// Data value.
pub value: Datum<String>,
/// there is one, falling back to the index.
pub fn category(&self) -> Option<usize> {
self.index
- .and_then(|v| (v >= 0.0 && v < usize::MAX as f64).then_some(v as usize))
}
/// Interprets this data value as a [Format], first by looking it up in
values
.iter()
.map(|value| DataValue {
- index: value.as_number().flatten(),
+ index: value
+ .as_number()
+ .flatten()
+ .and_then(|v| (v >= 0.0 && v < usize::MAX as f64).then_some(v as usize)),
value: value.clone(),
})
.collect()
if let Some(n_values) = series_len(series) {
(0..n_values)
.map(|_| DataValue {
- index: Some(0.0),
+ index: Some(0),
value: Datum::Number(Some(0.0)),
})
.collect()
});
vec![]
};
- for datum in &mut values {
- if let Datum::Number(Some(number)) = &datum.value {
- datum.index = Some(*number);
- }
- }
Map::from_vmes(&self.value_map).apply(&mut values);
if let Some(format) = &self.format {
Map::from_format(format).apply(&mut values);