@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.
584 lines (583 loc) • 19.1 kB
TypeScript
import { Canvas, Matrix, Paint } from '@nativescript-community/ui-canvas';
import { EventData } from '@nativescript/core';
import { GestureTypes } from '@nativescript/core/ui/gestures';
import { AxisDependency, YAxis } from '../components/YAxis';
import { BarLineScatterCandleBubbleData } from '../data/BarLineScatterCandleBubbleData';
import { Entry } from '../data/Entry';
import { BarLineScatterCandleBubbleDataProvider } from '../interfaces/dataprovider/BarLineScatterCandleBubbleDataProvider';
import { IBarLineScatterCandleBubbleDataSet } from '../interfaces/datasets/IBarLineScatterCandleBubbleDataSet';
import { BarLineChartTouchListener } from '../listener/BarLineChartTouchListener';
import { XAxisRenderer } from '../renderer/XAxisRenderer';
import { YAxisRenderer } from '../renderer/YAxisRenderer';
import { Transformer } from '../utils/Transformer';
import { Chart } from './Chart';
import { IDataSet } from '../interfaces/datasets/IDataSet';
export declare abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatterCandleBubbleDataSet<U>, T extends BarLineScatterCandleBubbleData<U, D>> extends Chart<U, D, T> implements BarLineScatterCandleBubbleDataProvider {
chartTouchListener: BarLineChartTouchListener;
/**
* the maximum number of entries to which values will be drawn
* (entry numbers greater than this value will cause value-labels to disappear)
*/
maxVisibleValueCount: number;
/**
* flag that indicates if auto scaling on the y axis is enabled
*/
autoScaleMinMaxEnabled: boolean;
/**
* flag that indicates if pinch-zoom is enabled. if true, both x and y axis
* can be scaled with 2 fingers, if false, x and y axis can be scaled
* separately
*/
pinchZoomEnabled: boolean;
/**
* flag that indicates if double tap zoom is enabled or not
*/
protected mDoubleTapToZoomEnabled: boolean;
/**
* flag that indicates if highlighting per dragging over a fully zoomed out
* chart is enabled
*/
protected mHighlightPerDragEnabled: boolean;
/**
* flag that indicates zoomed pan gesture should only work with 2 pointers
*/
zoomedPanWith2Pointers: boolean;
/**
* if true, dragging is enabled for the chart
*/
dragXEnabled: boolean;
dragYEnabled: boolean;
private mScaleXEnabled;
private mScaleYEnabled;
/**
* palet object for the (by default) lightgrey background of the grid
*/
protected mGridBackgroundPaint: Paint;
protected mBorderPaint: Paint;
/**
* flag indicating if the grid background should be drawn or not
*/
drawGridBackgroundEnabled: boolean;
drawBorders: boolean;
clipValuesToContent: boolean;
clipDataToContent: boolean;
drawHighlight: boolean;
/**
* Sets the minimum offset (padding) around the chart, defaults to 15
*/
minOffset: number;
/**
* flag indicating if the chart should stay at the same position after a rotation. Default is false.
*/
keepPositionOnRotation: boolean;
/**
* the object representing the labels on the left y-axis
*/
mAxisLeft: YAxis;
/**
* the object representing the labels on the right y-axis
*/
mAxisRight: YAxis;
/**
* axis renderer for the left axis.
*
*/
leftAxisRenderer: YAxisRenderer;
/**
* axis renderer for the right axis.
*
*/
rightAxisRenderer: YAxisRenderer;
/**
* axis renderer for the x axis.
*
*/
xAxisRenderer: XAxisRenderer;
protected leftAxisTransformer: Transformer;
protected rightAxisTransformer: Transformer;
protected init(): void;
get gridBackgroundPaint(): Paint;
get borderPaint(): Paint;
getOrCreateBarTouchListener(): BarLineChartTouchListener;
draw(canvas: Canvas): void;
protected prepareValuePxMatrix(): void;
protected prepareOffsetMatrix(): void;
notifyDataSetChanged(): void;
/**
* Performs auto scaling of the axis by recalculating the minimum and maximum y-values based on the entries currently in view.
*/
protected autoScale(): void;
protected calcMinMax(): void;
protected calculateLegendOffsets(offsets: any): void;
calculateOffsets(force?: boolean): void;
/**
* draws the grid background
*/
protected drawGridBackground(c: Canvas): void;
/**
* Returns the Transformer class that contains all matrices and is
* responsible for transforming values into pixels on the screen and
* backwards.
*/
getTransformer(which?: AxisDependency): Transformer;
get transformer(): Transformer;
/**
* ################ ################ ################ ################
*/
/**
* CODE BELOW THIS RELATED TO SCALING AND GESTURES AND MODIFICATION OF THE
* VIEWPORT
*/
protected mZoomMatrixBuffer: Matrix;
/**
* Zooms in by 1.4f, into the charts center.
*/
zoomIn(): void;
/**
* Zooms out by 0.7f, from the charts center.
*/
zoomOut(): void;
/**
* Zooms out to original size.
*/
resetZoom(): void;
/**
* Zooms in or out by the given scale factor. x and y are the coordinates
* (in pixels) of the zoom center.
*
* @param scaleX if < 1 --> zoom out, if > 1 --> zoom in
* @param scaleY if < 1 --> zoom out, if > 1 --> zoom in
* @param x
* @param y
*/
zoom(scaleX: any, scaleY: any, x: any, y: any): void;
/**
* Zooms in or out by the given scale factor.
* x and y are the values (NOT PIXELS) of the zoom center..
*
* @param scaleX
* @param scaleY
* @param xValue
* @param yValue
* @param axis the axis relative to which the zoom should take place
*/
zoomAtValue(scaleX: any, scaleY: any, xValue: any, yValue: any, axis: any): void;
/**
* Zooms to the center of the chart with the given scale factor.
*
* @param scaleX
* @param scaleY
*/
zoomToCenter(scaleX: any, scaleY: any): void;
/**
* Zooms by the specified scale factor to the specified values on the specified axis.
*
* @param scaleX
* @param scaleY
* @param xValue
* @param yValue
* @param axis
* @param duration
*/
zoomAndCenterAnimated(scaleX: any, scaleY: any, xValue: any, yValue: any, axis: any, duration: any): void;
/**
* Zooms by the specified scale factor to the specified values on the specified axis.
*
* @param scaleX
* @param scaleY
* @param xValue
* @param yValue
* @param axis
*/
zoomAndCenter(scaleX: any, scaleY: any, xValue: any, yValue: any, axis: any): void;
protected mFitScreenMatrixBuffer: Matrix;
/**
* Resets all zooming and dragging and makes the chart fit exactly it's
* bounds.
*/
fitScreen(): void;
/**
* Sets the minimum scale factor value to which can be zoomed out. 1 =
* fitScreen
*
* @param scaleX
* @param scaleY
*/
setScaleMinima(scaleX: any, scaleY: any): void;
/**
* Sets the scale factor. 1 =
* fitScreen
*
* @param scaleX
* @param scaleY
*/
setScale(scaleX: any, scaleY: any): void;
/**
* Sets the size of the area (range on the x-axis) that should be maximum
* visible at once (no further zooming out allowed). If this is e.g. set to
* 10, no more than a range of 10 on the x-axis can be viewed at once without
* scrolling.
*
* @param maxXRange The maximum visible range of x-values.
*/
set visibleXRangeMaximum(maxXRange: any);
/**
* Sets the size of the area (range on the x-axis) that should be minimum
* visible at once (no further zooming in allowed). If this is e.g. set to
* 10, no less than a range of 10 on the x-axis can be viewed at once without
* scrolling.
*
* @param minXRange The minimum visible range of x-values.
*/
set visibleXRangeMinimum(minXRange: any);
/**
* Limits the maximum and minimum x range that can be visible by pinching and zooming. e.g. minRange=10, maxRange=100 the
* smallest range to be displayed at once is 10, and no more than a range of 100 values can be viewed at once without
* scrolling
*
* @param minXRange
* @param maxXRange
*/
setVisibleXRange(minXRange: any, maxXRange: any): void;
/**
* Sets the size of the area (range on the y-axis) that should be maximum
* visible at once.
*
* @param maxYRange the maximum visible range on the y-axis
* @param axis the axis for which this limit should apply
*/
setVisibleYRangeMaximum(maxYRange: any, axis: any): void;
/**
* Sets the size of the area (range on the y-axis) that should be minimum visible at once, no further zooming in possible.
*
* @param minYRange
* @param axis the axis for which this limit should apply
*/
setVisibleYRangeMinimum(minYRange: any, axis: any): void;
/**
* Limits the maximum and minimum y range that can be visible by pinching and zooming.
*
* @param minYRange
* @param maxYRange
* @param axis
*/
setVisibleYRange(minYRange: any, maxYRange: any, axis: any): void;
/**
* Moves the left side of the current viewport to the specified x-position.
* This also refreshes the chart by calling invalidate().
*
* @param xValue
*/
moveViewToX(xValue: any): void;
/**
* This will move the left side of the current viewport to the specified
* x-value on the x-axis, and center the viewport to the specified y value on the y-axis.
* This also refreshes the chart by calling invalidate().
*
* @param xValue
* @param yValue
* @param axis - which axis should be used as a reference for the y-axis
*/
moveViewTo(xValue: any, yValue: any, axis: any): void;
/**
* This will move the left side of the current viewport to the specified x-value
* and center the viewport to the y value animated.
* This also refreshes the chart by calling invalidate().
*
* @param xValue
* @param yValue
* @param axis
* @param duration the duration of the animation in milliseconds
*/
moveViewToAnimated(xValue: any, yValue: any, axis: any, duration: any): void;
/**
* Centers the viewport to the specified y value on the y-axis.
* This also refreshes the chart by calling invalidate().
*
* @param yValue
* @param axis - which axis should be used as a reference for the y-axis
*/
centerViewToY(yValue: any, axis: any): void;
/**
* This will move the center of the current viewport to the specified
* x and y value.
* This also refreshes the chart by calling invalidate().
*
* @param xValue
* @param yValue
* @param axis - which axis should be used as a reference for the y axis
*/
centerViewTo(xValue: any, yValue: any, axis: any): void;
/**
* This will move the center of the current viewport to the specified
* x and y value animated.
*
* @param xValue
* @param yValue
* @param axis
* @param duration the duration of the animation in milliseconds
*/
centerViewToAnimated(xValue: any, yValue: any, axis: any, duration: any): void;
/**
* flag that indicates if a custom viewport offset has been set
*/
private mCustomViewPortEnabled;
/**
* Sets custom offsets for the current ViewPort (the offsets on the sides of
* the actual chart window). Setting this will prevent the chart from
* automatically calculating it's offsets. Use resetViewPortOffsets() to
* undo this. ONLY USE THIS WHEN YOU KNOW WHAT YOU ARE DOING, else use
* setExtraOffsets(...).
*
* @param left
* @param top
* @param right
* @param bottom
*/
setViewPortOffsets(left: any, top: any, right: any, bottom: any): void;
/**
* Resets all custom offsets set via setViewPortOffsets(...) method. Allows
* the chart to again calculate all offsets automatically.
*/
resetViewPortOffsets(): void;
/**
* ################ ################ ################ ################
*/
/** CODE BELOW IS GETTERS AND SETTERS */
/**
* Returns the range of the specified axis.
*
* @param axis
* @return
*/
protected getAxisRange(axis: any): number;
/**
* Returns a recyclable MPPointF instance.
* Returns the position (in pixels) the provided Entry has inside the chart
* view or null, if the provided Entry is null.
*
* @param e
* @return
*/
getPosition(e: U, axis: any): {
x: number;
y: number;
};
/**
* Set this to true to allow highlighting per dragging over the chart
* surface when it is fully zoomed out. Default: true
*
* @param enabled
*/
set highlightPerDragEnabled(enabled: boolean);
get highlightPerDragEnabled(): boolean;
/**
* Sets the color for the background of the chart-drawing area (everything
* behind the grid lines).
*
* @param color
*/
set gridBackgroundColor(color: any);
/**
* Set this to true to enable dragging (moving the chart with the finger)
* for the chart (this does not effect scaling).
*
* @param enabled
*/
set dragEnabled(enabled: boolean);
/**
* Returns true if dragging is enabled for the chart, false if not.
*/
get dragEnabled(): boolean;
/**
* Set this to true to enable scaling (zooming in and out by gesture) for
* the chart (this does not effect dragging) on both X- and Y-Axis.
*
* @param enabled
*/
set scaleEnabled(enabled: any);
set scaleXEnabled(enabled: boolean);
get scaleXEnabled(): boolean;
set scaleYEnabled(enabled: boolean);
get scaleYEnabled(): boolean;
/**
* Set this to true to enable zooming in by double-tap on the chart.
* Default: enabled
*
* @param enabled
*/
set doubleTapToZoomEnabled(enabled: boolean);
/**
* Returns true if zooming via double-tap is enabled false if not.
*/
get doubleTapToZoomEnabled(): boolean;
set highlightPerTapEnabled(enabled: boolean);
get highlightPerTapEnabled(): boolean;
/**
* wheter to highlight drawing will be clipped to contentRect,
* otherwise they can bleed outside the content rect.
*/
clipHighlightToContent: boolean;
/**
* Sets the width of the border lines in dp.
*
* @param width
*/
setBorderWidth(width: any): void;
/**
* Sets the color of the chart border lines.
*
* @param color
*/
setBorderColor(color: any): void;
/**
* Returns a recyclable MPPointD instance
* Returns the x and y values in the chart at the given touch point
* (encapsulated in a MPPointD). This method transforms pixel coordinates to
* coordinates / values in the chart. This is the opposite method to
* getPixelForValues(...).
*
* @param x
* @param y
* @return
*/
getValuesByTouchPoint(x: any, y: any, axis: any): any;
/**
* Returns a recyclable MPPointD instance
* Transforms the given chart values into pixels. This is the opposite
* method to getValuesByTouchPoint(...).
*
* @param x
* @param y
* @return
*/
getPixelForValues(x: any, y: any, axis: any): {
x: number;
y: number;
};
/**
* Returns a recyclable MPPointD instance
* Transforms the given chart values into pixels. This is the opposite
* method to getValuesByTouchPoint(...).
*
* @param set
* @param entry
* @param entry
* @return
*/
getPixelForEntry(set: IDataSet<Entry>, entry: Entry, index: any): {
x: number;
y: number;
};
/**
* returns the Entry object displayed at the touched position of the chart
*
* @param x
* @param y
* @return
*/
getEntryByTouchPoint(x: any, y: any): Entry;
/**
* returns the DataSet object displayed at the touched position of the chart
*
* @param x
* @param y
* @return
*/
getDataSetByTouchPoint(x: any, y: any): D;
/**
* buffer for storing lowest visible x point
*/
protected posForGetLowestVisibleX: {
x: number;
y: number;
};
/**
* Returns the lowest x-index (value on the x-axis) that is still visible on
* the chart.
*/
get lowestVisibleX(): number;
/**
* buffer for storing highest visible x point
*/
protected posForGetHighestVisibleX: {
x: number;
y: number;
};
/**
* Returns the highest x-index (value on the x-axis) that is still visible
* on the chart.
*/
get highestVisibleX(): number;
/**
* Returns the range visible on the x-axis.
*/
getVisibleXRange(): number;
/**
* returns the current x-scale factor
*/
getScaleX(): number;
/**
* returns the current y-scale factor
*/
getScaleY(): number;
/**
* if the chart is fully zoomed out, return true
*/
isFullyZoomedOut(): boolean;
/**
* Returns the left y-axis object. In the horizontal bar-chart, this is the
* top axis.
*/
get leftAxis(): YAxis;
/**
* @deprecated use leftAxis
*/
get axisLeft(): YAxis;
/**
* Returns the right y-axis object. In the horizontal bar-chart, this is the
* bottom axis.
*/
get rightAxis(): YAxis;
/**
* @deprecated use rightAxis
*/
get axisRight(): YAxis;
/**
* Returns the y-axis object to the corresponding AxisDependency. In the
* horizontal bar-chart, LEFT == top, RIGHT == BOTTOM
*
* @param axis
* @return
*/
getAxis(axis: any): YAxis;
isInverted(axis: any): boolean;
/**
* Set an offset in dp that allows the user to drag the chart over it's
* bounds on the x-axis.
*
* @param offset
*/
setDragOffsetX(offset: any): void;
/**
* Set an offset in dp that allows the user to drag the chart over it's
* bounds on the y-axis.
*
* @param offset
*/
setDragOffsetY(offset: any): void;
/**
* Returns true if both drag offsets (x and y) are zero or smaller.
*/
hasNoDragOffset(): boolean;
get yChartMax(): number;
get yChartMin(): number;
/**
* Returns true if either the left or the right or both axes are inverted.
*/
get anyAxisInverted(): boolean;
protected mOnSizeChangedBuffer: import("@nativescript-community/arraybuffers").TypedArray;
onSizeChanged(w: number, h: number, oldw: number, oldh: number): void;
addEventListener(arg: string | GestureTypes, callback: (data: EventData) => void, thisArg?: any): void;
removeEventListener(arg: string | GestureTypes, callback?: any, thisArg?: any): void;
}