Class: Ea::Svg::ConnectorPath

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

Overview

Renders one DiagramConnector as an SVG through its waypoints, with an arrowhead at the target end. Matches EA's convention: filled triangle for navigable associations, filled diamond for aggregations, open diamond for shared aggregations.

Constant Summary collapse

ARROW_SIZE =
8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connector, relationship: nil) ⇒ ConnectorPath

Returns a new instance of ConnectorPath.



14
15
16
17
# File 'lib/ea/svg/connector_path.rb', line 14

def initialize(connector, relationship: nil)
  @connector = connector
  @relationship = relationship
end

Instance Attribute Details

#connectorObject (readonly)

Returns the value of attribute connector.



12
13
14
# File 'lib/ea/svg/connector_path.rb', line 12

def connector
  @connector
end

#relationshipObject (readonly)

Returns the value of attribute relationship.



12
13
14
# File 'lib/ea/svg/connector_path.rb', line 12

def relationship
  @relationship
end

Instance Method Details

#renderObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ea/svg/connector_path.rb', line 19

def render
  points = waypoints
  return "" if points.size < 2

  path_d = build_path_d(points)
  style = StyleResolver.new(connector.style)

  parts = []
  parts << %(<g class="connector" data-connector-id="#{escape(connector.id)}">)
  parts << %(  <path d="#{path_d}" stroke="#{style.stroke_color}" stroke-width="#{style.stroke_width}" fill="none"/>)
  parts << render_source_marker(points) if source_marker?
  parts << render_target_marker(points)
  parts << %(</g>)
  parts.join("\n            ")
end