Class: Ea::Svg::EaEmitter::ColorResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/ea_emitter/color_resolver.rb

Overview

Single source of truth for fill + stroke color decisions.

Theme :119 applies:

- Border color (#9A8484) for element strokes
- Attribute color (#66413F) for attribute text
- Method color for operation text

Theme :119 does NOT apply:

- Per-type fill colors (elements use default #FFFFFF)
- Text color (#000000 black for non-attribute text)

Precedence chain for fill:

1. Element's BCol int (when present and not sentinel)
2. Default fill (#FFFFFF)

Precedence chain for stroke:

1. Element's LCol int (when present and not sentinel)
2. Theme border color (when theme is themed)
3. Default stroke (#000000)

Constant Summary collapse

DEFAULT_FILL =
"#FFFFFF"
DEFAULT_STROKE =
"#000000"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theme: nil, stereotype_resolver: Ea::Svg::StereotypeColorResolver.new) ⇒ ColorResolver

Returns a new instance of ColorResolver.



30
31
32
33
# File 'lib/ea/svg/ea_emitter/color_resolver.rb', line 30

def initialize(theme: nil, stereotype_resolver: Ea::Svg::StereotypeColorResolver.new)
  @theme = theme || Ea::Theme::Registry.default
  @stereotype_resolver = stereotype_resolver
end

Instance Attribute Details

#stereotype_resolverObject (readonly)

Returns the value of attribute stereotype_resolver.



28
29
30
# File 'lib/ea/svg/ea_emitter/color_resolver.rb', line 28

def stereotype_resolver
  @stereotype_resolver
end

#themeObject (readonly)

Returns the value of attribute theme.



28
29
30
# File 'lib/ea/svg/ea_emitter/color_resolver.rb', line 28

def theme
  @theme
end

Instance Method Details

#attribute_text_colorObject



50
51
52
# File 'lib/ea/svg/ea_emitter/color_resolver.rb', line 50

def attribute_text_color
  theme.themed? ? (theme.attribute_color || DEFAULT_STROKE) : DEFAULT_STROKE
end

#fill_for(element, classifier) ⇒ Object



35
36
37
38
39
40
# File 'lib/ea/svg/ea_emitter/color_resolver.rb', line 35

def fill_for(element, classifier)
  bcol = Element::BColDecoder.to_hex(element&.background_color)
  return bcol if bcol

  DEFAULT_FILL
end

#stroke_for(element) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/ea/svg/ea_emitter/color_resolver.rb', line 42

def stroke_for(element)
  lcol = Element::BColDecoder.to_hex(element&.line_color)
  return lcol if lcol
  return theme.border_color if theme.themed?

  DEFAULT_STROKE
end