VisActor / VisActor/VChart

[Bug] initial position for tooltip is incorrect in react-vchart

Open
#4,118 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug high priority react-vchart tooltip
Dominant language
TypeScript
Stars
1.8k
Forks
221
Avg merge
1d 6h
Merged PRs (30d)
26

Description

Version

2.0.0

Link to Minimal Reproduction

null

Steps to Reproduce
const getData = () =>
  ['2:00', '4:00', '6:00', '8:00', '10:00', '12:00', '14:00', '16:00', '18:00'].map(time => ({
    time,
    value: Math.random() * 10
  }));

const getSpec = () => ({
  type: 'line',
  data: {
    values: getData()
  },
  xField: 'time',
  yField: 'value'
});

const root = document.getElementById(CONTAINER_ID);
const { VChart } = ReactVChart;
const { useState, useRef, useEffect } = React;

const Card = () => {
  const [spec, setSpec] = useState(getSpec());
  const chartRef = useRef(null);
  useEffect(() => {
    window['vchart'] = chartRef;
  }, []);

  const handleSwitchData = () => {
    setSpec(getSpec());
  };

  return (
    <div>
      <VChart ref={chartRef} spec={spec} tooltipRender={()=>{
        return <div>1111</div>
      }}/>
      <button
        style={{ position: 'absolute', top: 0, left: '50%', transform: 'translate(-50%, 0)' }}
        onClick={handleSwitchData}
      >
        Switch Data
      </button>
    </div>
  );
};

ReactDom.createRoot(root).render(<Card />);

// release react instance, do not copy
window.customRelease = () => {
  ReactDom.unmountComponentAtNode(root);
};
Current Behavior

Tooltip 的初始位置出现在左下角,第一次 hover 时会出现 tooltip 从左下角移动过来的情况。

Expected Behavior

正确计算 Tooltip 初始位置。

Environment
- OS:
- Browser:
- Framework:
Any additional comments?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided ReactVChart example, focusing on the chartRef, tooltipRender callback, and Switch Data handler. Trace tooltip positioning during the initial render and after switching data, then verify that the first hover starts at the correct position without visible movement.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
data-visualization, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.