fixed a bug in the chart refresher that was incorrectly hidding charts in the middle of chart updates, causing them to be hidden until the next chart refresh
Costa Tsaousis (ktsaou) committed
Dec 24, 2017 at 23:09 UTC
cc05a3805eda98896123db9c8cb6ca917ca18395
1 file changed
+87
-41
web/dashboard.js
+87
-41
@@ -780,7 +780,8 @@ var NETDATA = window.NETDATA || {};
780
var len = targets.length;
781
782
while (len--)
783
- targets[len].isVisible();
783
+ if(targets[len].running === false)
784
+ targets[len].isVisible();
785
}
786
787
//var end = Date.now();
@@ -2708,6 +2709,9 @@ var NETDATA = window.NETDATA || {};
2709
if(that.chart_created === true) {
2710
if(NETDATA.options.current.show_help === true) {
2711
if(that.element_legend_childs.toolbox !== null) {
2712
+ if(that.debug === true)
2713
+ that.log('hideChart(): hidding legend popovers');
2714
+
2715
$(that.element_legend_childs.toolbox_left).popover('hide');
2716
$(that.element_legend_childs.toolbox_reset).popover('hide');
2717
$(that.element_legend_childs.toolbox_right).popover('hide');
@@ -2723,13 +2727,15 @@ var NETDATA = window.NETDATA || {};
2727
}
2728
2729
if(NETDATA.options.current.destroy_on_hide === true) {
2726
- // that.log('hideChart() init');
2730
+ if(that.debug === true)
2731
+ that.log('hideChart(): initializing chart');
2732
2733
// we should destroy it
2734
init('force');
2735
}
2736
else {
2732
- // that.log('hideChart()');
2737
+ if(that.debug === true)
2738
+ that.log('hideChart(): hiding chart');
2739
2740
showRendering();
2741
that.element_chart.style.display = 'none';
@@ -2759,13 +2765,17 @@ var NETDATA = window.NETDATA || {};
2765
that.updates_since_last_unhide = 0;
2766
2767
if(that.chart_created === false) {
2762
- // that.log('unhideChart() init');
2768
+ if(that.debug === true)
2769
+ that.log('unhideChart(): initializing chart');
2770
+
2771
// we need to re-initialize it, to show our background
2772
// logo in bootstrap tabs, until the chart loads
2773
init('force');
2774
}
2775
else {
2768
- // that.log('unhideChart()');
2776
+ if(that.debug === true)
2777
+ that.log('unhideChart(): unhiding chart');
2778
+
2779
that.element.style.willChange = 'transform';
2780
that.tm.last_unhidden = Date.now();
2781
that.element_chart.style.display = '';
@@ -2778,7 +2788,10 @@ var NETDATA = window.NETDATA || {};
2788
};
2789
2790
var canBeRendered = function(uncached_visibility) {
2781
- return (
2791
+ if(that.debug === true)
2792
+ that.log('canBeRendered() called');
2793
+
2794
+ var ret = (
2795
(
2796
NETDATA.options.page_is_visible === true ||
2797
NETDATA.options.current.stop_updates_when_focus_is_lost === false ||
@@ -2786,6 +2799,11 @@ var NETDATA = window.NETDATA || {};
2799
)
2800
&& isHidden() === false && that.isVisible(uncached_visibility) === true
2801
);
2802
+
2803
+ if(that.debug === true)
2804
+ that.log('canBeRendered(): ' + ret);
2805
+
2806
+ return ret;
2807
};
2808
2809
// https://github.com/petkaantonov/bluebird/wiki/Optimization-killers
@@ -2871,13 +2889,19 @@ var NETDATA = window.NETDATA || {};
2889
// to be called just before the chart library to make sure that
2890
// a properly sized dom is available
2891
var resizeChart = function() {
2874
- if(that.isVisible() === true && that.tm.last_resized < NETDATA.options.last_page_resize) {
2892
+ if(that.tm.last_resized < NETDATA.options.last_page_resize) {
2893
if(that.chart_created === false) return;
2894
2895
if(that.needsRecreation()) {
2896
+ if(that.debug === true)
2897
+ that.log('resizeChart(): initializing chart');
2898
+
2899
init('force');
2900
}
2901
else if(typeof that.library.resize === 'function') {
2902
+ if(that.debug === true)
2903
+ that.log('resizeChart(): resizing chart');
2904
+
2905
that.library.resize(that);
2906
2907
if(that.element_legend_childs.perfect_scroller !== null)
@@ -4492,14 +4516,14 @@ var NETDATA = window.NETDATA || {};
4516
};
4517
4518
this.updateChart = function(callback) {
4495
- if(this.debug === true)
4519
+ if (this.debug === true)
4520
this.log('updateChart()');
4521
4498
- if(this.fetching_data === true) {
4499
- if(this.debug === true)
4500
- this.log('I am already updating...');
4522
+ if (this.fetching_data === true) {
4523
+ if (this.debug === true)
4524
+ this.log('updateChart(): I am already updating...');
4525
4502
- if(typeof callback === 'function')
4526
+ if (typeof callback === 'function')
4527
return callback(false, 'already running');
4528
4529
return;
@@ -4507,33 +4531,47 @@ var NETDATA = window.NETDATA || {};
4531
4532
// due to late initialization of charts and libraries
4533
// we need to check this too
4510
- if(this.enabled === false) {
4511
- if(this.debug === true)
4512
- this.log('I am not enabled');
4534
+ if (this.enabled === false) {
4535
+ if (this.debug === true)
4536
+ this.log('updateChart(): I am not enabled');
4537
4514
- if(typeof callback === 'function')
4538
+ if (typeof callback === 'function')
4539
return callback(false, 'not enabled');
4540
4541
return;
4542
}
4543
4520
- if(canBeRendered() === false) {
4521
- if(typeof callback === 'function')
4544
+ if (canBeRendered() === false) {
4545
+ if (this.debug === true)
4546
+ this.log('updateChart(): cannot be rendered');
4547
+
4548
+ if (typeof callback === 'function')
4549
return callback(false, 'cannot be rendered');
4550
4551
return;
4552
}
4553
4527
- if(that.dom_created !== true)
4554
+ if (that.dom_created !== true) {
4555
+ if (this.debug === true)
4556
+ this.log('updateChart(): creating DOM');
4557
+
4558
createDOM();
4559
+ }
4560
4530
- if(this.chart === null)
4531
- return this.getChart(function() {
4561
+ if (this.chart === null) {
4562
+ if (this.debug === true)
4563
+ this.log('updateChart(): getting chart');
4564
+
4565
+ return this.getChart(function () {
4566
return that.updateChart(callback);
4567
});
4568
+ }
4569
4570
if(this.library.initialized === false) {
4571
if(this.library.enabled === true) {
4572
+ if(this.debug === true)
4573
+ this.log('updateChart(): initializing chart library');
4574
+
4575
return this.library.initialize(function () {
4576
return that.updateChart(callback);
4577
});
@@ -4633,24 +4671,30 @@ var NETDATA = window.NETDATA || {};
4671
};
4672
4673
var __isVisible = function() {
4636
- if(NETDATA.options.current.update_only_visible === false)
4637
- return true;
4674
+ var ret = true;
4675
4639
- // tolerance is the number of pixels a chart can be off-screen
4640
- // to consider it as visible and refresh it as if was visible
4641
- var tolerance = 0;
4676
+ if(NETDATA.options.current.update_only_visible !== false) {
4677
+ // tolerance is the number of pixels a chart can be off-screen
4678
+ // to consider it as visible and refresh it as if was visible
4679
+ var tolerance = 0;
4680
4643
- that.tm.last_visible_check = Date.now();
4681
+ that.tm.last_visible_check = Date.now();
4682
4645
- var rect = that.element.getBoundingClientRect();
4683
+ var rect = that.element.getBoundingClientRect();
4684
4647
- var screenTop = window.scrollY;
4648
- var screenBottom = screenTop + window.innerHeight;
4685
+ var screenTop = window.scrollY;
4686
+ var screenBottom = screenTop + window.innerHeight;
4687
4650
- var chartTop = rect.top + screenTop;
4651
- var chartBottom = chartTop + rect.height;
4688
+ var chartTop = rect.top + screenTop;
4689
+ var chartBottom = chartTop + rect.height;
4690
4653
- return !(rect.width === 0 || rect.height === 0 || chartBottom + tolerance < screenTop || chartTop - tolerance > screenBottom);
4691
+ ret = !(rect.width === 0 || rect.height === 0 || chartBottom + tolerance < screenTop || chartTop - tolerance > screenBottom);
4692
+ }
4693
+
4694
+ if(that.debug === true)
4695
+ that.log('__isVisible(): ' + ret);
4696
+
4697
+ return ret;
4698
};
4699
4700
this.isVisible = function(nocache) {
@@ -4658,14 +4702,16 @@ var NETDATA = window.NETDATA || {};
4702
4703
// caching - we do not evaluate the charts visibility
4704
// if the page has not been scrolled since the last check
4661
- if((typeof nocache === 'undefined' || nocache === false)
4662
- && typeof this.tmp.___isVisible___ !== 'undefined'
4663
- && this.tm.last_visible_check > NETDATA.options.last_page_scroll)
4664
- return this.tmp.___isVisible___;
4705
+ if((typeof nocache !== 'undefined' && nocache === true)
4706
+ || typeof this.tmp.___isVisible___ === 'undefined'
4707
+ || this.tm.last_visible_check <= NETDATA.options.last_page_scroll) {
4708
+ this.tmp.___isVisible___ = __isVisible();
4709
+ if (this.tmp.___isVisible___ === true) unhideChart();
4710
+ else hideChart();
4711
+ }
4712
4666
- this.tmp.___isVisible___ = __isVisible();
4667
- if(this.tmp.___isVisible___ === true) unhideChart();
4668
- else hideChart();
4713
+ if(this.debug === true)
4714
+ this.log('isVisible(' + nocache + '): ' + this.tmp.___isVisible___);
4715
4716
return this.tmp.___isVisible___;
4717
};
@@ -5256,7 +5302,7 @@ var NETDATA = window.NETDATA || {};
5302
var state;
5303
while(len--) {
5304
state = targets[len];
5259
- if(state.isVisible() === false || state.running === true)
5305
+ if(state.running === true || state.isVisible() === false)
5306
continue;
5307
5308
if(state.library.initialized === false) {