Module: Lutaml::Formatter::Graphviz::RelationshipFormatter

Included in:
Lutaml::Formatter::Graphviz
Defined in:
lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb

Constant Summary collapse

ARROW_TYPES =
{
  'composition' => 'diamond',
  'aggregation' => 'odiamond',
  'direct' => 'vee'
}.freeze
DASHED_TYPES =
%w[dependency realizes].freeze
DIRECTION_LABELS =
{
  'target' => '%s ▶',
  'source' => '◀ %s'
}.freeze

Instance Method Summary collapse

Instance Method Details

#build_edge_attributes(node) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb', line 29

def build_edge_attributes(node)
  attrs = Attributes.new

  apply_edge_style(attrs, node)
  apply_edge_direction(attrs, node)
  apply_edge_labels(attrs, node)
  apply_arrow_types(attrs, node)
  maybe_swap_labels(attrs)

  attrs
end

#format_label(name, cardinality = nil) ⇒ Object



41
42
43
44
45
46
# File 'lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb', line 41

def format_label(name, cardinality = nil)
  res = "+#{name}"
  return res if cardinality.nil? || cardinality.min.nil? || cardinality.max.nil?

  "#{res} #{cardinality.min}..#{cardinality.max}"
end

#format_relationship(node) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/lutaml/lml/formatter/graphviz/relationship_formatter.rb', line 20

def format_relationship(node)
  graph_parent_name = generate_graph_name(node.owner_end)
  graph_node_name = generate_graph_name(node.member_end)
  attributes = build_edge_attributes(node)
  graph_attributes = " [#{attributes}]" unless attributes.empty?

  "#{graph_parent_name} -> #{graph_node_name}#{graph_attributes}"
end