@@ -7,12 +7,13 @@ import { DefaultFillFormatter } from '../formatter/DefaultFillFormatter';
7
7
import { IFillFormatter } from '../formatter/IFillFormatter' ;
8
8
import { DashPathEffect , parseDashEffect } from 'nativescript-canvas' ;
9
9
import { ColorTemplate } from 'nativescript-chart/utils/ColorTemplate' ;
10
+ import { createLTTB } from 'downsample' ;
10
11
11
12
export enum Mode {
12
13
LINEAR ,
13
14
STEPPED ,
14
15
CUBIC_BEZIER ,
15
- HORIZONTAL_BEZIER
16
+ HORIZONTAL_BEZIER ,
16
17
}
17
18
18
19
export class LineDataSet extends LineRadarDataSet < Entry > implements ILineDataSet {
@@ -63,6 +64,58 @@ export class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
63
64
64
65
private mDrawCircleHole = true ;
65
66
67
+ /**
68
+ * the max number allowed point before filtering. <= O means disabled
69
+ */
70
+ private mMaxFilterNumber = 0 ;
71
+
72
+ public getMaxFilterNumber ( ) {
73
+ return this . mMaxFilterNumber ;
74
+ }
75
+
76
+ /**
77
+ * Sets the max number allowed point before filtering.
78
+ *
79
+ * @param value: number
80
+ */
81
+ public setMaxFilterNumber ( value : number ) {
82
+ this . mMaxFilterNumber = value ;
83
+ }
84
+
85
+ protected mFilteredValues : Entry [ ] = null ;
86
+ protected mFilterFunction ;
87
+ public applyFiltering ( scaleX : number ) {
88
+ // console.log('applyFiltering', scaleX, this.mMaxFilterNumber, this.mValues.length, this.mFilteredValues && this.mFilteredValues.length);
89
+ if ( this . mMaxFilterNumber > 0 && this . mValues . length / scaleX > this . mMaxFilterNumber ) {
90
+ const filterCount = Math . round ( this . mMaxFilterNumber * scaleX ) ;
91
+ if ( ! this . mFilteredValues || this . mFilteredValues . length !== filterCount ) {
92
+ if ( ! this . mFilterFunction ) {
93
+ this . mFilterFunction = createLTTB ( {
94
+ x : this . xProperty ,
95
+ y : this . yProperty ,
96
+ } as any ) ;
97
+ }
98
+ this . mFilteredValues = this . mFilterFunction ( this . mValues , filterCount ) ;
99
+ }
100
+ } else if ( this . mFilteredValues ) {
101
+ this . mFilteredValues = null ;
102
+ }
103
+ }
104
+
105
+ mIgnoreFiltered = false
106
+ protected getInternalValues ( ) {
107
+ if ( this . mFilteredValues && ! this . mIgnoreFiltered ) {
108
+ return this . mFilteredValues ;
109
+ }
110
+ return this . mValues ;
111
+ }
112
+ setIgnoreFiltered ( value ) {
113
+ this . mIgnoreFiltered = value ;
114
+ }
115
+ isFiltered ( ) {
116
+ return ! ! this . mFilteredValues ;
117
+ }
118
+
66
119
constructor ( yVals , label , xProperty ?, yProperty ?) {
67
120
super ( yVals , label , xProperty , yProperty ) ;
68
121
@@ -72,7 +125,7 @@ export class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
72
125
// if (this.mCircleColors == null) {
73
126
// this.mCircleColors = [];
74
127
// }
75
- this . mCircleColors = [ ]
128
+ this . mCircleColors = [ ] ;
76
129
77
130
// default colors
78
131
// this.mColors.add(new Color(255, 192, 255, 140));
@@ -183,7 +236,7 @@ export class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
183
236
* @param phase offset, in degrees (normally, use 0)
184
237
*/
185
238
public enableDashedLine ( lineLength , spaceLength , phase ) {
186
- this . mDashPathEffect = new DashPathEffect ( [ lineLength , spaceLength ] , phase ) ; ;
239
+ this . mDashPathEffect = new DashPathEffect ( [ lineLength , spaceLength ] , phase ) ;
187
240
// this.mDashPathEffect = parseDashEffect(`${lineLength} ${spaceLength} ${phase}`) ;
188
241
}
189
242
@@ -272,7 +325,7 @@ export class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
272
325
*/
273
326
public resetCircleColors ( ) {
274
327
// if (this.mCircleColors == null) {
275
- this . mCircleColors = [ ] ;
328
+ this . mCircleColors = [ ] ;
276
329
// }
277
330
// this.mCircleColors.clear();
278
331
}
0 commit comments