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 49bddd28c41e9e5aacb33913cd5fdc6c9cfe95cd..6dc4f5dce3d3b69800ebde3bf125d775755f742e 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 @@ -299,7 +299,7 @@ public class Axis implements ChartPart { // System.out.println("sampleLabel: " + sampleLabel); // get the height of the label including rotation - TextLayout textLayout = new TextLayout(sampleLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); AffineTransform rot = getChartPainter().getStyleManager().getXAxisLabelRotation() == 0 ? null : AffineTransform.getRotateInstance(-1 * Math.toRadians(getChartPainter().getStyleManager() .getXAxisLabelRotation())); Shape shape = textLayout.getOutline(rot); @@ -337,7 +337,7 @@ public class Axis implements ChartPart { } // get the height of the label including rotation - TextLayout textLayout = new TextLayout(sampleLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); + TextLayout textLayout = new TextLayout(sampleLabel.length() == 0 ? " " : sampleLabel, getChartPainter().getStyleManager().getAxisTickLabelsFont(), new FontRenderContext(null, true, false)); Rectangle2D rectangle = textLayout.getBounds(); axisTickLabelsHeight = rectangle.getWidth() + getChartPainter().getStyleManager().getAxisTickPadding() + getChartPainter().getStyleManager().getAxisTickMarkLength(); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickDateCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickDateCalculator.java index 08a0a7ce4e705f3ec51bf4cca3eef8999223e9bc..5e2ebb73914069eec30286a6f577c10e52b51925 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickDateCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickDateCalculator.java @@ -49,15 +49,18 @@ public class AxisTickDateCalculator extends AxisTickCalculator { // tick space - a percentage of the working space available for ticks double tickSpace = styleManager.getAxisTickSpacePercentage() * workingSpace; // in plot space + // this prevents an infinite loop when the plot gets sized really small. + if (tickSpace < 10) { + return; + } + // where the tick should begin in the working space in pixels double margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace); // the span of the data long span = (long) Math.abs(maxValue - minValue); // in data space - // Can tickSpacingHint be intelligently calculated by looking at the label data? - // YES. Generate the labels first, see if they "look" OK and reiterate with an increased tickSpacingHint - // TODO apply this to other Axis types including bar charts + // Generate the labels first, see if they "look" OK and reiterate with an increased tickSpacingHint int tickSpacingHint = styleManager.getXAxisTickMarkSpacingHint() - 5; do {