Java Code Examples for javafx.scene.canvas.GraphicsContext#restore()

The following examples show how to use javafx.scene.canvas.GraphicsContext#restore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultControlTreeItemGraphic.java    From arma-dialog-creator with MIT License 6 votes vote down vote up
private void fillBox(Color color) {
	GraphicsContext gc = box.getGraphicsContext2D();
	gc.save();
	gc.clearRect(0, 0, box.getWidth(), box.getHeight());
	gc.setFill(color);
	gc.fillRect(0, 0, box.getWidth(), box.getHeight());
	gc.restore();

	//generate hex string and bind it to tooltip
	final double f = 255.0;
	int r = (int) (color.getRed() * f);
	int g = (int) (color.getGreen() * f);
	int b = (int) (color.getBlue() * f);
	String opacity = DecimalFormat.getNumberInstance().format(color.getOpacity() * 100);

	Tooltip.install(box, new Tooltip(String.format(
			"red:%d, green:%d, blue:%d, opacity:%s%%", r, g, b, opacity))
	);
}
 
Example 2
Source File: GridRenderer.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected void drawEuclideanGrid(final GraphicsContext gc, XYChart xyChart) {
    final Axis xAxis = xyChart.getXAxis();
    final Axis yAxis = xyChart.getYAxis();
    final double xAxisWidth = xyChart.getCanvas().getWidth();
    final double xAxisWidthSnapped = snap(xAxisWidth);
    final double yAxisHeight = xyChart.getCanvas().getHeight();
    final double yAxisHeightSnapped = snap(yAxisHeight);
    if (xAxis instanceof Node) {
        ((Node) xAxis).setVisible(true);
    }

    gc.save();
    drawVerticalMajorGridLines(gc, xAxis, xAxisWidth, yAxisHeightSnapped);
    drawVerticalMinorGridLines(gc, xAxis, xAxisWidth, yAxisHeightSnapped);
    drawHorizontalMajorGridLines(gc, yAxis, xAxisWidthSnapped, yAxisHeight);
    drawHorizontalMinorGridLines(gc, yAxis, xAxisWidthSnapped, yAxisHeight);
    gc.restore();
}
 
Example 3
Source File: PlainAmpSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
private void drawLed(final GraphicsContext CTX) {
    CTX.clearRect(0, 0, ledSize, ledSize);
    CTX.setFill(frameGradient);
    CTX.fillOval(0, 0, ledSize, ledSize);

    CTX.save();
    if (gauge.isLedOn()) {
        CTX.setEffect(ledOnShadow);
        CTX.setFill(ledOnGradient);
    } else {
        CTX.setEffect(ledOffShadow);
        CTX.setFill(ledOffGradient);
    }
    CTX.fillOval(0.14 * ledSize, 0.14 * ledSize, 0.72 * ledSize, 0.72 * ledSize);
    CTX.restore();

    CTX.setFill(highlightGradient);
    CTX.fillOval(0.21 * ledSize, 0.21 * ledSize, 0.58 * ledSize, 0.58 * ledSize);
}
 
Example 4
Source File: ConcentricRingChart.java    From charts with Apache License 2.0 6 votes vote down vote up
private void drawTextAlongArc(final GraphicsContext CTX, final String TEXT, final double CENTER_X, final double CENTER_Y, final double RADIUS, final double ANGLE){
    int    length     = TEXT.length();
    double charSpacer = (7 / RADIUS) * size * 0.13;
    double textAngle  = (charSpacer * (length + 0.5));
    if (ANGLE > textAngle) {
        CTX.save();
        CTX.translate(CENTER_X, CENTER_Y);
        CTX.rotate(ANGLE - (charSpacer * (length + 0.5)));
        for (int i = 0; i < length; i++) {
            CTX.save();
            CTX.translate(0, -1 * RADIUS);
            char c = TEXT.charAt(i);
            CTX.fillText(Character.toString(c), 0, 0);
            CTX.restore();
            CTX.rotate(charSpacer);
        }
        CTX.restore();
    }
}
 
Example 5
Source File: BulletChartSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void drawSections(final GraphicsContext CTX) {
    sectionsCanvas.setCache(false);
    CTX.clearRect(0, 0, sectionsCanvas.getWidth(), sectionsCanvas.getHeight());
    CTX.setFill(gauge.getBackgroundPaint());
    if (Orientation.VERTICAL == orientation) {
        CTX.fillRect(0, 0, 0.5 * width, 0.9 * height);
    } else {
        CTX.fillRect(0, 0, 0.79699248 * width, 0.5 * height);
    }

    double tmpStepSize = stepSize * 1.11111111;
    double minValue = gauge.getMinValue();
    double maxValue = gauge.getMaxValue();

    int listSize = gauge.getSections().size();
    for (int i = 0 ; i < listSize ; i++) {
        final Section SECTION = gauge.getSections().get(i);
        final double SECTION_START;

        final double SECTION_SIZE = SECTION.getRange() * tmpStepSize;
        if (Double.compare(SECTION.getStart(), maxValue) <= 0 && Double.compare(SECTION.getStop(), minValue) >= 0) {
            if (Double.compare(SECTION.getStart(), minValue) < 0 && Double.compare(SECTION.getStop(), maxValue) < 0) {
                SECTION_START = minValue * tmpStepSize;
            } else {
                SECTION_START = height - (SECTION.getStart() * tmpStepSize) - SECTION_SIZE;
            }
            CTX.save();
            CTX.setFill(SECTION.getColor());
            if (Orientation.VERTICAL == orientation) {
                CTX.fillRect(0.0, SECTION_START, 0.5 * width, SECTION_SIZE);
            } else {
                CTX.fillRect(SECTION_START, 0.0, SECTION_SIZE, 0.5 * height);
            }
            CTX.restore();
        }
    }
    sectionsCanvas.setCache(true);
    sectionsCanvas.setCacheHint(CacheHint.QUALITY);
}
 
Example 6
Source File: TextHelper.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
/**
 Paint the text where designated. The text will not be clipped anywhere.
 <p>
 This method will invoke {@link GraphicsContext#save()} and {@link GraphicsContext#restore()}
 at the start and end of this method, respectively.

 @param gc context to use
 @param textX x position of text
 @param textY y position of text
 @param font font to use
 @param text text to use
 @param textColor color of text
 @param textShadow shadow to use
 @param shadowColor color of shadow
 */
public static void paintText(@NotNull GraphicsContext gc, int textX, int textY, @NotNull Font font,
							 @NotNull String text, @NotNull Color textColor,
							 @NotNull TextShadow textShadow, @NotNull Color shadowColor) {
	gc.save();

	gc.setFont(font);
	gc.setFill(textColor);
	switch (textShadow) {
		case None: {
			gc.fillText(text, textX, textY);
			break;
		}
		case DropShadow: {
			final double offset = 2.0;
			gc.setFill(shadowColor);
			gc.fillText(text, textX + offset, textY + offset);
			gc.setFill(textColor);
			gc.fillText(text, textX, textY);
			break;
		}
		case Stroke: {
			gc.setLineWidth(2);
			gc.setStroke(shadowColor);
			gc.strokeText(text, textX, textY);
			gc.fillText(text, textX, textY);
			break;
		}
		default: {
			throw new IllegalStateException("unknown textShadow=" + textShadow);
		}
	}
	gc.restore();
}
 
Example 7
Source File: ContourDataSetRenderer.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
private void drawHexagonMapContour(final GraphicsContext gc, final ContourDataSetCache lCache) {
    final long start = ProcessingProfiler.getTimeStamp();

    // process z quantisation to colour transform
    final WritableImage image = localCache.convertDataArrayToImage(lCache.reduced, lCache.xSize, lCache.ySize, getColorGradient());

    final int tileSize = Math.max(getMinHexTileSizeProperty(), (int) lCache.xAxisWidth / lCache.xSize);
    final int nWidthInTiles = (int) (lCache.xAxisWidth / (tileSize * Math.sqrt(3)));
    final HexagonMap hexMap = new HexagonMap(tileSize, image, nWidthInTiles, (q, r, imagePixelColor, map) -> {
        final Hexagon h = new Hexagon(q, r);
        h.setFill(Color.TRANSPARENT); // contour being plotted
        h.setStroke(imagePixelColor);
        h.setStrokeType(StrokeType.CENTERED);

        h.setStrokeWidth(1);
        map.addHexagon(h);
    });
    localCache.add(image);

    ProcessingProfiler.getTimeDiff(start, "drawHexagonMapContour - prepare");

    final double scaleX = lCache.xDataPixelRange / lCache.xAxisWidth;
    final double scaleY = lCache.yDataPixelRange / lCache.yAxisHeight;
    gc.save();
    gc.translate(lCache.xDataPixelMin, lCache.yDataPixelMin);
    gc.scale(scaleX, scaleY);

    hexMap.renderContour(gc.getCanvas());
    gc.restore();

    ProcessingProfiler.getTimeDiff(start, "drawHexagonMapContour");
}
 
