Module: Ea::Svg::EaEmitter::Compartment::EnumLiterals

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

Overview

Enumeration literal compartment: divider line + "literals" italic header + each literal name. Skipped when the classifier has no literals or the geometry cannot fit them.

Class Method Summary collapse

Class Method Details

.literal_header_text(context) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ea/svg/ea_emitter/compartment/enum_literals.rb', line 39

def literal_header_text(context)
  TextRenderer.new(
    content: "literals",
    x: context.bounds.x + (context.bounds.width / 2.0) -
      (8 * context.size * context.theme.text_width_factor) / 2,
    y: context.geometry.enum_literal_first_y,
    family: context.family, size: context.size, size_unit: context.size_unit,
    style: "italic", fill: context.theme.text_color,
    stroke_in_text: context.theme.stroke_in_text_color,
    width_factor: context.theme.text_width_factor
  ).to_svg
end

.literal_name_text(context, literal, y) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ea/svg/ea_emitter/compartment/enum_literals.rb', line 64

def literal_name_text(context, literal, y)
  TextRenderer.new(
    content: literal.name.to_s,
    x: context.bounds.x + (context.theme.attribute_spec.content_x_offset || 26),
    y: y,
    family: context.family, size: context.size, size_unit: context.size_unit,
    fill: context.theme.text_color,
    stroke_in_text: context.theme.stroke_in_text_color,
    width_factor: context.theme.text_width_factor
  ).to_svg
end

.render(context) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ea/svg/ea_emitter/compartment/enum_literals.rb', line 13

def render(context)
  return nil unless context.enum_literals.any?
  return nil unless context.geometry.enum_literal_first_y

  [
    Element::DividerRenderer.render(
      context.bounds,
      y: context.geometry.enum_divider_y,
      stroke: context.stroke,
      stroke_width: context.stroke_width
    ),
    render_literals_block(context)
  ].join("\n")
end

.render_literals_block(context) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/ea/svg/ea_emitter/compartment/enum_literals.rb', line 28

def render_literals_block(context)
  line_h = context.size + (context.theme.compartments.attr_line_offset || 4)
  text_blocks = [literal_header_text(context)]
  context.enum_literals.each_with_index do |literal, idx|
    y = context.geometry.enum_literal_first_y + ((idx + 1) * line_h)
    text_blocks << visibility_placeholder(context, y)
    text_blocks << literal_name_text(context, literal, y)
  end
  wrap_group(text_blocks, context.theme.text_color)
end

.visibility_placeholder(context, y) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ea/svg/ea_emitter/compartment/enum_literals.rb', line 52

def visibility_placeholder(context, y)
  TextRenderer.new(
    content: " ",
    x: context.bounds.x + (context.theme.attribute_spec.visibility_x_offset || 5),
    y: y,
    family: context.family, size: context.size, size_unit: context.size_unit,
    fill: context.theme.text_color,
    stroke_in_text: context.theme.stroke_in_text_color,
    width_factor: context.theme.text_width_factor
  ).to_svg
end

.wrap_group(text_blocks, text_color) ⇒ Object



76
77
78
79
80
81
# File 'lib/ea/svg/ea_emitter/compartment/enum_literals.rb', line 76

def wrap_group(text_blocks, text_color)
  style = "stroke-width:1;stroke-linecap:round;stroke-linejoin:bevel; " \
          "fill:#{text_color};fill-opacity:1.00; " \
          "stroke:#000000; stroke-opacity:0.00"
  %(<g style="#{style}">\n#{text_blocks.join("\n")}\n</g>)
end