Sha256: 1cd76b6a802d84e640a6f3d184d875ea3d68e5d9a280c9bf0ad5e4e216a484ea

Contents?: true

Size: 1.63 KB

Versions: 11

Compression:

Stored size: 1.63 KB

Contents

# = Crimeam War deaths (Grouped bar)
# Florence Nightingale used a coxcomb diagram to emphasize the number of deaths due to “preventible or mitigable zymotic diseases”. This graph shows data using a stacked bar chart.
$:.unshift(File.dirname(__FILE__)+"/../../../lib")
require 'rubyvis'
require 'ostruct'
load(File.dirname(__FILE__)+"/crimea_data.rb")


w = 545
h = 280
#x = pv.Scale.linear($crimea, lambda {|d| d.date}).range(0, w)

x=pv.Scale.ordinal($crimea, lambda {|d| d.date}).split_banded(0,w,4/5.0)

y = pv.Scale.linear(0, 1500).range(0, h)
k=x.range_band / $causes.size
fill = pv.colors("lightpink", "darkgray", "lightblue")

format = pv.Format.date("%b")



vis = pv.Panel.new()
    .width(w)
    .height(h)
    .margin(19.5)
    .right(40);
    
panel = vis.add(pv.Panel)
    .data($crimea)
    .left(lambda {|d| x.scale(d.date)})
    .width(x.range_band);
    
panel.add(pv.Bar)
    .data($causes)
    .bottom(0)
    .width(k)
    .left(lambda { self.index * k})
    .height(lambda {|t, d| y.scale(d.send(t))})
    .fill_style(lambda {|f| a=fill.scale(self.index); return a})
    .stroke_style(lambda {|d| fill_style ? fill_style.darker : pv.color('black')})
    .line_width(1);

panel.anchor("bottom").add(pv.Label)
.visible(lambda { (self.index % 3)==0})
.text_baseline("top")
    .text_margin(10)
    .text(lambda {|d| format.format(d.date)})
    
  
vis.add(pv.Rule)
    .data(y.ticks())
    .bottom(lambda {|d| y.scale(d)})
    .stroke_style(lambda {|i|  i!=0 ? pv.color("rgba(255, 255, 255, .5)") : pv.color("black")})
  .anchor("right").add(pv.Label)
  .visible(lambda { (self.index & 1)==0})
    .text_margin(6);

vis.render();

puts vis.to_svg

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rubyvis-0.7.0 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.6.1 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.6.0 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.5.2 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.5.1 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.5.0 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.4.1 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.4.0 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.3.6 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.3.5 examples/4_pv_custom/crimea/crimea_grouped_bar.rb
rubyvis-0.3.4 examples/4_pv_custom/crimea/crimea_grouped_bar.rb