textplots-rs icon indicating copy to clipboard operation
textplots-rs copied to clipboard

Add axes formatting callbacks

Open KoffeinFlummi opened this issue 3 years ago • 0 comments

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):

KoffeinFlummi avatar Jan 17 '22 22:01 KoffeinFlummi