Ox.Chart: fix sort regressions

This commit is contained in:
rlx 2013-05-07 14:33:52 +00:00
parent 4f37ff8783
commit e9668823e3

View file

@ -92,18 +92,24 @@ Ox.Chart = function(options, self) {
} }
self.items = self.keys.map(function(key) { self.items = self.keys.map(function(key) {
var value = self.options.data[key], return {
sort = self.options.sort.operator == '+' key: key,
? (self.subData ? self.totals[key] : value) keySort: self.sort[key],
: (self.subData ? self.max - self.totals[key] : self.max - value); value: self.options.data[key],
if (self.options.sort.key == 'value') { valueSort: self.subData ? self.totals[key] : self.options.data[key]
sort = Ox.pad(value, 64) + sort; };
}
return {key: key, value: value, sort: sort};
}); });
self.sortBy = self.options.sort.key == 'key'
? [
{key: 'keySort', operator: self.options.sort.operator}
]
: [
{key: 'valueSort', operator: self.options.sort.operator},
{key: 'keySort', operator: '+'}
]
if (self.options.limit) { if (self.options.limit) {
self.items = Ox.sortBy( self.items = Ox.sortBy(
self.items, {key: 'sort', operator: '+'} self.items, self.sortBy
).slice(0, self.options.limit); ).slice(0, self.options.limit);
self.max = Ox.max(self.items.map(function(item) { self.max = Ox.max(self.items.map(function(item) {
return self.subData ? Ox.sum(item.value) : item.value; return self.subData ? Ox.sum(item.value) : item.value;
@ -176,7 +182,7 @@ Ox.Chart = function(options, self) {
max: 0, max: 0,
min: 0, min: 0,
pageLength: self.items.length, pageLength: self.items.length,
sort: [{key: 'sort', operator: '+'}], sort: self.sortBy,
width: self.options.width, width: self.options.width,
unique: 'key' unique: 'key'
}) })