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

Support class Array for UnicodePlot.barplot data: - and wherever else it may make sense #61

Open
rubyFeedback opened this issue Apr 2, 2023 · 0 comments

Comments

@rubyFeedback
Copy link

I recently found this project. One can get a String via .to_s, without
colours, which is super-convenient for display on a webpage - so, no
clue who had this idea, but the project is a really good idea.

Now to my proposal here.

I just tried this:

require 'rbt'
array = RBT.statistics?
require 'unicode_plot'
UnicodePlot.barplot(
  data: array,
  title: 'RBT - increase in the number of programs over the years' 
    ).render

RBT.statistics? is a method in another project. It will return an Array
that has a simple two-entry structure like this:

[["25.10.2005", 274],

I then wanted to plot this.

However had, data: wants a Hash. If an array is given, it fails via:

 .gem/gems/unicode_plot-0.0.5/lib/unicode_plot/barplot.rb:134:in `Hash': can't convert Array into Hash (TypeError)

The simple solution is to pass a Hash e. g. via:

data: Hash[array],

Ok problem solved. But, I think it would be more convenient if an Array can be
given, and unicode_plot tries to convert it into a Hash instead automatically.

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

1 participant