Skip to content

Commit 2c370f7

Browse files
authored
Merge pull request #104 from NETWAYS/sort-labels-nat
Sort charts with strnatcmp
2 parents 4d7ed3d + d989dbc commit 2c370f7

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

library/Perfdatagraphs/Common/PerfdataChart.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ public function createChart(PerfdataRequest $request, PerfdataResponse $response
110110
}
111111

112112
$datasets = [];
113-
foreach ($response->getDatasets() as $dataset) {
113+
114+
// Ensure labels have a predictable order
115+
$sets = $response->getDatasets();
116+
uasort($sets, function ($a, $b) {
117+
return strnatcmp($a->getTitle(), $b->getTitle());
118+
});
119+
120+
foreach ($sets as $dataset) {
114121
// If the filter param is set, we only use the dataset when the label matches
115122
if (count($filter) > 0) {
116123
if (!in_array($dataset->getTitle(), $filter)) {

0 commit comments

Comments
 (0)