From 0f9ea44144ba7d1fa364eb6864a095c9398ea31b Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Wed, 23 Jul 2025 09:55:58 -0500 Subject: [PATCH] XYChart: Lift restrictions around re-using fields for color and size (#106690) --- public/app/plugins/panel/xychart/SeriesEditor.tsx | 2 -- .../app/plugins/panel/xychart/XYChartTooltip.tsx | 14 +++++++------- public/app/plugins/panel/xychart/utils.ts | 10 ++-------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/public/app/plugins/panel/xychart/SeriesEditor.tsx b/public/app/plugins/panel/xychart/SeriesEditor.tsx index a68cf297ac3..54bc8085154 100644 --- a/public/app/plugins/panel/xychart/SeriesEditor.tsx +++ b/public/app/plugins/panel/xychart/SeriesEditor.tsx @@ -256,7 +256,6 @@ export const SeriesEditor = ({ settings: { // TODO: filter out series.y?.exclude.options, series.size.matcher.options, series.color.matcher.options filter: (field) => - field.name !== series.x?.matcher.options && (mapping === SeriesMapping.Auto || field.state?.origin?.frameIndex === series.frame?.matcher.options) && field.type === FieldType.number && @@ -292,7 +291,6 @@ export const SeriesEditor = ({ settings: { // TODO: filter out series.y?.exclude.options, series.size.matcher.options, series.color.matcher.options filter: (field) => - field.name !== series.x?.matcher.options && (mapping === SeriesMapping.Auto || field.state?.origin?.frameIndex === series.frame?.matcher.options) && field.type === FieldType.number && diff --git a/public/app/plugins/panel/xychart/XYChartTooltip.tsx b/public/app/plugins/panel/xychart/XYChartTooltip.tsx index 6760621fd82..585910e9184 100644 --- a/public/app/plugins/panel/xychart/XYChartTooltip.tsx +++ b/public/app/plugins/panel/xychart/XYChartTooltip.tsx @@ -63,18 +63,18 @@ export const XYChartTooltip = ({ let label = series.name.value; - let seriesColor = series.color.fixed; - // let colorField = series.color.field; - // let pointColor: string; + let seriesColor = colorField?.display?.(colorField.values[rowIndex]).color ?? series.color.fixed ?? '#fff'; + let fillOpacity = colorField?.config.custom?.fillOpacity; - // if (colorField != null) { - // pointColor = colorField.display?.(colorField.values[rowIndex]).color!; - // } + // TODO: skip this if seriesColor already has an alpha component, such as opacity-by-value or opacity gradient schemes + if (fillOpacity != null) { + seriesColor = colorManipulator.alpha(seriesColor, fillOpacity / 100); + } const headerItem: VizTooltipItem = { label, value: '', - color: colorManipulator.alpha(seriesColor ?? '#fff', 0.5), + color: seriesColor, colorIndicator: ColorIndicator.marker_md, }; diff --git a/public/app/plugins/panel/xychart/utils.ts b/public/app/plugins/panel/xychart/utils.ts index df7fb0bc041..3526f7c9d6d 100644 --- a/public/app/plugins/panel/xychart/utils.ts +++ b/public/app/plugins/panel/xychart/utils.ts @@ -99,14 +99,8 @@ export function prepSeries( // only grabbing number fields (exclude time, string, enum, other) let onlyNumFields = onlyNumTimeFields.filter((field) => field.type === FieldType.number); - let color = - colorMatcher != null - ? onlyNumFields.find((field) => field !== x && colorMatcher!(field, frame, frames)) - : undefined; - let size = - sizeMatcher != null - ? onlyNumFields.find((field) => field !== x && field !== color && sizeMatcher!(field, frame, frames)) - : undefined; + let color = colorMatcher != null ? onlyNumFields.find((field) => colorMatcher(field, frame, frames)) : undefined; + let size = sizeMatcher != null ? onlyNumFields.find((field) => sizeMatcher(field, frame, frames)) : undefined; // x field is required if (x != null) {