1
+ import { Canvas } from '@nativescript-community/ui-canvas' ;
2
+ import { BarLineScatterCandleBubbleDataSet } from '../data/BarLineScatterCandleBubbleDataSet' ;
3
+ import { CombinedData } from '../data/CombinedData' ;
4
+ import { Entry } from '../data/Entry' ;
5
+ import { CombinedHighlighter } from '../highlight/CombinedHighlighter' ;
6
+ import { CombinedDataProvider } from '../interfaces/dataprovider/CombinedDataProvider' ;
7
+ import { IDataSet } from '../interfaces/datasets/IDataSet' ;
8
+ import { BarLineChartBase } from './BarLineChartBase' ;
9
+ import { CombinedChartRenderer } from '../renderer/CombinedChartRenderer' ;
1
10
11
+ /**
12
+ * enum that allows to specify the order in which the different data objects
13
+ * for the combined-chart are drawn
14
+ */
15
+ export enum DrawOrder {
16
+ BAR ,
17
+ BUBBLE ,
18
+ LINE ,
19
+ CANDLE ,
20
+ SCATTER ,
21
+ }
2
22
/**
3
23
* This chart class allows the combination of lines, bars, scatter and candle
4
24
* data all displayed in one chart area.
5
25
*
6
26
* @author Philipp Jahoda
7
27
*/
8
- export class CombinedChart extends BarLineChartBase < CombinedData > implements CombinedDataProvider {
9
-
28
+ export class CombinedChart extends BarLineChartBase < Entry , BarLineScatterCandleBubbleDataSet < Entry > , CombinedData > implements CombinedDataProvider {
10
29
/**
11
30
* if set to true, all values are drawn above their bars, instead of below
12
31
* their top
13
32
*/
14
- private boolean this . mDrawValueAboveBar = true ;
15
-
33
+ mDrawValueAboveBar = true ;
16
34
17
35
/**
18
36
* flag that indicates whether the highlight should be full-bar oriented, or single-value?
19
37
*/
20
- protected boolean this . mHighlightFullBarEnabled = false ;
38
+ mHighlightFullBarEnabled = false ;
21
39
22
40
/**
23
41
* if set to true, a grey area is drawn behind each bar that indicates the
24
42
* maximum value
25
43
*/
26
- private boolean this . mDrawBarShadow = false ;
27
-
28
- protected DrawOrder [ ] this . mDrawOrder ;
44
+ mDrawBarShadow = false ;
29
45
30
- /**
31
- * enum that allows to specify the order in which the different data objects
32
- * for the combined-chart are drawn
33
- */
34
- public enum DrawOrder {
35
- BAR , BUBBLE , LINE , CANDLE , SCATTER
36
- }
37
-
38
- public CombinedChart ( Context context ) {
39
- super ( context ) ;
40
- }
41
-
42
- public CombinedChart ( Context context , AttributeSet attrs ) {
43
- super ( context , attrs ) ;
44
- }
46
+ mDrawOrder : DrawOrder [ ] ;
45
47
46
- public CombinedChart ( Context context , AttributeSet attrs , let defStyle ) {
47
- super ( context , attrs , defStyle ) ;
48
- }
49
-
50
-
51
48
protected init ( ) {
52
49
super . init ( ) ;
53
50
54
51
// Default values are not ready here yet
55
- this . mDrawOrder = new DrawOrder [ ] {
56
- DrawOrder. BAR , DrawOrder . BUBBLE , DrawOrder . LINE , DrawOrder . CANDLE , DrawOrder . SCATTER
57
- } ;
52
+ this . mDrawOrder = [ DrawOrder . BAR , DrawOrder . BUBBLE , DrawOrder . LINE , DrawOrder . CANDLE , DrawOrder . SCATTER ] ;
58
53
59
- setHighlighter ( new CombinedHighlighter ( this , this ) ) ;
54
+ this . setHighlighter ( new CombinedHighlighter ( this , this ) ) ;
60
55
61
56
// Old default behaviour
62
- setHighlightFullBarEnabled ( true ) ;
57
+ this . setHighlightFullBarEnabled ( true ) ;
63
58
64
59
this . mRenderer = new CombinedChartRenderer ( this , this . mAnimator , this . mViewPortHandler ) ;
65
60
}
66
61
67
-
68
- public CombinedData getCombinedData ( ) {
62
+ public getCombinedData ( ) {
69
63
return this . mData ;
70
64
}
71
65
72
-
73
- public setData ( CombinedData data ) {
66
+ public setData ( data : CombinedData ) {
74
67
super . setData ( data ) ;
75
- setHighlighter ( new CombinedHighlighter ( this , this ) ) ;
76
- ( ( CombinedChartRenderer ) mRenderer ) . createRenderers ( ) ;
68
+ this . setHighlighter ( new CombinedHighlighter ( this , this ) ) ;
69
+ ( this . mRenderer as CombinedChartRenderer ) . createRenderers ( ) ;
77
70
this . mRenderer . initBuffers ( ) ;
78
71
}
79
72
@@ -86,64 +79,49 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
86
79
* @param y
87
80
* @return
88
81
*/
89
-
90
- public Highlight getHighlightByTouchPoint ( let x , let y ) {
91
82
92
- if ( mData == null ) {
93
- console . error ( LOG_TAG , "Can't select by touch. No data set." ) ;
83
+ public getHighlightByTouchPoint ( x , y ) {
84
+ if ( this . mData == null ) {
85
+ console . error ( "Can't select by touch. No data set." ) ;
94
86
return null ;
95
87
} else {
96
- Highlight h = getHighlighter ( ) . getHighlight ( x , y ) ;
97
- if ( h == null || ! isHighlightFullBarEnabled ( ) ) return h ;
88
+ const h = this . getHighlighter ( ) . getHighlight ( x , y ) ;
89
+ if ( h == null || ! this . isHighlightFullBarEnabled ( ) ) return h ;
98
90
99
91
// For isHighlightFullBarEnabled, remove stackIndex
100
- return new Highlight ( h . getX ( ) , h . getY ( ) ,
101
- h . getXPx ( ) , h . getYPx ( ) ,
102
- h . getDataSetIndex ( ) , - 1 , h . getAxis ( ) ) ;
92
+ return Object . assign ( { } , h , { } ) ;
103
93
}
104
94
}
105
95
106
-
107
- public LineData getLineData ( ) {
108
- if ( mData == null )
109
- return null ;
96
+ public getLineData ( ) {
97
+ if ( this . mData == null ) return null ;
110
98
return this . mData . getLineData ( ) ;
111
99
}
112
100
113
-
114
- public BarData getBarData ( ) {
115
- if ( mData == null )
116
- return null ;
101
+ public getBarData ( ) {
102
+ if ( this . mData == null ) return null ;
117
103
return this . mData . getBarData ( ) ;
118
104
}
119
105
120
-
121
- public ScatterData getScatterData ( ) {
122
- if ( mData == null )
123
- return null ;
106
+ public getScatterData ( ) {
107
+ if ( this . mData == null ) return null ;
124
108
return this . mData . getScatterData ( ) ;
125
109
}
126
110
127
-
128
- public CandleData getCandleData ( ) {
129
- if ( mData == null )
130
- return null ;
111
+ public getCandleData ( ) {
112
+ if ( this . mData == null ) return null ;
131
113
return this . mData . getCandleData ( ) ;
132
114
}
133
115
134
-
135
- public BubbleData getBubbleData ( ) {
136
- if ( mData == null )
137
- return null ;
116
+ public getBubbleData ( ) {
117
+ if ( this . mData == null ) return null ;
138
118
return this . mData . getBubbleData ( ) ;
139
119
}
140
120
141
-
142
121
public isDrawBarShadowEnabled ( ) {
143
122
return this . mDrawBarShadow ;
144
123
}
145
124
146
-
147
125
public isDrawValueAboveBarEnabled ( ) {
148
126
return this . mDrawValueAboveBar ;
149
127
}
@@ -154,18 +132,17 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
154
132
*
155
133
* @param enabled
156
134
*/
157
- public setDrawValueAboveBar ( enabled ) {
135
+ public setDrawValueAboveBar ( enabled ) {
158
136
this . mDrawValueAboveBar = enabled ;
159
137
}
160
138
161
-
162
139
/**
163
140
* If set to true, a grey area is drawn behind each bar that indicates the
164
141
* maximum value. Enabling his will reduce performance by about 50%.
165
142
*
166
143
* @param enabled
167
144
*/
168
- public setDrawBarShadow ( enabled ) {
145
+ public setDrawBarShadow ( enabled ) {
169
146
this . mDrawBarShadow = enabled ;
170
147
}
171
148
@@ -175,14 +152,14 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
175
152
*
176
153
* @param enabled
177
154
*/
178
- public setHighlightFullBarEnabled ( enabled ) {
155
+ public setHighlightFullBarEnabled ( enabled ) {
179
156
this . mHighlightFullBarEnabled = enabled ;
180
157
}
181
158
182
159
/**
183
160
* @return true the highlight operation is be full-bar oriented, false if single-value
184
161
*/
185
-
162
+
186
163
public isHighlightFullBarEnabled ( ) {
187
164
return this . mHighlightFullBarEnabled ;
188
165
}
@@ -192,7 +169,7 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
192
169
*
193
170
* @return
194
171
*/
195
- public DrawOrder [ ] getDrawOrder ( ) {
172
+ public getDrawOrder ( ) {
196
173
return this . mDrawOrder ;
197
174
}
198
175
@@ -204,49 +181,41 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
204
181
*
205
182
* @param order
206
183
*/
207
- public setDrawOrder ( DrawOrder [ ] order ) {
208
- if ( order == null || order . length <= 0 )
209
- return ;
184
+ public setDrawOrder ( order : DrawOrder [ ] ) {
185
+ if ( order == null || order . length <= 0 ) return ;
210
186
this . mDrawOrder = order ;
211
187
}
212
188
213
189
/**
214
190
* draws all MarkerViews on the highlighted positions
215
191
*/
216
- protected drawMarkers ( c : Canvasanvas ) {
217
-
192
+ protected drawMarkers ( c : Canvas ) {
218
193
// if there is no marker view or drawing marker is disabled
219
- if ( mMarker == null || ! isDrawMarkersEnabled ( ) || ! valuesToHighlight ( ) )
220
- return ;
194
+ if ( this . mMarker == null || ! this . isDrawMarkersEnabled ( ) || ! this . valuesToHighlight ( ) ) return ;
221
195
222
196
for ( let i = 0 ; i < this . mIndicesToHighlight . length ; i ++ ) {
197
+ const highlight = this . mIndicesToHighlight [ i ] ;
223
198
224
- Highlight highlight = this . mIndicesToHighlight [ i ] ;
225
-
226
- set:IDataSet = this . mData . getDataSetByHighlight ( highlight ) ;
199
+ const set : IDataSet < Entry > = this . mData . getDataSetByHighlight ( highlight ) ;
227
200
228
- Entry e = this . mData . getEntryForHighlight ( highlight ) ;
229
- if ( e == null )
230
- continue ;
201
+ const e = this . mData . getEntryForHighlight ( highlight ) ;
202
+ if ( e == null ) continue ;
231
203
232
- let entryIndex = set . getEntryIndex ( e ) ;
204
+ const entryIndex = set . getEntryIndex ( e ) ;
233
205
234
206
// make sure entry not null
235
- if ( entryIndex > set . getEntryCount ( ) * this . mAnimator . getPhaseX ( ) )
236
- continue ;
207
+ if ( entryIndex > set . getEntryCount ( ) * this . mAnimator . getPhaseX ( ) ) continue ;
237
208
238
- float [ ] pos = getMarkerPosition ( highlight ) ;
209
+ const pos = this . getMarkerPosition ( highlight ) ;
239
210
240
211
// check bounds
241
- if ( ! mViewPortHandler . isInBounds ( pos [ 0 ] , pos [ 1 ] ) )
242
- continue ;
212
+ if ( ! this . mViewPortHandler . isInBounds ( pos [ 0 ] , pos [ 1 ] ) ) continue ;
243
213
244
214
// callbacks to update the content
245
215
this . mMarker . refreshContent ( e , highlight ) ;
246
216
247
217
// draw the marker
248
- this . mMarker . draw ( canvas , pos [ 0 ] , pos [ 1 ] ) ;
218
+ this . mMarker . draw ( c , pos [ 0 ] , pos [ 1 ] ) ;
249
219
}
250
220
}
251
-
252
221
}
0 commit comments