mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 20:16:00 +08:00
style: corrected the positioning of the charts tooltip (#2402)
* style: corrected the positioning of the charts tooltip * style: stored value for pixel in variable * chore: logic is shifted to plugin --------- Co-authored-by: palashgdev <palashgdev@gmail.com>
This commit is contained in:
parent
80cd317b3b
commit
b0d5b15330
46
frontend/src/components/Graph/Plugin/Tooltip.ts
Normal file
46
frontend/src/components/Graph/Plugin/Tooltip.ts
Normal file
@ -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;
|
||||||
|
}
|
@ -44,6 +44,7 @@ import {
|
|||||||
intersectionCursorPluginId,
|
intersectionCursorPluginId,
|
||||||
IntersectionCursorPluginOptions,
|
IntersectionCursorPluginOptions,
|
||||||
} from './Plugin/IntersectionCursor';
|
} from './Plugin/IntersectionCursor';
|
||||||
|
import { TooltipPosition as TooltipPositionHandler } from './Plugin/Tooltip';
|
||||||
import { LegendsContainer } from './styles';
|
import { LegendsContainer } from './styles';
|
||||||
import { useXAxisTimeUnit } from './xAxisConfig';
|
import { useXAxisTimeUnit } from './xAxisConfig';
|
||||||
import { getToolTipValue, getYAxisFormattedValue } from './yAxisConfig';
|
import { getToolTipValue, getYAxisFormattedValue } from './yAxisConfig';
|
||||||
@ -67,6 +68,8 @@ Chart.register(
|
|||||||
annotationPlugin,
|
annotationPlugin,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Tooltip.positioners.custom = TooltipPositionHandler;
|
||||||
|
|
||||||
function Graph({
|
function Graph({
|
||||||
animate = true,
|
animate = true,
|
||||||
data,
|
data,
|
||||||
@ -177,6 +180,7 @@ function Graph({
|
|||||||
return 'rgba(255, 255, 255, 0.75)';
|
return 'rgba(255, 255, 255, 0.75)';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
position: 'custom',
|
||||||
},
|
},
|
||||||
[dragSelectPluginId]: createDragSelectPluginOptions(
|
[dragSelectPluginId]: createDragSelectPluginOptions(
|
||||||
!!onDragSelect,
|
!!onDragSelect,
|
||||||
@ -324,6 +328,12 @@ function Graph({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module 'chart.js' {
|
||||||
|
interface TooltipPositionerMap {
|
||||||
|
custom: TooltipPositionerFunction<ChartType>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type CustomChartOptions = ChartOptions & {
|
type CustomChartOptions = ChartOptions & {
|
||||||
plugins: {
|
plugins: {
|
||||||
[dragSelectPluginId]: DragSelectPluginOptions | false;
|
[dragSelectPluginId]: DragSelectPluginOptions | false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user