• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use plotters_backend::BackendCoord;
2 use std::ops::Deref;
3 
4 /// The trait that translates some customized object to the backend coordinate
5 pub trait CoordTranslate {
6     type From;
7 
8     /// Translate the guest coordinate to the guest coordinate
translate(&self, from: &Self::From) -> BackendCoord9     fn translate(&self, from: &Self::From) -> BackendCoord;
10 
11     /// Get the Z-value of current coordinate
depth(&self, _from: &Self::From) -> i3212     fn depth(&self, _from: &Self::From) -> i32 {
13         0
14     }
15 }
16 
17 impl<C, T> CoordTranslate for T
18 where
19     C: CoordTranslate,
20     T: Deref<Target = C>,
21 {
22     type From = C::From;
translate(&self, from: &Self::From) -> BackendCoord23     fn translate(&self, from: &Self::From) -> BackendCoord {
24         self.deref().translate(from)
25     }
26 }
27 
28 /// The trait indicates that the coordinate system supports reverse transform
29 /// This is useful when we need an interactive plot, thus we need to map the event
30 /// from the backend coordinate to the logical coordinate
31 pub trait ReverseCoordTranslate: CoordTranslate {
32     /// Reverse translate the coordinate from the drawing coordinate to the
33     /// logic coordinate.
34     /// Note: the return value is an option, because it's possible that the drawing
35     /// coordinate isn't able to be represented in te guest coordinate system
reverse_translate(&self, input: BackendCoord) -> Option<Self::From>36     fn reverse_translate(&self, input: BackendCoord) -> Option<Self::From>;
37 }
38