@cryptotaxi247 / netdata-1 / commits / 416257948

easyPieCharts can now be slaves of global selection sync

Costa Tsaousis (ktsaou) committed Jan 6, 2016 at 02:54 UTC 416257948feb3ed287cf34940004f37b6c71f729
1 file changed +42 -14
web/dashboard.js
+42 -14
@@ -225,7 +225,7 @@
225 focus: false,
226 visibility: false,
227 chart_data_url: false,
228 - chart_errors: true,
228 + chart_errors: false,
229 chart_timing: false,
230 chart_calls: false,
231 libraries: false,
@@ -4100,15 +4100,20 @@
4100 };
4101
4102 NETDATA.easypiechartClearSelection = function(state) {
4103 - var chart = $(state.element_chart);
4103 + if(typeof state.easyPieChartEvent !== 'undefined') {
4104 + if(state.easyPieChartEvent.timer !== null)
4105 + clearTimeout(state.easyPieChartEvent.timer);
4106 +
4107 + state.easyPieChartEvent.timer = null;
4108 + }
4109 +
4110 state.easyPieChartLabel.innerHTML = '';
4105 - chart.data('easyPieChart').update(0);
4111 + state.easyPieChart_instance.update(0);
4112 + state.easyPieChart_instance.enableAnimation();
4113 return true;
4114 };
4115
4116 NETDATA.easypiechartSetSelection = function(state, t) {
4110 - var chart = $(state.element_chart);
4111 -
4117 if(t < state.data_after || t > state.data_before)
4118 return NETDATA.easypiechartClearSelection(state);
4119
@@ -4128,15 +4133,31 @@
4133
4134 // console.log('slot = ' + slot + ' value = ' + value + ' max = ' + max + ' pcent = ' + pcent);
4135
4136 + if(typeof state.easyPieChartEvent === 'undefined') {
4137 + state.easyPieChartEvent = {
4138 + timer: null,
4139 + value: 0,
4140 + pcent: 0,
4141 + };
4142 + }
4143 +
4144 + state.easyPieChartEvent.value = value;
4145 + state.easyPieChartEvent.pcent = pcent;
4146 state.easyPieChartLabel.innerHTML = state.legendFormatValue(value);
4132 - chart.data('easyPieChart').update(pcent);
4147 +
4148 + if(state.easyPieChartEvent.timer === null) {
4149 + state.easyPieChart_instance.disableAnimation();
4150 +
4151 + state.easyPieChartEvent.timer = setTimeout(function() {
4152 + state.easyPieChartEvent.timer = null;
4153 + state.easyPieChart_instance.update(state.easyPieChartEvent.pcent);
4154 + }, 50);
4155 + }
4156
4157 return true;
4158 };
4159
4160 NETDATA.easypiechartChartUpdate = function(state, data) {
4138 - var chart = $(state.element_chart);
4139 -
4161 var value = data.result[0];
4162 if(value === null) value = 0;
4163
@@ -4147,8 +4168,14 @@
4168 if(max !== 0)
4169 pcent = Math.round(value * 100 / max);
4170
4150 - state.easyPieChartLabel.innerHTML = state.legendFormatValue(value);
4151 - chart.data('easyPieChart').update(pcent);
4171 + if(state.isAutoRefreshed() === true) {
4172 + state.easyPieChartLabel.innerHTML = state.legendFormatValue(value);
4173 + state.easyPieChart_instance.update(pcent);
4174 + }
4175 + else {
4176 + state.easyPieChartLabel.innerHTML = '';
4177 + state.easyPieChart_instance.update(0);
4178 + }
4179 return true;
4180 };
4181
@@ -4218,11 +4245,12 @@
4245 trackWidth: self.data('easypiechart-trackwidth') || undefined,
4246 size: self.data('easypiechart-size') || size,
4247 rotate: self.data('easypiechart-rotate') || 0,
4221 - animate: self.data('easypiechart-rotate') || {duration: data.view_update_every * 1000, enabled: true},
4248 + animate: self.data('easypiechart-rotate') || {duration: data.view_update_every * 1000 / 2, enabled: true},
4249 easing: self.data('easypiechart-easing') || undefined
4250 });
4251
4225 - chart.data('easyPieChart').update(pcent);
4252 + state.easyPieChart_instance = chart.data('easyPieChart');
4253 + state.easyPieChart_instance.update(pcent);
4254 return true;
4255 };
4256
@@ -4395,8 +4423,8 @@
4423 create: NETDATA.easypiechartChartCreate,
4424 update: NETDATA.easypiechartChartUpdate,
4425 resize: null,
4398 - setSelection: undefined, // NETDATA.easypiechartSetSelection,
4399 - clearSelection: undefined, // NETDATA.easypiechartClearSelection,
4426 + setSelection: NETDATA.easypiechartSetSelection,
4427 + clearSelection: NETDATA.easypiechartClearSelection,
4428 initialized: false,
4429 enabled: true,
4430 format: function(state) { return 'array'; },