diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart08.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart08.java index 431bbbfea3e0156f73f76fe46f2c9e2538926d41..7a9d7cf230916a80ef9ca8773d9662d8942c4208 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart08.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/date/DateChart08.java @@ -46,7 +46,7 @@ public class DateChart08 implements ExampleChart { // Create Chart Chart chart = new ChartBuilder().width(800).height(600).title("Year Scale").build(); chart.getStyleManager().setLegendVisible(false); - // chart.getStyleManager().setXAxisLabelRotation(45); + chart.getStyleManager().setXAxisLabelRotation(45); // chart.getStyleManager().setXAxisLabelRotation(90); // chart.getStyleManager().setXAxisLabelRotation(20); // chart.getStyleManager().setXAxisLabelRotation(80); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java index 2a6f00e2e4d600ad61ffd8b5362f5cae6c737016..027c08b3de85cb9805a1fb5767e753cc2eb1dcc0 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java @@ -21,7 +21,6 @@ import java.util.List; import com.xeiam.xchart.Chart; import com.xeiam.xchart.ChartBuilder; import com.xeiam.xchart.StyleManager.LegendPosition; -import com.xeiam.xchart.StyleManager.TextAlignment; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.ExampleChart; @@ -61,7 +60,10 @@ public class LineChart01 implements ExampleChart { chart.getStyleManager().setChartTitleVisible(false); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); chart.getStyleManager().setYAxisLogarithmic(true); - chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right); + // chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right); + chart.getStyleManager().setXAxisLabelRotation(45); + // chart.getStyleManager().setXAxisLabelRotation(90); + // chart.getStyleManager().setXAxisLabelRotation(0); // Series chart.addSeries("10^x", xData, yData); 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 7782376c422c15e013152457ab9f0f8bf5fdef56..d651c916943cf31aec42aae5f00715b1876e2eb7 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 @@ -144,10 +144,10 @@ public class AxisTickLabels implements ChartPart { FontRenderContext frc = g.getFontRenderContext(); TextLayout textLayout = new TextLayout(tickLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), frc); + System.out.println(textLayout.getOutline(null).getBounds().toString()); // Shape shape = v.getOutline(); - AffineTransform rot = - getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); + AffineTransform rot = AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()), 0, 0); Shape shape = textLayout.getOutline(rot); Rectangle2D tickLabelBounds = shape.getBounds2D(); @@ -165,12 +165,23 @@ public class AxisTickLabels implements ChartPart { default: xPos = shiftedTickLocation - tickLabelBounds.getWidth() / 2.0; } - at.translate(xPos, yOffset); + System.out.println("tickLabelBounds: " + tickLabelBounds.toString()); + // double shift = tickLabelBounds.getWidth() * Math.sin(Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); + double shiftX = -1 * tickLabelBounds.getX() * Math.sin(Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); + // double shiftY = textLayout.getOutline(null).getBounds().getHeight() * Math.cos(Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); + // double shiftY = 0; + double shiftY = -1 * (tickLabelBounds.getY() + tickLabelBounds.getHeight()); + // double shift = tickLabelBounds.getWidth() / 2.0; + // double shift = 0; + System.out.println(shiftX); + System.out.println("shiftY: " + shiftY); + at.translate(xPos + shiftX, yOffset + shiftY); + g.transform(at); g.fill(shape); g.setTransform(orig); - // // debug box + // debug box g.setColor(Color.MAGENTA); g.draw(new Rectangle2D.Double(xPos, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight())); g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor());