List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:ro.nextreports.engine.util.chart.CylinderRenderer.java
/** * Draws a cylinder to represent one data item. * //from www . jav a2s . c o m * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area for plotting the data. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); float barL0 = Math.min(transL0, transL1); float barLength = Math.abs(transL1 - transL0); // draw the bar... GeneralPath bar = new GeneralPath(); if (orientation == PlotOrientation.HORIZONTAL) { bar.moveTo(barL0, (float) barW0); bar.lineTo(barL0, (float) (barW0 + state.getBarWidth())); bar.lineTo(barL0 + barLength, (float) (barW0 + state.getBarWidth())); bar.lineTo(barL0 + barLength, (float) barW0); bar.closePath(); } else { bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2)); bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2)); Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(), getYOffset(), 180, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2)); arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); } Paint itemPaint = getItemPaint(row, column); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); g2.fill(bar); Shape bar3dTop = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset()); if (itemPaint instanceof GradientPaint) { g2.setPaint(((GradientPaint) itemPaint).getColor2()); } g2.fill(bar3dTop); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar.getBounds2D(), (value < 0.0)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }
From source file: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 va 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 = 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 www. ja 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 = 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.XYLineAndShapeRenderer.java
/** * Draws the item shapes and adds chart entities (second pass). This method * draws the shapes which mark the item positions. If <code>entities</code> * is not <code>null</code> it will be populated with entity information * for points that fall within the data area. * /*from w ww . j a v a 2s .c o m*/ * @param g2 the graphics device. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param dataArea the area within which the data is being drawn. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState the crosshair state. * @param entities the entity collection. */ protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) { Shape entityArea = null; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } entityArea = shape; if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } //g2.fill(shape); } if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); // g2.draw(shape); } } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item, but only if it falls within the data // area... if (entities != null && isPointInRect(dataArea, xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }
From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java
protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex, PieDataset data) {/*from w w w.j a va2 s. c o m*/ // adjust the plot area by the interior spacing value double gapHorizontal = plotArea.getWidth() * this.interiorGap; double gapVertical = plotArea.getHeight() * this.interiorGap; double radarX = plotArea.getX() + gapHorizontal / 2; double radarY = plotArea.getY() + gapVertical / 2; double radarW = plotArea.getWidth() - gapHorizontal; double radarH = plotArea.getHeight() - gapVertical; // make the radar area a square if the radar chart is to be circular... // NOTE that non-circular radar charts are not currently supported. if (true) { //circular) { double min = Math.min(radarW, radarH) / 2; radarX = (radarX + radarX + radarW) / 2 - min; radarY = (radarY + radarY + radarH) / 2 - min; radarW = 2 * min; radarH = 2 * min; } double radius = radarW / 2; double centerX = radarX + radarW / 2; double centerY = radarY + radarH / 2; Rectangle2D radarArea = new Rectangle2D.Double(radarX, radarY, radarW, radarH); // plot the data (unless the dataset is null)... if ((data != null) && (data.getKeys().size() > 0)) { // get a list of categories... List keys = data.getKeys(); int numAxes = keys.size(); // draw each of the axes on the radar chart, and register // the shape of the radar line. double multiplier = 1.0; GeneralPath lineShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1); GeneralPath gridShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1); int axisNumber = -1; Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable currentKey = (Comparable) iterator.next(); axisNumber++; Number dataValue = data.getValue(currentKey); double value = (dataValue != null ? dataValue.doubleValue() : 0); if (value > 1 || Double.isNaN(value) || Double.isInfinite(value)) value = 1.0; if (value < 0) value = 0.0; multiplier *= value; double angle = 2 * Math.PI * axisNumber / numAxes; double deltaX = Math.sin(angle) * radius; double deltaY = -Math.cos(angle) * radius; // draw the spoke g2.setPaint(axisPaint); g2.setStroke(axisStroke); Line2D line = new Line2D.Double(centerX, centerY, centerX + deltaX, centerY + deltaY); g2.draw(line); // register the grid line and the shape line if (axisNumber == 0) { gridShape.moveTo((float) deltaX, (float) deltaY); lineShape.moveTo((float) (deltaX * value), (float) (deltaY * value)); } else { gridShape.lineTo((float) deltaX, (float) deltaY); lineShape.lineTo((float) (deltaX * value), (float) (deltaY * value)); } if (showAxisLabels) { // draw the label double labelX = centerX + deltaX * (1 + axisLabelGap); double labelY = centerY + deltaY * (1 + axisLabelGap); String label = currentKey.toString(); drawLabel(g2, radarArea, label, axisNumber, labelX, labelY); } } gridShape.closePath(); lineShape.closePath(); // draw five gray concentric gridlines g2.translate(centerX, centerY); g2.setPaint(gridLinePaint); g2.setStroke(gridLineStroke); for (int i = 5; i > 0; i--) { Shape scaledGrid = gridShape .createTransformedShape(AffineTransform.getScaleInstance(i / 5.0, i / 5.0)); g2.draw(scaledGrid); } // get the color for the plot shape. Paint dataPaint = plotLinePaint; if (dataPaint == ADAPTIVE_COLORING) { //multiplier = Math.exp(Math.log(multiplier) * 2 / numAxes); dataPaint = getMultiplierColor((float) multiplier); } // compute a slightly transparent version of the plot color for // the fill. Paint dataFill = null; if (dataPaint instanceof Color && getForegroundAlpha() != 1.0) dataFill = new Color(((Color) dataPaint).getRed() / 255f, ((Color) dataPaint).getGreen() / 255f, ((Color) dataPaint).getBlue() / 255f, getForegroundAlpha()); else dataFill = dataPaint; // draw the plot shape. First fill with a parially // transparent color, then stroke with the opaque color. g2.setPaint(dataFill); g2.fill(lineShape); g2.setPaint(dataPaint); g2.setStroke(plotLineStroke); g2.draw(lineShape); // cleanup the graphics context. g2.translate(-centerX, -centerY); } }
From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java
private BufferedImage createFloorImage(HmFolder floor, double scale, int floorWidth, int floorHeight, Map<Long, Integer> channelMap, Map<Long, Integer> colorMap, int borderX, int borderY, double gridSize) throws Exception { BufferedImage image = new BufferedImage(floorWidth + borderX + 1, floorHeight + borderY + 1, BufferedImage.TYPE_INT_ARGB); if (floor == null) { return image; }/*from w w w.j a va 2 s . c om*/ double metricWidth = 0.0, metricHeight = 0.0, offsetX = 0.0, offsetY = 0.0; int imageWidth = 0; LengthUnit lengthUnit = LengthUnit.METERS; if (null != floor.getMetricWidth()) { metricWidth = floor.getMetricWidth().doubleValue(); } if (null != floor.getMetricHeight()) { metricHeight = floor.getMetricHeight().doubleValue(); } if (null != floor.getImageWidth()) { imageWidth = floor.getImageWidth().intValue(); } if (null != floor.getOffsetX()) { offsetX = floor.getOffsetX().doubleValue(); } if (null != floor.getOffsetY()) { offsetY = floor.getOffsetY().doubleValue(); } if (null != floor.getLengthUnit()) { lengthUnit = floor.getLengthUnit(); } Graphics2D g2 = image.createGraphics(); g2.setStroke(new BasicStroke(1)); if (getDistanceMetric(metricWidth, lengthUnit) == 0) { g2.setColor(new Color(255, 255, 255)); g2.fillRect(borderX, 0, floorWidth + 1, borderY); g2.fillRect(0, 0, borderX, borderY + floorHeight + 1); g2.setColor(new Color(120, 120, 120)); g2.drawLine(0, borderY, floorWidth + borderX, borderY); g2.drawLine(borderX, 0, borderX, floorHeight + borderY); g2.setColor(new Color(255, 255, 204)); g2.fillRect(borderX + 2, borderY + 2, 162, 25); g2.setColor(new Color(0, 51, 102)); g2.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12)); g2.drawString("Please size this floor plan.", borderX + 8, borderY + 19); return image; } double screenWidth = scale * getDistanceMetric(metricWidth, lengthUnit); double imageScale = screenWidth / imageWidth; int originX = (int) (getDistanceMetric(offsetX, lengthUnit) * scale); int originY = (int) (getDistanceMetric(offsetY, lengthUnit) * scale); g2.setColor(new Color(255, 255, 255)); if (floor.getBackground() != null && floor.getBackground().length() > 0) { LinkedMultiValueMap<String, String> metadata = new LinkedMultiValueMap<>(); String url = getImageBaseUrl(floor.getOwnerId()) + floor.getBackground(); try { BufferedImage map = ImageIO.read(clientFileService.getFile(url, "AFS_TOKEN", metadata)); AffineTransform transform = new AffineTransform(); transform.scale(imageScale, imageScale); g2.drawImage(map, new AffineTransformOp(transform, null), getFloorX(0, borderX, originX), getFloorY(0, borderY, originY)); } catch (Exception e) { logger.error(String.format("image file not found with url: %s", url)); double screenHeight = scale * getDistanceMetric(metricHeight, lengthUnit); g2.fillRect(getFloorX(0, borderX, originX), getFloorY(0, borderY, originY), (int) screenWidth, (int) screenHeight); } } else { double screenHeight = scale * getDistanceMetric(metricHeight, lengthUnit); g2.fillRect(getFloorX(0, borderX, originX), getFloorY(0, borderY, originY), (int) screenWidth, (int) screenHeight); } g2.setColor(new Color(204, 204, 204)); // Right edge border g2.drawLine(borderX + floorWidth, borderY + 1, borderX + floorWidth, borderY + floorHeight); // Left edge border (right of tick marks) g2.drawLine(borderX + 1, borderY + floorHeight, borderX + floorWidth, borderY + floorHeight); g2.setColor(new Color(255, 255, 255)); g2.fillRect(borderX, 0, floorWidth + 1, borderY); g2.fillRect(0, 0, borderX, borderY + floorHeight + 1); g2.setColor(new Color(120, 120, 120)); g2.drawLine(0, borderY, floorWidth + borderX, borderY); g2.drawLine(borderX, 0, borderX, floorHeight + borderY); Font font = new Font(Font.SANS_SERIF, Font.BOLD, 12); double actualWidth = floorWidth / scale; double actualHeight = floorHeight / scale; String firstLabel; double unitScale = scale; if (LengthUnit.FEET == lengthUnit) { firstLabel = "0 feet"; actualWidth /= HmFolder.FEET_TO_METERS; actualHeight /= HmFolder.FEET_TO_METERS; unitScale *= HmFolder.FEET_TO_METERS; } else { firstLabel = "0 meters"; } g2.drawString(firstLabel, borderX + 4, 12); double gridX = gridSize; while (gridX < actualWidth) { int x = (int) (gridX * unitScale) + borderX; g2.drawLine(x, 0, x, borderY); boolean label = true; if (gridX + gridSize >= actualWidth) { // Last mark if (x + getNumberPixelWidth(gridX) + 2 > floorWidth) { label = false; } } if (label) { g2.drawString("" + (int) gridX, x + 4, 12); } gridX += gridSize; } double gridY = 0; while (gridY < actualHeight) { int y = (int) (gridY * unitScale) + borderY; g2.drawLine(0, y, borderX, y); double lx = gridY; int dx = 1; for (int bx = borderX; bx >= 16; bx -= 7) { if (lx < 10) { dx += 7; } else { lx /= 10; } } boolean label = true; if (gridY + gridSize >= actualHeight) { // Last mark if (y - borderY + 13 > floorHeight) { label = false; } } if (label) { g2.drawString("" + (int) gridY, dx, y + 13); } gridY += gridSize; } double mapToImage = getMapToMetric(metricWidth, imageWidth, lengthUnit) * scale; if (floor.getPerimeter().size() > 0) { g2.setStroke(new BasicStroke(2)); g2.setColor(new Color(2, 159, 245)); int[] xPoints = new int[floor.getPerimeter().size()]; int[] yPoints = new int[floor.getPerimeter().size()]; int nPoints = 0; int perimId = floor.getPerimeter().get(0).getId(); for (int i = 0; i < floor.getPerimeter().size(); i++) { HmVertex vertex = floor.getPerimeter().get(i); if (vertex.getId() != perimId) { g2.drawPolygon(xPoints, yPoints, nPoints); nPoints = 0; perimId = vertex.getId(); } xPoints[nPoints] = getFloorX((int) (vertex.getX() * mapToImage), borderX, originX); yPoints[nPoints++] = getFloorY((int) (vertex.getY() * mapToImage), borderY, originY); } g2.drawPolygon(xPoints, yPoints, nPoints); } g2.setStroke(new BasicStroke(1)); g2.setColor(new Color(0, 170, 0)); g2.setFont(font.deriveFont(Font.BOLD, 11)); List<HmDeviceLocationEx> devices = deviceLocationExRep.findAllHmDevices(floor.getId()); if (null != devices && !devices.isEmpty()) { for (HmDeviceLocationEx device : devices) { double x = device.getX() * mapToImage; double y = device.getY() * mapToImage; createNodeImage(device.getId(), channelMap, colorMap, getFloorX((int) x, borderX, originX), getFloorY((int) y, borderY, originY), g2); } } else { List<HmDevicePlanningEx> plannedDevices = devicePlanningExRep.findAllPlannedDevices(floor.getId()); for (HmDevicePlanningEx plannedDevice : plannedDevices) { double x = plannedDevice.getX() * mapToImage; double y = plannedDevice.getY() * mapToImage; createNodeImage(plannedDevice.getId(), channelMap, colorMap, getFloorX((int) x, borderX, originX), getFloorY((int) y, borderY, originY), g2); } } return image; }
From source file:org.n52.v3d.terrainserver.povraywts.WebTerrainServlet.java
private void addAnnotations(BufferedImage pImage, int pHeight, int pWidth, double pPitch, double pYaw, boolean pDrawNorthArrow) { if (mCopyrightTextContent.length() > 0) { Graphics2D g = pImage.createGraphics(); g.drawImage(pImage, 0, 0, null); g.setColor(new java.awt.Color(mCopyrightTextColor.getRed(), mCopyrightTextColor.getGreen(), mCopyrightTextColor.getBlue())); // 1. Copyright-Vermerk // Etwas unschn: Durch JPEG-Komprimierung wird Text (insb. bei kleiner Font-Gre) wird unscharf... // TODO: Abhilfe evtl. durch Hintergrund? Font font = new Font(mCopyrightTextFont, Font.BOLD /* Style als int, siehe ggf. API-Dok.*/, mCopyrightTextSize);/* w ww .ja v a 2 s . co m*/ g.setFont(font); // mehrzeilige Copyright-Texte erlauben: StringTokenizer str = new StringTokenizer(mCopyrightTextContent, "\n"); int spacePerRow = mCopyrightTextSize; int rows = str.countTokens(); int startPos = spacePerRow * rows; int currRow = 0; while (str.hasMoreTokens()) { int yPos = pHeight - (startPos - (currRow * spacePerRow)) + spacePerRow / 2; g.drawString(str.nextToken().trim(), 5, yPos); currRow++; } // 2. Nordpfeil if (pDrawNorthArrow) { // Zeichenparameter: double radius = 35.; double phi = 15.; // Symbolkonstruktion: int rx = (int) radius; int ry = (int) Math.round(radius * Math.sin(-pPitch * Math.PI / 180.)); int mx = pWidth - rx - 5; int my = pHeight - ry - 5; int dx = (int) (radius * Math.sin(pYaw * Math.PI / 180.)); int dy = (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos(pYaw * Math.PI / 180.)); int px = mx - dx, py = my - dy; // Pfeilspitze int qlx = mx + (int) (radius * Math.sin((pYaw + phi) * Math.PI / 180.)); int qly = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos((pYaw + phi) * Math.PI / 180.)); int qrx = mx + (int) (radius * Math.sin((pYaw - phi) * Math.PI / 180.)); int qry = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos((pYaw - phi) * Math.PI / 180.)); // Ellipse zeichnen: g.setStroke(new BasicStroke(2.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); g.drawOval(mx - rx, my - ry, 2 * rx, 2 * ry); // Striche fr Pfeil zeichnen: g.setStroke(new BasicStroke(1.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); boolean fillArrow = true; if (fillArrow) g.fill(new Polygon(new int[] { px, qlx, qrx }, new int[] { py, qly, qry }, 3)); else { g.drawLine(px, py, qlx, qly); g.drawLine(px, py, qrx, qry); g.drawLine(qlx, qly, qrx, qry); } } g.dispose(); } }
From source file:extern.AsymmetricStatisticalBarRenderer.java
/** * Draws an item for a plot with a horizontal orientation. * * @param g2 the graphics device.//w w w.j a v a2 s . c o m * @param state the renderer state. * @param dataArea the data area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param visibleRow the visible row index. * @param row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, AsymmetricStatisticalCategoryDataset dataset, int visibleRow, int row, int column) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); // BAR Y double rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation); int seriesCount = state.getVisibleSeriesCount() >= 0 ? state.getVisibleSeriesCount() : getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectY = rectY + visibleRow * (state.getBarWidth() + seriesGap); } else { rectY = rectY + visibleRow * state.getBarWidth(); } // BAR X Number meanValue = dataset.getMeanValue(row, column); if (meanValue == null) { return; } double value = meanValue.doubleValue(); double base = 0.0; double lclip = getLowerClip(); double uclip = getUpperClip(); if (uclip <= 0.0) { // cases 1, 2, 3 and 4 if (value >= uclip) { return; // bar is not visible } base = uclip; if (value <= lclip) { value = lclip; } } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8 if (value >= uclip) { value = uclip; } else { if (value <= lclip) { value = lclip; } } } else { // cases 9, 10, 11 and 12 if (value <= lclip) { return; // bar is not visible } base = getLowerClip(); if (value >= uclip) { value = uclip; } } RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation); double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation); double rectX = Math.min(transY2, transY1); double rectHeight = state.getBarWidth(); double rectWidth = Math.abs(transY2 - transY1); Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); Paint itemPaint = getItemPaint(row, column); GradientPaintTransformer t = getGradientPaintTransformer(); if (t != null && itemPaint instanceof GradientPaint) { itemPaint = t.transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); // draw the outline... if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } // CI lines Number n = dataset.getUpperValue(row, column); Number m = dataset.getLowerValue(row, column); if (n != null && m != null) { double valueUpperDelta = n.doubleValue(); double valueLowerDelta = m.doubleValue(); double highVal = rangeAxis.valueToJava2D(valueUpperDelta, dataArea, yAxisLocation); double lowVal = rangeAxis.valueToJava2D(valueLowerDelta, dataArea, yAxisLocation); if (this.errorIndicatorPaint != null) { g2.setPaint(this.errorIndicatorPaint); } else { g2.setPaint(getItemOutlinePaint(row, column)); } if (this.errorIndicatorStroke != null) { g2.setStroke(this.errorIndicatorStroke); } else { g2.setStroke(getItemOutlineStroke(row, column)); } Line2D line = null; line = new Line2D.Double(lowVal, rectY + rectHeight / 2.0d, highVal, rectY + rectHeight / 2.0d); g2.draw(line); line = new Line2D.Double(highVal, rectY + rectHeight * 0.25, highVal, rectY + rectHeight * 0.75); g2.draw(line); line = new Line2D.Double(lowVal, rectY + rectHeight * 0.25, lowVal, rectY + rectHeight * 0.75); g2.draw(line); } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, bar); } }
From source file:extern.AsymmetricStatisticalBarRenderer.java
/** * Draws an item for a plot with a vertical orientation. * * @param g2 the graphics device.//from w w w . j av a2s. co m * @param state the renderer state. * @param dataArea the data area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param visibleRow the visible row index. * @param row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, AsymmetricStatisticalCategoryDataset dataset, int visibleRow, int row, int column) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); // BAR X double rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation); int seriesCount = state.getVisibleSeriesCount() >= 0 ? state.getVisibleSeriesCount() : getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectX = rectX + visibleRow * (state.getBarWidth() + seriesGap); } else { rectX = rectX + visibleRow * state.getBarWidth(); } // BAR Y Number meanValue = dataset.getMeanValue(row, column); if (meanValue == null) { return; } double value = meanValue.doubleValue(); double base = 0.0; double lclip = getLowerClip(); double uclip = getUpperClip(); if (uclip <= 0.0) { // cases 1, 2, 3 and 4 if (value >= uclip) { return; // bar is not visible } base = uclip; if (value <= lclip) { value = lclip; } } else if (lclip <= 0.0) { // cases 5, 6, 7 and 8 if (value >= uclip) { value = uclip; } else { if (value <= lclip) { value = lclip; } } } else { // cases 9, 10, 11 and 12 if (value <= lclip) { return; // bar is not visible } base = getLowerClip(); if (value >= uclip) { value = uclip; } } RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation); double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation); double rectY = Math.min(transY2, transY1); double rectWidth = state.getBarWidth(); double rectHeight = Math.abs(transY2 - transY1); Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); Paint itemPaint = getItemPaint(row, column); GradientPaintTransformer t = getGradientPaintTransformer(); if (t != null && itemPaint instanceof GradientPaint) { itemPaint = t.transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); // draw the outline... if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } // CI lines Number n = dataset.getUpperValue(row, column); Number m = dataset.getLowerValue(row, column); if (n != null && m != null) { double valueUpperDelta = n.doubleValue(); double valueLowerDelta = m.doubleValue(); if (valueLowerDelta > meanValue.doubleValue()) { double temp = valueLowerDelta - meanValue.doubleValue(); valueLowerDelta = meanValue.doubleValue() - temp; } if (valueUpperDelta < meanValue.doubleValue()) { double temp = meanValue.doubleValue() - valueUpperDelta; valueUpperDelta = temp; } double highVal = rangeAxis.valueToJava2D(valueUpperDelta, dataArea, yAxisLocation); double lowVal = rangeAxis.valueToJava2D(valueLowerDelta, dataArea, yAxisLocation); if (this.errorIndicatorPaint != null) { g2.setPaint(this.errorIndicatorPaint); } else { g2.setPaint(getItemOutlinePaint(row, column)); } if (this.errorIndicatorStroke != null) { g2.setStroke(this.errorIndicatorStroke); } else { g2.setStroke(getItemOutlineStroke(row, column)); } Line2D line = null; line = new Line2D.Double(rectX + rectWidth / 2.0d, lowVal, rectX + rectWidth / 2.0d, highVal); g2.draw(line); line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, highVal, rectX + rectWidth / 2.0d + 5.0d, highVal); g2.draw(line); line = new Line2D.Double(rectX + rectWidth / 2.0d - 5.0d, lowVal, rectX + rectWidth / 2.0d + 5.0d, lowVal); g2.draw(line); } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, bar); } }
From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java
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) { IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; Paint seriesPaint = getItemPaint(series, item); double value0; double value1; if (getUseYInterval()) { value0 = intervalDataset.getStartYValue(series, item); value1 = intervalDataset.getEndYValue(series, item); } else {/*w w w.j ava2s. c o m*/ value0 = getBase(); value1 = intervalDataset.getYValue(series, item); } if (Double.isNaN(value0) || Double.isNaN(value1)) { return; } double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge()); double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); double x1 = intervalDataset.getStartXValue(series, item); double translatedX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double x2 = intervalDataset.getEndXValue(series, item); double translatedX2 = domainAxis.valueToJava2D(x2, dataArea, xAxisLocation); double translatedWidth = Math.max(1, Math.abs(translatedX2 - translatedX1)); double translatedHeight = Math.abs(translatedValue0 - translatedValue1); /* * With BlueDragon, this value is always false so it's safe to comment this * code out. if (this.centerBarAtStartValue) { translatedX1 -= * translatedWidth / 2; } */ PlotOrientation orientation = plot.getOrientation(); if (getMargin() > 0.0) { if (orientation == PlotOrientation.HORIZONTAL) { // BEGIN fix for horizontal bar charts that have a margin double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; translatedX1 = translatedX1 - cut / 2; // END fix for horizontal bar charts that have a margin } else if (orientation == PlotOrientation.VERTICAL) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; translatedX1 = translatedX1 + cut / 2; } } int numSeries = dataset.getSeriesCount(); double seriesBarWidth = translatedWidth / numSeries; Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(Math.min(translatedValue0, translatedValue1), translatedX1 - seriesBarWidth * (numSeries - series), translatedHeight, seriesBarWidth); } else if (orientation == PlotOrientation.VERTICAL) { bar = new Rectangle2D.Double(translatedX1 + seriesBarWidth * series, Math.min(translatedValue0, translatedValue1), seriesBarWidth, translatedHeight); } g2.setPaint(seriesPaint); g2.fill(bar); if (isDrawBarOutline() && Math.abs(translatedX2 - translatedX1) > 3) { g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(bar); } // TODO: we need something better for the item labels if (isItemLabelVisible(series, item)) { // Change parameters passed to this method to call our local version drawItemLabel(g2, orientation, dataset, series, item, bar, value1 < 0.0); } // add an entity for the item... if (info != null) { EntityCollection entities = info.getOwner().getEntityCollection(); if (entities != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } XYItemEntity entity = new XYItemEntity(bar, dataset, series, item, tip, url); entities.add(entity); } } }