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

Width problem and persian prices #1380

Open
arefweb opened this issue Jun 18, 2023 · 7 comments
Open

Width problem and persian prices #1380

arefweb opened this issue Jun 18, 2023 · 7 comments

Comments

@arefweb
Copy link

arefweb commented Jun 18, 2023

Lightweight Charts™ Version: 4.0.1

Steps/code to reproduce:

Issue 1:

When price gets higher leftPriceScale or rightPriceScale width get wider. but at the same time the main chart region width doesn't follow and can't accommodate itself accordingly. so I noticed that the overall width of chart gets bigger than its parent container.
even if leftPriceScale or rightPriceScale had an id I could handle it somehow myself.

Issue 2:

PriceFormat type "price" is what I need but by default it adds decimal points. there is no way for "price" type to not add decimal point
for currency types other than dollar. Please add an option for price type to omit decimal points.

Thanks in advance.

@SlicedSilver
Copy link
Contributor

Could you please share some screenshots / videos, or a code example for the issue you are experiencing with the widths?
From what I understand, you are seeing the entire chart getting larger than the container div element when the values in the price scale get really large. I tried to reproduce this with this example: https://jsfiddle.net/msilverwood/x97fhdpk/ (where the chart width should always match that of the black bar).
It appears to be working as expected.

The price format for a series can be specified using the priceFormat option on the series:
https://tradingview.github.io/lightweight-charts/docs/api/interfaces/SeriesOptionsCommon#priceformat

Here is an explaination of that option:
https://tradingview.github.io/lightweight-charts/docs/api/interfaces/PriceFormatBuiltIn

Setting a precision of 0 will result in the price scales not having decimal points.

Additionally, a custom price formatter can be specified within the chart options:
https://tradingview.github.io/lightweight-charts/docs/api/interfaces/LocalizationOptions#priceformatter

@arefweb
Copy link
Author

arefweb commented Jun 19, 2023

This is the code sample:

image

Here is the screenshot of a large price number:
(Please note that I want the chart to be confined in its parent width ie. chartContainerRef )
large-number

Here is the screenshot of a regular price number:

regular-number

I think that the chart region doesn't follow the priceScale width correctly.

the expected behavior would be for the chart region to shrink in width for larger priceScale widths.

@SlicedSilver
Copy link
Contributor

Thanks for sharing the code and screenshots. I'll have a look at reproducing this later this afternoon (without the React and dynamic width property) but I can confirm that the what you are experiencing is unexpected, and the library shouldn't be expanding in that manner.

With respect to the React code, it is recommended that the chart is only created once (createChart should only be executed once per component). So you should try refactor your code so that the createChart is not within a useEffect. Ideally, you should create the chart once, and then only add / remove / update the series on that chart when the data or properties are changed. This will be more performant.

Additionally, the width option is being applied differently in two places in your code. Within the constructor it is clientWidth - 25, and on the resize event it is just clientWidth.

@arefweb
Copy link
Author

arefweb commented Jun 19, 2023

Thank you Mark for your response. I will consider your suggestions in my code. Actually I have copied this code from lightweight chart documentation. So in documentation example, createChart was in useEffect .

@SlicedSilver
Copy link
Contributor

Apologies, we will update the example in the documentation so it is a bit more performant.

@SlicedSilver
Copy link
Contributor

I'm unable to replicate the issue on a basic page.

Test case with price scale on the left:
https://jsfiddle.net/msilverwood/4m0koxrj/
Test case with the page direction set to rtl:
https://jsfiddle.net/msilverwood/ot9e5nmx/

FYI: an upcoming fix will change the behaviour of the chart when direction: rtl is set for the page (like in your case). #1338

@SlicedSilver
Copy link
Contributor

I would suggest that instead of having a resize handler and setting the width using clientWidth that you could rather use the autoSize option provided by the chart.

https://tradingview.github.io/lightweight-charts/docs/api/interfaces/ChartOptions#autosize

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

No branches or pull requests

2 participants