Skip to content

browser zoom and dom zoom will cause mouse position fault in tooltip  #15103

Open

Description

@sheepzheng

Version

5.1.1

Steps to reproduce

in script use document.body.style.zoom to adapt different size of screen. in echarts option add tooltip. use ctrl in browser to zoom your demo or use different size of screen to display your demo

What is expected?

use document.body.style.zoom and zoom browser will not effect mouse hover position in tooltip

What is actually happening?

you will find mouse hover event will trigger wrong part of this chart's tooltip.

Activity

  1. echarts-bot commented on Jun 8, 2021

    @echarts-bot

    Hi! We've received your issue and please be patient to get responded. 🎉
    The average response time is expected to be within one day for weekdays.

    In the meanwhile, please make sure that it contains a minimum reproducible demo and necessary images to illustrate. Otherwise, our committers will ask you to do so.

    A minimum reproducible demo should contain as little data and components as possible but can still illustrate your problem. This is the best way for us to reproduce it and solve the problem faster.

    You may also check out the API and chart option to get the answer.

    If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to [email protected]. Please attach the issue link if it's a technical question.

    If you are interested in the project, you may also subscribe our mailing list.

    Have a nice day! 🍵

  2. added
    en
    pending
    on Jun 8, 2021
  3. plainheart commented on Jun 8, 2021

    @plainheart
    Member

    Thanks for the report. Related to #14253, #13615, #13614, #13606, #12645, #11032, #9310, #8386, #8382, #8286, #6674, #6083, #3635, #3511 etc.
    I drafted a solution for this issue before, but it may need some discussion. List it in the 5.x milestone.

  4. added this to the 5.x milestone on Jun 8, 2021
  5. removed
    pending
    on Jun 8, 2021
  6. sheepzheng commented on Jun 11, 2021

    @sheepzheng
    Author

    I fixed this problem by setting body transform.
    In script add:

                 var ratioX = window.innerWidth / 1920;//dev screensize echarts instance 
             document.body.style.width = '1920px';//dev screensize echarts instance 
             document.body.style.height = '1080px';//dev screensize echarts instance 
             document.body.style.transform = `scale(${ratioX},${ratioX})`;
             document.body.style.transformOrigin = `0 0`;
    

    then tooltip works right with browser zoom and different sizes of screen

  7. yushouqing commented on Aug 24, 2021

    @yushouqing

    i have the same issue. browser zoom changed will cause mouse position fault.

  8. added
    discussion-required
    on May 22, 2022
  9. wmasfoe commented on Aug 9, 2022

    @wmasfoe

    hello 有解决方案吗?

  10. hauserkristof commented on Aug 25, 2022

    @hauserkristof

    +1

  11. modified the milestones: 5.x, TBD on Sep 1, 2022
  12. lihaonanzs commented on Nov 8, 2022

    @lihaonanzs

    transform后鼠标移入正常,触摸屏移入还存在。

  13. hjmmc commented on Nov 25, 2022

    @hjmmc

    If you just fix the width, you can try this code, which is basically the same as the zoom effect

    const app = document.getElementById('app')
    const ratioX = window.innerWidth / 1920
    app.style.width = '1920px'
    app.style.height = `${window.innerHeight / ratioX}px`
    app.style.transform = `scale(${ratioX},${ratioX})`
    app.style.transformOrigin = `0 0`
  14. tarik56 commented on May 14, 2023

    @tarik56

    Okey so for anyone encountering this issue, here is how I fixxed it after a few hours of torture. I have noticed that echarts has an internal rerenderer that triggers on certain conditions. Though, it won't do that when your zoom has already been applied to parent DOM elements.

    If your parent element, for example the html element has a predefined zoom of eg. 0.7 set by you, you will have to calculate the inverse and set the zoom on the echart parent div or the echart div itself to trigger a rerender with a valid zoom for it to handle it correctly.

    Calculate the inverse with eg.: 1 / 0.7 = 1.42857

    Sample:

    const element = document.getElementsByTagName('html')[0];
    const computedStyle = window.getComputedStyle(element);
    const zoom = computedStyle.getPropertyValue('zoom');
    this.setState({zoom_amount: 1 / zoom})
    
    //if zoom = 0.7
    //then zoom_amount = 1.42857
    //then give the new zoom, depending on what library you use like below
    
    <EchartDivOrParentDiv options={your_options} style={{zoom: this.state.zoom}} />
    
    //If you give the zoom to the parent div too early without the echart being rendered
    //then it might pose some scaling issues. I recommend giving the zoom directly the echart element.

    Would be great to have this kind of logic naturally included in the echart code but that's one way to handle it. Hope it helps some of you.

  15. zystudios commented on Jun 28, 2024

    @zystudios

    2024官方还没有解决啊

  16. modified the milestones: TBD, 6.0.0 on Jul 1, 2024
  17. self-assigned this
    on Jul 1, 2024
  18. york-chen commented on Jul 11, 2024

    @york-chen

    Okey so for anyone encountering this issue, here is how I fixxed it after a few hours of torture. I have noticed that echarts has an internal rerenderer that triggers on certain conditions. Though, it won't do that when your zoom has already been applied to parent DOM elements.

    If your parent element, for example the html element has a predefined zoom of eg. 0.7 set by you, you will have to calculate the inverse and set the zoom on the echart parent div or the echart div itself to trigger a rerender with a valid zoom for it to handle it correctly.

    Calculate the inverse with eg.: 1 / 0.7 = 1.42857

    Sample:

    const element = document.getElementsByTagName('html')[0];
    const computedStyle = window.getComputedStyle(element);
    const zoom = computedStyle.getPropertyValue('zoom');
    this.setState({zoom_amount: 1 / zoom})
    
    //if zoom = 0.7
    //then zoom_amount = 1.42857
    //then give the new zoom, depending on what library you use like below
    
    <EchartDivOrParentDiv options={your_options} style={{zoom: this.state.zoom}} />
    
    //If you give the zoom to the parent div too early without the echart being rendered
    //then it might pose some scaling issues. I recommend giving the zoom directly the echart element.

    Would be great to have this kind of logic naturally included in the echart code but that's one way to handle it. Hope it helps some of you.

    we set 'transform:scale' to it's parents elemet,and then set scale to itself, did that mean,do nothing for it

  19. modified the milestones: 6.0.0, 6.x on Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugdiscussion-requireden

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions