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 fbb6c8b85d20c9aa12f8fa964449f7eee00f49fc..643e516a0700a3c6f4c3d6266907fc100d8d1a91 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 @@ -48,7 +48,7 @@ public class DateChart08 implements ExampleChart { Chart chart = new ChartBuilder().width(800).height(600).title("Year Scale").build(); chart.getStyleManager().setLegendVisible(false); chart.getStyleManager().setXAxisLabelRotation(45); - chart.getStyleManager().setYAxisLabelRotation(90); + // chart.getStyleManager().setYAxisLabelRotation(90); chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right); chart.getStyleManager().setDatePattern("yyyy-MM-dd"); 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 01623269cf1ee3fbe54cdb104e72bc00c4d7c818..44decee01fff3d398303b754bfc59be40da9d982 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 @@ -15,6 +15,7 @@ */ package com.xeiam.xchart.internal.chartpart; +import java.awt.Color; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.font.FontRenderContext; @@ -28,7 +29,7 @@ import com.xeiam.xchart.StyleManager.LegendPosition; /** * Axis - * + * * @author timmolter */ public class Axis implements ChartPart { @@ -75,7 +76,7 @@ public class Axis implements ChartPart { /** * Constructor - * + * * @param direction the axis direction (X or Y) * @param chart the chart */ @@ -129,40 +130,6 @@ public class Axis implements ChartPart { return bounds; } - /** - * @return - */ - protected double getSizeHint() { - - if (direction == Direction.X) { // X-Axis - - // Axis title - double titleHeight = 0.0; - if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isXAxisTitleVisible()) { - TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartPainter().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); - Rectangle2D rectangle = textLayout.getBounds(); - titleHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTitlePadding(); - } - - // Axis tick labels - double axisTickLabelsHeight = 0.0; - if (getChartPainter().getStyleManager().isXAxisTicksVisible()) { - 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; - } - else { // Y-Axis - return 0; // We layout the yAxis first depending in the xAxis height hint. We don't care about the yAxis height hint - } - } - @Override public void paint(Graphics2D g) { @@ -188,8 +155,8 @@ public class Axis implements ChartPart { Rectangle2D yAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); this.paintZone = yAxisRectangle; - // g.setColor(Color.green); - // g.draw(yAxisRectangle); + g.setColor(Color.green); + g.draw(yAxisRectangle); // fill in Axis with sub-components axisTitle.paint(g); @@ -201,8 +168,8 @@ public class Axis implements ChartPart { height = paintZone.getHeight(); bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); - // g.setColor(Color.yellow); - // g.draw(bounds); + g.setColor(Color.yellow); + g.draw(bounds); } else { // X-Axis @@ -242,8 +209,8 @@ public class Axis implements ChartPart { Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); this.paintZone = xAxisRectangle; - // g.setColor(Color.green); - // g.draw(xAxisRectangle); + g.setColor(Color.green); + g.draw(xAxisRectangle); axisTitle.paint(g); axisTick.paint(g); @@ -253,12 +220,49 @@ public class Axis implements ChartPart { width = paintZone.getWidth(); height = (getChartPainter().getStyleManager().isXAxisTitleVisible() ? axisTitle.getBounds().getHeight() : 0) + axisTick.getBounds().getHeight(); bounds = new Rectangle2D.Double(xOffset, yOffset, width, height); - // g.setColor(Color.yellow); - // g.draw(bounds); + + g.setColor(Color.yellow); + g.draw(bounds); } } + /** + * @return + */ + private double getSizeHint() { + + System.out.println(axisTick.getTickLabels()); + + if (direction == Direction.X) { // X-Axis + + // Axis title + double titleHeight = 0.0; + if (axisTitle.getText() != null && !axisTitle.getText().trim().equalsIgnoreCase("") && getChartPainter().getStyleManager().isXAxisTitleVisible()) { + TextLayout textLayout = new TextLayout(axisTitle.getText(), getChartPainter().getStyleManager().getAxisTitleFont(), new FontRenderContext(null, true, false)); + Rectangle2D rectangle = textLayout.getBounds(); + titleHeight = rectangle.getHeight() + getChartPainter().getStyleManager().getAxisTitlePadding(); + } + + // Axis tick labels + double axisTickLabelsHeight = 0.0; + if (getChartPainter().getStyleManager().isXAxisTicksVisible()) { + 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; + } + else { // Y-Axis + return 0; // We layout the yAxis first depending in the xAxis height hint. We don't care about the yAxis height hint + } + } + @Override public ChartPainter getChartPainter() { diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java index 4e2c66c1960084fdcbcf0ffa6e7b72f30ba55873..0488e045f6f6e7ba96b2bff34296879169b236b8 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java @@ -15,6 +15,7 @@ */ package com.xeiam.xchart.internal.chartpart; +import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.util.List; @@ -43,7 +44,7 @@ public class AxisTick implements ChartPart { /** * Constructor - * + * * @param axis */ protected AxisTick(Axis axis) { @@ -115,8 +116,8 @@ public class AxisTick implements ChartPart { ); - // g.setColor(Color.red); - // g.draw(bounds); + g.setColor(Color.red); + g.draw(bounds); } else if (axis.getDirection() == Axis.Direction.X && getChartPainter().getStyleManager().isXAxisTicksVisible()) { 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 ff749abd2735740a99ed79ffac37772a0f270f3c..cb01cae4b76b48f9db0f44f5cc206490671c5747 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 @@ -68,6 +68,7 @@ public class AxisTickLabels implements ChartPart { Map<Double, TextLayout> axisLabelTextLayouts = new HashMap<Double, TextLayout>(); for (int i = 0; i < axisTick.getTickLabels().size(); i++) { + String tickLabel = axisTick.getTickLabels().get(i); // System.out.println("** " + tickLabel); double tickLocation = axisTick.getTickLocations().get(i); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java index 9b5ea136eb3bfdf851f9568fb8f6ffefaa92b9fb..e798a0a3f2ba85f2df9785170bf73f8cff6f09fd 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java @@ -78,6 +78,7 @@ public class ChartTitle implements ChartPart { return chartPainter.getStyleManager().getChartPadding() + 2 * chartPainter.getStyleManager().getChartTitlePadding() + titleHeight; } else { + // TODO make this zero return chartPainter.getStyleManager().getChartPadding(); } }