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

Merge pull request #92 from hwaipy/develop

Improved class Histogram
parents b1d80c00 95ef9177
Branches
No related tags found
No related merge requests found
...@@ -17,7 +17,6 @@ package com.xeiam.xchart; ...@@ -17,7 +17,6 @@ package com.xeiam.xchart;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -46,14 +45,19 @@ public class Histogram { ...@@ -46,14 +45,19 @@ public class Histogram {
this.numBins = numBins; this.numBins = numBins;
this.originalData = data; this.originalData = data;
List<Double> dataAsList = new ArrayList<Double>(); Double tempMax = Double.MIN_VALUE;
Iterator<? extends Number> itr = data.iterator(); Double tempMin = Double.MAX_VALUE;
while (itr.hasNext()) { for (Number number : data) {
dataAsList.add(((Number) itr.next()).doubleValue()); double value = number.doubleValue();
if (value > tempMax) {
tempMax = value;
}
if (value < tempMin) {
tempMin = value;
}
} }
Collections.sort(dataAsList); max = tempMax;
this.min = dataAsList.get(0); min = tempMin;
this.max = dataAsList.get(dataAsList.size() - 1);
init(); init();
} }
...@@ -92,8 +96,7 @@ public class Histogram { ...@@ -92,8 +96,7 @@ public class Histogram {
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 on the next bin of the max bin
tempYAxisData[bin - 1] += 1;
} }
else { else {
tempYAxisData[bin] += 1; tempYAxisData[bin] += 1;
...@@ -101,7 +104,7 @@ public class Histogram { ...@@ -101,7 +104,7 @@ public class Histogram {
} }
yAxisData = new ArrayList<Double>(numBins); yAxisData = new ArrayList<Double>(numBins);
for (double d : tempYAxisData) { for (double d : tempYAxisData) {
yAxisData.add(new Double(d)); yAxisData.add(d);
} }
// x axis data // x axis data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment