Ox.Chart: when sorting by value, descending, make sure sort order of tied items, by key, is ascending

This commit is contained in:
rolux 2013-04-26 12:27:35 +02:00
parent 2968d7b79a
commit f7c531c5df

View file

@ -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'
})