Skip to content
Snippets Groups Projects
Commit 192ccc8b authored by Bryan Cardillo's avatar Bryan Cardillo
Browse files

add support for axis label rotation.

parent 90aefe9f
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment