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 bfea7d59239c4db7c87ec2fbc241d818848f4969..1de853d6838ba34814831ad40fe80fbc1e564d6f 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 a6048547eae1d3d8953567024c4ff9a9257bc222..c3c0fa2002376cb504be1724564928b6e728a118 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();