tradingview / lightweight-charts

Performant financial charts built with HTML5 canvas
https://www.tradingview.com/lightweight-charts/
Apache License 2.0
9.62k stars 1.64k forks source link

autoSize is not smooth #1724

Open vishnuc opened 3 weeks ago

vishnuc commented 3 weeks ago

Please check this video

https://youtu.be/q4TgSq-eZ-M

When resized from right to left its smooth.. but when resized left to right its shaking and not giving smooth effect.

I tried

new ResizeObserver((entries) => {
    if (entries.length === 0 || entries[0].target !== container) {
        return;
    }
    const newRect = entries[0].contentRect;
    chart.applyOptions({ height: newRect.height, width: newRect.width });
}).observe(container);

, also tried autoSize : true option ,

even debounced , but when widht is increased on left side its causing this unpleasent experience.

vishnuc commented 1 week ago

hi @SlicedSilver , can you check this issue , please watch this video - https://youtu.be/J4hFzGIGR4o

price pane and time pane is jumping when resized and autoSize is set to true ,, its smooth in original tradingview website.. how to keep it fixed and autosize affects only the chart ??

signatenkov commented 1 week ago

Hey @vishnuc,

I've made a snippet with autoSize and it works fine in both directions.

https://stackblitz.com/edit/vitejs-vite-qtrscy?embed=1&file=index.ts&hideExplorer=1&view=preview

My initial assumption is:

Could you please have a look? Can you reproduce it in isolation?

vishnuc commented 1 week ago

Hi , check this out - https://stackblitz.com/edit/stackblitz-starters-qp2nbt?file=index.html

when u drag the horizontal bar up and down to resize.. u can see time pane is jumping.. also if resize from left u can see price pane is shaking..

if u cannot reproduce , let me know will share video..It happens same in mac and windows.

signatenkov commented 1 week ago

@vishnuc Thanks, i've checked you example and this jumping occurs when chart container width is not aligned to fixed value. Charts are pixel perfect by design so they resize in fixed increments while you supplying continues values. Container width of 443.281px resolves to chart width of 442px.

vishnuc commented 1 week ago

Hi , so what is the solution ? I increase height of container by percentage .. I cannot use pixels......also i tried to use rounded pixels like u said ,, still panes are jumping/shaking.

vishnuc commented 1 week ago

@signatenkov : please check - https://youtu.be/-BASMYx9fKo , how smooth panes are in main tradingview library