use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class StatisticalBarRenderer method drawItem.
/**
* Draws the bar with its standard deviation line range for a single
* (series, category) data item.
*
* @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 data the data.
* @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 data, int row, int column, int pass) {
int visibleRow = state.getVisibleSeriesIndex(row);
if (visibleRow < 0) {
return;
}
// defensive check
if (!(data instanceof StatisticalCategoryDataset)) {
throw new IllegalArgumentException("Requires StatisticalCategoryDataset.");
}
StatisticalCategoryDataset statData = (StatisticalCategoryDataset) data;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
drawHorizontalItem(g2, state, dataArea, plot, domainAxis, rangeAxis, statData, visibleRow, row, column);
} else if (orientation == PlotOrientation.VERTICAL) {
drawVerticalItem(g2, state, dataArea, plot, domainAxis, rangeAxis, statData, visibleRow, row, column);
}
}
use of org.jfree.chart.plot.PlotOrientation 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.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class XYAreaRenderer 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 data 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 (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) {
if (!getItemVisible(series, item)) {
return;
}
XYAreaRendererState areaState = (XYAreaRendererState) state;
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1)) {
y1 = 0.0;
}
double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
// get the previous point and the next point so we can calculate a
// "hot spot" for the area (used by the chart entity)...
int itemCount = dataset.getItemCount(series);
double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
if (Double.isNaN(y0)) {
y0 = 0.0;
}
double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());
double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
if (Double.isNaN(y2)) {
y2 = 0.0;
}
double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge());
double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge());
double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
GeneralPath hotspot = new GeneralPath();
if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
moveTo(hotspot, transZero, ((transX0 + transX1) / 2.0));
lineTo(hotspot, ((transY0 + transY1) / 2.0), ((transX0 + transX1) / 2.0));
lineTo(hotspot, transY1, transX1);
lineTo(hotspot, ((transY1 + transY2) / 2.0), ((transX1 + transX2) / 2.0));
lineTo(hotspot, transZero, ((transX1 + transX2) / 2.0));
} else {
// vertical orientation
moveTo(hotspot, ((transX0 + transX1) / 2.0), transZero);
lineTo(hotspot, ((transX0 + transX1) / 2.0), ((transY0 + transY1) / 2.0));
lineTo(hotspot, transX1, transY1);
lineTo(hotspot, ((transX1 + transX2) / 2.0), ((transY1 + transY2) / 2.0));
lineTo(hotspot, ((transX1 + transX2) / 2.0), transZero);
}
hotspot.closePath();
if (item == 0) {
// create a new area polygon for the series
areaState.area = new GeneralPath();
// the first point is (x, 0)
double zero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
moveTo(areaState.area, transX1, zero);
} else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
moveTo(areaState.area, zero, transX1);
}
}
// Add each point to Area (x, y)
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
lineTo(areaState.area, transX1, transY1);
} else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
lineTo(areaState.area, transY1, transX1);
}
PlotOrientation orientation = plot.getOrientation();
Paint paint = getItemPaint(series, item);
Stroke stroke = getItemStroke(series, item);
g2.setPaint(paint);
g2.setStroke(stroke);
Shape shape;
if (getPlotShapes()) {
shape = getItemShape(series, item);
if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
} else if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
}
g2.draw(shape);
}
if (getPlotLines()) {
if (item > 0) {
if (plot.getOrientation() == PlotOrientation.VERTICAL) {
areaState.line.setLine(transX0, transY0, transX1, transY1);
} else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
areaState.line.setLine(transY0, transX0, transY1, transX1);
}
g2.draw(areaState.line);
}
}
// and number of items > 0. We can't draw an area for a single point.
if (getPlotArea() && item > 0 && item == (itemCount - 1)) {
if (orientation == PlotOrientation.VERTICAL) {
// Add the last point (x,0)
lineTo(areaState.area, transX1, transZero);
areaState.area.closePath();
} else if (orientation == PlotOrientation.HORIZONTAL) {
// Add the last point (x,0)
lineTo(areaState.area, transZero, transX1);
areaState.area.closePath();
}
if (this.useFillPaint) {
paint = lookupSeriesFillPaint(series);
}
if (paint instanceof GradientPaint) {
GradientPaint gp = (GradientPaint) paint;
GradientPaint adjGP = this.gradientTransformer.transform(gp, dataArea);
g2.setPaint(adjGP);
}
g2.fill(areaState.area);
// draw an outline around the Area.
if (isOutline()) {
Shape area = areaState.area;
// Java2D has some issues drawing dashed lines around "large"
// geometrical shapes - for example, see bug 6620013 in the
// Java bug database. So, we'll check if the outline is
// dashed and, if it is, do our own clipping before drawing
// the outline...
Stroke outlineStroke = lookupSeriesOutlineStroke(series);
if (outlineStroke instanceof BasicStroke) {
BasicStroke bs = (BasicStroke) outlineStroke;
if (bs.getDashArray() != null) {
Area poly = new Area(areaState.area);
// we make the clip region slightly larger than the
// dataArea so that the clipped edges don't show lines
// on the chart
Area clip = new Area(new Rectangle2D.Double(dataArea.getX() - 5.0, dataArea.getY() - 5.0, dataArea.getWidth() + 10.0, dataArea.getHeight() + 10.0));
poly.intersect(clip);
area = poly;
}
}
// end of workaround
g2.setStroke(outlineStroke);
g2.setPaint(lookupSeriesOutlinePaint(series));
g2.draw(area);
}
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
// collect entity and tool tip information...
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
addEntity(entities, hotspot, dataset, series, item, 0.0, 0.0);
}
}
use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class XYAreaRenderer2 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 data 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 (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) {
if (!getItemVisible(series, item)) {
return;
}
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1)) {
y1 = 0.0;
}
double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());
// get the previous point and the next point so we can calculate a
// "hot spot" for the area (used by the chart entity)...
double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
if (Double.isNaN(y0)) {
y0 = 0.0;
}
double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());
int itemCount = dataset.getItemCount(series);
double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
if (Double.isNaN(y2)) {
y2 = 0.0;
}
double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge());
double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge());
double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
GeneralPath hotspot = new GeneralPath();
if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
moveTo(hotspot, transZero, ((transX0 + transX1) / 2.0));
lineTo(hotspot, ((transY0 + transY1) / 2.0), ((transX0 + transX1) / 2.0));
lineTo(hotspot, transY1, transX1);
lineTo(hotspot, ((transY1 + transY2) / 2.0), ((transX1 + transX2) / 2.0));
lineTo(hotspot, transZero, ((transX1 + transX2) / 2.0));
} else {
// vertical orientation
moveTo(hotspot, ((transX0 + transX1) / 2.0), transZero);
lineTo(hotspot, ((transX0 + transX1) / 2.0), ((transY0 + transY1) / 2.0));
lineTo(hotspot, transX1, transY1);
lineTo(hotspot, ((transX1 + transX2) / 2.0), ((transY1 + transY2) / 2.0));
lineTo(hotspot, ((transX1 + transX2) / 2.0), transZero);
}
hotspot.closePath();
PlotOrientation orientation = plot.getOrientation();
Paint paint = getItemPaint(series, item);
Stroke stroke = getItemStroke(series, item);
g2.setPaint(paint);
g2.setStroke(stroke);
// Check if the item is the last item for the series.
// and number of items > 0. We can't draw an area for a single point.
g2.fill(hotspot);
// draw an outline around the Area.
if (isOutline()) {
g2.setStroke(lookupSeriesOutlineStroke(series));
g2.setPaint(lookupSeriesOutlinePaint(series));
g2.draw(hotspot);
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
// collect entity and tool tip information...
if (state.getInfo() != null) {
EntityCollection entities = state.getEntityCollection();
if (entities != null) {
String tip = null;
XYToolTipGenerator generator = getToolTipGenerator(series, item);
if (generator != null) {
tip = generator.generateToolTip(dataset, series, item);
}
String url = null;
if (getURLGenerator() != null) {
url = getURLGenerator().generateURL(dataset, series, item);
}
XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item, tip, url);
entities.add(entity);
}
}
}
use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class BarRenderer3D method drawRangeGridline.
/**
* Draws a grid line against the range axis.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param axis the value axis.
* @param dataArea the area for plotting data (not yet adjusted for any
* 3D effect).
* @param value the value at which the grid line should be drawn.
*/
@Override
public void drawRangeGridline(Graphics2D g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value) {
Range range = axis.getRange();
if (!range.contains(value)) {
return;
}
Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
Line2D line1 = null;
Line2D line2 = null;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
double x0 = axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
double x1 = x0 + getXOffset();
double y0 = dataArea.getMaxY();
double y1 = y0 - getYOffset();
double y2 = dataArea.getMinY();
line1 = new Line2D.Double(x0, y0, x1, y1);
line2 = new Line2D.Double(x1, y1, x1, y2);
} else if (orientation == PlotOrientation.VERTICAL) {
double y0 = axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge());
double y1 = y0 - getYOffset();
double x0 = dataArea.getMinX();
double x1 = x0 + getXOffset();
double x2 = dataArea.getMaxX();
line1 = new Line2D.Double(x0, y0, x1, y1);
line2 = new Line2D.Double(x1, y1, x2, y1);
}
Paint paint = plot.getRangeGridlinePaint();
Stroke stroke = plot.getRangeGridlineStroke();
g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
g2.draw(line1);
g2.draw(line2);
}
Aggregations