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

Add axes formatting callbacks #37

Closed
wants to merge 2 commits into from

Conversation

KoffeinFlummi
Copy link

This adds the ability to specify a callback for formatting the min/max labels for both the x and y axis. This allows formatting the x axis as dates (#9) or adding units, and including colored strings.

I have also included a commit that changes the rendering order so that the axes are printed behind the plots. This prevents the white of the axes resetting the color of the plots. If you want, I can split this up into multiple PRs.

Example Code (from and to are chrono::NaiveDate):

        let mut chart = Chart::new(200, 40, 0.0, (to - from).num_days() as f32)
            .xaxis_formatter(move |x| format!("{}", from.clone() + Duration::days(x as i64)))
            .yaxis_formatter(move |y| format!("{:.1} {}", y, unit.clone().white()));

Result (without reordering commit):

Result (with reordering commit):

This allows adding units, or formatting the x axis as dates/times.
This only matters when color is used, but it prevents the white of the
axes blocking the color of the plot.
PraxTube added a commit to PraxTube/conplot that referenced this pull request Aug 7, 2023
@loony-bean
Copy link
Owner

This looks totally amazing @KoffeinFlummi! By any chance, could you include fully working example (into examples dir) that will render the picture similar to what you have put in this PR?

@loony-bean
Copy link
Owner

Requested features added as part of #47.
Thanks again @KoffeinFlummi for this PR and inspiration.

@loony-bean loony-bean closed this Sep 11, 2023
@KoffeinFlummi
Copy link
Author

Thanks to @uandere and apologies for the silence, I've unfortunately been pretty busy these past few weeks.

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

Successfully merging this pull request may close these issues.

2 participants