use of org.jfree.chart.plot.PlotOrientation 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.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class XYLineAndShapeRenderer method drawPrimaryLine.
/**
* Draws the item (first pass). This method draws the lines
* connecting the items.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param dataArea the area within which the data 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.
* @param pass the pass.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*/
protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {
if (item == 0) {
return;
}
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1) || Double.isNaN(x1)) {
return;
}
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
if (Double.isNaN(y0) || Double.isNaN(x0)) {
return;
}
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
// only draw if we have good values
if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
boolean visible;
if (orientation == PlotOrientation.HORIZONTAL) {
state.workingLine.setLine(transY0, transX0, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
state.workingLine.setLine(transX0, transY0, transX1, transY1);
}
visible = LineUtilities.clipLine(state.workingLine, dataArea);
if (visible) {
drawFirstPassShape(g2, pass, series, item, state.workingLine);
}
}
use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class XYLineAndShapeRenderer method drawSecondaryPass.
/**
* Draws the item shapes and adds chart entities (second pass). This method
* draws the shapes which mark the item positions. If <code>entities</code>
* is not <code>null</code> it will be populated with entity information
* for points that fall within the data area.
*
* @param g2 the graphics device.
* @param plot the plot (can be used to obtain standard color
* information etc).
* @param domainAxis the domain axis.
* @param dataArea the area within which the data is being drawn.
* @param rangeAxis the range axis.
* @param dataset the dataset.
* @param pass the pass.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param crosshairState the crosshair state.
* @param entities the entity collection.
*/
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) {
Shape entityArea = null;
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1) || Double.isNaN(x1)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
if (getItemShapeVisible(series, item)) {
Shape shape = getItemShape(series, item);
if (orientation == PlotOrientation.HORIZONTAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
} else if (orientation == PlotOrientation.VERTICAL) {
shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
}
entityArea = shape;
if (shape.intersects(dataArea)) {
if (getItemShapeFilled(series, item)) {
if (this.useFillPaint) {
g2.setPaint(getItemFillPaint(series, item));
} else {
g2.setPaint(getItemPaint(series, item));
}
g2.fill(shape);
}
if (this.drawOutlines) {
if (getUseOutlinePaint()) {
g2.setPaint(getItemOutlinePaint(series, item));
} else {
g2.setPaint(getItemPaint(series, item));
}
g2.setStroke(getItemOutlineStroke(series, item));
g2.draw(shape);
}
}
}
double xx = transX1;
double yy = transY1;
if (orientation == PlotOrientation.HORIZONTAL) {
xx = transY1;
yy = transX1;
}
// draw the item label if there is one...
if (isItemLabelVisible(series, item)) {
drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation);
// area...
if (entities != null && isPointInRect(dataArea, xx, yy)) {
addEntity(entities, entityArea, dataset, series, item, xx, yy);
}
}
use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class VectorRenderer method drawItem.
/**
* Draws the block representing the specified item.
*
* @param g2 the graphics device.
* @param state the state.
* @param dataArea the data area.
* @param info the plot rendering info.
* @param plot the plot.
* @param domainAxis the x-axis.
* @param rangeAxis the y-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) {
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double dx = 0.0;
double dy = 0.0;
if (dataset instanceof VectorXYDataset) {
dx = ((VectorXYDataset) dataset).getVectorXValue(series, item);
dy = ((VectorXYDataset) dataset).getVectorYValue(series, item);
}
double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge());
double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge());
Line2D line;
PlotOrientation orientation = plot.getOrientation();
if (orientation.equals(PlotOrientation.HORIZONTAL)) {
line = new Line2D.Double(yy0, xx0, yy1, xx1);
} else {
line = new Line2D.Double(xx0, yy0, xx1, yy1);
}
g2.setPaint(getItemPaint(series, item));
g2.setStroke(getItemStroke(series, item));
g2.draw(line);
// calculate the arrow head and draw it...
double dxx = (xx1 - xx0);
double dyy = (yy1 - yy0);
double bx = xx0 + (1.0 - this.baseLength) * dxx;
double by = yy0 + (1.0 - this.baseLength) * dyy;
double cx = xx0 + (1.0 - this.headLength) * dxx;
double cy = yy0 + (1.0 - this.headLength) * dyy;
double angle = 0.0;
if (dxx != 0.0) {
angle = Math.PI / 2.0 - Math.atan(dyy / dxx);
}
double deltaX = 2.0 * Math.cos(angle);
double deltaY = 2.0 * Math.sin(angle);
double leftx = cx + deltaX;
double lefty = cy - deltaY;
double rightx = cx - deltaX;
double righty = cy + deltaY;
GeneralPath p = new GeneralPath();
if (orientation == PlotOrientation.VERTICAL) {
p.moveTo((float) xx1, (float) yy1);
p.lineTo((float) rightx, (float) righty);
p.lineTo((float) bx, (float) by);
p.lineTo((float) leftx, (float) lefty);
} else {
// orientation is HORIZONTAL
p.moveTo((float) yy1, (float) xx1);
p.lineTo((float) righty, (float) rightx);
p.lineTo((float) by, (float) bx);
p.lineTo((float) lefty, (float) leftx);
}
p.closePath();
g2.draw(p);
// setup for collecting optional entity info...
EntityCollection entities;
if (info != null) {
entities = info.getOwner().getEntityCollection();
if (entities != null) {
addEntity(entities, line.getBounds(), dataset, series, item, 0.0, 0.0);
}
}
}
use of org.jfree.chart.plot.PlotOrientation in project SIMVA-SoS by SESoS.
the class CategoryTextAnnotation method draw.
/**
* Draws the annotation.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the data area.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
*/
@Override
public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) {
CategoryDataset dataset = plot.getDataset();
int catIndex = dataset.getColumnIndex(this.category);
int catCount = dataset.getColumnCount();
float anchorX = 0.0f;
float anchorY = 0.0f;
PlotOrientation orientation = plot.getOrientation();
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
if (orientation == PlotOrientation.HORIZONTAL) {
anchorY = (float) domainAxis.getCategoryJava2DCoordinate(this.categoryAnchor, catIndex, catCount, dataArea, domainEdge);
anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge);
} else if (orientation == PlotOrientation.VERTICAL) {
anchorX = (float) domainAxis.getCategoryJava2DCoordinate(this.categoryAnchor, catIndex, catCount, dataArea, domainEdge);
anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge);
}
g2.setFont(getFont());
g2.setPaint(getPaint());
TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor());
}
Aggregations