List of usage examples for java.awt.geom Rectangle2D contains
public boolean contains(Point2D p)
From source file:ucar.unidata.idv.control.chart.MyXYPlot.java
/** * Draws the plot within the specified area on a graphics device. * * @param g2 the graphics device.//www.j a v a 2 s . com * @param area the plot area (in Java2D space). * @param anchor an anchor point in Java2D space (<code>null</code> * permitted). * @param parentState the state from the parent plot, if there is one * (<code>null</code> permitted). * @param info collects chart drawing information (<code>null</code> * permitted). */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // 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 (info != null) { info.setPlotArea(area); } // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); this.axisOffset.trim(dataArea); if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); Map axisStateMap = drawAxes(g2, area, dataArea, info); if ((anchor != null) && !dataArea.contains(anchor)) { anchor = null; } CrosshairState crosshairState = new CrosshairState(); crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY); crosshairState.setAnchor(anchor); crosshairState.setCrosshairX(getDomainCrosshairValue()); crosshairState.setCrosshairY(getRangeCrosshairValue()); Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); AxisState domainAxisState = (AxisState) axisStateMap.get(getDomainAxis()); if (domainAxisState == null) { if (parentState != null) { domainAxisState = (AxisState) parentState.getSharedAxisStates().get(getDomainAxis()); } } if (domainAxisState != null) { drawDomainTickBands(g2, dataArea, domainAxisState.getTicks()); drawDomainGridlines(g2, dataArea, domainAxisState.getTicks()); } AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis()); if (rangeAxisState == null) { if (parentState != null) { rangeAxisState = (AxisState) parentState.getSharedAxisStates().get(getRangeAxis()); } } if (rangeAxisState != null) { drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks()); drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); drawZeroRangeBaseline(g2, dataArea); } // draw the markers that are associated with a specific renderer... for (int i = 0; i < this.renderers.size(); i++) { drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND); } for (int i = 0; i < this.renderers.size(); i++) { drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND); } // now draw annotations and render data items... boolean foundData = false; DatasetRenderingOrder order = getDatasetRenderingOrder(); if (order == DatasetRenderingOrder.FORWARD) { // draw background annotations int rendererCount = this.renderers.size(); for (int i = 0; i < rendererCount; i++) { XYItemRenderer r = getRenderer(i); if (r != null) { ValueAxis domainAxis = getDomainAxisForDataset(i); ValueAxis rangeAxis = getRangeAxisForDataset(i); r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info); } } // render data items... for (int i = 0; i < getDatasetCount(); i++) { foundData = render(g2, dataArea, i, info, crosshairState) || foundData; } // draw foreground annotations for (int i = 0; i < rendererCount; i++) { XYItemRenderer r = getRenderer(i); if (r != null) { ValueAxis domainAxis = getDomainAxisForDataset(i); ValueAxis rangeAxis = getRangeAxisForDataset(i); r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info); } } } else if (order == DatasetRenderingOrder.REVERSE) { // draw background annotations int rendererCount = this.renderers.size(); for (int i = rendererCount - 1; i >= 0; i--) { XYItemRenderer r = getRenderer(i); if (r != null) { ValueAxis domainAxis = getDomainAxisForDataset(i); ValueAxis rangeAxis = getRangeAxisForDataset(i); r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info); } } ucar.unidata.util.Trace.call1("renderData"); for (int i = getDatasetCount() - 1; i >= 0; i--) { foundData = render(g2, dataArea, i, info, crosshairState) || foundData; } ucar.unidata.util.Trace.call2("renderData"); // draw foreground annotations for (int i = rendererCount - 1; i >= 0; i--) { XYItemRenderer r = getRenderer(i); if (r != null) { ValueAxis domainAxis = getDomainAxisForDataset(i); ValueAxis rangeAxis = getRangeAxisForDataset(i); r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info); } } } PlotOrientation orient = getOrientation(); // draw domain crosshair if required... if (!this.domainCrosshairLockedOnData && (anchor != null)) { double xx = getDomainAxis().java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge()); crosshairState.setCrosshairX(xx); } setDomainCrosshairValue(crosshairState.getCrosshairX(), false); if (isDomainCrosshairVisible()) { double x = getDomainCrosshairValue(); Paint paint = getDomainCrosshairPaint(); Stroke stroke = getDomainCrosshairStroke(); if (orient == PlotOrientation.HORIZONTAL) { drawHorizontalLine(g2, dataArea, x, stroke, paint); } else if (orient == PlotOrientation.VERTICAL) { drawVerticalLine(g2, dataArea, x, stroke, paint); } } // draw range crosshair if required... if (!this.rangeCrosshairLockedOnData && (anchor != null)) { double yy = getRangeAxis().java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge()); crosshairState.setCrosshairX(yy); } setRangeCrosshairValue(crosshairState.getCrosshairY(), false); if (isRangeCrosshairVisible() && getRangeAxis().getRange().contains(getRangeCrosshairValue())) { double y = getRangeCrosshairValue(); Paint paint = getRangeCrosshairPaint(); Stroke stroke = getRangeCrosshairStroke(); if (orient == PlotOrientation.HORIZONTAL) { drawVerticalLine(g2, dataArea, y, stroke, paint); } else if (orient == PlotOrientation.VERTICAL) { drawHorizontalLine(g2, dataArea, y, stroke, paint); } } if (!foundData) { drawNoDataMessage(g2, dataArea); } for (int i = 0; i < this.renderers.size(); i++) { drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND); } for (int i = 0; i < this.renderers.size(); i++) { drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND); } drawAnnotations(g2, dataArea, info); g2.setClip(originalClip); g2.setComposite(originalComposite); drawOutline(g2, dataArea); }
From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.ExtendedBoxAndWhiskerRenderer.java
/** * Draws the visual representation of a single data item when the plot has a * vertical orientation.//from www. ja va2s . co m * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot 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 row the row index (zero-based). * @param column the column index (zero-based). */ @Override public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { // do nothing if item is not visible if (!getItemVisible(row, column)) { return; } //Determine the catgory start and end. BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset; double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double categoryWidth = categoryEnd - categoryStart; domainAxis.setCategoryMargin(0.25); rangeAxis.setUpperMargin(0.3); rangeAxis.setLowerMargin(0.3); double xx = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1)); // offset the start of the boxes if the total width used is smaller // than the category width double offset = (categoryWidth - usedWidth) / 2; xx = xx + offset + (row * (state.getBarWidth() + seriesGap)); } else { // offset the start of the box if the box width is smaller than the category width double offset = (categoryWidth - state.getBarWidth()) / 2; xx = xx + offset; } double xxmid = xx + state.getBarWidth() / 2.0; //Draw the box. Paint p = getItemPaint(row, column); if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); RectangleEdge location = plot.getRangeAxisEdge(); Shape box = null; Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) { double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location); double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location); double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location); double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location); // set the paint according to the right technical replicate int length = GuiUtils.getAvailableColors().length; int colorIndex = row % length; Color color = GuiUtils.getAvailableColors()[colorIndex]; g2.setPaint(color); // draw the upper whisker g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax)); // draw the lower whisker g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1)); g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin)); // draw the body box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3)); g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175)); // if (getFillBox()) { // g2.fill(box); // } g2.draw(box); } // draw mean g2.setPaint(getArtifactPaint()); double yyAverage = 0.0; double aRadius = 2.0; // mean radius Number yMean = bawDataset.getMeanValue(row, column); if (yMean != null) { yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location); Ellipse2D.Double avgEllipse = new Ellipse2D.Double((xxmid - aRadius), (yyAverage - aRadius), aRadius * 2, aRadius * 2); g2.draw(avgEllipse); } //draw median double yyMedian = 0.0; Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null) { yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian)); } //Outliers and Farouts double oRadius = 2.0; //outlier radius double foRadius = 1.0; //farout radius // From outlier array sort out which are outliers and put these into a // list. If there are any farouts, add them to the farout list. // draw the outliers and farouts only if they are within the data area. double yyOutlier; double yyFarout; List outliers = new ArrayList(); List farOutValues = new ArrayList(); List yOutliers = bawDataset.getOutliers(row, column); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { Number outlierNum = (Number) yOutliers.get(i); double outlier = outlierNum.doubleValue(); Number minOutlier = bawDataset.getMinOutlier(row, column); Number maxOutlier = bawDataset.getMaxOutlier(row, column); Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); if (outlier > maxOutlier.doubleValue() || outlier < minOutlier.doubleValue()) { yyFarout = rangeAxis.valueToJava2D(outlier, dataArea, location); Outlier faroutToAdd = new Outlier(xxmid, yyFarout, foRadius); if (dataArea.contains(faroutToAdd.getPoint())) { farOutValues.add(faroutToAdd); } } else if (outlier > maxRegular.doubleValue() || outlier < minRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); Outlier outlierToAdd = new Outlier(xxmid, yyOutlier, oRadius); if (dataArea.contains(outlierToAdd.getPoint())) { outliers.add(outlierToAdd); } } } //draw the outliers g2.setPaint(this.outlierPaint); for (Iterator iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); Point2D point = outlier.getPoint(); Shape dot = createEllipse(point, oRadius); g2.draw(dot); } //draw the farout values g2.setPaint(this.farOutColor); for (Iterator iterator = farOutValues.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); Point2D point = outlier.getPoint(); Shape triangle = createTriangleVertical(point, foRadius); g2.draw(triangle); } } }