UNPKG

@nativescript-community/ui-chart

Version:

A powerful chart / graph plugin, supporting line, bar, pie, radar, bubble, and candlestick charts as well as scaling, panning and animations.

76 lines 3 kB
import { Rect, Style } from '@nativescript-community/ui-canvas'; import { Color } from '@nativescript/core'; import { Utils } from '../utils/Utils'; import { LineScatterCandleRadarRenderer } from './LineScatterCandleRadarRenderer'; /** * Created by Philipp Jahoda on 25/01/16. */ export class LineRadarRenderer extends LineScatterCandleRadarRenderer { constructor(animator, viewPortHandler) { super(animator, viewPortHandler); } /** * Draws the provided path in filled mode with the provided drawable. * * @param c * @param filledPath * @param drawable */ drawFilledPathBitmap(c, filledPath, drawable, shader) { if (Utils.clipPathSupported()) { const save = c.save(); // c.scale(1, 1/SCALE_FACTOR, 0, this.mViewPortHandler.contentBottom) c.clipPath(filledPath); // drawable.setBounds(this.mViewPortHandler.contentLeft, this.mViewPortHandler.contentTop, this.mViewPortHandler.contentRight, this.mViewPortHandler.contentBottom); // drawable.draw(c); c.drawBitmap(drawable, new Rect(0, 0, drawable.width, drawable.height), new Rect(this.mViewPortHandler.contentLeft, this.mViewPortHandler.contentTop, this.mViewPortHandler.contentRight, this.mViewPortHandler.contentBottom), null); c.restoreToCount(save); } else { throw new Error('Fill-drawables not (yet) supported below API level 18 '); } } drawPath(canvas, path, paint) { canvas.drawPath(path, paint); } /** * Draws the provided path in filled mode with the provided color and alpha. * Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this. * * @param c * @param filledPath * @param fillColor * @param fillAlpha */ drawFilledPath(c, filledPath, fillColor, fillAlpha = 255, shader) { let color = fillColor; if (fillAlpha < 255) { fillColor = fillColor instanceof Color ? fillColor : new Color(fillColor); color = new Color(fillAlpha, fillColor.r, fillColor.g, fillColor.b); } const renderPaint = this.renderPaint; // save const previous = renderPaint.getStyle(); const previousColor = renderPaint.getColor(); const previousShader = renderPaint.getShader(); renderPaint.setStyle(Style.FILL); renderPaint.setColor(color); if (shader) { renderPaint.setShader(shader); } if (Utils.clipPathSupported()) { const save = c.save(); c.clipPath(filledPath); c.drawPaint(renderPaint); c.restoreToCount(save); } else { this.drawPath(c, filledPath, renderPaint); } // restore renderPaint.setColor(previousColor); renderPaint.setShader(previousShader); renderPaint.setStyle(previous); } } //# sourceMappingURL=LineRadarRenderer.js.map