Ox.Chart: improve sorting
This commit is contained in:
parent
41ca92a3d1
commit
dfde724a38
1 changed files with 15 additions and 20 deletions
33
source/Ox.UI/js/List/Chart.js
vendored
33
source/Ox.UI/js/List/Chart.js
vendored
|
@ -58,8 +58,6 @@ Ox.Chart = function(options, self) {
|
||||||
self.subData = {};
|
self.subData = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixme: a lot of the sorting is unneeded, since it happens in the list
|
|
||||||
|
|
||||||
self.sort = {};
|
self.sort = {};
|
||||||
self.totals = {};
|
self.totals = {};
|
||||||
Ox.forEach(self.options.data, function(value, key) {
|
Ox.forEach(self.options.data, function(value, key) {
|
||||||
|
@ -87,8 +85,6 @@ Ox.Chart = function(options, self) {
|
||||||
bValue = self.subData[b];
|
bValue = self.subData[b];
|
||||||
return a === '' ? 1
|
return a === '' ? 1
|
||||||
: b === '' ? -1
|
: b === '' ? -1
|
||||||
//: aValue < bValue ? 1
|
|
||||||
//: aValue > bValue ? -1
|
|
||||||
: self.sort[a] < self.sort[b] ? -1
|
: self.sort[a] < self.sort[b] ? -1
|
||||||
: self.sort[a] > self.sort[b] ? 1
|
: self.sort[a] > self.sort[b] ? 1
|
||||||
: 0;
|
: 0;
|
||||||
|
@ -96,23 +92,22 @@ Ox.Chart = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.items = self.keys.map(function(key) {
|
self.items = self.keys.map(function(key) {
|
||||||
return {key: key, value: self.options.data[key]};
|
var sort = self.sort[key],
|
||||||
})
|
value = self.options.data[key];
|
||||||
.sort(function(a, b) {
|
if (self.options.sort.key == 'value') {
|
||||||
var key = self.options.sort.key,
|
sort = Ox.pad(self.subData ? self.totals[key] : value, 64) + sort;
|
||||||
aValue = key == 'key' ? self.sort[a.key]
|
}
|
||||||
: self.subData ? self.totals[a.key] : a.value,
|
return {key: key, value: value, sort: sort};
|
||||||
bValue = key == 'key' ? self.sort[b.key]
|
|
||||||
: self.subData ? self.totals[b.key] : b.value;
|
|
||||||
return aValue < bValue ? (self.options.sort.operator == '+' ? -1 : 1)
|
|
||||||
: aValue > bValue ? (self.options.sort.operator == '+' ? 1 : -1)
|
|
||||||
: key == 'value' && self.sort[a.key] < self.sort[b.key] ? -1
|
|
||||||
: key == 'value' && self.sort[a.key] > self.sort[b.key] ? 1
|
|
||||||
: 0;
|
|
||||||
});
|
});
|
||||||
if (self.options.limit) {
|
if (self.options.limit) {
|
||||||
self.items = self.items.slice(0, self.options.limit);
|
self.items = Ox.sortBy(
|
||||||
|
self.items, {key: 'sort', operator: self.options.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;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
self.max = self.max || 1;
|
||||||
|
|
||||||
if (self.options.rows == 2) {
|
if (self.options.rows == 2) {
|
||||||
self.row = 0;
|
self.row = 0;
|
||||||
|
@ -179,7 +174,7 @@ Ox.Chart = function(options, self) {
|
||||||
max: 0,
|
max: 0,
|
||||||
min: 0,
|
min: 0,
|
||||||
pageLength: self.items.length,
|
pageLength: self.items.length,
|
||||||
sort: [self.options.sort],
|
sort: [{key: 'sort', operator: self.options.sort.operator}],
|
||||||
width: self.options.width,
|
width: self.options.width,
|
||||||
unique: 'key'
|
unique: 'key'
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue