HeatMap: Sort y buckets when all bucket names are numeric (#65322)

This commit is contained in:
Leon Sorokin 2023-03-28 17:16:24 -05:00 committed by GitHub
parent 1e098d2a4c
commit 6f4232bee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -650,13 +650,13 @@ function transformToHistogramOverTime(seriesList: DataFrame[]) {
return seriesList;
}
function sortSeriesByLabel(s1: DataFrame, s2: DataFrame): number {
export function sortSeriesByLabel(s1: DataFrame, s2: DataFrame): number {
let le1, le2;
try {
// fail if not integer. might happen with bad queries
le1 = parseSampleValue(s1.name ?? '');
le2 = parseSampleValue(s2.name ?? '');
le1 = parseSampleValue(s1.name ?? s1.fields[1].name);
le2 = parseSampleValue(s2.name ?? s2.fields[1].name);
} catch (err) {
console.error(err);
return 0;

View File

@ -19,6 +19,7 @@ import {
readHeatmapRowsCustomMeta,
rowsToCellsHeatmap,
} from 'app/features/transformers/calculateHeatmap/heatmap';
import { parseSampleValue, sortSeriesByLabel } from 'app/plugins/datasource/prometheus/result_transformer';
import { CellValues, PanelOptions } from './types';
import { boundedMinMax } from './utils';
@ -94,6 +95,14 @@ export function prepareHeatmapData(
// Everything past here assumes a field for each row in the heatmap (buckets)
if (!rowsHeatmap) {
if (frames.length > 1) {
let allNamesNumeric = frames.every(
(frame) => !Number.isNaN(parseSampleValue(frame.name ?? frame.fields[1].name))
);
if (allNamesNumeric) {
frames.sort(sortSeriesByLabel);
}
rowsHeatmap = [
outerJoinDataFrames({
frames,