@swimlane/ngx-charts
Version:
Declarative Charting Framework for Angular
48 lines • 1.39 kB
JavaScript
export function sortLinear(data, property, direction) {
if (direction === void 0) { direction = 'asc'; }
return data.sort(function (a, b) {
if (direction === 'asc') {
return a[property] - b[property];
}
else {
return b[property] - a[property];
}
});
}
export function sortByDomain(data, property, direction, domain) {
if (direction === void 0) { direction = 'asc'; }
return data.sort(function (a, b) {
var aVal = a[property];
var bVal = b[property];
var aIdx = domain.indexOf(aVal);
var bIdx = domain.indexOf(bVal);
if (direction === 'asc') {
return aIdx - bIdx;
}
else {
return bIdx - aIdx;
}
});
}
export function sortByTime(data, property, direction) {
if (direction === void 0) { direction = 'asc'; }
return data.sort(function (a, b) {
var aDate = a[property].getTime();
var bDate = b[property].getTime();
if (direction === 'asc') {
if (aDate > bDate)
return 1;
if (bDate > aDate)
return -1;
return 0;
}
else {
if (aDate > bDate)
return -1;
if (bDate > aDate)
return 1;
return 0;
}
});
}
//# sourceMappingURL=sort.js.map