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) {
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(value, 64) + sort;
}
return {key: key, value: value, sort: sort};
return {
key: key,
keySort: self.sort[key],
value: self.options.data[key],
valueSort: self.subData ? self.totals[key] : self.options.data[key]
};
});
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) {
self.items = Ox.sortBy(
self.items, {key: 'sort', operator: '+'}
self.items, self.sortBy
).slice(0, self.options.limit);
self.max = Ox.max(self.items.map(function(item) {
return self.subData ? Ox.sum(item.value) : item.value;
@ -176,7 +182,7 @@ Ox.Chart = function(options, self) {
max: 0,
min: 0,
pageLength: self.items.length,
sort: [{key: 'sort', operator: '+'}],
sort: self.sortBy,
width: self.options.width,
unique: 'key'
})