In the current implementation the user will use the methods set_vertex_options and set_edge_options location in dot.rb to set the options for the respective element of the graph. For this to work properly the user needs to initialize two procs and two hashes with all the options they want to use.
require 'rgl/adjacency'
require 'rgl/dot'
graph = RGL::DirectedAdjacencyGraph['a', 'b', 'b', 'c']
graph.add_edge('a', 'b')
graph.add_edge('a', 'c')
# Vertex Settings
graph.set_vertex_options('a', label: 'This is A', shape: 'box3d', fontcolor: 'green', fontsize: 16)
graph.set_vertex_options('b', label: 'This is B', shape: 'tab', fontcolor: 'red', fontsize: 14)
graph.set_vertex_options('c', shape: 'tab', fontcolor: 'blue')
# Edge Settings
graph.set_edge_options('a', 'b', label: 'NotCapitalEdge', style: 'dotted', direction: 'back', color: 'yellow')
graph.set_edge_options('a', 'c', weight: 5, color: 'blue')
# puts @vertex_options
# puts @edge_options
get_vertex_setting = proc { |v| graph.vertex_options[v] }
get_edge_setting = proc { |b, e| graph.edge_options[graph.edge_class.new(b, e)] }
# To configure more options, add the respective keys and the proc call here
# Then provide the respective key:value to set_vertex_options
# Any hard coded values for a key will be applied to all nodes
vertex_options = {
'label' => get_vertex_setting,
'shape' => get_vertex_setting,
'fontcolor' => get_vertex_setting,
'fontsize' => get_vertex_setting
}
# To configure more options, add the respective keys and the proc call here
# Then provide the respective key:value to set_edge_options
# Any hard coded values for a key will be applied to all edges
edge_options = {
'label' => get_edge_setting,
'dir' => get_edge_setting,
'color' => get_edge_setting,
'style' => get_edge_setting,
'weight' => get_edge_setting,
'constraint' => get_edge_setting,
'headlabel' => get_edge_setting,
'taillabel' => get_edge_setting
}
# Options
dot_options = { 'edge' => edge_options, 'vertex' => vertex_options }
graph.write_to_graphic_file('png', 'graph', dot_options)
We should move vertex_options and edge_options and the respective procs somewhere into the initialize phase for the graph so they get populated with all valid options automatically and the user does not have to concern themselves with it and just pass the respective option combination to the methods. I have not yet found the right place in the classes where this would apply to all graph types and can be used properly.
In the current implementation the user will use the methods
set_vertex_options
andset_edge_options
location indot.rb
to set the options for the respective element of the graph. For this to work properly the user needs to initialize two procs and two hashes with all the options they want to use.We should move
vertex_options
andedge_options
and the respective procs somewhere into the initialize phase for the graph so they get populated with all valid options automatically and the user does not have to concern themselves with it and just pass the respective option combination to the methods. I have not yet found the right place in the classes where this would apply to all graph types and can be used properly.https://github.com/monora/rgl/pull/89#issuecomment-1483091675 https://github.com/monora/rgl/pull/89#issuecomment-1483295214