Example 8
Source File: Helper.java    From Medusa with Apache License 2.0 5 votes vote down vote up
public static final void drawTimeSections(final Clock CLOCK, final GraphicsContext CTX, final List<TimeSection> SECTIONS, final double SIZE,
                                          final double XY_INSIDE, final double XY_OUTSIDE, final double WH_INSIDE, final double WH_OUTSIDE,
                                          final double LINE_WIDTH) {
    if (SECTIONS.isEmpty()) return;
    TickLabelLocation tickLabelLocation = CLOCK.getTickLabelLocation();
    ZonedDateTime     time              = CLOCK.getTime();
    boolean           isAM              = time.get(ChronoField.AMPM_OF_DAY) == 0;
    double            xy                = TickLabelLocation.INSIDE == tickLabelLocation ? XY_INSIDE * SIZE : XY_OUTSIDE * SIZE;
    double            wh                = TickLabelLocation.INSIDE == tickLabelLocation ? WH_INSIDE * SIZE : WH_OUTSIDE * SIZE;
    double            offset            = 90;
    int               listSize          = SECTIONS.size();
    double            angleStep         = 360.0 / 60.0;
    boolean           highlightSections = CLOCK.isHighlightSections();
    for (int i = 0 ; i < listSize ; i++) {
        TimeSection section   = SECTIONS.get(i);
        LocalTime   start     = section.getStart();
        LocalTime   stop      = section.getStop();
        boolean     isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean     isStopAM  = stop.get(ChronoField.AMPM_OF_DAY) == 0;
        boolean     draw      = isAM ? (isStartAM || isStopAM) :(!isStartAM || !isStopAM);
        if (draw) {
            double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;
            double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep;
            //TODO: Add an indicator to the section like -1 or similar
            // check if start was already yesterday
            if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); }
            CTX.save();
            if (highlightSections) {
                CTX.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor());
            } else {
                CTX.setStroke(section.getColor());
            }
            CTX.setLineWidth(SIZE * LINE_WIDTH);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(xy, xy, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example 9
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
/**
 * @param gc the graphics context from the Canvas parent
 * @param localCachedPoints reference to local cached data point object
 */
protected void drawMarker(final GraphicsContext gc, final CachedDataPoints localCachedPoints) {
    if (!isDrawMarker()) {
        return;
    }
    gc.save();
    DefaultRenderColorScheme.setMarkerScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);

    final Triple<Marker, Color, Double> markerTypeColorAndSize = getDefaultMarker(localCachedPoints.defaultStyle);
    final Marker defaultMarker = markerTypeColorAndSize.getFirst();
    final Color defaultMarkerColor = markerTypeColorAndSize.getSecond();
    final double defaultMarkerSize = markerTypeColorAndSize.getThird();
    if (defaultMarkerColor != null) {
        gc.setFill(defaultMarkerColor);
    }
    for (int i = 0; i < localCachedPoints.actualDataCount; i++) {
        final double x = localCachedPoints.xValues[i];
        final double y = localCachedPoints.yValues[i];
        if (localCachedPoints.styles[i] == null) {
            defaultMarker.draw(gc, x, y, defaultMarkerSize);
        } else {
            final Triple<Marker, Color, Double> markerForPoint = getDefaultMarker(
                    localCachedPoints.defaultStyle + localCachedPoints.styles[i]);
            gc.save();
            if (markerForPoint.getSecond() != null) {
                gc.setFill(markerForPoint.getSecond());
            }
            final Marker pointMarker = markerForPoint.getFirst() == null ? defaultMarker
                                                                         : markerForPoint.getFirst();
            pointMarker.draw(gc, x, y, markerForPoint.getThird());
            gc.restore();
        }
    }

    gc.restore();
}
 
