Skip to content

Commit

Permalink
fix(tooltips): fix tooltips on dashboards (#19473)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored Dec 21, 2023
1 parent 2f142b1 commit 8865be4
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export const LineGraph = (): JSX.Element => {
tooltipEl.classList.remove('above', 'below', 'no-transform')
tooltipEl.classList.add(tooltip.yAlign || 'no-transform')
tooltipEl.style.opacity = '1'
tooltipEl.style.display = 'initial'

if (tooltip.body) {
const referenceDataPoint = tooltip.dataPoints[0] // Use this point as reference to get the date
Expand Down Expand Up @@ -225,8 +224,8 @@ export const LineGraph = (): JSX.Element => {
? chartClientLeft + tooltip.caretX - tooltipEl.clientWidth - 8 // If tooltip is too large (or close to the edge), show it to the left of the data point instead
: defaultOffsetLeft

tooltipEl.style.top = Math.min(tooltipClientTop, window.innerHeight) + 'px'
tooltipEl.style.left = Math.min(tooltipClientLeft, window.innerWidth) + 'px'
tooltipEl.style.top = tooltipClientTop + 'px'
tooltipEl.style.left = tooltipClientLeft + 'px'
},
},
},
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/scenes/funnels/useFunnelTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ export function useFunnelTooltip(showPersonsModal: boolean): React.RefObject<HTM
const svgRect = vizRef.current?.getBoundingClientRect()
const [tooltipRoot, tooltipEl] = ensureTooltip()
tooltipEl.style.opacity = isTooltipShown ? '1' : '0'
if (isTooltipShown) {
tooltipEl.style.display = 'initial'
}
const tooltipRect = tooltipEl.getBoundingClientRect()
if (tooltipOrigin) {
tooltipRoot.render(
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/scenes/insights/views/BoldNumber/BoldNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ function useBoldNumberTooltip({

useLayoutEffect(() => {
tooltipEl.style.opacity = isTooltipShown ? '1' : '0'
if (isTooltipShown) {
tooltipEl.style.display = 'initial'
}

const seriesResult = insightData?.result?.[0]

Expand Down Expand Up @@ -73,10 +70,10 @@ function useBoldNumberTooltip({
useEffect(() => {
const tooltipRect = tooltipEl.getBoundingClientRect()
if (divRect) {
const desiredTop = window.scrollY + divRect.top - tooltipRect.height - BOLD_NUMBER_TOOLTIP_OFFSET_PX
const desiredLeft = divRect.left + divRect.width / 2 - tooltipRect.width / 2
tooltipEl.style.top = `${Math.min(desiredTop, window.innerHeight)}px`
tooltipEl.style.left = `${Math.min(desiredLeft, window.innerWidth)}px`
tooltipEl.style.top = `${
window.scrollY + divRect.top - tooltipRect.height - BOLD_NUMBER_TOOLTIP_OFFSET_PX
}px`
tooltipEl.style.left = `${divRect.left + divRect.width / 2 - tooltipRect.width / 2}px`
}
})

Expand Down
6 changes: 2 additions & 4 deletions frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export function ensureTooltip(): [Root, HTMLElement] {
tooltipEl = document.createElement('div')
tooltipEl.id = 'InsightTooltipWrapper'
tooltipEl.classList.add('InsightTooltipWrapper')
tooltipEl.style.display = 'none'
document.body.appendChild(tooltipEl)
}

Expand Down Expand Up @@ -461,7 +460,6 @@ export function LineGraph_({
tooltipEl.classList.remove('above', 'below', 'no-transform')
tooltipEl.classList.add(tooltip.yAlign || 'no-transform')
tooltipEl.style.opacity = '1'
tooltipEl.style.display = 'initial'

if (tooltip.body) {
const referenceDataPoint = tooltip.dataPoints[0] // Use this point as reference to get the date
Expand Down Expand Up @@ -549,8 +547,8 @@ export function LineGraph_({
? chartClientLeft + tooltip.caretX - tooltipEl.clientWidth - 8 // If tooltip is too large (or close to the edge), show it to the left of the data point instead
: defaultOffsetLeft

tooltipEl.style.top = Math.min(tooltipClientTop, window.innerHeight) + 'px'
tooltipEl.style.left = Math.min(tooltipClientLeft, window.innerWidth) + 'px'
tooltipEl.style.top = tooltipClientTop + 'px'
tooltipEl.style.left = tooltipClientLeft + 'px'
},
},
...(!isBar
Expand Down
1 change: 0 additions & 1 deletion frontend/src/scenes/insights/views/LineGraph/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export function PieChart({
tooltipEl.classList.remove('above', 'below', 'no-transform')
tooltipEl.classList.add(tooltip.yAlign || 'no-transform')
tooltipEl.style.opacity = '1'
tooltipEl.style.display = 'initial'

if (tooltip.body) {
const referenceDataPoint = tooltip.dataPoints[0] // Use this point as reference to get the date
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/scenes/insights/views/WorldMap/WorldMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ function useWorldMapTooltip(showPersonsModal: boolean): React.RefObject<SVGSVGEl

useEffect(() => {
tooltipEl.style.opacity = isTooltipShown ? '1' : '0'
if (isTooltipShown) {
tooltipEl.style.display = 'initial'
}

if (tooltipCoordinates) {
tooltipRoot.render(
Expand Down

0 comments on commit 8865be4

Please sign in to comment.