Class: Ea::Svg::ElementBox
- Inherits:
-
Object
- Object
- Ea::Svg::ElementBox
- Defined in:
- lib/ea/svg/element_box.rb
Overview
Renders one DiagramElement as an SVG
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#model_index ⇒ Object
readonly
Returns the value of attribute model_index.
Instance Method Summary collapse
-
#initialize(element, model_index:) ⇒ ElementBox
constructor
A new instance of ElementBox.
- #render ⇒ Object
Constructor Details
#initialize(element, model_index:) ⇒ ElementBox
Returns a new instance of ElementBox.
14 15 16 17 |
# File 'lib/ea/svg/element_box.rb', line 14 def initialize(element, model_index:) @element = element @model_index = model_index end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
12 13 14 |
# File 'lib/ea/svg/element_box.rb', line 12 def element @element end |
#model_index ⇒ Object (readonly)
Returns the value of attribute model_index.
12 13 14 |
# File 'lib/ea/svg/element_box.rb', line 12 def model_index @model_index end |
Instance Method Details
#render ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ea/svg/element_box.rb', line 19 def render return "" unless element.bounds b = normalize_bounds(element.bounds) style = StyleResolver.new(element.style) label_text = model_element_name <<~SVG.chomp <g class="element" data-element-id="#{escape(element.id)}"> <rect x="#{b.x}" y="#{b.y}" width="#{b.width}" height="#{b.height}" fill="#{style.fill_color}" stroke="#{style.stroke_color}" stroke-width="#{style.stroke_width}"/> <text x="#{b.x + (b.width / 2.0)}" y="#{b.y + (b.height / 2.0)}" text-anchor="middle" dominant-baseline="middle" fill="#{style.font_color}" font-family="sans-serif" font-size="14">#{escape(label_text)}</text> </g> SVG end |