lib/rails_erd/diagram/graphviz.rb in rails-erd-1.5.2 vs lib/rails_erd/diagram/graphviz.rb in rails-erd-1.6.0
- old
+ new
@@ -84,10 +84,15 @@
penwidth: 1.0,
labelangle: 32,
labeldistance: 1.8,
}
+ # Default cluster attributes.
+ CLUSTER_ATTRIBUTES = {
+ margin: "10,10"
+ }
+
module Simple
def entity_style(entity, attributes)
{}.tap do |options|
options[:fontcolor] = options[:color] = :grey60 if entity.virtual?
end
@@ -214,12 +219,14 @@
end
each_entity do |entity, attributes|
if options[:cluster] && entity.namespace
cluster_name = "cluster_#{entity.namespace}"
+ cluster_options = CLUSTER_ATTRIBUTES.merge(label: entity.namespace)
cluster = graph.get_graph(cluster_name) ||
- graph.add_graph(cluster_name, label: entity.namespace)
+ graph.add_graph(cluster_name, cluster_options)
+
draw_cluster_node cluster, entity.name, entity_options(entity, attributes)
else
draw_node entity.name, entity_options(entity, attributes)
end
end
@@ -301,10 +308,15 @@
def specialization_options(specialization)
specialization_style(specialization)
end
def read_template(type)
- ERB.new(File.read(File.expand_path("templates/#{NODE_LABEL_TEMPLATES[type]}", File.dirname(__FILE__))), nil, "<>")
+ template_text = File.read(File.expand_path("templates/#{NODE_LABEL_TEMPLATES[type]}", File.dirname(__FILE__)))
+ if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
+ ERB.new(template_text, trim_mode: "<>")
+ else
+ ERB.new(template_text, nil, "<>")
+ end
end
end
end
end