@cryptotaxi247 / netdata-1 / commits / 099f15022

allow easypiecharts to animate clockwise and counter clockwise; fixes #2455

Costa Tsaousis (ktsaou) committed Jul 24, 2017 at 19:48 UTC 099f15022fdbfd32501ae1b557516303b70ebea5
1 file changed +24 -4
web/dashboard.js
+24 -4
@@ -5557,16 +5557,36 @@ var NETDATA = window.NETDATA || {};
5557 if(typeof min !== 'number') min = 0;
5558 if(typeof max !== 'number') max = 0;
5559
5560 + if(min > max) {
5561 + var t = min;
5562 + min = max;
5563 + max = t;
5564 + }
5565 +
5566 if(min > value) min = value;
5567 if(max < value) max = value;
5568
5563 - // make sure it is zero based
5564 - // but only they have not been set by the user
5569 if(state.tmp.easyPieChartMin === null && min > 0) min = 0;
5570 if(state.tmp.easyPieChartMax === null && max < 0) max = 0;
5571
5568 - var pcent = Math.round((value - min) * 100 / (max - min));
5569 - if(pcent === 0) pcent = 0.1;
5572 + var pcent;
5573 +
5574 + if(min < 0 && max > 0) {
5575 + // it is both positive and negative
5576 + // zero at the top center of the chart
5577 + max = (-min > max)? -min : max;
5578 + pcent = Math.round(value * 100 / max);
5579 + }
5580 + else if(value >= 0 && min >= 0 && max >= 0) {
5581 + // clockwise
5582 + pcent = Math.round((value - min) * 100 / (max - min));
5583 + if(pcent === 0) pcent = 0.1;
5584 + }
5585 + else {
5586 + // counter clockwise
5587 + pcent = Math.round((value - max) * 100 / (max - min));
5588 + if(pcent === 0) pcent = -0.1;
5589 + }
5590
5591 return pcent;
5592 };