topfunky / gruff

Gruff graphing library for Ruby
http://gruff.rubyforge.org
MIT License
1.37k stars 239 forks source link

Fix error when input empty data in Gruff::Histogram #592

Closed Watson1978 closed 2 years ago

Watson1978 commented 2 years ago

This patch will fix following exception.

/home/watson/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/histogram-0.2.4.1/lib/histogram.rb:106:in `number_of_bins': undefined method `-' for nil:NilClass (NoMethodError)

          range = (self.max - self.min).to_f
                            ^
        from /home/watson/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/histogram-0.2.4.1/lib/histogram.rb:225:in `histogram'
        from /home/watson/prj/gruff/lib/gruff/histogram.rb:47:in `block in setup_data'
        from /home/watson/prj/gruff/lib/gruff/histogram.rb:46:in `each'
        from /home/watson/prj/gruff/lib/gruff/histogram.rb:46:in `setup_data'
        from /home/watson/prj/gruff/lib/gruff/base.rb:517:in `draw'
        from /home/watson/prj/gruff/lib/gruff/base.rb:497:in `to_image'
        from /home/watson/prj/gruff/lib/gruff/base.rb:479:in `write'
        from histogram.rb:8:in `<main>'