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

moved some static methods to Utils

parent 3fcf2470
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,30 @@ public class Utils {
}
/**
* Gets the percentage of working space allowed for tick marks
*
* @param workingSpace
* @return
*/
public static int getTickSpace(int workingSpace) {
return (int) (workingSpace * 0.95);
}
/**
* Gets the offset for the beginning of the tick marks
*
* @param workingSpace
* @param tickSpace
* @return
*/
public static int getTickStartOffset(int workingSpace, int tickSpace) {
int marginSpace = workingSpace - tickSpace;
return (int) (marginSpace / 2.0);
}
public static BigDecimal pow(double base, int exponent) {
if (exponent > 0) {
......
......@@ -157,30 +157,4 @@ public class AxisPair implements ChartPart {
return yAxis;
}
// Helper Methods ///////////////
/**
* Gets the percentage of working space allowed for tick marks
*
* @param workingSpace
* @return
*/
public static int getTickSpace(int workingSpace) {
return (int) (workingSpace * 0.95);
}
/**
* Gets the offset for the beginning of the tick marks
*
* @param workingSpace
* @param tickSpace
* @return
*/
public static int getTickStartOffset(int workingSpace, int tickSpace) {
int marginSpace = workingSpace - tickSpace;
return (int) (marginSpace / 2.0);
}
}
......@@ -29,6 +29,7 @@ import java.util.Set;
import java.util.TreeSet;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.internal.Utils;
import com.xeiam.xchart.internal.chartpart.Axis.AxisType;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;
......@@ -57,10 +58,10 @@ public class AxisTickBarChartCalculator extends AxisTickCalculator {
private void calculate(ChartPainter chart) {
// tick space - a percentage of the working space available for ticks, i.e. 95%
int tickSpace = AxisPair.getTickSpace(workingSpace); // in plot space
int tickSpace = Utils.getTickSpace(workingSpace); // in plot space
// where the tick should begin in the working space in pixels
int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
// get all categories
Set<Object> categories = new TreeSet<Object>();
......
......@@ -24,6 +24,7 @@ package com.xeiam.xchart.internal.chartpart;
import java.math.BigDecimal;
import com.xeiam.xchart.StyleManager;
import com.xeiam.xchart.internal.Utils;
import com.xeiam.xchart.internal.chartpart.Axis.Direction;
/**
......@@ -54,10 +55,10 @@ public class AxisTickDateCalculator extends AxisTickCalculator {
private void calculate() {
// tick space - a percentage of the working space available for ticks, i.e. 95%
int tickSpace = AxisPair.getTickSpace(workingSpace); // in plot space
int tickSpace = Utils.getTickSpace(workingSpace); // in plot space
// where the tick should begin in the working space in pixels
int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
// the span of the data
long span = Math.abs(maxValue.subtract(minValue).longValue()); // in data space
......
......@@ -62,10 +62,10 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator {
}
// tick space - a percentage of the working space available for ticks, i.e. 95%
int tickSpace = AxisPair.getTickSpace(workingSpace); // in plot space
int tickSpace = Utils.getTickSpace(workingSpace); // in plot space
// where the tick should begin in the working space in pixels
int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
int logMin = (int) Math.floor(Math.log10(minValue.doubleValue()));
int logMax = (int) Math.ceil(Math.log10(maxValue.doubleValue()));
......
......@@ -62,10 +62,10 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
}
// tick space - a percentage of the working space available for ticks, i.e. 95%
int tickSpace = AxisPair.getTickSpace(workingSpace); // in plot space
int tickSpace = Utils.getTickSpace(workingSpace); // in plot space
// where the tick should begin in the working space in pixels
int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
int margin = Utils.getTickStartOffset(workingSpace, tickSpace); // in plot space BigDecimal gridStep = getGridStepForDecimal(tickSpace);
BigDecimal gridStep = getGridStep(tickSpace);
BigDecimal firstPosition = getFirstPosition(gridStep);
......
......@@ -25,6 +25,7 @@ import java.util.Set;
import java.util.TreeSet;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.internal.Utils;
/**
* @author timmolter
......@@ -47,12 +48,12 @@ public class PlotContentBarChart extends PlotContent {
Rectangle bounds = plot.getBounds();
// X-Axis
int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth());
int xLeftMargin = AxisPair.getTickStartOffset((int) bounds.getWidth(), xTickSpace);
int xTickSpace = Utils.getTickSpace((int) bounds.getWidth());
int xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace);
// Y-Axis
int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight());
int yTopMargin = AxisPair.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
int yTickSpace = Utils.getTickSpace((int) bounds.getHeight());
int yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
// get all categories
Set<Object> categories = new TreeSet<Object>();
......
......@@ -25,6 +25,7 @@ import java.util.Map;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.StyleManager.ChartType;
import com.xeiam.xchart.internal.Utils;
import com.xeiam.xchart.internal.chartpart.Axis.AxisType;
/**
......@@ -48,12 +49,12 @@ public class PlotContentLineChart extends PlotContent {
Rectangle bounds = plot.getBounds();
// X-Axis
int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth());
int xLeftMargin = AxisPair.getTickStartOffset((int) bounds.getWidth(), xTickSpace);
int xTickSpace = Utils.getTickSpace((int) bounds.getWidth());
int xLeftMargin = Utils.getTickStartOffset((int) bounds.getWidth(), xTickSpace);
// Y-Axis
int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight());
int yTopMargin = AxisPair.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
int yTickSpace = Utils.getTickSpace((int) bounds.getHeight());
int yTopMargin = Utils.getTickStartOffset((int) bounds.getHeight(), yTickSpace);
Map<Integer, Series> seriesMap = getChartPainter().getAxisPair().getSeriesMap();
for (Integer seriesId : seriesMap.keySet()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment