Skip to content
Snippets Groups Projects
Commit 76d0c57e authored by Tim Molter's avatar Tim Molter
Browse files

insignificant cleanup [ci skip]

parent af9445b4
No related branches found
No related tags found
No related merge requests found
...@@ -73,13 +73,13 @@ public abstract class AxisTickCalculator { ...@@ -73,13 +73,13 @@ public abstract class AxisTickCalculator {
} }
// override min and maxValue if specified // 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(); overrideMinValue = styleManager.getXAxisMin();
} }
if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) { if (axisDirection == Direction.Y && styleManager.getYAxisMin() != null) {
overrideMinValue = styleManager.getYAxisMin(); 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(); overrideMaxValue = styleManager.getXAxisMax();
} }
if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) { if (axisDirection == Direction.Y && styleManager.getYAxisMax() != null) {
...@@ -98,7 +98,7 @@ public abstract class AxisTickCalculator { ...@@ -98,7 +98,7 @@ public abstract class AxisTickCalculator {
* @param gridStep * @param gridStep
* @return * @return
*/ */
double getFirstPosition(double gridStep) { double getFirstPosition(double gridStep) {
// System.out.println("******"); // System.out.println("******");
...@@ -116,70 +116,4 @@ public abstract class AxisTickCalculator { ...@@ -116,70 +116,4 @@ public abstract class AxisTickCalculator {
return tickLabels; 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;
}
} }
...@@ -63,8 +63,6 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { ...@@ -63,8 +63,6 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator {
int logMin = (int) Math.floor(Math.log10(minValue)); int logMin = (int) Math.floor(Math.log10(minValue));
int logMax = (int) Math.ceil(Math.log10(maxValue)); 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("minValue: " + minValue);
// System.out.println("maxValue: " + maxValue); // System.out.println("maxValue: " + maxValue);
// System.out.println("logMin: " + logMin); // System.out.println("logMin: " + logMin);
...@@ -116,7 +114,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { ...@@ -116,7 +114,7 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator {
tickLabels.add(numberFormatter.formatLogNumber(j, axisDirection)); tickLabels.add(numberFormatter.formatLogNumber(j, axisDirection));
} }
else { 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(" "); tickLabels.add(" ");
} }
......
...@@ -85,4 +85,70 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator { ...@@ -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;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment