Struct DrawingArea
pub struct DrawingArea<DB, CT>where
DB: DrawingBackend,
CT: CoordTranslate,{ /* private fields */ }Expand description
The abstraction of a drawing area. Plotters uses drawing area as the fundamental abstraction for the high level drawing API. The major functionality provided by the drawing area is
- Layout specification - Split the parent drawing area into sub-drawing-areas
- Coordinate Translation - Allows guest coordinate system attached and used for drawing.
- Element based drawing - drawing area provides the environment the element can be drawn onto it.
Implementations§
§impl<DB, X, Y> DrawingArea<DB, Cartesian2d<X, Y>>
impl<DB, X, Y> DrawingArea<DB, Cartesian2d<X, Y>>
pub fn draw_mesh<DrawFunc, YH, XH>(
&self,
draw_func: DrawFunc,
y_count_max: YH,
x_count_max: XH,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
YH: KeyPointHint,
XH: KeyPointHint,
DrawFunc: FnMut(&mut DB, MeshLine<'_, X, Y>) -> Result<(), DrawingErrorKind<<DB as DrawingBackend>::ErrorType>>,
pub fn draw_mesh<DrawFunc, YH, XH>(
&self,
draw_func: DrawFunc,
y_count_max: YH,
x_count_max: XH,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
YH: KeyPointHint,
XH: KeyPointHint,
DrawFunc: FnMut(&mut DB, MeshLine<'_, X, Y>) -> Result<(), DrawingErrorKind<<DB as DrawingBackend>::ErrorType>>,
Draw the mesh on a area
pub fn get_x_range(&self) -> Range<<X as Ranged>::ValueType> ⓘ
pub fn get_x_range(&self) -> Range<<X as Ranged>::ValueType> ⓘ
Get the range of X of the guest coordinate for current drawing area
pub fn get_y_range(&self) -> Range<<Y as Ranged>::ValueType> ⓘ
pub fn get_y_range(&self) -> Range<<Y as Ranged>::ValueType> ⓘ
Get the range of Y of the guest coordinate for current drawing area
pub fn get_x_axis_pixel_range(&self) -> Range<i32> ⓘ
pub fn get_x_axis_pixel_range(&self) -> Range<i32> ⓘ
Get the range of X of the backend coordinate for current drawing area
pub fn get_y_axis_pixel_range(&self) -> Range<i32> ⓘ
pub fn get_y_axis_pixel_range(&self) -> Range<i32> ⓘ
Get the range of Y of the backend coordinate for current drawing area
§impl<DB, CT> DrawingArea<DB, CT>where
DB: DrawingBackend,
CT: CoordTranslate,
impl<DB, CT> DrawingArea<DB, CT>where
DB: DrawingBackend,
CT: CoordTranslate,
pub fn get_base_pixel(&self) -> (i32, i32)
pub fn get_base_pixel(&self) -> (i32, i32)
Get the left upper conner of this area in the drawing backend
pub fn strip_coord_spec(&self) -> DrawingArea<DB, Shift>
pub fn strip_coord_spec(&self) -> DrawingArea<DB, Shift>
Strip the applied coordinate specification and returns a shift-based drawing area
pub fn use_screen_coord(&self) -> DrawingArea<DB, Shift>
pub fn use_screen_coord(&self) -> DrawingArea<DB, Shift>
Strip the applied coordinate specification and returns a drawing area
pub fn dim_in_pixel(&self) -> (u32, u32)
pub fn dim_in_pixel(&self) -> (u32, u32)
Get the area dimension in pixel
pub fn relative_to_height(&self, p: f64) -> f64
pub fn relative_to_height(&self, p: f64) -> f64
Compute the relative size based on the drawing area’s height
pub fn relative_to_width(&self, p: f64) -> f64
pub fn relative_to_width(&self, p: f64) -> f64
Compute the relative size based on the drawing area’s width
pub fn get_pixel_range(&self) -> (Range<i32>, Range<i32>)
pub fn get_pixel_range(&self) -> (Range<i32>, Range<i32>)
Get the pixel range of this area
pub fn fill<ColorType>(
&self,
color: &ColorType,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
ColorType: Color,
pub fn fill<ColorType>(
&self,
color: &ColorType,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
ColorType: Color,
Fill the entire drawing area with a color
pub fn draw_pixel<ColorType>(
&self,
pos: <CT as CoordTranslate>::From,
color: &ColorType,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
ColorType: Color,
pub fn draw_pixel<ColorType>(
&self,
pos: <CT as CoordTranslate>::From,
color: &ColorType,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
ColorType: Color,
Draw a single pixel
pub fn present(
&self,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
pub fn present( &self, ) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
Present all the pending changes to the backend
pub fn draw<'a, E, B>(
&self,
element: &'a E,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
B: CoordMapper,
&'a E: PointCollection<'a, <CT as CoordTranslate>::From, B>,
E: Drawable<DB, B>,
pub fn draw<'a, E, B>(
&self,
element: &'a E,
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
B: CoordMapper,
&'a E: PointCollection<'a, <CT as CoordTranslate>::From, B>,
E: Drawable<DB, B>,
Draw an high-level element
pub fn map_coordinate(&self, coord: &<CT as CoordTranslate>::From) -> (i32, i32)
pub fn map_coordinate(&self, coord: &<CT as CoordTranslate>::From) -> (i32, i32)
Map coordinate to the backend coordinate
pub fn estimate_text_size(
&self,
text: &str,
style: &TextStyle<'_>,
) -> Result<(u32, u32), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
pub fn estimate_text_size( &self, text: &str, style: &TextStyle<'_>, ) -> Result<(u32, u32), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
Estimate the dimension of the text if drawn on this drawing area. We can’t get this directly from the font, since the drawing backend may or may not follows the font configuration. In terminal, the font family will be dropped. So the size of the text is drawing area related.
text: The text we want to estimatefont: The font spec in which we want to draw the text- return: The size of the text if drawn on this area
§impl<DB> DrawingArea<DB, Shift>where
DB: DrawingBackend,
impl<DB> DrawingArea<DB, Shift>where
DB: DrawingBackend,
pub fn shrink<A, B, C, D>(
self,
left_upper: (A, B),
dimension: (C, D),
) -> DrawingArea<DB, Shift>
pub fn shrink<A, B, C, D>( self, left_upper: (A, B), dimension: (C, D), ) -> DrawingArea<DB, Shift>
Shrink the region, note all the locations are in guest coordinate
pub fn apply_coord_spec<CT>(&self, coord_spec: CT) -> DrawingArea<DB, CT>where
CT: CoordTranslate,
pub fn apply_coord_spec<CT>(&self, coord_spec: CT) -> DrawingArea<DB, CT>where
CT: CoordTranslate,
Apply a new coord transformation object and returns a new drawing area
pub fn margin<ST, SB, SL, SR>(
&self,
top: ST,
bottom: SB,
left: SL,
right: SR,
) -> DrawingArea<DB, Shift>
pub fn margin<ST, SB, SL, SR>( &self, top: ST, bottom: SB, left: SL, right: SR, ) -> DrawingArea<DB, Shift>
Create a margin for the given drawing area and returns the new drawing area
pub fn split_vertically<S>(
&self,
y: S,
) -> (DrawingArea<DB, Shift>, DrawingArea<DB, Shift>)where
S: SizeDesc,
pub fn split_vertically<S>(
&self,
y: S,
) -> (DrawingArea<DB, Shift>, DrawingArea<DB, Shift>)where
S: SizeDesc,
Split the drawing area vertically
pub fn split_horizontally<S>(
&self,
x: S,
) -> (DrawingArea<DB, Shift>, DrawingArea<DB, Shift>)where
S: SizeDesc,
pub fn split_horizontally<S>(
&self,
x: S,
) -> (DrawingArea<DB, Shift>, DrawingArea<DB, Shift>)where
S: SizeDesc,
Split the drawing area horizontally
pub fn split_evenly(&self, _: (usize, usize)) -> Vec<DrawingArea<DB, Shift>>
pub fn split_evenly(&self, _: (usize, usize)) -> Vec<DrawingArea<DB, Shift>>
Split the drawing area evenly
pub fn split_by_breakpoints<XSize, YSize, XS, YS>(
&self,
xs: XS,
ys: YS,
) -> Vec<DrawingArea<DB, Shift>>
pub fn split_by_breakpoints<XSize, YSize, XS, YS>( &self, xs: XS, ys: YS, ) -> Vec<DrawingArea<DB, Shift>>
Split the drawing area into a grid with specified breakpoints on both X axis and Y axis
pub fn titled<'a, S>(
&self,
text: &str,
style: S,
) -> Result<DrawingArea<DB, Shift>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
pub fn titled<'a, S>( &self, text: &str, style: S, ) -> Result<DrawingArea<DB, Shift>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
Draw a title of the drawing area and return the remaining drawing area
pub fn draw_text(
&self,
text: &str,
style: &TextStyle<'_>,
pos: (i32, i32),
) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
pub fn draw_text( &self, text: &str, style: &TextStyle<'_>, pos: (i32, i32), ) -> Result<(), DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
Draw text on the drawing area
§impl<DB, CT> DrawingArea<DB, CT>where
DB: DrawingBackend,
CT: CoordTranslate,
impl<DB, CT> DrawingArea<DB, CT>where
DB: DrawingBackend,
CT: CoordTranslate,
pub fn into_coord_spec(self) -> CT
pub fn into_coord_spec(self) -> CT
Returns the coordinates by value
pub fn as_coord_spec(&self) -> &CT
pub fn as_coord_spec(&self) -> &CT
Returns the coordinates by reference
pub fn as_coord_spec_mut(&mut self) -> &mut CT
pub fn as_coord_spec_mut(&mut self) -> &mut CT
Returns the coordinates by mutable reference
Trait Implementations§
§impl<DB, CT> Clone for DrawingArea<DB, CT>
impl<DB, CT> Clone for DrawingArea<DB, CT>
§fn clone(&self) -> DrawingArea<DB, CT>
fn clone(&self) -> DrawingArea<DB, CT>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<'a, DB> From<&'a Rc<RefCell<DB>>> for DrawingArea<DB, Shift>where
DB: DrawingBackend,
impl<'a, DB> From<&'a Rc<RefCell<DB>>> for DrawingArea<DB, Shift>where
DB: DrawingBackend,
§impl<DB> From<DB> for DrawingArea<DB, Shift>where
DB: DrawingBackend,
impl<DB> From<DB> for DrawingArea<DB, Shift>where
DB: DrawingBackend,
§fn from(backend: DB) -> DrawingArea<DB, Shift>
fn from(backend: DB) -> DrawingArea<DB, Shift>
Auto Trait Implementations§
impl<DB, CT> Freeze for DrawingArea<DB, CT>where
CT: Freeze,
impl<DB, CT> !RefUnwindSafe for DrawingArea<DB, CT>
impl<DB, CT> !Send for DrawingArea<DB, CT>
impl<DB, CT> !Sync for DrawingArea<DB, CT>
impl<DB, CT> Unpin for DrawingArea<DB, CT>where
CT: Unpin,
impl<DB, CT> !UnwindSafe for DrawingArea<DB, CT>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more