Class: Ea::Svg::EaEmitter::Elements

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

Overview

Emits the elements layer. Orchestrates per-element rendering by delegating to specialized compartment renderers (shape, header, divider, attribute). Frame-element filtering and stereotype-color fallback also live in dedicated collaborators.

Defined Under Namespace

Classes: PackageContentRow

Constant Summary collapse

DEFAULT_FILL =
"#FFFFFF"
DEFAULT_STROKE =
"#000000"
DEFAULT_STROKE_WIDTH =
2
DEFAULT_TEXT_COLOR =
"#000000"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diagram, model_index:, canvas: nil, document: nil) ⇒ Elements

Returns a new instance of Elements.



19
20
21
22
23
24
# File 'lib/ea/svg/ea_emitter/elements.rb', line 19

def initialize(diagram, model_index:, canvas: nil, document: nil)
  @diagram = diagram
  @model_index = model_index
  @canvas = canvas
  @document = document
end

Instance Attribute Details

#canvasObject (readonly)

Returns the value of attribute canvas.



17
18
19
# File 'lib/ea/svg/ea_emitter/elements.rb', line 17

def canvas
  @canvas
end

#diagramObject (readonly)

Returns the value of attribute diagram.



17
18
19
# File 'lib/ea/svg/ea_emitter/elements.rb', line 17

def diagram
  @diagram
end

#documentObject (readonly)

Returns the value of attribute document.



17
18
19
# File 'lib/ea/svg/ea_emitter/elements.rb', line 17

def document
  @document
end

#model_indexObject (readonly)

Returns the value of attribute model_index.



17
18
19
# File 'lib/ea/svg/ea_emitter/elements.rb', line 17

def model_index
  @model_index
end

Instance Method Details

#groupsObject

Returns an Array of per-entity <g>...</g> strings. Each element contributes up to 4 groups (shape, header, divider, attrs) in EA's per-entity layer order.



33
34
35
# File 'lib/ea/svg/ea_emitter/elements.rb', line 33

def groups
  ordered_elements.flat_map { |e| groups_for(e) }
end

#package_content_lines_for(model_element) ⇒ Object

EA renders a package's child classifiers and sub-packages as alphabetical "+ Name" rows in the body compartment, but only when the diagram's t_diagram.ShowPackageContents flag is non-zero. Returns [] when the diagram suppresses



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/ea/svg/ea_emitter/elements.rb', line 188

def package_content_lines_for(model_element)
  return [] unless model_element.is_a?(Ea::Model::Package)
  return [] unless diagram.show_package_contents

  children = package_children(model_element)
  return [] if children.empty?

  children.sort_by { |c| c.name.to_s }.map do |c|
    PackageContentRow.new(name: c.name.to_s, kind: row_icon_kind(c))
  end
end

#renderObject



26
27
28
# File 'lib/ea/svg/ea_emitter/elements.rb', line 26

def render
  groups.join("\n")
end