Skip to content

Commit 18dce90

Browse files
committed
Refactor the chart context
1 parent 9990a34 commit 18dce90

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/chart/context.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ where
6363
}
6464
}
6565

66+
impl<'a, DB: DrawingBackend, CT: ReverseCoordTranslate> ChartContext<'a, DB, CT> {
67+
/// Convert the chart context into an closure that can be used for coordinate translation
68+
pub fn into_coord_trans(self) -> impl Fn(BackendCoord) -> Option<CT::From> {
69+
let coord_spec = self.drawing_area.into_coord_spec();
70+
move |coord| coord_spec.reverse_translate(coord)
71+
}
72+
}
73+
6674
impl<'a, DB: DrawingBackend, CT: CoordTranslate> ChartContext<'a, DB, CT> {
6775
/// Configure the styles for drawing series labels in the chart
6876
pub fn configure_series_labels<'b>(&'b mut self) -> SeriesLabelStyle<'a, 'b, DB, CT>
@@ -76,24 +84,12 @@ impl<'a, DB: DrawingBackend, CT: CoordTranslate> ChartContext<'a, DB, CT> {
7684
pub fn plotting_area(&self) -> &DrawingArea<DB, CT> {
7785
&self.drawing_area
7886
}
79-
}
8087

81-
impl<'a, DB: DrawingBackend, CT: CoordTranslate> ChartContext<'a, DB, CT> {
8288
/// Cast the reference to a chart context to a reference to underlying coordinate specification.
8389
pub fn as_coord_spec(&self) -> &CT {
8490
self.drawing_area.as_coord_spec()
8591
}
86-
}
87-
88-
impl<'a, DB: DrawingBackend, CT: ReverseCoordTranslate> ChartContext<'a, DB, CT> {
89-
/// Convert the chart context into an closure that can be used for coordinate translation
90-
pub fn into_coord_trans(self) -> impl Fn(BackendCoord) -> Option<CT::From> {
91-
let coord_spec = self.drawing_area.into_coord_spec();
92-
move |coord| coord_spec.reverse_translate(coord)
93-
}
94-
}
9592

96-
impl<'a, DB: DrawingBackend, CT: CoordTranslate> ChartContext<'a, DB, CT> {
9793
// TODO: All draw_series_impl is overly strict about lifetime, because we don't have stable HKT,
9894
// what we can ensure is for all lifetime 'b the element reference &'b E is a iterator
9995
// of points reference with the same lifetime.

src/element/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ pub trait PointCollection<'a, Coord> {
230230
/// framework to do the coordinate mapping
231231
fn point_iter(self) -> Self::IntoIter;
232232
}
233-
234233
/// The trait indicates we are able to draw it on a drawing area
235234
pub trait Drawable<DB: DrawingBackend> {
236235
/// Actually draws the element. The key points is already translated into the

0 commit comments

Comments
 (0)