Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add named edges? #31

Closed
jergason opened this issue Dec 8, 2011 · 1 comment
Closed

How can I add named edges? #31

jergason opened this issue Dec 8, 2011 · 1 comment
Assignees
Labels

Comments

@jergason
Copy link
Contributor

jergason commented Dec 8, 2011

I want to add a to an edge, so the string will appear next to the edge, but the documentation does not explain how to do this. The code shows that you can pass in a hash of edge attributes, but I am not sure of how to name those attributes.

@glejeune
Copy link
Owner

glejeune commented Dec 8, 2011

You just need to use the attribute label (for more informations about attributs, see http://www.graphviz.org/content/attrs)

Here is differents examples on how to do this :

Solution #1 - With the "object" API

require 'graphviz'

g = GraphViz.new(:G)

nodeA = g.add_node("nodeA")
nodeB = g.add_node("nodeB")

edge = g.add_edge(nodeA, nodeB)

edge[:label] = "edge label"

Solution #2 - With a block

require 'graphviz'

GraphViz.new(:G) { |g|
   edge = g.nodeA << g.nodeB
   edge[:label => "edge label"]
}

Solution #3 - With a block (short)

require 'graphviz'

GraphViz.new(:G) { |g|
   (g.nodeA << g.nodeB)[:label => "edge label"]
}

Solution #4 - With the DSL

require 'graphviz/dsl'

digraph :G do
   nA = n("nodeA")
   nB = n("nodeB")
   edge = e(nA, nB)
   edge[:label => "edge label"]
end

Solution #5 - With the DSL (short)

require 'graphviz/dsl'

digraph :G do
   (nodeA << nodeB)[:label => "edge label"]
end

Greg

@ghost ghost assigned glejeune Dec 8, 2011
@glejeune glejeune closed this as completed Dec 8, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants