List of usage examples for java.awt.geom GeneralPath closePath
public final synchronized void closePath()
From source file:org.trade.ui.chart.renderer.PivotRenderer.java
/** * Draws the annotation.//from w w w . java2 s.c om * * @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. * @param angle * double * @param x * double * @param y * double * @param ledgend * String */ public void drawPivotArrow(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info, double angle, double x, double y, String ledgend) { double tipRadius = DEFAULT_TIP_RADIUS; double baseRadius = DEFAULT_BASE_RADIUS; double arrowLength = DEFAULT_ARROW_LENGTH; double arrowWidth = DEFAULT_ARROW_WIDTH; double labelOffset = DEFAULT_LABEL_OFFSET; Font font = DEFAULT_FONT; Paint paint = DEFAULT_PAINT; boolean outlineVisible = false; Paint outlinePaint = Color.black; Stroke outlineStroke = new BasicStroke(0.5f); TextAnchor textAnchor = DEFAULT_TEXT_ANCHOR; TextAnchor rotationAnchor = DEFAULT_ROTATION_ANCHOR; double rotationAngle = DEFAULT_ROTATION_ANGLE; Stroke arrowStroke = new BasicStroke(1.0f); Paint arrowPaint = Color.black; PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); double j2DX = domainAxis.valueToJava2D(x, dataArea, domainEdge); double j2DY = rangeAxis.valueToJava2D(y, dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { double temp = j2DX; j2DX = j2DY; j2DY = temp; } double startX = j2DX + (Math.cos(angle) * baseRadius); double startY = j2DY + (Math.sin(angle) * baseRadius); double endX = j2DX + (Math.cos(angle) * tipRadius); double endY = j2DY + (Math.sin(angle) * tipRadius); double arrowBaseX = endX + (Math.cos(angle) * arrowLength); double arrowBaseY = endY + (Math.sin(angle) * arrowLength); double arrowLeftX = arrowBaseX + (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth); double arrowLeftY = arrowBaseY + (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth); double arrowRightX = arrowBaseX - (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth); double arrowRightY = arrowBaseY - (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth); GeneralPath arrow = new GeneralPath(); arrow.moveTo((float) endX, (float) endY); arrow.lineTo((float) arrowLeftX, (float) arrowLeftY); arrow.lineTo((float) arrowRightX, (float) arrowRightY); arrow.closePath(); g2.setStroke(arrowStroke); g2.setPaint(arrowPaint); Line2D line = new Line2D.Double(startX, startY, endX, endY); g2.draw(line); g2.fill(arrow); // draw the label double labelX = j2DX + (Math.cos(angle) * (baseRadius + labelOffset)); double labelY = j2DY + (Math.sin(angle) * (baseRadius + labelOffset)); g2.setFont(font); Shape hotspot = TextUtilities.calculateRotatedStringBounds(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle, rotationAnchor); g2.setPaint(paint); TextUtilities.drawRotatedString(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle, rotationAnchor); if (outlineVisible) { g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(hotspot); } // String toolTip = getToolTipText(); // String url = getURL(); // if (toolTip != null || url != null) { // addEntity(info, hotspot, rendererIndex, toolTip, url); // } }
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
/**<!====== drawItem ======================================================> Draws a 3D bar to represent one data item. <! Name Description> @param g2 the graphics device. @param state the renderer state. @param dataArea the area for plotting the data. @param plot the plot.// ww w. j a v a 2s.c o m @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). @param pass the pass index. <!=======================================================================>*/ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } g2.setStroke(new BasicStroke(1)); double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof Color) { Color endColor = getFrontDark((Color) itemPaint); Color startColor = (Color) itemPaint; Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor, (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor); g2.setPaint(paint); } g2.fill(bar); double x0 = bar.getMinX(); // left double x1 = x0 + getXOffset(); // offset left double x2 = bar.getMaxX(); // right double x3 = x2 + getXOffset(); // offset right double y0 = bar.getMinY() - getYOffset(); // offset top double y1 = bar.getMinY(); // bar top double y2 = bar.getMaxY() - getYOffset(); // offset bottom double y3 = bar.getMaxY(); // bottom //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight()); Line2D.Double line = new Line2D.Double(x2, y1, x2, y3); g2.draw(line); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; g2.setPaint(itemPaint); // Draw the right side if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { Color startColor = getSideLight((Color) itemPaint); Color endColor = getSideDark((Color) itemPaint); Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3, endColor); g2.setPaint(paint); } g2.fill(bar3dRight); } // Draw the top bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); // bottom left bar3dTop.lineTo((float) x1, (float) y0); // top left bar3dTop.lineTo((float) x3, (float) y0); // top right bar3dTop.lineTo((float) x2, (float) y1); // bottom right bar3dTop.closePath(); if (itemPaint instanceof Color) { Color endColor = getTopDark((Color) itemPaint); Color startColor = getTopLight((Color) itemPaint); //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor); Point2D.Double topRight = new Point2D.Double(x3, y0); Point2D.Double bottomLeft = new Point2D.Double(x0, y1); //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2))); Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2))); Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor, (float) darkEnd.getX(), (float) darkEnd.getY(), endColor); g2.setPaint(paint); //drawMarker(topRight, g2, startColor); } g2.fill(bar3dTop); g2.setPaint(itemPaint); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:longMethod.jfreechart.draw.XYPolygonAnnotation.java
/** * 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./*ww w . j ava 2 s. c o m*/ * @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. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { // if we don't have at least 2 (x, y) coordinates, just return if (this.polygon.length < 4) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); GeneralPath area = new GeneralPath(); double x = domainAxis.valueToJava2D(this.polygon[0], dataArea, domainEdge); double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { area.moveTo((float) y, (float) x); for (int i = 2; i < this.polygon.length; i += 2) { x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge); y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge); area.lineTo((float) y, (float) x); } area.closePath(); } else if (orientation == PlotOrientation.VERTICAL) { area.moveTo((float) x, (float) y); for (int i = 2; i < this.polygon.length; i += 2) { x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge); y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge); area.lineTo((float) x, (float) y); } area.closePath(); } if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(area); } if (this.stroke != null && this.outlinePaint != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.stroke); g2.draw(area); } addEntity(info, area, rendererIndex, getToolTipText(), getURL()); }
From source file:MyCanvas.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; Point2D.Float point = new Point2D.Float(100, 100); // store start point GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO); p.moveTo(point.x, point.y);//from w ww . ja v a 2 s. co m p.lineTo(point.x + 20.0f, point.y - 5.0f); // Line from start to A point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x + 5.0f, point.y - 20.0f); // Line from A to B point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x + 5.0f, point.y + 20.0f); // Line from B to C point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x + 20.0f, point.y + 5.0f); // Line from C to D point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x - 20.0f, point.y + 5.0f); // Line from D to E point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x - 5.0f, point.y + 20.0f); // Line from E to F point = (Point2D.Float) p.getCurrentPoint(); p.lineTo(point.x - 5.0f, point.y - 20.0f); // Line from F to g p.closePath(); // Line from G to start g2D.draw(p); }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private VisualPeakAnnotation generateOutline(IChromatogramDescriptor chromatogram, IPeakAnnotationDescriptor peakDescr, ADataset1D<IChromatogram1D, IScan> dataset, int seriesIndex) { boolean baselineAvailable = false; if (!(Double.isNaN(peakDescr.getBaselineStartIntensity()) && Double.isNaN(peakDescr.getBaselineStopIntensity()) && Double.isNaN(peakDescr.getBaselineStartTime()) && Double.isNaN(peakDescr.getBaselineStopTime()))) { Logger.getLogger(getClass().getName()).warning("Using baseline for peak outline"); baselineAvailable = true;/*from w w w . java 2s . co m*/ } double sat = peakDescr.getApexTime(); double peakStartTime = peakDescr.getStartTime(); double peakStopTime = peakDescr.getStopTime(); if (Double.isNaN(peakStartTime) || Double.isNaN(peakStopTime)) { return null; } int scan = chromatogram.getChromatogram().getIndexFor(sat); int startIdx = chromatogram.getChromatogram().getIndexFor(peakStartTime); int stopIdx = chromatogram.getChromatogram().getIndexFor(peakStopTime); double peakStartValue = peakDescr.getStartIntensity(); double peakStopValue = peakDescr.getStopIntensity(); double blStartTime, blStopTime, blStartVal, blStopVal; if (baselineAvailable) { blStartTime = peakDescr.getBaselineStartTime(); blStopTime = peakDescr.getBaselineStopTime(); blStartVal = peakDescr.getBaselineStartIntensity(); blStopVal = peakDescr.getBaselineStopIntensity(); } else { blStartTime = peakStartTime; blStopTime = peakStopTime; //FIXME baseline is not correctly shown if (Double.isNaN(peakDescr.getStartIntensity()) || Double.isNaN(peakDescr.getStopIntensity())) { blStartVal = dataset.getYValue(seriesIndex, startIdx); blStopVal = dataset.getYValue(seriesIndex, stopIdx); } else { blStartVal = dataset.getYValue(seriesIndex, startIdx); blStopVal = dataset.getYValue(seriesIndex, stopIdx); } } peakStartValue = dataset.getYValue(seriesIndex, startIdx); peakStopValue = dataset.getYValue(seriesIndex, stopIdx); double peakApexValue = dataset.getYValue(seriesIndex, scan); GeneralPath gp = new GeneralPath(); gp.moveTo(blStartTime, dataset.getYValue(seriesIndex, startIdx) + blStartVal); gp.lineTo(peakStartTime, peakStartValue); for (int j = startIdx + 1; j <= stopIdx; j++) { gp.lineTo(dataset.getXValue(seriesIndex, j), dataset.getYValue(seriesIndex, j)); } gp.lineTo(blStopTime, dataset.getYValue(seriesIndex, stopIdx) + blStopVal); gp.closePath(); Logger.getLogger(getClass().getName()).log(Level.WARNING, "Generating peak outline: ({0};{1})({2};{3}" + ")" + "({4};{5})", new Object[] { peakStartTime, peakStartValue, sat, peakApexValue, peakStopTime, peakStopValue }); VisualPeakAnnotation vpa = new VisualPeakAnnotation(gp, new Point2D.Double(sat, Math.min(peakStartValue, Math.min(peakApexValue, peakStopValue))), PeakAnnotationType.OUTLINE);//generate(peakStartTime, peakStartValue, sat, peakApexValue, peakStopTime, peakStopValue); return vpa; }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java
private void buildLegend() { LegendTitle legend = corrChart.getLegend(); LegendItemSource[] sources = new LegendItemSource[1]; CorrLegendItemSource legendSrc = new CorrLegendItemSource(); LegendItem item = null;/*from w ww .ja va2 s .com*/ //Rect=survival less than 10 months GeneralPath downtriangle = new GeneralPath(); downtriangle.moveTo(-4.0f, -4.0f); downtriangle.lineTo(4.0f, -4.0f); downtriangle.lineTo(0.0f, 4.0f); downtriangle.closePath(); item = new LegendItem("Tumor size reduced by 30% or more (MRI)", null, null, null, downtriangle, Color.BLACK); legendSrc.addLegendItem(item); item = new LegendItem("Tumor size reduced less than 30% or no change (MRI)", null, null, null, new Ellipse2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); GeneralPath uptriangle = new GeneralPath(); uptriangle.moveTo(0.0f, -4.0f); uptriangle.lineTo(4.0f, 4.0f); uptriangle.lineTo(-4.0f, 4.0f); uptriangle.closePath(); item = new LegendItem("Tumor size increased (MRI)", null, null, null, uptriangle, Color.BLACK); legendSrc.addLegendItem(item); item = new LegendItem("Tumor size change N/A", null, null, null, new Rectangle2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); if (colorBy == ColorByType.CLINICALRESPONSE) { for (ClinicalResponseType cr : ClinicalResponseType.values()) { item = new LegendItem(cr.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), cr.getColor()); legendSrc.addLegendItem(item); } } else if (colorBy == ColorByType.DISEASESTAGE) { for (ClinicalStageType ds : ClinicalStageType.values()) { if (!ds.name().endsWith("ALL")) { item = new LegendItem(ds.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ds.getColor()); legendSrc.addLegendItem(item); } } } else if (colorBy == ColorByType.TIMEPOINT) { for (TimepointType tp : TimepointType.values()) { item = new LegendItem(tp.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), tp.getColor()); legendSrc.addLegendItem(item); } } else if ((colorBy == ColorByType.IHC_EXPRESSION_X) || (colorBy == ColorByType.IHC_EXPRESSION_Y)) { // for (CorrScatterColorByIHCType ihcType : CorrScatterColorByIHCType.values()) { // item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), ihcType.getColor()); // legendSrc.addLegendItem(item); // } if (ihcBiomarkerType == IHCBiomarkerType.BCL2) { for (BCL2ihcType ihcType : BCL2ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.EGFR) { for (EGFRihcType ihcType : EGFRihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.FAK) { for (FAKihcType ihcType : FAKihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.HER2) { for (HER2ihcType ihcType : HER2ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.KI67) { for (Ki67ihcType ihcType : Ki67ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.P27) { for (P27ihcType ihcType : P27ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.P53) { for (P53ihcType ihcType : P53ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.CYCLIN_D1) { for (CCND1ihcType ihcType : CCND1ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } } sources[0] = legendSrc; legend.setSources(sources); }
From source file:com.bdaum.zoom.report.internal.jfree.custom.CylinderRenderer.java
/** * Draws a cylinder to represent one data item. * * @param g2 the graphics device.//from w ww .jav a2 s.co m * @param state the renderer state. * @param dataArea the area for plotting the data. * @param plot the plot. * @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). * @param pass the pass index. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); float barL0 = Math.min(transL0, transL1); float barLength = Math.abs(transL1 - transL0); // draw the bar... GeneralPath bar = new GeneralPath(); Shape top = null; if (orientation == PlotOrientation.HORIZONTAL) { bar.moveTo((float) (barL0 + getXOffset() / 2), (float) barW0); bar.lineTo((float) (barL0 + barLength + getXOffset() / 2), (float) barW0); Arc2D arc = new Arc2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth(), 90, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barL0 + getXOffset() / 2), (float) (barW0 + state.getBarWidth())); arc = new Arc2D.Double(barL0, barW0, getXOffset(), state.getBarWidth(), 270, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); top = new Ellipse2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth()); } else { bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2)); bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2)); Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(), getYOffset(), 180, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2)); arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); top = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset()); } Paint itemPaint = getItemPaint(row, column); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); g2.fill(bar); if (itemPaint instanceof GradientPaint) { g2.setPaint(((GradientPaint) itemPaint).getColor2()); } else { g2.setPaint(PaintAlpha.darker(itemPaint)); // bd } if (top != null) { g2.fill(top); } if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (top != null) { g2.draw(top); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar.getBounds2D(), (value < 0.0)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private static void drawArrowToDestination(final Graphics2D gfx, final Rectangle2D start, final Rectangle2D destination, final Stroke lineStroke, final Stroke arrowStroke, final float arrowSize) { final double startx = start.getCenterX(); final double starty = start.getCenterY(); final Point2D arrowPoint = Utils.findRectEdgeIntersection(destination, startx, starty); if (arrowPoint != null) { gfx.setStroke(arrowStroke);/*from w w w.ja va 2 s. c o m*/ double angle = findLineAngle(arrowPoint.getX(), arrowPoint.getY(), startx, starty); final double arrowAngle = Math.PI / 12.0d; final double x1 = arrowSize * Math.cos(angle - arrowAngle); final double y1 = arrowSize * Math.sin(angle - arrowAngle); final double x2 = arrowSize * Math.cos(angle + arrowAngle); final double y2 = arrowSize * Math.sin(angle + arrowAngle); final double cx = (arrowSize / 2.0f) * Math.cos(angle); final double cy = (arrowSize / 2.0f) * Math.sin(angle); final GeneralPath polygon = new GeneralPath(); polygon.moveTo(arrowPoint.getX(), arrowPoint.getY()); polygon.lineTo(arrowPoint.getX() + x1, arrowPoint.getY() + y1); polygon.lineTo(arrowPoint.getX() + x2, arrowPoint.getY() + y2); polygon.closePath(); gfx.fill(polygon); gfx.setStroke(lineStroke); gfx.drawLine((int) startx, (int) starty, (int) (arrowPoint.getX() + cx), (int) (arrowPoint.getY() + cy)); } }
From source file:org.operamasks.faces.render.graph.CurveAndShapeRenderer.java
private void drawSeriesCurve(Graphics2D g2, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int series) { // do nothing if item is not visible if (!(getItemVisible(series, 0) && (getItemLineVisible(series, 0) || drawArea))) { return;/*from w ww .j a v a 2 s .c om*/ } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); PlotOrientation orientation = plot.getOrientation(); int itemCount = dataset.getColumnCount(); double[][] points = new double[itemCount][2]; int count = 0; // get data points for (int i = 0; i < itemCount; i++) { Number value = dataset.getValue(series, i); if (value != null) { points[count][0] = domainAxis.getCategoryMiddle(i, itemCount, dataArea, xAxisLocation); points[count][1] = rangeAxis.valueToJava2D(value.doubleValue(), dataArea, yAxisLocation); count++; } } if (count < 2) { return; } // draw curve CubicSplineFunction2D f = new CubicSplineFunction2D(points, count); GeneralPath path = new GeneralPath(); double startX = points[0][0]; double startY = points[0][1]; double endX = points[count - 1][0]; double endY = points[count - 1][1]; double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { if (drawArea) { path.moveTo((float) yz, (float) startX); path.lineTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); path.lineTo((float) yz, (float) endX); path.closePath(); } else { path.moveTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); } } else { if (drawArea) { path.moveTo((float) startX, (float) yz); path.lineTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); path.lineTo((float) endX, (float) yz); path.closePath(); } else { path.moveTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); } } Paint paint = getSeriesPaint(series); Stroke stroke = getSeriesStroke(series); if (drawArea) { g2.setPaint(paint); g2.fill(path); // create paint for outline if (paint instanceof Color) { paint = ((Color) paint).darker(); } else if (paint instanceof GradientPaint) { paint = ((GradientPaint) paint).getColor1().darker(); } } if (getItemLineVisible(series, 0)) { g2.setPaint(paint); g2.setStroke(stroke); g2.draw(path); } }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java
private void createGlyphsAndAddToPlot(XYPlot plot, double xScale, double yScale) { XYShapeAnnotation glyph;// ww w . j a v a 2 s . c o m Shape glyphShape = null; Color glyphColor; //double glyphSize = 8.0; //pixels double glyphIncrementX = (glyphSize * xScale) / 2.0; double glyphIncrementY = (glyphSize * yScale) / 2.0; float gi_x = (float) glyphIncrementX; float gi_y = (float) glyphIncrementY; PatientData pd; double x, y; Double mriPctChange = null; for (ISPYPlotPoint corrPoint : dataPoints) { x = corrPoint.getX(); y = corrPoint.getY(); mriPctChange = corrPoint.getMRITumorPctChange(); if (mriPctChange == null) { //data is missing Rectangle2D.Double rect = new Rectangle2D.Double(); //rect.setFrameFromCenter(x,y, x+1.25,y+1.25); rect.setFrameFromCenter(x, y, x + glyphIncrementX, y + glyphIncrementY); glyphShape = rect; } else if (mriPctChange <= -30.0) { //tumor shrank by more than 30% (down arrow) GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf - gi_x, yf + gi_y); gp.lineTo(xf + gi_x, yf + gi_y); gp.closePath(); glyphShape = gp; } else if (mriPctChange > 0.0) { //tumor size increased (up arrow) GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf + gi_x, yf - gi_y); gp.lineTo(xf - gi_x, yf - gi_y); gp.closePath(); glyphShape = gp; // Ellipse2D.Double circle = new Ellipse2D.Double(); // circle.setFrameFromCenter(x,y, x+2, y+2); } else if ((mriPctChange > -30.0) && (mriPctChange <= 0.0)) { //no change or reduction in tumor size but less than 30% reduction Ellipse2D.Double circle = new Ellipse2D.Double(); //circle.setFrameFromCenter(x,y,x+1.25,y+1.25); circle.setFrameFromCenter(x, y, x + gi_x, y + gi_y); glyphShape = circle; } //glyphColor = Color.BLUE; //later can set color based on glyphColor = getColorForDataPoint(corrPoint); glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor); String tooltip = corrPoint.getTag(); glyph.setToolTipText(tooltip); plot.addAnnotation(glyph); } }