Skip to content

Commit

Permalink
Tooltip staying on charts (#97182)
Browse files Browse the repository at this point in the history
* Add some extra spacing to the chart labels and remove the debounce.  Causing the tooltip to not destroy

* Add min width to the tooltip
  • Loading branch information
j6ll authored Dec 6, 2024
1 parent 11fd5f6 commit e11e16c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@ $break-huge-collapsed-menu: $break-huge - 222px;
border-radius: 4px;
display: none;
text-align: center;
min-width: 60px;
}

&__chart-tooltip-date {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const CampaignStatsLineChart = ( { data, source, resolution }: GraphProps ) => {
ticks: {
show: false,
},
gap: 12,
gap: 16,
values: ( u: uPlot, splits: number[] ) => {
// Filter the splits to show only non-overlapping labels
return splits.map( ( s, i ) =>
Expand All @@ -117,7 +117,7 @@ const CampaignStatsLineChart = ( { data, source, resolution }: GraphProps ) => {
ticks: {
show: false,
},
gap: 12,
gap: 16,
},
],
cursor: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { debounce } from 'lodash';
import React from 'react';
import uPlot from 'uplot';

Expand All @@ -15,11 +14,12 @@ export function tooltip(
if ( ! tooltipRef.current ) {
tooltipRef.current = document.createElement( 'div' );
tooltipRef.current.className = 'campaign-item-details__chart-tooltip';
tooltipRef.current.style.display = 'none';
u.over.parentNode?.appendChild( tooltipRef.current );
}

// Wrap mouse move in a Debounce to reduce the number of updates
const handleMouseMove = debounce( ( e ) => {
const handleMouseMove = ( e: MouseEvent ) => {
if ( ! tooltipRef?.current ) {
return;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ export function tooltip(
} else if ( tooltipRef.current ) {
tooltipRef.current.style.display = 'none';
}
}, 8 ); // 120mhz (1000/120 = 8.333ms)
};

u.over.addEventListener( 'mousemove', handleMouseMove );
u.over.addEventListener( 'mouseleave', () => {
Expand Down

0 comments on commit e11e16c

Please sign in to comment.