patrykandpatrick / vico

A light and extensible chart library for Android.
https://patrykandpatrick.com/vico/wiki
Apache License 2.0
2.06k stars 123 forks source link

Bottom label truncated sometimes #776

Open neobie opened 2 months ago

neobie commented 2 months ago

How to reproduce

There are around 20 points var spacing = 20/3 itemPlacer = AxisItemPlacer.Horizontal.default(spacing = spacing, offset = spacing / 3, addExtremeLabelPadding = true),

Observed behavior

image

Expected behavior

The label should not truncated providing there are plenty of spaces.

Vico version(s)

1.15.0-alpha.1

Android version(s)

wearos 30

Additional information

Sometimes it happen, but sometimes it don't (provided with dynamic data) Version 1.15

patrickmichalik commented 1 month ago

Hello! Thanks for the report. HorizontalAxis labels are centered relative to their x coordinates. A label’s maximum width is determined by the amount of room on the side with less free space. Here, there’s insufficient space to the left of the first label—some padding would be required for the label not to be truncated.

In Vico 1, addExtremeLabelPadding works only for labels whose x values are ChartValues.minX or ChartValues.maxX. The leftmost and rightmost labels in your chart don’t meet this requirement, hence the truncation issue. This has been addressed in Vico 2—now, addExtremeLabelPadding works for the first and last labels regardless of their x values. There’s currently a bug that can cause an excessive amount of padding to be added in charts with zoom disabled, but this will be resolved in Vico 2.0.0 Alpha 22, which we plan on releasing shortly.

Please consider updating to Vico 2.0.0 Alpha 22 once it’s available. The behavior observed in Vico 1, while suboptimal, isn’t a bug, and Vico 1 receives only bug fixes. A possible workaround for Vico 1 is to manually add some padding, which you can do via HorizontalLayout.FullWidth, but this won’t be as reliable as Vico 2.0.0 Alpha 22’s addExtremeLabelPadding.

Please also note that, by default, some padding is added to axis labels, making them wider than their text. You may want to remove this padding. Let me know if you need any help doing so. Finally, I wanted to mention that the Vico 1 documentation appears to wrongly suggest that addExtremeLabelPadding behaves as it does in Vico 2, and this inaccuracy will be corrected.

patrickmichalik commented 1 month ago

Vico 2.0.0 Alpha 22 is now available.

hadys7s commented 2 weeks ago

63915c39-b3f1-41e4-a8e8-d45d2767b602 still happening with me please i need help asap

Gowsky commented 2 weeks ago

@hadys7s this issue concerns the first and last labels being truncated. Can you please explain which labels in your image are truncated? Also, you’ve already asked this question in #838. What is the purpose of duplicating it?

hadys7s commented 2 weeks ago

sorry i don't know if it's an issue or still not supported b8925823-e01d-42ac-8ee2-db95a277a5a4

this is happening to me there are alot of empty x axis i dont want to show them but still it's taking space from the x axis here i used horizontalLayout = HorizontalLayout.segmented(), and when i use horizontalLayout = HorizontalLayout.fullWidth(), it shows the first label only

1c7402bf-e1c5-4e0d-8e79-c8869f9cdd88

Gowsky commented 2 weeks ago

@hadys7s, it is supported, but we need to see your code to help you achieve the desired result. Please share a runnable snippet, but under your discussion, not under this unrelated issue.

hadys7s commented 2 weeks ago

okay thank u

hadys7s commented 2 weeks ago

done please check and thanks for the quick reply and for ur help really appreciate it @Gowsky