Skip to content

Allow edge + vertex options to be passed to #write_to_graphic_file - #41

Merged
monora merged 4 commits into
monora:masterfrom
lskalkos:add-options-to-write-to-graphic-file
Feb 6, 2019
Merged

Allow edge + vertex options to be passed to #write_to_graphic_file#41
monora merged 4 commits into
monora:masterfrom
lskalkos:add-options-to-write-to-graphic-file

Conversation

@lskalkos

@lskalkos lskalkos commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

I was using this library, and I thought it would be nice to be able to pass additional edge and vertex options into the write_to_graphic_file method -- for instance, to add a label for each edge.

The idea is that the original default options get passed in, as well as any additional ones under params['edge'] or params['vertex']. If the setting comes in the form of a Proc, then the proc is called on each edge pair or vertex. Otherwise, the setting will apply to all edges and all vertices.

Happy to add tests, or do some additional work to get this in.

Example:

graph = RGL::DirectedAdjacencyGraph["a", "b", "b", "c"]

# Edge Settings
edge_labels = {}
graph.each_edge do |b, e|
  key              = "#{b}-#{e}"
  edge_labels[key] = "#{b} to #{e}"
end
edge_label_setting = Proc.new{|b, e| edge_labels["#{b}-#{e}"]}
edge_colors = {"a-b" => "red", "b-c" => "purple"}
edge_color_setting = Proc.new{|b, e| edge_colors["#{b}-#{e}"]}
edge_settings  = {'color' => edge_color_setting, 'label' => edge_label_setting, 'fontsize' => 15}

# Vertex Settings
vertex_font_colors = {"a" => "blue", "b" => "green", "c" => "purple"}
vertex_font_color_setting = Proc.new{|b| vertex_font_colors[b]}
vertex_settings = {'fontcolor' => vertex_font_color_setting, 'fontsize' => 10}

# Options
dot_options = {'edge' => edge_settings, 'vertex' => vertex_settings}

graph.write_to_graphic_file('png', 'graph', dot_options)

graph

@monora

monora commented Jan 9, 2019

Copy link
Copy Markdown
Owner

Looks good to me. Could you provide an example graph image which we could include in the README to show this feature?

I fixed the travis errors. Could you git rebase on master, then the checks should pass.

@monora monora added the dot label Jan 9, 2019
@lskalkos
lskalkos force-pushed the add-options-to-write-to-graphic-file branch from a2019b4 to ec346a9 Compare January 16, 2019 13:40
@lskalkos
lskalkos force-pushed the add-options-to-write-to-graphic-file branch from ec346a9 to 2081d8d Compare January 16, 2019 13:54
@lskalkos

lskalkos commented Feb 1, 2019

Copy link
Copy Markdown
Contributor Author

Hi there, I made a fix to the vertex settings, updated the test, and added an example to the PR description. Take a look and let me know if there is anything else that needs to be done on this. Thanks!

@monora

monora commented Feb 5, 2019

Copy link
Copy Markdown
Owner

Thank you, that is fine. I will mention the feature in the README.md and link to the test, which shows its usage. I will then merge the PR and make a new release.

monora added a commit that referenced this pull request Feb 6, 2019
@monora
monora merged commit c88bf80 into monora:master Feb 6, 2019
@r0ckarong r0ckarong mentioned this pull request Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants