Class: Bioroebe::SVG::SVGEE

Inherits:
Object
  • Object
show all
Defined in:
lib/bioroebe/svg/svgee.rb

Overview

Bioroebe::SVG::SVGEE

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ SVGEE

#

initialize

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

Arguments to this method:

:width = the width of the SVG page (100%)
:height = the amount of the page height the svg should take up (100%)
:style = the svg style information
#


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bioroebe/svg/svgee.rb', line 31

def initialize(args = {})
  reset
  opts = {
    width:  '100%',
    height: '100%'
  }
  if args
    opts.merge!(args) unless args.empty?
  end
  reset
  # ======================================================================= #
  # === @width
  # ======================================================================= #
  @width      = opts[:width]
  # ======================================================================= #
  # === @height
  # ======================================================================= #
  @height     = opts[:height]
  # ======================================================================= #
  # === @style
  # ======================================================================= #
  @style      = opts[:style] if opts.has_key? :style
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(primitive, args = {}) ⇒ Object (private)

#

method_missing

Only used to dynamically select the primitive type.

#

Raises:

  • (NoMethodError)


242
243
244
245
# File 'lib/bioroebe/svg/svgee.rb', line 242

def method_missing(primitive, args={}) 
  raise NoMethodError if not self.supported_primitives.include?(primitive) #we're only doing the listed primitive types...
  self.send('make_tag', primitive, args) 
end

Instance Method Details

#add_primitive(primitive_object) ⇒ Object

#

add_primitive

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

#


255
256
257
258
259
260
261
262
# File 'lib/bioroebe/svg/svgee.rb', line 255

def add_primitive(primitive_object)
  args = {}
  primitive_object.instance_variables.each {|variable|
    args[variable.to_s.gsub(/@/,'').to_sym] = primitive_object.instance_variable_get(variable)
  }
  primitive_string = args.delete(:primitive)
  make_tag(primitive_string, args)
end

#close_tagObject

#

close_tag

Produces the closing text for an svg file.

#


135
136
137
# File 'lib/bioroebe/svg/svgee.rb', line 135

def close_tag
  '</svg>'
end

#defs?Boolean Also known as: defs

#

defs?

#

Returns:

  • (Boolean)


115
116
117
# File 'lib/bioroebe/svg/svgee.rb', line 115

def defs?
  @defs
end

#drawObject

#

draw (draw tag)

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

#


292
293
294
295
296
297
298
299
# File 'lib/bioroebe/svg/svgee.rb', line 292

def draw
  head = self.open_tag
  defstring = ''.dup
  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) ⇒ Object

#

gradient

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)

#


273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/bioroebe/svg/svgee.rb', line 273

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 { |s|
    definition_string = definition_string+"\n"+
    %Q{<stop offset="#{s[:offset]}%" style="stop-color:#{s[:color]};stop-opacity:#{s[:opacity]}" />}
  }
  add_def definition_string + (a[:type] == :linear ? '</linearGradient>' : '</radialGradient>')
end

#open_tagObject

#

open_tag

Produces the opening text for an svg file.

#


124
125
126
127
128
# File 'lib/bioroebe/svg/svgee.rb', line 124

def open_tag
  %Q{
    <svg xmlns="https://www.w3.org/2000/svg" version="1.1" width="#{@width}" height="#{@height}" style="#{@style}" xmlns:xlink="http://www.w3.org/1999/xlink">
  }
end

#primitives?Boolean Also known as: primitives

#

primitives?

#

Returns:

  • (Boolean)


94
95
96
# File 'lib/bioroebe/svg/svgee.rb', line 94

def primitives?
  @primitives
end

#resetObject

#

reset (reset tag)

#


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
# File 'lib/bioroebe/svg/svgee.rb', line 58

def reset
  # ======================================================================= #
  # === @style
  # ======================================================================= #
  @style = nil
  # ======================================================================= #
  # === @primitives
  # ======================================================================= #
  @primitives = []
  # ======================================================================= #
  # === @defs
  # ======================================================================= #
  @defs       = []
  # ======================================================================= #
  # === @supported_primitives
  # ======================================================================= #
  @supported_primitives = [
    :circle,
    :rectangle,
    :ellipse,
    :line,
    :polyline,
    :text
  ]
end

#supported_primitives?Boolean Also known as: supported_primitives

#

supported_primitives?

#

Returns:

  • (Boolean)


87
88
89
# File 'lib/bioroebe/svg/svgee.rb', line 87

def supported_primitives?
  @supported_primitives
end

#update_height(i) ⇒ Object

#

update_height

#


101
102
103
# File 'lib/bioroebe/svg/svgee.rb', line 101

def update_height(i)
  @height = i
end

#update_width(i) ⇒ Object

#

update_width

#


108
109
110
# File 'lib/bioroebe/svg/svgee.rb', line 108

def update_width(i)
  @width = i
end