Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat: highlight nearest in chart on hover (#2184)

volodfast8a5b26cefeaf
diff --git a/frontend/src/components/Graph/index.tsx b/frontend/src/components/Graph/index.tsx
index 75b6ace889..20ffc5a22c 100644
--- a/frontend/src/components/Graph/index.tsx
+++ b/frontend/src/components/Graph/index.tsx
@@ -81,6 +81,7 @@ function Graph({
onDragSelect,
dragSelectColor,
}: GraphProps): JSX.Element {
+ const nearestDatasetIndex = useRef<null | number>(null);
const chartRef = useRef<HTMLCanvasElement>(null);
const isDarkMode = useIsDarkMode();
@@ -164,8 +165,16 @@ function Graph({
if (context.parsed.y !== null) {
label += getToolTipValue(context.parsed.y.toString(), yAxisUnit);
}
+
return label;
},
+ labelTextColor(labelData) {
+ if (labelData.datasetIndex === nearestDatasetIndex.current) {
+ return 'rgba(255, 255, 255, 1)';
+ }
+
+ return 'rgba(255, 255, 255, 0.75)';
+ },
},
},
[dragSelectPluginId]: createDragSelectPluginOptions(
@@ -237,6 +246,22 @@ function Graph({
onClickHandler(event, element, chart, data);
}
},
+ onHover: (event, _, chart) => {
+ if (event.native) {
+ const interactions = chart.getElementsAtEventForMode(
+ event.native,
+ 'nearest',
+ {
+ intersect: false,
+ },
+ true,
+ );
+
+ if (interactions[0]) {
+ nearestDatasetIndex.current = interactions[0].datasetIndex;
+ }
+ }
+ },
};
const chartHasData = hasData(data);