1 /*! 2 3 One of the key features of Plotters is flexible coordinate system abstraction and this module 4 provides all the abstraction used for the coordinate abstarction of Plotters. 5 6 Generally speaking, the coordinate system in Plotters is responsible for mapping logic data points into 7 pixel based backend coordinate. This task is abstracted by a simple trait called 8 [CoordTranslate](trait.CoordTranslate.html). Please note `CoordTranslate` trait doesn't assume any property 9 about the coordinate values, thus we are able to extend Plotters's coordinate system to other types of coorindate 10 easily. 11 12 Another important trait is [ReverseCoordTranslate](trait.ReverseCoordTranslate.html). This trait allows some coordinate 13 retrieve the logic value based on the pixel-based backend coordinate. This is particularly interesting for interactive plots. 14 15 Plotters contains a set of pre-defined coordinate specifications that fulfills the most common use. See documentation for 16 module [types](types/index.html) for details about the basic 1D types. 17 18 The coordinate system also can be tweaked by the coordinate combinators, such as logarithmic coordinate, nested coordinate, etc. 19 See documentation for module [combinators](combinators/index.html) for details. 20 21 Currently we support the following 2D coordinate system: 22 23 - 2-dimensional Cartesian Coordinate: This is done by the combinator [Cartesian2d](cartesian/struct.Cartesian2d.html). 24 25 */ 26 27 use plotters_backend::BackendCoord; 28 29 pub mod ranged1d; 30 31 /// The coordinate combinators 32 /// 33 /// Coordinate combinators are very important part of Plotters' coordinate system. 34 /// The combinator is more about the "combinator pattern", which takes one or more coordinate specification 35 /// and transform them into a new coordinate specification. 36 pub mod combinators { 37 pub use super::ranged1d::combinators::*; 38 } 39 40 /// The primitive types supported by Plotters coordinate system 41 pub mod types { 42 pub use super::ranged1d::types::*; 43 } 44 45 mod ranged2d; 46 pub mod ranged3d; 47 48 pub mod cartesian { 49 pub use super::ranged2d::cartesian::{Cartesian2d, MeshLine}; 50 pub use super::ranged3d::Cartesian3d; 51 } 52 53 mod translate; 54 pub use translate::{CoordTranslate, ReverseCoordTranslate}; 55 56 /// The coordinate translation that only impose shift 57 #[derive(Debug, Clone)] 58 pub struct Shift(pub BackendCoord); 59 60 impl CoordTranslate for Shift { 61 type From = BackendCoord; translate(&self, from: &Self::From) -> BackendCoord62 fn translate(&self, from: &Self::From) -> BackendCoord { 63 (from.0 + (self.0).0, from.1 + (self.0).1) 64 } 65 } 66 67 impl ReverseCoordTranslate for Shift { reverse_translate(&self, input: BackendCoord) -> Option<BackendCoord>68 fn reverse_translate(&self, input: BackendCoord) -> Option<BackendCoord> { 69 Some((input.0 - (self.0).0, input.1 - (self.0).1)) 70 } 71 } 72