Commit b79017e4 by Alexander Zobnin Committed by Torkel Ödegaard

graph: fix series sorting issue (#10617)

parent ac2b36c2
...@@ -355,33 +355,16 @@ function graphDirective(timeSrv, popoverSrv, contextSrv) { ...@@ -355,33 +355,16 @@ function graphDirective(timeSrv, popoverSrv, contextSrv) {
function sortSeries(series, panel) { function sortSeries(series, panel) {
var sortBy = panel.legend.sort; var sortBy = panel.legend.sort;
var sortOrder = panel.legend.sortDesc; var sortOrder = panel.legend.sortDesc;
var haveSortBy = sortBy !== null || sortBy !== undefined; var haveSortBy = sortBy !== null && sortBy !== undefined;
var haveSortOrder = sortOrder !== null || sortOrder !== undefined; var haveSortOrder = sortOrder !== null && sortOrder !== undefined;
var shouldSortBy = panel.stack && haveSortBy && haveSortOrder; var shouldSortBy = panel.stack && haveSortBy && haveSortOrder;
var sortDesc = panel.legend.sortDesc === true ? -1 : 1; var sortDesc = panel.legend.sortDesc === true ? -1 : 1;
series.sort((x, y) => {
if (x.zindex > y.zindex) {
return 1;
}
if (x.zindex < y.zindex) {
return -1;
}
if (shouldSortBy) { if (shouldSortBy) {
if (x.stats[sortBy] > y.stats[sortBy]) { return _.sortBy(series, s => s.stats[sortBy] * sortDesc);
return 1 * sortDesc; } else {
} return _.sortBy(series, s => s.zindex);
if (x.stats[sortBy] < y.stats[sortBy]) {
return -1 * sortDesc;
}
} }
return 0;
});
return series;
} }
function translateFillOption(fill) { function translateFillOption(fill) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment