Repository: plotters-rs/plotters (language: rust)

Issue:
[Feature Request] Different styles for x/y labels
We have one method
`pub fn label_style<T: Into<TextStyle<'b>>>(&mut self, style: T) -> &mut Self`
to change styles of both x/y labels.

Would be nice to have ability to change styles independently.


Discussion / hints:

Fix patch:
diff --git a/src/chart/context.rs b/src/chart/context.rs
index c54e3012..ff0d1bde 100644
--- a/src/chart/context.rs
+++ b/src/chart/context.rs
@@ -133,7 +133,8 @@ impl<
             n_y_labels: 10,
             line_style_1: None,
             line_style_2: None,
-            label_style: None,
+            x_label_style: None,
+            y_label_style: None,
             format_x: &|x| format!("{:?}", x),
             format_y: &|y| format!("{:?}", y),
             target: Some(self),
@@ -521,7 +522,8 @@ impl<'a, DB: DrawingBackend, X: Ranged, Y: Ranged> ChartContext<'a, DB, RangedCo
         &mut self,
         (r, c): (usize, usize),
         mesh_line_style: &ShapeStyle,
-        label_style: &TextStyle,
+        x_label_style: &TextStyle,
+        y_label_style: &TextStyle,
         fmt_label: FmtLabel,
         x_mesh: bool,
         y_mesh: bool,
@@ -547,7 +549,7 @@ impl<'a, DB: DrawingBackend, X: Ranged, Y: Ranged> ChartContext<'a, DB, RangedCo
                 self.x_label_area[idx].as_ref(),
                 if x_axis { Some(axis_style) } else { None },
                 &x_labels[..],
-                label_style,
+                x_label_style,
                 x_label_offset,
                 (0, -1 + idx as i16 * 2),
                 x_desc.as_ref().map(|desc| (&desc[..], axis_desc_style)),
@@ -558,7 +560,7 @@ impl<'a, DB: DrawingBackend, X: Ranged, Y: Ranged> ChartContext<'a, DB, RangedCo
                 self.y_label_area[idx].as_ref(),
                 if y_axis { Some(axis_style) } else { None },
                 &y_labels[..],
-                label_style,
+                y_label_style,
                 y_label_offset,
                 (-1 + idx as i16 * 2, 0),
                 y_desc.as_ref().map(|desc| (&desc[..], axis_desc_style)),
diff --git a/src/chart/mesh.rs b/src/chart/mesh.rs
index 7a328917..6b2df18f 100644
--- a/src/chart/mesh.rs
+++ b/src/chart/mesh.rs
@@ -156,7 +156,8 @@ where
     pub(super) line_style_1: Option<ShapeStyle>,
     pub(super) line_style_2: Option<ShapeStyle>,
     pub(super) axis_style: Option<ShapeStyle>,
-    pub(super) label_style: Option<TextStyle<'b>>,
+    pub(super) x_label_style: Option<TextStyle<'b>>,
+    pub(super) y_label_style: Option<TextStyle<'b>>,
     pub(super) format_x: &'b dyn Fn(&X::ValueType) -> String,
     pub(super) format_y: &'b dyn Fn(&Y::ValueType) -> String,
     pub(super) target: Option<&'b mut ChartContext<'a, DB, RangedCoord<X, Y>>>,
@@ -286,7 +287,23 @@ where
     /// Set the style of the label text
     /// - `style`: The text style that would be applied to the labels
     pub fn label_style<T: IntoTextStyle<'b>>(&mut self, style: T) -> &mut Self {
-        self.label_style = Some(style.into_text_style(&self.parent_size));
+        let style = style.into_text_style(&self.parent_size);
+        self.x_label_style = Some(style.clone());
+        self.y_label_style = Some(style);
+        self
+    }
+
+    /// Set the style of the label X axis text
+    /// - `style`: The text style that would be applied to the labels
+    pub fn x_label_style<T: IntoTextStyle<'b>>(&mut self, style: T) -> &mut Self {
+        self.x_label_style = Some(style.into_text_style(&self.parent_size));
+        self
+    }
+
+   /// Set the style of the label Y axis text
+    /// - `style`: The text style that would be applied to the labels
+    pub fn y_label_style<T: IntoTextStyle<'b>>(&mut self, style: T) -> &mut Self {
+        self.y_label_style = Some(style.into_text_style(&self.parent_size));
         self
     }
 
@@ -353,20 +370,26 @@ where
             .clone()
             .unwrap_or_else(|| (&default_axis_color).into());
 
-        let label_style = self
-            .label_style
+        let x_label_style = self
+            .x_label_style
+            .clone()
+            .unwrap_or_else(|| default_label_font.clone().into());
+
+        let y_label_style = self
+            .y_label_style
             .clone()
             .unwrap_or_else(|| default_label_font.into());
 
         let axis_desc_style = self
             .axis_desc_style
             .clone()
-            .unwrap_or_else(|| label_style.clone());
+            .unwrap_or_else(|| x_label_style.clone());
 
         target.draw_mesh(
             (self.n_y_labels * 10, self.n_x_labels * 10),
             &mesh_style_2,
-            &label_style,
+            &x_label_style,
+            &y_label_style,
             |_| None,
             self.draw_x_mesh,
             self.draw_y_mesh,
@@ -385,7 +408,8 @@ where
         target.draw_mesh(
             (self.n_y_labels, self.n_x_labels),
             &mesh_style_1,
-            &label_style,
+            &x_label_style,
+            &y_label_style,
             |m| match m {
                 MeshLine::XMesh(_, _, v) => Some((self.format_x)(v)),
                 MeshLine::YMesh(_, _, v) => Some((self.format_y)(v)),


Test patch: