Class: Wicket::SVGPath

Inherits:
Object
  • Object
show all
Defined in:
lib/wicket/svg_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, opts = {}) ⇒ SVGPath



4
5
6
7
8
9
# File 'lib/wicket/svg_path.rb', line 4

def initialize(text,opts={})
  @text = text
  @opts = Wicket.configuration.merge(opts)
  @subpaths = []
  parse
end

Instance Attribute Details

#subpathsObject (readonly)

Returns the value of attribute subpaths.



3
4
5
# File 'lib/wicket/svg_path.rb', line 3

def subpaths
  @subpaths
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/wicket/svg_path.rb', line 3

def text
  @text
end

Instance Method Details

#to_multipolygon(opts = {}) ⇒ Object



16
17
18
19
# File 'lib/wicket/svg_path.rb', line 16

def to_multipolygon(opts={})
  polys = @subpaths.map{|s| s.to_polygon(opts) }.join(",")
  "MULTIPOLYGON(#{polys})"
end

#to_polygon(opts = {}) ⇒ Object



11
12
13
14
# File 'lib/wicket/svg_path.rb', line 11

def to_polygon(opts={})
  poly = @subpaths.first.to_polygon(opts)
  "POLYGON#{poly}"
end

#to_svg(opts = {}, style = "fill:none;stroke:lawngreen") ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/wicket/svg_path.rb', line 21

def to_svg(opts={},style="fill:none;stroke:lawngreen")
  o = @opts.merge(opts)
  paths = @subpaths.map{|s| s.to_svg(o) }.join(" ")
  <<-SVG
    <svg>
      <path d="#{@text}" style="fill: slateblue; opacity:0.2"/>
      <path d="#{paths}" style="#{style}" stroke-weight="2"/>
    </svg>
  SVG
end