diff --git a/frontend/src/component/insights/components/LineChart/ChartTooltip/ChartTooltip.tsx b/frontend/src/component/insights/components/LineChart/ChartTooltip/ChartTooltip.tsx index ff0b8891b2..c50ea76e71 100644 --- a/frontend/src/component/insights/components/LineChart/ChartTooltip/ChartTooltip.tsx +++ b/frontend/src/component/insights/components/LineChart/ChartTooltip/ChartTooltip.tsx @@ -46,18 +46,6 @@ const StyledLabelIcon = styled('span')(({ theme }) => ({ const offset = 16; -const getAlign = (align?: 'left' | 'right' | 'center') => { - if (align === 'left') { - return 'flex-start'; - } - - if (align === 'right') { - return 'flex-end'; - } - - return 'center'; -}; - const getLeftOffset = (caretX = 0, align?: 'left' | 'right' | 'center') => { if (align === 'left') { return caretX + offset; @@ -73,23 +61,29 @@ const getLeftOffset = (caretX = 0, align?: 'left' | 'right' | 'center') => { export const ChartTooltipContainer: FC = ({ tooltip, children, -}) => ( - ({ - top: (tooltip?.caretY || 0) + offset, - left: getLeftOffset(tooltip?.caretX, tooltip?.align), - width: '1px', - position: 'absolute', - display: tooltip ? 'flex' : 'none', - pointerEvents: 'none', - zIndex: theme.zIndex.tooltip, - flexDirection: 'column', - alignItems: getAlign(tooltip?.align), - })} - > - {children} - -); +}) => { + const top = tooltip?.caretY ?? 0 + offset; + const left = getLeftOffset(tooltip?.caretX, tooltip?.align); + return ( + ({ + top: 0, + left: 0, + transform: `translate(${left}px, ${top}px)`, + transition: 'transform 0.2s ease-in-out', + width: '1px', + position: 'absolute', + display: tooltip ? 'flex' : 'none', + pointerEvents: 'none', + zIndex: theme.zIndex.tooltip, + flexDirection: 'column', + alignItems: 'center', + })} + > + {children} + + ); +}; export const ChartTooltip: VFC = ({ tooltip }) => (