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

Improve Barchart creation for developers #683

Open
joshka opened this issue Dec 11, 2023 · 2 comments · May be fixed by #936
Open

Improve Barchart creation for developers #683

joshka opened this issue Dec 11, 2023 · 2 comments · May be fixed by #936
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@joshka
Copy link
Member

joshka commented Dec 11, 2023

Problem

BarChart's construction is overly verbose. To construct anything other than the default value / text you need to do:

let data = BarGroup::default().bars(&[
        Bar::default()
            .label("Red".into())
            .value(2)
            .style(Style::new().red()),
        Bar::default()
            .label("Green".into())
            .value(7)
            .style(Style::new().green()),
        Bar::default()
            .label("Blue".into())
            .value(11)
            .style(Style::new().blue()),
    ]);

Solution

  • Bar should have a new() method that accepts a label and value Bar::new("Red", 2)
  • Bar::label and the new new method should accept Into<Line> so we can write Bar::default().label("foo") - Bar should implement styled so that style shorthands work Bar::new("Red", 2").red()
  • BarGroup should have a new method that accepts I: IntoIterator, with I::Item = Into so that Bargroup::new([Bar::new("R", 2").red(), Bar::new("B", 3).blue()]) works
  • BarGroup::label should accept Into
  • BarGroup::bars should accept I:IntoIterator, with I::Item : Into
  • BarChart should have a new function that accepts bars (into iterator item = into bar) (unsure if this should also take direction - probably worth doing it as it highlights that direction is available better than just defaulting it)
  • Docs and unit tests for all of the above

Generally this should aim to be a non-breaking change. There may be places that are under-tested, so make sure to add any missing unit tests. If you can change a method's behavior and some test doesn't break, then there's probably a missing test.

@joshka joshka added enhancement New feature or request good first issue Good for newcomers labels Dec 11, 2023
@KekmaTime
Copy link

@joshka i would like to work on this issue can you assign me this

@joshka
Copy link
Member Author

joshka commented Dec 11, 2023

Sounds good. I added a quick note above about non-breaking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
2 participants