TimeSeries: Fix legend and tooltip colors changing after data refreshes (#63823)

This commit is contained in:
Leon Sorokin
2023-02-28 08:16:27 -06:00
committed by GitHub
parent 429d693a4a
commit b2c0175777
3 changed files with 34 additions and 5 deletions

View File

@ -128,12 +128,30 @@ export function prepareGraphableFields(
}
if (frames.length) {
setClassicPaletteIdxs(frames, theme);
return frames;
}
return null;
}
const setClassicPaletteIdxs = (frames: DataFrame[], theme: GrafanaTheme2) => {
let seriesIndex = 0;
frames.forEach((frame) => {
frame.fields.forEach((field) => {
// TODO: also add FieldType.enum type here after https://github.com/grafana/grafana/pull/60491
if (field.type === FieldType.number || field.type === FieldType.boolean) {
field.state = {
...field.state,
seriesIndex: seriesIndex++, // TODO: skip this for fields with custom renderers (e.g. Candlestick)?
};
field.display = getDisplayProcessor({ field, theme });
}
});
});
};
export function getTimezones(timezones: string[] | undefined, defaultTimezone: string): string[] {
if (!timezones || !timezones.length) {
return [defaultTimezone];