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.

110 lines (109 loc) 3.92 kB
import Shape from '@nativescript-community/ui-canvas/shapes/shape'; import { Utils } from '../utils/Utils'; import { Renderer } from './Renderer'; /** * Superclass of all render classes for the different data types (line, bar, ...). * */ export class DataRenderer extends Renderer { constructor(animator, viewPortHandler) { super(viewPortHandler); this.animator = animator; } initBuffers() { } get renderPaint() { if (!this.mRenderPaint) { this.mRenderPaint = Utils.getTemplatePaint('black-fill'); } return this.mRenderPaint; } get highlightPaint() { if (!this.mHighlightPaint) { this.mHighlightPaint = Utils.getTemplatePaint('black-stroke'); this.mHighlightPaint.setStrokeWidth(2); this.mHighlightPaint.setColor('#FFBB73'); } return this.mHighlightPaint; } get valuePaint() { if (!this.mValuePaint) { this.mValuePaint = Utils.getTemplatePaint('value'); } return this.mValuePaint; } isDrawingValuesAllowed(chart) { return chart.data.entryCount < chart.maxVisibleValueCount * this.mViewPortHandler.getScaleX(); } /** * Applies the required styling (provided by the DataSet) to the value-paint * object. * * @param set */ applyValueTextStyle(set) { const typeface = set.valueTypeface; if (typeface) { this.valuePaint.setTypeface(typeface); } this.valuePaint.setTextSize(set.valueTextSize); } /** * Draws the value of the given entry by using the provided IValueFormatter. * * @param c canvas * @param entryIndex label to draw * @param entry label to draw * @param valueText label to draw * @param x position * @param y position * @param color * @param paint */ drawValue(c, chart, dataSet, dataSetIndex, entry, entryIndex, valueText, x, y, color, paint, customRender) { if (valueText) { if (customRender && customRender.drawValue) { customRender.drawValue(c, chart, dataSet, dataSetIndex, entry, entryIndex, valueText, x, y, color, paint); } else { paint.setColor(color); c.drawText(valueText, x, y, paint); } } } /** * Draws the icons of the given entry * * @param canvas canvas * @param icon icon to draw * @param chart icon to draw * @param x position * @param y position * @param color * @param paint */ drawIcon(canvas, chart, dataSet, dataSetIndex, entry, entryIndex, icon, x, y, customRender) { if (icon) { if (customRender && customRender.drawIcon) { customRender.drawIcon(canvas, chart, dataSet, dataSetIndex, entry, entryIndex, icon, x, y); } else { if (icon instanceof Shape) { const availableWidth = canvas.getWidth(); const availableHeight = canvas.getHeight(); const width = icon.getWidth(availableWidth, availableHeight); const height = icon.getHeight(availableWidth, availableHeight); canvas.save(); canvas.translate(x - width / 2, y - height / 2); icon.drawMyShapeOnCanvas(canvas, chart, availableWidth, availableHeight); canvas.restore(); } else { const drawOffsetX = x - icon.width / 2; const drawOffsetY = y - icon.height / 2; canvas.drawBitmap(__ANDROID__ ? icon.android : icon, drawOffsetX, drawOffsetY, null); } } } } } //# sourceMappingURL=DataRenderer.js.map