Class: Ea::Svg::EaEmitter::Markers
- Inherits:
-
Object
- Object
- Ea::Svg::EaEmitter::Markers
- Defined in:
- lib/ea/svg/ea_emitter/markers.rb
Overview
Emits marker <polygon> and <path> elements per connector,
matching EA's encoding rules. Returns an Array of Layer
structs bucketed by marker style.
Layer style keys:
- :diamond_filled → 4-pt <polygon>, black fill
- :triangle_open → 3-pt <polygon>, white fill
- :arrow → 3-pt <path>, no fill (shares style with
connector lines — same stroke, no fill)
Default mode (grouped: true) consolidates all markers of
the same style into ONE <g>. Pass grouped: false for
per-connector grouping.
Defined Under Namespace
Classes: Entry
Constant Summary collapse
- DIAMOND_HALF_W =
5- DIAMOND_HALF_H =
10- TRI_HALF_BASE =
6- TRI_HEIGHT =
11- ARROW_HALF_BASE =
6- ARROW_HEIGHT =
11
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.
-
#model_index ⇒ Object
readonly
Returns the value of attribute model_index.
-
#stroke_width ⇒ Object
readonly
Returns the value of attribute stroke_width.
Instance Method Summary collapse
-
#count_for(connector) ⇒ Object
Backwards-compatible API: count of marker bodies emitted.
-
#initialize(diagram, model_index:, canvas: nil, grouped: true, stroke_width: 2) ⇒ Markers
constructor
A new instance of Markers.
- #layers ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(diagram, model_index:, canvas: nil, grouped: true, stroke_width: 2) ⇒ Markers
Returns a new instance of Markers.
29 30 31 32 33 34 35 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 29 def initialize(diagram, model_index:, canvas: nil, grouped: true, stroke_width: 2) @diagram = diagram @model_index = model_index @canvas = canvas @grouped = grouped @stroke_width = stroke_width end |
Instance Attribute Details
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
27 28 29 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 27 def canvas @canvas end |
#diagram ⇒ Object (readonly)
Returns the value of attribute diagram.
27 28 29 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 27 def diagram @diagram end |
#grouped ⇒ Object (readonly)
Returns the value of attribute grouped.
27 28 29 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 27 def grouped @grouped end |
#model_index ⇒ Object (readonly)
Returns the value of attribute model_index.
27 28 29 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 27 def model_index @model_index end |
#stroke_width ⇒ Object (readonly)
Returns the value of attribute stroke_width.
27 28 29 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 27 def stroke_width @stroke_width end |
Instance Method Details
#count_for(connector) ⇒ Object
Backwards-compatible API: count of marker bodies emitted.
63 64 65 66 67 68 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 63 def count_for(connector) return 0 if connector.hidden return 0 unless connector.waypoints&.any? { |w| w.position } entries_for(connector).size end |
#layers ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 37 def layers entries = visible_connectors.flat_map { |c| entries_for(c) } return [] if entries.empty? if grouped entries.group_by(&:style_key).map do |key, grouped_entries| # EA emits ONE marker per connector regardless of # anchor overlap. Verified against plateau Bridge # diagram: 9 generalizations fanning from the same # parent anchor produce 9 distinct triangle polygons # at the same coordinates. The earlier "dedup by # anchor" hypothesis is disproven by reference SVGs. Layer.new(style_key: key, style: style_for(key), body: grouped_entries.map(&:body).join("\n ")) end else entries.map { |e| Layer.new(style_key: e.style_key, style: style_for(e.style_key), body: e.body) } end end |
#render ⇒ Object
58 59 60 |
# File 'lib/ea/svg/ea_emitter/markers.rb', line 58 def render layers.map(&:to_svg).join("\n") end |