Skip to content

fix(heatmap): update tooltip visibility logic to handle empty tooltip info #2661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 27, 2025

Conversation

andrimal
Copy link
Contributor

@andrimal andrimal commented May 16, 2025

Summary

The heatmap tooltip is no longer visible if it's empty.

Before the fix:
Kapture 2025-05-22 at 13 03 27

After the fix:
Kapture 2025-05-22 at 13 02 14

fix #2546

Details

Issues

Checklist

  • The proper chart type label has been added (e.g. :xy, :partition)
  • The proper feature labels have been added (e.g. :interactions, :axis)
  • All related issues have been linked (i.e. closes #123, fixes #123)
  • New public API exports have been added to packages/charts/src/index.ts
  • Unit tests have been added or updated to match the most common scenarios
  • The proper documentation and/or storybook story has been added or updated
  • The code has been checked for cross-browser compatibility (Chrome, Firefox, Safari, Edge)
  • Visual changes have been tested with light and dark themes

@andrimal andrimal added :tooltip Related to hover tooltip :heatmap Heatmap/Swimlane chart related issue labels May 21, 2025
@andrimal
Copy link
Contributor Author

buildkite update vrt

@andrimal andrimal marked this pull request as ready for review May 22, 2025 11:05
@markov00 markov00 requested a review from mariairiartef May 23, 2025 09:31
Copy link
Contributor

@mariairiartef mariairiartef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked and the tooltip has already a property called isVisible. For the specific case we are covering, we are setting it to true:

tooltipInfo.values.push({
label: '',
color: Colors.Transparent.keyword,
isHighlighted: false,
isVisible: true,
seriesIdentifier: {
specId: spec.id,
key: spec.id,
},
value: `${pickedShapes.value}`,
formattedValue: `${pickedShapes.text}`,
datum: pickedShapes.value,
displayOnly: true,
});

Have you considered updating this value and using it in isTooltipVisibleSelector? For example:

isVisible: Boolean(pickedShapes.text)

And then in the selector:

visible: tooltipInfo.values.some(({ isVisible }) => isVisible) || pinned,

Otherwise, you can try to add a condition like the following at the beginning of isTooltipVisibleSelector:

if (
  type === TooltipType.None ||
  tooltipInfo.values.length === 0 ||
  (tooltipInfo.values.length === 1 && !tooltipInfo.values[0]?.formattedValue)
) {
  return {
    visible: false,
    isExternal: false,
    displayOnly: false,
    isPinnable: false,
  };
}

but this depends on how you build the tooltip in packages/charts/src/chart_types/heatmap/state/selectors/tooltip.ts

@andrimal
Copy link
Contributor Author

I've checked and the tooltip has already a property called isVisible. For the specific case we are covering, we are setting it to true:

tooltipInfo.values.push({
label: '',
color: Colors.Transparent.keyword,
isHighlighted: false,
isVisible: true,
seriesIdentifier: {
specId: spec.id,
key: spec.id,
},
value: `${pickedShapes.value}`,
formattedValue: `${pickedShapes.text}`,
datum: pickedShapes.value,
displayOnly: true,
});

Have you considered updating this value and using it in isTooltipVisibleSelector? For example:

isVisible: Boolean(pickedShapes.text)

And then in the selector:

visible: tooltipInfo.values.some(({ isVisible }) => isVisible) || pinned,

Otherwise, you can try to add a condition like the following at the beginning of isTooltipVisibleSelector:

if (
  type === TooltipType.None ||
  tooltipInfo.values.length === 0 ||
  (tooltipInfo.values.length === 1 && !tooltipInfo.values[0]?.formattedValue)
) {
  return {
    visible: false,
    isExternal: false,
    displayOnly: false,
    isPinnable: false,
  };
}

but this depends on how you build the tooltip in packages/charts/src/chart_types/heatmap/state/selectors/tooltip.ts

Nice suggestion @mariairiartef! I used the isVisible property to check the tooltip visibility.

@andrimal
Copy link
Contributor Author

buildkite test this

@andrimal
Copy link
Contributor Author

buildkite update vrt

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation wise it LGTM. I've doubts if we need to apply the same logic also to the Y axis value and X axis value when the mouse pointer is on the chart and one of the axis has an empty value (see second screenshot that shows an empty Y Value) but I believe we can discuss this offline and and add it in case in a subsequent phase.

@andrimal andrimal merged commit ff5ff27 into elastic:main May 27, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:heatmap Heatmap/Swimlane chart related issue :tooltip Related to hover tooltip
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Heatmap axis tooltip shows even when no value is present
3 participants