use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class StackedXYAreaRenderer2 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 information about crosshairs on a plot.
* @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) {
// setup for collecting optional entity info...
Shape entityArea;
EntityCollection entities = null;
if (info != null) {
entities = info.getOwner().getEntityCollection();
}
TableXYDataset tdataset = (TableXYDataset) dataset;
PlotOrientation orientation = plot.getOrientation();
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
if (Double.isNaN(y1)) {
y1 = 0.0;
}
double[] stack1 = getStackValues(tdataset, series, item);
// 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[] stack0 = getStackValues(tdataset, series, Math.max(item - 1, 0));
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[] stack2 = getStackValues(tdataset, series, Math.min(item + 1, itemCount - 1));
double xleft = (x0 + x1) / 2.0;
double xright = (x1 + x2) / 2.0;
double[] stackLeft = averageStackValues(stack0, stack1);
double[] stackRight = averageStackValues(stack1, stack2);
double[] adjStackLeft = adjustedStackValues(stack0, stack1);
double[] adjStackRight = adjustedStackValues(stack1, stack2);
RectangleEdge edge0 = plot.getDomainAxisEdge();
float transX1 = (float) domainAxis.valueToJava2D(x1, dataArea, edge0);
float transXLeft = (float) domainAxis.valueToJava2D(xleft, dataArea, edge0);
float transXRight = (float) domainAxis.valueToJava2D(xright, dataArea, edge0);
if (this.roundXCoordinates) {
transX1 = Math.round(transX1);
transXLeft = Math.round(transXLeft);
transXRight = Math.round(transXRight);
}
float transY1;
RectangleEdge edge1 = plot.getRangeAxisEdge();
GeneralPath left = new GeneralPath();
GeneralPath right = new GeneralPath();
if (y1 >= 0.0) {
// handle positive value
transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1);
float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1);
float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[1], dataArea, edge1);
// LEFT POLYGON
if (y0 >= 0.0) {
double yleft = (y0 + y1) / 2.0 + stackLeft[1];
float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
if (orientation == PlotOrientation.VERTICAL) {
left.moveTo(transX1, transY1);
left.lineTo(transX1, transStack1);
left.lineTo(transXLeft, transStackLeft);
left.lineTo(transXLeft, transYLeft);
} else {
left.moveTo(transY1, transX1);
left.lineTo(transStack1, transX1);
left.lineTo(transStackLeft, transXLeft);
left.lineTo(transYLeft, transXLeft);
}
left.closePath();
} else {
if (orientation == PlotOrientation.VERTICAL) {
left.moveTo(transX1, transStack1);
left.lineTo(transX1, transY1);
left.lineTo(transXLeft, transStackLeft);
} else {
left.moveTo(transStack1, transX1);
left.lineTo(transY1, transX1);
left.lineTo(transStackLeft, transXLeft);
}
left.closePath();
}
float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[1], dataArea, edge1);
// RIGHT POLYGON
if (y2 >= 0.0) {
double yright = (y1 + y2) / 2.0 + stackRight[1];
float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
if (orientation == PlotOrientation.VERTICAL) {
right.moveTo(transX1, transStack1);
right.lineTo(transX1, transY1);
right.lineTo(transXRight, transYRight);
right.lineTo(transXRight, transStackRight);
} else {
right.moveTo(transStack1, transX1);
right.lineTo(transY1, transX1);
right.lineTo(transYRight, transXRight);
right.lineTo(transStackRight, transXRight);
}
right.closePath();
} else {
if (orientation == PlotOrientation.VERTICAL) {
right.moveTo(transX1, transStack1);
right.lineTo(transX1, transY1);
right.lineTo(transXRight, transStackRight);
} else {
right.moveTo(transStack1, transX1);
right.lineTo(transY1, transX1);
right.lineTo(transStackRight, transXRight);
}
right.closePath();
}
} else {
// handle negative value
transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1);
float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1);
float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1);
// LEFT POLYGON
if (y0 >= 0.0) {
if (orientation == PlotOrientation.VERTICAL) {
left.moveTo(transX1, transStack1);
left.lineTo(transX1, transY1);
left.lineTo(transXLeft, transStackLeft);
} else {
left.moveTo(transStack1, transX1);
left.lineTo(transY1, transX1);
left.lineTo(transStackLeft, transXLeft);
}
left.clone();
} else {
double yleft = (y0 + y1) / 2.0 + stackLeft[0];
float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1);
if (orientation == PlotOrientation.VERTICAL) {
left.moveTo(transX1, transY1);
left.lineTo(transX1, transStack1);
left.lineTo(transXLeft, transStackLeft);
left.lineTo(transXLeft, transYLeft);
} else {
left.moveTo(transY1, transX1);
left.lineTo(transStack1, transX1);
left.lineTo(transStackLeft, transXLeft);
left.lineTo(transYLeft, transXLeft);
}
left.closePath();
}
float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1);
// RIGHT POLYGON
if (y2 >= 0.0) {
if (orientation == PlotOrientation.VERTICAL) {
right.moveTo(transX1, transStack1);
right.lineTo(transX1, transY1);
right.lineTo(transXRight, transStackRight);
} else {
right.moveTo(transStack1, transX1);
right.lineTo(transY1, transX1);
right.lineTo(transStackRight, transXRight);
}
right.closePath();
} else {
double yright = (y1 + y2) / 2.0 + stackRight[0];
float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1);
if (orientation == PlotOrientation.VERTICAL) {
right.moveTo(transX1, transStack1);
right.lineTo(transX1, transY1);
right.lineTo(transXRight, transYRight);
right.lineTo(transXRight, transStackRight);
} else {
right.moveTo(transStack1, transX1);
right.lineTo(transY1, transX1);
right.lineTo(transYRight, transXRight);
right.lineTo(transStackRight, transXRight);
}
right.closePath();
}
}
// Get series Paint and Stroke
Paint itemPaint = getItemPaint(series, item);
if (pass == 0) {
g2.setPaint(itemPaint);
g2.fill(left);
g2.fill(right);
}
// add an entity for the item...
if (entities != null) {
GeneralPath gp = new GeneralPath(left);
gp.append(right, false);
entityArea = gp;
addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class XYDifferenceRenderer method createPolygon.
/**
* Draws the visual representation of a polygon
*
* @param x_graphics the graphics device.
* @param x_dataArea the area within which the data is being drawn.
* @param x_plot the plot (can be used to obtain standard color
* information etc).
* @param x_domainAxis the domain (horizontal) axis.
* @param x_rangeAxis the range (vertical) axis.
* @param x_positive indicates if the polygon is positive (true) or
* negative (false).
* @param x_xValues a linked list of the x values (expects values to be
* of type Double).
* @param x_yValues a linked list of the y values (expects values to be
* of type Double).
*/
private void createPolygon(Graphics2D x_graphics, Rectangle2D x_dataArea, XYPlot x_plot, ValueAxis x_domainAxis, ValueAxis x_rangeAxis, boolean x_positive, LinkedList x_xValues, LinkedList x_yValues) {
PlotOrientation l_orientation = x_plot.getOrientation();
RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
Object[] l_xValues = x_xValues.toArray();
Object[] l_yValues = x_yValues.toArray();
GeneralPath l_path = new GeneralPath();
if (PlotOrientation.VERTICAL == l_orientation) {
double l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[0]).doubleValue(), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
double l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[0]).doubleValue(), x_dataArea, l_rangeAxisLocation);
l_path.moveTo((float) l_x, (float) l_y);
for (int i = 1; i < l_xValues.length; i++) {
l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[i]).doubleValue(), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[i]).doubleValue(), x_dataArea, l_rangeAxisLocation);
l_path.lineTo((float) l_x, (float) l_y);
}
l_path.closePath();
} else {
double l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[0]).doubleValue(), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
double l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[0]).doubleValue(), x_dataArea, l_rangeAxisLocation);
l_path.moveTo((float) l_y, (float) l_x);
for (int i = 1; i < l_xValues.length; i++) {
l_x = x_domainAxis.valueToJava2D(((Double) l_xValues[i]).doubleValue(), x_dataArea, l_domainAxisLocation);
if (this.roundXCoordinates) {
l_x = Math.rint(l_x);
}
l_y = x_rangeAxis.valueToJava2D(((Double) l_yValues[i]).doubleValue(), x_dataArea, l_rangeAxisLocation);
l_path.lineTo((float) l_y, (float) l_x);
}
l_path.closePath();
}
if (l_path.intersects(x_dataArea)) {
x_graphics.setPaint(x_positive ? getPositivePaint() : getNegativePaint());
x_graphics.fill(l_path);
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class XYDotRenderer 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 (horizontal) axis.
* @param rangeAxis the range (vertical) 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) {
// do nothing if item is not visible
if (!getItemVisible(series, item)) {
return;
}
// get the data point...
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double adjx = (this.dotWidth - 1) / 2.0;
double adjy = (this.dotHeight - 1) / 2.0;
if (!Double.isNaN(y)) {
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;
g2.setPaint(getItemPaint(series, item));
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth);
} else if (orientation == PlotOrientation.VERTICAL) {
g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight);
}
int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation);
}
}
use of org.jfree.ui.RectangleEdge 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.ui.RectangleEdge 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);
}
}
Aggregations