diff --git a/static/js/trendings.js b/static/js/trendings.js index f0a020b..5a9c72f 100644 --- a/static/js/trendings.js +++ b/static/js/trendings.js @@ -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(); diff --git a/trendings_helper.py b/trendings_helper.py index ac81ca8..2fe4fdf 100644 --- a/trendings_helper.py +++ b/trendings_helper.py @@ -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):