Class: GraphMatching::Visualize

Inherits:
Object
  • Object
show all
Defined in:
lib/graph_matching/visualize.rb

Overview

Renders ‘GraphMatching::Graph` objects using `graphviz`.

Constant Summary collapse

TMP_DIR =
'/tmp/graph_matching'
USR_BIN_ENV =
'/usr/bin/env'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph) ⇒ Visualize

Returns a new instance of Visualize.



14
15
16
# File 'lib/graph_matching/visualize.rb', line 14

def initialize(graph)
  @graph = graph
end

Instance Attribute Details

#graphObject (readonly)

Returns the value of attribute graph.



12
13
14
# File 'lib/graph_matching/visualize.rb', line 12

def graph
  @graph
end

Instance Method Details

#dotObject

‘dot` returns a string representing the graph, in .dot format. www.graphviz.org/content/dot-language



20
21
22
# File 'lib/graph_matching/visualize.rb', line 20

def dot
  RGL::DOT::Graph.new('elements' => dot_edges).to_s
end

#png(base_filename) ⇒ Object

‘png` writes a “.png” file with graphviz and opens it



25
26
27
28
29
30
31
# File 'lib/graph_matching/visualize.rb', line 25

def png(base_filename)
  check_that_dot_is_installed
  mk_tmp_dir
  abs_path = "#{TMP_DIR}/#{base_filename}.png"
  write_png(abs_path)
  system "open #{abs_path}"
end