Example 10
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
protected static void drawPolyLineArea(final GraphicsContext gc, final CachedDataPoints localCachedPoints) {
    final int n = localCachedPoints.actualDataCount;
    if (n == 0) {
        return;
    }

    // need to allocate new array :-(
    final double[] newX = DoubleArrayCache.getInstance().getArrayExact(n + 2);
    final double[] newY = DoubleArrayCache.getInstance().getArrayExact(n + 2);

    final double zero = localCachedPoints.yZero;
    System.arraycopy(localCachedPoints.xValues, 0, newX, 0, n);
    System.arraycopy(localCachedPoints.yValues, 0, newY, 0, n);
    newX[n] = localCachedPoints.xValues[n - 1];
    newY[n] = zero;
    newX[n + 1] = localCachedPoints.xValues[0];
    newY[n + 1] = zero;

    gc.save();
    DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);
    DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle);
    // use stroke as fill colour
    gc.setFill(gc.getStroke());
    gc.fillPolygon(newX, newY, n + 2);
    gc.restore();

    // release arrays to cache
    DoubleArrayCache.getInstance().add(newX);
    DoubleArrayCache.getInstance().add(newY);
}
 
Example 11
Source File: ArmaAbsoluteBoxComponent.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
@Override
public void paint(@NotNull GraphicsContext gc, CanvasContext canvasContext) {
	gc.save();
	gc.setStroke(backgroundColor);
	Region.strokeRectangle(gc, resolution.getViewportX(), resolution.getViewportY(), resolution.getViewportX() + resolution.getViewportWidth(), resolution.getViewportY() + resolution.getViewportHeight());
	gc.restore();
}
 
Example 12
Source File: MiscHelpers.java    From arma-dialog-creator with MIT License 4 votes vote down vote up
public static void paintFlippedImage(@NotNull GraphicsContext gc, @NotNull Image img, int x, int y, int w, int h) {
	gc.save();
	gc.scale(-1, 1);
	gc.drawImage(img, -x - w, y, w, h);
	gc.restore();
}
 
