Class: Lutaml::Ea::Diagram::StyleParser

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

Overview

Style parser for EA diagram formats

  • matches Enterprise Architect’s exact visual style

This parser converts EA-specific style information into CSS-compatible properties that exactly match EA’s visual output.

Constant Summary collapse

EA_COLORS =

EA’s exact color scheme from real SVG analysis

{
  # Element background colors
  class_fill: "#FFFFCC",           # Light yellow for classes
  datatype_fill: "#FFCCFF",        # Light pink for data types
  type_fill: "#CCFFCC",            # Light green for types
  package_fill: "#FFFFFF",         # White for packages
  enumeration_fill: "#FFFFCC",     # Same as classes
  interface_fill: "#FFFFCC",       # Same as classes

  # Text colors
  text_normal: "#000000",          # Black for normal text
  text_italic: "#000000",          # Black for italic text
  text_bold: "#000000",            # Black for bold text
  # Dark blue for small text (like in legend)
  text_small: "#003060",

  # Border colors
  border_normal: "#000000",        # Black borders
  border_compartment: "#000000",   # Black compartment lines

  # Background
  diagram_background: "#FFFFFF", # Pure white background

  # Special colors for different element types
  legend_gml: "#A0FFC0",           # Light green for GML legend
  legend_citygml: "#FFFFCC",       # Light yellow for CityGML legend
  # Dark blue background for legend text
  legend_text_background: "#003060",
}.freeze
EA_TYPOGRAPHY =

EA’s exact typography from real SVG analysis

{
  # Font families
  primary_font: "Cambria",
  secondary_font: "Carlito",

  # Font sizes (in points)
  normal_size: "7pt",
  small_size: "7pt",
  stereotype_size: "7pt",
  class_name_size: "7pt",
  attribute_size: "7pt",

  # Font weights
  normal_weight: "0",
  bold_weight: "700",

  # Font styles
  normal_style: "normal",
  italic_style: "italic",
}.freeze
EA_STROKES =

EA’s exact stroke styling

{
  border_width: "1",               # Main element borders
  compartment_width: "1",          # Compartment separator lines
  connector_width: "1",            # Connector lines

  # Line styling
  linecap: "round",
  linejoin: "bevel",
  shape_rendering: "auto",
}.freeze

Instance Method Summary collapse

Instance Method Details

#parse_connector_style(connector) ⇒ Hash

Parse connector style from EA data to match EA’s exact visual output

Parameters:

  • connector (Hash)

    EA connector data

Returns:

  • (Hash)

    CSS-compatible style properties that match EA exactly



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/lutaml/ea/diagram/style_parser.rb', line 107

def parse_connector_style(connector) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  base_style = {
    stroke: EA_COLORS[:border_normal],
    stroke_width: EA_STROKES[:connector_width],
    stroke_linecap: EA_STROKES[:linecap],
    stroke_linejoin: EA_STROKES[:linejoin],
    fill: "none",
    shape_rendering: EA_STROKES[:shape_rendering],
  }

  # Apply connector type specific styling (EA has different styles for
  # different connectors)
  case connector[:type]
  when "generalization"
    base_style[:stroke_dasharray] = "5,5"
  when "aggregation"
    base_style[:stroke] = "#666666"
    base_style[:stroke_dasharray] = "10,5"
  when "composition"
    base_style[:stroke] = "#333333"
    base_style[:stroke_dasharray] = "10,5"
  when "dependency"
    base_style[:stroke] = "#999999"
    base_style[:stroke_dasharray] = "2,2"
  end

  # Parse EA style string if present
  if connector[:style]
    ea_style = parse_ea_style_string(connector[:style])
    base_style.merge!(ea_style)
  end

  base_style
end

#parse_element_style(element) ⇒ Hash

Parse element style from EA data to match EA’s exact visual output

Parameters:

  • element (Hash)

    EA element data

Returns:

  • (Hash)

    CSS-compatible style properties that match EA exactly



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/lutaml/ea/diagram/style_parser.rb', line 80

def parse_element_style(element) # rubocop:disable Metrics/MethodLength
  base_style = get_base_element_style(element[:type])

  # Apply EA-specific style overrides based on element analysis
  style = base_style.dup

  # Parse EA style string if present (EA uses specific format)
  if element[:style]
    ea_style = parse_ea_style_string(element[:style])
    style.merge!(ea_style)
  end

  # Apply stereotype-specific styling
  # (EA has specific colors for stereotypes)
  if element[:stereotype]
    style.merge!(stereotype_style(element[:stereotype]))
  end

  # Apply element-specific EA styling
  style.merge!(element_specific_style(element))

  style
end