use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.
the class DatasetUtilities method findMinimumDomainValue.
/**
* Finds the minimum domain (or X) value for the specified dataset. This
* is easy if the dataset implements the {@link DomainInfo} interface (a
* good idea if there is an efficient way to determine the minimum value).
* Otherwise, it involves iterating over the entire data-set.
* <p>
* Returns <code>null</code> if all the data values in the dataset are
* <code>null</code>.
*
* @param dataset the dataset (<code>null</code> not permitted).
*
* @return The minimum value (possibly <code>null</code>).
*/
public static Number findMinimumDomainValue(XYDataset dataset) {
ParamChecks.nullNotPermitted(dataset, "dataset");
Number result;
// if the dataset implements DomainInfo, life is easy
if (dataset instanceof DomainInfo) {
DomainInfo info = (DomainInfo) dataset;
return new Double(info.getDomainLowerBound(true));
} else {
double minimum = Double.POSITIVE_INFINITY;
int seriesCount = dataset.getSeriesCount();
for (int series = 0; series < seriesCount; series++) {
int itemCount = dataset.getItemCount(series);
for (int item = 0; item < itemCount; item++) {
double value;
if (dataset instanceof IntervalXYDataset) {
IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
value = intervalXYData.getStartXValue(series, item);
} else {
value = dataset.getXValue(series, item);
}
if (!Double.isNaN(value)) {
minimum = Math.min(minimum, value);
}
}
}
if (minimum == Double.POSITIVE_INFINITY) {
result = null;
} else {
result = new Double(minimum);
}
}
return result;
}
use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.
the class DatasetUtilities method findMaximumRangeValue.
/**
* Returns the maximum range value for the specified dataset. This is
* easy if the dataset implements the {@link RangeInfo} interface (a good
* idea if there is an efficient way to determine the maximum value).
* Otherwise, it involves iterating over the entire data-set. Returns
* <code>null</code> if all the data values are <code>null</code>.
*
* @param dataset the dataset (<code>null</code> not permitted).
*
* @return The maximum value (possibly <code>null</code>).
*/
public static Number findMaximumRangeValue(XYDataset dataset) {
ParamChecks.nullNotPermitted(dataset, "dataset");
// work out the minimum value...
if (dataset instanceof RangeInfo) {
RangeInfo info = (RangeInfo) dataset;
return new Double(info.getRangeUpperBound(true));
} else // hasn't implemented RangeInfo, so we'll have to iterate...
{
double maximum = Double.NEGATIVE_INFINITY;
int seriesCount = dataset.getSeriesCount();
for (int series = 0; series < seriesCount; series++) {
int itemCount = dataset.getItemCount(series);
for (int item = 0; item < itemCount; item++) {
double value;
if (dataset instanceof IntervalXYDataset) {
IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
value = intervalXYData.getEndYValue(series, item);
} else if (dataset instanceof OHLCDataset) {
OHLCDataset highLowData = (OHLCDataset) dataset;
value = highLowData.getHighValue(series, item);
} else {
value = dataset.getYValue(series, item);
}
if (!Double.isNaN(value)) {
maximum = Math.max(maximum, value);
}
}
}
if (maximum == Double.NEGATIVE_INFINITY) {
return null;
} else {
return new Double(maximum);
}
}
}
use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.
the class XYBarChartTest method createChart.
/**
* Create a horizontal bar chart with sample data in the range -3 to +3.
*
* @return The chart.
*/
private static JFreeChart createChart() {
XYSeries series1 = new XYSeries("Series 1");
series1.add(1.0, 1.0);
series1.add(2.0, 2.0);
series1.add(3.0, 3.0);
IntervalXYDataset dataset = new XYBarDataset(new XYSeriesCollection(series1), 1.0);
return ChartFactory.createXYBarChart("XY Bar Chart", "Domain", false, "Range", dataset);
}
use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.
the class XYErrorRenderer method drawItem.
/**
* Draws the visual representation for one data item.
*
* @param g2 the graphics output target.
* @param state the renderer state.
* @param dataArea the data area.
* @param info the plot rendering info.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param series the series index.
* @param item the item index.
* @param crosshairState the crosshair state.
* @param pass the pass index.
*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
if (pass == 0 && dataset instanceof IntervalXYDataset && getItemVisible(series, item)) {
IntervalXYDataset ixyd = (IntervalXYDataset) dataset;
PlotOrientation orientation = plot.getOrientation();
if (this.drawXError) {
// draw the error bar for the x-interval
double x0 = ixyd.getStartXValue(series, item);
double x1 = ixyd.getEndXValue(series, item);
double y = ixyd.getYValue(series, item);
RectangleEdge edge = plot.getDomainAxisEdge();
double xx0 = domainAxis.valueToJava2D(x0, dataArea, edge);
double xx1 = domainAxis.valueToJava2D(x1, dataArea, edge);
double yy = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
Line2D line;
Line2D cap1;
Line2D cap2;
double adj = this.capLength / 2.0;
if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(xx0, yy, xx1, yy);
cap1 = new Line2D.Double(xx0, yy - adj, xx0, yy + adj);
cap2 = new Line2D.Double(xx1, yy - adj, xx1, yy + adj);
} else {
// PlotOrientation.HORIZONTAL
line = new Line2D.Double(yy, xx0, yy, xx1);
cap1 = new Line2D.Double(yy - adj, xx0, yy + adj, xx0);
cap2 = new Line2D.Double(yy - adj, xx1, yy + adj, xx1);
}
if (this.errorPaint != null) {
g2.setPaint(this.errorPaint);
} else {
g2.setPaint(getItemPaint(series, item));
}
if (this.errorStroke != null) {
g2.setStroke(this.errorStroke);
} else {
g2.setStroke(getItemStroke(series, item));
}
g2.draw(line);
g2.draw(cap1);
g2.draw(cap2);
}
if (this.drawYError) {
// draw the error bar for the y-interval
double y0 = ixyd.getStartYValue(series, item);
double y1 = ixyd.getEndYValue(series, item);
double x = ixyd.getXValue(series, item);
RectangleEdge edge = plot.getRangeAxisEdge();
double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge);
double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge);
double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
Line2D line;
Line2D cap1;
Line2D cap2;
double adj = this.capLength / 2.0;
if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(xx, yy0, xx, yy1);
cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0);
cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1);
} else {
// PlotOrientation.HORIZONTAL
line = new Line2D.Double(yy0, xx, yy1, xx);
cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj);
cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj);
}
if (this.errorPaint != null) {
g2.setPaint(this.errorPaint);
} else {
g2.setPaint(getItemPaint(series, item));
}
if (this.errorStroke != null) {
g2.setStroke(this.errorStroke);
} else {
g2.setStroke(getItemStroke(series, item));
}
g2.draw(line);
g2.draw(cap1);
g2.draw(cap2);
}
}
super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass);
}
use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.
the class ClusteredXYBarRenderer method drawItem.
/**
* Draws the visual representation of a single data item. This method
* is mostly copied from the superclass, the change is that in the
* calculated space for a singe bar we draw bars for each series next to
* each other. The width of each bar is the available width divided by
* the number of series. Bars for each series are drawn in order left to
* right.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the plot is being drawn.
* @param info collects information about the drawing.
* @param plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param series the series index.
* @param item the item index.
* @param crosshairState crosshair information for the plot
* (<code>null</code> permitted).
* @param pass the pass index.
*/
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
double y0;
double y1;
if (getUseYInterval()) {
y0 = intervalDataset.getStartYValue(series, item);
y1 = intervalDataset.getEndYValue(series, item);
} else {
y0 = getBase();
y1 = intervalDataset.getYValue(series, item);
}
if (Double.isNaN(y0) || Double.isNaN(y1)) {
return;
}
double yy0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());
double yy1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
double x0 = intervalDataset.getStartXValue(series, item);
double xx0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double x1 = intervalDataset.getEndXValue(series, item);
double xx1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
// this may be negative
double intervalW = xx1 - xx0;
double baseX = xx0;
if (this.centerBarAtStartValue) {
baseX = baseX - intervalW / 2.0;
}
double m = getMargin();
if (m > 0.0) {
double cut = intervalW * getMargin();
intervalW = intervalW - cut;
baseX = baseX + (cut / 2);
}
// we don't need the sign
double intervalH = Math.abs(yy0 - yy1);
PlotOrientation orientation = plot.getOrientation();
int numSeries = dataset.getSeriesCount();
// may be negative
double seriesBarWidth = intervalW / numSeries;
Rectangle2D bar = null;
if (orientation == PlotOrientation.HORIZONTAL) {
double barY0 = baseX + (seriesBarWidth * series);
double barY1 = barY0 + seriesBarWidth;
double rx = Math.min(yy0, yy1);
double rw = intervalH;
double ry = Math.min(barY0, barY1);
double rh = Math.abs(barY1 - barY0);
bar = new Rectangle2D.Double(rx, ry, rw, rh);
} else if (orientation == PlotOrientation.VERTICAL) {
double barX0 = baseX + (seriesBarWidth * series);
double barX1 = barX0 + seriesBarWidth;
double rx = Math.min(barX0, barX1);
double rw = Math.abs(barX1 - barX0);
double ry = Math.min(yy0, yy1);
double rh = intervalH;
bar = new Rectangle2D.Double(rx, ry, rw, rh);
} else {
throw new IllegalStateException();
}
boolean positive = (y1 > 0.0);
boolean inverted = rangeAxis.isInverted();
RectangleEdge barBase;
if (orientation == PlotOrientation.HORIZONTAL) {
if (positive && inverted || !positive && !inverted) {
barBase = RectangleEdge.RIGHT;
} else {
barBase = RectangleEdge.LEFT;
}
} else {
if (positive && !inverted || !positive && inverted) {
barBase = RectangleEdge.BOTTOM;
} else {
barBase = RectangleEdge.TOP;
}
}
if (pass == 0 && getShadowsVisible()) {
getBarPainter().paintBarShadow(g2, this, series, item, bar, barBase, !getUseYInterval());
}
if (pass == 1) {
getBarPainter().paintBar(g2, this, series, item, bar, barBase);
if (isItemLabelVisible(series, item)) {
XYItemLabelGenerator generator = getItemLabelGenerator(series, item);
drawItemLabel(g2, dataset, series, item, plot, generator, bar, y1 < 0.0);
}
// add an entity for the item...
if (info != null) {
EntityCollection entities = info.getOwner().getEntityCollection();
if (entities != null) {
addEntity(entities, bar, dataset, series, item, bar.getCenterX(), bar.getCenterY());
}
}
}
}
Aggregations