Sorting Pie Chart items by label to avoid shuffling content on every update

This commit is contained in:
Alfredo Cardigliano 2019-07-11 17:27:01 +02:00
parent 92c50fd8f6
commit b3a35ef2d4
3 changed files with 41 additions and 5 deletions

View file

@ -61,14 +61,23 @@ function PieChart(name, update_url, url_params, units, refresh) {
// Needed to draw the pie immediately
this.update();
this.update();
//this.update();
// var updateInterval = window.setInterval(update, refresh);
function compare_by_label(a, b) {
if (a.label < b.label){
return -1;
} else if (a.label > b.label) {
return 1;
} else {
return 0;
}
}
function update_pie_chart(data) {
data.sort(compare_by_label);
streakerDataAdded = data;
oldPieData = filteredPieData;
pieData = donut(streakerDataAdded);