Example 13
Source File: AmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawSections(final GraphicsContext CTX) {
    final double x                         = width * 0.06;
    final double y                         = width * 0.21;
    final double w                         = width * 0.88;
    final double h                         = height * 1.05;
    final double MIN_VALUE                 = gauge.getMinValue();
    final double MAX_VALUE                 = gauge.getMaxValue();
    final double OFFSET                    = 90 - START_ANGLE;
    final ObservableList<Section> sections = gauge.getSections();
    final boolean highlightSections        = gauge.isHighlightSections();

    double value    = gauge.getCurrentValue();
    int    listSize = sections.size();
    for (int i = 0 ; i < listSize ; i++) {
        final Section SECTION = sections.get(i);
        final double  SECTION_START_ANGLE;
        if (Double.compare(SECTION.getStart(), MAX_VALUE) <= 0 && Double.compare(SECTION.getStop(), MIN_VALUE) >= 0) {
            if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
                SECTION_START_ANGLE = 0;
            } else {
                SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
            }
            final double SECTION_ANGLE_EXTEND;
            if (SECTION.getStop() > MAX_VALUE) {
                SECTION_ANGLE_EXTEND = (MAX_VALUE - SECTION.getStart()) * angleStep;
            } else {
                SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
            }

            CTX.save();
            if (highlightSections) {
                CTX.setStroke(SECTION.contains(value) ? SECTION.getHighlightColor() : SECTION.getColor());
            } else {
                CTX.setStroke(SECTION.getColor());
            }
            CTX.setLineWidth(height * 0.0415);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(x, y, w, h, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example 14
Source File: PlainAmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawSections(final GraphicsContext CTX) {
    final double                  x                 = -width * 0.03;
    final double                  y                 = height * 0.345;
    final double                  w                 = width * 1.06;
    final double                  h                 = height * 2.085;
    final double                  MIN_VALUE         = gauge.getMinValue();
    final double                  MAX_VALUE         = gauge.getMaxValue();
    final double                  OFFSET            = 90 - START_ANGLE;
    final ObservableList<Section> sections          = gauge.getSections();
    final boolean                 highlightSections = gauge.isHighlightSections();

    double value    = gauge.getCurrentValue();
    int    listSize = sections.size();
    for (int i = 0 ; i < listSize ; i++) {
        final Section SECTION = sections.get(i);
        final double  SECTION_START_ANGLE;
        if (Double.compare(SECTION.getStart(), MAX_VALUE) <= 0 && Double.compare(SECTION.getStop(), MIN_VALUE) >= 0) {
            if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
                SECTION_START_ANGLE = 0;
            } else {
                SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
            }
            final double SECTION_ANGLE_EXTEND;
            if (SECTION.getStop() > MAX_VALUE) {
                SECTION_ANGLE_EXTEND = (MAX_VALUE - SECTION.getStart()) * angleStep;
            } else {
                SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
            }

            CTX.save();
            if (highlightSections) {
                CTX.setStroke(SECTION.contains(value) ? SECTION.getHighlightColor() : SECTION.getColor());
            } else {
                CTX.setStroke(SECTION.getColor());
            }
            CTX.setLineWidth(height * 0.0415);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(x, y, w, h, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example 15
Source File: HSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawAreasAndSections(final GraphicsContext CTX) {
    if (areas.isEmpty() && sections.isEmpty()) return;

    double value       = gauge.getCurrentValue();
    double scaledWidth = width * 0.9;
    double offset      = 90 - startAngle;
    double offsetY     = -0.1 * height;
    double xy;
    double wh;
    int    listSize;

    // Draw areas
    if (areasVisible && !areas.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.1445 * scaledWidth : 0.081 * scaledWidth;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledWidth * 0.821 : scaledWidth * 0.9505;
        listSize = areas.size();
        for (int i = 0 ; i < listSize ; i++) {
            Section area = areas.get(i);
            double areaStartAngle;
            if (Double.compare(area.getStart(), maxValue) <= 0 && Double.compare(area.getStop(), minValue) >= 0) {
                if (area.getStart() < minValue && area.getStop() < maxValue) {
                    areaStartAngle = 0;
                } else {
                    areaStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStart() - minValue) * angleStep : -(area.getStart() - minValue) * angleStep;
                }
                double areaAngleExtend;
                if (area.getStop() > maxValue) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - area.getStart()) * angleStep : -(maxValue - area.getStart()) * angleStep;
                } else if (Double.compare(area.getStart(), minValue) < 0) {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - minValue) * angleStep : -(area.getStop() - minValue) * angleStep;
                } else {
                    areaAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (area.getStop() - area.getStart()) * angleStep : -(area.getStop() - area.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightAreas) {
                    CTX.setFill(area.contains(value) ? area.getHighlightColor() : area.getColor());
                } else {
                    CTX.setFill(area.getColor());
                }
                CTX.fillArc(xy, xy + offsetY, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND);
                CTX.restore();
            }
        }
    }

    // Draw sections
    if (sectionsVisible && !sections.isEmpty()) {
        xy       = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.1705 * scaledWidth : 0.107 * scaledWidth;
        wh       = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledWidth * 0.77 : scaledWidth * 0.897;
        listSize = sections.size();
        CTX.setLineWidth(scaledWidth * 0.052);
        CTX.setLineCap(StrokeLineCap.BUTT);
        for (int i = 0; i < listSize; i++) {
            Section section = sections.get(i);
            double  sectionStartAngle;
            if (Double.compare(section.getStart(), maxValue) <= 0 && Double.compare(section.getStop(), minValue) >= 0) {
                if (Double.compare(section.getStart(), minValue) < 0 && Double.compare(section.getStop(), maxValue) < 0) {
                    sectionStartAngle = 0;
                } else {
                    sectionStartAngle = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStart() - minValue) * angleStep : -(section.getStart() - minValue) * angleStep;
                }
                double sectionAngleExtend;
                if (Double.compare(section.getStop(), maxValue) > 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (maxValue - section.getStart()) * angleStep : -(maxValue - section.getStart()) * angleStep;
                } else if (Double.compare(section.getStart(), minValue) < 0) {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - minValue) * angleStep : -(section.getStop() - minValue) * angleStep;
                } else {
                    sectionAngleExtend = ScaleDirection.CLOCKWISE == scaleDirection ? (section.getStop() - section.getStart()) * angleStep : -(section.getStop() - section.getStart()) * angleStep;
                }
                CTX.save();
                if (highlightSections) {
                    CTX.setStroke(section.contains(value) ? section.getHighlightColor() : section.getColor());
                } else {
                    CTX.setStroke(section.getColor());
                }
                CTX.strokeArc(xy, xy + offsetY, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN);
                CTX.restore();
            }
        }
    }
}
 
Example 16
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
protected static void drawPolyLineHistogramFilled(final GraphicsContext gc,
        final CachedDataPoints localCachedPoints) {
    final int n = localCachedPoints.actualDataCount;
    if (n == 0) {
        return;
    }

    // need to allocate new array :-(
    final double[] newX = DoubleArrayCache.getInstance().getArrayExact(2 * (n + 1));
    final double[] newY = DoubleArrayCache.getInstance().getArrayExact(2 * (n + 1));

    final double xRange = localCachedPoints.xMax - localCachedPoints.xMin;
    double diffLeft;
    double diffRight = n > 0 ? 0.5 * (localCachedPoints.xValues[1] - localCachedPoints.xValues[0]) : 0.5 * xRange;
    newX[0] = localCachedPoints.xValues[0] - diffRight;
    newY[0] = localCachedPoints.yZero;
    for (int i = 0; i < n; i++) {
        diffLeft = localCachedPoints.xValues[i] - newX[2 * i];
        diffRight = i + 1 < n ? 0.5 * (localCachedPoints.xValues[i + 1] - localCachedPoints.xValues[i]) : diffLeft;
        if (i == 0) {
            diffLeft = diffRight;
        }

        newX[2 * i + 1] = localCachedPoints.xValues[i] - diffLeft;
        newY[2 * i + 1] = localCachedPoints.yValues[i];
        newX[2 * i + 2] = localCachedPoints.xValues[i] + diffRight;
        newY[2 * i + 2] = localCachedPoints.yValues[i];
    }
    // last point
    newX[2 * (n + 1) - 1] = localCachedPoints.xValues[n - 1] + diffRight;
    newY[2 * (n + 1) - 1] = localCachedPoints.yZero;

    gc.save();
    DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);
    DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle);
    // use stroke as fill colour
    gc.setFill(gc.getStroke());
    gc.fillPolygon(newX, newY, 2 * (n + 1));
    gc.restore();

    // release arrays to cache
    DoubleArrayCache.getInstance().add(newX);
    DoubleArrayCache.getInstance().add(newY);
}
 
