mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DataFrame: Add meta indicating comparison series (#71129)
* DataFrame: Add meta indicating comparison series * Update metadata type * Update test
This commit is contained in:
parent
57960148e4
commit
c060d5c341
@ -15,6 +15,47 @@ function checkScenario(scenario: TitleScenario): string {
|
||||
return getFieldDisplayName(field, frame, scenario.frames);
|
||||
}
|
||||
|
||||
describe('getFieldDisplayName', () => {
|
||||
it('Should add suffix for comparison frames', () => {
|
||||
const frame = toDataFrame({
|
||||
meta: {
|
||||
timeCompare: {
|
||||
diffMs: -86400000,
|
||||
isTimeShiftQuery: true,
|
||||
},
|
||||
},
|
||||
fields: [
|
||||
{ name: TIME_SERIES_TIME_FIELD_NAME, values: [1, 2, 3], type: FieldType.time },
|
||||
{
|
||||
name: 'Value 1',
|
||||
values: [1, 2, 3],
|
||||
type: FieldType.number,
|
||||
config: {
|
||||
displayName: 'ServerA',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Value 2',
|
||||
values: [1, 2, 3],
|
||||
type: FieldType.number,
|
||||
config: {
|
||||
displayNameFromDS: 'ServerB',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Value 3',
|
||||
values: [1, 2, 3],
|
||||
type: FieldType.number,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(getFieldDisplayName(frame.fields[1], frame)).toBe('ServerA (comparison)');
|
||||
expect(getFieldDisplayName(frame.fields[2], frame)).toBe('ServerB (comparison)');
|
||||
expect(getFieldDisplayName(frame.fields[3], frame)).toBe('Value 3 (comparison)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFrameDisplayName', () => {
|
||||
it('Should return frame name if set', () => {
|
||||
const frame = toDataFrame({
|
||||
|
@ -72,15 +72,15 @@ export function getFieldDisplayName(field: Field, frame?: DataFrame, allFrames?:
|
||||
*/
|
||||
export function calculateFieldDisplayName(field: Field, frame?: DataFrame, allFrames?: DataFrame[]): string {
|
||||
const hasConfigTitle = field.config?.displayName && field.config?.displayName.length;
|
||||
|
||||
const isComparisonSeries = Boolean(frame?.meta?.timeCompare?.isTimeShiftQuery);
|
||||
let displayName = hasConfigTitle ? field.config!.displayName! : field.name;
|
||||
|
||||
if (hasConfigTitle) {
|
||||
return displayName;
|
||||
return isComparisonSeries ? `${displayName} (comparison)` : displayName;
|
||||
}
|
||||
|
||||
if (frame && field.config?.displayNameFromDS) {
|
||||
return field.config.displayNameFromDS;
|
||||
return isComparisonSeries ? `${field.config.displayNameFromDS} (comparison)` : field.config.displayNameFromDS;
|
||||
}
|
||||
|
||||
// This is an ugly exception for time field
|
||||
@ -151,6 +151,9 @@ export function calculateFieldDisplayName(field: Field, frame?: DataFrame, allFr
|
||||
displayName = getUniqueFieldName(field, frame);
|
||||
}
|
||||
|
||||
if (isComparisonSeries) {
|
||||
displayName = `${displayName} (comparison)`;
|
||||
}
|
||||
return displayName;
|
||||
}
|
||||
|
||||
|
@ -94,6 +94,12 @@ export interface QueryResultMeta {
|
||||
*/
|
||||
pathSeparator?: string;
|
||||
|
||||
/** A time shift metadata indicating a result of comparison */
|
||||
timeCompare?: {
|
||||
diffMs: number;
|
||||
isTimeShiftQuery: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Legacy data source specific, should be moved to custom
|
||||
* */
|
||||
|
Loading…
Reference in New Issue
Block a user