diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickCalculator.java index 03ac423e30abee53fd5463cda05952acda8b01b5..ad5f53bd9a3ece3f1fae06f88789b727590f1d39 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickCalculator.java @@ -73,13 +73,13 @@ public abstract class AxisTickCalculator { } // override min and maxValue if specified - if (axisDirection == Direction.X && styleManager.getXAxisMin() != null && styleManager.getChartType() != ChartType.Bar) { + if (axisDirection == Direction.X && styleManager.getXAxisMin() != null && styleManager.getChartType() != ChartType.Bar) { // bar chart cannot have a max or min overrideMinValue = styleManager.getXAxisMin(); } if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) { overrideMinValue = styleManager.getYAxisMin(); } - if (axisDirection == Direction.X && styleManager.getXAxisMax() != null && styleManager.getChartType() != ChartType.Bar) { + if (axisDirection == Direction.X && styleManager.getXAxisMax() != null && styleManager.getChartType() != ChartType.Bar) { // bar chart cannot have a max or min overrideMaxValue = styleManager.getXAxisMax(); } if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) { @@ -98,7 +98,7 @@ public abstract class AxisTickCalculator { * @param gridStep * @return */ - double getFirstPosition(double gridStep) { + double getFirstPosition(double gridStep) { // System.out.println("******"); @@ -116,70 +116,4 @@ public abstract class AxisTickCalculator { return tickLabels; } - /** - * Determine the grid step for the data set given the space in pixels allocated for the axis - * - * @param tickSpace in plot space - * @return - */ - public double getNumericalGridStep(double tickSpace) { - - // this prevents an infinite loop when the plot gets sized really small. - if (tickSpace < 10) { - return 1.0; - } - - // the span of the data - double span = Math.abs(maxValue - minValue); // in data space - - int tickMarkSpaceHint = (axisDirection == Direction.X ? styleManager.getXAxisTickMarkSpacingHint() : styleManager.getYAxisTickMarkSpacingHint()); - - // for very short plots, squeeze some more ticks in than normal - if (axisDirection == Direction.Y && tickSpace < 160) { - tickMarkSpaceHint = 25; - } - - double gridStepHint = span / tickSpace * tickMarkSpaceHint; - - // gridStepHint --> significand * 10 ** exponent - // e.g. 724.1 --> 7.241 * 10 ** 2 - double significand = gridStepHint; - int exponent = 0; - if (significand == 0) { - exponent = 1; - } - else if (significand < 1) { - while (significand < 1) { - significand *= 10.0; - exponent--; - } - } - else { - while (significand >= 10 || significand == Double.NEGATIVE_INFINITY) { - significand /= 10.0; - exponent++; - } - } - - // calculate the grid step with hint. - double gridStep; - if (significand > 7.5) { - // gridStep = 10.0 * 10 ** exponent - gridStep = 10.0 * Utils.pow(10, exponent); - } - else if (significand > 3.5) { - // gridStep = 5.0 * 10 ** exponent - gridStep = 5.0 * Utils.pow(10, exponent); - } - else if (significand > 1.5) { - // gridStep = 2.0 * 10 ** exponent - gridStep = 2.0 * Utils.pow(10, exponent); - } - else { - // gridStep = 1.0 * 10 ** exponent - gridStep = Utils.pow(10, exponent); - } - return gridStep; - } - } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java index e48ae436f09d3e787daadd925ac1b6b086456817..ca206e2cca6f1d5482d5590ac072e753fefbd45a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLogarithmicCalculator.java @@ -63,8 +63,6 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { int logMin = (int) Math.floor(Math.log10(minValue)); int logMax = (int) Math.ceil(Math.log10(maxValue)); - // int logMin = (int) Math.log10(minValue.doubleValue()); - // int logMax = (int) Math.log10(maxValue.doubleValue()); // System.out.println("minValue: " + minValue); // System.out.println("maxValue: " + maxValue); // System.out.println("logMin: " + logMin); @@ -116,7 +114,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { tickLabels.add(numberFormatter.formatLogNumber(j, axisDirection)); } else { - // Set a space to avoid Zero length string passed to TextLayout constructor + // Set a space to avoid Zero length string passed to TextLayout constructor tickLabels.add(" "); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java index ba41617daf38fbe098051c0d9df3d89d4c617b62..99f7fe2ef508e354692da6d50de9107b4411ce5d 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickNumericalCalculator.java @@ -85,4 +85,70 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator { } } + /** + * Determine the grid step for the data set given the space in pixels allocated for the axis + * + * @param tickSpace in plot space + * @return + */ + private double getNumericalGridStep(double tickSpace) { + + // this prevents an infinite loop when the plot gets sized really small. + if (tickSpace < 10) { + return 1.0; + } + + // the span of the data + double span = Math.abs(maxValue - minValue); // in data space + + int tickMarkSpaceHint = (axisDirection == Direction.X ? styleManager.getXAxisTickMarkSpacingHint() : styleManager.getYAxisTickMarkSpacingHint()); + + // for very short plots, squeeze some more ticks in than normal + if (axisDirection == Direction.Y && tickSpace < 160) { + tickMarkSpaceHint = 25; + } + + double gridStepHint = span / tickSpace * tickMarkSpaceHint; + + // gridStepHint --> significand * 10 ** exponent + // e.g. 724.1 --> 7.241 * 10 ** 2 + double significand = gridStepHint; + int exponent = 0; + if (significand == 0) { + exponent = 1; + } + else if (significand < 1) { + while (significand < 1) { + significand *= 10.0; + exponent--; + } + } + else { + while (significand >= 10 || significand == Double.NEGATIVE_INFINITY) { + significand /= 10.0; + exponent++; + } + } + + // calculate the grid step with hint. + double gridStep; + if (significand > 7.5) { + // gridStep = 10.0 * 10 ** exponent + gridStep = 10.0 * Utils.pow(10, exponent); + } + else if (significand > 3.5) { + // gridStep = 5.0 * 10 ** exponent + gridStep = 5.0 * Utils.pow(10, exponent); + } + else if (significand > 1.5) { + // gridStep = 2.0 * 10 ** exponent + gridStep = 2.0 * Utils.pow(10, exponent); + } + else { + // gridStep = 1.0 * 10 ** exponent + gridStep = Utils.pow(10, exponent); + } + return gridStep; + } + }