use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class Plot method resolveDomainAxisLocation.
/**
* Resolves a domain axis location for a given plot orientation.
*
* @param location the location (<code>null</code> not permitted).
* @param orientation the orientation (<code>null</code> not permitted).
*
* @return The edge (never <code>null</code>).
*/
public static RectangleEdge resolveDomainAxisLocation(AxisLocation location, PlotOrientation orientation) {
ParamChecks.nullNotPermitted(location, "location");
ParamChecks.nullNotPermitted(orientation, "orientation");
RectangleEdge result = null;
if (location == AxisLocation.TOP_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.RIGHT;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.TOP;
}
} else if (location == AxisLocation.TOP_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.LEFT;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.TOP;
}
} else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.RIGHT;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.BOTTOM;
}
} else if (location == AxisLocation.BOTTOM_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.LEFT;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.BOTTOM;
}
}
// the above should cover all the options...
if (result == null) {
throw new IllegalStateException("resolveDomainAxisLocation()");
}
return result;
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class Plot method resolveRangeAxisLocation.
/**
* Resolves a range axis location for a given plot orientation.
*
* @param location the location (<code>null</code> not permitted).
* @param orientation the orientation (<code>null</code> not permitted).
*
* @return The edge (never <code>null</code>).
*/
public static RectangleEdge resolveRangeAxisLocation(AxisLocation location, PlotOrientation orientation) {
ParamChecks.nullNotPermitted(location, "location");
ParamChecks.nullNotPermitted(orientation, "orientation");
RectangleEdge result = null;
if (location == AxisLocation.TOP_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.TOP;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.RIGHT;
}
} else if (location == AxisLocation.TOP_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.TOP;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.LEFT;
}
} else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.BOTTOM;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.RIGHT;
}
} else if (location == AxisLocation.BOTTOM_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.BOTTOM;
} else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.LEFT;
}
}
// the above should cover all the options...
if (result == null) {
throw new IllegalStateException("resolveRangeAxisLocation()");
}
return result;
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class XYShapeAnnotation method draw.
/**
* Draws the annotation. This method is usually called by the
* {@link XYPlot} class, you shouldn't need to call it directly.
*
* @param g2 the graphics device.
* @param plot the plot.
* @param dataArea the data area.
* @param domainAxis the domain axis.
* @param rangeAxis the range axis.
* @param rendererIndex the renderer index.
* @param info the plot rendering info.
*/
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
PlotOrientation orientation = plot.getOrientation();
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation);
RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation);
// compute transform matrix elements via sample points. Assume no
// rotation or shear.
Rectangle2D bounds = this.shape.getBounds2D();
double x0 = bounds.getMinX();
double x1 = bounds.getMaxX();
double xx0 = domainAxis.valueToJava2D(x0, dataArea, domainEdge);
double xx1 = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
double m00 = (xx1 - xx0) / (x1 - x0);
double m02 = xx0 - x0 * m00;
double y0 = bounds.getMaxY();
double y1 = bounds.getMinY();
double yy0 = rangeAxis.valueToJava2D(y0, dataArea, rangeEdge);
double yy1 = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
double m11 = (yy1 - yy0) / (y1 - y0);
double m12 = yy0 - m11 * y0;
// create transform & transform shape
Shape s = null;
if (orientation == PlotOrientation.HORIZONTAL) {
AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02);
s = t1.createTransformedShape(this.shape);
s = t2.createTransformedShape(s);
} else if (orientation == PlotOrientation.VERTICAL) {
AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
s = t.createTransformedShape(this.shape);
}
if (this.fillPaint != null) {
g2.setPaint(this.fillPaint);
g2.fill(s);
}
if (this.stroke != null && this.outlinePaint != null) {
g2.setPaint(this.outlinePaint);
g2.setStroke(this.stroke);
g2.draw(s);
}
addEntity(info, s, rendererIndex, getToolTipText(), getURL());
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class CategoryPlot method draw.
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer).
* <P>
* At your option, you may supply an instance of {@link PlotRenderingInfo}.
* If you do, it will be populated with information about the drawing,
* including various plot dimensions and tooltip info.
*
* @param g2 the graphics device.
* @param area the area within which the plot (including axes) should
* be drawn.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState the state from the parent plot, if there is one.
* @param state collects info as the chart is drawn (possibly
* <code>null</code>).
*/
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo state) {
// if the plot area is too small, just return...
boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (state == null) {
// if the incoming state is null, no information will be passed
// back to the caller - but we create a temporary state to record
// the plot area, since that is used later by the axes
state = new PlotRenderingInfo(null);
}
state.setPlotArea(area);
// adjust the drawing area for the plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
// calculate the data area...
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
this.axisOffset.trim(dataArea);
dataArea = integerise(dataArea);
if (dataArea.isEmpty()) {
return;
}
state.setDataArea(dataArea);
createAndAddEntity((Rectangle2D) dataArea.clone(), state, null, null);
// default background...
if (getRenderer() != null) {
getRenderer().drawBackground(g2, this, dataArea);
} else {
drawBackground(g2, dataArea);
}
Map axisStateMap = drawAxes(g2, area, dataArea, state);
// clicked - the crosshairs will be driven off this point...
if (anchor != null && !dataArea.contains(anchor)) {
anchor = ShapeUtilities.getPointInRectangle(anchor.getX(), anchor.getY(), dataArea);
}
CategoryCrosshairState crosshairState = new CategoryCrosshairState();
crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY);
crosshairState.setAnchor(anchor);
// specify the anchor X and Y coordinates in Java2D space, for the
// cases where these are not updated during rendering (i.e. no lock
// on data)
crosshairState.setAnchorX(Double.NaN);
crosshairState.setAnchorY(Double.NaN);
if (anchor != null) {
ValueAxis rangeAxis = getRangeAxis();
if (rangeAxis != null) {
double y;
if (getOrientation() == PlotOrientation.VERTICAL) {
y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge());
} else {
y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge());
}
crosshairState.setAnchorY(y);
}
}
crosshairState.setRowKey(getDomainCrosshairRowKey());
crosshairState.setColumnKey(getDomainCrosshairColumnKey());
crosshairState.setCrosshairY(getRangeCrosshairValue());
// don't let anyone draw outside the data area
Shape savedClip = g2.getClip();
g2.clip(dataArea);
drawDomainGridlines(g2, dataArea);
AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
if (rangeAxisState == null) {
if (parentState != null) {
rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis());
}
}
if (rangeAxisState != null) {
drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
drawZeroRangeBaseline(g2, dataArea);
}
Graphics2D savedG2 = g2;
BufferedImage dataImage = null;
boolean suppressShadow = Boolean.TRUE.equals(g2.getRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION));
if (this.shadowGenerator != null && !suppressShadow) {
dataImage = new BufferedImage((int) dataArea.getWidth(), (int) dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB);
g2 = dataImage.createGraphics();
g2.translate(-dataArea.getX(), -dataArea.getY());
g2.setRenderingHints(savedG2.getRenderingHints());
}
// draw the markers...
for (CategoryItemRenderer renderer : this.renderers.values()) {
int i = getIndexOf(renderer);
drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND);
}
for (CategoryItemRenderer renderer : this.renderers.values()) {
int i = getIndexOf(renderer);
drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND);
}
// now render data items...
boolean foundData = false;
// set up the alpha-transparency...
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
DatasetRenderingOrder order = getDatasetRenderingOrder();
List<Integer> datasetIndices = getDatasetIndices(order);
for (int i : datasetIndices) {
foundData = render(g2, dataArea, i, state, crosshairState) || foundData;
}
// draw the foreground markers...
List<Integer> rendererIndices = getRendererIndices(order);
for (int i : rendererIndices) {
drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND);
}
for (int i : rendererIndices) {
drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND);
}
// draw the annotations (if any)...
drawAnnotations(g2, dataArea);
if (this.shadowGenerator != null && !suppressShadow) {
BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage);
g2 = savedG2;
g2.drawImage(shadowImage, (int) dataArea.getX() + this.shadowGenerator.calculateOffsetX(), (int) dataArea.getY() + this.shadowGenerator.calculateOffsetY(), null);
g2.drawImage(dataImage, (int) dataArea.getX(), (int) dataArea.getY(), null);
}
g2.setClip(savedClip);
g2.setComposite(originalComposite);
if (!foundData) {
drawNoDataMessage(g2, dataArea);
}
int datasetIndex = crosshairState.getDatasetIndex();
setCrosshairDatasetIndex(datasetIndex, false);
// draw domain crosshair if required...
Comparable rowKey = crosshairState.getRowKey();
Comparable columnKey = crosshairState.getColumnKey();
setDomainCrosshairRowKey(rowKey, false);
setDomainCrosshairColumnKey(columnKey, false);
if (isDomainCrosshairVisible() && columnKey != null) {
Paint paint = getDomainCrosshairPaint();
Stroke stroke = getDomainCrosshairStroke();
drawDomainCrosshair(g2, dataArea, this.orientation, datasetIndex, rowKey, columnKey, stroke, paint);
}
// draw range crosshair if required...
ValueAxis yAxis = getRangeAxisForDataset(datasetIndex);
RectangleEdge yAxisEdge = getRangeAxisEdge();
if (!this.rangeCrosshairLockedOnData && anchor != null) {
double yy;
if (getOrientation() == PlotOrientation.VERTICAL) {
yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge);
} else {
yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge);
}
crosshairState.setCrosshairY(yy);
}
setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
if (isRangeCrosshairVisible()) {
double y = getRangeCrosshairValue();
Paint paint = getRangeCrosshairPaint();
Stroke stroke = getRangeCrosshairStroke();
drawRangeCrosshair(g2, dataArea, getOrientation(), y, yAxis, stroke, paint);
}
// draw an outline around the plot area...
if (isOutlineVisible()) {
if (getRenderer() != null) {
getRenderer().drawOutline(g2, this, dataArea);
} else {
drawOutline(g2, dataArea);
}
}
}
use of org.jfree.ui.RectangleEdge in project SIMVA-SoS by SESoS.
the class CategoryPlot method calculateRangeAxisSpace.
/**
* Calculates the space required for the range axis/axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param space a carrier for the result (<code>null</code> permitted).
*
* @return The required space.
*/
protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) {
if (space == null) {
space = new AxisSpace();
}
// reserve some space for the range axis...
if (this.fixedRangeAxisSpace != null) {
if (this.orientation.isHorizontal()) {
space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), RectangleEdge.TOP);
space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), RectangleEdge.BOTTOM);
} else if (this.orientation == PlotOrientation.VERTICAL) {
space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), RectangleEdge.LEFT);
space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), RectangleEdge.RIGHT);
}
} else {
// reserve space for the range axes (if any)...
for (ValueAxis yAxis : this.rangeAxes.values()) {
if (yAxis != null) {
int i = findRangeAxisIndex(yAxis);
RectangleEdge edge = getRangeAxisEdge(i);
space = yAxis.reserveSpace(g2, this, plotArea, edge, space);
}
}
}
return space;
}
Aggregations