Skip to content
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

[Bug] timeScale width is 0 after visiblity change #1407

Open
nichita-pasecinic opened this issue Aug 17, 2023 · 5 comments
Open

[Bug] timeScale width is 0 after visiblity change #1407

nichita-pasecinic opened this issue Aug 17, 2023 · 5 comments
Labels
good first issue Good issue for first-time contributors. polish Very minor behavior improvement that users will enjoy.

Comments

@nichita-pasecinic
Copy link

Lightweight Charts™ Version: 4.0.1

  1. Create a chart instance with timeScale.visible: false.
  2. Using chart.applyOptions({ timescale: { visible: true } }) to make timescale visible
  3. Then read width of the timescale - in the same call stack (it will be 0)

Repro on CodeSandbox

if calling the .width() method in a timeout it works, is this expected ?

chart.applyOptions({
    timeScale: { visible: true },
  });

setTimeout(() => {
    const width = chart.timeScale().width();
    console.log("width: ", width);
}, 0);
@SlicedSilver
Copy link
Contributor

Yes, I believe that this is expected behaviour (only check value after a timeout like requestAnimationFrame).
For the chart to know the width of the timeScale it needs to render it. So it can't be checked immediately.

However, it should be possible for the chart to know what the width of the timescale would be if it was visible (even if it is not) because the timescale width is the same as the pane width (chart width minus the price scale widths).

@SlicedSilver SlicedSilver added good first issue Good issue for first-time contributors. polish Very minor behavior improvement that users will enjoy. labels Aug 17, 2023
@nichita-pasecinic
Copy link
Author

@SlicedSilver thanks for explanations.

I agree with:

However, it should be possible for the chart to know what the width of the timescale would be if it was visible (even if it is not) because the timescale width is the same as the pane width (chart width minus the price scale widths).

@ghost
Copy link

ghost commented Sep 1, 2023

I'm also running into an issue around this where I'm trying to render markers over a series and when I call setMarkers on the series the markers don't render. This is because when this._internal__series._internal_setMarkers(convertedMarkers) is called within in setMarkers there is a call to _private__recalculateMarkers which retrieves the timescale and then does a check timeScale._internal_isEmpty(). This check checks the width this._private__width === 0 and is causing the markers to not render.

@ghost ghost mentioned this issue Sep 1, 2023
2 tasks
@SlicedSilver
Copy link
Contributor

@ghost
Copy link

ghost commented Sep 1, 2023

Yup, bumping our patch version resolved the issue. Thanks for pointing that out @SlicedSilver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good issue for first-time contributors. polish Very minor behavior improvement that users will enjoy.
Projects
None yet
Development

No branches or pull requests

2 participants