List of usage examples for javafx.scene.canvas GraphicsContext beginPath
public void beginPath()
From source file:org.nmrfx.processor.gui.spectra.DrawSpectrum.java
private void genContourPath(DatasetAttributes dataGenerator, AXMODE[] axModes, Contour contours, final int coordIndex, GraphicsContext g2) { int lineCount = contours.getLineCount(coordIndex); float scale = Contour.getScaleFac() / Short.MAX_VALUE; double cxOffset = contours.xOffset; double cyOffset = contours.yOffset; g2.beginPath(); Dataset dataset = dataGenerator.getDataset(); for (int iLine = 0; iLine < lineCount; iLine += 4) { if (cancelled) { System.out.println("can response1"); break; }/* w ww .j a va 2s . c o m*/ double xPoint1 = scale * contours.coords[coordIndex][iLine] + cxOffset; double xPoint2 = scale * contours.coords[coordIndex][iLine + 2] + cxOffset; double yPoint1 = scale * contours.coords[coordIndex][iLine + 1] + cyOffset; double yPoint2 = scale * contours.coords[coordIndex][iLine + 3] + cyOffset; xPoint1 = dataset.pointToPPM(dataGenerator.dim[0], xPoint1); xPoint2 = dataset.pointToPPM(dataGenerator.dim[0], xPoint2); yPoint1 = dataset.pointToPPM(dataGenerator.dim[1], yPoint1); yPoint2 = dataset.pointToPPM(dataGenerator.dim[1], yPoint2); double x1 = axes[0].getDisplayPosition(xPoint1); double x2 = axes[0].getDisplayPosition(xPoint2); double y1 = axes[1].getDisplayPosition(yPoint1); double y2 = axes[1].getDisplayPosition(yPoint2); g2.moveTo(x1, y1); g2.lineTo(x2, y2); } g2.stroke(); }
From source file:qupath.lib.gui.plots.ScatterPlot.java
public void drawPlot(GraphicsContext g, Rectangle2D region, int maxPoints) { g.save();//from w w w . ja v a2s .c o m g.beginPath(); g.moveTo(region.getMinX(), region.getMinY()); g.lineTo(region.getMaxX(), region.getMinY()); g.lineTo(region.getMaxX(), region.getMaxY()); g.lineTo(region.getMinX(), region.getMaxY()); g.closePath(); g.clip(); // int pad = 10; double scaleX = region.getWidth() / (maxX - minX); double scaleY = region.getHeight() / (maxY - minY); g.setLineWidth(1.5f); // g.setStroke(javafx.scene.paint.Color.GRAY); // g.strokeRect(region.getX(), region.getY(), region.getWidth(), region.getHeight()); g.translate(region.getMinX(), region.getMinY()); // g2d.drawLine(0, 0, 0, region.height); // g2d.drawLine(0, region.height, region.width, region.height); double increment; if (maxPoints < 0 || x.length <= maxPoints) increment = 1; else increment = (double) x.length / maxPoints; for (double i = 0; i < x.length; i += increment) { int ind = (int) i; double xx = x[ind]; double yy = y[ind]; // // Skip if out of range // if (xx < minX || xx > maxX || yy < minY || yy > maxY) // continue; double xo = (xx - minX) * scaleX - markerSize / 2; double yo = region.getHeight() - (yy - minY) * scaleY - markerSize / 2; Color cDraw = colorDraw == null ? null : colorDraw[ind]; if (fillMarkers) { Color cFill = colorFill[ind] == null ? cDraw : colorFill[ind]; if (cFill != null) { g.setFill(cFill); g.fillOval(xo, yo, markerSize, markerSize); // Don't need to draw if it would be the same color anyway if (cFill == cDraw) continue; } } if (cDraw != null) { g.setStroke(cDraw); g.strokeOval(xo, yo, markerSize, markerSize); } } g.restore(); }