List of usage examples for java.awt.geom GeneralPath moveTo
public abstract void moveTo(double x, double y);
From source file:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java
protected Shape getOuterWindow(Rectangle2D frame) { double radiusMargin = 0.02; double angleMargin = 1.5; Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius - radiusMargin, this.innerRadius - radiusMargin); Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius + radiusMargin, this.outerRadius + radiusMargin); Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN);//from w ww . jav a 2 s . c o m Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + angleMargin + this.extent, -this.extent - 2 * angleMargin, Arc2D.OPEN); GeneralPath p = new GeneralPath(); Point2D point1 = inner.getStartPoint(); p.moveTo((float) point1.getX(), (float) point1.getY()); p.append(inner, true); p.append(outer, true); p.closePath(); return p; }
From source file:io.github.dsheirer.spectrum.SpectrumPanel.java
/** * Draws the current fft spectrum with a line and a gradient fill. *//*from w w w . ja va 2 s. c om*/ private void drawSpectrum(Graphics2D graphics) { Dimension size = getSize(); //Draw the background Rectangle background = new Rectangle(0, 0, size.width, size.height); graphics.setColor(mColorSpectrumBackground); graphics.draw(background); graphics.fill(background); //Define the gradient GradientPaint gradient = new GradientPaint(0, (getSize().height - mSpectrumInset) / 2, mColorSpectrumGradientTop, 0, getSize().height, mColorSpectrumGradientBottom); graphics.setBackground(mColorSpectrumBackground); GeneralPath spectrumShape = new GeneralPath(); //Start at the lower right inset point spectrumShape.moveTo(size.getWidth(), size.getHeight() - mSpectrumInset); //Draw to the lower left spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset); float[] bins = getBins(); //If we have FFT data to display ... if (bins != null) { float insideHeight = size.height - mSpectrumInset; float scalor = insideHeight / -mDBScale; /* Calculate based on bin size - 1, since bin 0 is rendered at zero * and the last bin is rendered at the width */ float binSize = (float) size.width / ((float) (bins.length)); for (int x = 0; x < bins.length; x++) { float height; height = bins[x] * scalor; if (height > insideHeight) { height = insideHeight; } if (height < 0) { height = 0; } float xAxis = (float) x * binSize; spectrumShape.lineTo(xAxis, height); } } //Otherwise show an empty spectrum else { //Draw Left Size graphics.setPaint(gradient); spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset); //Draw Middle spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset); } //Draw Right Side spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset); graphics.setPaint(gradient); graphics.draw(spectrumShape); graphics.fill(spectrumShape); graphics.setPaint(mColorSpectrumLine); //Draw the bottom line under the spectrum graphics.draw(new Line2D.Float(0, size.height - mSpectrumInset, size.width, size.height - mSpectrumInset)); }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java
/** * This chart uses the XYAnnotation as a glyph to represent * a single pca data point. Glyph shape is determined by survival time. * Survival of more than 10 months is represented by a circle. 10 months or less * is represented by a square. Component1 values are represented by X * Component2 values are represented by Y *//*from w w w .j ava2s. co m*/ protected void createGlyphsAndAddToPlot(XYPlot plot) { XYShapeAnnotation glyph; Shape glyphShape; Color glyphColor; PrincipalComponentAnalysisDataPoint pcaPoint; double x, y; for (Iterator i = dataPoints.iterator(); i.hasNext();) { pcaPoint = (PrincipalComponentAnalysisDataPoint) i.next(); x = pcaPoint.getComponentValue(component1); y = pcaPoint.getComponentValue(component2); double survival = pcaPoint.getSurvivalInMonths(); if ((survival > 0) && (survival < 10.0)) { Rectangle2D.Double rect = new Rectangle2D.Double(); rect.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = rect; } else if ((survival > 0) && (survival >= 10.0)) { Ellipse2D.Double circle = new Ellipse2D.Double(); circle.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = circle; } else { //Rectangle2D.Double rect = new Rectangle2D.Double(); //rect.setFrameFromCenter(x,y, x+2,y+2); GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf + 3.0f, yf - 3.0f); gp.lineTo(xf - 3.0f, yf - 3.0f); gp.closePath(); glyphShape = gp; } glyphColor = getColorForDataPoint(pcaPoint); glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor); String tooltip = ""; if (pcaPoint.getSurvivalInMonths() <= 0.0) { tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName(); } else { tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName() + " survivalMonths=" + nf.format(pcaPoint.getSurvivalInMonths()); } glyph.setToolTipText(tooltip); plot.addAnnotation(glyph); } }
From source file:gda.plots.TurboXYItemRenderer.java
private GeneralPath addPointToLine(GeneralPath path, PlotOrientation orientation, int x, int y) { if (drawLines) { if (orientation == PlotOrientation.HORIZONTAL) { int dummy = x; x = y;//from w w w . j a v a2 s . c o m y = dummy; } if (path == null) { path = new GeneralPath(); path.moveTo(x, y); } else { path.lineTo(x, y); } } return path; }
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;//www .j av a 2 s.com } 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:org.operamasks.faces.render.graph.XYCurveAndShapeRenderer.java
/** * 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.// ww w. j a v a2 s . c om * * @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 domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataArea the area within which the data is being drawn. */ protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item != 0) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); PlotOrientation orientation = plot.getOrientation(); int itemCount = dataset.getItemCount(series); double[][] points = new double[itemCount][2]; int count = 0; for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(series, i); double y = dataset.getYValue(series, i); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); if (!Double.isNaN(transX) && !Double.isNaN(transY)) { points[count][0] = transX; points[count][1] = transY; count++; } } if (count < 2) { return; } // sort points according to x axis Arrays.sort(points, new Comparator<double[]>() { public int compare(double[] a, double[] b) { return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0; } }); // 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 = getItemPaint(series, item); Stroke stroke = getItemStroke(series, item); 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(); } } g2.setPaint(paint); g2.setStroke(stroke); g2.draw(path); }
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./* www . j a v a2 s. com*/ @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:org.openmeetings.app.data.record.BatikMethods.java
public void drawArrow(SVGGraphics2D g2d, GeomPoint start, GeomPoint end, float thickness, float alpha, Color linecoler, Color fillColor) { if (start.equals(end)) return;/*w w w.jav a2 s .c o m*/ // (double edgeControlPosition, double edgeControlSize, // double headLength, double headWidth, double shaftControlPosition, // double shaftControlSize, float shaftPosition, double shaftThickness) ArrowStyle arrowStyle = new ArrowStyle(0.5, 0.5, thickness * 5, thickness * 5, 0.5, 0.5, 0, thickness); GeomPoint fullVect = end.subtract(start); double halfWidth = (arrowStyle.headWidth != -1) ? arrowStyle.headWidth / 2 : arrowStyle.headLength / 2; //Figure out the line start/end points GeomPoint startNorm = new GeomPoint(); startNorm.setLocation(fullVect.getY(), -fullVect.getX()); startNorm.normalize(arrowStyle.shaftThickness / 2); GeomPoint start1 = start.add(startNorm); GeomPoint start2 = start.subtract(startNorm); GeomPoint end1 = end.add(startNorm); GeomPoint end2 = end.subtract(startNorm); //log.debug("startNorm: "+startNorm.toString()); //log.debug("start1: "+start1.toString()); //log.debug("start2: "+start2.toString()); //log.debug("end1: "+end1.toString()); //log.debug("end2: "+end2.toString()); //figure out where the arrow head starts GeomPoint headPnt = fullVect.clone(); //log.debug("headPnt 1: "+headPnt.toString()); //log.debug("headPnt.length 1: "+headPnt.length()); //log.debug("arrowStyle.headLength 1: "+arrowStyle.headLength); headPnt.normalize(headPnt.length() - arrowStyle.headLength); //log.debug("headPnt 2: "+headPnt.toString()); headPnt = headPnt.add(start); //log.debug("headPnt 3: "+headPnt.toString()); //calculate the arrowhead corners GeomPoint headPntNorm = startNorm.clone(); //log.debug("headPntNorm ^^: "+headPntNorm.toString()); //log.debug("halfWidth ^^: "+halfWidth); headPntNorm.normalize(halfWidth); //log.debug("headPntNorm: "+headPntNorm.toString()); GeomPoint edge1 = headPnt.add(headPntNorm); GeomPoint edge2 = headPnt.subtract(headPntNorm); //log.debug("edge1: "+edge1.toString()); //log.debug("edge2: "+edge2.toString()); //Figure out where the arrow connects the the shaft, then calc the intersections GeomPoint shaftCenter = GeomPoint.interpolate(end, headPnt, arrowStyle.shaftPosition); //log.debug("end"+end.toString()); //log.debug("headPnt: "+headPnt.toString()); //log.debug("arrowStyle.shaftPosition: "+arrowStyle.shaftPosition); //log.debug("shaftCenter: "+shaftCenter); //log.debug("edge1: "+edge1); //shaftCenter.setLocation(185.857864376269, 185.857864376269); GeomPoint inter1 = GeomPoint.getLineIntersection(start1, end1, shaftCenter, edge1); GeomPoint inter2 = GeomPoint.getLineIntersection(start2, end2, shaftCenter, edge2); //log.debug("inter1: "+inter1.toString()); //log.debug("inter2: "+inter2.toString()); //Figure out the control points GeomPoint edgeCenter = GeomPoint.interpolate(end, headPnt, (float) arrowStyle.edgeControlPosition); GeomPoint edgeNorm = startNorm.clone(); edgeNorm.normalize(halfWidth * arrowStyle.edgeControlSize); //log.debug("halfWidth*arrowStyle.edgeControlSize: "+(halfWidth*arrowStyle.edgeControlSize)); //log.debug("edgeNorm: "+edgeNorm.toString()); GeomPoint edgeCntrl1 = edgeCenter.add(edgeNorm); GeomPoint edgeCntrl2 = edgeCenter.subtract(edgeNorm); //log.debug("edgeCntrl1: "+edgeCntrl1.toString()); //log.debug("edgeCntrl2: "+edgeCntrl2.toString()); g2d.setPaint(new Color(255, 0, 0)); // graphics.moveTo(start1.x,start1.y); // graphics.lineTo(inter1.x,inter1.y); // graphics.lineTo(edge1.x,edge1.y); // graphics.curveTo(edgeCntrl1.x,edgeCntrl1.y,end.x,end.y); // graphics.curveTo(edgeCntrl2.x,edgeCntrl2.y,edge2.x,edge2.y); // graphics.lineTo(inter2.x,inter2.y); // graphics.lineTo(start2.x,start2.y); // graphics.lineTo(start1.x,start1.y); // log.debug("moveTo"+start1.x+","+start1.y); // log.debug("lineTo"+inter1.x+","+inter1.y); // log.debug("lineTo"+edge1.x+","+edge1.y); // log.debug("quadTo"+edgeCntrl1.x+","+edgeCntrl1.y+","+end.x+","+end.y); // log.debug("quadTo"+edgeCntrl2.x+","+edgeCntrl2.y+","+edge2.x+","+edge2.y); // log.debug("lineTo"+inter2.x+","+inter2.y); // log.debug("lineTo"+start2.x+","+start2.y); // log.debug("lineTo"+start1.x+","+start1.y); GeneralPath graphics = new GeneralPath(); graphics.moveTo(start1.x, start1.y); graphics.lineTo(inter1.x, inter1.y); graphics.lineTo(edge1.x, edge1.y); graphics.quadTo(edgeCntrl1.x, edgeCntrl1.y, end.x, end.y); graphics.quadTo(edgeCntrl2.x, edgeCntrl2.y, edge2.x, edge2.y); graphics.lineTo(inter2.x, inter2.y); graphics.lineTo(start2.x, start2.y); graphics.lineTo(start1.x, start1.y); graphics.closePath(); int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); if (linecoler != null) { g2d.setPaint(linecoler); g2d.draw(graphics); } if (fillColor != null) { g2d.setPaint(fillColor); g2d.fill(graphics); } }
From source file:org.trade.ui.chart.renderer.PivotRenderer.java
/** * Draws the annotation./* ww w.j av a 2s . com*/ * * @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:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYPrincipalComponentAnalysisPlot.java
/** * This chart uses the XYAnnotation as a glyph to represent * a single pca data point. Glyph shape is determined by survival time. * Survival of more than 10 months is represented by a circle. 10 months or less * is represented by a square. Component1 values are represented by X * Component2 values are represented by Y *//*from w ww. j a v a 2 s .c om*/ private void createGlyphsAndAddToPlot(XYPlot plot, double glyphScaleFactor) { XYShapeAnnotation glyph; Shape glyphShape = null; Color glyphColor; double glyphSize = 8.0; //pixels double glyphIncrement = (glyphSize * glyphScaleFactor) / 2.0; float gi = (float) glyphIncrement; ISPYPCADataPoint pcaPoint; double x, y; for (Iterator i = dataPoints.iterator(); i.hasNext();) { pcaPoint = (ISPYPCADataPoint) i.next(); x = pcaPoint.getComponentValue(component1); y = pcaPoint.getComponentValue(component2); Double mriPctChange = pcaPoint.getTumorMRIpctChange(); 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 + glyphIncrement, y + glyphIncrement); 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, yf + gi); gp.lineTo(xf + gi, yf + gi); 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, yf - gi); gp.lineTo(xf - gi, yf - gi); 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, y + gi); glyphShape = circle; } glyphColor = getColorForDataPoint(pcaPoint); glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor); String tooltip = pcaPoint.toString(); glyph.setToolTipText(tooltip); plot.addAnnotation(glyph); } }