• 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     /// Specifies the object to be translated from
7     type From;
8 
9     /// Translate the guest coordinate to the guest coordinate
translate(&self, from: &Self::From) -> BackendCoord10     fn translate(&self, from: &Self::From) -> BackendCoord;
11 
12     /// Get the Z-value of current coordinate
depth(&self, _from: &Self::From) -> i3213     fn depth(&self, _from: &Self::From) -> i32 {
14         0
15     }
16 }
17 
18 impl<C, T> CoordTranslate for T
19 where
20     C: CoordTranslate,
21     T: Deref<Target = C>,
22 {
23     type From = C::From;
translate(&self, from: &Self::From) -> BackendCoord24     fn translate(&self, from: &Self::From) -> BackendCoord {
25         self.deref().translate(from)
26     }
27 }
28 
29 /// The trait indicates that the coordinate system supports reverse transform
30 /// This is useful when we need an interactive plot, thus we need to map the event
31 /// from the backend coordinate to the logical coordinate
32 pub trait ReverseCoordTranslate: CoordTranslate {
33     /// Reverse translate the coordinate from the drawing coordinate to the
34     /// logic coordinate.
35     /// Note: the return value is an option, because it's possible that the drawing
36     /// coordinate isn't able to be represented in te guest coordinate system
reverse_translate(&self, input: BackendCoord) -> Option<Self::From>37     fn reverse_translate(&self, input: BackendCoord) -> Option<Self::From>;
38 }
39