@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.
248 lines (246 loc) • 7.56 kB
TypeScript
import { Canvas, Paint, Path, RectF } from '@nativescript-community/ui-canvas';
import { Font } from '@nativescript/core/ui/styling/font';
import { Entry } from '../data/Entry';
import { PieData } from '../data/PieData';
import { PieDataSet } from '../data/PieDataSet';
import { Highlight } from '../highlight/Highlight';
import { BaseCustomRenderer } from '../renderer/DataRenderer';
import { PieChartRenderer } from '../renderer/PieChartRenderer';
import { MPPointF } from '../utils/MPPointF';
import { PieRadarChartBase } from './PieRadarChartBase';
export interface CustomRenderer extends BaseCustomRenderer {
drawSlice?: (c: Canvas, e: Entry, slice: Path, paint: Paint) => void;
drawHighlight?: (c: Canvas, e: Highlight, slice: Path, paint: Paint) => void;
}
/**
* View that represents a pie chart. Draws cake like slices.
*
*/
export declare class PieChart extends PieRadarChartBase<Entry, PieDataSet, PieData> {
renderer: PieChartRenderer;
/**
* rect object that represents the bounds of the piechart, needed for
* drawing the circle
*/
readonly circleBox: RectF;
/**
* flag indicating if entry labels should be drawn or not
*/
drawEntryLabels: boolean;
/**
* array that holds the width of each pie-slice in degrees
*/
private mDrawAngles;
/**
* array that holds the absolute angle in degrees of each slice
*/
private mAbsoluteAngles;
/**
* if true, the white hole inside the chart will be drawn
*/
drawHoleEnabled: boolean;
/**
* if true, the hole will see-through to the inner tips of the slices
*/
drawSlicesUnderHoleEnabled: boolean;
/**
* if true, the values inside the piechart are drawn as percent values
*/
usePercentValues: boolean;
/**
* if true, the slices of the piechart are rounded
*/
drawRoundedSlices: boolean;
/**
* variable for the text that is drawn in the center of the pie-chart
*/
centerText: string;
private mCenterTextOffset;
/**
* indicates the size of the hole in the center of the piechart, default:
* radius / 2
*/
private mHoleRadiusPercent;
/**
* the radius of the transparent circle that is drawn next to the hole
* in the piechart in percent of the maximum radius (max = the radius of the
* whole chart), default 55% -> means 5% larger than the center-hole by
*/
transparentCircleRadiusPercent: number;
/**
* if enabled, centertext is drawn
*/
drawCenterText: boolean;
/**
* the rectangular radius of the bounding box for the center text, as a percentage of the pie
* hole
* default 1.f (100%)
*/
centerTextRadiusPercent: number;
protected mMaxAngle: number;
/**
* Minimum angle to draw slices, this only works if there is enough room for all slices to have
* the minimum angle, default 0.
*/
private mMinAngleForSlices;
protected init(): void;
draw(canvas: Canvas): void;
calculateOffsets(): void;
protected calcMinMax(): void;
protected getMarkerPosition(highlight: Highlight): number[];
/**
* calculates the needed angles for the chart slices
*/
private calcAngles;
/**
* Checks if the given index is set to be highlighted.
*
* @param index
* @return
*/
needsHighlight(index: number): boolean;
/**
* Calculates the needed angle for a given value
*
* @param value
* @param yValueSum
* @return
*/
private calcAngle;
getIndexForAngle(angle: number): number;
/**
* Returns the index of the DataSet this x-index belongs to.
*
* @param xIndex
* @return
*/
getDataSetIndexForIndex(xIndex: number): number;
/**
* returns an integer array of all the different angles the chart slices
* have the angles in the returned array determine how much space (of 360°)
* each slice takes
*/
get drawAngles(): number[];
/**
* returns the absolute angles of the different chart slices (where the
* slices end)
*/
get absoluteAngles(): number[];
/**
* Sets the color for the hole that is drawn in the center of the PieChart
* (if enabled).
*
* @param color
*/
set holeColor(color: any);
get holeColor(): any;
protected get requiredLegendOffset(): number;
protected get requiredBaseOffset(): number;
get radius(): number;
/**
* Returns the center of the circlebox
*/
get centerCircleBox(): MPPointF;
/**
* Sets the typeface for the center-text paint
*
* @param t
*/
set centerTextTypeface(t: Font);
get centerTextTypeface(): Font;
/**
* Sets the size of the center text of the PieChart in dp.
*
* @param sizeDp
*/
set centerTextSize(sizeDp: number);
get centerTextSize(): number;
/**
* Sets the offset the center text should have from it's original position in dp. Default x = 0, y = 0
*
* @param x
* @param y
*/
set centerTextOffset({ x, y }: {
x: number;
y: number;
});
/**
* Returns the offset on the x- and y-axis the center text has in dp.
*/
get centerTextOffset(): MPPointF;
/**
* Sets the color of the center text of the PieChart.
*
* @param color
*/
set centerTextColor(color: any);
get centerTextColor(): any;
/**
* sets the radius of the hole in the center of the piechart in percent of
* the maximum radius (max = the radius of the whole chart), default 50%
*
* @param percent
*/
set holeRadius(percent: number);
/**
* Returns the size of the hole radius in percent of the total radius.
*/
get holeRadius(): number;
/**
* Sets the color the transparent-circle should have.
*
* @param color
*/
set transparentCircleColor(color: any);
/**
* Sets the amount of transparency the transparent circle should have 0 = fully transparent,
* 255 = fully opaque.
* Default value is 100.
*
* @param alpha 0-255
*/
set transparentCircleAlpha(alpha: any);
/**
* Sets the color the entry labels are drawn with.
*
* @param color
*/
set entryLabelColor(color: any);
/**
* Sets a custom font for the drawing of the entry labels.
*
* @param tf
*/
set entryLabelTypeface(tf: any);
/**
* Sets the size of the entry labels in dp. Default: 13dp
*
* @param size
*/
set entryLabelTextSize(size: any);
get maxAngle(): number;
/**
* Sets the max angle that is used for calculating the pie-circle. 360 means
* it's a full PieChart, 180 results in a half-pie-chart. Default: 360
*
* @param maxangle min 90, max 360
*/
set maxAngle(maxangle: number);
/**
* The minimum angle slices on the chart are rendered with, default is 0.
*
* @return minimum angle for slices
*/
get minAngleForSlices(): number;
/**
* Set the angle to set minimum size for slices, you must call {@link #notifyDataSetChanged()}
* and {@link #invalidate()} when changing this, only works if there is enough room for all
* slices to have the minimum angle.
*
* @param minAngle minimum 0, maximum is half of {@link #setMaxAngle}
*/
set minAngleForSlices(minAngle: number);
_onDetachedFromWindow(): void;
customRenderer: CustomRenderer;
}