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

Allow hiding nil group entries or allow simple bar chart color assignment #621

Open
forddavis opened this issue Jul 19, 2023 · 3 comments
Open

Comments

@forddavis
Copy link

Description

I would really like an option to hide nil bars. Perhaps this is an unconventional use case, but I am trying to show intensity of a variable over time on a bar chart.

I could also achieve this if it were possible to style individual bars and fully customize the legend, however it doesn't appear to be possible to assign colors to bars within a single dataset either.

Steps to Reproduce

data = [
  [0.5, "00:00", "#07A6FF", "nominal"],
  [0.64, "00:20", "#FFA500", "marginal"],
  [0.75, "00:40", "#FFA500", "marginal"],
  [1.0, "01:00", "#FF0000", "failed"]
]

intervals = data.map(&:second)
intensities = data.map(&:last).uniq

g = Gruff::Bar.new
colors = ["#07A6FF","#FFA500", "#FF0000"]

g.theme = {
  colors: colors,
  marker_color: '#dddddd',
  font_color: 'black',
  background_colors: 'white'
}

g.labels = intervals

intensities.each do |intensity|
   g.data(intensity, data.map { |i| i.first if i.last == intensity })
end

This results in wonky spacing because it draws the nil datapoints for each set. But I only want to draw one set per label.
graph

Additionally there is no way to assign a color to each bar without assigning separate datasets.

Would it be possible to add support for hiding empty bars and their spacing?

Apologies if I'm missing something. I thought for sure it could be done with the library in it's current state since it is very capable, but I've spent a good amount of time tinkering with this and can't figure it out with existing methods.

System Configuration

  • ImageMagick version: ImageMagick 7.1.1-8 Q16-HDRI aarch64 21129
  • RMagick version: 5.2.0
  • Gruff version: 0.22.0
  • Ruby version: 2.7.2
  • Environment (Operating system, version and so on): Mac Ventura 13.3.1
@Watson1978
Copy link
Collaborator

Unfortunately, it does not have such the features...
If we support it, we may need to create a new class instead of Gruff::Bar...

@forddavis
Copy link
Author

Thank you for the response @Watson1978. Is there any interest in this feature? I could potentially make a PR.

It seems like an option g.collapse_empty_columns defaulting to false would be potentially useful, although I could see a separate class being warranted if you expect that to be a major deviation from current behavior.

@Watson1978
Copy link
Collaborator

The internal that it is not distinction is made between nil and 0.
It wouldn't handle properly when you really need 0, currently implementation...

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

No branches or pull requests

2 participants