Class: Ea::Svg::EaEmitter::Connectors
- Inherits:
-
Object
- Object
- Ea::Svg::EaEmitter::Connectors
- 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
-
#canvas ⇒ Object
readonly
Returns the value of attribute canvas.
-
#diagram ⇒ Object
readonly
Returns the value of attribute diagram.
-
#grouped ⇒ Object
readonly
Returns the value of attribute grouped.
-
#stroke_width ⇒ Object
readonly
Returns the value of attribute stroke_width.
Instance Method Summary collapse
-
#initialize(diagram, canvas: nil, grouped: true, stroke_width: 2) ⇒ Connectors
constructor
A new instance of Connectors.
- #layers ⇒ Object
- #line_style ⇒ Object
-
#render ⇒ Object
Backwards-compatible render — joins all layers'
<g>.
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
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
19 20 21 |
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 19 def canvas @canvas end |
#diagram ⇒ Object (readonly)
Returns the value of attribute diagram.
19 20 21 |
# File 'lib/ea/svg/ea_emitter/connectors.rb', line 19 def diagram @diagram end |
#grouped ⇒ Object (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_width ⇒ Object (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
#layers ⇒ Object
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_style ⇒ Object
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 |
#render ⇒ Object
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 |