Java Code Examples for javafx.scene.canvas.GraphicsContext#save()
The following examples show how to use
javafx.scene.canvas.GraphicsContext#save() .
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: PlainAmpSkin.java From Medusa with Apache License 2.0 | 6 votes |
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 2
Source File: ConcentricRingChart.java From charts with Apache License 2.0 | 6 votes |
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 3
Source File: DefaultControlTreeItemGraphic.java From arma-dialog-creator with MIT License | 6 votes |
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 4
Source File: ComparisonRingChart.java From charts with Apache License 2.0 | 6 votes |
private void drawTextAlongArc(final boolean UPPER, 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)); double offset = UPPER ? 90 : -90; if (ANGLE + offset > 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 |
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: Helper.java From Medusa with Apache License 2.0 | 5 votes |
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 7
Source File: ContourDataSetRenderer.java From chart-fx with Apache License 2.0 | 5 votes |
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: AbstractAxis.java From chart-fx with Apache License 2.0 | 5 votes |
protected static void drawAxisLabel(final GraphicsContext gc, final double x, final double y, final Text label) { gc.save(); gc.setTextAlign(label.getTextAlignment()); gc.setFont(label.getFont()); gc.setFill(label.getFill()); gc.setStroke(label.getStroke()); gc.setLineWidth(label.getStrokeWidth()); gc.translate(x, y); gc.rotate(label.getRotate()); gc.fillText(label.getText(), 0, 0); gc.restore(); }
Example 9
Source File: ChartCanvas.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Draws the content of the canvas and updates the * {@code renderingInfo} attribute with the latest rendering * information. */ public final void draw() { GraphicsContext ctx = getGraphicsContext2D(); ctx.save(); double width = getWidth(); double height = getHeight(); if (width > 0 && height > 0) { ctx.clearRect(0, 0, width, height); this.info = new ChartRenderingInfo(); this.chart.draw(this.g2, new Rectangle((int) width, (int) height), this.anchor, this.info); } ctx.restore(); this.anchor = null; }
Example 10
Source File: Hexagon.java From chart-fx with Apache License 2.0 | 5 votes |
public void draw(GraphicsContext gc) { gc.save(); gc.setStroke(getStroke()); gc.setLineWidth(getStrokeWidth()); gc.setFill(getFill()); drawHexagon(gc); gc.restore(); }
Example 11
Source File: Helper.java From charts with Apache License 2.0 | 5 votes |
public static final void drawTextWithBackground(final GraphicsContext CTX, final String TEXT, final Font FONT, final Color TEXT_BACKGROUND, final Color TEXT_FILL, final double X, final double Y) { CtxDimension dim = getTextDimension(TEXT, FONT); double textWidth = dim.getWidth() * 1.2; double textHeight = dim.getHeight(); CTX.save(); CTX.setFont(FONT); CTX.setTextBaseline(VPos.CENTER); CTX.setTextAlign(TextAlignment.CENTER); CTX.setFill(TEXT_BACKGROUND); CTX.fillRect(X - textWidth * 0.5, Y - textHeight * 0.5, textWidth, textHeight); CTX.setFill(TEXT_FILL); CTX.fillText(TEXT, X, Y); CTX.restore(); }
Example 12
Source File: ArmaAbsoluteBoxComponent.java From arma-dialog-creator with MIT License | 5 votes |
@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 13
Source File: BasicTextRenderer.java From arma-dialog-creator with MIT License | 5 votes |
/** Will paint the text where there renderer wants to. This will also create a clip for the text. The text will be clipped if it exceeds the width of the control. @param gc context to use */ public void paint(GraphicsContext gc) { gc.save(); gc.beginPath(); //don't let the text render past the control's bounds gc.rect(renderer.getLeftX(), renderer.getTopY(), renderer.getWidth(), renderer.getHeight()); gc.closePath(); gc.clip(); paint(gc, getTextX(), getTextY()); gc.restore(); }
Example 14
Source File: AbstractAxis.java From chart-fx with Apache License 2.0 | 4 votes |
protected void drawAxisLine(final GraphicsContext gc, final double axisLength, final double axisWidth, final double axisHeight) { // N.B. axis canvas is (by-design) larger by 'padding' w.r.t. // required/requested axis length (needed for nicer label placements on // border. final double paddingX = getSide().isHorizontal() ? getAxisPadding() : 0.0; final double paddingY = getSide().isVertical() ? getAxisPadding() : 0.0; // for relative positioning of axes drawn on top of the main canvas final double axisCentre = getCenterAxisPosition(); // save css-styled line parameters final Path tickStyle = getMajorTickStyle(); gc.save(); gc.setStroke(tickStyle.getStroke()); gc.setFill(tickStyle.getFill()); gc.setLineWidth(tickStyle.getStrokeWidth()); // N.B. important: translate by padding ie. canvas is +padding larger on // all size compared to region gc.translate(paddingX, paddingY); switch (getSide()) { case LEFT: // axis line on right side of canvas gc.strokeLine(snap(axisWidth), snap(0), snap(axisWidth), snap(axisLength)); break; case RIGHT: // axis line on left side of canvas gc.strokeLine(snap(0), snap(0), snap(0), snap(axisLength)); break; case TOP: // line on bottom side of canvas (N.B. (0,0) is top left corner) gc.strokeLine(snap(0), snap(axisHeight), snap(axisLength), snap(axisHeight)); break; case BOTTOM: // line on top side of canvas (N.B. (0,0) is top left corner) gc.strokeLine(snap(0), snap(0), snap(axisLength), snap(0)); break; case CENTER_HOR: // axis line at the centre of the canvas gc.strokeLine(snap(0), axisCentre * axisHeight, snap(axisLength), snap(axisCentre * axisHeight)); break; case CENTER_VER: // axis line at the centre of the canvas gc.strokeLine(snap(axisCentre * axisWidth), snap(0), snap(axisCentre * axisWidth), snap(axisLength)); break; default: break; } gc.restore(); }
Example 15
Source File: ColorGradientAxis.java From chart-fx with Apache License 2.0 | 4 votes |
@Override protected void drawAxisLine(final GraphicsContext gc, final double axisLength, final double axisWidth, final double axisHeight) { // N.B. axis canvas is (by-design) larger by 'padding' w.r.t. // required/requested axis length (needed for nicer label placements on // border. final double paddingX = getSide().isHorizontal() ? getAxisPadding() : 0.0; final double paddingY = getSide().isVertical() ? getAxisPadding() : 0.0; // for relative positioning of axes drawn on top of the main canvas final double axisCentre = getCenterAxisPosition(); final double gradientWidth = getGradientWidth(); // save css-styled line parameters final Path tickStyle = getMajorTickStyle(); gc.save(); gc.setStroke(tickStyle.getStroke()); gc.setLineWidth(tickStyle.getStrokeWidth()); if (getSide().isHorizontal()) { gc.setFill(new LinearGradient(0, 0, axisLength, 0, false, NO_CYCLE, getColorGradient().getStops())); } else { gc.setFill(new LinearGradient(0, axisLength, 0, 0, false, NO_CYCLE, getColorGradient().getStops())); } // N.B. important: translate by padding ie. canvas is +padding larger on // all size compared to region gc.translate(paddingX, paddingY); switch (getSide()) { case LEFT: // axis line on right side of canvas gc.fillRect(snap(axisWidth - gradientWidth), snap(0), snap(axisWidth), snap(axisLength)); gc.strokeRect(snap(axisWidth - gradientWidth), snap(0), snap(axisWidth), snap(axisLength)); break; case RIGHT: // axis line on left side of canvas gc.fillRect(snap(0), snap(0), snap(gradientWidth), snap(axisLength)); gc.strokeRect(snap(0), snap(0), snap(gradientWidth), snap(axisLength)); break; case TOP: // line on bottom side of canvas (N.B. (0,0) is top left corner) gc.fillRect(snap(0), snap(axisHeight - gradientWidth), snap(axisLength), snap(axisHeight)); gc.strokeRect(snap(0), snap(axisHeight - gradientWidth), snap(axisLength), snap(axisHeight)); break; case BOTTOM: // line on top side of canvas (N.B. (0,0) is top left corner) gc.rect(snap(0), snap(0), snap(axisLength), snap(gradientWidth)); break; case CENTER_HOR: // axis line at the centre of the canvas gc.fillRect(snap(0), axisCentre * axisHeight - 0.5 * gradientWidth, snap(axisLength), snap(axisCentre * axisHeight + 0.5 * gradientWidth)); gc.strokeRect(snap(0), axisCentre * axisHeight - 0.5 * gradientWidth, snap(axisLength), snap(axisCentre * axisHeight + 0.5 * gradientWidth)); break; case CENTER_VER: // axis line at the centre of the canvas gc.fillRect(snap(axisCentre * axisWidth - 0.5 * gradientWidth), snap(0), snap(axisCentre * axisWidth + 0.5 * gradientWidth), snap(axisLength)); gc.strokeRect(snap(axisCentre * axisWidth - 0.5 * gradientWidth), snap(0), snap(axisCentre * axisWidth + 0.5 * gradientWidth), snap(axisLength)); break; default: break; } gc.restore(); }
Example 16
Source File: QuarterSkin.java From Medusa with Apache License 2.0 | 4 votes |
private void drawAreasAndSections(final GraphicsContext CTX) { if (areas.isEmpty() && sections.isEmpty()) return; double value = gauge.getCurrentValue(); Pos knobPosition = gauge.getKnobPosition(); double scaledSize = size * 1.9; double offset = 90 - startAngle; double offsetX; double offsetY; double xy; double wh; int listSize; // Draw Areas if (areasVisible && !areas.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.078 * scaledSize : 0.0125 * scaledSize; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledSize * 0.846 : scaledSize * 0.97; offsetX = Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? 0 : -scaledSize * 0.475; offsetY = Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.475 : 0; 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 + offsetX, xy + offsetY, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND); CTX.restore(); } } } // Draw Sections if (sectionsVisible && !sections.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.11675 * scaledSize : 0.03265 * scaledSize; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? scaledSize * 0.7745 : scaledSize * 0.935; offsetX = TickLabelLocation.OUTSIDE == tickLabelLocation ? ( Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.0045 : -scaledSize * 0.4770 ) : ( Pos.BOTTOM_RIGHT == knobPosition || Pos.TOP_RIGHT == knobPosition ? 0 : -scaledSize * 0.4738 ); offsetY = TickLabelLocation.OUTSIDE == tickLabelLocation ? ( Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.4770 : -scaledSize * 0.0045 ) : ( Pos.TOP_LEFT == knobPosition || Pos.TOP_RIGHT == knobPosition ? -scaledSize * 0.4738 : 0 ); listSize = sections.size(); CTX.setLineWidth(scaledSize * 0.04); 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 + offsetX, xy + offsetY, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN); CTX.restore(); } } } }
Example 17
Source File: InteractiveGaugeSkin.java From medusademo with Apache License 2.0 | 4 votes |
private void drawAreasAndSections(final GraphicsContext CTX) { if (areas.isEmpty() && sections.isEmpty()) return; double value = getSkinnable().getCurrentValue(); double offset = 90 - startAngle; double xy; double wh; int listSize; // Draw Areas if (areasVisible && !areas.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.0895 * size : 0.025 * size; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.821 : size * 0.95; 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, wh, wh, -(offset + areaStartAngle), - areaAngleExtend, ArcType.ROUND); CTX.restore(); } } } // Draw Sections if (sectionsVisible && !sections.isEmpty()) { xy = TickLabelLocation.OUTSIDE == tickLabelLocation ? 0.115 * size : 0.0515 * size; wh = TickLabelLocation.OUTSIDE == tickLabelLocation ? size * 0.77 : size * 0.897; listSize = sections.size(); CTX.setLineWidth(size * 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, wh, wh, -(offset + sectionStartAngle), -sectionAngleExtend, ArcType.OPEN); CTX.restore(); } } } }
Example 18
Source File: BulletChartSkin.java From Medusa with Apache License 2.0 | 4 votes |
private void drawTickMarks(final GraphicsContext CTX) { tickMarkCanvas.setCache(false); CTX.clearRect(0, 0, tickMarkCanvas.getWidth(), tickMarkCanvas.getHeight()); CTX.setFill(gauge.getMajorTickMarkColor()); List<Section> tickMarkSections = gauge.getTickMarkSections(); List<Section> tickLabelSections = gauge.getTickLabelSections(); Color majorTickMarkColor = gauge.getTickMarkColor(); Color tickLabelColor = gauge.getTickLabelColor(); boolean smallRange = Double.compare(gauge.getRange(), 10.0) <= 0; double minValue = gauge.getMinValue(); double maxValue = gauge.getMaxValue(); double tmpStepSize = smallRange ? stepSize / 10 : stepSize; Font tickLabelFont = Fonts.robotoRegular(0.1 * size); boolean tickMarkSectionsVisible = gauge.getTickMarkSectionsVisible(); boolean tickLabelSectionsVisible = gauge.getTickLabelSectionsVisible(); double offsetX = 0.18345865 * width; double offsetY = 0.1 * height; double innerPointX = 0; double innerPointY = 0; double outerPointX = 0.07 * width; double outerPointY = 0.08 * height; double textPointX = Orientation.HORIZONTAL == orientation ? 0.55 * tickMarkCanvas.getWidth() : outerPointX + size * 0.05; double textPointY = 0.7 * tickMarkCanvas.getHeight(); BigDecimal minorTickSpaceBD = BigDecimal.valueOf(gauge.getMinorTickSpace()); BigDecimal majorTickSpaceBD = BigDecimal.valueOf(gauge.getMajorTickSpace()); BigDecimal counterBD = BigDecimal.valueOf(gauge.getMinValue()); double counter = minValue; double range = gauge.getRange(); for (double i = 0 ; Double.compare(i, range) <= 0 ; i++) { if (Orientation.VERTICAL == orientation) { innerPointY = counter * tmpStepSize + offsetY; outerPointY = innerPointY; textPointY = innerPointY; } else { innerPointX = counter * tmpStepSize + offsetX; outerPointX = innerPointX; textPointX = innerPointX; } // Set the general tickmark color CTX.setStroke(gauge.getTickMarkColor()); if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) { // Draw major tick mark if (gauge.getMajorTickMarksVisible()) { CTX.setFill(tickMarkSectionsVisible ? Helper.getColorOfSection(tickMarkSections, counter, majorTickMarkColor) : majorTickMarkColor); CTX.setStroke(tickMarkSectionsVisible ? Helper.getColorOfSection(tickMarkSections, counter, majorTickMarkColor) : majorTickMarkColor); CTX.setLineWidth(1); CTX.strokeLine(innerPointX, innerPointY, outerPointX, outerPointY); } // Draw tick label text if (gauge.getTickLabelsVisible()) { CTX.save(); CTX.translate(textPointX, textPointY); CTX.setFont(tickLabelFont); CTX.setTextAlign(Orientation.HORIZONTAL == orientation ? TextAlignment.CENTER : TextAlignment.LEFT); CTX.setTextBaseline(VPos.CENTER); CTX.setFill(tickLabelSectionsVisible ? Helper.getColorOfSection(tickLabelSections, counter, tickLabelColor) : tickLabelColor); if (Orientation.VERTICAL == orientation) { CTX.fillText(Integer.toString((int) (maxValue - counter)), 0, 0); } else { CTX.fillText(Integer.toString((int) counter), 0, 0); } CTX.restore(); } } counterBD = counterBD.add(minorTickSpaceBD); counter = counterBD.doubleValue(); if (counter > maxValue) break; } tickMarkCanvas.setCache(true); tickMarkCanvas.setCacheHint(CacheHint.QUALITY); }
Example 19
Source File: LabelledMarkerRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
/** * Draws vertical markers with vertical (default) labels attached to the top * * @param gc the graphics context from the Canvas parent * @param chart instance of the calling chart * @param dataSet instance of the data set that is supposed to be drawn * @param indexMin minimum index of data set to be drawn * @param indexMax maximum index of data set to be drawn */ protected void drawVerticalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet, final int indexMin, final int indexMax) { Axis xAxis = this.getFirstAxis(Orientation.HORIZONTAL); if (xAxis == null) { xAxis = chart.getFirstAxis(Orientation.HORIZONTAL); } if (xAxis == null) { if (LOGGER.isWarnEnabled()) { LOGGER.atWarn().addArgument(LabelledMarkerRenderer.class.getSimpleName()).log("{}::drawVerticalLabelledMarker(...) getFirstAxis(HORIZONTAL) returned null skip plotting"); } return; } gc.save(); setGraphicsContextAttributes(gc, dataSet.getStyle()); gc.setTextAlign(TextAlignment.LEFT); final double height = chart.getCanvas().getHeight(); double lastLabel = -Double.MAX_VALUE; double lastFontSize = 0; for (int i = indexMin; i < indexMax; i++) { final double screenX = (int) xAxis.getDisplayPosition(dataSet.get(DataSet.DIM_X, i)); final String label = dataSet.getDataLabel(i); if (label == null) { continue; } final String pointStyle = dataSet.getStyle(i); if (pointStyle != null) { gc.save(); setGraphicsContextAttributes(gc, pointStyle); } gc.strokeLine(screenX, 0, screenX, height); if (Math.abs(screenX - lastLabel) > lastFontSize && !label.isEmpty()) { gc.save(); gc.setLineWidth(0.8); gc.setLineDashes(1.0); gc.translate(Math.ceil(screenX + 3), Math.ceil(0.01 * height)); gc.rotate(+90); gc.fillText(label, 0.0, 0); gc.restore(); lastLabel = screenX; lastFontSize = gc.getFont().getSize(); } if (pointStyle != null) { gc.restore(); } } gc.restore(); }
Example 20
Source File: LabelledMarkerRenderer.java From chart-fx with Apache License 2.0 | 4 votes |
/** * Draws horizontal markers with horizontal (default) labels attached to the top * * @param gc the graphics context from the Canvas parent * @param chart instance of the calling chart * @param dataSet instance of the data set that is supposed to be drawn * @param indexMin minimum index of data set to be drawn * @param indexMax maximum index of data set to be drawn */ protected void drawHorizontalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet, final int indexMin, final int indexMax) { final Axis yAxis = this.getFirstAxis(Orientation.VERTICAL, chart); gc.save(); setGraphicsContextAttributes(gc, dataSet.getStyle()); gc.setTextAlign(TextAlignment.RIGHT); final double width = chart.getCanvas().getWidth(); double lastLabel = -Double.MAX_VALUE; double lastFontSize = 0; for (int i = indexMin; i < indexMax; i++) { final double screenY = (int) yAxis.getDisplayPosition(dataSet.get(DataSet.DIM_Y, i)); final String label = dataSet.getDataLabel(i); if (label == null) { continue; } final String pointStyle = dataSet.getStyle(i); if (pointStyle != null) { gc.save(); setGraphicsContextAttributes(gc, pointStyle); } gc.strokeLine(0, screenY, width, screenY); if (Math.abs(screenY - lastLabel) > lastFontSize && !label.isEmpty()) { gc.save(); gc.setLineWidth(0.8); gc.setLineDashes(1.0); gc.translate(Math.ceil(screenY + 3), Math.ceil(0.99 * width)); gc.fillText(label, 0.0, 0); gc.restore(); lastLabel = screenY; lastFontSize = gc.getFont().getSize(); } if (pointStyle != null) { gc.restore(); } } gc.restore(); }