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

Error when running example #20

Closed
schneems opened this issue Jan 6, 2020 · 2 comments
Closed

Error when running example #20

schneems opened this issue Jan 6, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@schneems
Copy link
Contributor

schneems commented Jan 6, 2020

Code:

values = [3.101679, 3.113501, 3.123834, 3.125208, 3.129073, 3.140281, 3.142695, 3.144393, 3.144639, 3.145352, 3.146368, 3.149352, 3.150657, 3.15165, 3.158634, 3.15962, 3.162757, 3.163482, 3.169293, 3.178286, 3.18577, 3.194678, 3.19519, 3.201861, 3.204169, 3.208111, 3.20958, 3.219322, 3.220371, 3.225563, 3.228888, 3.233049, 3.244273, 3.247167, 3.24887, 3.253761, 3.296395, 3.336913, 3.354431, 3.358318, 3.37479, 3.375476, 3.415869, 3.420531, 3.492295, 3.500603, 3.618732, 3.639656, 3.663728, 3.686562, 3.689323, 3.704562, 3.712246, 3.715634, 3.765543, 3.776477, 3.78326, 3.784031, 3.798115, 3.812997, 3.82962]

require 'unicode_plot'

plot = UnicodePlot.histogram(values, title: "Histogram")
plot.render($stdout)

IRB:

irb(main):001:0> values = [3.101679, 3.113501, 3.123834, 3.125208, 3.129073, 3.1
40281, 3.142695, 3.144393, 3.144639, 3.145352, 3.146368, 3.149352, 3.150657, 3.1
5165, 3.158634, 3.15962, 3.162757, 3.163482, 3.169293, 3.178286, 3.18577, 3.1946
78, 3.19519, 3.201861, 3.204169, 3.208111, 3.20958, 3.219322, 3.220371, 3.225563
, 3.228888, 3.233049, 3.244273, 3.247167, 3.24887, 3.253761, 3.296395, 3.336913,
 3.354431, 3.358318, 3.37479, 3.375476, 3.415869, 3.420531, 3.492295, 3.500603,
3.618732, 3.639656, 3.663728, 3.686562, 3.689323, 3.704562, 3.712246, 3.715634,
3.765543, 3.776477, 3.78326, 3.784031, 3.798115, 3.812997, 3.82962]
irb(main):002:0>
irb(main):003:0> require 'unicode_plot'
=> true
irb(main):004:0>
irb(main):005:0> plot = UnicodePlot.histogram(values, title: "Histogram")
irb(main):006:0> plot.render($stdout)
Traceback (most recent call last):
       10: from /Users/rschneeman/.rubies/ruby-2.7.0/bin/irb:23:in `<main>'
        9: from /Users/rschneeman/.rubies/ruby-2.7.0/bin/irb:23:in `load'
        8: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
        7: from (irb):6
        6: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/plot.rb:106:in `render'
        5: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/renderer.rb:63:in `render'
        4: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/renderer.rb:78:in `render'
        3: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/renderer.rb:87:in `render_top'
        2: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/renderer.rb:231:in `print_title'
        1: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/styled_printer.rb:63:in `print_styled'
NameError (uninitialized constant UnicodePlot::StyledPrinter::StringIO)

I'm guessing that StringIO in that context should be ::StringIO

Ruby 2.7.0, latest version of this gem.

@schneems
Copy link
Contributor Author

schneems commented Jan 6, 2020

Ahh, there needs to be a:

require 'stringio'

schneems added a commit to schneems/unicode_plot.rb that referenced this issue Jan 6, 2020
When the `stringio` library is not required then using the examples gives us this error:

```
NameError (uninitialized constant UnicodePlot::StyledPrinter::StringIO)
```

By adding this require to the top level library file we guarantee it is always loaded.
schneems added a commit to schneems/unicode_plot.rb that referenced this issue Jan 6, 2020
When the `stringio` library is not required then using the examples gives us this error:

```
NameError (uninitialized constant UnicodePlot::StyledPrinter::StringIO)
```

By adding this require to the top level library file we guarantee it is always loaded.
@schneems
Copy link
Contributor Author

schneems commented Jan 6, 2020

First impressions with the library: This is awesome!

                              Histogram
              ┌                                        ┐
   [3.1, 3.2) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 23
   [3.2, 3.3) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 14
   [3.3, 3.4) ┤▇▇▇▇▇▇▇▇ 5
   [3.4, 3.5) ┤▇▇▇▇▇ 3
   [3.5, 3.6) ┤▇▇ 1
   [3.6, 3.7) ┤▇▇▇▇▇▇▇▇ 5
   [3.7, 3.8) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇ 8
   [3.8, 3.9) ┤▇▇▇ 2
              └                                        ┘
                              Frequency=> nil

@mrkn mrkn added the bug Something isn't working label Jan 8, 2020
@mrkn mrkn closed this as completed in 1edf538 Jan 9, 2020
mrkn added a commit that referenced this issue Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants