navidys / tvxwidgets

tvxwidgets provides extra widgets for tview
MIT License
146 stars 12 forks source link

Feature: Allow custom X-Axis labeling #69

Closed markusressel closed 1 month ago

markusressel commented 1 month ago

This PR adds the ability to draw custom X-Axis labels:

image

To use this, a dev must provide a custom function that calculates the X-Axis label for an index:

bmLineChart.SetXAxisLabelFunc(func(i int) string {
    label := fmt.Sprintf("%.1f", xFunc1(i))
    return label
})

Please have a look at the added example in demos/plot_xaxis_labels/main.go for a better explanation. By default this function simply returns i as a string, maintaining the existing behavior.

Animated Version:

Peek 2024-10-13 01-09

Note that it is automatically determined which labels are shown, based on the available space and the width of each individual label. Labels are selected based on their centered distance to the actual value in the graph.

markusressel commented 1 month ago

Note: The Example is not complete yet, since it is supposed to use the functionality of #68 . As with #68 , please let me integrate these changes before merging.

codecov-commenter commented 1 month ago

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 22.58065% with 48 lines in your changes missing coverage. Please review.

Project coverage is 51.08%. Comparing base (40e5944) to head (091fcae).

Files with missing lines Patch % Lines
plot.go 22.58% 44 Missing and 4 partials :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #69 +/- ## ========================================== - Coverage 53.61% 51.08% -2.54% ========================================== Files 9 9 Lines 968 1016 +48 ========================================== Hits 519 519 - Misses 433 477 +44 - Partials 16 20 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

navidys commented 1 month ago

Hi @markusressel

Thanks for the PR, I have merged the previous PRs, will wait for you to push your changes to this PR and then will release a new version.

Thanks.

markusressel commented 1 month ago

@navidys Necessary changes have been made, this is how it looks now:

Peek 2024-10-13 10-42

Peek 2024-10-13 10-43

markusressel commented 1 month ago

@navidys I have fixed as many issues as I could, please decide yourself what to do with the rest.

markusressel commented 1 month ago

Also: I do not plan to create any more feature PRs after this for the time beeing ;)

navidys commented 1 month ago

Hi @markusressel Thanks for the PR, I will fix the lint and merge it.