class Bio::Graphics::SVGEE

The SVGEE class is used to create the text that will go into the final SVG file. It takes information from the supplied Glyph objects, parses them and creates the SVG text necessary to display the given glyphs.

Attributes

defs[R]
primitives[R]
supported_primitives[R]

Public Instance Methods

add_primitive(primitive_object) click to toggle source

Adds a Primitive object to the SVGEE object and makes the svg text for that Primitive

# File lib/bio/graphics/svgee.rb, line 96
def add_primitive(primitive_object)
  args = {}
  primitive_object.instance_variables.each{|v| args[v.to_s.gsub(/@/,"").to_sym] = primitive_object.instance_variable_get(v)  }
  primitive_string = args.delete(:primitive)
  make_tag(primitive_string, args)
end
close_tag() click to toggle source

Produces the closing text for an svg file

# File lib/bio/graphics/svgee.rb, line 31
def close_tag
  %Q{</svg>}
end
draw() click to toggle source

Produces the svg text to display all the features on a Page

# File lib/bio/graphics/svgee.rb, line 117
def draw
  head = self.open_tag
  defstring = ""
  defstring = "<defs>\n" + self.defs.join("\n") + "\n </defs>\n" if not defs.empty?
  shapes = self.primitives.join("\n")
  close = self.close_tag
  head + defstring + shapes + close
end
gradient(a) click to toggle source

Takes the gradient information from a Glyph, which must be of type ‘radial’ or ‘linear’ and creates the svg text for that gradient

  • a = a gradient (a gradient type, a colour and the parameters for a given type)

# File lib/bio/graphics/svgee.rb, line 104
def gradient(a)
  definition_string = case a[:type]
  when :radial
    %Q{<radialGradient id="#{a[:id]}" cx="#{a[:cx]}%" cy="#{a[:cy]}%" r="#{a[:r]}%" fx="#{a[:fx]}%" fy="#{a[:fy]}%">}
  else
    %Q{<linearGradient id="#{a[:id]}" x1="#{a[:x1]}%" x2="#{a[:x2]}%" y1="#{a[:y1]}%" y2="#{a[:y2]}%">}
  end
  a[:stops].each do |s|
    definition_string = definition_string + "\n" + %Q{<stop offset="#{s[:offset]}%" style="stop-color:#{s[:color]};stop-opacity:#{s[:opacity]}" />}
  end
  add_def definition_string + (a[:type] == :linear ? '</linearGradient>' : '</radialGradient>')
end
open_tag() click to toggle source

Produces the opening text for an svg file

# File lib/bio/graphics/svgee.rb, line 27
def open_tag
  %Q{<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="#{@width}" height="#{@height}" style="#{@style}" xmlns:xlink="http://www.w3.org/1999/xlink">}
end

Public Class Methods

new(args) click to toggle source

Creates a new SVGEE object which will contain all the necessary objects to display all the features on a page

args

  • width = the amount of the page width the svg should take up (100%)

  • height = the amount of the page height the svg should take up (100%)

  • style = the svg style information

  • primitives = an array of glyphs

  • defs = the gradients that will be used in the SVG

  • supported_primitives = a list of permitted Glyphs

# File lib/bio/graphics/svgee.rb, line 17
def initialize(args)
  opts = {:width => '100%', :height => '100%'}.merge!(args)
  @width = opts[:width]
  @height = opts[:height]
  @style= opts[:style]
  @primitives = []
  @defs = []
  @supported_primitives = [:circle, :rectangle, :ellipse, :line, :polyline, :text]
end