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

Resizing chart applies only every 2 pixels #1746

Open
vishnuc opened this issue Dec 1, 2024 · 5 comments
Open

Resizing chart applies only every 2 pixels #1746

vishnuc opened this issue Dec 1, 2024 · 5 comments
Labels
needs investigation Needs further investigation.

Comments

@vishnuc
Copy link

vishnuc commented Dec 1, 2024

Hi , when I set height and weight of chart using following function

	chart.resize(width, height, 1);

only when its value is even number its resizing , how to change this behaviour to 1 pixels or lower.

@SlicedSilver
Copy link
Contributor

This behavior is expected because we need to ensure that the canvas elements on the page have a rounded width instead of a partial pixel (such as 100.5px). If the dimensions are not integers, the canvas rendering can appear blurry. Since there are two canvases in each direction (the chart and price scale, or the chart and timescale), the calculation accounts for this.

The library does not provide an option to change this behavior.

@vishnuc
Copy link
Author

vishnuc commented Dec 1, 2024

hi yea , in library it was rounding to even numbers,, I modified to just Math.round and build it .. its working 99% smooth like original TV now.

Can I know the reason why its rounded to even like 92,94 instead of 91,92,93 .. like how origianl Tv does.

@vishnuc
Copy link
Author

vishnuc commented Dec 1, 2024

To be exact this is the code that rounds to even

export function suggestChartSize(originalSize: Size): Size {
    const integerWidth = Math.floor(originalSize.width);
    const integerHeight = Math.floor(originalSize.height);
    const width = integerWidth - (integerWidth % 2);
    const height = integerHeight - (integerHeight % 2);
    return size({ width, height });
}

@SlicedSilver
Copy link
Contributor

We want to ensure that the dimension is not larger than the originalSize, so if we used round instead of floor then it is possible that the value would be too large (499.5 rounded becomes 500 and 500 % 2 is 0 therefore the calculated size is 500 which is larger than 499.5).

I know that using 498 instead of 499 (in this example) seems strange but this behaviour was coded to ensure that the browser doesn't apply any smoothing to canvas. You may not notice this on your machine but from experience across many different browsers and DPR values (sometimes strange DPRs like 1.25 as well) that this will be providing a more robust result.

The time spent by the user resizing windows (or panels) is typically very small in comparison to a static size.

The browser rendering issues that we are working around may not be an issue any more in newer browser versions so we could re-investigate this and adjust this behaviour.

@SlicedSilver SlicedSilver added the needs investigation Needs further investigation. label Dec 1, 2024
@vishnuc
Copy link
Author

vishnuc commented Dec 1, 2024

Yea I can understand that , but how come original tradingview incrementing / decrementing its divs / canvas etc pixels by 1 , but LWC is doing it by 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation Needs further investigation.
Projects
None yet
Development

No branches or pull requests

2 participants