@cryptotaxi247 / netdata-1 / commits / 721683bf2

sync easyPieChart refreshes, bootstrap tab monitoring, chart resets

Costa Tsaousis (ktsaou) committed Jan 9, 2016 at 00:16 UTC 721683bf2a7485e316b1cdb02a3d0034bc1f2192
1 file changed +82 -34
web/dashboard.js
+82 -34
@@ -526,7 +526,7 @@
526 return;
527
528 if(this.master !== null && this.master !== state)
529 - this.master.resetChart();
529 + this.master.resetChart(true, true);
530
531 var now = new Date().getTime();
532 this.master = state;
@@ -538,21 +538,17 @@
538
539 // clear the master
540 clearMaster: function() {
541 - if(NETDATA.options.current.sync_pan_and_zoom === false)
542 - return;
543 -
541 if(this.master !== null) {
545 - var state = this.master;
546 - this.master = null; // prevent infinite recursion
547 - this.seq = 0;
548 - state.resetChart();
549 - NETDATA.options.auto_refresher_stop_until = 0;
542 + var st = this.master;
543 + this.master = null;
544 + st.resetChart();
545 }
546
547 this.master = null;
548 this.seq = 0;
549 this.force_after_ms = null;
550 this.force_before_ms = null;
551 + NETDATA.options.auto_refresher_stop_until = 0;
552 },
553
554 // is the given state the master of the global
@@ -1599,29 +1595,43 @@
1595 this.pauseChart = function() {
1596 if(this.paused === false) {
1597 if(this.debug === true)
1602 - this.log('paused');
1598 + this.log('pauseChart()');
1599
1600 this.paused = true;
1601 }
1602 }
1603
1604 this.unpauseChart = function() {
1609 - if(this.paused) {
1605 + if(this.paused === true) {
1606 if(this.debug === true)
1611 - this.log('unpaused');
1607 + this.log('unpauseChart()');
1608
1609 this.paused = false;
1610 }
1611 }
1612
1617 - this.resetChart = function() {
1618 - if(NETDATA.globalPanAndZoom.isMaster(this) && this.isVisible())
1619 - NETDATA.globalPanAndZoom.clearMaster();
1613 + this.resetChart = function(dont_clear_master, dont_update) {
1614 + if(this.debug === true)
1615 + this.log('resetChart(' + dont_clear_master + ', ' + dont_update + ') called');
1616
1621 - this.tm.pan_and_zoom_seq = 0;
1617 + if(typeof dont_clear_master === 'undefined')
1618 + dont_clear_master = false;
1619 +
1620 + if(typeof dont_update === 'undefined')
1621 + dont_update = false;
1622 +
1623 + if(dont_clear_master !== true && NETDATA.globalPanAndZoom.isMaster(this) === true) {
1624 + if(this.debug === true)
1625 + this.log('resetChart() diverting to clearMaster().');
1626 + // this will call us back with master === true
1627 + NETDATA.globalPanAndZoom.clearMaster();
1628 + return;
1629 + }
1630
1631 this.clearSelection();
1632
1633 + this.tm.pan_and_zoom_seq = 0;
1634 +
1635 this.setMode('auto');
1636 this.current.force_update_at = 0;
1637 this.current.force_before_ms = null;
@@ -1630,17 +1640,22 @@
1640 this.paused = false;
1641 this.selected = false;
1642 this.enabled = true;
1633 - this.debug = false;
1643 + // this.debug = false;
1644
1645 // do not update the chart here
1646 // or the chart will flip-flop when it is the master
1647 // of a selection sync and another chart becomes
1648 // the new master
1639 - if(NETDATA.options.current.sync_pan_and_zoom === false && this.isVisible() === true)
1649 +
1650 + if(dont_update !== true && this.isVisible() === true) {
1651 this.updateChart();
1652 + }
1653 }
1654
1655 this.updateChartPanOrZoom = function(after, before) {
1656 + if(this.debug === true)
1657 + this.log('updateChartPanOrZoom() called.');
1658 +
1659 if(before < after) return false;
1660
1661 var min_duration = Math.round((this.chartWidth() / 30 * this.chart.update_every * 1000));
@@ -2164,7 +2179,7 @@
2179
2180 this.updateChartWithData = function(data) {
2181 if(this.debug === true)
2167 - this.log('got data from netdata server');
2182 + this.log('updateChartWithData() called.');
2183
2184 // this may force the chart to be re-created
2185 resizeChart();
@@ -2291,6 +2306,9 @@
2306 }
2307
2308 this.updateChart = function(callback) {
2309 + if(this.debug === true)
2310 + this.log('updateChart() called.');
2311 +
2312 // due to late initialization of charts and libraries
2313 // we need to check this too
2314 if(this.enabled === false) {
@@ -2567,6 +2585,30 @@
2585 init();
2586 }
2587
2588 + NETDATA.resetAllCharts = function(state) {
2589 + // first clear the global selection sync
2590 + // to make sure no chart is in selected state
2591 + state.globalSelectionSyncStop();
2592 +
2593 + // there are 2 possibilities here
2594 + // a. state is the global Pan and Zoom master
2595 + // b. state is not the global Pan and Zoom master
2596 + var master = true;
2597 + if(NETDATA.globalPanAndZoom.isMaster(state) === false)
2598 + master = false;
2599 +
2600 + // clear the global Pan and Zoom
2601 + // this will also refresh the master
2602 + // and unblock any charts currently mirroring the master
2603 + NETDATA.globalPanAndZoom.clearMaster();
2604 +
2605 + // if we were not the master, reset our status too
2606 + // this is required because most probably the mouse
2607 + // is over this chart, blocking it from autorefreshing
2608 + if(master === false && (state.paused === true || state.selected === true))
2609 + state.resetChart();
2610 + }
2611 +
2612 // get or create a chart state, given a DOM element
2613 NETDATA.chartState = function(element) {
2614 var state = $(element).data('netdata-state-object') || null;
@@ -2894,9 +2936,7 @@
2936 }
2937
2938 // bootstrap tab switching
2897 - $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
2898 - NETDATA.onresize();
2899 - });
2939 + $('a[data-toggle="tab"]').on('shown.bs.tab', NETDATA.onscroll);
2940
2941 NETDATA.parseDom(NETDATA.chartRefresher);
2942 }
@@ -3501,10 +3541,7 @@
3541 dblclick: function(event, dygraph, context) {
3542 if(NETDATA.options.debug.dygraph === true || state.debug === true)
3543 state.log('interactionModel.dblclick()');
3504 -
3505 - state.globalSelectionSyncStop();
3506 - NETDATA.globalPanAndZoom.clearMaster();
3507 - state.resetChart();
3544 + NETDATA.resetAllCharts(state);
3545 },
3546 mousewheel: function(event, dygraph, context) {
3547 if(NETDATA.options.debug.dygraph === true || state.debug === true)
@@ -3658,11 +3695,8 @@
3695 if(typeof state.dygraph_last_touch_end !== 'undefined') {
3696 if(state.dygraph_last_touch_move === 0) {
3697 var dt = now - state.dygraph_last_touch_end;
3661 - if(dt <= NETDATA.options.current.double_click_speed) {
3662 - state.globalSelectionSyncStop();
3663 - NETDATA.globalPanAndZoom.clearMaster();
3664 - state.resetChart();
3665 - }
3698 + if(dt <= NETDATA.options.current.double_click_speed)
3699 + NETDATA.resetAllCharts(state);
3700 }
3701 }
3702
@@ -4146,9 +4180,15 @@
4180 state.easyPieChartEvent.timer = null;
4181 }
4182
4149 - state.easyPieChartLabel.innerHTML = state.legendFormatValue(null);
4150 - state.easyPieChart_instance.update(0);
4183 + if(state.isAutoRefreshed() === true && state.data !== null) {
4184 + NETDATA.easypiechartChartUpdate(state, state.data);
4185 + }
4186 + else {
4187 + state.easyPieChartLabel.innerHTML = state.legendFormatValue(null);
4188 + state.easyPieChart_instance.update(0);
4189 + }
4190 state.easyPieChart_instance.enableAnimation();
4191 +
4192 return true;
4193 };
4194
@@ -4297,12 +4337,20 @@
4337 trackWidth: self.data('easypiechart-trackwidth') || undefined,
4338 size: self.data('easypiechart-size') || size,
4339 rotate: self.data('easypiechart-rotate') || 0,
4300 - animate: self.data('easypiechart-rotate') || {duration: data.view_update_every * 1000 / 2, enabled: true},
4340 + animate: self.data('easypiechart-rotate') || {duration: 500, enabled: true},
4341 easing: self.data('easypiechart-easing') || undefined
4342 });
4343
4344 + // when we just re-create the chart
4345 + // do not animate the first update
4346 + var animate = true;
4347 + if(typeof state.easyPieChart_instance !== 'undefined')
4348 + animate = false;
4349 +
4350 state.easyPieChart_instance = chart.data('easyPieChart');
4351 + if(animate === false) state.easyPieChart_instance.disableAnimation();
4352 state.easyPieChart_instance.update(pcent);
4353 + if(animate === false) state.easyPieChart_instance.enableAnimation();
4354 return true;
4355 };
4356