Class: Ea::Svg::EaEmitter::Label::EndLabel

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

Overview

Renders the role + «property» + multiplicity cluster at one endpoint of a UML association connector.

EA encodes end-labels in two geometry boxes per endpoint:

LLT/LRT - "label text" position (role name slot)
LLB/LRB - "label box" position (multiplicity slot)

Each box carries OX/OY offsets from the connector anchor. The «property» stereotype renders one line below the role name. EA records qualified role names ("pkg::role") for cross-package associations but suppresses label rendering for those — only simple role names render.

Constant Summary collapse

PROPERTY_STEREOTYPE =
"«property»"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(canvas:, model_index:, document:, theme:, font_family:, font_size:, font_unit:) ⇒ EndLabel

Returns a new instance of EndLabel.



26
27
28
29
30
31
32
33
34
35
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 26

def initialize(canvas:, model_index:, document:, theme:,
               font_family:, font_size:, font_unit:)
  @canvas = canvas
  @model_index = model_index
  @document = document
  @theme = theme
  @font_family = font_family
  @font_size = font_size
  @font_unit = font_unit
end

Instance Attribute Details

#canvasObject (readonly)

Returns the value of attribute canvas.



23
24
25
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 23

def canvas
  @canvas
end

#documentObject (readonly)

Returns the value of attribute document.



23
24
25
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 23

def document
  @document
end

#font_familyObject (readonly)

Returns the value of attribute font_family.



23
24
25
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 23

def font_family
  @font_family
end

#font_sizeObject (readonly)

Returns the value of attribute font_size.



23
24
25
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 23

def font_size
  @font_size
end

#font_unitObject (readonly)

Returns the value of attribute font_unit.



23
24
25
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 23

def font_unit
  @font_unit
end

#model_indexObject (readonly)

Returns the value of attribute model_index.



23
24
25
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 23

def model_index
  @model_index
end

#themeObject (readonly)

Returns the value of attribute theme.



23
24
25
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 23

def theme
  @theme
end

Instance Method Details

#texts(text_box:, mult_box:, anchor:, connector:, end_kind:) ⇒ Object

Returns an Array of <text> SVG strings for one endpoint.

text_box   - LLT or LRT box geometry (role position)
mult_box   - LLB or LRB box geometry (mult position)
anchor     - [x, y] of the connector endpoint
connector  - the DiagramConnector (for relationship lookup)
end_kind   - :source or :target


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ea/svg/ea_emitter/label/end_label.rb', line 44

def texts(text_box:, mult_box:, anchor:, connector:, end_kind:)
  from_property, role, mult = role_and_multiplicity(connector, end_kind)
  if role_empty?(role) && mult_empty?(mult)
    other_from_prop, other_role, other_mult = role_and_multiplicity(connector,
                                                    opposite(end_kind))
    role = other_role if role_empty?(role)
    mult ||= other_mult
    from_property ||= other_from_prop
  end
  agg = aggregation_kind_for(connector, end_kind)
  standalone = standalone_multiplicity(role, mult, aggregation: agg)
  return [] if role_empty?(role) && (standalone.nil? || standalone.empty?)

  text_pos = position_at(text_box, anchor)
  mult_pos = position_at(mult_box, anchor) || text_pos
  show_property = property_label?(connector)

  build_texts(role:, mult:, standalone:,
              text_pos:, mult_pos:, show_property:)
end