Added a limit for the number of displayed item in piechart

pull/9/head
Sami Mokaddem 2017-11-20 15:14:13 +01:00
parent 95faae3fd2
commit 2216b96c6c
2 changed files with 18 additions and 6 deletions

View File

@ -144,6 +144,13 @@ function generateEmptyAndFillData(data) {
return toPlot;
}
function compareObj(a,b) {
if (a.data < b.data)
return -1;
if (a.data > b.data)
return 1;
return 0;
}
/* UPDATES */
function updatePie(pie, data) {
@ -166,14 +173,19 @@ function updatePie(pie, data) {
toPlot_obj[itemStr] += count;
}
}
toPlot = [];
for (var itemStr in toPlot_obj) {
if (toPlot_obj.hasOwnProperty(itemStr)) {
toPlot.push({label: itemStr, data: toPlot_obj[itemStr], color: itemMapping[itemStr].colour})
if (Object.keys(toPlot_obj).length == 0) { // no data
toPlot = [{ label: 'No data', data: 100 }];
} else {
toPlot = [];
for (var itemStr in toPlot_obj) {
if (toPlot_obj.hasOwnProperty(itemStr)) {
toPlot.push({label: itemStr, data: toPlot_obj[itemStr], color: itemMapping[itemStr].colour})
}
}
}
toPlot.sort(compareObj).reverse();
toPlot = toPlot.slice(0,15); // take at max 12 elements
}
if (!(pieWidget === undefined)) {
pieWidget.setData(toPlot);
pieWidget.setupGrid();

View File

@ -54,7 +54,7 @@ class Trendings_helper:
''' GETTER '''
def getGenericTrending(self, trendingType, dateS, dateE, topNum=12):
def getGenericTrending(self, trendingType, dateS, dateE, topNum=0):
to_ret = []
prev_days = (dateE - dateS).days
for curDate in util.getXPrevDaysSpan(dateE, prev_days):