From 1aa2104c9b9ae3cd94226d0a234cfdff475f17be Mon Sep 17 00:00:00 2001 From: Tim Molter <tim@knowm.org> Date: Sat, 3 Oct 2015 00:19:08 +0200 Subject: [PATCH] chart freezing bug fix --- .../java/com/xeiam/xchart/internal/chartpart/Axis.java | 4 ++-- .../internal/chartpart/AxisTickDateCalculator.java | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) 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 49bddd28..6dc4f5dc 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 08a0a7ce..5e2ebb73 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 { -- GitLab