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.

300 lines (298 loc) 9.59 kB
import { Align, DashPathEffect } from '@nativescript-community/ui-canvas'; import { IAxisValueFormatter } from '../formatter/IAxisValueFormatter'; import { CustomRenderer } from '../renderer/AxisRenderer'; import { ComponentBase } from './ComponentBase'; import { LimitLine } from './LimitLine'; import { Chart } from '../charts/Chart'; /** * Base-class of all axes (previously called labels). * */ export declare abstract class AxisBase extends ComponentBase { /** * custom formatter that is used instead of the auto-formatter if set */ protected mAxisValueFormatter: IAxisValueFormatter; /** * the color of the grid lines for this axis (the horizontal lines * coming from each label). */ gridColor: string; /** * the width of the grid lines that are drawn away from each axis * label. */ gridLineWidth: number; /** * the color of the border surrounding the chart. */ axisLineColor: string; /** * the width of the border surrounding the chart in dp. */ axisLineWidth: number; /** * the actual array of entries */ mEntries: number[]; mLabels: string[]; /** * axis label entries only used for centered labels */ mCenteredEntries: number[]; /** * the number of entries the legend contains */ mEntryCount: number; /** * the number of decimal digits to use */ mDecimals: number; /** * the number of label entries the axis should have, default 6 */ labelCount: number; /** * the labels text alignment of the axis labels. */ labelTextAlign: Align; /** * the minimum interval between axis values * When set, axis labels are controlled by the `granularity` property. * When not set, axis values could possibly be repeated. * This could happen if two adjacent axis values are rounded to same value. * If using granularity this could be aed by having fewer axis values visible. */ granularity: number; forcedInterval: number; /** * if true, the set number of y-labels will be forced */ forceLabelsEnabled: boolean; /** * flag indicating if the grid lines for this axis should be drawn */ drawGridLines: boolean; /** * flag that indicates if the line alongside the axis is drawn or not */ drawAxisLine: boolean; /** * flag that indicates of the labels of this axis should be drawn or not */ drawLabels: boolean; /** * Centers the axis labels instead of drawing them at their original position. * This is useful especially for grouped BarChart. */ centerAxisLabels: boolean; ensureLastLabel: boolean; allowLastLabelAboveMax: boolean; /** * the path effect of the axis line that makes dashed lines possible */ axisLineDashPathEffect: DashPathEffect; /** * the path effect of the grid lines that makes dashed lines possible */ gridDashPathEffect: DashPathEffect; /** * array of limit lines that can be set for the axis */ protected mLimitLines: LimitLine[]; /** * flag indicating if the limit lines are drawn */ drawLimitLines: boolean; /** * When enabled the LimitLines are drawn behind the actual data, * otherwise on top. Default: false * * @param enabled */ drawLimitLinesBehindData: boolean; /** * When enabled the limitlines will be clipped to contentRect, * otherwise they can bleed outside the content rect. */ clipLimitLinesToContent: boolean; /** * When enabled the labels are drawn behind the actual data, * otherwise on top. Default: false */ drawLabelsBehindData: boolean; /** * When enabled the grid lines are draw on top of the actual data, * otherwise behind. Default: true */ drawGridLinesBehindData: boolean; /** * flag indicating the mark ticks should be drawn */ drawMarkTicks: boolean; /** * Extra spacing for `axisMinimum` to be added to automatically calculated `axisMinimum` */ spaceMin: number; /** * Extra spacing for `axisMaximum` to be added to automatically calculated `axisMaximum` */ spaceMax: number; /** * flag indicating that the axis-min value has been customized */ protected mCustomAxisMin: boolean; /** * flag indicating that the axis-max value has been customized */ protected mCustomAxisMax: boolean; /** * don't touch this direclty, use setter */ protected mAxisMaximum: number; /** * don't touch this directly, use setter */ protected mAxisMinimum: number; /** * Set a suggested maximum value for this axis. If set, this will be used * as maximum is no value is greater than it. */ axisSuggestedMaximum: number; /** * Set a suggested minimum value for this axis. If set, this will be used * as minimum is no value is greater than it. */ axisSuggestedMinimum: number; /** * the total range of values this axis covers */ axisRange: number; /** * the total range of values this axis covers */ ignoreOffsets: boolean; /** * custom line renderer */ customRenderer: CustomRenderer; /** * chart it belongs to */ chart: WeakRef<Chart<any, any, any>>; /** * default constructor */ constructor(chart: WeakRef<Chart<any, any, any>>); /** * Adds a new LimitLine to this axis. * * @param l */ addLimitLine(l: LimitLine): void; /** * Removes the specified LimitLine from the axis. * * @param l */ removeLimitLine(l: LimitLine): void; /** * Removes all LimitLines from the axis. */ removeAllLimitLines(): void; /** * Returns the LimitLines of this axis. */ get limitLines(): LimitLine[]; /** * Returns the longest formatted label (in terms of characters), this axis * contains. */ get longestLabel(): string; getFormattedLabel(index: any): string; /** * Sets the formatter to be used for formatting the axis labels. If no formatter is set, the * chart will * automatically determine a reasonable formatting (concerning decimals) for all the values * that are drawn inside * the chart. Use chart.defaultValueFormatter to use the formatter calculated by the chart. * * @param f */ set valueFormatter(f: IAxisValueFormatter); /** * Returns the formatter used for formatting the axis labels. */ get valueFormatter(): IAxisValueFormatter; /** * Enables the grid 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) */ enableGridDashedLine(lineLength: any, spaceLength: any, phase: any): void; /** * Enables the axis 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) */ enableAxisLineDashedLine(lineLength: any, spaceLength: any, phase: any): void; /** * ###### BELOW CODE RELATED TO CUSTOM AXIS VALUES ###### */ /** * By calling this method, any custom maximum value that has been previously set is reseted, * and the calculation is * done automatically. */ resetAxisMaximum(): void; /** * Returns true if the axis max value has been customized (and is not calculated automatically) */ isAxisMaxCustom(): boolean; /** * By calling this method, any custom minimum value that has been previously set is reseted, * and the calculation is * done automatically. */ resetAxisMinimum(): void; /** * Returns true if the axis min value has been customized (and is not calculated automatically) */ isAxisMinCustom(): boolean; /** * Set a custom minimum value for this axis. If set, this value will not be calculated * automatically depending on * the provided data. Use resetAxisMinValue() to undo this. Do not forget to call * setStartAtZero(false) if you use * this method. Otherwise, the axis-minimum value will still be forced to 0. * * @param min */ set axisMinimum(min: number); get axisMinimum(): number; get axisMaximum(): number; /** * Set a custom maximum value for this axis. If set, this value will not be calculated * automatically depending on * the provided data. Use resetAxisMaxValue() to undo this. * * @param max */ set axisMaximum(max: number); /** * Calculates the minimum / maximum and range values of the axis with the given * minimum and maximum values from the chart data. * * @param dataMin the min value according to chart data * @param dataMax the max value according to chart data */ calculate(dataMin: any, dataMax: any): void; }