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

enhancement - converted more int return values to double precision for more accurate drawing

parent cc2fb134
Branches
No related tags found
No related merge requests found
......@@ -15,7 +15,6 @@
*/
package com.xeiam.xchart.internal;
/**
* @author timmolter
*/
......@@ -35,10 +34,10 @@ public class Utils {
* @param tickSpace
* @return
*/
public static int getTickStartOffset(int workingSpace, int tickSpace) {
public static double getTickStartOffset(double workingSpace, double tickSpace) {
int marginSpace = workingSpace - tickSpace;
return (int) (marginSpace / 2.0);
double marginSpace = workingSpace - tickSpace;
return marginSpace / 2.0;
}
public static double pow(double base, int exponent) {
......
......@@ -53,7 +53,7 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
int tickSpace = (int) (styleManager.getAxisTickSpaceRatio() * workingSpace); // in plot space
// where the tick should begin in the working space in pixels
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);
double margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);
// get all categories
List<Object> categories = new ArrayList<Object>();
......
......@@ -126,7 +126,7 @@ public abstract class AxisTickCalculator {
* @param tickSpace in plot space
* @return
*/
public double getNumericalGridStep(int tickSpace) {
public double getNumericalGridStep(double tickSpace) {
// this prevents an infinite loop when the plot gets sized really small.
if (tickSpace < 10) {
......
......@@ -50,7 +50,7 @@ public class AxisTickDateCalculator extends AxisTickCalculator {
int tickSpace = (int) (styleManager.getAxisTickSpaceRatio() * workingSpace); // in plot space
// where the tick should begin in the working space in pixels
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);
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
......
......@@ -54,10 +54,10 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator {
}
// tick space - a percentage of the working space available for ticks
int tickSpace = (int) (styleManager.getAxisTickSpaceRatio() * workingSpace); // in plot space
double tickSpace = styleManager.getAxisTickSpaceRatio() * workingSpace; // in plot space
// where the tick should begin in the working space in pixels
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);
double margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);
int logMin = (int) Math.floor(Math.log10(minValue));
int logMax = (int) Math.ceil(Math.log10(maxValue));
......
......@@ -54,10 +54,10 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
}
// tick space - a percentage of the working space available for ticks
int tickSpace = (int) (styleManager.getAxisTickSpaceRatio() * workingSpace); // in plot space
double tickSpace = styleManager.getAxisTickSpaceRatio() * workingSpace; // in plot space
// where the tick should begin in the working space in pixels
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);
double margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space double gridStep = getGridStepForDecimal(tickSpace);
double gridStep = getNumericalGridStep(tickSpace);
double firstPosition = getFirstPosition(gridStep);
......
......@@ -49,12 +49,12 @@ public class PlotContentBarChart extends PlotContent {
StyleManager styleManager = plot.getChartPainter().getStyleManager();
// X-Axis
int xTickSpace = (int) (styleManager.getAxisTickSpaceRatio() * bounds.getWidth());
int xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace);
double xTickSpace = styleManager.getAxisTickSpaceRatio() * bounds.getWidth();
double xLeftMargin = Utils.getTickStartOffset(bounds.getWidth(), xTickSpace);
// Y-Axis
int yTickSpace = (int) (styleManager.getAxisTickSpaceRatio() * bounds.getHeight());
int yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
double yTickSpace = styleManager.getAxisTickSpaceRatio() * bounds.getHeight();
double yTopMargin = Utils.getTickStartOffset(bounds.getHeight(), yTickSpace);
// get all categories
List<Object> categories = new ArrayList<Object>();
......@@ -69,7 +69,7 @@ public class PlotContentBarChart extends PlotContent {
}
}
int numBars = categories.size();
double gridStep = xTickSpace / (double) numBars;
double gridStep = xTickSpace / numBars;
// plot series
int seriesCounter = 0;
......@@ -97,7 +97,7 @@ public class PlotContentBarChart extends PlotContent {
}
else if (getChartPainter().getStyleManager().isYAxisLogarithmic()) {
// int logMin = (int) Math.floor(Math.log10(getChartPainter().getAxisPair().getyAxis().getMin().doubleValue()));
int logMin = (int) Math.floor(Math.log10(getChartPainter().getAxisPair().getYAxis().getMin()));
double logMin = Math.floor(Math.log10(getChartPainter().getAxisPair().getYAxis().getMin()));
// System.out.println("logMin: " + logMin);
// System.out.println("min : " + getChartPainter().getAxisPair().getyAxis().getMin().doubleValue());
yMin = logMin;
......@@ -163,10 +163,10 @@ public class PlotContentBarChart extends PlotContent {
double yTransform = bounds.getHeight() - (yTopMargin + (yTop - yMin) / (yMax - yMin) * yTickSpace);
double yOffset = bounds.getY() + yTransform + 1;
double yOffset = bounds.getY() + yTransform;
double zeroTransform = bounds.getHeight() - (yTopMargin + (yBottom - yMin) / (yMax - yMin) * yTickSpace);
double zeroOffset = bounds.getY() + zeroTransform + 1;
double zeroOffset = bounds.getY() + zeroTransform;
// paint bar
double barWidth = gridStep / getChartPainter().getAxisPair().getSeriesMap().size() / 1.1;
......
......@@ -55,12 +55,12 @@ public class PlotContentLineChart extends PlotContent {
g.setClip(bounds);
// X-Axis
int xTickSpace = (int) (styleManager.getAxisTickSpaceRatio() * bounds.getWidth());
int xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace);
double xTickSpace = styleManager.getAxisTickSpaceRatio() * bounds.getWidth();
double xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace);
// Y-Axis
int yTickSpace = (int) (styleManager.getAxisTickSpaceRatio() * bounds.getHeight());
int yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
double yTickSpace = styleManager.getAxisTickSpaceRatio() * bounds.getHeight();
double yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
for (Series series : getChartPainter().getAxisPair().getSeriesMap().values()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment