Class: Ea::Svg::EaEmitter::Connectors

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

Overview

Emits connector line <path> elements grouped per line-style. Returns an Array of Layer structs.

Default mode (grouped: true) consolidates all same-style paths into ONE <g> element — matching EA's encoding for diagrams with many similarly-styled connectors.

Pass grouped: false for per-connector grouping (one <g> per line, used when strict per-entity interleaving with markers is required).

Constant Summary collapse

LINE_STYLE_KEY =
:connector_line

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diagram, canvas: nil, grouped: true, stroke_width: 2) ⇒ Connectors

Returns a new instance of Connectors.



21
22
23
24
25
26
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 21

def initialize(diagram, canvas: nil, grouped: true, stroke_width: 2)
  @diagram = diagram
  @canvas = canvas
  @grouped = grouped
  @stroke_width = stroke_width
end

Instance Attribute Details

#canvasObject (readonly)

Returns the value of attribute canvas.



19
20
21
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 19

def canvas
  @canvas
end

#diagramObject (readonly)

Returns the value of attribute diagram.



19
20
21
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 19

def diagram
  @diagram
end

#groupedObject (readonly)

Returns the value of attribute grouped.



19
20
21
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 19

def grouped
  @grouped
end

#stroke_widthObject (readonly)

Returns the value of attribute stroke_width.



19
20
21
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 19

def stroke_width
  @stroke_width
end

Instance Method Details

#layersObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 28

def layers
  paths = visible_connectors.filter_map { |c| path_for(c) }
  return [] if paths.empty?

  if grouped
    [Layer.new(style_key: LINE_STYLE_KEY, style: line_style,
               body: paths.join("\n  "))]
  else
    paths.map do |path|
      Layer.new(style_key: LINE_STYLE_KEY, style: line_style, body: path)
    end
  end
end

#line_styleObject



42
43
44
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 42

def line_style
  "stroke-width:#{stroke_width};stroke-linecap:round;stroke-linejoin:bevel; fill:#000000;fill-opacity:0.00; stroke:#000000; stroke-opacity:1.00"
end

#renderObject

Backwards-compatible render — joins all layers' <g>.



47
48
49
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 47

def render
  layers.map(&:to_svg).join("\n")
end