Open MrLepage opened 2 weeks ago
Hi! We've been circling around this issue for quite some time. There's a nuance to this problem, where we believe that ultimately, it's best if the developer makes the decision.
Relevant discussions for reference: Issue 646 and Pull Request 684.
We had an implementation where the max tick length was set to 60 characters, truncating anything longer. This was done to address an edge case with 200+ character ticks without spaces, which ended up occupying 99% of the chart’s width. The solution also needs to work with orientation = "vertical", where labels/ticks can wrap. However, long words can still cause issues. We’d prefer truncated ticks/labels over a full-length label that makes the chart almost invisible, especially on mobile devices.
Additionally, Recharts' styles are extremely sensitive to any padding changes from the default 20. Changing it requires a different logic, especially if you add a y-axis label.
Finally, we’ve noticed that even if a solution works initially, changing the font family or default font size throws off the calculations. Altering padding adds further complications as mentioned.
In the end, we believe it’s up to the developer to decide on label handling. If your data includes dynamic labels that range between 0 and 60+ characters, we think it’s an issue with the labeling itself, rather than with the y-axis width.
Hope this makes the current state more clear.
What problem does this feature solve?
Currently, we manually set the Y-axis width using the
yAxisWidth
prop (e.g.,yAxisWidth={30}
). This can lead to truncated labels or unnecessary white space depending on the data displayed.Feature Request
Add a way to make the Y-axis width adapt automatically to its content.
This would ensure that:
Expected Behavior
The chart component should calculate the optimal width for the Y-axis based on:
Potential Benefits
Additional Context
This feature would be particularly useful for dynamic datasets where label lengths can vary significantly.
Current Workaround
We're currently using a fixed width:
yAxisWidth={30}
.What does the proposed API look like?
To address the issue of automatically adjusting the Y-axis width based on content, I propose the following API enhancement:
autoAdjustYAxisWidth
to the LineChart component.minYAxisWidth
prop when needed.API Usage
Here's how the API would look:
The implementation would work as follows:
If
autoAdjustYAxisWidth
is true (default), calculate the optimal width:If
minYAxisWidth
is also provided, use it as a minimum width:minYAxisWidth
If
autoAdjustYAxisWidth
is false, use the providedminYAxisWidth
or a default value