VizTooltips: Fix series labels after zooming (#82985)

This commit is contained in:
Leon Sorokin 2024-02-17 00:38:13 -06:00 committed by GitHub
parent a02519895e
commit 94a274635b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 2 deletions

View File

@ -56,6 +56,11 @@ export interface JoinOptions {
*/ */
keepOriginIndices?: boolean; keepOriginIndices?: boolean;
/**
* @internal -- keep any pre-cached state.displayName
*/
keepDisplayNames?: boolean;
/** /**
* @internal -- Optionally specify a join mode (outer or inner) * @internal -- Optionally specify a join mode (outer or inner)
*/ */
@ -223,8 +228,10 @@ export function joinDataFrames(options: JoinOptions): DataFrame | undefined {
for (const field of fields) { for (const field of fields) {
a.push(field.values); a.push(field.values);
originalFields.push(field); originalFields.push(field);
// clear field displayName state if (!options.keepDisplayNames) {
delete field.state?.displayName; // clear field displayName state
delete field.state?.displayName;
}
// store frame field order for tabular data join // store frame field order for tabular data join
frameFieldsOrder.push(fieldsOrder); frameFieldsOrder.push(fieldsOrder);
fieldsOrder++; fieldsOrder++;

View File

@ -110,6 +110,11 @@ export function preparePlotFrame(frames: DataFrame[], dimFields: XYFieldMatchers
joinBy: dimFields.x, joinBy: dimFields.x,
keep: dimFields.y, keep: dimFields.y,
keepOriginIndices: true, keepOriginIndices: true,
// the join transformer force-deletes our state.displayName cache unless keepDisplayNames: true
// https://github.com/grafana/grafana/pull/31121
// https://github.com/grafana/grafana/pull/71806
keepDisplayNames: true,
}); });
if (alignedFrame) { if (alignedFrame) {

View File

@ -21,6 +21,7 @@ import {
getFieldConfigWithMinMax, getFieldConfigWithMinMax,
ThresholdsMode, ThresholdsMode,
TimeRange, TimeRange,
cacheFieldDisplayNames,
} from '@grafana/data'; } from '@grafana/data';
import { maybeSortFrame } from '@grafana/data/src/transformations/transformers/joinDataFrames'; import { maybeSortFrame } from '@grafana/data/src/transformations/transformers/joinDataFrames';
import { applyNullInsertThreshold } from '@grafana/data/src/transformations/transformers/nulls/nullInsertThreshold'; import { applyNullInsertThreshold } from '@grafana/data/src/transformations/transformers/nulls/nullInsertThreshold';
@ -437,6 +438,9 @@ export function prepareTimelineFields(
if (!series?.length) { if (!series?.length) {
return { warn: 'No data in response' }; return { warn: 'No data in response' };
} }
cacheFieldDisplayNames(series);
let hasTimeseries = false; let hasTimeseries = false;
const frames: DataFrame[] = []; const frames: DataFrame[] = [];

View File

@ -10,6 +10,7 @@ import {
isBooleanUnit, isBooleanUnit,
SortedVector, SortedVector,
TimeRange, TimeRange,
cacheFieldDisplayNames,
} from '@grafana/data'; } from '@grafana/data';
import { convertFieldType } from '@grafana/data/src/transformations/transformers/convertFieldType'; import { convertFieldType } from '@grafana/data/src/transformations/transformers/convertFieldType';
import { applyNullInsertThreshold } from '@grafana/data/src/transformations/transformers/nulls/nullInsertThreshold'; import { applyNullInsertThreshold } from '@grafana/data/src/transformations/transformers/nulls/nullInsertThreshold';
@ -82,6 +83,8 @@ export function prepareGraphableFields(
return null; return null;
} }
cacheFieldDisplayNames(series);
let useNumericX = xNumFieldIdx != null; let useNumericX = xNumFieldIdx != null;
// Make sure the numeric x field is first in the frame // Make sure the numeric x field is first in the frame