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.

109 lines 3.46 kB
import { BarLineScatterCandleBubbleDataSet } from './BarLineScatterCandleBubbleDataSet'; import { Utils } from '../utils/Utils'; export class BarDataSet extends BarLineScatterCandleBubbleDataSet { constructor(values, label, xProperty, yProperty) { super(values, label, xProperty, yProperty); /** * the color used for drawing the bar shadows */ this.barShadowColor = '#D7D7D7'; /** * Sets the width used for drawing borders around the bars. * If borderWidth === 0, no border will be drawn. */ this.barBorderWidth = 0.0; /** * Sets the color drawing borders around the bars. */ this.barBorderColor = 'black'; /** * the alpha value used to draw the highlight indicator bar */ this.highLightAlpha = 120; /** * array of labels used to describe the different values of the stacked bars */ this.stackLabels = ['Stack']; this.highlightColor = 'black'; this.init(); } calcEntryRanges(e) { const values = e.yVals; if (!values || values.length === 0) return; e.ranges = []; let negRemain = -e.negativeSum; let posRemain = 0; for (let i = 0; i < values.length; i++) { const value = values[i]; if (value < 0) { e.ranges.push([negRemain, negRemain - value]); negRemain -= value; } else { e.ranges.push([posRemain, posRemain + value]); posRemain += value; } } } initEntryData(e) { super.initEntryData(e); const vals = e.yVals; // Defaults this.mStackSize = 1; this.mEntryCountStacks = 0; const sums = Utils.calcPosNegSum(vals); e.positiveSum = sums.pos; e.negativeSum = sums.neg; if (!vals || vals.length === 0) { this.mEntryCountStacks++; } else { // Get stack-based y value e[this.yProperty] = Utils.calcSum(vals); e.isStacked = true; // Get ranges this.calcEntryRanges(e); this.mEntryCountStacks += vals.length; // Always use highest stack size if (vals.length > this.mStackSize) { this.mStackSize = vals.length; } } } calcMinMaxForEntry(e, index) { if (!e) return; const yProperty = this.yProperty; const yVal = e?.[yProperty]; if (e && !isNaN(yVal)) { if (!e.yVals) { if (yVal < this.mYMin) this.mYMin = yVal; if (yVal > this.mYMax) this.mYMax = yVal; } else { if (-e.negativeSum < this.mYMin) this.mYMin = -e.negativeSum; if (e.positiveSum > this.mYMax) this.mYMax = e.positiveSum; } this.calcMinMaxX(e); } } get stackSize() { return this.mStackSize; } get stacked() { return this.mStackSize > 1; } /** * returns the overall entry count, including counting each stack-value * individually */ get entryCountStacks() { return this.mEntryCountStacks; } } //# sourceMappingURL=BarDataSet.js.map