Example 17
Source File: GaugeSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private final void drawSections(final GraphicsContext CTX) {
    final double xy        = (size - 0.83 * size) / 2;
    final double wh        = size * 0.83;
    final double MIN_VALUE = getSkinnable().getMinValue();
    final double MAX_VALUE = getSkinnable().getMaxValue();
    final double OFFSET = 90 - getSkinnable().getStartAngle();
    for (int i = 0 ; i < getSkinnable().getSections().size() ; i++) {
        final Section SECTION = getSkinnable().getSections().get(i);

        if (SECTION.getStart() > MAX_VALUE || SECTION.getStop() < MIN_VALUE) continue;

        final double SECTION_START_ANGLE;
        if (SECTION.getStart() > MAX_VALUE || SECTION.getStop() < MIN_VALUE) continue;

        if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
            SECTION_START_ANGLE = MIN_VALUE * angleStep;
        } else {
            SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
        }
        final double SECTION_ANGLE_EXTEND;
        if (SECTION.getStop() > MAX_VALUE) {
            SECTION_ANGLE_EXTEND = MAX_VALUE * angleStep;
        } else {
            SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
        }

        CTX.save();
        switch(i) {
            case 0: CTX.setStroke(getSkinnable().getSectionFill0()); break;
            case 1: CTX.setStroke(getSkinnable().getSectionFill1()); break;
            case 2: CTX.setStroke(getSkinnable().getSectionFill2()); break;
            case 3: CTX.setStroke(getSkinnable().getSectionFill3()); break;
            case 4: CTX.setStroke(getSkinnable().getSectionFill4()); break;
            case 5: CTX.setStroke(getSkinnable().getSectionFill5()); break;
            case 6: CTX.setStroke(getSkinnable().getSectionFill6()); break;
            case 7: CTX.setStroke(getSkinnable().getSectionFill7()); break;
            case 8: CTX.setStroke(getSkinnable().getSectionFill8()); break;
            case 9: CTX.setStroke(getSkinnable().getSectionFill9()); break;
        }
        CTX.setLineWidth(size * 0.037);
        CTX.setLineCap(StrokeLineCap.BUTT);
        CTX.strokeArc(xy, xy, wh, wh, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
        CTX.restore();
    }
}
 
