@@ -28,6 +28,10 @@ export class LegendRenderer extends Renderer {
28
28
*/
29
29
protected mLegend : Legend ;
30
30
31
+ protected legendFontMetrics = new FontMetrics ( ) ;
32
+
33
+ protected computedEntries : LegendEntry [ ] = [ ] ;
34
+
31
35
constructor ( viewPortHandler : ViewPortHandler , legend : Legend ) {
32
36
super ( viewPortHandler ) ;
33
37
@@ -61,8 +65,6 @@ export class LegendRenderer extends Renderer {
61
65
return this . mLegendFormPaint ;
62
66
}
63
67
64
- protected computedEntries : LegendEntry [ ] = [ ] ;
65
-
66
68
/**
67
69
* Prepares the legend and calculates all needed forms, labels and colors.
68
70
*
@@ -94,8 +96,8 @@ export class LegendRenderer extends Renderer {
94
96
// add the legend description label
95
97
this . computedEntries . push ( new LegendEntry ( dataSet . getLabel ( ) , LegendForm . NONE , NaN , NaN , null , ColorTemplate . COLOR_NONE ) ) ;
96
98
}
97
- } else if ( dataSet instanceof PieDataSet ) {
98
- const pds = dataSet ;
99
+ } else if ( dataSet . constructor . name === ' PieDataSet' ) {
100
+ const pds = dataSet as PieDataSet ;
99
101
100
102
for ( let j = 0 ; j < clrs . length && j < entryCount ; j ++ ) {
101
103
const label = pds . getEntryForIndex ( j ) . label ;
@@ -110,15 +112,16 @@ export class LegendRenderer extends Renderer {
110
112
// add the legend description label
111
113
this . computedEntries . push ( new LegendEntry ( dataSet . getLabel ( ) , LegendForm . NONE , NaN , NaN , null , ColorTemplate . COLOR_NONE ) ) ;
112
114
}
113
- } else if ( dataSet instanceof CandleDataSet && dataSet . getDecreasingColor ( ) !== ColorTemplate . COLOR_NONE ) {
114
- const decreasingColor = dataSet . getDecreasingColor ( ) ;
115
- const increasingColor = dataSet . getIncreasingColor ( ) ;
115
+ } else if ( dataSet . constructor . name === 'CandleDataSet' ) {
116
+ const dSet = dataSet as CandleDataSet ;
117
+ if ( dSet . getDecreasingColor ( ) !== ColorTemplate . COLOR_NONE ) {
118
+ const decreasingColor = dSet . getDecreasingColor ( ) ;
119
+ const increasingColor = dSet . getIncreasingColor ( ) ;
116
120
117
- this . computedEntries . push ( new LegendEntry ( null , dataSet . getForm ( ) , dataSet . getFormSize ( ) , dataSet . getFormLineWidth ( ) , dataSet . getFormLineDashEffect ( ) , decreasingColor ) ) ;
121
+ this . computedEntries . push ( new LegendEntry ( null , dSet . getForm ( ) , dSet . getFormSize ( ) , dSet . getFormLineWidth ( ) , dSet . getFormLineDashEffect ( ) , decreasingColor ) ) ;
118
122
119
- this . computedEntries . push (
120
- new LegendEntry ( dataSet . getLabel ( ) , dataSet . getForm ( ) , dataSet . getFormSize ( ) , dataSet . getFormLineWidth ( ) , dataSet . getFormLineDashEffect ( ) , increasingColor )
121
- ) ;
123
+ this . computedEntries . push ( new LegendEntry ( dSet . getLabel ( ) , dSet . getForm ( ) , dSet . getFormSize ( ) , dSet . getFormLineWidth ( ) , dSet . getFormLineDashEffect ( ) , increasingColor ) ) ;
124
+ }
122
125
} else {
123
126
// all others
124
127
@@ -147,14 +150,11 @@ export class LegendRenderer extends Renderer {
147
150
}
148
151
149
152
this . mLegendLabelPaint . setTypeface ( this . mLegend . getTypeface ( ) ) ;
150
- this . mLegendLabelPaint . setColor ( this . mLegend . getTextColor ( ) ) ;
151
153
152
154
// calculate all dimensions of the this.mLegend
153
155
this . mLegend . calculateDimensions ( this . mLegendLabelPaint , this . mViewPortHandler ) ;
154
156
}
155
157
156
- protected legendFontMetrics = new FontMetrics ( ) ;
157
-
158
158
@profile
159
159
public renderLegend ( c : Canvas ) {
160
160
if ( ! this . mLegend . isEnabled ( ) ) return ;
0 commit comments