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 7a9d7cf230916a80ef9ca8773d9662d8942c4208..4c27ea599e92d7133e34e7cfa1acc64cb81aa535 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 @@ -30,6 +30,11 @@ import com.xeiam.xchart.demo.charts.ExampleChart; /** * Year scale + * <p> + * Demonstrates the following: + * <ul> + * <li>Rotated X-Axis labels + * <li>Setting a custom date formatter String */ public class DateChart08 implements ExampleChart { @@ -47,11 +52,6 @@ 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().setXAxisLabelRotation(90); - // chart.getStyleManager().setXAxisLabelRotation(20); - // chart.getStyleManager().setXAxisLabelRotation(80); - // chart.getStyleManager().setXAxisLabelAlignment(TextAlignment.Right); - chart.getStyleManager().setDatePattern("yyyy-MM-dd"); // generate data List<Date> xData = new ArrayList<Date>(); 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 b0694c72b3c1e7bf5ba161ce40572ce9ad092d3b..68de6dd23a66274bce8f1b6ff7029084933e5351 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,7 +15,6 @@ */ package com.xeiam.xchart.internal.chartpart; -import java.awt.Color; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.font.FontRenderContext; @@ -159,27 +158,27 @@ public class Axis implements ChartPart { getChartPainter().getWidth() - - width // y-axis approx. width + - width // y-axis approx. width - - chartLegendWidth + - chartLegendWidth - - 2 - * getChartPainter().getStyleManager().getChartPadding() + - 2 + * getChartPainter().getStyleManager().getChartPadding() - - (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0) + - (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0) - - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager() - .getChartPadding() : 0) + - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager() + .getChartPadding() : 0) - ; + ; double height = getChartPainter().getHeight() - yOffset - axisPair.getXAxis().getXAxisHeightHint(approximateXAxisWidth) - getChartPainter().getStyleManager().getPlotPadding() - - getChartPainter().getStyleManager().getChartPadding(); + - getChartPainter().getStyleManager().getChartPadding(); 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); @@ -191,8 +190,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 @@ -202,7 +201,7 @@ public class Axis implements ChartPart { double xOffset = axisPair.getYAxis().getBounds().getWidth() + (getChartPainter().getStyleManager().isYAxisTicksVisible() ? getChartPainter().getStyleManager().getPlotPadding() : 0) - + getChartPainter().getStyleManager().getChartPadding(); + + getChartPainter().getStyleManager().getChartPadding(); double yOffset = axisPair.getYAxis().getBounds().getY() + axisPair.getYAxis().getBounds().getHeight() + getChartPainter().getStyleManager().getPlotPadding(); double chartLegendWidth = 0; @@ -214,27 +213,27 @@ public class Axis implements ChartPart { getChartPainter().getWidth() - - axisPair.getYAxis().getBounds().getWidth() // y-axis was already painted + - axisPair.getYAxis().getBounds().getWidth() // y-axis was already painted - - chartLegendWidth + - chartLegendWidth - - 2 - * getChartPainter().getStyleManager().getChartPadding() + - 2 + * getChartPainter().getStyleManager().getChartPadding() - - (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0) + - (getChartPainter().getStyleManager().isYAxisTicksVisible() ? (getChartPainter().getStyleManager().getPlotPadding()) : 0) - - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager() - .getChartPadding() : 0) + - (getChartPainter().getStyleManager().getLegendPosition() == LegendPosition.OutsideE && getChartPainter().getStyleManager().isLegendVisible() ? getChartPainter().getStyleManager() + .getChartPadding() : 0) - ; + ; double height = this.getXAxisHeightHint(width); Rectangle2D xAxisRectangle = new Rectangle2D.Double(xOffset, yOffset, width, height); // the paint zone this.paintZone = xAxisRectangle; - g.setColor(Color.green); - g.draw(xAxisRectangle); + // g.setColor(Color.green); + // g.draw(xAxisRectangle); // now paint the X-Axis given the above paint zone axisTitle.paint(g); @@ -242,8 +241,8 @@ public class Axis implements ChartPart { bounds = paintZone; - g.setColor(Color.yellow); - g.draw(bounds); + // g.setColor(Color.yellow); + // g.draw(bounds); } } 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 d651c916943cf31aec42aae5f00715b1876e2eb7..b6dd5812f996755f7abee2bc0d5ec121b30d52bb 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 @@ -15,7 +15,6 @@ */ package com.xeiam.xchart.internal.chartpart; -import java.awt.Color; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.font.FontRenderContext; @@ -144,7 +143,7 @@ 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()); + // System.out.println(textLayout.getOutline(null).getBounds().toString()); // Shape shape = v.getOutline(); AffineTransform rot = AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation()), 0, 0); @@ -165,14 +164,9 @@ public class AxisTickLabels implements ChartPart { default: xPos = shiftedTickLocation - tickLabelBounds.getWidth() / 2.0; } - System.out.println("tickLabelBounds: " + tickLabelBounds.toString()); - // double shift = tickLabelBounds.getWidth() * Math.sin(Math.toRadians(getChartPainter().getStyleManager().getXAxisLabelRotation())); + // System.out.println("tickLabelBounds: " + tickLabelBounds.toString()); 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); @@ -181,10 +175,10 @@ public class AxisTickLabels implements ChartPart { g.fill(shape); g.setTransform(orig); - // debug box - g.setColor(Color.MAGENTA); - g.draw(new Rectangle2D.Double(xPos, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight())); - g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor()); + // // debug box + // g.setColor(Color.MAGENTA); + // g.draw(new Rectangle2D.Double(xPos, yOffset - tickLabelBounds.getHeight(), tickLabelBounds.getWidth(), tickLabelBounds.getHeight())); + // g.setColor(getChartPainter().getStyleManager().getAxisTickLabelsColor()); if (tickLabelBounds.getHeight() > maxTickLabelHeight) { maxTickLabelHeight = tickLabelBounds.getHeight();