Example 18
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
protected static void drawPolyLineHistogram(final GraphicsContext gc, final CachedDataPoints localCachedPoints) {
    final int n = localCachedPoints.actualDataCount;
    if (n == 0) {
        return;
    }

    // need to allocate new array :-(
    final double[] newX = DoubleArrayCache.getInstance().getArrayExact(2 * (n + 1));
    final double[] newY = DoubleArrayCache.getInstance().getArrayExact(2 * (n + 1));

    final double xRange = localCachedPoints.xMax - localCachedPoints.xMin;
    double diffLeft;
    double diffRight = n > 0 ? 0.5 * (localCachedPoints.xValues[1] - localCachedPoints.xValues[0]) : 0.5 * xRange;
    newX[0] = localCachedPoints.xValues[0] - diffRight;
    newY[0] = localCachedPoints.yZero;
    for (int i = 0; i < n; i++) {
        diffLeft = localCachedPoints.xValues[i] - newX[2 * i];
        diffRight = i + 1 < n ? 0.5 * (localCachedPoints.xValues[i + 1] - localCachedPoints.xValues[i]) : diffLeft;
        if (i == 0) {
            diffLeft = diffRight;
        }

        newX[2 * i + 1] = localCachedPoints.xValues[i] - diffLeft;
        newY[2 * i + 1] = localCachedPoints.yValues[i];
        newX[2 * i + 2] = localCachedPoints.xValues[i] + diffRight;
        newY[2 * i + 2] = localCachedPoints.yValues[i];
    }
    // last point
    newX[2 * (n + 1) - 1] = localCachedPoints.xValues[n - 1] + diffRight;
    newY[2 * (n + 1) - 1] = localCachedPoints.yZero;

    gc.save();
    DefaultRenderColorScheme.setLineScheme(gc, localCachedPoints.defaultStyle,
            localCachedPoints.dataSetIndex + localCachedPoints.dataSetStyleIndex);
    DefaultRenderColorScheme.setGraphicsContextAttributes(gc, localCachedPoints.defaultStyle);

    for (int i = 0; i < 2 * (n + 1) - 1; i++) {
        final double x1 = newX[i];
        final double x2 = newX[i + 1];
        final double y1 = newY[i];
        final double y2 = newY[i + 1];
        gc.strokeLine(x1, y1, x2, y2);
    }

    gc.restore();

    // release arrays to cache
    DoubleArrayCache.getInstance().add(newX);
    DoubleArrayCache.getInstance().add(newY);
}
 
Example 19
Source File: ErrorDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
/**
 * @param gc the graphics context from the Canvas parent
 * @param lCacheP reference to local cached data point object
 */
