Class: Rubyvis::Wedge
- Inherits:
-
Mark
show all
- Defined in:
- lib/rubyvis/mark/wedge.rb
Instance Attribute Summary
Attributes inherited from Mark
#_properties, #binds, #child_index, #parent, #proto, #root, #scale, #scene, #target
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Mark
#add, attr_accessor_dsl, #bind, #build, #build_instance, #build_properties, #context, #context_apply, #context_clear, #cousin, #delete_index, #event, #extend, index, #index, index=, #index=, #index_defined?, #initialize, #instance, #instances, #margin, #mark_anchor, #mark_bind, #mark_build_implied, #mark_build_instance, #properties, properties, property_method, #property_value, #render, scene, scene=, #sibling, stack, stack=
Constructor Details
This class inherits a constructor from Rubyvis::Mark
Class Method Details
12
13
14
15
|
# File 'lib/rubyvis/mark/wedge.rb', line 12
def self.defaults
a=Rubyvis.Colors.category20()
Wedge.new.extend(Mark.defaults).start_angle(lambda {s=self.sibling; s ? s.end_angle: -Math::PI.quo(2) } ).inner_radius( 0 ).line_width( 1.5 ).stroke_style( nil ).fill_style( lambda {a.scale(self.index)})
end
|
.upright(angle) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/rubyvis/mark/wedge.rb', line 111
def self.upright(angle)
angle=angle % (2*Math::PI)
angle=(angle<0) ? (2*Math::PI+angle) : angle
(angle < Math::PI/2.0) or (angle>=3*Math::PI / 2.0)
end
|
Instance Method Details
#anchor(name) ⇒ Object
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/rubyvis/mark/wedge.rb', line 23
def anchor(name)
partial=lambda {|s| s.inner_radius!=0 ? true : s.angle<2*Math.PI}
mid_radius=lambda {|s| (s.inner_radius+s.outer_radius) / 2.0}
mid_angle=lambda {|s| (s.start_angle+s.end_angle) / 2.0 }
mark_anchor(name).left(lambda {
s = self.scene.target[self.index];
if (partial.call(s))
case (self.name())
when "outer"
return s.left + s.outer_radius * Math.cos(mid_angle.call(s))
when "inner"
return s.left + s.inner_radius * Math.cos(mid_angle.call(s))
when "start"
return s.left + mid_radius.call(s) * Math.cos(s.start_angle)
when "center"
return s.left + mid_radius.call(s) * Math.cos(mid_angle.call(s))
when "end"
return s.left + mid_radius.call(s) * Math.cos(s.end_angle)
end
end
return s.left;
}).top(lambda {
s = self.scene.target[self.index];
if (partial.call(s))
case (self.name())
when "outer"
return s.top + s.outer_radius * Math.sin(mid_angle.call(s))
when "inner"
return s.top + s.inner_radius * Math.sin(mid_angle.call(s))
when "start"
return s.top + mid_radius.call(s) * Math.sin(s.start_angle)
when "center"
return s.top + mid_radius.call(s) * Math.sin(mid_angle.call(s))
when "end"
return s.top + mid_radius.call(s) * Math.sin(s.end_angle)
end
end
return s.top;
}).text_align(lambda {
s = self.scene.target[self.index];
if (partial.call(s))
case (self.name())
when 'outer'
return self.upright(mid_angle.call(s)) ? 'right':'left'
when 'inner'
return self.upright(mid_angle.call(s)) ? 'left':'right'
end
end
return 'center'
}).text_baseline(lambda {
s = self.scene.target[self.index];
if (partial.call(s))
case (self.name())
when 'start'
return self.upright(s.start_angle) ? 'top':'bottom'
when 'end'
return self.upright(s.end_angle) ? 'bottom':'top'
end
end
return 'middle'
}).text_angle(lambda {
s = self.scene.target[self.index];
a=0
if (partial.call(s))
case (self.name())
when 'center'
a=mid_angle.call(s)
when 'inner'
a=mid_angle.call(s)
when 'outer'
a=mid_angle.call(s)
when 'start'
a=s.start_angle
when 'end'
a=s.end_angle
end
end
self.upright(a) ? a: (a+Math::PI)
})
end
|
#build_implied(s) ⇒ Object
117
118
119
120
121
122
123
124
|
# File 'lib/rubyvis/mark/wedge.rb', line 117
def build_implied(s)
if (s.angle.nil?)
s.angle= s.end_angle-s.start_angle
elsif s.end_angle.nil?
s.end_angle=s.start_angle+s.angle
end
mark_build_implied(s)
end
|
#mid_angle ⇒ Object
19
20
21
|
# File 'lib/rubyvis/mark/wedge.rb', line 19
def mid_angle
(start_angle+end_angle) / 2.0
end
|
#mid_radius ⇒ Object
16
17
18
|
# File 'lib/rubyvis/mark/wedge.rb', line 16
def mid_radius
(inner_radius+outer_radius) / 2.0
end
|
7
8
9
|
# File 'lib/rubyvis/mark/wedge.rb', line 7
def type
"wedge"
end
|