From f7c531c5dfbe1a48850ae17ab7a57c8d91b1e876 Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 26 Apr 2013 12:27:35 +0200 Subject: [PATCH] Ox.Chart: when sorting by value, descending, make sure sort order of tied items, by key, is ascending --- source/Ox.UI/js/List/Chart.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/Ox.UI/js/List/Chart.js b/source/Ox.UI/js/List/Chart.js index 84a565f6..be1f6717 100644 --- a/source/Ox.UI/js/List/Chart.js +++ b/source/Ox.UI/js/List/Chart.js @@ -92,16 +92,18 @@ Ox.Chart = function(options, self) { } self.items = self.keys.map(function(key) { - var sort = self.sort[key], - value = self.options.data[key]; + var value = self.options.data[key], + sort = self.options.sort.operator == '+' + ? (self.subData ? self.totals[key] : value) + ? (self.subData ? self.max - self.totals[key] : self.max - value); if (self.options.sort.key == 'value') { - sort = Ox.pad(self.subData ? self.totals[key] : value, 64) + sort; + sort = Ox.pad(value, 64) + sort; } return {key: key, value: value, sort: sort}; }); if (self.options.limit) { self.items = Ox.sortBy( - self.items, {key: 'sort', operator: self.options.sort.operator} + self.items, {key: 'sort', operator: '+'} ).slice(0, self.options.limit); self.max = Ox.max(self.items.map(function(item) { return self.subData ? Ox.sum(item.value) : item.value; @@ -174,7 +176,7 @@ Ox.Chart = function(options, self) { max: 0, min: 0, pageLength: self.items.length, - sort: [{key: 'sort', operator: self.options.sort.operator}], + sort: [{key: 'sort', operator: '+'}], width: self.options.width, unique: 'key' })