Sha256: 7ca28973441dacf6840d4d070e190c5cce9c4c3820bfdaac38083e4c6c99ea48

Contents?: true

Size: 1.44 KB

Versions: 16

Compression:

Stored size: 1.44 KB

Contents

module Rubyvis
  module SvgScene
    def self.label(scenes)
      e=scenes._g.elements[1]
      scenes.each_with_index do |s,i|
        next unless s.visible
        fill=s.text_style
        next if(fill.opacity==0 or s.text.nil?)
        x=0
        y=0
        dy=0
        anchor='start'
        case s.text_baseline
          when 'middle'
            dy=".35em"
          when "top"
            dy = ".71em"
            y = s.text_margin
          when "bottom"
            y = "-" + s.text_margin.to_s
        end
        
        case s.text_align
          when 'right'
            anchor = "end"
            x = "-" + s.text_margin.to_s
          when "center"
            anchor = "middle"
          when "left"
            x = s.text_margin
        end
        e=SvgScene.expect(e,'text', {
          "pointer-events"=> s.events,
          "cursor"=> s.cursor,
          "x"=> x,
          "y"=> y,
          "dy"=> dy,
          "transform"=> "translate(#{s.left},#{s.top})" + (s.text_angle!=0 ? " rotate(" + (180 * s.text_angle / Math::PI).to_s + ")" : "") + (self.scale != 1 ? " scale(" + 1 / self.scale + ")" : ""),
          "fill"=> fill.color,
          "fill-opacity"=> fill.opacity==0 ? nil : fill.opacity,
          "text-anchor"=> anchor
        }, {
        "font"=> s.font, "text-shadow"=> s.text_shadow, "text-decoration"=> s.text_decoration      })
        e.text=s.text


        e=SvgScene.append(e,scenes,i)

      end
      e
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rubyvis-0.4.0 lib/rubyvis/scene/svg_label.rb
rubyvis-0.3.6 lib/rubyvis/scene/svg_label.rb
rubyvis-0.3.5 lib/rubyvis/scene/svg_label.rb
rubyvis-0.3.4 lib/rubyvis/scene/svg_label.rb
rubyvis-0.3.3 lib/rubyvis/scene/svg_label.rb
rubyvis-0.3.2 lib/rubyvis/scene/svg_label.rb
rubyvis-0.3.1 lib/rubyvis/scene/svg_label.rb
rubyvis-0.3.0 lib/rubyvis/scene/svg_label.rb
rubyvis-0.2.2 lib/rubyvis/scene/svg_label.rb
rubyvis-0.2.1 lib/rubyvis/scene/svg_label.rb
rubyvis-0.2.0 lib/rubyvis/scene/svg_label.rb
rubyvis-0.1.7 lib/rubyvis/scene/svg_label.rb
rubyvis-0.1.6 lib/rubyvis/scene/svg_label.rb
rubyvis-0.1.5 lib/rubyvis/scene/svg_label.rb
rubyvis-0.1.4 lib/rubyvis/scene/svg_label.rb
rubyvis-0.1.3 lib/rubyvis/scene/svg_label.rb