@@ -39,8 +39,9 @@ module.exports = function(Chart) {
3939 var data = chart . data ;
4040 if ( data . labels . length && data . datasets . length ) {
4141 return data . labels . map ( function ( label , i ) {
42+ var meta = chart . getDatasetMeta ( 0 ) ;
4243 var ds = data . datasets [ 0 ] ;
43- var arc = chart . getDatasetMeta ( 0 ) . data [ i ] ;
44+ var arc = meta . data [ i ] ;
4445 var fill = arc . custom && arc . custom . backgroundColor ? arc . custom . backgroundColor : helpers . getValueAtIndexOrDefault ( ds . backgroundColor , i , this . chart . options . elements . arc . backgroundColor ) ;
4546 var stroke = arc . custom && arc . custom . borderColor ? arc . custom . borderColor : helpers . getValueAtIndexOrDefault ( ds . borderColor , i , this . chart . options . elements . arc . borderColor ) ;
4647 var bw = arc . custom && arc . custom . borderWidth ? arc . custom . borderWidth : helpers . getValueAtIndexOrDefault ( ds . borderWidth , i , this . chart . options . elements . arc . borderWidth ) ;
@@ -50,7 +51,7 @@ module.exports = function(Chart) {
5051 fillStyle : fill ,
5152 strokeStyle : stroke ,
5253 lineWidth : bw ,
53- hidden : isNaN ( data . datasets [ 0 ] . data [ i ] ) ,
54+ hidden : isNaN ( ds . data [ i ] ) || meta . data [ i ] . hidden ,
5455
5556 // Extra data used for toggling the correct item
5657 index : i
@@ -61,20 +62,18 @@ module.exports = function(Chart) {
6162 }
6263 }
6364 } ,
65+
6466 onClick : function ( e , legendItem ) {
65- helpers . each ( this . chart . data . datasets , function ( dataset , datasetIndex ) {
66- var meta = this . chart . getDatasetMeta ( datasetIndex ) ;
67- var idx = legendItem . index ;
68-
69- if ( ! isNaN ( dataset . data [ idx ] ) ) {
70- meta . hiddenData [ idx ] = dataset . data [ idx ] ;
71- dataset . data [ idx ] = NaN ;
72- } else if ( ! isNaN ( meta . hiddenData [ idx ] ) ) {
73- dataset . data [ idx ] = meta . hiddenData [ idx ] ;
74- }
75- } , this ) ;
67+ var index = legendItem . index ;
68+ var chart = this . chart ;
69+ var i , ilen , meta ;
70+
71+ for ( i = 0 , ilen = ( chart . data . datasets || [ ] ) . length ; i < ilen ; ++ i ) {
72+ meta = chart . getDatasetMeta ( i ) ;
73+ meta . data [ index ] . hidden = ! meta . data [ index ] . hidden ;
74+ }
7675
77- this . chart . update ( ) ;
76+ chart . update ( ) ;
7877 }
7978 } ,
8079
@@ -125,11 +124,6 @@ module.exports = function(Chart) {
125124 this . chart . innerRadius = Math . max ( this . chart . options . cutoutPercentage ? ( this . chart . outerRadius / 100 ) * ( this . chart . options . cutoutPercentage ) : 1 , 0 ) ;
126125 this . chart . radiusLength = ( this . chart . outerRadius - this . chart . innerRadius ) / this . chart . getVisibleDatasetCount ( ) ;
127126
128- this . getDataset ( ) . total = 0 ;
129- helpers . each ( this . getDataset ( ) . data , function ( value ) {
130- this . getDataset ( ) . total += Math . abs ( value ) ;
131- } , this ) ;
132-
133127 this . outerRadius = this . chart . outerRadius - ( this . chart . radiusLength * this . index ) ;
134128 this . innerRadius = this . outerRadius - this . chart . radiusLength ;
135129
@@ -145,21 +139,23 @@ module.exports = function(Chart) {
145139
146140 // If there is NaN data before us, we need to calculate the starting angle correctly.
147141 // We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
148- var notNullIndex = 0 ;
142+ var visibleCount = 0 ;
143+ var meta = this . getMeta ( ) ;
149144 for ( var i = 0 ; i < index ; ++ i ) {
150- if ( ! isNaN ( this . getDataset ( ) . data [ i ] ) ) {
151- ++ notNullIndex ;
145+ if ( ! isNaN ( this . getDataset ( ) . data [ i ] ) && ! meta . data [ i ] . hidden ) {
146+ ++ visibleCount ;
152147 }
153148 }
154149
155- var startAngle = ( - 0.5 * Math . PI ) + ( circumference * notNullIndex ) ;
156- var endAngle = startAngle + circumference ;
150+ var distance = arc . hidden ? 0 : this . chart . scale . getDistanceFromCenterForValue ( this . getDataset ( ) . data [ index ] ) ;
151+ var startAngle = ( - 0.5 * Math . PI ) + ( circumference * visibleCount ) ;
152+ var endAngle = startAngle + ( arc . hidden ? 0 : circumference ) ;
157153
158154 var resetModel = {
159155 x : centerX ,
160156 y : centerY ,
161157 innerRadius : 0 ,
162- outerRadius : this . chart . options . animateScale ? 0 : this . chart . scale . getDistanceFromCenterForValue ( this . getDataset ( ) . data [ index ] ) ,
158+ outerRadius : this . chart . options . animateScale ? 0 : distance ,
163159 startAngle : this . chart . options . animateRotate ? Math . PI * - 0.5 : startAngle ,
164160 endAngle : this . chart . options . animateRotate ? Math . PI * - 0.5 : endAngle ,
165161
@@ -182,7 +178,7 @@ module.exports = function(Chart) {
182178 x : centerX ,
183179 y : centerY ,
184180 innerRadius : 0 ,
185- outerRadius : this . chart . scale . getDistanceFromCenterForValue ( this . getDataset ( ) . data [ index ] ) ,
181+ outerRadius : distance ,
186182 startAngle : startAngle ,
187183 endAngle : endAngle ,
188184
@@ -225,15 +221,20 @@ module.exports = function(Chart) {
225221 calculateCircumference : function ( value ) {
226222 if ( isNaN ( value ) ) {
227223 return 0 ;
228- } else {
229- // Count the number of NaN values
230- var numNaN = helpers . where ( this . getDataset ( ) . data , function ( data ) {
231- return isNaN ( data ) ;
232- } ) . length ;
233-
234- return ( 2 * Math . PI ) / ( this . getDataset ( ) . data . length - numNaN ) ;
235224 }
225+
226+ // Count the number of "visible"" values
227+ var meta = this . getMeta ( ) ;
228+ var count = 0 ;
229+
230+ this . getDataset ( ) . data . forEach ( function ( value , index ) {
231+ if ( ! isNaN ( value ) && ! meta . data [ index ] . hidden ) {
232+ count ++ ;
233+ }
234+ } ) ;
235+
236+ return ( 2 * Math . PI ) / count ;
236237 }
237238 } ) ;
238239
239- } ;
240+ } ;
0 commit comments