mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Configure explore series colours via field config (#20239)
This commit is contained in:
parent
e4afc8d518
commit
225ecd680a
@ -63,10 +63,9 @@ function convertTimeSeriesToDataFrame(timeSeries: TimeSeries): DataFrame {
|
||||
type: FieldType.number,
|
||||
config: {
|
||||
unit: timeSeries.unit,
|
||||
color: timeSeries.color,
|
||||
},
|
||||
values: new ArrayVector<TimeSeriesValue>(),
|
||||
} as Field<TimeSeriesValue, ArrayVector<TimeSeriesValue>>,
|
||||
},
|
||||
{
|
||||
name: 'Time',
|
||||
type: FieldType.time,
|
||||
@ -74,7 +73,7 @@ function convertTimeSeriesToDataFrame(timeSeries: TimeSeries): DataFrame {
|
||||
unit: 'dateTimeAsIso',
|
||||
},
|
||||
values: new ArrayVector<number>(),
|
||||
} as Field<number, ArrayVector<number>>,
|
||||
},
|
||||
];
|
||||
|
||||
for (const point of timeSeries.datapoints) {
|
||||
|
@ -58,7 +58,6 @@ export interface TimeSeries extends QueryResultBase {
|
||||
target: string;
|
||||
datapoints: TimeSeriesPoints;
|
||||
unit?: string;
|
||||
color?: string;
|
||||
tags?: Labels;
|
||||
}
|
||||
|
||||
|
@ -149,13 +149,18 @@ export function makeSeriesForLogs(rows: LogRowModel[], intervalMs: number, timeZ
|
||||
});
|
||||
|
||||
const timeField = data.fields[1];
|
||||
|
||||
timeField.display = getDisplayProcessor({
|
||||
config: timeField.config,
|
||||
type: timeField.type,
|
||||
isUtc: timeZone === 'utc',
|
||||
});
|
||||
|
||||
const valueField = data.fields[0];
|
||||
valueField.config = {
|
||||
...valueField.config,
|
||||
color: series.color,
|
||||
};
|
||||
|
||||
const graphSeries: GraphSeriesXY = {
|
||||
color: series.color,
|
||||
label: series.alias,
|
||||
@ -168,7 +173,7 @@ export function makeSeriesForLogs(rows: LogRowModel[], intervalMs: number, timeZ
|
||||
},
|
||||
seriesIndex: i,
|
||||
timeField,
|
||||
valueField: data.fields[0],
|
||||
valueField,
|
||||
// for now setting the time step to be 0,
|
||||
// and handle the bar width by setting lineWidth instead of barWidth in flot options
|
||||
timeStep: 0,
|
||||
@ -197,7 +202,6 @@ export function dataFrameToLogsModel(dataFrame: DataFrame[], intervalMs: number,
|
||||
// Create metrics from logs
|
||||
logsModel.series = makeSeriesForLogs(logsModel.rows, intervalMs, timeZone);
|
||||
} else {
|
||||
// We got metrics in the dataFrame so process those
|
||||
logsModel.series = getGraphSeriesModel(
|
||||
metricSeries,
|
||||
timeZone,
|
||||
|
@ -74,10 +74,16 @@ export const getGraphSeriesModel = (
|
||||
});
|
||||
}
|
||||
|
||||
const seriesColor =
|
||||
seriesOptions[field.name] && seriesOptions[field.name].color
|
||||
? getColorFromHexRgbOrName(seriesOptions[field.name].color)
|
||||
: colors[graphs.length % colors.length];
|
||||
let seriesColor;
|
||||
if (seriesOptions[field.name] && seriesOptions[field.name].color) {
|
||||
// Case when panel has settings provided via SeriesOptions, i.e. graph panel
|
||||
seriesColor = getColorFromHexRgbOrName(seriesOptions[field.name].color);
|
||||
} else if (field.config && field.config.color) {
|
||||
// Case when color settings are set on field, i.e. Explore logs histogram (see makeSeriesForLogs)
|
||||
seriesColor = field.config.color;
|
||||
} else {
|
||||
seriesColor = colors[graphs.length % colors.length];
|
||||
}
|
||||
|
||||
field.config = fieldOptions
|
||||
? {
|
||||
@ -86,7 +92,7 @@ export const getGraphSeriesModel = (
|
||||
decimals: fieldOptions.defaults.decimals,
|
||||
color: seriesColor,
|
||||
}
|
||||
: { ...field.config };
|
||||
: { ...field.config, color: seriesColor };
|
||||
|
||||
field.display = getDisplayProcessor({ config: { ...field.config }, type: field.type });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user