List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
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./*from w w w. ja v a 2 s . c o m*/ * * @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:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();//from ww w . java2 s .c o m Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Rectangle2D entityBounds = entity.getBounds2D(); double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge); double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge); double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge); double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge); PlotOrientation orientation = plot.getOrientation(); //transform model to origin (0,0) in model coordinates AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(), -entityBounds.getCenterY()); //transform from origin (0,0) to model location AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(), entityBounds.getCenterY()); //transform from model scale to view scale double scaleX = viewW / entityBounds.getWidth(); double scaleY = viewH / entityBounds.getHeight(); Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}", new Object[] { scaleX, scaleY }); AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY); AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f); AffineTransform modelToView = new AffineTransform(toOrigin); modelToView.preConcatenate(flipTransform); modelToView.preConcatenate(toViewScale); modelToView.preConcatenate(toViewLocation); // // if (orientation == PlotOrientation.HORIZONTAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewY, // viewX); // } else if (orientation == PlotOrientation.VERTICAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewX, // viewY); // } FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity) .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * Creates a bubble chart with default settings. The chart is composed of an {@link XYPlot}, with a {@link NumberAxis} for the * domain axis, a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} to draw the data items. * //from w ww.j ava 2s . c o m * This method is copied from * {@link org.jfree.chart.ChartFactory#createBubbleChart(String, String, String, XYZDataset, PlotOrientation, boolean, boolean, boolean)} * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException(Messages.getString("TopChartFactory.argument")); //$NON-NLS-1$ } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS) { @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // return straight away if the item is not visible if (!getItemVisible(series, item)) { return; } PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double transDomain = 0.0; double transRange = 0.0; double zero; // MOD scorreia +2L avoid points: minimal size of circle must be 1 // z = z * transX + 1; // ADD xqliu 2009-07-06 bug 8035 double zSize = getBubbleSize(z); // calculate the multiple of bubble's default size z = 0; // use bubble's default size // ~ switch (getScaleType()) { case SCALE_ON_DOMAIN_AXIS: zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero; transRange = transDomain; break; case SCALE_ON_RANGE_AXIS: zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); transDomain = transRange; break; default: double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1; transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); } transDomain = Math.abs(transDomain); transRange = Math.abs(transRange); // MODSCA 2008-11-27 enlarge ellipse by diag% of the total diagonal double diag = Math.sqrt(dataArea.getHeight() * dataArea.getHeight() + dataArea.getWidth() * dataArea.getWidth()); transDomain += diag / 100; transRange += diag / 100; Ellipse2D circle = null; // ADD xqliu 2009-07-06 bug 8035 transDomain *= zSize; transRange *= zSize; // ~ if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double(transX - transDomain / 2.0, transY - transRange / 2.0, transDomain, transRange); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double(transY - transRange / 2.0, transX - transDomain / 2.0, transRange, transDomain); } g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // add an entity if this info is being collected EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); if (entities != null && circle.intersects(dataArea)) { addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY()); } } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } } /** * DOC xqliu : calculate the size of bubble. for bug 8035 2009-07-06. * * @param z multiple of bubble's default size * @return */ private double getBubbleSize(double z) { if (z > 0 && z <= 10) { return 2; } else if (z > 10 && z <= 100) { return 3; } else if (z > 100) { return 4; } return 1; } }; if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:ucar.unidata.idv.control.chart.MyXYPlot.java
/** * Utility method for drawing a vertical line on the data area of the plot. * * @param g2 the graphics device./* w ww . j av a 2 s . c o m*/ * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getDomainAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getRangeAxis(); } if (axis.getRange().contains(value)) { double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
From source file:ucar.unidata.idv.control.chart.MyXYPlot.java
/** * Utility method for drawing a horizontal line across the data area of the * plot./*from www .java2s .com*/ * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getRangeAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getDomainAxis(); } if (axis.getRange().contains(value)) { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
From source file:gov.nih.nci.caintegrator.application.graphing.BoxAndWhiskerDotsRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a vertical orientation./*from w w w. j a v a 2 s . 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). */ public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { 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); 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 yyAverage = 0.0; double yyOutlier; //bar colors are determined by the Paint p obtained here in a rotational //manner (from a Color array). By switching the column and raw values, //you can get a different color pattern for the bar: In the method //getItemPaint(), only the first argument counts for the color. The original //code Paint p = getItemPaint(row, column); is commented out for a difference. //Paint p = getItemPaint(row, column); Paint p = getItemPaint(column, row); // <-- this is wrong, dont know who put this here // Paint p = PaintUtilities.stringToColor("red"); // coin plot should all be one color if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); double aRadius = 0; // average radius RectangleEdge location = plot.getRangeAxisEdge(); Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); Shape box = null; 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); double xxmid = xx + state.getBarWidth() / 2.0; // draw the upper shadow... g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax)); // draw the lower shadow... 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)); if (this.fillBox) { g2.fill(box); } //The following draw the boxes where mean and media are located. g2.draw(box); } g2.setPaint(this.artifactPaint); // draw median... Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null) { double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian)); } //caIntegrator: The outLiner is no longer needed to be here. // draw the rawData around the box... /////////////////////////////////caIntegrator: Begin of drawing dots around the box double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius; double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius; g2.setPaint(p); //caIntegrator: oRadius is the radius of the outlier circles. It was used to be 3. double oRadius = state.getBarWidth() / 10; // outlier radius List outliers = new ArrayList(); //Get the raw item data for a given row/column pair for plotting. //getRawItemData() method is added to bawDataset object for //this purpose. //List yOutliers = bawDataset.getRawItemData(row, column); List yOutliers = this.caintegOutliers.get(String.valueOf(row) + "_" + String.valueOf(column)); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { double outlier = ((Number) yOutliers.get(i)).doubleValue(); yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); Collections.sort(outliers); } //Sort the raw data according to its Y axis first as groups. //Grouping of these raw data is based on a single standard: //if any number of data, when plotted on a vertical line, overlap //with one another, they belong to the same group. In this case, //the grouping is largely determined by the diameter of the dot, that //represents each raw data. boolean firstOutlier = true; double topY = 0; double bottomY = 0; List groupList = new ArrayList(); List tempList = null; double diameter = 2 * oRadius; double difference = 0; for (Iterator iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); //Set the smallest outlier as the base bottom line if (firstOutlier) { firstOutlier = false; bottomY = outlier.getY(); tempList = new ArrayList(); tempList.add(outlier); continue; } topY = outlier.getY(); //If this one and the one before it is overlapping, //Then put them in the same group, so we can spread them //horizontally difference = topY - bottomY; if (difference < diameter) { tempList.add(outlier); } //They do not overlap, they belong to the different groups. else { bottomY = topY; groupList.add(tempList); tempList = new ArrayList(); tempList.add(outlier); } } //caIntegrator - x axis cloud //Process each outlier's x coordinates boolean isOdd = true; double offSet = 0; int listSize = 0; for (int m = 0; m < groupList.size(); m++) { List list = (List) groupList.get(m); if (list != null && list.size() > 1) { listSize = list.size(); isOdd = (listSize % 2 == 1) ? true : false; if (isOdd) { offSet = diameter * (listSize / 2); } else { offSet = diameter * (listSize / 2) - oRadius; } Random r = new Random(); offSet = (Math.abs(r.nextInt()) % 3) * 3; offSet = 0; for (int n = 0; n < list.size(); n++) { Outlier outlier = (Outlier) list.get(n); outlier.setPoint(new Point2D.Double(outlier.getX() - offSet, outlier.getY())); offSet = offSet - diameter; r = new Random(); int randInt = Math.abs(r.nextInt()) % 3; offSet = randInt * 2; } } } //Draw these dots on the graph. for (Iterator iterator = groupList.iterator(); iterator.hasNext();) { List list = (List) iterator.next(); for (int i = 0; i < list.size(); i++) { Outlier outlier = (Outlier) list.get(i); Point2D point = outlier.getPoint(); drawEllipse(point, oRadius, g2); } } } }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.BoxAndWhiskerCoinPlotRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a vertical orientation.// w ww. j a v a 2 s.c o 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). */ public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column) { 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; 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 yyAverage = 0.0; double yyOutlier; // bar colors are determined by the Paint p obtained here in a rotational //manner (from a Color array). By switching the column and raw values, //you can get a different color pattern for the bar: In the method //getItemPaint(), only the first argument counts for the color. The original //code Paint p = getItemPaint(row, column); is commented out for a difference. Paint p = null; if (this.getPlotColor() != null) { p = PaintUtilities.stringToColor(getPlotColor()); // coin plot should all be one color } else { p = getItemPaint(row, column); } // Paint p = PaintUtilities.stringToColor("red"); if (p != null) { g2.setPaint(p); } Stroke s = getItemStroke(row, column); g2.setStroke(s); double aRadius = 0; // average radius RectangleEdge location = plot.getRangeAxisEdge(); Number yQ1 = bawDataset.getQ1Value(row, column); Number yQ3 = bawDataset.getQ3Value(row, column); Number yMax = bawDataset.getMaxRegularValue(row, column); Number yMin = bawDataset.getMinRegularValue(row, column); Shape box = null; 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); double xxmid = xx + state.getBarWidth() / 2.0; // draw the upper shadow... g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3)); g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax)); // draw the lower shadow... 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)); if (getFillBox()) { g2.fill(box); } g2.draw(box); } g2.setPaint(getArtifactPaint()); if (this.isDisplayMean()) { // draw mean - SPECIAL AIMS REQUIREMENT... Number yMean = bawDataset.getMeanValue(row, column); if (yMean != null) { yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location); aRadius = state.getBarWidth() / 4; Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx + aRadius, yyAverage - aRadius, aRadius * 2, aRadius * 2); g2.fill(avgEllipse); g2.draw(avgEllipse); } } if (this.isDisplayMedian()) { // draw median... Number yMedian = bawDataset.getMedianValue(row, column); if (yMedian != null) { double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location); g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian)); } } // draw yOutliers... double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius; double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius; g2.setPaint(p); if (this.isDisplayCoinCloud()) { //draw coin clouds drawCoinCloud(g2, state, dataArea, location, rangeAxis, xx, row, column, bawDataset); } //caIntegrator: oRadius is the radius of the outlier circles. It was used to be 3. // draw outliers double oRadius = state.getBarWidth() / this.outlierRadiusDenominator; // outlier radius List outliers = new ArrayList(); OutlierListCollection outlierListCollection = new OutlierListCollection(); List yOutliers = bawDataset.getOutliers(row, column); if (yOutliers != null) { for (int i = 0; i < yOutliers.size(); i++) { double outlier = ((Number) yOutliers.get(i)).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()) { outlierListCollection.setHighFarOut(true); } else if (outlier < minOutlier.doubleValue()) { outlierListCollection.setLowFarOut(true); } else if (outlier > maxRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } else if (outlier < minRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } Collections.sort(outliers); } //display farouts as JFreeChart Implemetation if (!displayAllOutliers) { // Process outliers. Each outlier is either added to the // appropriate outlier list or a new outlier list is made for (int i = 0; i < yOutliers.size(); i++) { Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); double outlier = ((Number) yOutliers.get(i)).doubleValue(); if (outlier < minRegular.doubleValue() || outlier > maxRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } } for (Iterator iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); outlierListCollection.add(outlier); } for (Iterator iterator = outlierListCollection.iterator(); iterator.hasNext();) { OutlierList list = (OutlierList) iterator.next(); Outlier outlier = list.getAveragedOutlier(); Point2D point = outlier.getPoint(); if (list.isMultiple()) { drawMultipleEllipse(point, state.getBarWidth(), oRadius, g2); } else { drawEllipse(point, oRadius, g2); } } // draw farout indicators if (outlierListCollection.isHighFarOut()) { drawHighFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, maxAxisValue); } if (outlierListCollection.isLowFarOut()) { drawLowFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, minAxisValue); } } else { for (int i = 0; i < yOutliers.size(); i++) { Number minRegular = bawDataset.getMinRegularValue(row, column); Number maxRegular = bawDataset.getMaxRegularValue(row, column); double outlier = ((Number) yOutliers.get(i)).doubleValue(); if (outlier < minRegular.doubleValue() || outlier > maxRegular.doubleValue()) { yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location); outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius)); } } Collections.sort(outliers); for (Iterator iterator = outliers.iterator(); iterator.hasNext();) { Outlier outlier = (Outlier) iterator.next(); Point2D point = outlier.getPoint(); drawEllipse(point, oRadius, g2); } } } // 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(box, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); } } }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw a frame around the image; color depends on resolution if wanted * * @param movie//www .j a va 2s .c o m * @param bi * @return */ private BufferedImage drawFrame(Movie movie, BufferedImage bi) { BufferedImage newImg = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D newGraphics = newImg.createGraphics(); newGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int cornerRadius2 = 0; if (!movie.isHD()) { String[] colorSD = frameColorSD.split("/"); int[] lengthSD = new int[colorSD.length]; for (int i = 0; i < colorSD.length; i++) { lengthSD[i] = Integer.parseInt(colorSD[i]); } newGraphics.setPaint(new Color(lengthSD[0], lengthSD[1], lengthSD[2])); } else if (highdefDiff) { if (movie.isHD()) { // Otherwise use the 720p String[] color720 = frameColor720.split("/"); int[] length720 = new int[color720.length]; for (int i = 0; i < color720.length; i++) { length720[i] = Integer.parseInt(color720[i]); } newGraphics.setPaint(new Color(length720[0], length720[1], length720[2])); } if (movie.isHD1080()) { String[] color1080 = frameColor1080.split("/"); int[] length1080 = new int[color1080.length]; for (int i = 0; i < color1080.length; i++) { length1080[i] = Integer.parseInt(color1080[i]); } newGraphics.setPaint(new Color(length1080[0], length1080[1], length1080[2])); } } else { // We don't care, so use the default HD logo. String[] colorHD = frameColorHD.split("/"); int[] lengthHD = new int[colorHD.length]; for (int i = 0; i < colorHD.length; i++) { lengthHD[i] = Integer.parseInt(colorHD[i]); } newGraphics.setPaint(new Color(lengthHD[0], lengthHD[1], lengthHD[2])); } if (roundCorners) { cornerRadius2 = cornerRadius; } RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, bi.getWidth(), bi.getHeight(), rcqFactor * cornerRadius2, rcqFactor * cornerRadius2); newGraphics.setClip(rect); // image fitted into border newGraphics.drawImage(bi, (int) (rcqFactor * frameSize - 1), (int) (rcqFactor * frameSize - 1), (int) (bi.getWidth() - (rcqFactor * frameSize * 2) + 2), (int) (bi.getHeight() - (rcqFactor * frameSize * 2) + 2), null); BasicStroke s4 = new BasicStroke(rcqFactor * frameSize * 2); newGraphics.setStroke(s4); newGraphics.draw(rect); newGraphics.dispose(); return newImg; }
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer).// www. j a v a 2 s.c o m * * @param g2 the graphics device. * @param area the area within which the plot 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 info about the drawing. */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); if (info != null) { info.setPlotArea(area); info.setDataArea(area); } drawBackground(g2, area); //drawOutline(g2, area); Shape savedClip = g2.getClip(); g2.clip(area); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { int seriesCount = 0, catCount = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { seriesCount = this.dataset.getRowCount(); catCount = this.dataset.getColumnCount(); } else { seriesCount = this.dataset.getColumnCount(); catCount = this.dataset.getRowCount(); } // ensure we have a maximum value to use on the axes if (this.maxValue == DEFAULT_MAX_VALUE) calculateMaxValue(seriesCount, catCount); // Next, setup the plot area // adjust the plot area by the interior spacing value double gapHorizontal = area.getWidth() * getInteriorGap(); double gapVertical = area.getHeight() * getInteriorGap(); double X = area.getX() + gapHorizontal / 2; double Y = area.getY() + gapVertical / 2; double W = area.getWidth() - gapHorizontal; double H = area.getHeight() - gapVertical; double headW = area.getWidth() * this.headPercent; double headH = area.getHeight() * this.headPercent; // make the chart area a square double min = Math.min(W, H) / 2; X = (X + X + W) / 2 - min; Y = (Y + Y + H) / 2 - min; W = 2 * min; H = 2 * min; Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2); Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H); // draw the axis and category label for (int cat = 0; cat < catCount; cat++) { double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3)); Point2D endPoint = getWebPoint(radarArea, angle, 1); // 1 = end of axis Line2D line = new Line2D.Double(centre, endPoint); g2.setPaint(this.axisLinePaint); g2.setStroke(this.axisLineStroke); g2.draw(line); drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / (catCount > 2 ? catCount : 3)); } // Now actually plot each of the series polygons.. for (int series = 0; series < seriesCount; series++) { drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW); } } else { drawNoDataMessage(g2, area); } g2.setClip(savedClip); g2.setComposite(originalComposite); //drawOutline(g2, area); }
From source file:org.jfree.chart.demo.CylinderRenderer.java
public void drawItem(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate, Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis, CategoryDataset categorydataset, int i, int j, int k) { Number number = categorydataset.getValue(i, j); if (number == null) return;/*from w ww . ja v a 2 s . com*/ double d = number.doubleValue(); java.awt.geom.Rectangle2D.Double double1 = new java.awt.geom.Rectangle2D.Double(rectangle2d.getX(), rectangle2d.getY() + getYOffset(), rectangle2d.getWidth() - getXOffset(), rectangle2d.getHeight() - getYOffset()); PlotOrientation plotorientation = categoryplot.getOrientation(); double d1 = calculateBarW0(categoryplot, plotorientation, double1, categoryaxis, categoryitemrendererstate, i, j); double ad[] = calculateBarL0L1(d); if (ad == null) return; RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge(); float f = (float) valueaxis.valueToJava2D(ad[0], double1, rectangleedge); float f1 = (float) valueaxis.valueToJava2D(ad[1], double1, rectangleedge); float f2 = Math.min(f, f1); float f3 = Math.abs(f1 - f); GeneralPath generalpath = new GeneralPath(); java.awt.geom.Ellipse2D.Double double2 = null; if (plotorientation == PlotOrientation.HORIZONTAL) { generalpath.moveTo((float) ((double) f2 + getXOffset() / 2D), (float) d1); generalpath.lineTo((float) ((double) (f2 + f3) + getXOffset() / 2D), (float) d1); java.awt.geom.Arc2D.Double double3 = new java.awt.geom.Arc2D.Double(f2 + f3, d1, getXOffset(), categoryitemrendererstate.getBarWidth(), 90D, 180D, 0); generalpath.append(double3, true); generalpath.lineTo((float) ((double) f2 + getXOffset() / 2D), (float) (d1 + categoryitemrendererstate.getBarWidth())); double3 = new java.awt.geom.Arc2D.Double(f2, d1, getXOffset(), categoryitemrendererstate.getBarWidth(), 270D, -180D, 0); generalpath.append(double3, true); generalpath.closePath(); double2 = new java.awt.geom.Ellipse2D.Double(f2 + f3, d1, getXOffset(), categoryitemrendererstate.getBarWidth()); } else { generalpath.moveTo((float) d1, (float) ((double) f2 - getYOffset() / 2D)); generalpath.lineTo((float) d1, (float) ((double) (f2 + f3) - getYOffset() / 2D)); java.awt.geom.Arc2D.Double double4 = new java.awt.geom.Arc2D.Double(d1, (double) (f2 + f3) - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 180D, 180D, 0); generalpath.append(double4, true); generalpath.lineTo((float) (d1 + categoryitemrendererstate.getBarWidth()), (float) ((double) f2 - getYOffset() / 2D)); double4 = new java.awt.geom.Arc2D.Double(d1, (double) f2 - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset(), 0.0D, -180D, 0); generalpath.append(double4, true); generalpath.closePath(); double2 = new java.awt.geom.Ellipse2D.Double(d1, (double) f2 - getYOffset(), categoryitemrendererstate.getBarWidth(), getYOffset()); } Object obj = getItemPaint(i, j); if (getGradientPaintTransformer() != null && (obj instanceof GradientPaint)) { GradientPaint gradientpaint = (GradientPaint) obj; obj = getGradientPaintTransformer().transform(gradientpaint, generalpath); } graphics2d.setPaint(((java.awt.Paint) (obj))); graphics2d.fill(generalpath); if (obj instanceof GradientPaint) { graphics2d.setPaint(((GradientPaint) obj).getColor2()); } if (double2 != null) { graphics2d.fill(double2); } if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) { graphics2d.setStroke(getItemOutlineStroke(i, j)); graphics2d.setPaint(getItemOutlinePaint(i, j)); graphics2d.draw(generalpath); if (double2 != null) graphics2d.draw(double2); } CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j); if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j)) drawItemLabel(graphics2d, categorydataset, i, j, categoryplot, categoryitemlabelgenerator, generalpath.getBounds2D(), d < 0.0D); if (categoryitemrendererstate.getInfo() != null) { EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection(); if (entitycollection != null) { String s = null; CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j); if (categorytooltipgenerator != null) s = categorytooltipgenerator.generateToolTip(categorydataset, i, j); String s1 = null; if (getItemURLGenerator(i, j) != null) s1 = getItemURLGenerator(i, j).generateURL(categorydataset, i, j); CategoryItemEntity categoryitementity = new CategoryItemEntity(generalpath.getBounds2D(), s, s1, categorydataset, categorydataset.getRowKey(i), categorydataset.getColumnKey(j)); entitycollection.add(categoryitementity); } } }