Statistics: Ellipsize long product names

This commit is contained in:
Raphael Michel
2019-02-01 15:09:16 +01:00
parent 13cc57e98b
commit 4dae224d73
2 changed files with 15 additions and 1 deletions

View File

@@ -34,10 +34,23 @@ $(function () {
new Morris.Bar({
element: 'obp_chart',
data: JSON.parse($("#obp-data").html()),
xkey: 'item',
xkey: 'item_short',
ykeys: ['ordered', 'paid'],
labels: [gettext('Placed orders'), gettext('Paid orders')],
barColors: ['#3b1c4a', '#50a167'],
hoverCallback: function (index, options, content, row) {
console.log(content);
var $c = $("<div>" + content + "</div>");
var $label = $c.find(".morris-hover-row-label");
$label.text(row.item);
var newc = $label.get(0).outerHTML;
$c.find('.morris-hover-point').each(function (i, r) {
if ($.trim($(r).text().split("\n")[2]) !== "0") {
newc += r.outerHTML;
}
});
return newc;
},
resize: true,
xLabelAngle: 30
});

View File

@@ -117,6 +117,7 @@ class IndexView(EventPermissionRequiredMixin, ChartContainingView, TemplateView)
ctx['obp_data'] = json.dumps([
{
'item': item_names[item],
'item_short': item_names[item] if len(item_names[item]) < 15 else (item_names[item][:15] + ""),
'ordered': cnt,
'paid': num_paid.get(item, 0)
} for item, cnt in num_ordered.items()