Class: Lutaml::Ea::Diagram::StyleResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/ea/diagram/style_resolver.rb

Overview

Resolves styles for diagram elements by merging multiple sources

Priority order (highest to lowest):

  1. EA Data from DiagramObject.style (BCol, LCol, etc.)

  2. User Configuration (YAML)

  3. Built-in Defaults

This ensures that:

  • EA’s original styling is preserved when present

  • Users can override defaults via configuration

  • Sensible defaults are always available

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path = nil) ⇒ StyleResolver

Initialize with configuration

Parameters:

  • config_path (String, nil) (defaults to: nil)

    Path to configuration file



26
27
28
29
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 26

def initialize(config_path = nil)
  @configuration = Configuration.new(config_path)
  @style_parser = StyleParser.new
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



21
22
23
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 21

def configuration
  @configuration
end

#style_parserObject (readonly)

Returns the value of attribute style_parser.



21
22
23
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 21

def style_parser
  @style_parser
end

Instance Method Details

#resolve_connector_style(connector, diagram_link = nil) ⇒ Hash

Resolve complete style for a connector

(Association, Generalization, etc.) Diagram routing data

Parameters:

Returns:

  • (Hash)

    Complete resolved style



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 82

def resolve_connector_style(connector, diagram_link = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  # Determine connector type
  connector_type = determine_connector_type(connector)

  style = {}

  # Start with configuration defaults for this connector type
  style[:arrow_type] =
    configuration.connector_style(connector_type, "arrow.type")
  style[:arrow_size] =
    configuration.connector_style(connector_type, "arrow.size")
  style[:stroke] =
    configuration.connector_style(connector_type, "line.stroke")
  style[:stroke_width] =
    configuration.connector_style(connector_type, "line.stroke_width")
  style[:stroke_dasharray] =
    configuration.connector_style(connector_type,
                                  "line.stroke_dasharray")
  style[:fill] =
    configuration.connector_style(connector_type, "line.fill") || "none"

  # Override with EA data if present (highest priority)
  if diagram_link&.style
    ea_style = parse_diagram_link_style(diagram_link.style)
    style.merge!(ea_style)
  end

  style.compact
end

#resolve_element_style(element, diagram_object = nil) ⇒ Hash Also known as: parse_element_style

Resolve complete style for an element

Diagram placement data

Parameters:

Returns:

  • (Hash)

    Complete resolved style



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/ea/diagram/style_resolver.rb', line 37

def resolve_element_style(element, diagram_object = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  style = {}

  # Start with configuration defaults
  style[:fill] = configuration.style_for(element, "colors.fill")
  style[:stroke] = configuration.style_for(element, "colors.stroke")
  style[:stroke_width] =
    configuration.style_for(element, "box.stroke_width")
  style[:stroke_linecap] =
    configuration.style_for(element, "box.stroke_linecap")
  style[:stroke_linejoin] =
    configuration.style_for(element, "box.stroke_linejoin")
  style[:corner_radius] =
    configuration.style_for(element, "box.corner_radius")
  style[:fill_opacity] =
    configuration.style_for(element, "box.fill_opacity")
  style[:stroke_opacity] =
    configuration.style_for(element, "box.stroke_opacity")

  # Font configuration
  style[:font_family] =
    configuration.style_for(element, "fonts.class_name.family")
  style[:font_size] =
    configuration.style_for(element, "fonts.class_name.size")
  style[:font_weight] =
    configuration.style_for(element, "fonts.class_name.weight")
  style[:font_style] =
    configuration.style_for(element, "fonts.class_name.style")

  # Override with EA data if present (highest priority)
  if diagram_object&.style
    ea_style = parse_diagram_object_style(diagram_object.style)
    style.merge!(ea_style)
  end

  style.compact
end

#resolve_fill_color(element, diagram_object = nil) ⇒ String

Resolve fill color specifically

Diagram placement data

Parameters:

Returns:

  • (String)

    Resolved fill color



118
119
120
121
122
123
124
125
126
127
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 118

def resolve_fill_color(element, diagram_object = nil)
  # Priority 1: EA data from DiagramObject.style
  if diagram_object&.style
    ea_style = parse_diagram_object_style(diagram_object.style)
    return ea_style[:fill] if ea_style[:fill]
  end

  # Priority 2: Configuration (Class > Package > Stereotype > Defaults)
  configuration.style_for(element, "colors.fill")
end

#resolve_font(element, context = :class_name) ⇒ Hash

Resolve font properties

(:class_name, :attribute, :operation, :stereotype)

Parameters:

  • element (Object)

    UML element

  • context (Symbol) (defaults to: :class_name)

    Font context

Returns:

  • (Hash)

    Font properties (family, size, weight, style)



152
153
154
155
156
157
158
159
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 152

def resolve_font(element, context = :class_name)
  {
    family: configuration.style_for(element, "fonts.#{context}.family"),
    size: configuration.style_for(element, "fonts.#{context}.size"),
    weight: configuration.style_for(element, "fonts.#{context}.weight"),
    style: configuration.style_for(element, "fonts.#{context}.style"),
  }.compact
end

#resolve_stroke_color(element, diagram_object = nil) ⇒ String

Resolve stroke color specifically

Diagram placement data

Parameters:

Returns:

  • (String)

    Resolved stroke color



135
136
137
138
139
140
141
142
143
144
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 135

def resolve_stroke_color(element, diagram_object = nil)
  # Priority 1: EA data from DiagramObject.style
  if diagram_object&.style
    ea_style = parse_diagram_object_style(diagram_object.style)
    return ea_style[:stroke] if ea_style[:stroke]
  end

  # Priority 2: Configuration
  configuration.style_for(element, "colors.stroke")
end