Visualizations: Fixes Stat/BarGauge/Gauge/PieChart all values mode showing same name if same value (#35368) (#35384)
(cherry picked from commit c425c30d7e)
Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
This commit is contained in:
co-authored by
Torkel Ödegaard
parent
7360428b3e
commit
11f2a91377
@@ -259,6 +259,32 @@ describe('FieldDisplay', () => {
|
|||||||
expect(result[1].display.text).toEqual('20');
|
expect(result[1].display.text).toEqual('20');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('With cached display processor', () => {
|
||||||
|
const options = createDisplayOptions({
|
||||||
|
reduceOptions: {
|
||||||
|
values: true,
|
||||||
|
calcs: [],
|
||||||
|
},
|
||||||
|
data: [
|
||||||
|
toDataFrame({
|
||||||
|
fields: [
|
||||||
|
{ name: 'Name', values: ['A', 'B'] },
|
||||||
|
{ name: 'Value', values: [10, 10] },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const cache = { numeric: 10, text: 'Value' };
|
||||||
|
options.data![0].fields[1].display = (v: any) => {
|
||||||
|
return cache;
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = getFieldDisplayValues(options);
|
||||||
|
expect(result[0].display.title).toEqual('A');
|
||||||
|
expect(result[1].display.title).toEqual('B');
|
||||||
|
});
|
||||||
|
|
||||||
it('Single string field multiple value fields', () => {
|
it('Single string field multiple value fields', () => {
|
||||||
const options = createDisplayOptions({
|
const options = createDisplayOptions({
|
||||||
reduceOptions: {
|
reduceOptions: {
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// const displayName = getFieldDisplayName(field, dataFrame, data);
|
|
||||||
const displayName = field.config.displayName ?? '';
|
const displayName = field.config.displayName ?? '';
|
||||||
|
|
||||||
const display =
|
const display =
|
||||||
@@ -155,25 +154,17 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi
|
|||||||
field.state = setIndexForPaletteColor(field, values.length);
|
field.state = setIndexForPaletteColor(field, values.length);
|
||||||
|
|
||||||
const displayValue = display(field.values.get(j));
|
const displayValue = display(field.values.get(j));
|
||||||
|
const rowName = getSmartDisplayNameForRow(dataFrame, field, j, replaceVariables, scopedVars);
|
||||||
if (displayName !== '') {
|
const overrideColor = lookupRowColorFromOverride(rowName, options.fieldConfig, theme);
|
||||||
displayValue.title = replaceVariables(displayName, {
|
|
||||||
...field.state?.scopedVars, // series and field scoped vars
|
|
||||||
...scopedVars,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
displayValue.title = getSmartDisplayNameForRow(dataFrame, field, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
const overrideColor = lookupRowColorFromOverride(displayValue, options.fieldConfig);
|
|
||||||
if (overrideColor) {
|
|
||||||
displayValue.color = theme.visualization.getColorByName(overrideColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
values.push({
|
values.push({
|
||||||
name: '',
|
name: '',
|
||||||
field: config,
|
field: config,
|
||||||
display: displayValue,
|
display: {
|
||||||
|
...displayValue,
|
||||||
|
title: rowName,
|
||||||
|
color: overrideColor ?? displayValue.color,
|
||||||
|
},
|
||||||
view,
|
view,
|
||||||
colIndex: i,
|
colIndex: i,
|
||||||
rowIndex: j,
|
rowIndex: j,
|
||||||
@@ -250,10 +241,23 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi
|
|||||||
return values;
|
return values;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getSmartDisplayNameForRow(frame: DataFrame, field: Field, rowIndex: number): string {
|
function getSmartDisplayNameForRow(
|
||||||
|
frame: DataFrame,
|
||||||
|
field: Field,
|
||||||
|
rowIndex: number,
|
||||||
|
replaceVariables: InterpolateFunction,
|
||||||
|
scopedVars: ScopedVars
|
||||||
|
): string {
|
||||||
let parts: string[] = [];
|
let parts: string[] = [];
|
||||||
let otherNumericFields = 0;
|
let otherNumericFields = 0;
|
||||||
|
|
||||||
|
if (field.config.displayName) {
|
||||||
|
return replaceVariables(field.config.displayName, {
|
||||||
|
...field.state?.scopedVars, // series and field scoped vars
|
||||||
|
...scopedVars,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const otherField of frame.fields) {
|
for (const otherField of frame.fields) {
|
||||||
if (otherField === field) {
|
if (otherField === field) {
|
||||||
continue;
|
continue;
|
||||||
@@ -290,16 +294,18 @@ function setIndexForPaletteColor(field: Field, currentLength: number) {
|
|||||||
/**
|
/**
|
||||||
* This function makes overrides that set color work for row values
|
* This function makes overrides that set color work for row values
|
||||||
*/
|
*/
|
||||||
function lookupRowColorFromOverride(display: DisplayValue, fieldConfig: FieldConfigSource) {
|
function lookupRowColorFromOverride(displayName: string, fieldConfig: FieldConfigSource, theme: GrafanaTheme2) {
|
||||||
for (const override of fieldConfig.overrides) {
|
for (const override of fieldConfig.overrides) {
|
||||||
if (override.matcher.id === 'byName' && override.matcher.options === display.title) {
|
if (override.matcher.id === 'byName' && override.matcher.options === displayName) {
|
||||||
for (const prop of override.properties) {
|
for (const prop of override.properties) {
|
||||||
if (prop.id === 'color' && prop.value) {
|
if (prop.id === 'color' && prop.value) {
|
||||||
return prop.value.fixedColor;
|
return theme.visualization.getColorByName(prop.value.fixedColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasLinks(field: Field): boolean {
|
export function hasLinks(field: Field): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user