From 2dec34768d469da3baedc1a46c6c273530aaca70 Mon Sep 17 00:00:00 2001 From: Tim Molter <tim.molter@gmail.com> Date: Sat, 11 Apr 2015 17:53:44 +0200 Subject: [PATCH] format [ci skip] --- .../xchart/demo/charts/date/DateChart08.java | 2 +- .../xeiam/xchart/internal/chartpart/Axis.java | 92 ++++++++++--------- .../xchart/internal/chartpart/AxisTick.java | 7 +- .../internal/chartpart/AxisTickLabels.java | 1 + .../xchart/internal/chartpart/ChartTitle.java | 1 + 5 files changed, 55 insertions(+), 48 deletions(-) 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 fbb6c8b8..643e516a 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 01623269..44decee0 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 4e2c66c1..0488e045 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 ff749abd..cb01cae4 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 9b5ea136..e798a0a3 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(); } } -- GitLab