List of usage examples for java.awt Graphics2D fill
public abstract void fill(Shape s);
From source file:extern.NpairsBoxAndWhiskerRenderer.java
/** * Draws the visual representation of a single data item when the plot has * a horizontal orientation.//from w ww .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 (must be an instance of * {@link BoxAndWhiskerCategoryDataset}). * @param row the row index (zero-based). * @param column the column index (zero-based). */ public void drawHorizontalItem(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 = Math.abs(categoryEnd - categoryStart); double yy = categoryStart; int seriesCount = getRowCount(); int categoryCount = getColumnCount(); double widthWeWannaUse = Math.min(state.getBarWidth(), dataArea.getWidth() / 10); if (seriesCount > 1) { double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); // double usedWidth = (state.getBarWidth() * seriesCount) // + (seriesGap * (seriesCount - 1)); double usedWidth = (widthWeWannaUse * 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; // yy = yy + offset + (row * (state.getBarWidth() + seriesGap)); yy = yy + offset + (row * (widthWeWannaUse + seriesGap)); } else { // offset the start of the box if the box width is smaller than // the category width // double offset = (categoryWidth - state.getBarWidth()) / 2; double offset = (categoryWidth - widthWeWannaUse) / 2; yy = yy + offset; } g2.setPaint(getItemPaint(row, column)); Stroke s = getItemStroke(row, column); g2.setStroke(s); RectangleEdge location = plot.getRangeAxisEdge(); Number xQ1 = bawDataset.getQ1Value(row, column); Number xQ3 = bawDataset.getQ3Value(row, column); Number xMax = bawDataset.getMaxRegularValue(row, column); Number xMin = bawDataset.getMinRegularValue(row, column); Shape box = null; if (xQ1 != null && xQ3 != null && xMax != null && xMin != null) { double xxQ1 = rangeAxis.valueToJava2D(xQ1.doubleValue(), dataArea, location); double xxQ3 = rangeAxis.valueToJava2D(xQ3.doubleValue(), dataArea, location); double xxMax = rangeAxis.valueToJava2D(xMax.doubleValue(), dataArea, location); double xxMin = rangeAxis.valueToJava2D(xMin.doubleValue(), dataArea, location); // double yymid = yy + state.getBarWidth() / 2.0; double yymid = yy + widthWeWannaUse / 2.0; // draw the upper shadow... g2.draw(new Line2D.Double(xxMax, yymid, xxQ3, yymid)); // g2.draw(new Line2D.Double(xxMax, yy, xxMax, // yy + state.getBarWidth())); g2.draw(new Line2D.Double(xxMax, yy, xxMax, yy + widthWeWannaUse)); // draw the lower shadow... g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid)); // g2.draw(new Line2D.Double(xxMin, yy, xxMin, // yy + state.getBarWidth())); g2.draw(new Line2D.Double(xxMin, yy, xxMin, yy + widthWeWannaUse)); // draw the box... // box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, // Math.abs(xxQ1 - xxQ3), state.getBarWidth()); box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, Math.abs(xxQ1 - xxQ3), widthWeWannaUse); if (this.fillBox) { g2.fill(box); } g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(box); } g2.setPaint(this.artifactPaint); double aRadius = 0; // average radius // draw mean - SPECIAL AIMS REQUIREMENT... Number xMean = bawDataset.getMeanValue(row, column); if (xMean != null) { double xxMean = rangeAxis.valueToJava2D(xMean.doubleValue(), dataArea, location); // aRadius = state.getBarWidth() / 4; aRadius = widthWeWannaUse / 4; // here we check that the average marker will in fact be visible // before drawing it... if ((xxMean > (dataArea.getMinX() - aRadius)) && (xxMean < (dataArea.getMaxX() + aRadius))) { Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxMean - aRadius, yy + aRadius, aRadius * 2, aRadius * 2); g2.fill(avgEllipse); g2.draw(avgEllipse); } } // draw median... Number xMedian = bawDataset.getMedianValue(row, column); if (xMedian != null) { double xxMedian = rangeAxis.valueToJava2D(xMedian.doubleValue(), dataArea, location); // g2.draw(new Line2D.Double(xxMedian, yy, xxMedian, // yy + state.getBarWidth())); g2.draw(new Line2D.Double(xxMedian, yy, xxMedian, yy + widthWeWannaUse)); } // collect entity and tool tip information... if (state.getInfo() != null && box != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, box); } } }
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./*w ww . ja v a 2 s. com*/ * * @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.//from w ww . j a v a 2s.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:edu.dlnu.liuwenpeng.render.XYBarRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device.// w w w . ja va 2 s. c o m * @param state the renderer state. * @param dataArea the area within which the plot is being drawn. * @param info collects information about the drawing. * @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 series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ 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) { if (!getItemVisible(series, item)) { return; } IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double value0; double value1; if (this.useYInterval) { value0 = intervalDataset.getStartYValue(series, item); value1 = intervalDataset.getEndYValue(series, item); } else { value0 = this.base; value1 = intervalDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } if (value0 <= value1) { if (!rangeAxis.getRange().intersects(value0, value1)) { return; } } else { if (!rangeAxis.getRange().intersects(value1, value0)) { return; } } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); double bottom = Math.min(translatedValue0, translatedValue1); double top = Math.max(translatedValue0, translatedValue1); double startX = intervalDataset.getStartXValue(series, item); if (Double.isNaN(startX)) { return; } double endX = intervalDataset.getEndXValue(series, item); if (Double.isNaN(endX)) { return; } if (startX <= endX) { if (!domainAxis.getRange().intersects(startX, endX)) { return; } } else { if (!domainAxis.getRange().intersects(endX, startX)) { return; } } RectangleEdge location = plot.getDomainAxisEdge(); double translatedStartX1 = domainAxis.valueToJava2D(startX, dataArea, location); double translatedEndX1 = domainAxis.valueToJava2D(endX, dataArea, location); double translatedWidth = Math.max(1, Math.abs(translatedEndX1 - translatedStartX1)); double translatedStartX = translatedStartX1 - translatedWidth / 2; double translatedEndX = translatedEndX1 - translatedWidth / 2; double left = Math.min(translatedStartX, translatedEndX); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; left = left + cut / 2; } Rectangle2D bar = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { // clip left and right bounds to data area bottom = Math.max(bottom, dataArea.getMinX()); top = Math.min(top, dataArea.getMaxX()); bar = new Rectangle2D.Double(bottom, left, top - bottom, translatedWidth); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area bottom = Math.max(bottom, dataArea.getMinY()); top = Math.min(top, dataArea.getMaxY()); bar = new Rectangle2D.Double(left, bottom, translatedWidth, top - bottom); } Paint itemPaint = getItemPaint(series, item); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); g2.fill(bar); if (isDrawBarOutline() && Math.abs(translatedEndX - translatedStartX) > 3) { Stroke stroke = getItemOutlineStroke(series, item); Paint paint = getItemOutlinePaint(series, item); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } if (isItemLabelVisible(series, item)) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0); } // update the crosshair point double x1 = (startX + endX) / 2.0; double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, location); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation()); EntityCollection entities = state.getEntityCollection(); if (entities != null) { addEntity(entities, bar, dataset, series, item, 0.0, 0.0); } }
From source file:edu.dlnu.liuwenpeng.render.NewXYBarRenderer.java
/** * Draws the visual representation of a single data item. * //from ww 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 info collects information about the drawing. * @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 series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ 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) { if (!getItemVisible(series, item)) { return; } IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double value0; double value1; if (this.useYInterval) { value0 = intervalDataset.getStartYValue(series, item); value1 = intervalDataset.getEndYValue(series, item); } else { value0 = this.base; value1 = intervalDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } if (value0 <= value1) { if (!rangeAxis.getRange().intersects(value0, value1)) { return; } } else { if (!rangeAxis.getRange().intersects(value1, value0)) { return; } } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); double bottom = Math.min(translatedValue0, translatedValue1); double top = Math.max(translatedValue0, translatedValue1); double startX = intervalDataset.getStartXValue(series, item); if (Double.isNaN(startX)) { return; } double endX = intervalDataset.getEndXValue(series, item); if (Double.isNaN(endX)) { return; } if (startX <= endX) { if (!domainAxis.getRange().intersects(startX, endX)) { return; } } else { if (!domainAxis.getRange().intersects(endX, startX)) { return; } } RectangleEdge location = plot.getDomainAxisEdge(); double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location); double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location); double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX)); double left = Math.min(translatedStartX, translatedEndX); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; left = left + cut / 2; } Rectangle2D bar = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { // clip left and right bounds to data area bottom = Math.max(bottom, dataArea.getMinX()); top = Math.min(top, dataArea.getMaxX()); bar = new Rectangle2D.Double(bottom, left, top - bottom, translatedWidth); } else if (orientation == PlotOrientation.VERTICAL) { // clip top and bottom bounds to data area bottom = Math.max(bottom, dataArea.getMinY()); top = Math.min(top, dataArea.getMaxY()); bar = new Rectangle2D.Double(left, bottom, translatedWidth, top - bottom); } /* Paint itemPaint = getItemPaint(series, item); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); */ if (dataset.getYValue(series, item) >= 0) { g2.setPaint(Color.red); } else { g2.setPaint(Color.green); } g2.fill(bar); if (isDrawBarOutline() && Math.abs(translatedEndX - translatedStartX) > 3) { Stroke stroke = getItemOutlineStroke(series, item); Paint paint = getItemOutlinePaint(series, item); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } if (isItemLabelVisible(series, item)) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); drawItemLabel(g2, dataset, series, item, plot, generator, bar, value1 < 0.0); } // update the crosshair point double x1 = (startX + endX) / 2.0; double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, location); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation()); EntityCollection entities = state.getEntityCollection(); if (entities != null) { addEntity(entities, bar, dataset, series, item, 0.0, 0.0); } }
From source file:de.laures.cewolf.jfree.ThermometerPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device./*from w ww . ja v a2s.c om*/ * @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) { RoundRectangle2D outerStem = new RoundRectangle2D.Double(); RoundRectangle2D innerStem = new RoundRectangle2D.Double(); RoundRectangle2D mercuryStem = new RoundRectangle2D.Double(); Ellipse2D outerBulb = new Ellipse2D.Double(); Ellipse2D innerBulb = new Ellipse2D.Double(); String temp = null; FontMetrics metrics = null; if (info != null) { info.setPlotArea(area); } // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); // adjust for padding... Rectangle2D interior = (Rectangle2D) area.clone(); this.padding.trim(interior); int midX = (int) (interior.getX() + (interior.getWidth() / 2)); int midY = (int) (interior.getY() + (interior.getHeight() / 2)); int stemTop = (int) (interior.getMinY() + getBulbRadius()); int stemBottom = (int) (interior.getMaxY() - getBulbDiameter()); Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(), stemBottom - stemTop); outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter()); outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter()); Area outerThermometer = new Area(outerBulb); Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2); innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(), getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop, getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); innerThermometer.add(tempArea); if ((this.dataset != null) && (this.dataset.getValue() != null)) { double current = this.dataset.getValue().doubleValue(); double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); int i = getColumnDiameter() - getGap() * 2; // already calculated int j = getColumnRadius() - getGap(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); if (k < (getGap() + interior.getMinY())) { k = (int) (getGap() + interior.getMinY()); l = getBulbRadius(); } Area mercury = new Area(innerBulb); if (k < (stemBottom + getBulbRadius())) { mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l); tempArea = new Area(mercuryStem); mercury.add(tempArea); } g2.setPaint(getCurrentPaint()); g2.fill(mercury); // draw range indicators... if (this.subrangeIndicatorsVisible) { g2.setStroke(this.subrangeIndicatorStroke); Range range = this.rangeAxis.getRange(); // draw start of normal range double value = this.subrangeInfo[NORMAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[NORMAL]); g2.draw(line); } // draw start of warning range value = this.subrangeInfo[WARNING][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[WARNING]); g2.draw(line); } // draw start of critical range value = this.subrangeInfo[CRITICAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[CRITICAL]); g2.draw(line); } } // draw the axis... if ((this.rangeAxis != null) && (this.axisLocation != NONE)) { int drawWidth = AXIS_GAP; Rectangle2D drawArea; double cursor = 0; switch (this.axisLocation) { case RIGHT: cursor = midX + getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null); break; case LEFT: default: //cursor = midX - COLUMN_RADIUS - AXIS_GAP; cursor = midX - getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null); break; } } // draw text value on screen g2.setFont(this.valueFont); g2.setPaint(this.valuePaint); metrics = g2.getFontMetrics(); switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap()); break; default: } /***/ } g2.setPaint(this.thermometerPaint); g2.setFont(this.valueFont); // draw units indicator metrics = g2.getFontMetrics(); int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20)); } // draw thermometer outline g2.setStroke(this.thermometerStroke); g2.draw(outerThermometer); g2.draw(innerThermometer); drawOutline(g2, area); }
From source file:spinworld.gui.RadarPlot.java
/** * Draws a radar plot polygon./*from ww w . j ava 2 s. com*/ * * @param g2 the graphics device. * @param plotArea the area we are plotting in (already adjusted). * @param centre the centre point of the radar axes * @param info chart rendering info. * @param series the series within the dataset we are plotting * @param catCount the number of categories per radar plot * @param headH the data point height * @param headW the data point width */ protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info, int series, int catCount, double headH, double headW) { Polygon polygon = new Polygon(); EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // plot the data... for (int cat = 0; cat < catCount; cat++) { Number dataValue = getPlotValue(series, cat); if (dataValue != null) { double value = dataValue.doubleValue(); // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount); // The following angle calc will ensure there isn't a top // vertical axis - this may be useful if you don't want any // given criteria to 'appear' move important than the // others.. // + (getDirection().getFactor() // * (cat + 0.5) * 360 / catCount); // find the point at the appropriate distance end point // along the axis/angle identified above and add it to the // polygon double _maxValue = getMaxValue(cat).doubleValue(); double _origin = getOrigin(cat).doubleValue(); double lowerBound = Math.min(_origin, _maxValue); double upperBound = Math.max(_origin, _maxValue); boolean lesser = value < lowerBound; boolean greater = value > upperBound; if ((lesser || greater) && !drawOutOfRangePoints) { continue; } if (lesser) { value = lowerBound; } if (greater) { value = upperBound; } double length = _maxValue == _origin ? 0 : (value - lowerBound) / (upperBound - lowerBound); if (_maxValue < _origin) { // inversed length = 1 - length; } Point2D point = getWebPoint(plotArea, angle, length); polygon.addPoint((int) point.getX(), (int) point.getY()); Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); double px = point.getX(); double py = point.getY(); g2.setPaint(paint); if (lesser || greater) { // user crosshair for out-of-range data points distinguish g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); double delta = 3; g2.draw(new Line2D.Double(px - delta, py, px + delta, py)); g2.draw(new Line2D.Double(px, py - delta, px, py + delta)); } else { // put an elipse at the point being plotted.. Ellipse2D head = new Ellipse2D.Double(px - headW / 2, py - headH / 2, headW, headH); g2.fill(head); g2.setStroke(getHeadOutlineStroke(series)); g2.setPaint(outlinePaint); g2.draw(head); } if (entities != null) { int row = 0; int col = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { row = series; col = cat; } else { row = cat; col = series; } String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, row, col); } Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH), (int) (headW * 2), (int) (headH * 2)); CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset, this.dataset.getRowKey(row), this.dataset.getColumnKey(col)); entities.add(entity); } } } // Plot the polygon Paint paint = getSeriesPaint(series); g2.setPaint(paint); g2.setStroke(getSeriesOutlineStroke(series)); g2.draw(polygon); // Lastly, fill the web polygon if this is required if (this.webFilled) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2.fill(polygon); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); } }
From source file:org.gumtree.vis.awt.JChartPanel.java
private void drawTextInputBox(Graphics2D g2) { if (textInputFlag && textInputPoint != null) { // g2.drawChars("Input Text Here".toCharArray(), 1, 60, (int) textInputPoint.getX(), (int) textInputPoint.getY()); Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); String inputText = textInputContent == null ? "" : textInputContent; FontMetrics fm = g2.getFontMetrics(); // int sWidth; // if (textInputCursorIndex == 0 || inputText.length() == 0) { // sWidth = 0; // } else if (textInputCursorIndex < inputText.length()){ // sWidth = fm.stringWidth(inputText.substring(0, textInputCursorIndex)); // } else { // sWidth = fm.stringWidth(inputText); // } String[] lines = inputText.split("\n", 100); int cursorY = 0; int cursorX = 0; int charCount = 0; int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) textInputPoint.getX() + 3, (int) textInputPoint.getY() - 3 + i * 15); // charCount += lines[i].length() + 1; if (textInputCursorIndex > charCount && textInputCursorIndex < charCount + lines[i].length() + 1) { cursorY = i;// w w w . j a va2s .c om cursorX = fm.stringWidth(lines[i].substring(0, textInputCursorIndex - charCount)); } else if (textInputCursorIndex == charCount + lines[i].length() + 1) { cursorY = i + 1; cursorX = 0; } charCount += lines[i].length() + 1; int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } maxHeight = 15 * lines.length; // g2.drawString(inputText, (int) textInputPoint.getX() + 3, (int) textInputPoint.getY() - 3); g2.setColor(Color.MAGENTA); // g2.drawString("|", (float) textInputPoint.getX() + 2 + sWidth, (float) textInputPoint.getY() - 3); g2.drawLine((int) textInputPoint.getX() + 3 + cursorX, (int) textInputPoint.getY() + (cursorY - 1) * 15, (int) textInputPoint.getX() + 3 + cursorX, (int) textInputPoint.getY() + cursorY * 15); g2.setColor(Color.BLACK); g2.setColor(oldColor); // int boxWidth = fm.stringWidth(inputText) + 10; if (maxWidth < 100) { maxWidth = 100; } Rectangle2D inputBox = new Rectangle2D.Double(textInputPoint.getX(), textInputPoint.getY() - 15, maxWidth + 8, maxHeight); // ChartMaskingUtilities.drawMaskBoarder(g2, inputBox); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(inputBox); g2.setColor(Color.ORANGE); g2.drawRect((int) textInputPoint.getX(), (int) textInputPoint.getY() - 15, maxWidth + 8, maxHeight); } if (textContentMap.size() > 0) { Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); Rectangle2D imageArea = getScreenDataArea(); for (Entry<Rectangle2D, String> entry : textContentMap.entrySet()) { Rectangle2D rect = entry.getKey(); Point2D screenPoint = ChartMaskingUtilities .translateChartPoint(new Point2D.Double(rect.getX(), rect.getY()), imageArea, getChart()); String text = entry.getValue(); if (text == null) { continue; } String[] lines = text.split("\n"); g2.setColor(Color.BLACK); for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3 + i * 15); } if (rect == selectedTextWrapper) { FontMetrics fm = g2.getFontMetrics(); int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < lines.length; i++) { int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } maxHeight = 15 * lines.length; if (maxWidth < 100) { maxWidth = 100; } Rectangle2D inputBox = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, maxWidth + 8, maxHeight); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(inputBox); g2.setColor(Color.ORANGE); g2.drawRect((int) screenPoint.getX(), (int) screenPoint.getY() - 15, maxWidth + 8, maxHeight); } // g2.drawString(text == null ? "" : text, (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3); } g2.setColor(oldColor); } }
From source file:org.forester.archaeopteryx.TreePanel.java
final void paintPhylogeny(final Graphics2D g, final boolean to_pdf, final boolean to_graphics_file, final int graphics_file_width, final int graphics_file_height, final int graphics_file_x, final int graphics_file_y) { /* GUILHEM_BEG */ _query_sequence = _control_panel.getSelectedQuerySequence(); /* GUILHEM_END */ // Color the background if (!to_pdf) { final Rectangle r = getVisibleRect(); if (!getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite()) { g.setColor(getTreeColorSet().getBackgroundColor()); if (!to_graphics_file) { g.fill(r); } else { if (getOptions().isPrintBlackAndWhite()) { g.setColor(Color.WHITE); }/* www .j a v a 2s . c o m*/ g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height); } } else { if (!to_graphics_file) { g.setPaint(new GradientPaint(r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y + r.height, getTreeColorSet().getBackgroundColorGradientBottom())); g.fill(r); } else { g.setPaint(new GradientPaint(graphics_file_x, graphics_file_y, getTreeColorSet().getBackgroundColor(), graphics_file_x, graphics_file_y + graphics_file_height, getTreeColorSet().getBackgroundColorGradientBottom())); g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height); } } g.setStroke(new BasicStroke(1)); } else { g.setStroke(new BasicStroke(getOptions().getPrintLineWidth())); } if ((getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED) && (getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) { _external_node_index = 0; // Position starting X of tree if (!_phylogeny.isRooted()) { _phylogeny.getRoot().setXcoord(TreePanel.MOVE); } else if ((_phylogeny.getRoot().getDistanceToParent() > 0.0) && getControlPanel().isDrawPhylogram()) { _phylogeny.getRoot().setXcoord((float) (TreePanel.MOVE + (_phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor()))); } else { _phylogeny.getRoot().setXcoord(TreePanel.MOVE + getXdistance()); } // Position starting Y of tree _phylogeny.getRoot().setYcoord( (getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes()) + (TreePanel.MOVE / 2.0f)); final int dynamic_hiding_factor = (int) (getTreeFontSet()._fm_large.getHeight() / (1.5 * getYdistance())); if (getControlPanel().isDynamicallyHideData()) { if (dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } final PhylogenyNodeIterator it; for (it = _phylogeny.iteratorPreorder(); it.hasNext();) { paintNodeRectangular(g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData() && (dynamic_hiding_factor > 1), dynamic_hiding_factor, to_graphics_file); } if (getOptions().isShowScale()) { if (!(to_graphics_file || to_pdf)) { paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf, to_graphics_file); } else { paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file); } } if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { paintPhylogenyLite(g); } } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) { if (getControlPanel().getDynamicallyHideData() != null) { getControlPanel().setDynamicHidingIsOn(false); } final double angle = getStartingAngle(); final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL; _dynamic_hiding_factor = 0; if (getControlPanel().isDynamicallyHideData()) { _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * 10)); } if (getControlPanel().getDynamicallyHideData() != null) { if (_dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } paintUnrooted(_phylogeny.getRoot(), angle, (float) (angle + 2 * Math.PI), radial_labels, g, to_pdf, to_graphics_file); if (getOptions().isShowScale()) { if (!(to_graphics_file || to_pdf)) { paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf, to_graphics_file); } else { paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file); } } if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { g.setColor(getTreeColorSet().getOvColor()); paintUnrootedLite(_phylogeny.getRoot(), angle, angle + 2 * Math.PI, g, (getUrtFactorOv() / (getVisibleRect().width / getOvMaxWidth()))); paintOvRectangle(g); } } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR) { final int radius = (int) ((Math.min(getPreferredSize().getWidth(), getPreferredSize().getHeight()) / 2) - (MOVE + getLongestExtNodeInfo())); final int d = radius + MOVE + getLongestExtNodeInfo(); _dynamic_hiding_factor = 0; if (getControlPanel().isDynamicallyHideData() && (radius > 0)) { _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * radius)); } if (getControlPanel().getDynamicallyHideData() != null) { if (_dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } paintCircular(_phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file); if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { final int radius_ov = (int) (getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2 : getOvMaxWidth() / 2); double x_scale = 1.0; double y_scale = 1.0; int x_pos = getVisibleRect().x + getOvXPosition(); int y_pos = getVisibleRect().y + getOvYPosition(); if (getWidth() > getHeight()) { x_scale = (double) getHeight() / getWidth(); x_pos = ForesterUtil.roundToInt(x_pos / x_scale); } else { y_scale = (double) getWidth() / getHeight(); y_pos = ForesterUtil.roundToInt(y_pos / y_scale); } _at = g.getTransform(); g.scale(x_scale, y_scale); paintCircularLite(_phylogeny, getStartingAngle(), x_pos + radius_ov, y_pos + radius_ov, (int) (radius_ov - (getLongestExtNodeInfo() / (getVisibleRect().width / getOvRectangle().getWidth()))), g); g.setTransform(_at); paintOvRectangle(g); } } }
From source file:net.sf.mzmine.modules.visualization.twod.PointTwoDXYPlot.java
public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { // if this is not TwoDDataSet if (index != 0) return super.render(g2, dataArea, index, info, crosshairState); // prepare some necessary constants final int x = (int) dataArea.getX(); final int y = (int) dataArea.getY(); final int width = (int) dataArea.getWidth(); final int height = (int) dataArea.getHeight(); final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound(); final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound(); final double imageRTStep = (imageRTMax - imageRTMin) / width; final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound(); final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound(); final double imageMZStep = (imageMZMax - imageMZMin) / height; // This if statement below keeps the min max values at the original values when the user // zooms in. We need some variables that scall as the box size so that the points we show // have better resolution the more someone zooms in. double dynamicImageRTMin = imageRTMin; double dynamicImageRTMax = imageRTMax; double dynamicImageMZMin = imageMZMin; double dynamicImageMZMax = imageMZMax; double dynamicImageRTStep = imageRTStep; double dynamicImageMZStep = imageMZStep; if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.lowerEndpoint()) && (imageRTMax == totalRTRange.upperEndpoint()) && (imageMZMin == totalMZRange.lowerEndpoint()) && (imageMZMax == totalMZRange.upperEndpoint()) && (zoomOutBitmap.getWidth() == width) && (zoomOutBitmap.getHeight() == height)) { g2.drawImage(zoomOutBitmap, x, y, null); return true; }/*from ww w . j a v a 2 s .c om*/ // Save current time Date renderStartTime = new Date(); // prepare a bitmap of required size //BufferedImage image = new BufferedImage(width, height, //BufferedImage.TYPE_INT_ARGB); //ArrayList<DataPoint> listOfDataPoints = new ArrayList<DataPoint>(); //ArrayList<DataPoint> listOfRTValues = new ArrayList<DataPoint>(); ArrayList<DataPoint> listOfDataPoints; ArrayList<Double> listOfRTValues; // These two function must be run in this order Range<Double> rtRangeIn = Range.closed(getDomainAxis().getRange().getLowerBound(), getDomainAxis().getRange().getUpperBound()); Range<Double> mzRangeIn = Range.closed(getRangeAxis().getRange().getLowerBound(), getRangeAxis().getRange().getUpperBound()); listOfDataPoints = dataset.getCentroidedDataPointsInRTMZRange(rtRangeIn, mzRangeIn); listOfRTValues = dataset.getrtValuesInUserRange(); // points to be plotted List plotPoints = new ArrayList(); int count = 0; // Store the current mz,rt,int values so that they can be outputed to a file if we want //currentlyPlottedMZ = new ArrayList(); //for (Iterator dpIt = listOfDataPoints.iterator(); dpIt.hasNext();) { // make a list to keep track of the intesities of each for (DataPoint curDataPoint : listOfDataPoints) { //DataPoint curDataPoint = dpIt.next(); double currentRT = listOfRTValues.get(count).doubleValue(); double currentMZ = curDataPoint.getMZ(); plotPoints.add(new Point2D.Double(currentRT, currentMZ)); count += 1; //currentlyPlottedMZ.add() } // draw image points //for (int i = 0; i < width; i++) // for (int j = 0; j < height; j++) { // Color pointColor = paletteType.getColor(values[i][j]); // //image.setRGB(i, height - j - 1, pointColor.getRGB()); // points.add(new Point2D.Float(i,j)); // } count = 0; for (Iterator i = plotPoints.iterator(); i.hasNext();) { Point2D.Double pt = (Point2D.Double) i.next(); // using the ''dynamic'' min and max will make the resolution imporve as someone zooms // in //float xPlace = (pt.x-(float)dynamicImageRTMin)/((float)dynamicImageRTStep) + x; //float yPlace = (pt.y-(float)dynamicImageMZMin)/((float)dynamicImageMZStep) + y; double xPlace = (pt.x - dynamicImageRTMin) / (dynamicImageRTStep) + (double) x; double yPlace = (double) height - (pt.y - dynamicImageMZMin) / (dynamicImageMZStep) + (double) y; //get the current intensity // use the R, G B for the intensity double curIntensity = listOfDataPoints.get(count).getIntensity(); curIntensity = curIntensity / dataset.curMaxIntensity; //g2.setColor(Color.BLACK); Color pointColor = paletteType.getColor(curIntensity); g2.setColor(pointColor); Ellipse2D dot = new Ellipse2D.Double(xPlace - 1, yPlace - 1, 2, 2); g2.fill(dot); count += 1; } //float xPlace = ((float)42.0-(float)dynamicImageRTMin)/((float)dynamicImageRTStep)+x; //float yPlace = (float)height - ((float)201.02-(float)dynamicImageMZMin)/((float)dynamicImageMZStep)+y; //Ellipse2D dot = new Ellipse2D.Float(xPlace - 1, yPlace - 1, 2, 2); //g2.fill(dot); //g2.dispose(); // if we are zoomed out, save the values if ((imageRTMin == totalRTRange.lowerEndpoint()) && (imageRTMax == totalRTRange.upperEndpoint()) && (imageMZMin == totalMZRange.lowerEndpoint()) && (imageMZMax == totalMZRange.upperEndpoint())) { //zoomOutBitmap = image; } // Paint image //g2.drawImage(image, x, y, null); //g.setColor(Color.BLACK) Date renderFinishTime = new Date(); logger.finest("Finished rendering 2D visualizer, " + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms"); return true; }