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.

style: corrected the positioning of the charts tooltip (#2402)

Mary Ojob0d5b1533065
diff --git a/frontend/src/components/Graph/Plugin/Tooltip.ts b/frontend/src/components/Graph/Plugin/Tooltip.ts
new file mode 100644
index 0000000000..0a37694609
--- /dev/null
+++ b/frontend/src/components/Graph/Plugin/Tooltip.ts
@@ -0,0 +1,46 @@
+import {
+ ActiveElement,
+ ChartTypeRegistry,
+ Point,
+ TooltipModel,
+ TooltipXAlignment,
+ TooltipYAlignment,
+} from 'chart.js';
+
+export function TooltipPosition(
+ this: TooltipModel<keyof ChartTypeRegistry>,
+ _: readonly ActiveElement[],
+ eventPosition: Point,
+): ITooltipPosition {
+ const {
+ chartArea: { width },
+ scales: { x, y },
+ } = this.chart;
+
+ const valueForPixelOnX = Number(x.getValueForPixel(eventPosition.x));
+ const valueForPixelonY = Number(y.getValueForPixel(eventPosition.y));
+
+ const rightmostWidth = this.width + x.getPixelForValue(valueForPixelOnX) + 20;
+
+ if (rightmostWidth > width) {
+ return {
+ x: x.getPixelForValue(valueForPixelOnX) - 20,
+ y: y.getPixelForValue(valueForPixelonY) + 10,
+ xAlign: 'right',
+ yAlign: 'top',
+ };
+ }
+ return {
+ x: x.getPixelForValue(valueForPixelOnX) + 20,
+ y: y.getPixelForValue(valueForPixelonY) + 10,
+ xAlign: 'left',
+ yAlign: 'top',
+ };
+}
+
+interface ITooltipPosition {
+ x: number;
+ y: number;
+ xAlign: TooltipXAlignment;
+ yAlign: TooltipYAlignment;
+}
diff --git a/frontend/src/components/Graph/index.tsx b/frontend/src/components/Graph/index.tsx
index 8bc8ee4109..527510f764 100644
--- a/frontend/src/components/Graph/index.tsx
+++ b/frontend/src/components/Graph/index.tsx
@@ -44,6 +44,7 @@ import {
intersectionCursorPluginId,
IntersectionCursorPluginOptions,
} from './Plugin/IntersectionCursor';
+import { TooltipPosition as TooltipPositionHandler } from './Plugin/Tooltip';
import { LegendsContainer } from './styles';
import { useXAxisTimeUnit } from './xAxisConfig';
import { getToolTipValue, getYAxisFormattedValue } from './yAxisConfig';
@@ -67,6 +68,8 @@ Chart.register(
annotationPlugin,
);
+Tooltip.positioners.custom = TooltipPositionHandler;
+
function Graph({
animate = true,
data,
@@ -177,6 +180,7 @@ function Graph({
return 'rgba(255, 255, 255, 0.75)';
},
},
+ position: 'custom',
},
[dragSelectPluginId]: createDragSelectPluginOptions(
!!onDragSelect,
@@ -324,6 +328,12 @@ function Graph({
);
}
+declare module 'chart.js' {
+ interface TooltipPositionerMap {
+ custom: TooltipPositionerFunction<ChartType>;
+ }
+}
+
type CustomChartOptions = ChartOptions & {
plugins: {
[dragSelectPluginId]: DragSelectPluginOptions | false;