List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:savant.view.swing.GraphPane.java
@Override protected void paintComponent(Graphics g) { if (tracks != null && tracks.length > 0) { LOG.trace("GraphPane.paintComponent(" + tracks[0].getName() + ")"); }/* ww w. j a v a 2 s.c om*/ super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; boolean trueRender = render(g2); GraphPaneController gpc = GraphPaneController.getInstance(); int h = getHeight(); // Aiming adjustments. if (gpc.isAiming() && mouseInside) { g2.setColor(Color.BLACK); Font thickfont = g2.getFont().deriveFont(Font.BOLD, 15.0F); g2.setFont(thickfont); int genomeX = gpc.getMouseXPosition(); double genomeY = gpc.getMouseYPosition(); String target = ""; target += "X: " + MiscUtils.numToString(genomeX); if (!Double.isNaN(genomeY)) { target += " Y: " + MiscUtils.numToString(genomeY); } g2.drawLine(mouseX, 0, mouseX, h); if (genomeY != -1) { g.drawLine(0, mouseY, this.getWidth(), mouseY); } g2.drawString(target, mouseX + 5, mouseY - 5); } double x1 = transformXPos(gpc.getMouseClickPosition()); double x2 = transformXPos(gpc.getMouseReleasePosition()); double width = x1 - x2; selectionRect = new Rectangle2D.Double(width < 0 ? x1 : x2, 0.0, Math.max(2.0, Math.abs(width)), h); if (gpc.isPanning()) { // Panning adjustments (none). } else if (gpc.isZooming() || gpc.isSelecting()) { // Zooming adjustments. Rectangle2D rectangle = new Rectangle2D.Double(selectionRect.getX(), selectionRect.getY() - 10.0, selectionRect.getWidth(), selectionRect.getHeight() + 10.0); g2.setColor(Color.gray); g2.setStroke( new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 3f, new float[] { 4f }, 4f)); g2.draw(rectangle); if (gpc.isZooming()) { g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_ZOOM_FILL)); } else if (gpc.isSelecting()) { g.setColor(ColourSettings.getColor(ColourKey.GRAPH_PANE_SELECTION_FILL)); } g2.fill(selectionRect); } // Plumbing adjustments. Range xRange = getXRange(); if (gpc.isPlumbing()) { g2.setColor(Color.BLACK); double spos = transformXPos(gpc.getMouseXPosition()); g2.draw(new Line2D.Double(spos, 0, spos, h)); double rpos = transformXPos(gpc.getMouseXPosition() + 1); g2.draw(new Line2D.Double(rpos, 0, rpos, h)); } // Spotlight if (gpc.isSpotlight() && !gpc.isZooming()) { int center = gpc.getMouseXPosition(); int left = center - gpc.getSpotlightSize() / 2; int right = left + gpc.getSpotlightSize(); g2.setColor(new Color(0, 0, 0, 200)); // draw left of spotlight if (left >= xRange.getFrom()) { g2.fill(new Rectangle2D.Double(0.0, 0.0, transformXPos(left), h)); } // draw right of spotlight if (right <= xRange.getTo()) { double pix = transformXPos(right); g2.fill(new Rectangle2D.Double(pix, 0, getWidth() - pix, h)); } } if (isLocked()) { drawMessage((Graphics2D) g, "Locked"); } if (trueRender) { gpc.delistRenderingGraphpane(this); } }
From source file:org.earthtime.UPb_Redux.dateInterpretation.WeightedMeanGraphPanel.java
/** * * @param g2d//www. j ava 2 s .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:org.trade.ui.chart.renderer.PivotRenderer.java
/** * Draws the annotation.//from ww w. ja v a2 s . c o m * * @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:userinterface.graph.PrismErrorRenderer.java
/** * Draws the visual representation for one data item. * * @param g2 the graphics output target. * @param state the renderer state.//from ww w.jav a 2s.co m * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index * @author Muhammad Omer Saeed. */ @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 (!drawError) { super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); return; } switch (currentMethod) { case PrismErrorRenderer.ERRORBARS: if (pass == 0 && dataset instanceof XYSeriesCollection && getItemVisible(series, item)) { synchronized (dataset) { XYSeriesCollection collection = (XYSeriesCollection) dataset; PlotOrientation orientation = plot.getOrientation(); // draw the error bar for the y-interval XYSeries s = collection.getSeries(series); PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item); double y0 = it.getYValue() + it.getError(); double y1 = it.getYValue() - it.getError(); double x = collection.getXValue(series, item); RectangleEdge edge = plot.getRangeAxisEdge(); double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge); double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge); double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); Line2D line; Line2D cap1; Line2D cap2; double adj = this.capLength / 2.0; if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yy0, xx, yy1); cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0); cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1); } else { // PlotOrientation.HORIZONTAL line = new Line2D.Double(yy0, xx, yy1, xx); cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj); cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj); } g2.setPaint(getItemPaint(series, item)); if (this.errorStroke != null) { g2.setStroke(this.errorStroke); } else { g2.setStroke(getItemStroke(series, item)); } g2.draw(line); g2.draw(cap1); g2.draw(cap2); } } super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); break; case PrismErrorRenderer.ERRORDEVIATION: synchronized (dataset) { // do nothing if item is not visible if (!getItemVisible(series, item)) { return; } // first pass draws the shading if (pass == 0) { XYSeriesCollection collection = (XYSeriesCollection) dataset; XYSeries s = collection.getSeries(series); PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item); State drState = (State) state; double x = collection.getXValue(series, item); double yLow = it.getYValue() - it.getError(); double yHigh = it.getYValue() + it.getError(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { drState.lowerCoordinates.add(new double[] { yyLow, xx }); drState.upperCoordinates.add(new double[] { yyHigh, xx }); } else if (orientation == PlotOrientation.VERTICAL) { drState.lowerCoordinates.add(new double[] { xx, yyLow }); drState.upperCoordinates.add(new double[] { xx, yyHigh }); } if (item == (dataset.getItemCount(series) - 1)) { // last item in series, draw the lot... // set up the alpha-transparency... Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) this.alpha)); g2.setPaint(getItemPaint(series, item)); GeneralPath area = new GeneralPath(); double[] coords = (double[]) drState.lowerCoordinates.get(0); area.moveTo((float) coords[0], (float) coords[1]); for (int i = 1; i < drState.lowerCoordinates.size(); i++) { coords = (double[]) drState.lowerCoordinates.get(i); area.lineTo((float) coords[0], (float) coords[1]); } int count = drState.upperCoordinates.size(); coords = (double[]) drState.upperCoordinates.get(count - 1); area.lineTo((float) coords[0], (float) coords[1]); for (int i = count - 2; i >= 0; i--) { coords = (double[]) drState.upperCoordinates.get(i); area.lineTo((float) coords[0], (float) coords[1]); } area.closePath(); g2.fill(area); g2.setComposite(originalComposite); drState.lowerCoordinates.clear(); drState.upperCoordinates.clear(); } } if (isLinePass(pass)) { // the following code handles the line for the y-values...it's // all done by code in the super class if (item == 0) { State s = (State) state; s.seriesPath.reset(); s.setLastPointGood(false); } if (getItemLineVisible(series, item)) { drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis, dataArea); } } // second pass adds shapes where the items are .. else if (isItemPass(pass)) { // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis, crosshairState, entities); } } break; default: return; } }
From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java
/** * Draws an item for a plot with a vertical orientation. * //from w w w .ja v a 2 s.co m * @param g2 the graphics device. * @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 row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawVerticalItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) { // nothing is drawn for null... //ADDED THIS BLOCK, RINKE final Number v = dataset.getValue(row, column); if (v == null) { return; } final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); // BAR X double rectX = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation); final int seriesCount = getRowCount(); final int categoryCount = getColumnCount(); if (seriesCount > 1) { final double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectX = rectX + row * (state.getBarWidth() + seriesGap); } else { rectX = rectX + row * state.getBarWidth(); } // BAR Y final Number meanValue = dataset.getMeanValue(row, column); double value = meanValue.doubleValue(); double base = 0.0; final double lclip = getLowerClip(); final 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; } } final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation); final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation); final double rectY = Math.min(transY2, transY1); final double rectWidth = state.getBarWidth(); final double rectHeight = Math.abs(transY2 - transY1); final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); final Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (state.getBarWidth() > 3) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // standard deviation lines final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset; final Number highValRaw = asymmDataset.getUpperValue(row, column); final Number lowValRaw = asymmDataset.getLowerValue(row, column); // only draw if both error bars items are not null if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation); final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation); if (getErrorIndicatorPaint() != null) { g2.setPaint(getErrorIndicatorPaint()); } else { g2.setPaint(getItemOutlinePaint(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); } final 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 final EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, bar); } }
From source file:nl.strohalm.cyclos.utils.jfreeAsymmetric.AsymmetricStatisticalBarRenderer.java
/** * Draws an item for a plot with a horizontal orientation. * /*from ww w .j a v a 2 s. c om*/ * @param g2 the graphics device. * @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 row the row index (zero-based). * @param column the column index (zero-based). */ protected void drawHorizontalItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final StatisticalCategoryDataset dataset, final int row, final int column) { // nothing is drawn for null... //added this test block, Rinke final Number v = dataset.getValue(row, column); if (v == null) { return; } final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); // BAR Y double rectY = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, xAxisLocation); final int seriesCount = getRowCount(); final int categoryCount = getColumnCount(); if (seriesCount > 1) { final double seriesGap = dataArea.getHeight() * getItemMargin() / (categoryCount * (seriesCount - 1)); rectY = rectY + row * (state.getBarWidth() + seriesGap); } else { rectY = rectY + row * state.getBarWidth(); } // BAR X final Number meanValue = dataset.getMeanValue(row, column); double value = meanValue.doubleValue(); double base = 0.0; final double lclip = getLowerClip(); final 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; } } final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transY1 = rangeAxis.valueToJava2D(base, dataArea, yAxisLocation); final double transY2 = rangeAxis.valueToJava2D(value, dataArea, yAxisLocation); final double rectX = Math.min(transY2, transY1); final double rectHeight = state.getBarWidth(); final double rectWidth = Math.abs(transY2 - transY1); final Rectangle2D bar = new Rectangle2D.Double(rectX, rectY, rectWidth, rectHeight); final Paint seriesPaint = getItemPaint(row, column); g2.setPaint(seriesPaint); g2.fill(bar); if (state.getBarWidth() > 3) { g2.setStroke(getItemStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); } // ********** BLOCK WITH CHANGES RELATIVE TO StatisticalBarRenderere ********************* // standard deviation lines final AsymmetricStatisticalCategoryDataset asymmDataset = (AsymmetricStatisticalCategoryDataset) dataset; final Number highValRaw = asymmDataset.getUpperValue(row, column); final Number lowValRaw = asymmDataset.getLowerValue(row, column); if (highValRaw != null && lowValRaw != null) { // ADDED THIS IF, RINKE final double highVal = rangeAxis.valueToJava2D(highValRaw.doubleValue(), dataArea, yAxisLocation); final double lowVal = rangeAxis.valueToJava2D(lowValRaw.doubleValue(), dataArea, yAxisLocation); // *************************** end of block with changes ****************************** if (getErrorIndicatorPaint() != null) { g2.setPaint(getErrorIndicatorPaint()); } else { g2.setPaint(getItemOutlinePaint(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); } final 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 final EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, bar); } }
From source file:open.dolphin.impl.lbtest.IgnoreNullLineRenderer.java
/** * Draw a single data item.// w w w. j av a2 s. co m * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area in which the data is drawn. * @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. */ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // do nothing if item is not visible if (!getItemVisible(row, column)) { return; } // do nothing if both the line and shape are not visible if (!getItemLineVisible(row, column) && !getItemShapeVisible(row, column)) { return; } // nothing is drawn for null... Number v = dataset.getValue(row, column); if (v == null) { return; } int visibleRow = state.getVisibleSeriesIndex(row); if (visibleRow < 0) { return; } int visibleRowCount = state.getVisibleSeriesCount(); PlotOrientation orientation = plot.getOrientation(); // current data point... double x1; if (getUseSeriesOffset()) { x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge()); } else { x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); } double value = v.doubleValue(); double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); if (pass == 0 && getItemLineVisible(row, column)) { if (column != 0) { int prevColumn = getPreviousNotNullColumn(dataset, row, column - 1); Number previousValue = (prevColumn != -1) ? dataset.getValue(row, prevColumn) : null; if (previousValue != null) { // previous data point... double previous = previousValue.doubleValue(); double x0; if (getUseSeriesOffset()) { x0 = domainAxis.getCategorySeriesMiddle(prevColumn, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge()); } else { x0 = domainAxis.getCategoryMiddle(prevColumn, getColumnCount(), dataArea, plot.getDomainAxisEdge()); } double y0 = rangeAxis.valueToJava2D(previous, dataArea, plot.getRangeAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(y0, x0, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(x0, y0, x1, y1); } g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); g2.draw(line); } } } if (pass == 1) { Shape shape = getItemShape(row, column); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, x1, y1); } if (getItemShapeVisible(row, column)) { if (getItemShapeFilled(row, column)) { if (getUseFillPaint()) { g2.setPaint(getItemFillPaint(row, column)); } else { g2.setPaint(getItemPaint(row, column)); } g2.fill(shape); } if (getDrawOutlines()) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(row, column)); } else { g2.setPaint(getItemPaint(row, column)); } g2.setStroke(getItemOutlineStroke(row, column)); g2.draw(shape); } } // draw the item label if there is one... if (isItemLabelVisible(row, column)) { if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, row, column, y1, x1, (value < 0.0)); } else if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, row, column, x1, y1, (value < 0.0)); } } // submit the current data point as a crosshair candidate int datasetIndex = plot.indexOf(dataset); updateCrosshairValues(state.getCrosshairState(), dataset.getRowKey(row), dataset.getColumnKey(column), value, datasetIndex, x1, y1, orientation); // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { addItemEntity(entities, dataset, row, column, shape); } } }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param g2//from w w w.j av a 2s . c o m * @param shape * @param glowWidth */ public static void paintBorderGlow(final Graphics2D g2, final Shape shape, final int glowWidth) { int gw = glowWidth * 2; for (int i = gw; i >= 2; i -= 2) { float pct = (float) (gw - i) / (gw - 1); Color mixHi = getMixedColor(clrGlowInnerHi, pct, clrGlowOuterHi, 1.0f - pct); Color mixLo = getMixedColor(clrGlowInnerLo, pct, clrGlowOuterLo, 1.0f - pct); g2.setPaint(new GradientPaint(0.0f, 40 * 0.25f, mixHi, 0.0f, 40, mixLo)); g2.setColor(Color.WHITE); // See my "Java 2D Trickery: Soft Clipping" entry for more // on why we use SRC_ATOP here g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, pct)); g2.setStroke(new BasicStroke(i)); g2.draw(shape); } }
From source file:org.trade.ui.chart.renderer.CandleRenderer.java
/** * Method drawItem./*from www. j a v a 2 s . c om*/ * * @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 OHLCVwapDataset) { // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } CandleDataset candleDataset = (CandleDataset) dataset; CandleItem candle = (CandleItem) candleDataset.getSeries(series).getDataItem(item); double startX = candle.getPeriod().getFirstMillisecond(); if (Double.isNaN(startX)) { return; } double endX = candle.getPeriod().getLastMillisecond(); if (Double.isNaN(endX)) { return; } if (startX <= endX) { if (!domainAxis.getRange().intersects(startX, endX)) { return; } } else { if (!domainAxis.getRange().intersects(endX, startX)) { return; } } RectangleEdge location = plot.getDomainAxisEdge(); double translatedStartX = domainAxis.valueToJava2D(startX, dataArea, location); double translatedEndX = domainAxis.valueToJava2D(endX, dataArea, location); double translatedWidth = Math.max(1, Math.abs(translatedEndX - translatedStartX)); if (getMargin() > 0.0) { double cut = translatedWidth * getMargin(); translatedWidth = translatedWidth - cut; } double x = candleDataset.getXValue(series, item); double yHigh = candleDataset.getHighValue(series, item); double yLow = candleDataset.getLowValue(series, item); double yOpen = candleDataset.getOpenValue(series, item); double yClose = candleDataset.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); 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 - (translatedWidth / 2), yyHigh - 10, translatedWidth, (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 - (translatedWidth / 2), yyMinOpenClose, translatedWidth, (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 - (translatedWidth / 2), yyMinOpenClose, translatedWidth, 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); } // update the cross hair point double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, location); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge()); int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation()); } }
From source file:it.cnr.istc.utils.gui.ReverseGradientXYBarPainter.java
/** * Paints a single bar instance./*w ww .j a v a 2 s. c o m*/ * * @param g2 the graphics target. * @param renderer the renderer. * @param row the row index. * @param column the column index. * @param bar the bar * @param base indicates which side of the rectangle is the base of the bar. */ @Override public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) { Paint itemPaint = renderer.getItemPaint(row, column); Color c0, c1; if (itemPaint instanceof Color) { c0 = (Color) itemPaint; c1 = c0.brighter(); } else if (itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; c0 = gp.getColor1(); c1 = gp.getColor2(); } else { c0 = Color.blue; c1 = Color.blue.brighter(); } // as a special case, if the bar colour has alpha == 0, we draw // nothing. if (c0.getAlpha() == 0) { return; } if (base == RectangleEdge.LEFT || base == RectangleEdge.RIGHT) { Rectangle2D[] regions = splitVerticalBar(bar, this.g1, this.g2, this.g3); GradientPaint gp = new GradientPaint((float) regions[0].getMinX(), 0.0f, c0, (float) regions[0].getMaxX(), 0.0f, Color.white); g2.setPaint(gp); g2.fill(regions[0]); gp = new GradientPaint((float) regions[1].getMinX(), 0.0f, Color.white, (float) regions[1].getMaxX(), 0.0f, c0); g2.setPaint(gp); g2.fill(regions[1]); gp = new GradientPaint((float) regions[2].getMinX(), 0.0f, c0, (float) regions[2].getMaxX(), 0.0f, c1); g2.setPaint(gp); g2.fill(regions[2]); gp = new GradientPaint((float) regions[3].getMinX(), 0.0f, c1, (float) regions[3].getMaxX(), 0.0f, c0); g2.setPaint(gp); g2.fill(regions[3]); } else if (base == RectangleEdge.TOP || base == RectangleEdge.BOTTOM) { Rectangle2D[] regions = splitHorizontalBar(bar, this.g1, this.g2, this.g3); GradientPaint gp = new GradientPaint(0.0f, (float) regions[0].getMinY(), c0, 0.0f, (float) regions[0].getMaxX(), Color.white); g2.setPaint(gp); g2.fill(regions[0]); gp = new GradientPaint(0.0f, (float) regions[1].getMinY(), Color.white, 0.0f, (float) regions[1].getMaxY(), c0); g2.setPaint(gp); g2.fill(regions[1]); gp = new GradientPaint(0.0f, (float) regions[2].getMinY(), c0, 0.0f, (float) regions[2].getMaxY(), c1); g2.setPaint(gp); g2.fill(regions[2]); gp = new GradientPaint(0.0f, (float) regions[3].getMinY(), c1, 0.0f, (float) regions[3].getMaxY(), c0); g2.setPaint(gp); g2.fill(regions[3]); } // draw the outline... if (renderer.isDrawBarOutline()) { Stroke stroke = renderer.getItemOutlineStroke(row, column); Paint paint = renderer.getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } }