Module: Ea::Svg::EaEmitter::Compartment::PackageContents

Defined in:
lib/ea/svg/ea_emitter/compartment/package_contents.rb

Overview

Package-contents compartment. Renders the package's child classifiers and sub-packages as a list of "+ Name" rows in the body, matching EA's package-on-diagram rendering. Each row also draws a small per-type icon to the left of the text (Enumeration gets a list-style icon; other classifiers get the "folded paper" silhouette).

Constant Summary collapse

ROW_HEIGHT =
16
ICON_X_OFFSET =
5
TEXT_X_OFFSET =
23

Class Method Summary collapse

Class Method Details

.group_styleObject



42
43
44
45
# File 'lib/ea/svg/ea_emitter/compartment/package_contents.rb', line 42

def group_style
  "stroke-width:1;stroke-linecap:square;stroke-linejoin:bevel; " \
    "fill-opacity:1.00; stroke-opacity:1.00"
end

.icon_block(bounds, y_top, kind) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/ea/svg/ea_emitter/compartment/package_contents.rb', line 48

def icon_block(bounds, y_top, kind)
  Element::RowIconRenderer.render(
    x_pos: bounds.x + ICON_X_OFFSET,
    y_pos: y_top,
    kind: kind || :default
  )
end

.render(context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ea/svg/ea_emitter/compartment/package_contents.rb', line 20

def render(context)
  rows = context.package_content_lines
  return nil if rows.nil? || rows.empty?

  bounds = context.bounds
  first_y = context.geometry.attr_first_y
  blocks = rows.each_with_index.flat_map do |row, idx|
    y_top = first_y - 11 + (idx * ROW_HEIGHT)
    y_text = first_y + (idx * ROW_HEIGHT)
    [
      icon_block(bounds, y_top, row.kind),
      text_block(bounds, y_text, row.name, context)
    ]
  end
  wrap_group(blocks.join("\n"))
end

.text_block(bounds, y, name, context) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/ea/svg/ea_emitter/compartment/package_contents.rb', line 57

def text_block(bounds, y, name, context)
  TextRenderer.new(
    content: "+ #{name}",
    x: bounds.x + TEXT_X_OFFSET,
    y: y,
    family: context.family, size: context.size,
    size_unit: context.size_unit,
    fill: context.theme.attribute_text_color
  ).to_svg
end

.wrap_group(body) ⇒ Object



37
38
39
# File 'lib/ea/svg/ea_emitter/compartment/package_contents.rb', line 37

def wrap_group(body)
  %(<g style="#{group_style}">\n#{body}\n</g>)
end