@@ -307,10 +307,30 @@ angular.module('patternfly.charts').component('pfHeatmap', {
307
307
} ) ;
308
308
} ;
309
309
310
- ctrl . updateAll = function ( ) {
311
- // Need to deep watch changes in chart data
310
+ var updateDisplay = function ( ) {
311
+ setStyles ( ) ;
312
+
313
+ if ( ctrl . chartDataAvailable !== false && ctrl . data ) {
314
+ ctrl . loadingDone = true ;
315
+
316
+ // Allow the style change to take effect to update the container size
317
+ $timeout ( function ( ) {
318
+ setSizes ( ) ;
319
+ redraw ( ) ;
320
+ } ) ;
321
+ }
322
+ } ;
323
+
324
+ var handleDataUpdate = function ( ) {
312
325
prevData = angular . copy ( ctrl . data ) ;
326
+ updateDisplay ( ) ;
327
+ } ;
313
328
329
+ var debounceResize = _ . debounce ( function ( ) {
330
+ updateDisplay ( ) ;
331
+ } , 250 , 500 ) ;
332
+
333
+ var updateConfig = function ( ) {
314
334
//Allow overriding of defaults
315
335
if ( ctrl . maxBlockSize === undefined || isNaN ( ctrl . maxBlockSize ) ) {
316
336
ctrl . maxSize = 64 ;
@@ -360,46 +380,36 @@ angular.module('patternfly.charts').component('pfHeatmap', {
360
380
}
361
381
ctrl . height = ctrl . height || heightDefault ;
362
382
ctrl . showLegend = ctrl . showLegend || ( ctrl . showLegend === undefined ) ;
363
- ctrl . loadingDone = false ;
364
-
365
- angular . element ( $window ) . on ( 'resize' , function ( ) {
366
- setSizes ( ) ;
367
- redraw ( ) ;
368
- } ) ;
369
-
370
- ctrl . thisComponent = $element [ 0 ] . querySelector ( '.heatmap-pf-svg' ) ;
371
-
372
- $timeout ( function ( ) {
373
- setStyles ( ) ;
374
- setSizes ( ) ;
375
- redraw ( ) ;
376
- } ) ;
377
383
} ;
378
384
385
+ ctrl . loadingDone = false ;
386
+
379
387
ctrl . $onChanges = function ( changesObj ) {
380
388
if ( changesObj . chartDataAvailable && ! changesObj . chartDataAvailable . isFirstChange ( ) ) {
381
389
setStyles ( ) ;
382
- } else {
383
- ctrl . updateAll ( ) ;
384
- ctrl . loadingDone = true ;
390
+ } else if ( ! changesObj . data ) {
391
+ updateConfig ( ) ;
392
+ updateDisplay ( ) ;
385
393
}
386
394
} ;
387
395
388
396
ctrl . $doCheck = function ( ) {
389
397
// do a deep compare on chartData and config
390
398
if ( ! angular . equals ( ctrl . data , prevData ) ) {
391
- setStyles ( ) ;
392
- if ( ctrl . chartDataAvailable !== false ) {
393
- setSizes ( ) ;
394
- redraw ( ) ;
395
- }
399
+ handleDataUpdate ( ) ;
396
400
}
397
401
} ;
398
402
399
403
ctrl . $postLink = function ( ) {
400
- setStyles ( ) ;
401
- setSizes ( ) ;
402
- redraw ( ) ;
404
+ ctrl . thisComponent = $element [ 0 ] . querySelector ( '.heatmap-pf-svg' ) ;
405
+ updateConfig ( ) ;
406
+ handleDataUpdate ( ) ;
407
+
408
+ angular . element ( $window ) . on ( 'resize' , debounceResize ) ;
409
+ } ;
410
+
411
+ ctrl . $onDestroy = function ( ) {
412
+ angular . element ( $window ) . off ( 'resize' , debounceResize ) ;
403
413
} ;
404
414
}
405
415
} ) ;
0 commit comments