Struct DualCoordChartContext
pub struct DualCoordChartContext<'a, DB, CT1, CT2>{ /* private fields */ }Expand description
The chart context that has two coordinate system attached.
This situation is quite common, for example, we with two different coordinate system.
For instance this example
This is done by attaching a second coordinate system to ChartContext by method ChartContext::set_secondary_coord.
For instance of dual coordinate charts, see this example.
Note: DualCoordChartContext is always deref to the chart context.
- If you want to configure the secondary axis, method DualCoordChartContext::configure_secondary_axes
- If you want to draw a series using secondary coordinate system, use DualCoordChartContext::draw_secondary_series. And method ChartContext::draw_series will always use primary coordinate spec.
Implementations§
§impl<DB, CT1, CT2> DualCoordChartContext<'_, DB, CT1, CT2>
impl<DB, CT1, CT2> DualCoordChartContext<'_, DB, CT1, CT2>
pub fn into_chart_state(self) -> DualCoordChartState<CT1, CT2>
pub fn into_chart_state(self) -> DualCoordChartState<CT1, CT2>
Convert the chart context into a chart state, similar to ChartContext::into_chart_state
Convert the chart context into a sharable chart state.
pub fn to_chart_state(&self) -> DualCoordChartState<CT1, CT2>
pub fn to_chart_state(&self) -> DualCoordChartState<CT1, CT2>
Copy the coordinate specs and make a chart state
§impl<'a, DB, CT1, CT2> DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> DualCoordChartContext<'a, DB, CT1, CT2>
pub fn secondary_plotting_area(&self) -> &DrawingArea<DB, CT2>
pub fn secondary_plotting_area(&self) -> &DrawingArea<DB, CT2>
Get a reference to the drawing area that uses the secondary coordinate system
pub fn borrow_secondary(&self) -> &ChartContext<'a, DB, CT2>
pub fn borrow_secondary(&self) -> &ChartContext<'a, DB, CT2>
Borrow a mutable reference to the chart context that uses the secondary coordinate system
§impl<DB, CT1, CT2> DualCoordChartContext<'_, DB, CT1, CT2>
impl<DB, CT1, CT2> DualCoordChartContext<'_, DB, CT1, CT2>
pub fn into_secondary_coord_trans(self) -> impl Fn((i32, i32))
pub fn into_secondary_coord_trans(self) -> impl Fn((i32, i32))
Convert the chart context into the secondary coordinate translation function
§impl<DB, CT1, CT2> DualCoordChartContext<'_, DB, CT1, CT2>
impl<DB, CT1, CT2> DualCoordChartContext<'_, DB, CT1, CT2>
§impl<'a, DB, CT1, XT, YT, SX, SY> DualCoordChartContext<'a, DB, CT1, Cartesian2d<SX, SY>>where
DB: DrawingBackend,
CT1: CoordTranslate,
SX: Ranged<ValueType = XT> + ValueFormatter<XT>,
SY: Ranged<ValueType = YT> + ValueFormatter<YT>,
impl<'a, DB, CT1, XT, YT, SX, SY> DualCoordChartContext<'a, DB, CT1, Cartesian2d<SX, SY>>where
DB: DrawingBackend,
CT1: CoordTranslate,
SX: Ranged<ValueType = XT> + ValueFormatter<XT>,
SY: Ranged<ValueType = YT> + ValueFormatter<YT>,
pub fn configure_secondary_axes<'b>(
&'b mut self,
) -> SecondaryMeshStyle<'a, 'b, SX, SY, DB>
pub fn configure_secondary_axes<'b>( &'b mut self, ) -> SecondaryMeshStyle<'a, 'b, SX, SY, DB>
Start configure the style for the secondary axes
§impl<'a, DB, X, Y, SX, SY> DualCoordChartContext<'a, DB, Cartesian2d<X, Y>, Cartesian2d<SX, SY>>
impl<'a, DB, X, Y, SX, SY> DualCoordChartContext<'a, DB, Cartesian2d<X, Y>, Cartesian2d<SX, SY>>
pub fn draw_secondary_series<E, R, S>(
&mut self,
series: S,
) -> Result<&mut SeriesAnno<'a, DB>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
&'b E: for<'b> PointCollection<'b, (<SX as Ranged>::ValueType, <SY as Ranged>::ValueType)>,
E: Drawable<DB>,
R: Borrow<E>,
S: IntoIterator<Item = R>,
pub fn draw_secondary_series<E, R, S>(
&mut self,
series: S,
) -> Result<&mut SeriesAnno<'a, DB>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
&'b E: for<'b> PointCollection<'b, (<SX as Ranged>::ValueType, <SY as Ranged>::ValueType)>,
E: Drawable<DB>,
R: Borrow<E>,
S: IntoIterator<Item = R>,
Draw a series use the secondary coordinate system.
series: The series to drawReturnsthe series annotation object or error code
Methods from Deref<Target = ChartContext<'a, DB, CT1>>§
pub fn configure_series_labels<'b>(
&'b mut self,
) -> SeriesLabelStyle<'a, 'b, DB, CT>where
DB: 'a,
pub fn configure_series_labels<'b>(
&'b mut self,
) -> SeriesLabelStyle<'a, 'b, DB, CT>where
DB: 'a,
Configure the styles for drawing series labels in the chart
§Example
use plotters::prelude::*;
let data = [(1.0, 3.3), (2., 2.1), (3., 1.5), (4., 1.9), (5., 1.0)];
let drawing_area = SVGBackend::new("configure_series_labels.svg", (300, 200)).into_drawing_area();
drawing_area.fill(&WHITE).unwrap();
let mut chart_builder = ChartBuilder::on(&drawing_area);
chart_builder.margin(7).set_left_and_bottom_label_area_size(20);
let mut chart_context = chart_builder.build_cartesian_2d(0.0..5.5, 0.0..5.5).unwrap();
chart_context.configure_mesh().draw().unwrap();
chart_context.draw_series(LineSeries::new(data, BLACK)).unwrap().label("Series 1")
.legend(|(x,y)| Rectangle::new([(x - 15, y + 1), (x, y)], BLACK));
chart_context.configure_series_labels().position(SeriesLabelPosition::UpperRight).margin(20)
.legend_area_size(5).border_style(BLUE).background_style(BLUE.mix(0.1)).label_font(("Calibri", 20)).draw().unwrap();The result is a chart with one data series labeled “Series 1” in a blue legend box:
§See also
See crate::series::LineSeries for more information and examples
pub fn plotting_area(&self) -> &DrawingArea<DB, CT>
pub fn plotting_area(&self) -> &DrawingArea<DB, CT>
Get a reference of underlying plotting area
pub fn as_coord_spec(&self) -> &CT
pub fn as_coord_spec(&self) -> &CT
Cast the reference to a chart context to a reference to underlying coordinate specification.
pub fn draw_series<B, E, R, S>(
&mut self,
series: S,
) -> Result<&mut SeriesAnno<'a, DB>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
B: CoordMapper,
&'b E: for<'b> PointCollection<'b, <CT as CoordTranslate>::From, B>,
E: Drawable<DB, B>,
R: Borrow<E>,
S: IntoIterator<Item = R>,
pub fn draw_series<B, E, R, S>(
&mut self,
series: S,
) -> Result<&mut SeriesAnno<'a, DB>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
B: CoordMapper,
&'b E: for<'b> PointCollection<'b, <CT as CoordTranslate>::From, B>,
E: Drawable<DB, B>,
R: Borrow<E>,
S: IntoIterator<Item = R>,
Draws a data series. A data series in Plotters is abstracted as an iterator of elements.
See crate::series::LineSeries and ChartContext::configure_series_labels() for more information and examples.
pub fn to_chart_state(&self) -> ChartState<CT>
pub fn to_chart_state(&self) -> ChartState<CT>
Make the chart context, do not consume the chart context and clone the coordinate spec
Trait Implementations§
§impl<'a, DB, CT1, CT2> Borrow<ChartContext<'a, DB, CT1>> for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> Borrow<ChartContext<'a, DB, CT1>> for DualCoordChartContext<'a, DB, CT1, CT2>
§fn borrow(&self) -> &ChartContext<'a, DB, CT1>
fn borrow(&self) -> &ChartContext<'a, DB, CT1>
§impl<'a, DB, CT1, CT2> BorrowMut<ChartContext<'a, DB, CT1>> for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> BorrowMut<ChartContext<'a, DB, CT1>> for DualCoordChartContext<'a, DB, CT1, CT2>
§fn borrow_mut(&mut self) -> &mut ChartContext<'a, DB, CT1>
fn borrow_mut(&mut self) -> &mut ChartContext<'a, DB, CT1>
§impl<'a, DB, CT1, CT2> Deref for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> Deref for DualCoordChartContext<'a, DB, CT1, CT2>
§type Target = ChartContext<'a, DB, CT1>
type Target = ChartContext<'a, DB, CT1>
§fn deref(&self) -> &<DualCoordChartContext<'a, DB, CT1, CT2> as Deref>::Target
fn deref(&self) -> &<DualCoordChartContext<'a, DB, CT1, CT2> as Deref>::Target
§impl<'a, DB, CT1, CT2> DerefMut for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> DerefMut for DualCoordChartContext<'a, DB, CT1, CT2>
§fn deref_mut(
&mut self,
) -> &mut <DualCoordChartContext<'a, DB, CT1, CT2> as Deref>::Target
fn deref_mut( &mut self, ) -> &mut <DualCoordChartContext<'a, DB, CT1, CT2> as Deref>::Target
§impl<'b, DB, CT1, CT2> From<&'b DualCoordChartContext<'_, DB, CT1, CT2>> for DualCoordChartState<CT1, CT2>
impl<'b, DB, CT1, CT2> From<&'b DualCoordChartContext<'_, DB, CT1, CT2>> for DualCoordChartState<CT1, CT2>
§fn from(
chart: &'b DualCoordChartContext<'_, DB, CT1, CT2>,
) -> DualCoordChartState<CT1, CT2>
fn from( chart: &'b DualCoordChartContext<'_, DB, CT1, CT2>, ) -> DualCoordChartState<CT1, CT2>
§impl<DB, CT1, CT2> From<DualCoordChartContext<'_, DB, CT1, CT2>> for DualCoordChartState<CT1, CT2>
impl<DB, CT1, CT2> From<DualCoordChartContext<'_, DB, CT1, CT2>> for DualCoordChartState<CT1, CT2>
§fn from(
chart: DualCoordChartContext<'_, DB, CT1, CT2>,
) -> DualCoordChartState<CT1, CT2>
fn from( chart: DualCoordChartContext<'_, DB, CT1, CT2>, ) -> DualCoordChartState<CT1, CT2>
Auto Trait Implementations§
impl<'a, DB, CT1, CT2> Freeze for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> !RefUnwindSafe for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> !Send for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> !Sync for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> Unpin for DualCoordChartContext<'a, DB, CT1, CT2>
impl<'a, DB, CT1, CT2> !UnwindSafe for DualCoordChartContext<'a, DB, CT1, CT2>
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
§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