use of org.jfree.chart.axis.AxisState 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.chart.axis.AxisState in project SIMVA-SoS by SESoS.
the class CombinedDomainCategoryPlot method draw.
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer). Will perform all the placement calculations for each of the
* sub-plots and then tell these to draw themselves.
*
* @param g2 the graphics device.
* @param area the area within which the plot (including axis labels)
* 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 info collects information about the drawing (<code>null</code>
* permitted).
*/
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
// set up info collection...
if (info != null) {
info.setPlotArea(area);
}
// adjust the drawing area for plot insets (if any)...
RectangleInsets insets = getInsets();
area.setRect(area.getX() + insets.getLeft(), area.getY() + insets.getTop(), area.getWidth() - insets.getLeft() - insets.getRight(), area.getHeight() - insets.getTop() - insets.getBottom());
// calculate the data area...
setFixedRangeAxisSpaceForSubplots(null);
AxisSpace space = calculateAxisSpace(g2, area);
Rectangle2D dataArea = space.shrink(area, null);
// set the width and height of non-shared axis of all sub-plots
setFixedRangeAxisSpaceForSubplots(space);
// draw the shared axis
CategoryAxis axis = getDomainAxis();
RectangleEdge domainEdge = getDomainAxisEdge();
double cursor = RectangleEdge.coordinate(dataArea, domainEdge);
AxisState axisState = axis.draw(g2, cursor, area, dataArea, domainEdge, info);
if (parentState == null) {
parentState = new PlotState();
}
parentState.getSharedAxisStates().put(axis, axisState);
// draw all the subplots
for (int i = 0; i < this.subplots.size(); i++) {
CategoryPlot plot = (CategoryPlot) this.subplots.get(i);
PlotRenderingInfo subplotInfo = null;
if (info != null) {
subplotInfo = new PlotRenderingInfo(info.getOwner());
info.addSubplotInfo(subplotInfo);
}
Point2D subAnchor = null;
if (anchor != null && this.subplotAreas[i].contains(anchor)) {
subAnchor = anchor;
}
plot.draw(g2, this.subplotAreas[i], subAnchor, parentState, subplotInfo);
}
if (info != null) {
info.setDataArea(dataArea);
}
}
Aggregations