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 ability to create y axis tick labels #53

Merged
merged 5 commits into from
Jan 18, 2024

Conversation

CloverLeaf5
Copy link
Contributor

@CloverLeaf5 CloverLeaf5 commented Jan 15, 2024

This Pull Request uses the Builder Pattern modeled in #47 to give the user the ability to add sparse or dense labeling of ticks along the y-axis. The same could not be done with the x-axis due to the text direction.

An example and plot are shown below:

Chart::new_with_y_range(200, 50, 0.0, 90 as f32, 0.0, 25_000.0)
        .linecolorplot(&Shape::Continuous(Box::new(|x| 1000.0 * (5.0 * (0.5 * x).sin() + 0.05 * x) + 9000.0)), rgb::RGB { r: 10, g: 100, b: 200 })
        .x_label_format(LabelFormat::Custom(Box::new(move |val| {format!("{}", chrono::Local::now().date_naive() + chrono::Duration::days(val as i64))})))
        .y_label_format(LabelFormat::Value)
        .y_tick_display(TickDisplay::Sparse)
        .nice();

y-axis-tick-labels

A TickDisplayBuilder trait gives Chart a y_tick_display() method for the user to specify the use of tick labels on the y-axis. Calling this method also slightly alters the height of the frame to give better accuracy of positioning and spacing between the labels.

/// Specifies density of labels on the Y axis between ymin and ymax.
/// Default value is `TickDisplay::None`.
pub enum TickDisplay {
    /// Tick labels are not displayed.
    None,
    /// Tick labels are sparsely shown (every 4th row)
    Sparse,
    /// Tick labels are densely shown (every 2nd row)
    Dense,
}

Copy link
Owner

@loony-bean loony-bean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is looking good! Just added few comments about style

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@CloverLeaf5
Copy link
Contributor Author

I updated the Display segment of the update to better match the codebase style and better handle the Vec indexing Option.

src/lib.rs Outdated Show resolved Hide resolved
@loony-bean
Copy link
Owner

Also please update the PR description using new names :)

@CloverLeaf5
Copy link
Contributor Author

I added the line to the label.rs example as well, if that's alright?

@loony-bean loony-bean merged commit 9b3ec25 into loony-bean:master Jan 18, 2024
1 check passed
@CloverLeaf5
Copy link
Contributor Author

I see it up on crates.io! Thanks.
I apologize, it looks like I missed renaming one of the symbols in the doc comment about the enum, line 189

@loony-bean
Copy link
Owner

I see it up on crates.io! Thanks. I apologize, it looks like I missed renaming one of the symbols in the doc comment about the enum, line 189

Ah, no worries, I will fix it later. Thanks for the PR!

@CloverLeaf5
Copy link
Contributor Author

Of course. Happy to contribute!

@CloverLeaf5
Copy link
Contributor Author

Just an FYI - https://docs.rs/textplots/latest/textplots/ still shows the out of date YAxisTickFormat::None under Enums.

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