Class: Ea::Svg::EaEmitter::Element::OperationRenderer
- Inherits:
-
Object
- Object
- Ea::Svg::EaEmitter::Element::OperationRenderer
- Defined in:
- lib/ea/svg/ea_emitter/element/operation_renderer.rb
Overview
Emits the operation compartment text <g>. Each operation
renders as TWO <text> elements matching EA's encoding:
<text>+ </text>
<text>methodName(params): ReturnType</text>
Rendered as a third compartment below the attribute compartment for Klass / Interface classifiers.
Constant Summary collapse
- VISIBILITY_X_OFFSET =
5- CONTENT_X_OFFSET =
20
Class Method Summary collapse
-
.lines_for(classifier) ⇒ Object
Builds display lines for a classifier's operations.
- .render(operations, bounds:, first_y:, family:, size:) ⇒ Object
Class Method Details
.lines_for(classifier) ⇒ Object
Builds display lines for a classifier's operations.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ea/svg/ea_emitter/element/operation_renderer.rb', line 45 def self.lines_for(classifier) ops = classifier.operations return [] unless ops&.any? ops.map do |op| visibility = visibility_prefix(op).strip params = (op.parameters || []).map { |p| "#{p.name}: #{namespace_double_colon(p.type_name)}" }.join(", ") return_type = namespace_double_colon(op.return_type_name) "#{visibility} #{op.name}(#{params}): #{return_type}".strip end end |
.render(operations, bounds:, first_y:, family:, size:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ea/svg/ea_emitter/element/operation_renderer.rb', line 19 def self.render(operations, bounds:, first_y:, family:, size:) line_h = size + 4 text_blocks = [] has_receptions = operations.any?(&:is_reception) if has_receptions text_blocks << TextRenderer.new( content: "receptions", x: bounds.x + (bounds.width / 2.0) - (8 * size * 0.65) / 2, y: first_y, family: family, size: size, style: "italic", fill: "#000000" ).to_svg end ops = has_receptions ? operations : operations offset = has_receptions ? 1 : 0 ops.each_with_index do |op, idx| y = first_y + ((idx + offset) * line_h) text_blocks << build_text(bounds.x + VISIBILITY_X_OFFSET, y, visibility_prefix(op), family, size) text_blocks << build_text(bounds.x + CONTENT_X_OFFSET, y, operation_text(op), family, size) end %(<g style="#{Style::TEXT_GROUP}">\n#{text_blocks.join("\n")}\n</g>) end |