Trait that abstracts from rectangular 'Value'-like elements, such as bars or boxes
| 6 | /// Trait that abstracts from rectangular 'Value'-like elements, such as bars or |
| 7 | /// boxes |
| 8 | pub(super) trait RectElement { |
| 9 | fn name(&self) -> &str; |
| 10 | |
| 11 | fn bounds_min(&self) -> PlotPoint; |
| 12 | |
| 13 | fn bounds_max(&self) -> PlotPoint; |
| 14 | |
| 15 | fn bounds(&self) -> PlotBounds { |
| 16 | let mut bounds = PlotBounds::NOTHING; |
| 17 | bounds.extend_with(&self.bounds_min()); |
| 18 | bounds.extend_with(&self.bounds_max()); |
| 19 | bounds |
| 20 | } |
| 21 | |
| 22 | /// At which argument (input; usually X) there is a ruler (usually vertical) |
| 23 | fn arguments_with_ruler(&self) -> Vec<PlotPoint> { |
| 24 | // Default: one at center |
| 25 | vec![self.bounds().center()] |
| 26 | } |
| 27 | |
| 28 | /// At which value (output; usually Y) there is a ruler (usually horizontal) |
| 29 | fn values_with_ruler(&self) -> Vec<PlotPoint>; |
| 30 | |
| 31 | /// The diagram's orientation (vertical/horizontal) |
| 32 | fn orientation(&self) -> Orientation; |
| 33 | |
| 34 | /// Get X/Y-value for (argument, value) pair, taking into account |
| 35 | /// orientation |
| 36 | fn point_at(&self, argument: f64, value: f64) -> PlotPoint { |
| 37 | match self.orientation() { |
| 38 | Orientation::Horizontal => PlotPoint::new(value, argument), |
| 39 | Orientation::Vertical => PlotPoint::new(argument, value), |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /// Right top of the rectangle (position of text) |
| 44 | fn corner_value(&self) -> PlotPoint { |
| 45 | PlotPoint { |
| 46 | x: self.bounds_max().x, |
| 47 | y: self.bounds_max().y, |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /// Debug formatting for hovered-over value, if none is specified by the |
| 52 | /// user |
| 53 | fn default_values_format(&self, transform: &PlotTransform) -> String; |
| 54 | } |
| 55 | |
| 56 | // ---------------------------------------------------------------------------- |
| 57 | // Helper functions |
no outgoing calls
no test coverage detected