use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class StatisticalLineAndShapeRenderer 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 (a {@link StatisticalCategoryDataset} is
* required).
* @param row the row index (zero-based).
* @param column the column index (zero-based).
* @param pass the pass.
*/
@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;
}
// to the superclass (LineAndShapeRenderer) behaviour...
if (!(dataset instanceof StatisticalCategoryDataset)) {
super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
return;
}
int visibleRow = state.getVisibleSeriesIndex(row);
if (visibleRow < 0) {
return;
}
int visibleRowCount = state.getVisibleSeriesCount();
StatisticalCategoryDataset statDataset = (StatisticalCategoryDataset) dataset;
Number meanValue = statDataset.getMeanValue(row, column);
if (meanValue == null) {
return;
}
PlotOrientation orientation = plot.getOrientation();
// current data point...
double x1;
if (getUseSeriesOffset()) {
x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
} else {
x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
}
double y1 = rangeAxis.valueToJava2D(meanValue.doubleValue(), dataArea, plot.getRangeAxisEdge());
// draw the standard deviation lines *before* the shapes (if they're
// visible) - it looks better if the shape fill colour is different to
// the line colour
Number sdv = statDataset.getStdDevValue(row, column);
if (pass == 1 && sdv != null) {
// standard deviation lines
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double valueDelta = sdv.doubleValue();
double highVal, lowVal;
if ((meanValue.doubleValue() + valueDelta) > rangeAxis.getRange().getUpperBound()) {
highVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getUpperBound(), dataArea, yAxisLocation);
} else {
highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + valueDelta, dataArea, yAxisLocation);
}
if ((meanValue.doubleValue() + valueDelta) < rangeAxis.getRange().getLowerBound()) {
lowVal = rangeAxis.valueToJava2D(rangeAxis.getRange().getLowerBound(), dataArea, yAxisLocation);
} else {
lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - valueDelta, dataArea, yAxisLocation);
}
if (this.errorIndicatorPaint != null) {
g2.setPaint(this.errorIndicatorPaint);
} else {
g2.setPaint(getItemPaint(row, column));
}
if (this.errorIndicatorStroke != null) {
g2.setStroke(this.errorIndicatorStroke);
} else {
g2.setStroke(getItemOutlineStroke(row, column));
}
Line2D line = new Line2D.Double();
if (orientation == PlotOrientation.HORIZONTAL) {
line.setLine(lowVal, x1, highVal, x1);
g2.draw(line);
line.setLine(lowVal, x1 - 5.0d, lowVal, x1 + 5.0d);
g2.draw(line);
line.setLine(highVal, x1 - 5.0d, highVal, x1 + 5.0d);
g2.draw(line);
} else {
// PlotOrientation.VERTICAL
line.setLine(x1, lowVal, x1, highVal);
g2.draw(line);
line.setLine(x1 - 5.0d, highVal, x1 + 5.0d, highVal);
g2.draw(line);
line.setLine(x1 - 5.0d, lowVal, x1 + 5.0d, lowVal);
g2.draw(line);
}
}
Shape hotspot = null;
if (pass == 1 && getItemShapeVisible(row, column)) {
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);
}
hotspot = shape;
if (getItemShapeFilled(row, column)) {
if (getUseFillPaint()) {
g2.setPaint(getItemFillPaint(row, column));
} else {
g2.setPaint(getItemPaint(row, column));
}
g2.fill(shape);
}
if (getDrawOutlines()) {
if (getUseOutlinePaint()) {
g2.setPaint(getItemOutlinePaint(row, column));
} else {
g2.setPaint(getItemPaint(row, column));
}
g2.setStroke(getItemOutlineStroke(row, column));
g2.draw(shape);
}
// draw the item label if there is one...
if (isItemLabelVisible(row, column)) {
if (orientation == PlotOrientation.HORIZONTAL) {
drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (meanValue.doubleValue() < 0.0));
} else if (orientation == PlotOrientation.VERTICAL) {
drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (meanValue.doubleValue() < 0.0));
}
}
}
if (pass == 0 && getItemLineVisible(row, column)) {
if (column != 0) {
Number previousValue = statDataset.getValue(row, column - 1);
if (previousValue != null) {
// previous data point...
double previous = previousValue.doubleValue();
double x0;
if (getUseSeriesOffset()) {
x0 = domainAxis.getCategorySeriesMiddle(column - 1, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge());
} else {
x0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge());
}
double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge());
Line2D line = null;
if (orientation == PlotOrientation.HORIZONTAL) {
line = new Line2D.Double(y0, x0, y1, x1);
} else if (orientation == PlotOrientation.VERTICAL) {
line = new Line2D.Double(x0, y0, x1, y1);
}
g2.setPaint(getItemPaint(row, column));
g2.setStroke(getItemStroke(row, column));
g2.draw(line);
}
}
}
if (pass == 1) {
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, hotspot, dataset, row, column, x1, y1);
}
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class StatisticalBarRenderer method drawVerticalItem.
/**
* Draws an item for a plot with a vertical orientation.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the data area.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the data.
* @param visibleRow the visible row index.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
protected void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, StatisticalCategoryDataset dataset, int visibleRow, int row, int column) {
// BAR X
double rectX = calculateBarW0(plot, PlotOrientation.VERTICAL, dataArea, domainAxis, state, visibleRow, column);
// BAR Y
Number meanValue = dataset.getMeanValue(row, column);
if (meanValue == null) {
return;
}
double value = meanValue.doubleValue();
double base = 0.0;
double lclip = getLowerClip();
double uclip = getUpperClip();
if (uclip <= 0.0) {
// cases 1, 2, 3 and 4
if (value >= uclip) {
// bar is not visible
return;
}
base = uclip;
if (value <= lclip) {
value = lclip;
}
} else if (lclip <= 0.0) {
// cases 5, 6, 7 and 8
if (value >= uclip) {
value = uclip;
} else {
if (value <= lclip) {
value = lclip;
}
}
} else {
// cases 9, 10, 11 and 12
if (value <= lclip) {
// bar is not visible
return;
}
base = getLowerClip();
if (value >= uclip) {
value = uclip;
}
}
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
double rectY = Math.min(transY2, transY1);
double rectWidth = state.getBarWidth();
double rectHeight = Math.abs(transY2 - transY1);
Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
Paint itemPaint = getItemPaint(row, column);
GradientPaintTransformer t = getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = getItemOutlineStroke(row, column);
Paint paint = getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
// standard deviation lines
Number n = dataset.getStdDevValue(row, column);
if (n != null) {
double valueDelta = n.doubleValue();
double highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + valueDelta, dataArea, yAxisLocation);
double lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - valueDelta, dataArea, yAxisLocation);
if (this.errorIndicatorPaint != null) {
g2.setPaint(this.errorIndicatorPaint);
} else {
g2.setPaint(getItemOutlinePaint(row, column));
}
if (this.errorIndicatorStroke != null) {
g2.setStroke(this.errorIndicatorStroke);
} else {
g2.setStroke(getItemOutlineStroke(row, column));
}
Line2D line;
line = new Line2D.Double(rectX + rectWidth / 2.0d, lowVal, rectX + rectWidth / 2.0d, highVal);
g2.draw(line);
line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, rectX + rectWidth / 2.0d + 5.0d, highVal);
g2.draw(line);
line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, rectX + rectWidth / 2.0d + 5.0d, lowVal);
g2.draw(line);
}
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null && isItemLabelVisible(row, column)) {
drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
}
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, bar);
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class StatisticalBarRenderer method drawHorizontalItem.
/**
* Draws an item for a plot with a horizontal orientation.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the data area.
* @param plot the plot.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param dataset the data.
* @param visibleRow the visible row index.
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
protected void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, StatisticalCategoryDataset dataset, int visibleRow, int row, int column) {
// BAR Y
double rectY = calculateBarW0(plot, PlotOrientation.HORIZONTAL, dataArea, domainAxis, state, visibleRow, column);
// BAR X
Number meanValue = dataset.getMeanValue(row, column);
if (meanValue == null) {
return;
}
double value = meanValue.doubleValue();
double base = 0.0;
double lclip = getLowerClip();
double uclip = getUpperClip();
if (uclip <= 0.0) {
// cases 1, 2, 3 and 4
if (value >= uclip) {
// bar is not visible
return;
}
base = uclip;
if (value <= lclip) {
value = lclip;
}
} else if (lclip <= 0.0) {
// cases 5, 6, 7 and 8
if (value >= uclip) {
value = uclip;
} else {
if (value <= lclip) {
value = lclip;
}
}
} else {
// cases 9, 10, 11 and 12
if (value <= lclip) {
// bar is not visible
return;
}
base = getLowerClip();
if (value >= uclip) {
value = uclip;
}
}
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation);
double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation);
double rectX = Math.min(transY2, transY1);
double rectHeight = state.getBarWidth();
double rectWidth = Math.abs(transY2 - transY1);
Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight);
Paint itemPaint = getItemPaint(row, column);
GradientPaintTransformer t = getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
g2.fill(bar);
// draw the outline...
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
Stroke stroke = getItemOutlineStroke(row, column);
Paint paint = getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
// standard deviation lines
Number n = dataset.getStdDevValue(row, column);
if (n != null) {
double valueDelta = n.doubleValue();
double highVal = rangeAxis.valueToJava2D(meanValue.doubleValue() + valueDelta, dataArea, yAxisLocation);
double lowVal = rangeAxis.valueToJava2D(meanValue.doubleValue() - valueDelta, dataArea, yAxisLocation);
if (this.errorIndicatorPaint != null) {
g2.setPaint(this.errorIndicatorPaint);
} else {
g2.setPaint(getItemOutlinePaint(row, column));
}
if (this.errorIndicatorStroke != null) {
g2.setStroke(this.errorIndicatorStroke);
} else {
g2.setStroke(getItemOutlineStroke(row, column));
}
Line2D line;
line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, highVal, rectY + rectHeight / 2.0d);
g2.draw(line);
line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, highVal, rectY + rectHeight * 0.75);
g2.draw(line);
line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, lowVal, rectY + rectHeight * 0.75);
g2.draw(line);
}
CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
if (generator != null && isItemLabelVisible(row, column)) {
drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
}
// add an item entity, if this information is being collected
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, bar);
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class CandlestickRenderer method drawItem.
/**
* Draws the visual representation of a single data item.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the plot is being drawn.
* @param info collects info 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 (zero-based).
* @param item the item index (zero-based).
* @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) {
boolean horiz;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
horiz = true;
} else if (orientation == PlotOrientation.VERTICAL) {
horiz = false;
} else {
return;
}
// setup for collecting optional entity info...
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
OHLCDataset highLowData = (OHLCDataset) dataset;
double x = highLowData.getXValue(series, item);
double yHigh = highLowData.getHighValue(series, item);
double yLow = highLowData.getLowValue(series, item);
double yOpen = highLowData.getOpenValue(series, item);
double yClose = highLowData.getCloseValue(series, item);
RectangleEdge domainEdge = plot.getDomainAxisEdge();
double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge);
RectangleEdge edge = plot.getRangeAxisEdge();
double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge);
double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge);
double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge);
double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge);
double volumeWidth;
double stickWidth;
if (this.candleWidth > 0) {
// These are deliberately not bounded to minimums/maxCandleWidth to
// retain old behaviour.
volumeWidth = this.candleWidth;
stickWidth = this.candleWidth;
} else {
double xxWidth = 0;
int itemCount;
switch(this.autoWidthMethod) {
case WIDTHMETHOD_AVERAGE:
itemCount = highLowData.getItemCount(series);
if (horiz) {
xxWidth = dataArea.getHeight() / itemCount;
} else {
xxWidth = dataArea.getWidth() / itemCount;
}
break;
case WIDTHMETHOD_SMALLEST:
// Note: It would be nice to pre-calculate this per series
itemCount = highLowData.getItemCount(series);
double lastPos = -1;
xxWidth = dataArea.getWidth();
for (int i = 0; i < itemCount; i++) {
double pos = domainAxis.valueToJava2D(highLowData.getXValue(series, i), dataArea, domainEdge);
if (lastPos != -1) {
xxWidth = Math.min(xxWidth, Math.abs(pos - lastPos));
}
lastPos = pos;
}
break;
case WIDTHMETHOD_INTERVALDATA:
IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
double startPos = domainAxis.valueToJava2D(intervalXYData.getStartXValue(series, item), dataArea, plot.getDomainAxisEdge());
double endPos = domainAxis.valueToJava2D(intervalXYData.getEndXValue(series, item), dataArea, plot.getDomainAxisEdge());
xxWidth = Math.abs(endPos - startPos);
break;
}
xxWidth -= 2 * this.autoWidthGap;
xxWidth *= this.autoWidthFactor;
xxWidth = Math.min(xxWidth, this.maxCandleWidth);
volumeWidth = Math.max(Math.min(1, this.maxCandleWidth), xxWidth);
stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth);
}
Paint p = getItemPaint(series, item);
Paint outlinePaint = null;
if (this.useOutlinePaint) {
outlinePaint = getItemOutlinePaint(series, item);
}
Stroke s = getItemStroke(series, item);
g2.setStroke(s);
if (this.drawVolume) {
int volume = (int) highLowData.getVolumeValue(series, item);
double volumeHeight = volume / this.maxVolume;
double min, max;
if (horiz) {
min = dataArea.getMinX();
max = dataArea.getMaxX();
} else {
min = dataArea.getMinY();
max = dataArea.getMaxY();
}
double zzVolume = volumeHeight * (max - min);
g2.setPaint(getVolumePaint());
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
if (horiz) {
g2.fill(new Rectangle2D.Double(min, xx - volumeWidth / 2, zzVolume, volumeWidth));
} else {
g2.fill(new Rectangle2D.Double(xx - volumeWidth / 2, max - zzVolume, volumeWidth, zzVolume));
}
g2.setComposite(originalComposite);
}
if (this.useOutlinePaint) {
g2.setPaint(outlinePaint);
} else {
g2.setPaint(p);
}
double yyMaxOpenClose = Math.max(yyOpen, yyClose);
double yyMinOpenClose = Math.min(yyOpen, yyClose);
double maxOpenClose = Math.max(yOpen, yClose);
double minOpenClose = Math.min(yOpen, yClose);
// draw the upper shadow
if (yHigh > maxOpenClose) {
if (horiz) {
g2.draw(new Line2D.Double(yyHigh, xx, yyMaxOpenClose, xx));
} else {
g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose));
}
}
// draw the lower shadow
if (yLow < minOpenClose) {
if (horiz) {
g2.draw(new Line2D.Double(yyLow, xx, yyMinOpenClose, xx));
} else {
g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose));
}
}
// draw the body
Rectangle2D body;
Rectangle2D hotspot;
double length = Math.abs(yyHigh - yyLow);
double base = Math.min(yyHigh, yyLow);
if (horiz) {
body = new Rectangle2D.Double(yyMinOpenClose, xx - stickWidth / 2, yyMaxOpenClose - yyMinOpenClose, stickWidth);
hotspot = new Rectangle2D.Double(base, xx - stickWidth / 2, length, stickWidth);
} else {
body = new Rectangle2D.Double(xx - stickWidth / 2, yyMinOpenClose, stickWidth, yyMaxOpenClose - yyMinOpenClose);
hotspot = new Rectangle2D.Double(xx - stickWidth / 2, base, stickWidth, length);
}
if (yClose > yOpen) {
if (this.upPaint != null) {
g2.setPaint(this.upPaint);
} else {
g2.setPaint(p);
}
g2.fill(body);
} else {
if (this.downPaint != null) {
g2.setPaint(this.downPaint);
} else {
g2.setPaint(p);
}
g2.fill(body);
}
if (this.useOutlinePaint) {
g2.setPaint(outlinePaint);
} else {
g2.setPaint(p);
}
g2.draw(body);
// add an entity for the item...
if (entities != null) {
addEntity(entities, hotspot, dataset, series, item, 0.0, 0.0);
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class BoxAndWhiskerRenderer method drawVerticalItem.
/**
* Draws the visual representation of a single data item when the plot has
* a vertical orientation.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the plot is being drawn.
* @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 (must be an instance of
* {@link BoxAndWhiskerCategoryDataset}).
* @param row the row index (zero-based).
* @param column the column index (zero-based).
*/
public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) {
BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;
double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge());
double categoryWidth = categoryEnd - categoryStart;
double xx = categoryStart;
int seriesCount = getRowCount();
int categoryCount = getColumnCount();
if (seriesCount > 1) {
double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1));
// offset the start of the boxes if the total width used is smaller
// than the category width
double offset = (categoryWidth - usedWidth) / 2;
xx = xx + offset + (row * (state.getBarWidth() + seriesGap));
} else {
// offset the start of the box if the box width is smaller than the
// category width
double offset = (categoryWidth - state.getBarWidth()) / 2;
xx = xx + offset;
}
double yyAverage;
double yyOutlier;
Paint itemPaint = getItemPaint(row, column);
g2.setPaint(itemPaint);
Stroke s = getItemStroke(row, column);
g2.setStroke(s);
// average radius
double aRadius = 0;
RectangleEdge location = plot.getRangeAxisEdge();
Number yQ1 = bawDataset.getQ1Value(row, column);
Number yQ3 = bawDataset.getQ3Value(row, column);
Number yMax = bawDataset.getMaxRegularValue(row, column);
Number yMin = bawDataset.getMinRegularValue(row, column);
Shape box = null;
if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) {
double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location);
double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location);
double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);
double xxmid = xx + state.getBarWidth() / 2.0;
double halfW = (state.getBarWidth() / 2.0) * this.whiskerWidth;
// draw the body...
box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3));
if (this.fillBox) {
g2.fill(box);
}
Paint outlinePaint = getItemOutlinePaint(row, column);
if (this.useOutlinePaintForWhiskers) {
g2.setPaint(outlinePaint);
}
// draw the upper shadow...
g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
g2.draw(new Line2D.Double(xxmid - halfW, yyMax, xxmid + halfW, yyMax));
// draw the lower shadow...
g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
g2.draw(new Line2D.Double(xxmid - halfW, yyMin, xxmid + halfW, yyMin));
g2.setStroke(getItemOutlineStroke(row, column));
g2.setPaint(outlinePaint);
g2.draw(box);
}
g2.setPaint(this.artifactPaint);
// draw mean - SPECIAL AIMS REQUIREMENT...
if (this.meanVisible) {
Number yMean = bawDataset.getMeanValue(row, column);
if (yMean != null) {
yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location);
aRadius = state.getBarWidth() / 4;
// visible before drawing it...
if ((yyAverage > (dataArea.getMinY() - aRadius)) && (yyAverage < (dataArea.getMaxY() + aRadius))) {
Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx + aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2);
g2.fill(avgEllipse);
g2.draw(avgEllipse);
}
}
}
// draw median...
if (this.medianVisible) {
Number yMedian = bawDataset.getMedianValue(row, column);
if (yMedian != null) {
double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian));
}
}
// draw yOutliers...
double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius;
double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius;
g2.setPaint(itemPaint);
// draw outliers
// outlier radius
double oRadius = state.getBarWidth() / 3;
List outliers = new ArrayList();
OutlierListCollection outlierListCollection = new OutlierListCollection();
// From outlier array sort out which are outliers and put these into a
// list If there are any farouts, set the flag on the
// OutlierListCollection
List yOutliers = bawDataset.getOutliers(row, column);
if (yOutliers != null) {
for (int i = 0; i < yOutliers.size(); i++) {
double outlier = ((Number) yOutliers.get(i)).doubleValue();
Number minOutlier = bawDataset.getMinOutlier(row, column);
Number maxOutlier = bawDataset.getMaxOutlier(row, column);
Number minRegular = bawDataset.getMinRegularValue(row, column);
Number maxRegular = bawDataset.getMaxRegularValue(row, column);
if (outlier > maxOutlier.doubleValue()) {
outlierListCollection.setHighFarOut(true);
} else if (outlier < minOutlier.doubleValue()) {
outlierListCollection.setLowFarOut(true);
} else if (outlier > maxRegular.doubleValue()) {
yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius));
} else if (outlier < minRegular.doubleValue()) {
yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius));
}
Collections.sort(outliers);
}
// appropriate outlier list or a new outlier list is made
for (Iterator iterator = outliers.iterator(); iterator.hasNext(); ) {
Outlier outlier = (Outlier) iterator.next();
outlierListCollection.add(outlier);
}
for (Iterator iterator = outlierListCollection.iterator(); iterator.hasNext(); ) {
OutlierList list = (OutlierList) iterator.next();
Outlier outlier = list.getAveragedOutlier();
Point2D point = outlier.getPoint();
if (list.isMultiple()) {
drawMultipleEllipse(point, state.getBarWidth(), oRadius, g2);
} else {
drawEllipse(point, oRadius, g2);
}
}
// draw farout indicators
if (outlierListCollection.isHighFarOut()) {
drawHighFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, maxAxisValue);
}
if (outlierListCollection.isLowFarOut()) {
drawLowFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, minAxisValue);
}
}
// collect entity and tool tip information...
if (state.getInfo() != null && box != null) {
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addItemEntity(entities, dataset, row, column, box);
}
}
}
Aggregations