List of usage examples for java.awt Graphics2D fill
public abstract void fill(Shape s);
From source file:org.trade.ui.chart.renderer.HeikinAshiRenderer.java
/** * Method drawItem.//from w w w .j av a2 s . co m * * @param g2 * Graphics2D * @param state * XYItemRendererState * @param dataArea * Rectangle2D * @param info * PlotRenderingInfo * @param plot * XYPlot * @param domainAxis * ValueAxis * @param rangeAxis * ValueAxis * @param dataset * XYDataset * @param series * int * @param item * int * @param crosshairState * CrosshairState * @param pass * int * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D, * XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot, * ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int) */ 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 (dataset instanceof HeikinAshiDataset) { // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } HeikinAshiDataset highLowData = (HeikinAshiDataset) dataset; double x = highLowData.getXValue(series, item); double yHigh = highLowData.getHighValue(series, item); double yLow = highLowData.getLowValue(series, item); double yOpen = highLowData.getOpenValue(series, item); double yClose = highLowData.getCloseValue(series, item); RectangleEdge domainEdge = plot.getDomainAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge); RectangleEdge edge = plot.getRangeAxisEdge(); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge); double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge); double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge); int itemCount = highLowData.getItemCount(series); double xxWidth = dataArea.getWidth() / itemCount; xxWidth -= 2 * this.getAutoWidthGap(); xxWidth *= this.getAutoWidthFactor(); xxWidth = Math.min(xxWidth, this.maxCandleWidth); double stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth); Paint outlinePaint = null; outlinePaint = getItemOutlinePaint(series, item); g2.setStroke(getItemStroke(series, item)); g2.setPaint(outlinePaint); double yyMaxOpenClose = Math.max(yyOpen, yyClose); double yyMinOpenClose = Math.min(yyOpen, yyClose); double maxOpenClose = Math.max(yOpen, yClose); double minOpenClose = Math.min(yOpen, yClose); Shape body = null; boolean highlight = highlight(series, item); /********************************** * draw the upper shadow START **********************************/ if (yHigh > maxOpenClose) { if (highlight) { body = new Rectangle2D.Double(xx - (stickWidth / 2), yyHigh - 10, stickWidth, (yyMaxOpenClose - yyHigh) + 10); g2.setPaint(Color.YELLOW); g2.fill(body); g2.draw(body); } } if (yHigh > maxOpenClose) { if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(Color.black); } g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose)); } /********************************** * draw the lower shadow START **********************************/ if (yLow < minOpenClose) { if (highlight) { body = new Rectangle2D.Double(xx - (stickWidth / 2), yyMinOpenClose, stickWidth, (yyLow - yyMinOpenClose) + 10); g2.setPaint(Color.YELLOW); g2.fill(body); g2.draw(body); } if (yLow < minOpenClose) { if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(Color.BLACK); } g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose)); } } /********************************** * draw the body **********************************/ body = new Rectangle2D.Double(xx - (stickWidth / 2), yyMinOpenClose, stickWidth, yyMaxOpenClose - yyMinOpenClose); if (nightMode) { g2.setPaint(Color.white); } else { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } g2.fill(body); g2.draw(body); if (nightMode) { if (yClose > yOpen) { g2.setPaint(upPaint); } else { g2.setPaint(downPaint); } } else { g2.setPaint(outlinePaint); } g2.draw(body); // add an entity for the item... if (entities != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(body, dataset, series, item, tip, null); entities.add(entity); } } }
From source file:umontreal.iro.lecuyer.charts.EmpiricalRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data 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./* ww w . j av a 2 s . com*/ * @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; PlotOrientation orientation = plot.getOrientation(); java.awt.Paint seriesPaint = getItemPaint(series, item); java.awt.Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(seriesPaint); g2.setStroke(seriesStroke); double x0 = dataset.getXValue(series, item); double y0 = dataset.getYValue(series, item); if (java.lang.Double.isNaN(y0)) return; org.jfree.ui.RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); org.jfree.ui.RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double x1 = 0, y1 = 0; if (item < dataset.getItemCount(series) - 1) { x1 = dataset.getXValue(series, item + 1); y1 = dataset.getYValue(series, item + 1); } else { x1 = dataArea.getMaxX(); y1 = dataArea.getMaxY(); } boolean useFillPaint = getUseFillPaint(); ; boolean drawOutlines = getDrawOutlines(); if (!java.lang.Double.isNaN(y0)) { double transX1; double transY1; if (item < dataset.getItemCount(series) - 1) { transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); } else { transX1 = x1; transY1 = y1; } Line2D line = state.workingLine; if (orientation == PlotOrientation.HORIZONTAL) { line.setLine(transY0, transX0, transY0, transX1); g2.draw(line); } else if (orientation == PlotOrientation.VERTICAL) { line.setLine(transX0, transY0, transX1, transY0); g2.draw(line); } } if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) shape = ShapeUtilities.createTranslatedShape(shape, transY0, transX0); else if (orientation == PlotOrientation.VERTICAL) shape = ShapeUtilities.createTranslatedShape(shape, transX0, transY0); if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (useFillPaint) g2.setPaint(getItemFillPaint(series, item)); else g2.setPaint(getItemPaint(series, item)); g2.fill(shape); } if (drawOutlines) { if (getUseOutlinePaint()) g2.setPaint(getItemOutlinePaint(series, item)); else g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } if (isItemLabelVisible(series, item)) { double xx = transX0; double yy = transY0; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY0; yy = transX0; } drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y0 < 0.0D); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x0, y0, domainAxisIndex, rangeAxisIndex, transX0, transY0, orientation); if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { int r = getDefaultEntityRadius(); java.awt.Shape shape = orientation != PlotOrientation.VERTICAL ? ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transY0 - (double) r, transX0 - (double) r, 2 * r, 2 * r))) : ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transX0 - (double) r, transY0 - (double) r, 2 * r, 2 * r))); if (shape != 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(shape, dataset, series, item, tip, url); entities.add(entity); } } } }
From source file:org.trade.ui.chart.renderer.PivotRenderer.java
/** * Draws the annotation./*from w w w. j a v a 2s.c om*/ * * @param g2 * the graphics device. * @param plot * the plot. * @param dataArea * the data area. * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param rendererIndex * the renderer index. * @param info * the plot rendering info. * @param angle * double * @param x * double * @param y * double * @param ledgend * String */ public void drawPivotArrow(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info, double angle, double x, double y, String ledgend) { double tipRadius = DEFAULT_TIP_RADIUS; double baseRadius = DEFAULT_BASE_RADIUS; double arrowLength = DEFAULT_ARROW_LENGTH; double arrowWidth = DEFAULT_ARROW_WIDTH; double labelOffset = DEFAULT_LABEL_OFFSET; Font font = DEFAULT_FONT; Paint paint = DEFAULT_PAINT; boolean outlineVisible = false; Paint outlinePaint = Color.black; Stroke outlineStroke = new BasicStroke(0.5f); TextAnchor textAnchor = DEFAULT_TEXT_ANCHOR; TextAnchor rotationAnchor = DEFAULT_ROTATION_ANCHOR; double rotationAngle = DEFAULT_ROTATION_ANGLE; Stroke arrowStroke = new BasicStroke(1.0f); Paint arrowPaint = Color.black; PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); double j2DX = domainAxis.valueToJava2D(x, dataArea, domainEdge); double j2DY = rangeAxis.valueToJava2D(y, dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { double temp = j2DX; j2DX = j2DY; j2DY = temp; } double startX = j2DX + (Math.cos(angle) * baseRadius); double startY = j2DY + (Math.sin(angle) * baseRadius); double endX = j2DX + (Math.cos(angle) * tipRadius); double endY = j2DY + (Math.sin(angle) * tipRadius); double arrowBaseX = endX + (Math.cos(angle) * arrowLength); double arrowBaseY = endY + (Math.sin(angle) * arrowLength); double arrowLeftX = arrowBaseX + (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth); double arrowLeftY = arrowBaseY + (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth); double arrowRightX = arrowBaseX - (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth); double arrowRightY = arrowBaseY - (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth); GeneralPath arrow = new GeneralPath(); arrow.moveTo((float) endX, (float) endY); arrow.lineTo((float) arrowLeftX, (float) arrowLeftY); arrow.lineTo((float) arrowRightX, (float) arrowRightY); arrow.closePath(); g2.setStroke(arrowStroke); g2.setPaint(arrowPaint); Line2D line = new Line2D.Double(startX, startY, endX, endY); g2.draw(line); g2.fill(arrow); // draw the label double labelX = j2DX + (Math.cos(angle) * (baseRadius + labelOffset)); double labelY = j2DY + (Math.sin(angle) * (baseRadius + labelOffset)); g2.setFont(font); Shape hotspot = TextUtilities.calculateRotatedStringBounds(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle, rotationAnchor); g2.setPaint(paint); TextUtilities.drawRotatedString(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle, rotationAnchor); if (outlineVisible) { g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(hotspot); } // String toolTip = getToolTipText(); // String url = getURL(); // if (toolTip != null || url != null) { // addEntity(info, hotspot, rendererIndex, toolTip, url); // } }
From source file:extern.AsymmetricStatisticalBarRenderer.java
/** * Draws an item for a plot with a horizontal orientation. * * @param g2 the graphics device./*from w ww . ja v a 2s . 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 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./* w w w . j a v a 2 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 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:org.jfree.chart.demo.GanttRenderer2.java
protected void drawTasks(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate, Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis, GanttCategoryDataset ganttcategorydataset, int i, int j) { int k = ganttcategorydataset.getSubIntervalCount(i, j); if (k == 0)/*from w w w. j ava 2 s . c o m*/ drawTask(graphics2d, categoryitemrendererstate, rectangle2d, categoryplot, categoryaxis, valueaxis, ganttcategorydataset, i, j); for (int l = 0; l < k; l++) { org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge(); Number number = ganttcategorydataset.getStartValue(i, j, l); if (number == null) return; double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge); Number number1 = ganttcategorydataset.getEndValue(i, j, l); if (number1 == null) return; double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge); if (d1 < d) { double d2 = d1; d1 = d; d = d2; } double d3 = calculateBarW0(categoryplot, categoryplot.getOrientation(), rectangle2d, categoryaxis, categoryitemrendererstate, i, j); double d4 = Math.abs(d1 - d); double d5 = categoryitemrendererstate.getBarWidth(); java.awt.geom.Rectangle2D.Double double1 = null; if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) double1 = new java.awt.geom.Rectangle2D.Double(d, d3, d4, d5); else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) double1 = new java.awt.geom.Rectangle2D.Double(d3, d, d5, d4); java.awt.geom.Rectangle2D.Double double2 = null; java.awt.geom.Rectangle2D.Double double3 = null; Number number2 = ganttcategorydataset.getPercentComplete(i, j, l); double d6 = getStartPercent(); double d7 = getEndPercent(); if (number2 != null) { double d8 = number2.doubleValue(); if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) { double2 = new java.awt.geom.Rectangle2D.Double(d, d3 + d6 * d5, d4 * d8, d5 * (d7 - d6)); double3 = new java.awt.geom.Rectangle2D.Double(d + d4 * d8, d3 + d6 * d5, d4 * (1.0D - d8), d5 * (d7 - d6)); } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) { double2 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d + d4 * (1.0D - d8), d5 * (d7 - d6), d4 * d8); double3 = new java.awt.geom.Rectangle2D.Double(d3 + d6 * d5, d, d5 * (d7 - d6), d4 * (1.0D - d8)); } } Paint paint = getItemPaint(i, j); graphics2d.setPaint(paint); graphics2d.fill(double1); if (double2 != null) { graphics2d.setPaint(getCompletePaint()); graphics2d.fill(double2); } if (double3 != null) { graphics2d.setPaint(getIncompletePaint()); graphics2d.fill(double3); } if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) { graphics2d.setStroke(getItemStroke(i, j)); graphics2d.setPaint(getItemOutlinePaint(i, j)); graphics2d.draw(double1); } if (categoryitemrendererstate.getInfo() == null) continue; EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection(); if (entitycollection == null) continue; String s = null; if (getToolTipGenerator(i, j) != null) s = getToolTipGenerator(i, j).generateToolTip(ganttcategorydataset, i, j); String s1 = null; if (getItemURLGenerator(i, j) != null) s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j); CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset, ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j)); entitycollection.add(categoryitementity); } }
From source file:org.jfree.chart.demo.GanttRenderer2.java
protected void drawTask(Graphics2D graphics2d, CategoryItemRendererState categoryitemrendererstate, Rectangle2D rectangle2d, CategoryPlot categoryplot, CategoryAxis categoryaxis, ValueAxis valueaxis, GanttCategoryDataset ganttcategorydataset, int i, int j) { PlotOrientation plotorientation = categoryplot.getOrientation(); org.jfree.ui.RectangleEdge rectangleedge = categoryplot.getRangeAxisEdge(); Number number = ganttcategorydataset.getEndValue(i, j); if (number == null) return;/*from w ww . j ava 2 s.com*/ double d = valueaxis.valueToJava2D(number.doubleValue(), rectangle2d, rectangleedge); Number number1 = ganttcategorydataset.getStartValue(i, j); if (number1 == null) return; double d1 = valueaxis.valueToJava2D(number1.doubleValue(), rectangle2d, rectangleedge); if (d1 < d) { double d2 = d1; d1 = d; d = d2; Number number2 = number1; number1 = number; number = number2; } int k = countNonNullValues(ganttcategorydataset, j); if (k == 0) return; int l = countPriorNonNullValues(ganttcategorydataset, j, i); double d3 = (categoryaxis.getCategoryEnd(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()) - categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge())) / (double) k; double d4 = categoryaxis.getCategoryStart(j, getColumnCount(), rectangle2d, categoryplot.getDomainAxisEdge()) + d3 * (double) l; double d5 = Math.abs(d1 - d); java.awt.geom.Rectangle2D.Double double1 = null; if (plotorientation == PlotOrientation.HORIZONTAL) double1 = new java.awt.geom.Rectangle2D.Double(d, d4, d5, d3); else if (plotorientation == PlotOrientation.VERTICAL) double1 = new java.awt.geom.Rectangle2D.Double(d4, d1, d3, d5); java.awt.geom.Rectangle2D.Double double2 = null; java.awt.geom.Rectangle2D.Double double3 = null; Number number3 = ganttcategorydataset.getPercentComplete(i, j); double d6 = getStartPercent(); double d7 = getEndPercent(); if (number3 != null) { double d8 = number3.doubleValue(); if (categoryplot.getOrientation() == PlotOrientation.HORIZONTAL) { double2 = new java.awt.geom.Rectangle2D.Double(d, d4 + d6 * d3, d5 * d8, d3 * (d7 - d6)); double3 = new java.awt.geom.Rectangle2D.Double(d + d5 * d8, d4 + d6 * d3, d5 * (1.0D - d8), d3 * (d7 - d6)); } else if (categoryplot.getOrientation() == PlotOrientation.VERTICAL) { double2 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1 + d5 * (1.0D - d8), d3 * (d7 - d6), d5 * d8); double3 = new java.awt.geom.Rectangle2D.Double(d4 + d6 * d3, d1, d3 * (d7 - d6), d5 * (1.0D - d8)); } } Paint paint = getItemPaint(i, j); graphics2d.setPaint(paint); graphics2d.fill(double1); if (double2 != null) { graphics2d.setPaint(getCompletePaint()); graphics2d.fill(double2); } if (double3 != null) { graphics2d.setPaint(getIncompletePaint()); graphics2d.fill(double3); } if (isDrawBarOutline() && categoryitemrendererstate.getBarWidth() > 3D) { java.awt.Stroke stroke = getItemOutlineStroke(i, j); Paint paint1 = getItemOutlinePaint(i, j); if (stroke != null && paint1 != null) { graphics2d.setStroke(stroke); graphics2d.setPaint(paint1); graphics2d.draw(double1); } } org.jfree.chart.labels.CategoryItemLabelGenerator categoryitemlabelgenerator = getItemLabelGenerator(i, j); if (categoryitemlabelgenerator != null && isItemLabelVisible(i, j)) drawItemLabel(graphics2d, ganttcategorydataset, i, j, categoryplot, categoryitemlabelgenerator, double1, false); if (categoryitemrendererstate.getInfo() != null) { EntityCollection entitycollection = categoryitemrendererstate.getEntityCollection(); if (entitycollection != null) { String s = null; CategoryToolTipGenerator categorytooltipgenerator = getToolTipGenerator(i, j); if (categorytooltipgenerator != null) s = categorytooltipgenerator.generateToolTip(ganttcategorydataset, i, j); String s1 = null; if (getItemURLGenerator(i, j) != null) s1 = getItemURLGenerator(i, j).generateURL(ganttcategorydataset, i, j); CategoryItemEntity categoryitementity = new CategoryItemEntity(double1, s, s1, ganttcategorydataset, ganttcategorydataset.getRowKey(i), ganttcategorydataset.getColumnKey(j)); entitycollection.add(categoryitementity); } } }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Draws the edge <code>e</code>, whose endpoints are at <code>(x1,y1)</code> * and <code>(x2,y2)</code>, on the graphics context <code>g</code>. * The <code>Shape</code> provided by the <code>EdgeShapeFunction</code> instance * is scaled in the x-direction so that its width is equal to the distance between * <code>(x1,y1)</code> and <code>(x2,y2)</code>. *///from ww w. j ava 2 s. co m protected void drawSimpleEdge(Graphics2D g, Edge e, int x1, int y1, int x2, int y2) { Pair endpoints = e.getEndpoints(); Vertex v1 = (Vertex) endpoints.getFirst(); Vertex v2 = (Vertex) endpoints.getSecond(); boolean isLoop = v1.equals(v2); Shape s2 = vertexShapeFunction.getShape(v2); Shape edgeShape = edgeShapeFunction.getShape(e); boolean edgeHit = true; boolean arrowHit = true; Rectangle deviceRectangle = null; if (screenDevice != null) { Dimension d = screenDevice.getSize(); if (d.width <= 0 || d.height <= 0) { d = screenDevice.getPreferredSize(); } deviceRectangle = new Rectangle(0, 0, d.width, d.height); } AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); if (isLoop) { // this is a self-loop. scale it is larger than the vertex // it decorates and translate it so that its nadir is // at the center of the vertex. Rectangle2D s2Bounds = s2.getBounds2D(); xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight()); xform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { // this is a normal edge. Rotate it to the angle between // vertex endpoints, then scale it to the distance between // the vertices float dx = x2 - x1; float dy = y2 - y1; float thetaRadians = (float) Math.atan2(dy, dx); xform.rotate(thetaRadians); float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale(dist, 1.0); } edgeShape = xform.createTransformedShape(edgeShape); edgeHit = viewTransformer.transform(edgeShape).intersects(deviceRectangle); if (edgeHit == true) { Paint oldPaint = g.getPaint(); // get Paints for filling and drawing // (filling is done first so that drawing and label use same Paint) Paint fill_paint = edgePaintFunction.getFillPaint(e); if (fill_paint != null) { g.setPaint(fill_paint); g.fill(edgeShape); } Paint draw_paint = edgePaintFunction.getDrawPaint(e); if (draw_paint != null) { g.setPaint(draw_paint); g.draw(edgeShape); } float scalex = (float) g.getTransform().getScaleX(); float scaley = (float) g.getTransform().getScaleY(); // see if arrows are too small to bother drawing if (scalex < .3 || scaley < .3) return; if (edgeArrowPredicate.evaluate(e)) { Shape destVertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getSecond()); AffineTransform xf = AffineTransform.getTranslateInstance(x2, y2); destVertexShape = xf.createTransformedShape(destVertexShape); arrowHit = viewTransformer.transform(destVertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getArrowTransform((GeneralPath) edgeShape, destVertexShape); else at = getArrowTransform(new GeneralPath(edgeShape), destVertexShape); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); // note that arrows implicitly use the edge's draw paint g.fill(arrow); } if (e instanceof UndirectedEdge) { Shape vertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getFirst()); xf = AffineTransform.getTranslateInstance(x1, y1); vertexShape = xf.createTransformedShape(vertexShape); arrowHit = viewTransformer.transform(vertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getReverseArrowTransform((GeneralPath) edgeShape, vertexShape, !isLoop); else at = getReverseArrowTransform(new GeneralPath(edgeShape), vertexShape, !isLoop); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); g.fill(arrow); } } } // use existing paint for text if no draw paint specified if (draw_paint == null) g.setPaint(oldPaint); String label = edgeStringer.getLabel(e); if (label != null) { labelEdge(g, e, label, x1, x2, y1, y2); } // restore old paint g.setPaint(oldPaint); } }
From source file:edu.cuny.jfree.chart.renderer.category.IntervalListBarRenderer.java
/** * Draws a single interval.// w w w . j a v a2 s. c om * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the data plot area. * @param plot * the plot. * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the data. * @param row * the row index (zero-based). * @param column * the column index (zero-based). */ protected void drawInterval(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final DefaultIntervalListCategoryDataset dataset, final int row, final int column) { final int seriesCount = getRowCount(); final int categoryCount = getColumnCount(); final PlotOrientation orientation = plot.getOrientation(); double rectX = 0.0; double rectY = 0.0; final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); final List list = dataset.getList(row, column); if (list == null) { return; } Interval interval = null; for (int i = 0; i < list.size(); i++) { interval = (Interval) list.get(i); if (!interval.isMeaningful()) { continue; } // Y0 double java2dValue0 = rangeAxis.valueToJava2D(interval.low, dataArea, rangeAxisLocation); // Y1 double java2dValue1 = rangeAxis.valueToJava2D(interval.high, dataArea, rangeAxisLocation); if (java2dValue1 < java2dValue0) { final double temp = java2dValue1; java2dValue1 = java2dValue0; java2dValue0 = temp; } // BAR WIDTH double rectWidth = state.getBarWidth(); // BAR HEIGHT double rectHeight = Math.abs(java2dValue1 - java2dValue0); if (orientation == PlotOrientation.HORIZONTAL) { // BAR Y rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); if (seriesCount > 1) { final double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectY = rectY + row * (state.getBarWidth() + seriesGap); } else { rectY = rectY + row * state.getBarWidth(); } rectX = java2dValue0; rectHeight = state.getBarWidth(); rectWidth = Math.abs(java2dValue1 - java2dValue0); } else if (orientation == PlotOrientation.VERTICAL) { // BAR X rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); if (seriesCount > 1) { final double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectX = rectX + row * (state.getBarWidth() + seriesGap); } else { rectX = rectX + row * state.getBarWidth(); } rectY = java2dValue0; } final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); final Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); // draw the outline... if (state.getBarWidth() > BarRenderer.BAR_OUTLINE_WIDTH_THRESHOLD) { final Stroke stroke = getItemOutlineStroke(row, column); final Paint paint = getItemOutlinePaint(row, column); if ((stroke != null) && (paint != null)) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } final CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if ((generator != null) && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, false); } // collect entity and tool tip information... if (state.getInfo() != null) { final EntityCollection entities = state.getInfo().getOwner().getEntityCollection(); if (entities != null) { String tip = null; final 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); } final CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } } }
From source file:com.bdaum.zoom.report.internal.jfree.custom.CylinderRenderer.java
/** * Draws a cylinder to represent one data item. * * @param g2 the graphics device.//from www . ja v a 2 s .c o m * @param state the renderer state. * @param dataArea the area for plotting the data. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); float barL0 = Math.min(transL0, transL1); float barLength = Math.abs(transL1 - transL0); // draw the bar... GeneralPath bar = new GeneralPath(); Shape top = null; if (orientation == PlotOrientation.HORIZONTAL) { bar.moveTo((float) (barL0 + getXOffset() / 2), (float) barW0); bar.lineTo((float) (barL0 + barLength + getXOffset() / 2), (float) barW0); Arc2D arc = new Arc2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth(), 90, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barL0 + getXOffset() / 2), (float) (barW0 + state.getBarWidth())); arc = new Arc2D.Double(barL0, barW0, getXOffset(), state.getBarWidth(), 270, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); top = new Ellipse2D.Double(barL0 + barLength, barW0, getXOffset(), state.getBarWidth()); } else { bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2)); bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2)); Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(), getYOffset(), 180, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2)); arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); top = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset()); } Paint itemPaint = getItemPaint(row, column); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); g2.fill(bar); if (itemPaint instanceof GradientPaint) { g2.setPaint(((GradientPaint) itemPaint).getColor2()); } else { g2.setPaint(PaintAlpha.darker(itemPaint)); // bd } if (top != null) { g2.fill(top); } if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (top != null) { g2.draw(top); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar.getBounds2D(), (value < 0.0)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }