From f7766f73b8deed23cb01d5b07600a21ff918429c Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Sun, 11 Jun 2023 07:54:58 +0200 Subject: [PATCH] [v10.0.x] Heatmap: Sort fields by numeric names when single frame (#69880) Heatmap: Sort fields by numeric names when single frame (#69879) (cherry picked from commit cc8bedc1739331456ff27ca46a6ada1cb85f2608) Co-authored-by: Leon Sorokin --- public/app/plugins/panel/heatmap/fields.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/panel/heatmap/fields.ts b/public/app/plugins/panel/heatmap/fields.ts index 9c3aae6fcd4..00f9c32597d 100644 --- a/public/app/plugins/panel/heatmap/fields.ts +++ b/public/app/plugins/panel/heatmap/fields.ts @@ -108,7 +108,20 @@ export function prepareHeatmapData( })!, ][0]; } else { - rowsHeatmap = frames[0]; + let frame = frames[0]; + let numberFields = frame.fields.filter((field) => field.type === FieldType.number); + let allNamesNumeric = numberFields.every((field) => !Number.isNaN(parseSampleValue(field.name))); + + if (allNamesNumeric) { + numberFields.sort((a, b) => parseSampleValue(a.name) - parseSampleValue(b.name)); + + rowsHeatmap = { + ...frame, + fields: [frame.fields.find((f) => f.type === FieldType.time)!, ...numberFields], + }; + } else { + rowsHeatmap = frame; + } } }