use of org.jfree.data.statistics.MultiValueCategoryDataset in project SIMVA-SoS by SESoS.
the class DatasetUtilities method iterateToFindRangeBounds.
/**
* Iterates over the data item of the category dataset to find
* the range bounds.
*
* @param dataset the dataset (<code>null</code> not permitted).
* @param includeInterval a flag that determines whether or not the
* y-interval is taken into account.
* @param visibleSeriesKeys the visible series keys.
*
* @return The range (possibly <code>null</code>).
*
* @since 1.0.13
*/
public static Range iterateToFindRangeBounds(CategoryDataset dataset, List visibleSeriesKeys, boolean includeInterval) {
ParamChecks.nullNotPermitted(dataset, "dataset");
ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");
double minimum = Double.POSITIVE_INFINITY;
double maximum = Double.NEGATIVE_INFINITY;
int columnCount = dataset.getColumnCount();
if (includeInterval && dataset instanceof BoxAndWhiskerCategoryDataset) {
// handle special case of BoxAndWhiskerDataset
BoxAndWhiskerCategoryDataset bx = (BoxAndWhiskerCategoryDataset) dataset;
Iterator iterator = visibleSeriesKeys.iterator();
while (iterator.hasNext()) {
Comparable seriesKey = (Comparable) iterator.next();
int series = dataset.getRowIndex(seriesKey);
int itemCount = dataset.getColumnCount();
for (int item = 0; item < itemCount; item++) {
Number lvalue = bx.getMinRegularValue(series, item);
if (lvalue == null) {
lvalue = bx.getValue(series, item);
}
Number uvalue = bx.getMaxRegularValue(series, item);
if (uvalue == null) {
uvalue = bx.getValue(series, item);
}
if (lvalue != null) {
minimum = Math.min(minimum, lvalue.doubleValue());
}
if (uvalue != null) {
maximum = Math.max(maximum, uvalue.doubleValue());
}
}
}
} else if (includeInterval && dataset instanceof IntervalCategoryDataset) {
// handle the special case where the dataset has y-intervals that
// we want to measure
IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
Number lvalue, uvalue;
Iterator iterator = visibleSeriesKeys.iterator();
while (iterator.hasNext()) {
Comparable seriesKey = (Comparable) iterator.next();
int series = dataset.getRowIndex(seriesKey);
for (int column = 0; column < columnCount; column++) {
lvalue = icd.getStartValue(series, column);
uvalue = icd.getEndValue(series, column);
if (lvalue != null && !Double.isNaN(lvalue.doubleValue())) {
minimum = Math.min(minimum, lvalue.doubleValue());
}
if (uvalue != null && !Double.isNaN(uvalue.doubleValue())) {
maximum = Math.max(maximum, uvalue.doubleValue());
}
}
}
} else if (includeInterval && dataset instanceof MultiValueCategoryDataset) {
// handle the special case where the dataset has y-intervals that
// we want to measure
MultiValueCategoryDataset mvcd = (MultiValueCategoryDataset) dataset;
Iterator iterator = visibleSeriesKeys.iterator();
while (iterator.hasNext()) {
Comparable seriesKey = (Comparable) iterator.next();
int series = dataset.getRowIndex(seriesKey);
for (int column = 0; column < columnCount; column++) {
List values = mvcd.getValues(series, column);
Iterator valueIterator = values.iterator();
while (valueIterator.hasNext()) {
Object o = valueIterator.next();
if (o instanceof Number) {
double v = ((Number) o).doubleValue();
if (!Double.isNaN(v)) {
minimum = Math.min(minimum, v);
maximum = Math.max(maximum, v);
}
}
}
}
}
} else if (includeInterval && dataset instanceof StatisticalCategoryDataset) {
// handle the special case where the dataset has y-intervals that
// we want to measure
StatisticalCategoryDataset scd = (StatisticalCategoryDataset) dataset;
Iterator iterator = visibleSeriesKeys.iterator();
while (iterator.hasNext()) {
Comparable seriesKey = (Comparable) iterator.next();
int series = dataset.getRowIndex(seriesKey);
for (int column = 0; column < columnCount; column++) {
Number meanN = scd.getMeanValue(series, column);
if (meanN != null) {
double std = 0.0;
Number stdN = scd.getStdDevValue(series, column);
if (stdN != null) {
std = stdN.doubleValue();
if (Double.isNaN(std)) {
std = 0.0;
}
}
double mean = meanN.doubleValue();
if (!Double.isNaN(mean)) {
minimum = Math.min(minimum, mean - std);
maximum = Math.max(maximum, mean + std);
}
}
}
}
} else {
// handle the standard case (plain CategoryDataset)
Iterator iterator = visibleSeriesKeys.iterator();
while (iterator.hasNext()) {
Comparable seriesKey = (Comparable) iterator.next();
int series = dataset.getRowIndex(seriesKey);
for (int column = 0; column < columnCount; column++) {
Number value = dataset.getValue(series, column);
if (value != null) {
double v = value.doubleValue();
if (!Double.isNaN(v)) {
minimum = Math.min(minimum, v);
maximum = Math.max(maximum, v);
}
}
}
}
}
if (minimum == Double.POSITIVE_INFINITY) {
return null;
} else {
return new Range(minimum, maximum);
}
}
use of org.jfree.data.statistics.MultiValueCategoryDataset in project SIMVA-SoS by SESoS.
the class ScatterRenderer method drawItem.
/**
* Draw a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area in which the data is drawn.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
* @param pass the pass index.
*/
@Override
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {
// do nothing if item is not visible
if (!getItemVisible(row, column)) {
return;
}
int visibleRow = state.getVisibleSeriesIndex(row);
if (visibleRow < 0) {
return;
}
int visibleRowCount = state.getVisibleSeriesCount();
PlotOrientation orientation = plot.getOrientation();
MultiValueCategoryDataset d = (MultiValueCategoryDataset) dataset;
List values = d.getValues(row, column);
if (values == null) {
return;
}
int valueCount = values.size();
for (int i = 0; i < valueCount; i++) {
// current data point...
double x1;
if (this.useSeriesOffset) {
x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount, this.itemMargin, dataArea, plot.getDomainAxisEdge());
} else {
x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
}
Number n = (Number) values.get(i);
double value = n.doubleValue();
double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
Shape shape = getItemShape(row, column);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, y1, x1);
} else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, x1, y1);
}
if (getItemShapeFilled(row, column)) {
if (this.useFillPaint) {
g2.setPaint(getItemFillPaint(row, column));
} else {
g2.setPaint(getItemPaint(row, column));
}
g2.fill(shape);
}
if (this.drawOutlines) {
if (this.useOutlinePaint) {
g2.setPaint(getItemOutlinePaint(row, column));
} else {
g2.setPaint(getItemPaint(row, column));
}
g2.setStroke(getItemOutlineStroke(row, column));
g2.draw(shape);
}
}
}
Aggregations