File: wedge_spec.rb

package info (click to toggle)
ruby-rubyvis 0.6.1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,812 kB
  • sloc: ruby: 11,114; javascript: 25; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,889 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
describe Rubyvis::Wedge do
  include Rubyvis::GeneralSpec
  it "should have correct properties" do
    props=[:angle, :antialias, :bottom, :cursor, :data, :end_angle, :events, :fill_style,  :id, :inner_radius, :left, :line_width, :outer_radius, :reverse, :right, :start_angle, :stroke_style, :title, :top, :visible].inject({}) {|ac, v| ac[v]=true; ac}
    Rubyvis::Wedge.properties.should==props
  end
  it "Rubyvis.Wedge be the same as Rubyvis::Wedge" do
    Rubyvis.Wedge.should eql Rubyvis::Wedge
  end
  it "should render equal to protovis 'wedge-anchor.html' test" do
    
    data = Rubyvis.range(5).map {|x| x}
    w = 400
    h = 400
    r = w / 2.0
    t = 30
    a = Rubyvis::Scale.linear(0, Rubyvis.sum(data)).range(0, 2 * Math::PI);

    vis = Rubyvis::Panel.new().
width(w).
height(h)

    anchors=["outer","inner","start","center","end"]
    
    vis.add(Rubyvis::Wedge).
data(data).
outer_radius(r).
angle(a).
anchor(lambda {anchors[self.index]}).add(pv.Label).
text(lambda {anchors[self.index]})

    vis.render();
    pv_out=fixture_svg_read("wedge_anchor.svg")
    vis.to_svg.should have_same_svg_elements(pv_out)
    
  end
  it "should render equal to protovis 'wedge-donut.html' test" do
    data = Rubyvis.range(10).map {|x| (Math.sin(x)).abs}
    w = 400
    h = 400
    r = w / 2.0
    t = 30
    a = Rubyvis.Scale.linear(0, Rubyvis.sum(data)).range(0, 2 * Math::PI)
    
    @vis = Rubyvis::Panel.new().
width(w).
height(h)
    
    @vis.add(Rubyvis::Wedge).
data(data).
inner_radius(r - t).
outer_radius(r).
angle(a).
title(lambda {|d| d}).
anchor("outer").add(Rubyvis::Label).
visible(lambda {|d| d>0.05}).
text_margin(t + 5).
text(lambda {|d| "%0.2f" % d})
    @vis.render();

    @pv_out=fixture_svg_read("wedge_donut.svg")
    @vis.to_svg.should have_same_svg_elements(@pv_out)
  end  
  
end