Sha256: 5291a0d4dfcec38f00a30819ab4cbdd551323fdb297aeabaf51d327b5e9cda09

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 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 'rigth'
        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.to_s + "," + s.top.to_s + ")" + (s.text_angle ? " rotate(" + (180 * s.text_angle / Math::PI).to_s + ")" : "") + (self.scale != 1 ? " scale(" + 1 / self.scale + ")" : ""),
        "fill"=> fill.color,
        "fill-opacity"=> fill.opacity || nil,
        "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

1 entries across 1 versions & 1 rubygems

Version Path
rubyvis-0.1.0 lib/rubyvis/scene/svg_label.rb