From 192ccc8b286956f9cd97c1ff85173ec07eb708d9 Mon Sep 17 00:00:00 2001
From: Bryan Cardillo <bryan.cardillo@gmail.com>
Date: Wed, 25 Feb 2015 17:40:21 -0500
Subject: [PATCH] add support for axis label rotation.

---
 .../com/xeiam/xchart/internal/chartpart/Axis.java   | 13 +++++++++++--
 .../xchart/internal/chartpart/AxisTickLabels.java   | 10 +++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java
index bfea7d59..1de853d6 100644
--- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java
+++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java
@@ -16,9 +16,13 @@
 package com.xeiam.xchart.internal.chartpart;
 
 import java.awt.Graphics2D;
+import java.awt.Shape;
 import java.awt.font.FontRenderContext;
 import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import com.xeiam.xchart.StyleManager.LegendPosition;
 
@@ -143,8 +147,13 @@ public class Axis implements ChartPart {
       // Axis tick labels
       double axisTickLabelsHeight = 0.0;
       if (getChartPainter().getStyleManager().isXAxisTicksVisible()) {
-        TextLayout textLayout = new TextLayout("0", getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false));
-        Rectangle2D rectangle = textLayout.getBounds();
+        String tickLabel = getChartPainter().getAxisPair().getXAxis().getAxisType().equals(AxisType.Date) ?
+            new SimpleDateFormat(getChartPainter().getStyleManager().getDatePattern()).format(new Date()) : "0";
+        TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false));
+        AffineTransform rot = getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null :
+          AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
+        Shape shape = textLayout.getOutline(rot);
+        Rectangle2D rectangle = shape.getBounds();
         axisTickLabelsHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength();
       }
       return titleHeight + axisTickLabelsHeight;
diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java
index a6048547..c3c0fa20 100644
--- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java
+++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java
@@ -88,8 +88,10 @@ public class AxisTickLabels implements ChartPart {
       for (Double tickLocation : axisLabelTextLayouts.keySet()) {
 
         TextLayout axisLabelTextLayout = axisLabelTextLayouts.get(tickLocation);
-        Rectangle2D tickLabelBounds = axisLabelTextLayout.getBounds();
-        Shape shape = axisLabelTextLayout.getOutline(null);
+        AffineTransform rot = getChartPainter().getStyleManager().getYAxisLabelRotation() == 0 ? null :
+          AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getYAxisLabelRotation()));
+        Shape shape = axisLabelTextLayout.getOutline(rot);
+        Rectangle2D tickLabelBounds = shape.getBounds();
 
         double flippedTickLocation = yOffset + height - tickLocation;
 
@@ -142,7 +144,9 @@ public class AxisTickLabels implements ChartPart {
           TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), frc);
 
           // Shape shape = v.getOutline();
-          Shape shape = textLayout.getOutline(null);
+          AffineTransform rot = getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null :
+            AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()));
+          Shape shape = textLayout.getOutline(rot);
           Rectangle2D tickLabelBounds = shape.getBounds2D();
 
           AffineTransform orig = g.getTransform();
-- 
GitLab