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

added ticker marks below and above min and max values if with a certain tolerance.

parent 20d3f843
No related branches found
No related tags found
No related merge requests found
...@@ -53,16 +53,16 @@ public class DateChart03 implements ExampleChart { ...@@ -53,16 +53,16 @@ public class DateChart03 implements ExampleChart {
Random random = new Random(); Random random = new Random();
DateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss.SSS");
Date date = null; Date date = null;
for (int i = 1; i <= 14; i++) { for (int i = 1; i <= 14; i++) {
try { try {
date = sdf.parse("08:" + (5 * i + random.nextInt(2)) + ":" + (random.nextInt(2)) + "." + random.nextInt(1000)); date = sdf.parse("2013-07-22-08:" + (5 * i + random.nextInt(2)) + ":" + (random.nextInt(2)) + "." + random.nextInt(1000));
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
// System.out.println(date.getTime()); System.out.println(date.getTime());
// System.out.println(date.toString()); System.out.println(date.toString());
xData.add(date); xData.add(date);
yData.add(Math.random() * i); yData.add(Math.random() * i);
} }
......
...@@ -55,7 +55,7 @@ public class ScatterChart02 implements ExampleChart { ...@@ -55,7 +55,7 @@ public class ScatterChart02 implements ExampleChart {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
double nextRandom = random.nextDouble(); double nextRandom = random.nextDouble();
xData.add(Math.pow(10, nextRandom * 10)); xData.add(Math.pow(10, nextRandom * 10));
yData.add(nextRandom + random.nextDouble()); yData.add(1000000000.0 + nextRandom + random.nextDouble());
} }
// Create Chart // Create Chart
......
...@@ -87,10 +87,10 @@ public class Histogram { ...@@ -87,10 +87,10 @@ public class Histogram {
int bin = (int) ((((Number) itr.next()).doubleValue() - min) / binSize); // changed this from numBins int bin = (int) ((((Number) itr.next()).doubleValue() - min) / binSize); // changed this from numBins
if (bin < 0) { /* this data is smaller than min */ if (bin < 0) { /* this data is smaller than min */
System.out.println("less than"); // System.out.println("less than");
} }
else if (bin > numBins) { /* this data point is bigger than max */ else if (bin > numBins) { /* this data point is bigger than max */
System.out.println("greater than"); // System.out.println("greater than");
} }
else if (bin == numBins) { // this falls right on the edge of the max bin else if (bin == numBins) { // this falls right on the edge of the max bin
tempYAxisData[bin - 1] += 1; tempYAxisData[bin - 1] += 1;
......
...@@ -100,13 +100,16 @@ public abstract class AxisTickCalculator { ...@@ -100,13 +100,16 @@ public abstract class AxisTickCalculator {
*/ */
double getFirstPosition(double gridStep) { double getFirstPosition(double gridStep) {
double firstPosition; // System.out.println("******");
if (minValue % gridStep <= 0.0) {
double firstPosition = minValue - (minValue % gridStep) + gridStep;
// System.out.println(firstPosition - minValue);
// System.out.println(.9 * gridStep);
if ((firstPosition - minValue) > .8 * gridStep) {
firstPosition = minValue - (minValue % gridStep); firstPosition = minValue - (minValue % gridStep);
} }
else {
firstPosition = minValue - (minValue % gridStep) + gridStep;
}
return firstPosition; return firstPosition;
} }
......
...@@ -47,7 +47,7 @@ public class AxisTickDateCalculator extends AxisTickCalculator { ...@@ -47,7 +47,7 @@ public class AxisTickDateCalculator extends AxisTickCalculator {
private void calculate() { private void calculate() {
// tick space - a percentage of the working space available for ticks // 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 // where the tick should begin in the working space in pixels
double 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);
...@@ -55,7 +55,7 @@ public class AxisTickDateCalculator extends AxisTickCalculator { ...@@ -55,7 +55,7 @@ public class AxisTickDateCalculator extends AxisTickCalculator {
// the span of the data // the span of the data
long span = (long) Math.abs(maxValue - minValue); // in data space long span = (long) Math.abs(maxValue - minValue); // in data space
long gridStepHint = (long) (span / (double) tickSpace * styleManager.getXAxisTickMarkSpacingHint()); long gridStepHint = (long) (span / tickSpace * styleManager.getXAxisTickMarkSpacingHint());
long timeUnit = dateFormatter.getTimeUnit(gridStepHint); long timeUnit = dateFormatter.getTimeUnit(gridStepHint);
double gridStep = 0.0; double gridStep = 0.0;
...@@ -74,7 +74,7 @@ public class AxisTickDateCalculator extends AxisTickCalculator { ...@@ -74,7 +74,7 @@ public class AxisTickDateCalculator extends AxisTickCalculator {
tickLabels.add(dateFormatter.formatDate(tickPosition, timeUnit)); tickLabels.add(dateFormatter.formatDate(tickPosition, timeUnit));
// here we convert tickPosition finally to plot space, i.e. pixels // here we convert tickPosition finally to plot space, i.e. pixels
double tickLabelPosition = (int) (margin + ((tickPosition - minValue) / (maxValue - minValue) * tickSpace)); double tickLabelPosition = margin + ((tickPosition - minValue) / (maxValue - minValue) * tickSpace);
tickLocations.add(tickLabelPosition); tickLocations.add(tickLabelPosition);
} }
} }
......
...@@ -93,18 +93,18 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator { ...@@ -93,18 +93,18 @@ public class AxisTickLogarithmicCalculator extends AxisTickCalculator {
// System.out.println("i: " + i); // System.out.println("i: " + i);
// System.out.println("pow(10, i).doubleValue(): " + pow(10, i).doubleValue()); // System.out.println("pow(10, i).doubleValue(): " + pow(10, i).doubleValue());
// using trhe .00000001 factor to dal with double value imprecision // using the .00000001 factor to deal with double value imprecision
for (double j = firstPosition; j <= Utils.pow(10, i) + .00000001; j = j + tickStep) { for (double j = firstPosition; j <= Utils.pow(10, i) + .00000001; j = j + tickStep) {
// System.out.println("j: " + j); // System.out.println("j: " + j);
// System.out.println(Math.log10(j) % 1); // System.out.println(Math.log10(j) % 1);
if (j < minValue) { if (j < minValue - tickStep * .2) {
// System.out.println("continue"); // System.out.println("continue");
continue; continue;
} }
if (j > maxValue) { if (j > maxValue + tickStep * 1.2) {
// System.out.println("break"); // System.out.println("break");
break; break;
} }
......
...@@ -65,7 +65,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator { ...@@ -65,7 +65,7 @@ public class AxisTickNumericalCalculator extends AxisTickCalculator {
BigDecimal firstPosition = BigDecimal.valueOf(getFirstPosition(gridStep.doubleValue())); BigDecimal firstPosition = BigDecimal.valueOf(getFirstPosition(gridStep.doubleValue()));
// 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 = firstPosition; tickPosition.compareTo(BigDecimal.valueOf(maxValue)) <= 0; tickPosition = tickPosition.add(gridStep)) { for (BigDecimal tickPosition = firstPosition; tickPosition.compareTo(BigDecimal.valueOf(maxValue + gridStep.doubleValue() * 0.8)) <= 0; tickPosition = tickPosition.add(gridStep)) {
tickLabels.add(numberFormatter.formatNumber(tickPosition.doubleValue())); tickLabels.add(numberFormatter.formatNumber(tickPosition.doubleValue()));
// here we convert tickPosition finally to plot space, i.e. pixels // here we convert tickPosition finally to plot space, i.e. pixels
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment