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

bugfix Issue #83 - Bad signatures on axis (numbers should be rounded)

parent 9d8a2780
Branches
Tags
No related merge requests found
...@@ -131,36 +131,24 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator { ...@@ -131,36 +131,24 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
tickLocations.add(tickLabelPosition); tickLocations.add(tickLabelPosition);
} }
} }
else { // Number or Date and more than 12 categories. divide up the axis tick space according to normal number axis layout else { // Number or Date and more than 12 categories. divide up the axis tick space according to normal date oor number axis layout
double gridStep = getNumericalGridStep(tickSpace);
double firstPosition = getFirstPosition(gridStep);
// generate all tickLabels and tickLocations from the first to last position // generate all tickLabels and tickLocations from the first to last position
NumberFormatter numberFormatter = null;
DateFormatter dateFormatter = null;
if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) { if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) {
numberFormatter = new NumberFormatter(styleManager);
}
else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) {
dateFormatter = new DateFormatter(chartPainter.getStyleManager());
}
for (double tickPosition = firstPosition; tickPosition <= maxValue + 2 * gridStep; tickPosition = tickPosition + gridStep) { AxisTickNumericalCalculator axisTickNumericalCalculator = new AxisTickNumericalCalculator(axisDirection, workingSpace, minValue, maxValue, styleManager);
tickLabels = axisTickNumericalCalculator.getTickLabels();
tickLocations = axisTickNumericalCalculator.getTickLocations();
if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Number) {
tickLabels.add(numberFormatter.formatNumber(BigDecimal.valueOf(tickPosition), minValue, maxValue, axisDirection));
} }
else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) { else if (chartPainter.getAxisPair().getXAxis().getAxisType() == AxisType.Date) {
long span = (long) Math.abs(maxValue - minValue); // in data space
long gridStepHint = (long) (span / (double) tickSpace * styleManager.getXAxisTickMarkSpacingHint()); AxisTickDateCalculator axisTickDateCalculator = new AxisTickDateCalculator(axisDirection, workingSpace, minValue, maxValue, styleManager);
long timeUnit = dateFormatter.getTimeUnit(gridStepHint); tickLabels = axisTickDateCalculator.getTickLabels();
tickLabels.add(dateFormatter.formatDate(tickPosition, timeUnit)); tickLocations = axisTickDateCalculator.getTickLocations();
}
double tickLabelPosition = margin + ((tickPosition - minValue) / (maxValue - minValue) * tickSpace);
tickLocations.add(tickLabelPosition);
} }
} }
} }
......
...@@ -74,8 +74,10 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator { ...@@ -74,8 +74,10 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
// generate all tickLabels and tickLocations from the first to last position // generate all tickLabels and tickLocations from the first to last position
for (BigDecimal tickPosition = cleanedFirstPosition; tickPosition.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0; tickPosition = tickPosition.add(cleanedGridStep)) { for (BigDecimal tickPosition = cleanedFirstPosition; tickPosition.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0; tickPosition = tickPosition.add(cleanedGridStep)) {
// System.out.println(tickPosition);
String tickLabel = numberFormatter.formatNumber(tickPosition, minValue, maxValue, axisDirection); String tickLabel = numberFormatter.formatNumber(tickPosition, minValue, maxValue, axisDirection);
// System.out.println(tickLabel); // System.out.println(tickLabel);
tickLabels.add(tickLabel); tickLabels.add(tickLabel);
// here we convert tickPosition finally to plot space, i.e. pixels // here we convert tickPosition finally to plot space, i.e. pixels
double tickLabelPosition = margin + ((tickPosition.doubleValue() - minValue) / (maxValue - minValue) * tickSpace); double tickLabelPosition = margin + ((tickPosition.doubleValue() - minValue) / (maxValue - minValue) * tickSpace);
......
...@@ -133,6 +133,7 @@ public class NumberFormatter { ...@@ -133,6 +133,7 @@ public class NumberFormatter {
else { else {
decimalPattern = getFormatPattern(value, min, max); decimalPattern = getFormatPattern(value, min, max);
} }
// System.out.println(decimalPattern);
DecimalFormat normalFormat = (DecimalFormat) numberFormat; DecimalFormat normalFormat = (DecimalFormat) numberFormat;
normalFormat.applyPattern(decimalPattern); normalFormat.applyPattern(decimalPattern);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment