Class: Lutaml::Ea::Diagram::StyleResolver
- Inherits:
-
Object
- Object
- Lutaml::Ea::Diagram::StyleResolver
- Defined in:
- lib/lutaml/ea/diagram/style_resolver.rb
Overview
Resolves styles for diagram elements by merging multiple sources
Priority order (highest to lowest):
-
EA Data from DiagramObject.style (BCol, LCol, etc.)
-
User Configuration (YAML)
-
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
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#style_parser ⇒ Object
readonly
Returns the value of attribute style_parser.
Instance Method Summary collapse
-
#initialize(config_path = nil) ⇒ StyleResolver
constructor
Initialize with configuration.
-
#resolve_connector_style(connector, diagram_link = nil) ⇒ Hash
Resolve complete style for a connector.
-
#resolve_element_style(element, diagram_object = nil) ⇒ Hash
(also: #parse_element_style)
Resolve complete style for an element.
-
#resolve_fill_color(element, diagram_object = nil) ⇒ String
Resolve fill color specifically.
-
#resolve_font(element, context = :class_name) ⇒ Hash
Resolve font properties.
-
#resolve_stroke_color(element, diagram_object = nil) ⇒ String
Resolve stroke color specifically.
Constructor Details
#initialize(config_path = nil) ⇒ StyleResolver
Initialize with configuration
23 24 25 26 |
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 23 def initialize(config_path = nil) @configuration = Configuration.new(config_path) @style_parser = StyleParser.new end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
18 19 20 |
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 18 def configuration @configuration end |
#style_parser ⇒ Object (readonly)
Returns the value of attribute style_parser.
18 19 20 |
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 18 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
79 80 81 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 |
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 79 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
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 |
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 34 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
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 115 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)
149 150 151 152 153 154 155 156 |
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 149 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
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/lutaml/ea/diagram/style_resolver.rb', line 132 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 |