Class: Ea::Svg::Renderer
- Inherits:
-
Object
- Object
- Ea::Svg::Renderer
- Defined in:
- lib/ea/svg/renderer.rb
Overview
Renders an Ea::Model::Diagram into a standalone SVG string. Coordinates come straight from the umldi (UML Diagram Interchange) content captured by the source adapter: DiagramElement bounds and DiagramConnector waypoints.
The renderer walks the diagram once, computes the union bounding box, and emits SVG in the same coordinate space (no y-flip; SVG's +y is down, same as EA's pixel space).
Constant Summary collapse
- DEFAULT_PADDING =
20
Instance Attribute Summary collapse
-
#diagram ⇒ Object
readonly
Returns the value of attribute diagram.
-
#model_index ⇒ Object
readonly
Returns the value of attribute model_index.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(diagram, model_index: {}, padding: DEFAULT_PADDING) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
Constructor Details
#initialize(diagram, model_index: {}, padding: DEFAULT_PADDING) ⇒ Renderer
Returns a new instance of Renderer.
20 21 22 23 24 |
# File 'lib/ea/svg/renderer.rb', line 20 def initialize(diagram, model_index: {}, padding: DEFAULT_PADDING) @diagram = diagram @model_index = model_index @options = { padding: padding } end |
Instance Attribute Details
#diagram ⇒ Object (readonly)
Returns the value of attribute diagram.
18 19 20 |
# File 'lib/ea/svg/renderer.rb', line 18 def diagram @diagram end |
#model_index ⇒ Object (readonly)
Returns the value of attribute model_index.
18 19 20 |
# File 'lib/ea/svg/renderer.rb', line 18 def model_index @model_index end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/ea/svg/renderer.rb', line 18 def @options end |
Instance Method Details
#render ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ea/svg/renderer.rb', line 26 def render bounds = BoundsCalculator.new(diagram).compute padded = pad(bounds) <<~SVG <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox="#{padded.x} #{padded.y} #{padded.width} #{padded.height}" width="#{padded.width}" height="#{padded.height}" font-family="sans-serif"> <rect x="#{padded.x}" y="#{padded.y}" width="#{padded.width}" height="#{padded.height}" fill="white"/> #{render_elements} #{render_connectors} </svg> SVG end |