protected void drawErrorBars(final GraphicsContext gc, final CachedDataPoints lCacheP) {
    final long start = ProcessingProfiler.getTimeStamp();

    drawBars(gc, lCacheP);

    final int dashHalf = getDashSize() / 2;
    gc.save();
    DefaultRenderColorScheme.setFillScheme(gc, lCacheP.defaultStyle, lCacheP.dataSetIndex);
    DefaultRenderColorScheme.setGraphicsContextAttributes(gc, lCacheP.defaultStyle);

    for (int i = 0; i < lCacheP.actualDataCount; i++) {
        if (lCacheP.errorType[DataSet.DIM_X] != ErrorType.NO_ERROR
                && lCacheP.errorType[DataSet.DIM_Y] != ErrorType.NO_ERROR) {
            // draw error bars
            gc.strokeLine(lCacheP.xValues[i], lCacheP.errorYNeg[i], lCacheP.xValues[i], lCacheP.errorYPos[i]);
            gc.strokeLine(lCacheP.errorXNeg[i], lCacheP.yValues[i], lCacheP.errorXPos[i], lCacheP.yValues[i]);

            // draw horizontal dashes
            gc.strokeLine(lCacheP.xValues[i] - dashHalf, lCacheP.errorYNeg[i], lCacheP.xValues[i] + dashHalf,
                    lCacheP.errorYNeg[i]);
            gc.strokeLine(lCacheP.xValues[i] - dashHalf, lCacheP.errorYPos[i], lCacheP.xValues[i] + dashHalf,
                    lCacheP.errorYPos[i]);

            // draw vertical dashes
            gc.strokeLine(lCacheP.errorXNeg[i], lCacheP.yValues[i] - dashHalf, lCacheP.errorXNeg[i],
                    lCacheP.yValues[i] + dashHalf);
            gc.strokeLine(lCacheP.errorXPos[i], lCacheP.yValues[i] - dashHalf, lCacheP.errorXPos[i],
                    lCacheP.yValues[i] + dashHalf);
        } else if (lCacheP.errorType[DataSet.DIM_X] == ErrorType.NO_ERROR
                   && lCacheP.errorType[DataSet.DIM_Y] != ErrorType.NO_ERROR) {
            // draw error bars
            gc.strokeLine(lCacheP.xValues[i], lCacheP.errorYNeg[i], lCacheP.xValues[i], lCacheP.errorYPos[i]);

            // draw horizontal dashes
            gc.strokeLine(lCacheP.xValues[i] - dashHalf, lCacheP.errorYNeg[i], lCacheP.xValues[i] + dashHalf,
                    lCacheP.errorYNeg[i]);
            gc.strokeLine(lCacheP.xValues[i] - dashHalf, lCacheP.errorYPos[i], lCacheP.xValues[i] + dashHalf,
                    lCacheP.errorYPos[i]);
        } else if (lCacheP.errorType[DataSet.DIM_X] != ErrorType.NO_ERROR
                   && lCacheP.errorType[DataSet.DIM_Y] == ErrorType.NO_ERROR) {
            // draw error bars
            gc.strokeLine(lCacheP.errorXNeg[i], lCacheP.yValues[i], lCacheP.errorXPos[i], lCacheP.yValues[i]);

            // draw horizontal dashes
            gc.strokeLine(lCacheP.xValues[i] - dashHalf, lCacheP.errorYNeg[i], lCacheP.xValues[i] + dashHalf,
                    lCacheP.errorYNeg[i]);
            gc.strokeLine(lCacheP.xValues[i] - dashHalf, lCacheP.errorYPos[i], lCacheP.xValues[i] + dashHalf,
                    lCacheP.errorYPos[i]);
        }
    }
    gc.restore();

    drawPolyLine(gc, lCacheP);
    drawMarker(gc, lCacheP);
    drawBubbles(gc, lCacheP);

    ProcessingProfiler.getTimeDiff(start);
}
 
Example 20
Source File: ContourDataSetRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
private void drawContour(final GraphicsContext gc, final ContourDataSetCache lCache) {
    final double[] levels = new double[getNumberQuantisationLevels()];
    for (int i = 0; i < levels.length; i++) {
        levels[i] = (i + 1) / (double) levels.length;
    }

    final int xSize = lCache.xSize;
    final int ySize = lCache.ySize;
    final double[][] data = new double[ySize][xSize];
    for (int yIndex = 0; yIndex < ySize; yIndex++) {
        for (int xIndex = 0; xIndex < xSize; xIndex++) {
            final double offset = lCache.reduced[yIndex * xSize + xIndex];
            data[ySize - 1 - yIndex][xIndex] = offset;
        }
    }

    // abort if min/max == 0 -> cannot compute contours
    final double zRange = Math.abs(lCache.zMax - lCache.zMin);
    if (zRange <= 0) {
        return;
    }

    final ColorGradient colorGradient = getColorGradient();
    final MarchingSquares marchingSquares = new MarchingSquares();
    final double scaleX = lCache.xDataPixelRange / xSize;
    final double scaleY = lCache.yDataPixelRange / ySize;
    gc.save();
    gc.translate(lCache.xDataPixelMin, lCache.yDataPixelMin);
    gc.scale(scaleX, scaleY);
    final GeneralPath[] isolines;
    try {
        isolines = marchingSquares.buildContours(data, levels);
        int levelCount = 0;
        for (final GeneralPath path : isolines) {
            if (path.size() > getMaxContourSegments()) {
                levelCount++;
                continue;
            }
            final Color color = lCache.zInverted ? colorGradient.getColor(1 - levels[levelCount++])
                                                 : colorGradient.getColor(levels[levelCount++]);
            gc.setStroke(color);
            gc.setLineDashes(1.0);
            gc.setMiterLimit(10);
            gc.setFill(color);
            gc.setLineWidth(0.5);
            path.draw(gc);
        }
    } catch (InterruptedException | ExecutionException e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.atError().setCause(e).log("marchingSquares algorithm");
        }
    } finally {
        gc.restore();
    }
}