Class: Lutaml::Xsd::Spa::Svg::Layouts::VerticalLayout

Inherits:
Lutaml::Xsd::Spa::Svg::LayoutEngine show all
Defined in:
lib/lutaml/xsd/spa/svg/layouts/vertical_layout.rb

Overview

Simple vertical layout - stacks components vertically

Instance Attribute Summary

Attributes inherited from Lutaml::Xsd::Spa::Svg::LayoutEngine

#config

Instance Method Summary collapse

Methods inherited from Lutaml::Xsd::Spa::Svg::LayoutEngine

for, #initialize

Constructor Details

This class inherits a constructor from Lutaml::Xsd::Spa::Svg::LayoutEngine

Instance Method Details

#calculate(component_data, _component_type) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/lutaml/xsd/spa/svg/layouts/vertical_layout.rb', line 12

def calculate(component_data, _component_type)
  nodes = []
  connections = []

  start_x = 20
  start_y = 20
  current_y = start_y

  # Main component node
  main_node = create_node(
    component_data,
    Geometry::Point.new(start_x, current_y),
    0,
  )
  nodes << main_node
  current_y += config.dimensions.box_height +
    config.dimensions.spacing_vertical

  # Add type reference if present
  if component_data["type"]
    type_node = create_node(
      { "name" => component_data["type"], "kind" => "type" },
      Geometry::Point.new(start_x, current_y),
      1,
    )
    nodes << type_node
    connections << LayoutConnection.new(
      main_node,
      type_node,
      "containment",
    )
    current_y += config.dimensions.box_height +
      config.dimensions.spacing_vertical
  end

  # Add attributes
  if component_data["attributes"]&.any?
    component_data["attributes"].each do |attr|
      attr_node = create_node(
        attr.merge("kind" => "attribute"),
        Geometry::Point.new(
          start_x + config.dimensions.spacing_indent,
          current_y,
        ),
        1,
      )
      nodes << attr_node
      current_y += config.dimensions.box_height +
        config.dimensions.spacing_vertical
    end
  end

  # Calculate total dimensions
  max_y = current_y + 20
  width = config.dimensions.box_width + 40

  LayoutResult.new(
    nodes,
    connections,
    Geometry::Box.new(0, 0, width, max_y),
  )
end