lib/rubyvis/mark/wedge.rb in rubyvis-0.2.0 vs lib/rubyvis/mark/wedge.rb in rubyvis-0.2.1

- old
+ new

@@ -6,11 +6,13 @@ class Wedge < Mark def type "wedge" end @properties=Mark.properties.dup + attr_accessor_dsl :start_angle, :end_angle, :angle, :inner_radius, :outer_radius, :line_width, [:stroke_style, lambda {|d| Rubyvis.color(d)}], [:fill_style, lambda {|d| Rubyvis.color(d)}] + 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 def mid_radius @@ -19,11 +21,12 @@ def mid_angle (start_angle+end_angle) / 2.0 end def anchor(name) - partial=lambda {|s| s.inner_radius!=0 ? true : s.angle<2*Math.PI} + that=self + 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]; @@ -64,25 +67,25 @@ }).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' + return that.upright(mid_angle.call(s)) ? 'right':'left' when 'inner' - return self.upright(mid_angle.call(s)) ? 'left':'right' + return that.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' + return that.upright(s.start_angle) ? 'top':'bottom' when 'end' - return self.upright(s.end_angle) ? 'bottom':'top' + return that.upright(s.end_angle) ? 'bottom':'top' end end return 'middle' }).text_angle(lambda { @@ -100,27 +103,29 @@ a=s.start_angle when 'end' a=s.end_angle end end - self.upright(a) ? a: (a+Math::PI) + that.upright(a) ? a: (a+Math::PI) }) end - def self.upright(angle) + def 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 def build_implied(s) - if (s.angle.nil?) - s.angle= s.end_angle-s.start_angle + + 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 + s.end_angle = s.start_angle + s.angle end + mark_build_implied(s) end end end