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; return toPlot;
} }
function compareObj(a,b) {
if (a.data < b.data)
return -1;
if (a.data > b.data)
return 1;
return 0;
}
/* UPDATES */ /* UPDATES */
function updatePie(pie, data) { function updatePie(pie, data) {
@ -166,14 +173,19 @@ function updatePie(pie, data) {
toPlot_obj[itemStr] += count; toPlot_obj[itemStr] += count;
} }
} }
toPlot = []; if (Object.keys(toPlot_obj).length == 0) { // no data
for (var itemStr in toPlot_obj) { toPlot = [{ label: 'No data', data: 100 }];
if (toPlot_obj.hasOwnProperty(itemStr)) { } else {
toPlot.push({label: itemStr, data: toPlot_obj[itemStr], color: itemMapping[itemStr].colour}) 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)) { if (!(pieWidget === undefined)) {
pieWidget.setData(toPlot); pieWidget.setData(toPlot);
pieWidget.setupGrid(); pieWidget.setupGrid();

View File

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