use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class XYBubbleRenderer 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 (an {@link XYZDataset} is expected).
* @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) {
// return straight away if the item is not visible
if (!getItemVisible(series, item)) {
return;
}
PlotOrientation orientation = plot.getOrientation();
// get the data point...
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double z = Double.NaN;
if (dataset instanceof XYZDataset) {
XYZDataset xyzData = (XYZDataset) dataset;
z = xyzData.getZValue(series, item);
}
if (!Double.isNaN(z)) {
RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);
double transDomain;
double transRange;
double zero;
switch(getScaleType()) {
case SCALE_ON_DOMAIN_AXIS:
zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation);
transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero;
transRange = transDomain;
break;
case SCALE_ON_RANGE_AXIS:
zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation);
transDomain = transRange;
break;
default:
double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation);
double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation);
transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1;
transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation);
}
transDomain = Math.abs(transDomain);
transRange = Math.abs(transRange);
Ellipse2D circle = null;
if (orientation == PlotOrientation.VERTICAL) {
circle = new Ellipse2D.Double(transX - transDomain / 2.0, transY - transRange / 2.0, transDomain, transRange);
} else if (orientation == PlotOrientation.HORIZONTAL) {
circle = new Ellipse2D.Double(transY - transRange / 2.0, transX - transDomain / 2.0, transRange, transDomain);
} else {
throw new IllegalStateException();
}
g2.setPaint(getItemPaint(series, item));
g2.fill(circle);
g2.setStroke(getItemOutlineStroke(series, item));
g2.setPaint(getItemOutlinePaint(series, item));
g2.draw(circle);
if (isItemLabelVisible(series, item)) {
if (orientation == PlotOrientation.VERTICAL) {
drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
} else if (orientation == PlotOrientation.HORIZONTAL) {
drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
}
}
// add an entity if this info is being collected
if (info != null) {
EntityCollection entities = info.getOwner().getEntityCollection();
if (entities != null && circle.intersects(dataArea)) {
addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY());
}
}
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 XYSplineRenderer method drawPrimaryLineAsPath.
/**
* Draws the item (first pass). This method draws the lines
* connecting the items. Instead of drawing separate lines,
* a GeneralPath is constructed and drawn at the end of
* the series painting.
*
* @param g2 the graphics device.
* @param state the renderer state.
* @param plot the plot (can be used to obtain standard color information
* etc).
* @param dataset the dataset.
* @param pass the pass.
* @param series the series index (zero-based).
* @param item the item index (zero-based).
* @param xAxis the domain axis.
* @param yAxis the range axis.
* @param dataArea the area within which the data is being drawn.
*/
@Override
protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis xAxis, ValueAxis yAxis, Rectangle2D dataArea) {
XYSplineState s = (XYSplineState) state;
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
// get the data points
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
double transX1 = xAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = yAxis.valueToJava2D(y1, dataArea, yAxisLocation);
// Collect points
if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
Point2D p = plot.getOrientation() == PlotOrientation.HORIZONTAL ? new Point2D.Float((float) transY1, (float) transX1) : new Point2D.Float((float) transX1, (float) transY1);
if (!s.points.contains(p))
s.points.add(p);
}
if (item == dataset.getItemCount(series) - 1) {
// construct path
if (s.points.size() > 1) {
Point2D origin;
if (this.fillType == FillType.TO_ZERO) {
float xz = (float) xAxis.valueToJava2D(0, dataArea, yAxisLocation);
float yz = (float) yAxis.valueToJava2D(0, dataArea, yAxisLocation);
origin = plot.getOrientation() == PlotOrientation.HORIZONTAL ? new Point2D.Float(yz, xz) : new Point2D.Float(xz, yz);
} else if (this.fillType == FillType.TO_LOWER_BOUND) {
float xlb = (float) xAxis.valueToJava2D(xAxis.getLowerBound(), dataArea, xAxisLocation);
float ylb = (float) yAxis.valueToJava2D(yAxis.getLowerBound(), dataArea, yAxisLocation);
origin = plot.getOrientation() == PlotOrientation.HORIZONTAL ? new Point2D.Float(ylb, xlb) : new Point2D.Float(xlb, ylb);
} else {
// fillType == TO_UPPER_BOUND
float xub = (float) xAxis.valueToJava2D(xAxis.getUpperBound(), dataArea, xAxisLocation);
float yub = (float) yAxis.valueToJava2D(yAxis.getUpperBound(), dataArea, yAxisLocation);
origin = plot.getOrientation() == PlotOrientation.HORIZONTAL ? new Point2D.Float(yub, xub) : new Point2D.Float(xub, yub);
}
// we need at least two points to draw something
Point2D cp0 = s.points.get(0);
s.seriesPath.moveTo(cp0.getX(), cp0.getY());
if (this.fillType != FillType.NONE) {
if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
s.fillArea.moveTo(origin.getX(), cp0.getY());
} else {
s.fillArea.moveTo(cp0.getX(), origin.getY());
}
s.fillArea.lineTo(cp0.getX(), cp0.getY());
}
if (s.points.size() == 2) {
// we need at least 3 points to spline. Draw simple line
// for two points
Point2D cp1 = s.points.get(1);
if (this.fillType != FillType.NONE) {
s.fillArea.lineTo(cp1.getX(), cp1.getY());
s.fillArea.lineTo(cp1.getX(), origin.getY());
s.fillArea.closePath();
}
s.seriesPath.lineTo(cp1.getX(), cp1.getY());
} else {
// construct spline
// number of points
int np = s.points.size();
// Newton form coefficients
float[] d = new float[np];
// x-coordinates of nodes
float[] x = new float[np];
float y, oldy;
float t, oldt;
float[] a = new float[np];
float t1;
float t2;
float[] h = new float[np];
for (int i = 0; i < np; i++) {
Point2D.Float cpi = (Point2D.Float) s.points.get(i);
x[i] = cpi.x;
d[i] = cpi.y;
}
for (int i = 1; i <= np - 1; i++) h[i] = x[i] - x[i - 1];
float[] sub = new float[np - 1];
float[] diag = new float[np - 1];
float[] sup = new float[np - 1];
for (int i = 1; i <= np - 2; i++) {
diag[i] = (h[i] + h[i + 1]) / 3;
sup[i] = h[i + 1] / 6;
sub[i] = h[i] / 6;
a[i] = (d[i + 1] - d[i]) / h[i + 1] - (d[i] - d[i - 1]) / h[i];
}
solveTridiag(sub, diag, sup, a, np - 2);
// note that a[0]=a[np-1]=0
oldt = x[0];
oldy = d[0];
for (int i = 1; i <= np - 1; i++) {
// loop over intervals between nodes
for (int j = 1; j <= this.precision; j++) {
t1 = (h[i] * j) / this.precision;
t2 = h[i] - t1;
y = ((-a[i - 1] / 6 * (t2 + h[i]) * t1 + d[i - 1]) * t2 + (-a[i] / 6 * (t1 + h[i]) * t2 + d[i]) * t1) / h[i];
t = x[i - 1] + t1;
s.seriesPath.lineTo(t, y);
if (this.fillType != FillType.NONE) {
s.fillArea.lineTo(t, y);
}
}
}
}
// Add last point @ y=0 for fillPath and close path
if (this.fillType != FillType.NONE) {
if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
s.fillArea.lineTo(origin.getX(), s.points.get(s.points.size() - 1).getY());
} else {
s.fillArea.lineTo(s.points.get(s.points.size() - 1).getX(), origin.getY());
}
s.fillArea.closePath();
}
// fill under the curve...
if (this.fillType != FillType.NONE) {
Paint fp = getSeriesFillPaint(series);
if (this.gradientPaintTransformer != null && fp instanceof GradientPaint) {
GradientPaint gp = this.gradientPaintTransformer.transform((GradientPaint) fp, s.fillArea);
g2.setPaint(gp);
} else {
g2.setPaint(fp);
}
g2.fill(s.fillArea);
s.fillArea.reset();
}
// then draw the line...
drawFirstPassShape(g2, pass, series, item, s.seriesPath);
}
// reset points vector
s.points = new ArrayList<Point2D>();
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class XYStepRenderer 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 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;
}
PlotOrientation orientation = plot.getOrientation();
Paint seriesPaint = getItemPaint(series, item);
Stroke seriesStroke = getItemStroke(series, item);
g2.setPaint(seriesPaint);
g2.setStroke(seriesStroke);
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = (Double.isNaN(y1) ? Double.NaN : rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation));
if (pass == 0 && item > 0) {
// get the previous data point...
double x0 = dataset.getXValue(series, item - 1);
double y0 = dataset.getYValue(series, item - 1);
double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
double transY0 = (Double.isNaN(y0) ? Double.NaN : rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation));
if (orientation == PlotOrientation.HORIZONTAL) {
if (transY0 == transY1) {
// this represents the situation
// for drawing a horizontal bar.
drawLine(g2, state.workingLine, transY0, transX0, transY1, transX1);
} else {
// this handles the need to perform a 'step'.
// calculate the step point
double transXs = transX0 + (getStepPoint() * (transX1 - transX0));
drawLine(g2, state.workingLine, transY0, transX0, transY0, transXs);
drawLine(g2, state.workingLine, transY0, transXs, transY1, transXs);
drawLine(g2, state.workingLine, transY1, transXs, transY1, transX1);
}
} else if (orientation == PlotOrientation.VERTICAL) {
if (transY0 == transY1) {
// this represents the situation
// for drawing a horizontal bar.
drawLine(g2, state.workingLine, transX0, transY0, transX1, transY1);
} else {
// this handles the need to perform a 'step'.
// calculate the step point
double transXs = transX0 + (getStepPoint() * (transX1 - transX0));
drawLine(g2, state.workingLine, transX0, transY0, transXs, transY0);
drawLine(g2, state.workingLine, transXs, transY0, transXs, transY1);
drawLine(g2, state.workingLine, transXs, transY1, transX1, transY1);
}
}
// submit this data item as a candidate for the crosshair point
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, null, dataset, series, item, transX1, transY1);
}
}
if (pass == 1) {
// draw the item label if there is one...
if (isItemLabelVisible(series, item)) {
double xx = transX1;
double yy = transY1;
if (orientation == PlotOrientation.HORIZONTAL) {
xx = transY1;
yy = transX1;
}
drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
}
}
}
use of org.jfree.ui.RectangleEdge 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());
}
}
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class SamplingXYLineRenderer 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) {
// do nothing if item is not visible
if (!getItemVisible(series, item)) {
return;
}
RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
// get the data point...
double x1 = dataset.getXValue(series, item);
double y1 = dataset.getYValue(series, item);
double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
State s = (State) state;
// update path to reflect latest point
if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
float x = (float) transX1;
float y = (float) transY1;
PlotOrientation orientation = plot.getOrientation();
if (orientation == PlotOrientation.HORIZONTAL) {
x = (float) transY1;
y = (float) transX1;
}
if (s.lastPointGood) {
if ((Math.abs(x - s.lastX) > s.dX)) {
s.seriesPath.lineTo(x, y);
if (s.lowY < s.highY) {
s.intervalPath.moveTo((float) s.lastX, (float) s.lowY);
s.intervalPath.lineTo((float) s.lastX, (float) s.highY);
}
s.lastX = x;
s.openY = y;
s.highY = y;
s.lowY = y;
s.closeY = y;
} else {
s.highY = Math.max(s.highY, y);
s.lowY = Math.min(s.lowY, y);
s.closeY = y;
}
} else {
s.seriesPath.moveTo(x, y);
s.lastX = x;
s.openY = y;
s.highY = y;
s.lowY = y;
s.closeY = y;
}
s.lastPointGood = true;
} else {
s.lastPointGood = false;
}
// if this is the last item, draw the path ...
if (item == s.getLastItemIndex()) {
// draw path
PathIterator pi = s.seriesPath.getPathIterator(null);
int count = 0;
while (!pi.isDone()) {
count++;
pi.next();
}
g2.setStroke(getItemStroke(series, item));
g2.setPaint(getItemPaint(series, item));
g2.draw(s.seriesPath);
g2.draw(s.intervalPath);
}
}
Aggregations