Class: Ea::Svg::EaEmitter::Element::ConstraintRenderer

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

Overview

Emits the constraints compartment text <g>. EA renders constraints as a sub-compartment with an italic "constraints" header followed by {name} lines:

<text style="...font-style:italic;...">constraints</text>
<text style="...font-style:normal;...">{pattern}</text>

Constant Summary collapse

HEADER_TEXT =
"constraints"
HEADER_X_OFFSET =
5
LINE_X_OFFSET =
5

Class Method Summary collapse

Class Method Details

.render(constraints, bounds:, first_y:, family:, size:, fill: "#000000") ⇒ Object



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

def self.render(constraints, bounds:, first_y:, family:, size:,
                fill: "#000000")
  line_h = size + 4
  text_blocks = []
  text_blocks << build_text(
    bounds.x + centered_x_offset(bounds, size), first_y,
    HEADER_TEXT, family, size, fill, style: "italic"
  )
  constraints.each_with_index do |constraint, idx|
    y = first_y + ((idx + 1) * line_h)
    text_blocks << build_text(
      bounds.x + LINE_X_OFFSET, y,
      "{#{constraint.name}}", family, size, fill
    )
  end
  %(<g style="#{Style::TEXT_GROUP}">\n#{text_blocks.join("\n")}\n</g>)
end