Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Tooltip no longer highlights hovered data series #24756

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function EchartsMixedTimeseries({
emitCrossFilters,
seriesBreakdown,
onContextMenu,
onFocusedSeries,
xValueFormatter,
xAxis,
refs,
Expand Down Expand Up @@ -123,6 +124,12 @@ export default function EchartsMixedTimeseries({
const { seriesName, seriesIndex } = props;
handleChange(seriesName, seriesIndex);
},
mouseout: () => {
onFocusedSeries(null);
},
mouseover: params => {
onFocusedSeries(params.seriesName);
},
contextmenu: async eventParams => {
if (onContextMenu) {
eventParams.event.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export default function transformProps(
inContextMenu,
emitCrossFilters,
} = chartProps;

let focusedSeries: string | null = null;

const {
verboseMap = {},
currencyFormats = {},
Expand Down Expand Up @@ -576,7 +579,9 @@ export default function transformProps(
? tooltipFormatter
: tooltipFormatterSecondary,
});
rows.push(`<span style="opacity: 0.7">${content}</span>`);
const contentStyle =
key === focusedSeries ? 'font-weight: 700' : 'opacity: 0.7';
rows.push(`<span style="${contentStyle}">${content}</span>`);
});
return rows.join('<br />');
},
Expand Down Expand Up @@ -627,6 +632,10 @@ export default function transformProps(
: [],
};

const onFocusedSeries = (seriesName: string | null) => {
focusedSeries = seriesName;
};

return {
formData,
width,
Expand All @@ -641,6 +650,7 @@ export default function transformProps(
seriesBreakdown: rawSeriesA.length,
selectedValues: filterState.selectedValues || [],
onContextMenu,
onFocusedSeries,
xValueFormatter: tooltipFormatter,
xAxis: {
label: xAxisLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,5 @@ export type EchartsMixedTimeseriesChartTransformedProps =
label: string;
type: AxisType;
};
onFocusedSeries: (series: string | null) => void;
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function EchartsTimeseries({
legendData = [],
onContextMenu,
onLegendStateChanged,
onFocusedSeries,
xValueFormatter,
xAxis,
refs,
Expand Down Expand Up @@ -146,6 +147,12 @@ export default function EchartsTimeseries({
handleChange(name);
}, TIMER_DURATION);
},
mouseout: () => {
onFocusedSeries(null);
},
mouseover: params => {
onFocusedSeries(params.seriesName);
},
legendselectchanged: payload => {
onLegendStateChanged?.(payload.selected);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export default function transformProps(
inContextMenu,
emitCrossFilters,
} = chartProps;

let focusedSeries: string | null = null;

const {
verboseMap = {},
columnFormats = {},
Expand Down Expand Up @@ -524,11 +527,9 @@ export default function transformProps(
: getCustomFormatter(customFormatters, metrics, formatterKey) ??
defaultFormatter,
});
if (!legendState || legendState[key]) {
rows.push(`<span style="font-weight: 700">${content}</span>`);
} else {
rows.push(`<span style="opacity: 0.7">${content}</span>`);
}
const contentStyle =
key === focusedSeries ? 'font-weight: 700' : 'opacity: 0.7';
rows.push(`<span style="${contentStyle}">${content}</span>`);
});
if (stack) {
rows.reverse();
Expand Down Expand Up @@ -575,6 +576,10 @@ export default function transformProps(
: [],
};

const onFocusedSeries = (seriesName: string | null) => {
focusedSeries = seriesName;
};

return {
echartOptions,
emitCrossFilters,
Expand All @@ -589,6 +594,7 @@ export default function transformProps(
legendData,
onContextMenu,
onLegendStateChanged,
onFocusedSeries,
xValueFormatter: tooltipFormatter,
xAxis: {
label: xAxisLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ export type TimeseriesChartTransformedProps =
label: string;
type: AxisType;
};
onFocusedSeries: (series: string | null) => void;
};
Loading