List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:de.laures.cewolf.jfree.ThermometerPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device./*from w w w . jav a 2s . co m*/ * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { RoundRectangle2D outerStem = new RoundRectangle2D.Double(); RoundRectangle2D innerStem = new RoundRectangle2D.Double(); RoundRectangle2D mercuryStem = new RoundRectangle2D.Double(); Ellipse2D outerBulb = new Ellipse2D.Double(); Ellipse2D innerBulb = new Ellipse2D.Double(); String temp = null; FontMetrics metrics = null; if (info != null) { info.setPlotArea(area); } // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); // adjust for padding... Rectangle2D interior = (Rectangle2D) area.clone(); this.padding.trim(interior); int midX = (int) (interior.getX() + (interior.getWidth() / 2)); int midY = (int) (interior.getY() + (interior.getHeight() / 2)); int stemTop = (int) (interior.getMinY() + getBulbRadius()); int stemBottom = (int) (interior.getMaxY() - getBulbDiameter()); Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(), stemBottom - stemTop); outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter()); outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter()); Area outerThermometer = new Area(outerBulb); Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2); innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(), getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop, getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); innerThermometer.add(tempArea); if ((this.dataset != null) && (this.dataset.getValue() != null)) { double current = this.dataset.getValue().doubleValue(); double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); int i = getColumnDiameter() - getGap() * 2; // already calculated int j = getColumnRadius() - getGap(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); if (k < (getGap() + interior.getMinY())) { k = (int) (getGap() + interior.getMinY()); l = getBulbRadius(); } Area mercury = new Area(innerBulb); if (k < (stemBottom + getBulbRadius())) { mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l); tempArea = new Area(mercuryStem); mercury.add(tempArea); } g2.setPaint(getCurrentPaint()); g2.fill(mercury); // draw range indicators... if (this.subrangeIndicatorsVisible) { g2.setStroke(this.subrangeIndicatorStroke); Range range = this.rangeAxis.getRange(); // draw start of normal range double value = this.subrangeInfo[NORMAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[NORMAL]); g2.draw(line); } // draw start of warning range value = this.subrangeInfo[WARNING][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[WARNING]); g2.draw(line); } // draw start of critical range value = this.subrangeInfo[CRITICAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[CRITICAL]); g2.draw(line); } } // draw the axis... if ((this.rangeAxis != null) && (this.axisLocation != NONE)) { int drawWidth = AXIS_GAP; Rectangle2D drawArea; double cursor = 0; switch (this.axisLocation) { case RIGHT: cursor = midX + getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null); break; case LEFT: default: //cursor = midX - COLUMN_RADIUS - AXIS_GAP; cursor = midX - getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null); break; } } // draw text value on screen g2.setFont(this.valueFont); g2.setPaint(this.valuePaint); metrics = g2.getFontMetrics(); switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap()); break; default: } /***/ } g2.setPaint(this.thermometerPaint); g2.setFont(this.valueFont); // draw units indicator metrics = g2.getFontMetrics(); int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20)); } // draw thermometer outline g2.setStroke(this.thermometerStroke); g2.draw(outerThermometer); g2.draw(innerThermometer); drawOutline(g2, area); }
From source file:edu.dlnu.liuwenpeng.render.CandlestickRenderer.java
/** * Draws the visual representation of a single data item. * /*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 info collects info about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { boolean horiz; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { horiz = true; } else if (orientation == PlotOrientation.VERTICAL) { horiz = false; } else { return; } // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } OHLCDataset highLowData = (OHLCDataset) 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); double volumeWidth; double stickWidth; if (this.candleWidth > 0) { // These are deliberately not bounded to minimums/maxCandleWidth to // retain old behaviour. volumeWidth = this.candleWidth; stickWidth = this.candleWidth; } else { double xxWidth = 0; int itemCount; switch (this.autoWidthMethod) { case WIDTHMETHOD_AVERAGE: itemCount = highLowData.getItemCount(series); if (horiz) { xxWidth = dataArea.getHeight() / itemCount; } else { xxWidth = dataArea.getWidth() / itemCount; } break; case WIDTHMETHOD_SMALLEST: // Note: It would be nice to pre-calculate this per series itemCount = highLowData.getItemCount(series); double lastPos = -1; xxWidth = dataArea.getWidth(); for (int i = 0; i < itemCount; i++) { double pos = domainAxis.valueToJava2D(highLowData.getXValue(series, i), dataArea, domainEdge); if (lastPos != -1) { xxWidth = Math.min(xxWidth, Math.abs(pos - lastPos)); } lastPos = pos; } break; case WIDTHMETHOD_INTERVALDATA: IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; double startPos = domainAxis.valueToJava2D(intervalXYData.getStartXValue(series, item), dataArea, plot.getDomainAxisEdge()); double endPos = domainAxis.valueToJava2D(intervalXYData.getEndXValue(series, item), dataArea, plot.getDomainAxisEdge()); xxWidth = Math.abs(endPos - startPos); break; } xxWidth -= 2 * this.autoWidthGap; xxWidth *= this.autoWidthFactor; xxWidth = Math.min(xxWidth, this.maxCandleWidth); volumeWidth = Math.max(Math.min(1, this.maxCandleWidth), xxWidth); stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth); } Paint p = getItemPaint(series, item); Paint outlinePaint = null; if (this.useOutlinePaint) { outlinePaint = getItemOutlinePaint(series, item); } Stroke s = getItemStroke(series, item); g2.setStroke(s); if (this.drawVolume) { int volume = (int) highLowData.getVolumeValue(series, item); double volumeHeight = volume / this.maxVolume; double min, max; if (horiz) { min = dataArea.getMinX(); max = dataArea.getMaxX(); } else { min = dataArea.getMinY(); max = dataArea.getMaxY(); } double zzVolume = volumeHeight * (max - min); g2.setPaint(getVolumePaint()); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f)); if (horiz) { g2.fill(new Rectangle2D.Double(min, xx - volumeWidth / 2, zzVolume, volumeWidth)); } else { g2.fill(new Rectangle2D.Double(xx - volumeWidth / 2, max - zzVolume, volumeWidth, zzVolume)); } g2.setComposite(originalComposite); } if (this.useOutlinePaint) { g2.setPaint(outlinePaint); } else { g2.setPaint(p); } double yyMaxOpenClose = Math.max(yyOpen, yyClose); double yyMinOpenClose = Math.min(yyOpen, yyClose); double maxOpenClose = Math.max(yOpen, yClose); double minOpenClose = Math.min(yOpen, yClose); // draw the upper shadow if (yHigh > maxOpenClose) { if (yClose > yOpen) { g2.setPaint(Color.green); } else { g2.setPaint(Color.red); } if (horiz) { g2.draw(new Line2D.Double(yyHigh, xx, yyMaxOpenClose, xx)); } else { g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose)); } } // draw the lower shadow if (yLow < minOpenClose) { if (yClose > yOpen) { g2.setPaint(Color.green); } else { g2.setPaint(Color.red); } if (horiz) { g2.draw(new Line2D.Double(yyLow, xx, yyMinOpenClose, xx)); } else { g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose)); } } // draw the body Rectangle2D body = null; Rectangle2D hotspot = null; double length = Math.abs(yyHigh - yyLow); double base = Math.min(yyHigh, yyLow); if (horiz) { body = new Rectangle2D.Double(yyMinOpenClose, xx - stickWidth / 2, yyMaxOpenClose - yyMinOpenClose, stickWidth); hotspot = new Rectangle2D.Double(base, xx - stickWidth / 2, length, stickWidth); } else { body = new Rectangle2D.Double(xx - stickWidth / 2, yyMinOpenClose, stickWidth, yyMaxOpenClose - yyMinOpenClose); hotspot = new Rectangle2D.Double(xx - stickWidth / 2, base, stickWidth, length); } if (yClose > yOpen) { if (this.upPaint != null) { g2.setPaint(this.upPaint); } else { g2.setPaint(p); } g2.fill(body); } else { if (this.downPaint != null) { g2.setPaint(this.downPaint); } else { g2.setPaint(p); } g2.fill(body); } if (this.useOutlinePaint) { g2.setPaint(outlinePaint); } else { if (yClose > yOpen) { g2.setPaint(Color.green); } else { g2.setPaint(p); } } g2.draw(body); // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, 0.0, 0.0); } }
From source file:gda.plots.TurboXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself./*from w ww . j a v a2 s. c o m*/ * * @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. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param crosshairState * crosshair information for the plot ( <code>null</code> permitted). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int _item, CrosshairState crosshairState, int pass) { if (_item > 0) return; SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); try { int x0 = -1; // the x position in pixels of the previous point int y0 = -1; // the y position in pixels of the previous point int x1 = -1; // the x position in pixels of the current point int y1 = -1; // the y position in pixels of the current point int xmin = (int) dataArea.getMinX(); int xmax = (int) dataArea.getMaxX(); int ymin = (int) dataArea.getMinY(); int ymax = (int) dataArea.getMaxY(); GeneralPath path = null; /* * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear * maths */ double xl = 0., mx = Double.NaN, cx = 0.; if (domainAxis instanceof SimpleNumberAxis) { xl = domainAxis.getRange().getLowerBound(); mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl); cx = xmin; } double yl = 0., my = Double.NaN, cy = 0.; if (rangeAxis instanceof SimpleNumberAxis) { yl = rangeAxis.getRange().getLowerBound(); my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl); cy = ymax; } List<XYDataItem> list = sxys.getData(); boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my); Paint paint = sxys.getPaint(); Stroke stroke = sxys.getStroke(); Paint paint_symbol = sxys.getSymbolPaint(); Stroke stroke_symbol = new BasicStroke(); drawLines = sxys.isDrawLines(); boolean filled = sxys.getFilled(); Shape shape = sxys.getSymbol(); boolean drawMarkers = sxys.isDrawMarkers() & shape != null; int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */ if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) { Rectangle shapeBoundingBox = shape.getBounds(); tooltipThresholdCounts = (int) dataArea.getWidth() / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold); } java.util.Vector<ddouble> markerPositions = null; Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } boolean prevLineAdded = false; // In case the iterator does not work then use the TODO comment iterator use and why not always // comment variables synchronized (list) { Iterator<XYDataItem> iter = list.iterator(); /* * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The * variable addThis determines if the current point is to be added to the path If previous line was * added that the current must be even if off the screen - but in this case the flag prevLineAdded is * set false so that the next does not have to be added. */ for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) { XYDataItem dataitem = iter.next(); double x = dataitem.getX().doubleValue(); double y = dataitem.getY().doubleValue(); x = xValueTransformer.transformValue(x); x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation) : (int) ((x - xl) * mx + cx); y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) : (int) ((y - yl) * my + cy); boolean addThis = true; if (item == 0) { x0 = x1; y0 = y1; if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) { addThis = false; } } else { if (x1 == x0 && y1 == y0) { addThis = false; } if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin) || (y1 > ymax && y0 > ymax)) { if (prevLineAdded) { path = addPointToLine(path, orientation, x1, y1); } addThis = false; } } if (addThis) { /* * If the current point is to be added then ensure previous one is as well to prevent lines * not crossing the edge of the screen */ if (!prevLineAdded) { path = addPointToLine(path, orientation, x0, y0); } path = addPointToLine(path, orientation, x1, y1); prevLineAdded = true; } prevLineAdded = addThis; if (addThis && drawMarkers) { if (markerPositions == null) { markerPositions = new java.util.Vector<ddouble>(); } markerPositions.add(new ddouble(item, x1, y1)); if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) { drawMarkers = false; markerPositions = null; } } } if (path != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(path); } if (markerPositions != null) { if (drawMarkers) { g2.setPaint(paint_symbol); g2.setStroke(stroke_symbol); for (ddouble dd : markerPositions) { Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y); if (filled) { g2.fill(shape_item); } else { g2.draw(shape_item); } entityArea = shape_item; // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y); } } g2.setPaint(paint); g2.setStroke(stroke); } } } } catch (Exception e) { e.printStackTrace(); } }
From source file:de.saring.util.gui.jfreechart.StackedRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device.//w ww .ja v a 2s . c om * @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. * @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 information about crosshairs on a plot. * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } TableXYDataset tdataset = (TableXYDataset) dataset; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1)) { y1 = 0.0; } double[] stack1 = getStackValues(tdataset, series, item); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... double x0 = dataset.getXValue(series, Math.max(item - 1, 0)); double y0 = dataset.getYValue(series, Math.max(item - 1, 0)); if (Double.isNaN(y0)) { y0 = 0.0; } double[] stack0 = getStackValues(tdataset, series, Math.max(item - 1, 0)); int itemCount = dataset.getItemCount(series); double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1)); double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1)); if (Double.isNaN(y2)) { y2 = 0.0; } double[] stack2 = getStackValues(tdataset, series, Math.min(item + 1, itemCount - 1)); double xleft = (x0 + x1) / 2.0; double xright = (x1 + x2) / 2.0; double[] stackLeft = averageStackValues(stack0, stack1); double[] stackRight = averageStackValues(stack1, stack2); double[] adjStackLeft = adjustedStackValues(stack0, stack1); double[] adjStackRight = adjustedStackValues(stack1, stack2); RectangleEdge edge0 = plot.getDomainAxisEdge(); float transX1 = (float) domainAxis.valueToJava2D(x1, dataArea, edge0); float transXLeft = (float) domainAxis.valueToJava2D(xleft, dataArea, edge0); float transXRight = (float) domainAxis.valueToJava2D(xright, dataArea, edge0); if (this.roundXCoordinates) { transX1 = Math.round(transX1); transXLeft = Math.round(transXLeft); transXRight = Math.round(transXRight); } float transY1; RectangleEdge edge1 = plot.getRangeAxisEdge(); GeneralPath left = new GeneralPath(); GeneralPath right = new GeneralPath(); if (y1 >= 0.0) { // handle positive value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1); float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1); float transStackLeft = (float) rangeAxis.valueToJava2D(stackLeft[1], dataArea, edge1); // other than StackedXYAreaRenderer2! // LEFT POLYGON if (y0 >= 0.0) { double yleft = (y0 + y1) / 2.0 + stackLeft[1]; float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo(transX1, transY1); left.lineTo(transX1, transStack1); left.lineTo(transXLeft, transStackLeft); left.lineTo(transXLeft, transYLeft); left.closePath(); } else { left.moveTo(transX1, transStack1); left.lineTo(transX1, transY1); left.lineTo(transXLeft, transStackLeft); left.closePath(); } float transStackRight = (float) rangeAxis.valueToJava2D(stackRight[1], dataArea, edge1); // other than StackedXYAreaRenderer2! // RIGHT POLYGON if (y2 >= 0.0) { double yright = (y1 + y2) / 2.0 + stackRight[1]; float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transYRight); right.lineTo(transXRight, transStackRight); right.closePath(); } else { right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transStackRight); right.closePath(); } } else { // handle negative value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1); float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1); float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { left.moveTo(transX1, transStack1); left.lineTo(transX1, transY1); left.lineTo(transXLeft, transStackLeft); left.clone(); } else { double yleft = (y0 + y1) / 2.0 + stackLeft[0]; float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo(transX1, transY1); left.lineTo(transX1, transStack1); left.lineTo(transXLeft, transStackLeft); left.lineTo(transXLeft, transYLeft); left.closePath(); } float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transStackRight); right.closePath(); } else { double yright = (y1 + y2) / 2.0 + stackRight[0]; float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transYRight); right.lineTo(transXRight, transStackRight); right.closePath(); } } // Get series Paint and Stroke Paint itemPaint = getItemPaint(series, item); if (pass == 0) { g2.setPaint(itemPaint); g2.fill(left); g2.fill(right); } else if (pass == 1) { if (item == 0 || (y1 == 0.0 && y0 == 0.0)) { return; } // get the data point... if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0 + stack0[1], dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } state.workingLine.setLine(transX0, transY0, transX1, transY1); if (state.workingLine.intersects(dataArea)) { g2.setStroke(getItemStroke(series, item)); g2.setPaint(super.lookupSeriesPaint(series)); g2.draw(state.workingLine); } return; } // add an entity for the item... if (entities != null) { GeneralPath gp = new GeneralPath(left); gp.append(right, false); entityArea = gp; addEntity(entities, entityArea, dataset, series, item, transX1, transY1); } }
From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java
/** * Draws the visual representation of a series as lines. * * @param g2 the graphics device./*from w w w. j a va 2 s . c o m*/ * @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. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ protected void drawVerticalSeriesLine(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, CrosshairState crosshairState, int pass) { State s = (State) state; RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double lowestVisibleX = domainAxis.getLowerBound(); double highestVisibleX = domainAxis.getUpperBound(); double width = dataArea.getWidth(); double dX = (highestVisibleX - lowestVisibleX) / width * lineWidth; double lowestVisibleY = rangeAxis.getLowerBound(); double highestVisibleY = rangeAxis.getUpperBound(); double lastX = Double.NEGATIVE_INFINITY; double lastY = 0.0; double highY = 0.0; double lowY = 0.0; double openY = 0.0; double closeY = 0.0; boolean lastIntervalDone = false; boolean currentPointVisible = false; boolean lastPointVisible = false; boolean lastPointGood = false; boolean lastPointInInterval = false; boolean pathStarted = false; for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) { double x = dataset.getXValue(series, itemIndex); double y = dataset.getYValue(series, itemIndex); if (!Double.isNaN(x) && !Double.isNaN(y)) { //System.out.println ("Breakpoint 736: pathStarted " + pathStarted); if (!pathStarted) { float startX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation); float startY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); s.seriesPath.moveTo(startX, startY); pathStarted = true; } if ((Math.abs(x - lastX) > dX)) { //System.out.println ("Breakpoint 744: leaving interval "); //in any case, add the interval that we are about to leave to the intervalPath float intervalPathX = 0.0f; float intervalPathStartY = 0.0f; float intervalPathEndY = 0.0f; float seriesPathCurrentX = 0.0f; float seriesPathCurrentY = 0.0f; float seriesPathLastX = 0.0f; float seriesPathLastY = 0.0f; //first set some variables intervalPathX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalPathStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalPathEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); seriesPathCurrentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation); seriesPathLastX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); seriesPathCurrentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); seriesPathLastY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation); /*if((lowY - highY) < 1){ lastPointInInterval = false; }*/ //Double[] values = new Double[]{new Double(openY), new Double(closeY), new Double(highY), new Double(lowY), new Double(lastX)}; /*MessageFormat mf = new MessageFormat("openY {0,number, integer}," + " closeY {1,number, integer}" + " highY {2,number, integer}" + " lowY {3,number, integer}" + "lastX {4,number, integer}");*/ //String text = mf.format(values); //System.out.println("Breakpoint 772" + text); boolean drawInterval = false; if (openY >= closeY) { if (highY > openY || lowY < closeY) { drawInterval = true; } } if (openY < closeY) { if (lowY < openY || highY > closeY) { drawInterval = true; } } //System.out.println("Breakpoint 784, drawInterval " + drawInterval); if (drawInterval) { s.intervalPath.moveTo(intervalPathX, intervalPathStartY); s.intervalPath.lineTo(intervalPathX, intervalPathEndY); } lastIntervalDone = true; //now the series path currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY) && (y <= highestVisibleY)); if (!lastPointGood && !lastPointInInterval) {//last point not valid -- if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position s.seriesPath.moveTo(seriesPathCurrentX, seriesPathCurrentY); } } else {//last point valid //if the last point was visible and not part of an interval, //we have already moved the seriesPath cursor to the last point, either with or without drawingh a line //thus we only need to draw a line to the current position if (lastPointInInterval && lastPointGood) { s.seriesPath.lineTo(seriesPathLastX, seriesPathLastY); s.seriesPath.lineTo(seriesPathCurrentX, seriesPathCurrentY); } //if the last point was not visible or part of an interval, we have just stored the y values of the last point //and not yet moved the seriesPath cursor. Thus, we need to move the cursor to the last point without drawing //and draw a line to the current position. else { s.seriesPath.lineTo(seriesPathCurrentX, seriesPathCurrentY); } } lastPointVisible = currentPointVisible; lastX = x; lastY = y; highY = y; lowY = y; openY = y; closeY = y; lastPointInInterval = false; } else { lastIntervalDone = false; lastPointInInterval = true; highY = Math.max(highY, y); lowY = Math.min(lowY, y); closeY = y; } lastPointGood = true; } else { lastPointGood = false; } } // if this is the last item, draw the path ... // draw path, but first check whether we need to complete an interval if (!lastIntervalDone) { if (lowY < highY) { float intervalX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); float intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); float intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); s.intervalPath.moveTo(intervalX, intervalStartY); s.intervalPath.lineTo(intervalX, intervalEndY); } } PathIterator pi = s.seriesPath.getPathIterator(null); g2.setStroke(getItemStroke(series, 0)); g2.setPaint(getItemPaint(series, 0)); g2.draw(s.seriesPath); g2.draw(s.intervalPath); }
From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java
protected void drawSeriesLine(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, CrosshairState crosshairState, int pass) { State s = (State) state; PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double lowestVisibleX = domainAxis.getLowerBound(); double highestVisibleX = domainAxis.getUpperBound(); double width = (orientation == PlotOrientation.HORIZONTAL) ? dataArea.getHeight() : dataArea.getWidth(); double dX = (highestVisibleX - lowestVisibleX) / width * lineWidth; double lowestVisibleY = rangeAxis.getLowerBound(); double highestVisibleY = rangeAxis.getUpperBound(); double lastX = Double.NEGATIVE_INFINITY; double lastY = 0.0; double highY = 0.0; double lowY = 0.0; double closeY = 0.0; boolean lastIntervalDone = false; boolean currentPointVisible = false; boolean lastPointVisible = false; boolean lastPointGood = false; boolean lastPointInInterval = false; int intervalCount = 0; int badPoints = 0; for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) { double x = dataset.getXValue(series, itemIndex); double y = dataset.getYValue(series, itemIndex); if (!Double.isNaN(x) && !Double.isNaN(y)) { if ((Math.abs(x - lastX) > dX)) { //System.out.println("Breakpoint 1: leaving interval"); //in any case, add the interval that we are about to leave to the intervalPath float intervalStartX = 0.0f; float intervalEndX = 0.0f; float intervalStartY = 0.0f; float intervalEndY = 0.0f; float currentX = 0.0f; float currentY = 0.0f; float lastFX = 0.0f; float lastFY = 0.0f; //first set some variables if (orientation == PlotOrientation.VERTICAL) { intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); currentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation); lastFX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); currentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); lastFY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation); } else { intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); currentX = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); lastFX = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation); currentY = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation); lastFY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); }/* w w w . j a v a2 s .c om*/ if ((lowY - highY) < 1) { //System.out.println("Breakpoint 2: setting lastPointInInterval"); lastPointInInterval = false; } //System.out.println("Breakpoint 3: lastPointInInterval: " +lastPointInInterval); if ((lowY < highY)) { intervalCount++; //System.out.println("Breakpoint 4: adding segment to interval path:" ); //System.out.println("xStart" + intervalStartX + ", yStart " + intervalStartY + ", xEnd " + intervalEndX + ", yEnd " + intervalEndY); s.intervalPath.moveTo(intervalStartX, intervalStartY); s.intervalPath.lineTo(intervalEndX, intervalEndY); lastIntervalDone = true; } //now the series path currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY) && (y <= highestVisibleY)); if (!lastPointGood) {//last point not valid -- badPoints++; if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position s.seriesPath.moveTo(currentX, currentY); } } else {//last point valid //if the last point was visible and not part of an interval, //we have already moved the seriesPath cursor to the last point, either with or without drawingh a line //thus we only need to draw a line to the current position if (lastPointVisible && !lastPointInInterval) { s.seriesPath.lineTo(currentX, currentY); } //if the last point was not visible or part of an interval, we have just stored the y values of the last point //and not yet moved the seriesPath cursor. Thus, we need to move the cursor to the last point without drawing //and draw a line to the current position. else { s.seriesPath.moveTo(lastFX, lastFY); s.seriesPath.lineTo(currentX, currentY); } } lastPointVisible = currentPointVisible; lastX = x; lastY = y; highY = y; lowY = y; closeY = y; lastPointInInterval = false; } else { lastIntervalDone = false; lastPointInInterval = true; highY = Math.max(highY, y); lowY = Math.min(lowY, y); closeY = y; } lastPointGood = true; } else { lastPointGood = false; } } // if this is the last item, draw the path ... // draw path, but first check whether we need to complete an interval if (!lastIntervalDone) { if (lowY < highY) { float intervalStartX = 0.0f; float intervalEndX = 0.0f; float intervalStartY = 0.0f; float intervalEndY = 0.0f; if (orientation == PlotOrientation.VERTICAL) { intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); } else { intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); } intervalCount++; s.intervalPath.moveTo(intervalStartX, intervalStartY); s.intervalPath.lineTo(intervalEndX, intervalEndY); } } PathIterator pi = s.seriesPath.getPathIterator(null); g2.setStroke(getItemStroke(series, 0)); g2.setPaint(getItemPaint(series, 0)); g2.draw(s.seriesPath); g2.draw(s.intervalPath); //System.out.println("Interval count " + intervalCount); //System.out.println("Bad points " + badPoints); }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.renderer.HierarchicalBarRenderer.java
/** * Draws the bar for one item in the dataset. * * @param g2/*from w ww . ja v a2s .com*/ * the graphics device. * @param state * the renderer state. * @param dataArea * the plot area. * @param plot * the plot. * @param domainAxis * the domain (category) axis. * @param rangeAxis * the range (value) axis. * @param data * the data. * @param row * the row index (zero-based). * @param column * the column index (zero-based). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset data, int row, int column, int pass) { // nothing is drawn for null values... Number dataValue = data.getValue(row, column); if (dataValue == null) { return; } // BAR X double rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0); int seriesCount = this.getRowCount(); // BAR Y double value = dataValue.doubleValue(); double base = 0.0; double lclip = this.getLowerClip(); double uclip = this.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 = this.getLowerClip(); if (value >= uclip) { value = uclip; } } RectangleEdge edge = plot.getRangeAxisEdge(); double transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); double transY2 = rangeAxis.valueToJava2D(value, dataArea, edge); double rectY = Math.min(transY2, transY1); double rectWidth = state.getBarWidth(); double rectHeight = Math.abs(transY2 - transY1); // draw the bar... double shift = 0.0; rectWidth = 0.0; double widthFactor = 1.0; double seriesBarWidth = this.getSeriesBarWidth(row); if (!Double.isNaN(seriesBarWidth)) { widthFactor = seriesBarWidth; } rectWidth = widthFactor * state.getBarWidth(); rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0); if (seriesCount > 1) { // needs to be improved !!! shift = (rectWidth * 0.20) / (seriesCount - 1); } Rectangle2D bar = new Rectangle2D.Double((rectX + ((seriesCount - 1 - row) * shift)), rectY, (rectWidth - ((seriesCount - 1 - row) * shift * 2)), rectHeight); double rrX; double rrY; double rrW; double rrH; if (row == 0) { @SuppressWarnings("unchecked") Iterator it = this.datasetTree[column].getDescendants(); int numElement = -1; while (it.hasNext()) { try { Element elt = (Element) it.next(); numElement++; String name = elt.getAttributeValue("name"); dataValue = Double.valueOf(elt.getAttributeValue("avg")); // System.out.println("["+column+"] "+name+" \t--> // "+dataValue); // BAR X rectX = domainAxis.getCategoryMiddle(column, this.getColumnCount(), dataArea, plot.getDomainAxisEdge()) - (state.getBarWidth() / 2.0); seriesCount = this.getRowCount(); // BAR Y value = dataValue.doubleValue(); base = 0.0; lclip = this.getLowerClip(); uclip = this.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 = this.getLowerClip(); if (value >= uclip) { value = uclip; } } edge = plot.getRangeAxisEdge(); transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); transY2 = rangeAxis.valueToJava2D(value, dataArea, edge); rectY = Math.min(transY2, transY1); rectWidth = state.getBarWidth(); rectHeight = Math.abs(transY2 - transY1); // draw the bar... shift = 0.0; rectWidth = 0.0; widthFactor = 1.0; seriesBarWidth = this.getSeriesBarWidth(row); if (!Double.isNaN(seriesBarWidth)) { widthFactor = seriesBarWidth; } rectWidth = widthFactor * state.getBarWidth(); rectX = rectX + (((1 - widthFactor) * state.getBarWidth()) / 2.0); if (seriesCount > 1) { // needs to be improved !!! shift = (rectWidth * 0.20) / (seriesCount - 1); } rrX = (rectX + ((seriesCount - 1 - row) * shift)); rrY = rectY; rrW = (rectWidth - ((seriesCount - 1 - row) * shift * 2)); rrH = rectHeight; // IMPORTANT NOTE : // dev attribute is used to save width of the element // min attribute is used to save X position of the element // max attribute is used to save the number of child already // managed if (numElement == 0) { elt.setAttribute("dev", "" + rrW); elt.setAttribute("min", "" + rrX); elt.setAttribute("max", "0"); } else { Element parent = elt.getParentElement(); // System.out.println(" Parent // "+parent.getAttributeValue("name") // + " rrX/rrW/child -> " // + parent.getAttributeValue("min")+"/" // + parent.getAttributeValue("dev")+"/" // + parent.getAttributeValue("max") ); double pW = Double.valueOf(parent.getAttributeValue("dev")); double pX = Double.valueOf(parent.getAttributeValue("min")); int numChild = Integer.valueOf(parent.getAttributeValue("max")); rrW = pW / parent.getChildren().size(); rrX = pX + (rrW * numChild); rrX += HierarchicalBarRenderer.INCLUSION_MARGIN; rrW -= (HierarchicalBarRenderer.INCLUSION_MARGIN * 2); elt.setAttribute("dev", "" + rrW); elt.setAttribute("min", "" + rrX); parent.setAttribute("max", "" + (numChild + 1)); } RoundRectangle2D rbar = new RoundRectangle2D.Double(rrX, rrY, rrW, rrH, HierarchicalBarRenderer.CORNER, HierarchicalBarRenderer.CORNER); Rectangle2D childSumLine = null; double childSum = Double.valueOf(elt.getAttributeValue("sum")); transY1 = rangeAxis.valueToJava2D(base, dataArea, edge); transY2 = rangeAxis.valueToJava2D(childSum, dataArea, edge); rectY = Math.min(transY2, transY1); childSum = (childSum / dataValue.doubleValue()) * rrH; if ((childSum < rrH) && (childSum > 0) && ((childSum / rrH) < 0.95)) { childSumLine = new Rectangle2D.Double(rrX, rectY, rrW, 1); } Paint itemPaint = this.getItemPaintFromName(name, this.series, column); GradientPaintTransformer t = this.getGradientPaintTransformer(); if ((t != null) && itemPaint instanceof GradientPaint) { itemPaint = t.transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); Color c = g2.getColor(); g2.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), this.alpha)); g2.fill(rbar); g2.setColor(Color.DARK_GRAY); if (childSumLine != null) { g2.fill(childSumLine); } // draw the outline... if (this.isDrawBarOutline() && (state.getBarWidth() > BarRenderer.BAR_OUTLINE_WIDTH_THRESHOLD)) { Stroke stroke = this.getItemOutlineStroke(row, column); Paint paint = this.getItemOutlinePaint(row, column); if ((stroke != null) && (paint != null)) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(rbar); } } } catch (ClassCastException e) { continue; } } } // //////////////////////////// // draw the item labels if there are any... double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge); double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge); CategoryItemLabelGenerator generator = this.getItemLabelGenerator(row, column); if ((generator != null) && this.isItemLabelVisible(row, column)) { this.drawItemLabel(g2, data, row, column, plot, generator, bar, (transX1 > transX2)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = this.getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(data, row, column); } String url = null; if (this.getItemURLGenerator(row, column) != null) { url = this.getItemURLGenerator(row, column).generateURL(data, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, data, row, data.getColumnKey(column), column); entities.add(entity); } } }
From source file:org.earthtime.UPb_Redux.dateInterpretation.WeightedMeanGraphPanel.java
/** * * @param g2d// w w w . j a v a 2s. com */ public void paint(Graphics2D g2d) { // setup painting parameters String fractionSortOrder = "name"; //random, weight, date if (getWeightedMeanOptions().containsKey("fractionSortOrder")) { fractionSortOrder = getWeightedMeanOptions().get("fractionSortOrder"); } double rangeX = (getMaxX_Display() - getMinX_Display()); double rangeY = (getMaxY_Display() - getMinY_Display()); g2d.setClip(getLeftMargin(), getTopMargin(), getGraphWidth(), getGraphHeight()); RenderingHints rh = g2d.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); // walk the sampleDateInterpretations and produce graphs g2d.setPaint(Color.BLACK); g2d.setStroke(new BasicStroke(2.0f)); g2d.setFont(new Font("SansSerif", Font.BOLD, 10)); double barWidth = 15.0; double barGap = 10.0; double startSamX = 10.0; double saveStartSamX = 0.0; double samSpace = 3.0; for (int i = 0; i < selectedSampleDateModels.length; i++) { for (int j = 1; j < 9; j++) { if (selectedSampleDateModels[i][j] instanceof SampleDateModel) { final SampleDateModel SAM = ((SampleDateModel) selectedSampleDateModels[i][j]); double wMean = SAM.getValue().movePointLeft(6).doubleValue(); double wMeanOneSigma = SAM.getOneSigmaAbs().movePointLeft(6).doubleValue(); Path2D mean = new Path2D.Double(Path2D.WIND_NON_ZERO); // july 2008 // modified to show de-selected fractions as gray // this means a new special list of fractionIDs is created fromall non-rejected fractions // and each instance is tested for being included // should eventually refactor Vector<String> allFIDs = new Vector<String>(); for (String f : ((UPbReduxAliquot) SAM.getAliquot()).getAliquotFractionIDs()) { // test added for Sample-based wm if (SAM.fractionDateIsPositive(// ((UPbReduxAliquot) SAM.getAliquot()).getAliquotFractionByName(f))) { allFIDs.add(f); } } final int iFinal = i; if (fractionSortOrder.equalsIgnoreCase("weight")) { Collections.sort(allFIDs, new Comparator<String>() { public int compare(String fID1, String fID2) { double invertOneSigmaF1 = // 1.0 // / ((UPbReduxAliquot) selectedSampleDateModels[iFinal][0])// .getAliquotFractionByName(fID1)// .getRadiogenicIsotopeDateByName(SAM.getDateName())// .getOneSigmaAbs().movePointLeft(6).doubleValue(); double invertOneSigmaF2 = // 1.0 // / ((UPbReduxAliquot) selectedSampleDateModels[iFinal][0])// .getAliquotFractionByName(fID2)// .getRadiogenicIsotopeDateByName(SAM.getDateName())// .getOneSigmaAbs().movePointLeft(6).doubleValue(); return Double.compare(invertOneSigmaF2, invertOneSigmaF1); } }); } else if (fractionSortOrder.equalsIgnoreCase("date")) { Collections.sort(allFIDs, new Comparator<String>() { public int compare(String fID1, String fID2) { double dateF1 = // ((UPbReduxAliquot) selectedSampleDateModels[iFinal][0])// .getAliquotFractionByName(fID1)// .getRadiogenicIsotopeDateByName(SAM.getDateName())// .getValue().doubleValue(); double dateF2 = // ((UPbReduxAliquot) selectedSampleDateModels[iFinal][0])// .getAliquotFractionByName(fID2)// .getRadiogenicIsotopeDateByName(SAM.getDateName())// .getValue().doubleValue(); return Double.compare(dateF1, dateF2); } }); } else if ( /* ! isInRandomMode() &&*/fractionSortOrder.equalsIgnoreCase("random")) { Collections.shuffle(allFIDs, new Random()); } else if (fractionSortOrder.equalsIgnoreCase("name")) { // default to alphabetic by name //Collections.sort(allFIDs); // april 2010 give same lexigraphic ordering that UPbFractions get Collections.sort(allFIDs, new IntuitiveStringComparator<String>()); } else { // do nothing } double actualWidthX = (allFIDs.size()) * (barWidth + barGap);//; + barGap; // plot 2-sigma of mean mean.moveTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean + 2.0 * wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight)); mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean + 2.0 * wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight)); mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean - 2.0 * wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight)); mean.lineTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean - 2.0 * wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight)); mean.closePath(); g2d.setColor(ReduxConstants.mySampleYellowColor); g2d.fill(mean); g2d.setPaint(Color.BLACK); // plot 1-sigma of mean mean.reset(); mean.moveTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean + wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight)); mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean + wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight)); mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean - wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight)); mean.lineTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean - wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight)); mean.closePath(); g2d.setColor(ReduxConstants.ColorOfRedux); g2d.fill(mean); g2d.setPaint(Color.BLACK); // plot mean mean.reset(); mean.moveTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean, getMaxY_Display(), rangeY, graphHeight)); mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(wMean, getMaxY_Display(), rangeY, graphHeight)); g2d.setStroke(new BasicStroke(1.0f)); g2d.draw(mean); g2d.setStroke(new BasicStroke(2.0f)); saveStartSamX = startSamX; // plot fraction bars double minPoint = 5000.0; double maxWeight = 0.0; double totalWeight = 0.0; int barNum = 0; for (String fID : allFIDs) { // the dateModel has an associated aliquot, but in sample mode, it is a // standin aliquot for the sample. to get the aliquot number for // use in coloring fractions, we need to query the fraction itself String aliquotName = sample.getAliquotNameByFractionID(fID); Color includedFillColor = new Color(0, 0, 0); if (sample.getSampleDateInterpretationGUISettings().getAliquotOptions().get(aliquotName) .containsKey("includedFillColor")) { String[] temp = // sample.getSampleDateInterpretationGUISettings().getAliquotOptions() .get(aliquotName).get("includedFillColor").split(","); includedFillColor = buildRGBColor(temp); } Fraction f = ((UPbReduxAliquot) selectedSampleDateModels[i][0]) .getAliquotFractionByName(fID); double date = f.//((UPbReduxAliquot) selectedSampleDateModels[i][0]).getAliquotFractionByName(fID).// getRadiogenicIsotopeDateByName(SAM.getDateName()).getValue().movePointLeft(6) .doubleValue(); double twoSigma = f.//((UPbReduxAliquot) selectedSampleDateModels[i][0]).getAliquotFractionByName(fID).// getRadiogenicIsotopeDateByName(SAM.getDateName()).getTwoSigmaAbs().movePointLeft(6) .doubleValue(); if ((date - twoSigma) < minPoint) { minPoint = (date - twoSigma); } double invertedOneSigma = // 1.0 // / f.//((UPbReduxAliquot) selectedSampleDateModels[i][0]).getAliquotFractionByName(fID).// getRadiogenicIsotopeDateByName(SAM.getDateName()).getOneSigmaAbs() .movePointLeft(6).doubleValue(); if (invertedOneSigma > maxWeight) { maxWeight = invertedOneSigma; } Path2D bar = new Path2D.Double(Path2D.WIND_NON_ZERO); bar.moveTo( (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)), getMinX_Display(), rangeX, graphWidth), (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight)); bar.lineTo( (float) mapX( saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)) + barWidth, getMinX_Display(), rangeX, graphWidth), (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight)); bar.lineTo( (float) mapX( saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)) + barWidth, getMinX_Display(), rangeX, graphWidth), (float) mapY(date - twoSigma, getMaxY_Display(), rangeY, graphHeight)); bar.lineTo( (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)), getMinX_Display(), rangeX, graphWidth), (float) mapY(date - twoSigma, getMaxY_Display(), rangeY, graphHeight)); bar.closePath(); Composite originalComposite = g2d.getComposite(); if (SAM.getIncludedFractionIDsVector().contains(fID)) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); totalWeight += Math.pow(invertedOneSigma, 2.0); // april 2014 experiment if (f.getRgbColor() != 0) { includedFillColor = new Color(f.getRgbColor()); } } else { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f)); } g2d.setPaint(includedFillColor); g2d.draw(bar); //restore composite g2d.setComposite(originalComposite); g2d.setColor(Color.black); // label fraction at top g2d.rotate(-Math.PI / 4.0, (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)), getMinX_Display(), rangeX, graphWidth), (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight)); g2d.drawString( ((UPbReduxAliquot) selectedSampleDateModels[i][0]).getAliquotFractionByName(fID) .getFractionID(), (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)), getMinX_Display(), rangeX, graphWidth) + 15, (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight)); g2d.rotate(Math.PI / 4.0, (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)), getMinX_Display(), rangeX, graphWidth), (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight)); barNum++; // startSamX += 2 * barWidth; startSamX += barWidth + barGap; } // display three info boxes below weighted means // each tic is the height of one calculated y-axis tic // determine the y axis tic double minYtic = Math.ceil(getMinY_Display() * 100) / 100; double maxYtic = Math.floor(getMaxY_Display() * 100) / 100; double deltay = Math.rint((maxYtic - minYtic) * 10 + 0.5); double yTic = deltay / 100; double yTopSummary = minPoint - yTic / 2.0;// wMeanOneSigma; //double specialYTic = yTic; double yTopWeights = yTopSummary - yTic * 1.1; double yTopMSWD_PDF = yTopWeights - yTic * 1.1; // summary box Path2D box = new Path2D.Double(Path2D.WIND_NON_ZERO); box.moveTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopSummary - yTic, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopSummary - yTic, getMaxY_Display(), rangeY, graphHeight)); box.closePath(); g2d.setStroke(new BasicStroke(1.5f)); g2d.draw(box); // Info Box g2d.drawString(// SAM.getAliquot().getAliquotName(), (float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f, (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight) + 13f); g2d.drawString(// SAM.getName(), (float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f, (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight) + 25f); g2d.drawString(// SAM.FormatValueAndTwoSigmaABSThreeWaysForPublication(6, 2), (float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f, (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight) + 36f); g2d.drawString(// SAM.ShowCustomMSWDwithN(), (float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f, (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight) + 48f); // weights box box.reset(); box.moveTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopWeights, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopWeights, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopWeights - yTic, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopWeights - yTic, getMaxY_Display(), rangeY, graphHeight)); box.closePath(); g2d.setStroke(new BasicStroke(1.5f)); g2d.draw(box); // plot fraction weights double artificialXRange = allFIDs.size(); double count = 0; //double weightWidth = Math.min(3.0 * barWidth, (yTic / rangeY * graphHeight)) - 15;//yTic;//barWidth * 2.0; double weightWidth = (barWidth + barGap) * 0.9; for (String fID : allFIDs) { // the dateModel has an associated aliquot, but in sample mode, it is a // standin aliquot for the sample. to get the aliquot number for // use in coloring fractions, we need to query the fraction itself String aliquotName = sample.getAliquotNameByFractionID(fID); Fraction f = ((UPbReduxAliquot) selectedSampleDateModels[i][0]) .getAliquotFractionByName(fID); Color includedFillColor = new Color(0, 0, 0); if (sample.getSampleDateInterpretationGUISettings().getAliquotOptions().get(aliquotName) .containsKey("includedFillColor")) { String[] temp = // sample.getSampleDateInterpretationGUISettings().getAliquotOptions() .get(aliquotName).get("includedFillColor").split(","); includedFillColor = buildRGBColor(temp); } double invertOneSigma = // 1.0 // / ((UPbReduxAliquot) selectedSampleDateModels[i][0]) .getAliquotFractionByName(fID)// .getRadiogenicIsotopeDateByName(SAM.getDateName()).getOneSigmaAbs() .movePointLeft(6).doubleValue(); Path2D weight = new Path2D.Double(Path2D.WIND_NON_ZERO); weight.moveTo( (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX, getMinX_Display(), rangeX, graphWidth) // - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth), (float) mapY(yTopWeights - (yTic / 2.0), getMaxY_Display(), rangeY, graphHeight) // + (float) (invertOneSigma / maxWeight / 2.0 * weightWidth) - 5f); weight.lineTo( (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX, getMinX_Display(), rangeX, graphWidth) // + (float) (invertOneSigma / maxWeight / 2.0 * weightWidth), (float) mapY(yTopWeights - (yTic / 2.0), getMaxY_Display(), rangeY, graphHeight) // + (float) (invertOneSigma / maxWeight / 2.0 * weightWidth) - 5f); weight.lineTo( (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX, getMinX_Display(), rangeX, graphWidth) // + (float) (invertOneSigma / maxWeight / 2.0 * weightWidth), (float) mapY(yTopWeights - (yTic / 2.0), getMaxY_Display(), rangeY, graphHeight) // - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth) - 5f); weight.lineTo( (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX, getMinX_Display(), rangeX, graphWidth) // - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth), (float) mapY(yTopWeights - (yTic / 2.0), getMaxY_Display(), rangeY, graphHeight) // - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth) - 5f); weight.closePath(); g2d.setStroke(new BasicStroke(2.5f)); // test for included or not == black or gray String weightPerCent = " 0";//0.0%"; // g2d.setPaint(includedFillColor); Composite originalComposite = g2d.getComposite(); if (SAM.getIncludedFractionIDsVector().contains(fID)) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); weightPerCent = formatter1DecPlace .format(Math.pow(invertOneSigma, 2.0) / totalWeight * 100.0);// + "%"; // april 2014 experiment if (f.getRgbColor() != 0) { includedFillColor = new Color(f.getRgbColor()); } } else { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f)); } g2d.setPaint(includedFillColor); g2d.fill(weight); //restore composite g2d.setComposite(originalComposite); // write percent of total weight g2d.drawString(weightPerCent, (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX, getMinX_Display(), rangeX, graphWidth) // - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth), (float) mapY(yTopWeights - yTic, getMaxY_Display(), rangeY, graphHeight) - 5f); g2d.setColor(Color.black); count += 1.0; } // double box height for graph yTic *= 2.0; // plot MSWD_PDF // store function x,y values Vector<Double> xVals = new Vector<Double>(); Vector<Double> yVals = new Vector<Double>(); double f = SAM.getIncludedFractionIDsVector().size() - 1; if (f > 1.0) { g2d.setStroke(new BasicStroke(1.0f)); double yRange = MSWDCoordinates.valuesByPointCount[(int) f][5] * 1.03; // alitle air at the top of curve double xStart = MSWDCoordinates.valuesByPointCount[(int) f][1]; double xRange = MSWDCoordinates.valuesByPointCount[(int) f][4] - xStart; double xStep = 0.005; Path2D MSWD_PDF = new Path2D.Double(Path2D.WIND_NON_ZERO); Path2D MSWD_right = new Path2D.Double(Path2D.WIND_NON_ZERO); // start at lower left corner of box (may or may not be 0,0 ) MSWD_PDF.moveTo(// (float) mapX((double) saveStartSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); // setup MSWD to paint last Path2D MSWD = null; // calculate function values for (double x = xStart; x < xRange; x += xStep) { xVals.add((((x - xStart) / xRange) * actualWidthX) + (double) saveStartSamX); double y = // Math.pow(2, -1.0 * f / 2.0)// * Math.exp(-1.0 * f * x / 2.0)// * Math.pow(f, f / 2.0)// * Math.pow(x, (-1.0 + f / 2.0))// / Math.exp(Gamma.logGamma(f / 2.0)); yVals.add(((y / yRange) * yTic) + yTopMSWD_PDF - yTic); MSWD_PDF.lineTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight)); // test for location of left RED zone if ((MSWDCoordinates.valuesByPointCount[(int) f][2] >= x) && (MSWDCoordinates.valuesByPointCount[(int) f][2] < (x + xStep))) { double leftX = MSWDCoordinates.valuesByPointCount[(int) f][2]; xVals.add((((leftX - xStart) / xRange) * actualWidthX) + (double) saveStartSamX); double leftY = // Math.pow(2, -1.0 * f / 2.0)// * Math.exp(-1.0 * f * leftX / 2.0)// * Math.pow(f, f / 2.0)// * Math.pow(leftX, (-1.0 + f / 2.0))// / Math.exp(Gamma.logGamma(f / 2.0)); yVals.add(((leftY / yRange) * yTic) + yTopMSWD_PDF - yTic); MSWD_PDF.lineTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight)); Path2D ciLower = new Path2D.Double(Path2D.WIND_NON_ZERO); ciLower.append(MSWD_PDF.getPathIterator(new AffineTransform()), true); ciLower.lineTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); ciLower.closePath(); g2d.setColor(Color.RED); g2d.fill(ciLower); // draw right hand border line to compensate for a bug in the filler Line2D right = new Line2D.Double(// mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight), mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); g2d.setStroke(new BasicStroke(0.5f)); g2d.draw(right); g2d.setStroke(new BasicStroke(1.0f)); g2d.setColor(Color.BLACK); System.out.println("Left Red = (" + leftX + ", " + leftY + ")"); } // test for location of right RED zone if ((MSWDCoordinates.valuesByPointCount[(int) f][3] >= x) && (MSWDCoordinates.valuesByPointCount[(int) f][3] < (x + xStep))) { double rightX = MSWDCoordinates.valuesByPointCount[(int) f][3]; xVals.add((((rightX - xStart) / xRange) * actualWidthX) + (double) saveStartSamX); double rightY = // Math.pow(2, -1.0 * f / 2.0)// * Math.exp(-1.0 * f * rightX / 2.0)// * Math.pow(f, f / 2.0)// * Math.pow(rightX, (-1.0 + f / 2.0))// / Math.exp(Gamma.logGamma(f / 2.0)); yVals.add(((rightY / yRange) * yTic) + yTopMSWD_PDF - yTic); MSWD_PDF.lineTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight)); // here the strategy is to draw the curve and then reset it to record the remainder g2d.setStroke(new BasicStroke(1.0f)); g2d.draw(MSWD_PDF); MSWD_PDF = new Path2D.Double(Path2D.WIND_NON_ZERO); MSWD_PDF.moveTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight)); MSWD_right.moveTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); MSWD_right.lineTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight)); System.out.println("Right Red = (" + rightX + ", " + rightY + ")"); } // test for location of MSWD AND paint last if ((SAM.getMeanSquaredWeightedDeviation().doubleValue() >= x) && (SAM.getMeanSquaredWeightedDeviation().doubleValue() < (x + xStep))) { MSWD = new Path2D.Double(Path2D.WIND_NON_ZERO); MSWD.moveTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); MSWD.lineTo(// (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth), (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight)); } } g2d.setStroke(new BasicStroke(1.0f)); // merge with border of right RED and fill MSWD_right.append(MSWD_PDF.getPathIterator(new AffineTransform()), true); g2d.setColor(Color.RED); g2d.fill(MSWD_right); g2d.setColor(Color.BLACK); // draw the remaining curves g2d.draw(MSWD_PDF); // MSWD may be off the graph and hence not exist try { g2d.draw(MSWD); } catch (Exception e) { } // label 95% conf interval and MSWD g2d.drawString(// "95% CI: (" + formatter2DecPlaces.format(MSWDCoordinates.valuesByPointCount[(int) f][2]) + ", " + formatter2DecPlaces.format(MSWDCoordinates.valuesByPointCount[(int) f][3]) + ")", (float) mapX(saveStartSamX + (actualWidthX / 2.0), getMinX_Display(), rangeX, graphWidth) - 30f, (float) mapY(yTopMSWD_PDF, getMaxY_Display(), rangeY, graphHeight) + 15f); // determine if MSWD is out of range String mswdAlert = ""; if (SAM.getMeanSquaredWeightedDeviation() .doubleValue() > MSWDCoordinates.valuesByPointCount[(int) f][4]) { mswdAlert = "\n !Out of Range!"; } g2d.drawString(// "MSWD = " + formatter2DecPlaces .format(SAM.getMeanSquaredWeightedDeviation().doubleValue()) + ", n = " + (int) (f + 1) + mswdAlert, (float) mapX(saveStartSamX + (actualWidthX / 2.0), getMinX_Display(), rangeX, graphWidth) - 15f, (float) mapY(yTopMSWD_PDF, getMaxY_Display(), rangeY, graphHeight) + 30f); } else { g2d.drawString("need more data...", (float) mapX((double) saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f, (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight) - 10f); } // MSWD_PDF box box.reset(); box.moveTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); box.lineTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); box.closePath(); g2d.setStroke(new BasicStroke(1.5f)); g2d.draw(box); // MSWD_PDF x-axis tics if (f > 1.0) { g2d.setStroke(new BasicStroke(1.0f)); double xStart = (MSWDCoordinates.valuesByPointCount[(int) f][1] <= 0.5) ? 0.5 : 1.0; double xRange = MSWDCoordinates.valuesByPointCount[(int) f][4] - MSWDCoordinates.valuesByPointCount[(int) f][1]; double xStep = 0.5; for (double x = xStart; x < xRange; x += xStep) { double xPlot = (((x - MSWDCoordinates.valuesByPointCount[(int) f][1]) / xRange) * actualWidthX) + (double) saveStartSamX; Line2D line = new Line2D.Double(mapX(xPlot, getMinX_Display(), rangeX, graphWidth), mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight), mapX(xPlot, getMinX_Display(), rangeX, graphWidth), mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight) + 7); g2d.draw(line); g2d.rotate(-Math.PI / 2.0, (float) mapX(xPlot, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); g2d.drawString(formatter1DecPlace.format(x), (float) mapX(xPlot, getMinX_Display(), rangeX, graphWidth) - 30f, (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight) + 5f); g2d.rotate(Math.PI / 2.0, (float) mapX(xPlot, getMinX_Display(), rangeX, graphWidth), (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight)); } } // set counters barNum += samSpace; startSamX += 2 * samSpace * barWidth; } } } // // prevents re-randomization // setInRandomMode( true ); drawAxesAndTicks(g2d, rangeX, rangeY); // draw zoom box if in use if ((Math.abs(zoomMaxX - zoomMinX) * Math.abs(zoomMinY - zoomMaxY)) > 0.0) { g2d.setStroke(new BasicStroke(2.0f)); g2d.setColor(Color.red); g2d.drawRect(// Math.min(zoomMinX, zoomMaxX), Math.min(zoomMaxY, zoomMinY), Math.abs(zoomMaxX - zoomMinX), Math.abs(zoomMinY - zoomMaxY)); } }
From source file:com.aurel.track.report.gantt.data.TrackGanttRenderer.java
/** * Draws a single task.//from www . j av a 2 s . com * * @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 drawTask(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, TrackTaskSeriesCollection dataset, int row, int column, int pass) { log.debug("Working on item at position - column: " + column + " row: " + row); int seriesCount = getRowCount(); int categoryCount = getColumnCount(); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); // Y0 Number value0 = dataset.getEndValue(row, column); if (value0 == null) { return; } double java2dValue0 = rangeAxis.valueToJava2D(value0.doubleValue(), dataArea, rangeAxisLocation); // Y1 Number value1 = dataset.getStartValue(row, column); if (value1 == null) { return; } double java2dValue1 = rangeAxis.valueToJava2D(value1.doubleValue(), dataArea, rangeAxisLocation); if (java2dValue1 < java2dValue0) { double temp = java2dValue1; java2dValue1 = java2dValue0; java2dValue0 = temp; Number tempNum = value1; value1 = value0; value0 = tempNum; } double rectStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, domainAxisLocation); // BREADTH double rectBreadth = state.getBarWidth(); // BAR HEIGHT double rectLength = Math.abs(java2dValue1 - java2dValue0); Rectangle2D bar = null; if (seriesCount > 1) { double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectStart = rectStart + row * (state.getBarWidth() + seriesGap); } else { rectStart = rectStart + row * state.getBarWidth(); } // correct the start/stop Bars point if (startBars > (int) (java2dValue1 - rectLength)) { this.startBars = (int) (java2dValue1 - rectLength); } if (stopBars < (int) java2dValue1) { stopBars = (int) java2dValue1; } // The coordinates for the bar labels int startLabelX = 0; int startLabelY = 0; int endLabelX = 0; int endLabelY = 0; int barLabelX = 0; int barLabelY = 0; Polygon outer = null; Polygon inner = null; boolean isMilestone = dataset.isMilestone(column, row); boolean isSupertask = dataset.isSupertask(column, row); if (isMilestone) { // The start point for the end date label endLabelX = (int) (java2dValue1 + rectBreadth / 2); endLabelY = (int) (rectStart + (3 * rectBreadth / 4)); barLabelX = (int) (java2dValue1 - rectBreadth / 2); barLabelY = (int) (rectStart + (3 * rectBreadth / 4)); int breadth = (int) rectBreadth; int centerX = (int) java2dValue1; int centerY = (int) (rectStart + rectBreadth / 2); int[] xPoints = { centerX, centerX - breadth / 2, centerX, centerX + breadth / 2 }; int[] yPoints = { centerY - breadth / 2, centerY, centerY + breadth / 2, centerY }; outer = new Polygon(xPoints, yPoints, 4); //calculate the difference from the ratio int diff = (int) (rectBreadth / (2 * msInfo.getRatio())); int[] xPointsI = { centerX, centerX - breadth / 2 + diff, centerX, centerX + breadth / 2 - diff }; int[] yPointsI = { centerY - breadth / 2 + diff, centerY, centerY + breadth / 2 - diff, centerY }; inner = new Polygon(xPointsI, yPointsI, 4); } else if (isSupertask) { // The start point for the end date label startLabelX = (int) (java2dValue1 - rectLength - rectBreadth / 2); startLabelY = (int) (rectStart + rectBreadth * 3 / 4); endLabelX = (int) (java2dValue1 + rectBreadth / 2); endLabelY = (int) (rectStart + rectBreadth * 3 / 4); barLabelX = (int) (java2dValue1 - rectLength + rectBreadth / 3); barLabelY = (int) (rectStart + rectBreadth); int breadth = (int) rectBreadth; int length = (int) rectLength; int startX = (int) (java2dValue1 - rectLength); int startY = (int) rectStart; int[] xPoints = { startX - breadth / 2, startX + length + breadth / 2, startX + length + breadth / 2, startX + length, startX + length - breadth / 2, startX + breadth / 2, startX, startX - breadth / 2 }; int[] yPoints = { startY, startY, startY + breadth / 2, startY + breadth, startY + breadth / 2, startY + breadth / 2, startY + breadth, startY + breadth / 2 }; outer = new Polygon(xPoints, yPoints, 8); //calculate the difference from the ratio int diff = (int) (rectBreadth / (2 * stInfo.getRatio())); int[] xPointsI = { startX - breadth / 2 + diff, startX + length + breadth / 2 - diff, startX + length + breadth / 2 - diff, startX + length, startX + length - breadth / 2 + diff, startX + length - breadth / 2 + diff, startX + breadth / 2 - diff, startX + breadth / 2 - diff, startX, startX - breadth / 2 + diff }; int[] yPointsI = { startY + diff, startY + diff, startY + breadth / 2, startY + breadth / 2 + diff, startY + breadth / 2, startY + breadth / 2 - diff, startY + breadth / 2 - diff, startY + breadth / 2, startY + breadth / 2 + diff, startY + breadth / 2 }; inner = new Polygon(xPointsI, yPointsI, 10); } else { rectBreadth = rectBreadth / 2.0; // The start point for the end date label startLabelX = (int) (java2dValue1 - rectLength); startLabelY = (int) (rectStart + rectBreadth * 3 / 4); endLabelX = (int) java2dValue1; endLabelY = (int) (rectStart + rectBreadth * 3 / 4); barLabelX = (int) (java2dValue1 - rectLength); barLabelY = (int) (rectStart); //+ rectBreadth * 4 / 3 ); bar = new Rectangle2D.Double(java2dValue0, rectStart, rectLength, rectBreadth); // percent complete could be obtained in the // ReportBeans, set in the ReportBean and set in the Item by the GanttGenerator // currently this is not relevant. Rectangle2D completeBar = null; Rectangle2D incompleteBar = null; Number percent = dataset.getPercentComplete(row, column); double start = getStartPercent(); double end = getEndPercent(); if (percent != null) { double p = percent.doubleValue(); completeBar = new Rectangle2D.Double(java2dValue0, rectStart + start * rectBreadth, rectLength * p, rectBreadth * (end - start)); incompleteBar = new Rectangle2D.Double(java2dValue0 + rectLength * p, rectStart + start * rectBreadth, rectLength * (1 - p), rectBreadth * (end - start)); } /** This is for displaying e.g. (german Soll und Ist Termine). This implementation is designed to display only one Series. * If you need Soll und Ist, you can generate two gantt charts. * --->> Paint seriesPaint = getItemPaint (row, column); */ Paint seriesPaint = tsInfo.getInnerColor(); g2.setPaint(seriesPaint); g2.fill(bar); if (tsInfo.isDisplayIDLabel() && (!tsInfo.isDisplaySynopsis())) { // draw the tasks ID drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, tsInfo.getLabelFontID(), false, (int) rectLength); } else if (tsInfo.isDisplaySynopsis()) { if (tsInfo.isDisplayDateLabel()) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); label = dataset.getItem(column, row).getDescription() + " - " + label; drawLabel(label, g2, barLabelX, barLabelY, tsInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false); } else { drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY, tsInfo.getLabelFont(), true); } } if (tsInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); // draw the tasks start date drawLabel(label, g2, startLabelX, startLabelY, tsInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(tsInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the tasks end date drawLabel(label, g2, endLabelX, endLabelY, tsInfo.getLabelFont(), false); } if (completeBar != null) { g2.setPaint(getCompletePaint()); g2.fill(completeBar); } if (incompleteBar != null) { g2.setPaint(getIncompletePaint()); g2.fill(incompleteBar); } // draw the outline... if (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); } } } // Draw milestone or Supertask if (isMilestone) { g2.setPaint(msInfo.getOuterColor()); g2.fill(outer); g2.draw(outer); g2.setPaint(msInfo.getInnerColor()); g2.fill(inner); g2.draw(inner); Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(outer); } // draw the milestones due date if (msInfo.isDisplayDateLabel()) { // format milestone date to the requested format using the current locale String label = (new SimpleDateFormat(msInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); drawLabel(label, g2, endLabelX, endLabelY, msInfo.getLabelFont(), false); } if (msInfo.isDisplayIDLabel() && (!msInfo.isDisplaySynopsis())) { // for milestones the ID is aligned at the left side. drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, msInfo.getLabelFontID(), true, (int) rectLength); } else if (msInfo.isDisplaySynopsis()) { drawLabel(dataset.getItem(column, row).getDescription(), g2, barLabelX, barLabelY, msInfo.getLabelFont(), true, (int) rectLength); } } else if (isSupertask) { g2.setPaint(stInfo.getOuterColor()); g2.fill(outer); g2.draw(outer); g2.setPaint(stInfo.getInnerColor()); g2.fill(inner); g2.draw(inner); Stroke stroke = getItemOutlineStroke(row, column); Paint paint = getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(outer); } // draw the supertasks ID if (stInfo.isDisplayIDLabel() && (!stInfo.isDisplaySynopsis())) { drawLabel(new Integer(dataset.getItem(column, row).getId()).toString(), g2, barLabelX, barLabelY, stInfo.getLabelFontID(), false, (int) rectLength); } else if (stInfo.isDisplaySynopsis()) { if (stInfo.isDisplayDateLabel()) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); label = dataset.getItem(column, row).getDescription() + " - " + label; drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false); } else { drawLabel(dataset.getItem(column, row).getDescription(), g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); } } if (stInfo.isDisplayDateLabel() && (!tsInfo.isDisplaySynopsis())) { // format start date to the requested format using the current locale String label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStart()); // draw the supertasks start date drawLabel(label, g2, startLabelX, startLabelY, stInfo.getLabelFont(), true); // format end date to the requested format using the current locale label = (new SimpleDateFormat(stInfo.getDateLabelFormat(), locale)) .format(dataset.getItem(column, row).getStop()); // draw the supertasks end date drawLabel(label, g2, endLabelX, endLabelY, stInfo.getLabelFont(), false); } } }
From source file:tilt.image.page.Line.java
/** * Draw the line on the image for debugging * @param g the graphics environment to draw in * @param n the number of the line/* w w w. java2 s.co m*/ */ public void draw(Graphics g, int n) { Point p1, p2 = null; for (int i = 0; i < points.size(); i++) { p1 = p2; p2 = points.get(i); if (p1 != null) { int x1 = Math.round(p1.x); int y1 = Math.round(p1.y); int x2 = Math.round(p2.x); int y2 = Math.round(p2.y); if (!rogue) { g.drawLine(x1, y1, x2, y2); } else { Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(3)); g2.draw(new Line2D.Float(x1, y1, x2, y2)); g2.setStroke(new BasicStroke(1)); } } } Rectangle bounds = getPointsBounds(); String num = Integer.toString(n); g.drawString(num, bounds.x - 30, (bounds.y * 2 + bounds.height) / 2); //System.out.println("width of line"+n+": "+bounds.width); }