Class: Mappum::MapServer::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/mappum/mapserver/mapgraph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ Graph

Returns a new instance of Graph.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mappum/mapserver/mapgraph.rb', line 5

def initialize(map)
  @map = map
  @root = []
  @struct_from = StrTree.new(nil,0,@root)
  @struct_from.name = "struct1"
  @struct_to = StrTree.new(nil,0,@root)
  @struct_to.name = "struct2"
  @edges = []
  @edge_maps = {}
  init(@map,@struct_from, @struct_to)
end

Instance Attribute Details

#edge_mapsObject (readonly)

Returns the value of attribute edge_maps.



4
5
6
# File 'lib/mappum/mapserver/mapgraph.rb', line 4

def edge_maps
  @edge_maps
end

Instance Method Details

#getDotObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mappum/mapserver/mapgraph.rb', line 36

def getDot
  str1 = makeStruct(@struct_from)
  str2 = makeStruct(@struct_to)
  edge = @edges.join
  return "digraph structs { node [shape=plaintext]; rankdir=LR;  nodesep=0.1;    \n struct1 [\n   label=<\n    \#{str1}\n  >\n  ]; \n struct2 [\n   label=<\n    \#{str2}\n   >\n  ];\n  \#{@root.collect { |struct| struct.line}}\n  \#{edge}\n  \n  }              \n"
end

#getPngObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/mappum/mapserver/mapgraph.rb', line 26

def getPng
  cmd = "dot"
  format = "png"
  xCmd = "#{cmd} -T#{format}"
  dot = getDot
  f = IO.popen( xCmd ,"r+")
  f.print(dot)
  f.close_write
  return f
end

#getSvgObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/mappum/mapserver/mapgraph.rb', line 16

def getSvg
  cmd = "dot"
  format = "svg"
  xCmd = "#{cmd} -T#{format}"
  puts dot = getDot
  f = IO.popen( xCmd ,"r+")
  f.print(dot)
  f.close_write
  return f
end