Bugs: Browse | Submit New | Admin

[#5896] stacked graphs fail with even number of stacks

Date:
2006-09-25 17:38
Priority:
3
Submitted By:
Aslak Hellesøy (aslak_hellesoy)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
stacked graphs fail with even number of stacks

Detailed description
The following script fails with

/usr/local/lib/ruby/gems/1.8/gems/scruffy-0.2.2/lib/scruffy/layers/stacked.rb:71:in `points': undefined method `size'
for nil:NilClass (NoMethodError)
        from /usr/local/lib/ruby/gems/1.8/gems/scruffy-0.2.2/lib/scruffy/layers/stacked.rb:63:in `top_value'
        from /usr/local/lib/ruby/gems/1.8/gems/scruffy-0.2.2/lib/scruffy/helpers/layer_container.rb:64:in `top_value'
        from /usr/local/lib/ruby/gems/1.8/gems/scruffy-0.2.2/lib/scruffy/helpers/layer_container.rb:41:in `inject'
        from /usr/local/lib/ruby/gems/1.8/gems/scruffy-0.2.2/lib/scruffy/helpers/layer_container.rb:64:in `top_value'
        from /usr/local/lib/ruby/gems/1.8/gems/scruffy-0.2.2/lib/scruffy/helpers/layer_container.rb:74:in
`bottom_value'
        from /usr/local/lib/ruby/gems/1.8/gems/scruffy-0.2.2/lib/scruffy/graph.rb:137:in `render'
        from scruffy_stack.rb:14

Commenting out bars so it's an odd number makes it pass.

I haven't looked into what causes this, but it would be great to have it fixed.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-09-30 22:36
Sender: Kacper Cieśla

I faced this problem too with version 0.2.2

It would be great if you could fix that.


PS. Great script and great work, congratulations.
Date: 2007-01-17 13:26
Sender: Eric Soderberg

This is caused due to how inject is being used
in Scruffy::Layers::Stacked.points(). Here's the relevant code:

longest_arr = layers.inject(nil) do |longest, layer|
  longest = layer.points if (longest.nil? || longest.size <
layer.points.size)
end

On the first pass, longest is nil and gets assigned. If on the
second pass, layer.points.size >= longest.size, longest will
not be set and the block will return nil, re-setting longest
to nil. So, two layers, each with the same size, will result
in longest_arr being nil.

I've fixed this in my version via:

longest_arr = layers.inject(nil) do |longest, layer|
  longest = layer.points if (longest.nil? || longest.size <
layer.points.size)
  longest
end

Attached Files:

Name Description Download
scruffy_stack.rb Download

Changes:

Field Old Value Date By
File Added827: scruffy_stack.rb2006-09-25 17:45aslak_hellesoy