1use plotters_backend::BackendCoord;
2use std::ops::Deref;
3
4/// The trait that translates some customized object to the backend coordinate
5pub trait CoordTranslate {
6 /// Specifies the object to be translated from
7 type From;
8
9 /// Translate the guest coordinate to the guest coordinate
10 fn translate(&self, from: &Self::From) -> BackendCoord;
11
12 /// Get the Z-value of current coordinate
13 fn depth(&self, _from: &Self::From) -> i32 {
14 0
15 }
16}
17
18impl<C, T> CoordTranslate for T
19where
20 C: CoordTranslate,
21 T: Deref<Target = C>,
22{
23 type From = C::From;
24 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
32pub 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
37 fn reverse_translate(&self, input: BackendCoord) -> Option<Self::From>;
38}
39