Class: Lutaml::UmlRepository::Presenters::DiagramPresenter

Inherits:
ElementPresenter show all
Defined in:
lib/lutaml/uml_repository/presenters/diagram_presenter.rb

Overview

Presenter for UML Diagram elements

Coordinates the entire diagram rendering pipeline by:

  1. Loading elements and connectors from the repository

  2. Converting EA coordinates to SVG format

  3. Using StyleResolver to merge EA data + config + defaults

  4. Creating a DiagramRenderer wrapper

  5. Generating SVG output via SvgRenderer

Defined Under Namespace

Classes: DiagramRendererWrapper

Instance Attribute Summary collapse

Attributes inherited from ElementPresenter

#context, #element, #repository

Instance Method Summary collapse

Constructor Details

#initialize(diagram, repository, options = {}) ⇒ DiagramPresenter

Returns a new instance of DiagramPresenter.

Parameters:

  • diagram (Lutaml::Uml::Diagram)

    The diagram to present

  • repository (Repository)

    Repository for looking up elements

  • options (Hash) (defaults to: {})

    Rendering options

Options Hash (options):

  • :config_path (String)

    Path to diagram configuration



26
27
28
29
30
# File 'lib/lutaml/uml_repository/presenters/diagram_presenter.rb', line 26

def initialize(diagram, repository, options = {})
  super(diagram, repository)
  @config_path = options[:config_path]
  @layout_engine = Ea::Diagram::LayoutEngine.new
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



20
21
22
# File 'lib/lutaml/uml_repository/presenters/diagram_presenter.rb', line 20

def config_path
  @config_path
end

Instance Method Details

#connectorsArray<Hash>

Get connectors in the diagram

Returns:

  • (Array<Hash>)

    Array of connector data hashes



73
74
75
# File 'lib/lutaml/uml_repository/presenters/diagram_presenter.rb', line 73

def connectors
  build_connectors_data
end

#elementsArray<Hash>

Get elements in the diagram

Returns:

  • (Array<Hash>)

    Array of element data hashes



66
67
68
# File 'lib/lutaml/uml_repository/presenters/diagram_presenter.rb', line 66

def elements
  build_elements_data
end

#svg_output(options = {}) ⇒ String

Generate SVG output for the diagram

Background color Enable interactive features

Parameters:

  • options (Hash) (defaults to: {})

    Rendering options

Options Hash (options):

  • :padding (Integer) — default: 20

    Padding around diagram

  • :background_color (String) — default: "#ffffff"
  • :grid_visible (Boolean) — default: false

    Show grid

  • :interactive (Boolean) — default: false

Returns:

  • (String)

    Complete SVG content



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lutaml/uml_repository/presenters/diagram_presenter.rb', line 42

def svg_output(options = {}) # rubocop:disable Metrics/MethodLength
  # Build diagram data structure
  diagram_data = {
    name: element.name,
    elements: build_elements_data,
    connectors: build_connectors_data,
  }

  # Create diagram renderer wrapper
  diagram_renderer = DiagramRendererWrapper.new(diagram_data,
                                                @layout_engine)

  # Create SVG renderer with configuration
  renderer_options = options.merge(config_path: config_path)
  svg_renderer = Ea::Diagram::SvgRenderer.new(diagram_renderer,
                                              renderer_options)

  # Generate and return SVG
  svg_renderer.render
end

#to_hashObject

Hash representation



101
102
103
104
105
106
107
108
109
110
# File 'lib/lutaml/uml_repository/presenters/diagram_presenter.rb', line 101

def to_hash
  {
    type: "Diagram",
    name: element.name,
    diagram_type: element.diagram_type,
    package_name: element.package_name,
    elements_count: (element.diagram_objects || []).count,
    connectors_count: (element.diagram_links || []).count,
  }
end

#to_table_rowObject

Table row for diagram



91
92
93
94
95
96
97
98
# File 'lib/lutaml/uml_repository/presenters/diagram_presenter.rb', line 91

def to_table_row
  {
    type: "Diagram",
    name: element.name || "(unnamed)",
    details: "#{element.diagram_type} " \
             "- #{(element.diagram_objects || []).count} elements",
  }
end

#to_textObject

Text output for diagram



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/lutaml/uml_repository/presenters/diagram_presenter.rb', line 78

def to_text # rubocop:disable Metrics/AbcSize
  lines = []
  lines << "Diagram: #{element.name}"
  lines << ("=" * 50)
  lines << ""
  lines << "Type:          #{element.diagram_type}"
  lines << "Package:       #{element.package_name || 'Unknown'}"
  lines << "Elements:      #{(element.diagram_objects || []).count}"
  lines << "Connectors:    #{(element.diagram_links || []).count}"
  lines.join("\n")
end