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.

148 lines 5.28 kB
import { DashPathEffect } from '@nativescript-community/ui-canvas'; import { createLTTB } from 'downsample/methods/LTTB'; import { DefaultFillFormatter } from '../formatter/DefaultFillFormatter'; import { ColorTemplate } from '../utils/ColorTemplate'; import { LineRadarDataSet } from './LineRadarDataSet'; export var Mode; (function (Mode) { Mode[Mode["LINEAR"] = 0] = "LINEAR"; Mode[Mode["STEPPED"] = 1] = "STEPPED"; Mode[Mode["CUBIC_BEZIER"] = 2] = "CUBIC_BEZIER"; Mode[Mode["HORIZONTAL_BEZIER"] = 3] = "HORIZONTAL_BEZIER"; })(Mode || (Mode = {})); export class LineDataSet extends LineRadarDataSet { constructor(yVals, label, xProperty, yProperty) { super(yVals, label, xProperty, yProperty); /** * Drawing mode for this line dataset **/ this.mode = Mode.LINEAR; /** * List representing all colors that are used for the circles */ this.circleColors = []; /** * the color of the inner circles */ this.circleHoleColor = ColorTemplate.COLOR_NONE; /** * the radius of the circle-shaped value indicators */ this.circleRadius = 4; /** * the hole radius of the circle-shaped value indicators */ this.circleHoleRadius = 2; /** * sets the intensity of the cubic lines (if enabled). Max = 1 = very cubic, * Min = 0.05f = low cubic effect, Default: 0.2f */ this.cubicIntensity = 0.2; /** * the path effect of this DataSet that makes dashed lines possible */ this.dashPathEffect = null; /** * the path effect of this DataSet that makes dashed lines possible */ this.shader = null; /** * formatter for customizing the position of the fill-line */ this.fillFormatter = new DefaultFillFormatter(); /** * if true, drawing circles is enabled */ this.drawCirclesEnabled = false; this.drawCircleHoleEnabled = true; this.useColorsForFill = false; this.useColorsForLine = false; /** * the max number allowed point before filtering. <= O means disabled */ this.maxFilterNumber = 0; this.mFilteredValues = null; this.mIgnoreFiltered = false; /** * Property definining wheter circles are drawn in high res. * Default true */ this.circleHighRes = true; this.init(); } getCircleColor(index) { return this.circleColors[Math.floor(index)] || this.color; } /** * Sets the colors that should be used for the circles of this DataSet. * Colors are reused as soon as the number of Entries the DataSet represents * is higher than the size of the colors array. Make sure that the colors * are already prepared (by calling getResources().getColor(...)) before * adding them to the DataSet. * * @param colors */ setCircleColors(colors) { this.circleColors = colors; } /** * Sets the one and ONLY color that should be used for this DataSet. * Internally, this recreates the colors array and adds the specified color. * * @param color */ set circleColor(color) { this.circleColors = [color]; } applyFiltering(scaleX) { if (this.maxFilterNumber > 0 && this.mValues.length / scaleX > this.maxFilterNumber) { const filterCount = Math.round(this.maxFilterNumber * scaleX); if (!this.mFilteredValues || this.mFilteredValues.length !== filterCount) { if (!this.mFilterFunction) { this.mFilterFunction = createLTTB({ x: this.xProperty, y: this.yProperty }); } this.mFilteredValues = this.mFilterFunction(this.mValues, filterCount); } } else if (this.mFilteredValues) { this.mFilteredValues = null; } this.updateGetEntryForIndex(); } getInternalValues() { if (this.mFilteredValues && !this.mIgnoreFiltered) { return this.mFilteredValues; } return this.mValues; } set ignoreFiltered(value) { this.mIgnoreFiltered = value; this.updateGetEntryForIndex(); } get ignoreFiltered() { return this.mIgnoreFiltered; } set values(values) { this.mFilteredValues = null; super.values = values; } get filtered() { return !!this.mFilteredValues; } /** * Enables the line to be drawn in dashed mode, e.g. like this * "- - - - - -". THIS ONLY WORKS IF HARDWARE-ACCELERATION IS TURNED OFF. * Keep in mind that hardware acceleration boosts performance. * * @param lineLength the length of the line pieces * @param spaceLength the length of space in between the pieces * @param phase offset, in degrees (normally, use 0) */ enableDashedLine(lineLength, spaceLength, phase) { this.dashPathEffect = new DashPathEffect([lineLength, spaceLength], phase); } } //# sourceMappingURL=LineDataSet.js.map