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.

119 lines (118 loc) 4.09 kB
import { CombinedHighlighter } from '../highlight/CombinedHighlighter'; import { BarLineChartBase } from './BarLineChartBase'; import { CombinedChartRenderer } from '../renderer/CombinedChartRenderer'; /** * enum that allows to specify the order in which the different data objects * for the combined-chart are drawn */ export var DrawOrder; (function (DrawOrder) { DrawOrder[DrawOrder["BAR"] = 0] = "BAR"; DrawOrder[DrawOrder["BUBBLE"] = 1] = "BUBBLE"; DrawOrder[DrawOrder["LINE"] = 2] = "LINE"; DrawOrder[DrawOrder["CANDLE"] = 3] = "CANDLE"; DrawOrder[DrawOrder["SCATTER"] = 4] = "SCATTER"; })(DrawOrder || (DrawOrder = {})); /** * This chart class allows the combination of lines, bars, scatter and candle * data all displayed in one chart area. * */ export class CombinedChart extends BarLineChartBase { constructor() { super(...arguments); /** * if set to true, all values are drawn above their bars, instead of below * their top */ this.drawValueAboveBarEnabled = true; } init() { super.init(); // Default values are not ready here yet this.drawOrder = [DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.LINE, DrawOrder.CANDLE, DrawOrder.SCATTER]; this.highlighter = new CombinedHighlighter(this, this); // Old default behaviour this.highlightFullBarEnabled = true; this.renderer = new CombinedChartRenderer(this, this.animator, this.viewPortHandler); } get combinedData() { return this.mData; } set data(data) { super.data = data; // we need to reset highlighter here because it checks for barData // to create BarHighligther this.highlighter = new CombinedHighlighter(this, this); this.renderer.createRenderers(); // if (this.viewPortHandler.hasChartDimens) { this.renderer.initBuffers(); // } } get data() { return this.mData; } /** * Returns the Highlight object (contains x-index and DataSet index) of the selected value at the given touch * point * inside the CombinedChart. * * @param x * @param y * @return */ getHighlightByTouchPoint(x, y) { if (!this.mData) { console.error("Can't select by touch. No data set."); return null; } else { return this.highlighter.getHighlight(x, y)?.[0]; // For isHighlightFullBarEnabled, remove stackIndex // return Object.assign({}, h, {}); } } get lineData() { return this.data?.lineData; } get barData() { return this.data?.barData; } get scatterData() { return this.data?.scatterData; } get candleData() { return this.data?.candleData; } get bubbleData() { return this.data?.bubbleData; } /** * draws all MarkerViews on the highlighted positions */ drawMarkers(c) { // if there is no marker view or drawing marker is disabled if (!this.marker || !this.drawMarkersEnabled || !this.hasValuesToHighlight) return; for (let i = 0; i < this.indicesToHighlight.length; i++) { const highlight = this.indicesToHighlight[i]; const set = this.mData.getDataSetByHighlight(highlight); const e = this.mData.getEntryForHighlight(highlight); if (!e) continue; const entryIndex = set.getEntryIndex(e); // make sure entry not null if (entryIndex > set.entryCount * this.animator.phaseX) continue; const pos = this.getMarkerPosition(highlight); // check bounds if (!this.viewPortHandler.isInBounds(pos[0], pos[1])) continue; // callbacks to update the content this.marker.refreshContent(e, highlight); // draw the marker this.marker.draw(c, pos[0], pos[1]); } } } //# sourceMappingURL=CombinedChart.js.map