Skip to content

fix(GlLineChart): Tooltip fix on MS Edge

Miguel Rincon requested to merge 2230-line-chart-tooltip-fix into main

What does this MR do?

Fixes #2230 (closed)

Fixes missing tooltips for line charts on Microsoft Edge by making use of the simplified tooltip component. Line charts don't have to calculate the tooltip position.

Background

#2230 (closed) was opened because our tooltips were missing in all our chart types: area-chart, bar-chart, column-chart, discrete-scatter-chart, heatmap, line-chart, stacked-column-chart. Later the grouprunner opened gitlab#431238 (closed) because we saw the same issue in our line-chart.

@x-- provided a fix for a few of them (!3467 (merged), !3468 (merged), !3469 (merged)), we needed to fix each.

In gitlab-ui, in each chart we used chart.getDom().addEventListener('mousemove') to decide the state of the tooltip (it's position and whether is shown or not), @x-- replaced chart.getDom().addEventListener with chart.getZr().on to provide support in Edge (more on getZr and zRender at https://apache.github.io/echarts-handbook/en/concepts/event/). I quote from !3454 (closed):

Cause of the problem: use getDom() to bind event, then, use zrX and zrY which are not included in the native event to get the relative position, in firefox/chrome browser, echarts has inject the value (it's out of specification), in edge, not injected, so tooltip can not display correctly.

Correction method: use the standard getZr() to get zrender instance to bind the event.

In !3806 (merged) I introduced a refactor in our tooltips, so they can directly use the chart instance and add the event listeners required. I took the opportunity to use chart.getZr().on to provide Edge support (In that MR I only made changes to the area-chart to keep the MR scope small and a strictly a refactor, so there were no bugfixes there).

In this MR we put everything together! (@x--'s fix, plus my refactor) to apply the same change to all charts. I also include integration tests in cypress for all chart to prevent this regression: I suspect there could be better ways than chart.getZr().on, but at least for now this works well in all browsers.

Work to be done

We should enable our on CI to run Edge (!3813 (merged)) now that our Edge tests pass. I am also looking into improving the <slot> API of our tooltips (!3800 (closed)) because I find them hard to customize.

More ideas! echarts has a hook to render tooltips: https://echarts.apache.org/en/option.html#tooltip.formatter which could be better suited to this than zRender events. Now that we have our tooltip implementation in a single place and with integration tests, this should accelerate our improvements in this area.

Screenshots or screen recordings

2023-11-17_08.09.16

Testing locally

$ yarn run start

In a separate tab:

$ yarn run cy:edge # runs on edge
$ yarn run cy:run # runs on firefox

You can also visit http://localhost:9001/ and confirm charts show tooltips correctly in different browsers (I tried all our supported browsers Chrome, Firefox, Safari and Edge).

Integration merge requests

Does this MR meet the acceptance criteria?

This checklist encourages the authors, reviewers, and maintainers of merge requests (MRs) to confirm changes were analyzed for conformity with the project's guidelines, security and accessibility.

Toggle the acceptance checklist

Conformity

  • Code review guidelines.
  • GitLab UI's contributing guidelines.
  • If it changes a Pajamas-compliant component's look & feel, the MR has been reviewed by a UX designer.
  • If it changes GitLab UI's documentation guidelines, the MR has been reviewed by a Technical Writer.
  • If the MR changes a component's API, integration MR(s) have been opened (see integration merge requests above).
  • Added the ~"component:*" label(s) if applicable.

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • Security reports checked/validated by a reviewer from the AppSec team

Accessibility

If this MR adds or modifies a component, take a few moments to review the following:

  • All actions and functionality can be done with a keyboard.
  • Links, buttons, and controls have a visible focus state.
  • All content is presented in text or with a text equivalent. For example, alt text for SVG, or aria-label for icons that have meaning or perform actions.
  • Changes in a component’s state are announced by a screen reader. For example, changing aria-expanded="false" to aria-expanded="true" when an accordion is expanded.
  • Color combinations have sufficient contrast.

Closes #2230 (closed)

Edited by Miguel Rincon

Merge request reports