lib/rails_erd/diagram/graphviz.rb in rails-erd-1.4.7 vs lib/rails_erd/diagram/graphviz.rb in rails-erd-1.5.0
- old
+ new
@@ -208,11 +208,18 @@
"and in your path, or use filetype=dot."
end
end
each_entity do |entity, attributes|
- draw_node entity.name, entity_options(entity, attributes)
+ if options[:cluster] && entity.namespace
+ cluster_name = "cluster_#{entity.namespace}"
+ cluster = graph.get_graph(cluster_name) ||
+ graph.add_graph(cluster_name, label: entity.namespace)
+ draw_cluster_node cluster, entity.name, entity_options(entity, attributes)
+ else
+ draw_node entity.name, entity_options(entity, attributes)
+ end
end
each_specialization do |specialization|
from, to = specialization.generalized, specialization.specialized
draw_edge from.name, to.name, specialization_options(specialization)
@@ -231,18 +238,22 @@
end
private
def node_exists?(name)
- !!graph.get_node(escape_name(name))
+ !!graph.search_node(escape_name(name))
end
def draw_node(name, options)
graph.add_nodes escape_name(name), options
end
+ def draw_cluster_node(cluster, name, options)
+ cluster.add_nodes escape_name(name), options
+ end
+
def draw_edge(from, to, options)
- graph.add_edges graph.get_node(escape_name(from)), graph.get_node(escape_name(to)), options if node_exists?(from) and node_exists?(to)
+ graph.add_edges graph.search_node(escape_name(from)), graph.search_node(escape_name(to)), options if node_exists?(from) and node_exists?(to)
end
def escape_name(name)
"m_#{name}"
end