Class: Ea::Svg::EaEmitter::Element::AttributeRenderer

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

Overview

Emits the attribute compartment text <g>. Each attribute renders as TWO <text> elements (visibility marker + content) matching EA's encoding.

Constant Summary collapse

DEFAULT_VISIBILITY_X_OFFSET =
5
DEFAULT_CONTENT_X_OFFSET =
26
DEFAULT_FONT_UNIT =
"pt"

Class Method Summary collapse

Class Method Details

.lines_for(classifier, lookup: nil) ⇒ Object

Builds attribute display lines from classifier properties, hiding properties that are navigable association ends (those are rendered as connector lines).

When a property carries a stereotype (e.g. «voidable»), EA renders the stereotype label as a separate line above the property's own line. We insert those labels here so the renderer's per-line spacing naturally places them.

Pass a lookup (any callable returning a Classifier for an id) to enable inherited-property namespace prefixing.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ea/svg/ea_emitter/element/attribute_renderer.rb', line 47

def self.lines_for(classifier, lookup: nil)
  props = displayable_properties(classifier)
  return [] unless props

  props.flat_map do |prop|
    lines = []
    stereotype = property_stereotype(prop)
    lines << "«#{stereotype}»" if stereotype
    lines << AttributeLineBuilder.new(prop, host: classifier,
                                        lookup: lookup).to_s
  end
end

.render(lines, bounds:, first_y:, family:, size:, size_unit: DEFAULT_FONT_UNIT, fill: "#000000", visibility_x_offset: DEFAULT_VISIBILITY_X_OFFSET, content_x_offset: DEFAULT_CONTENT_X_OFFSET) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ea/svg/ea_emitter/element/attribute_renderer.rb', line 15

def self.render(lines, bounds:, first_y:, family:,
                size:, size_unit: DEFAULT_FONT_UNIT,
                fill: "#000000",
                visibility_x_offset: DEFAULT_VISIBILITY_X_OFFSET,
                content_x_offset: DEFAULT_CONTENT_X_OFFSET)
  line_h = size + 4
  text_blocks = []
  lines.each_with_index do |line, idx|
    y = first_y + (idx * line_h)
    visibility, rest = split_visibility(line)
    if visibility
      text_blocks << build_text(bounds.x + visibility_x_offset, y, visibility, family, size, size_unit, fill)
      text_blocks << build_text(bounds.x + content_x_offset, y, rest, family, size, size_unit, fill)
    else
      text_blocks << build_text(bounds.x + visibility_x_offset, y, line.strip, family, size, size_unit, fill)
    end
  end
  group_style = "stroke-width:1;stroke-linecap:round;stroke-linejoin:bevel; fill:#{fill};fill-opacity:1.00; stroke:#000000; stroke-opacity:0.00"
  %(<g style="#{group_style}">\n#{text_blocks.join("\n")}\n</g>)
end