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