lightweight-charts
lightweight-charts copied to clipboard
[Bug] `timeScale` width is 0 after `visiblity` change
Lightweight Charts™ Version: 4.0.1
- Create a chart instance with
timeScale.visible: false
. - Using
chart.applyOptions({ timescale: { visible: true } })
to make timescale visible - Then read width of the timescale - in the same call stack (it will be 0)
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);
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 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).
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.
@skdillon Would you say that your issue is the same as this one?
- https://github.com/tradingview/lightweight-charts/issues/1271
- https://github.com/tradingview/lightweight-charts/pull/1281
Yup, bumping our patch version resolved the issue. Thanks for pointing that out @SlicedSilver