Class: Archimate::Svg::Entity::BaseEntity
- Inherits:
-
Object
- Object
- Archimate::Svg::Entity::BaseEntity
- Defined in:
- lib/archimate/svg/entity/base_entity.rb
Direct Known Subclasses
ApplicationComponent, Artifact, DataEntity, Device, DiagramObject, Equipment, EventEntity, Facility, Group, Meaning, MotivationEntity, Node, Note, Product, RectEntity, Representation, RoundedRectEntity, ServiceEntity, Value
Instance Attribute Summary collapse
-
#background_class ⇒ Object
readonly
Returns the value of attribute background_class.
-
#badge ⇒ Object
readonly
Returns the value of attribute badge.
-
#badge_bounds ⇒ Object
readonly
Returns the value of attribute badge_bounds.
-
#bounds_offset ⇒ Object
readonly
Returns the value of attribute bounds_offset.
-
#child ⇒ Object
readonly
Returns the value of attribute child.
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#text_bounds ⇒ Object
readonly
Returns the value of attribute text_bounds.
Instance Method Summary collapse
- #entity_badge(xml) ⇒ Object
- #entity_label(xml) ⇒ Object
- #group_attrs ⇒ Object
-
#initialize(child, bounds_offset) ⇒ BaseEntity
constructor
A new instance of BaseEntity.
- #layer_background_class ⇒ Object
- #optional_link(xml, &block) ⇒ Object
- #shape_style ⇒ Object
- #text_lines(text) ⇒ Object
- #text_style ⇒ Object
- #to_svg(xml) ⇒ Object
Constructor Details
#initialize(child, bounds_offset) ⇒ BaseEntity
Returns a new instance of BaseEntity.
15 16 17 18 19 20 21 22 23 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 15 def initialize(child, bounds_offset) @child = child @text_bounds = child.bounds.reduced_by(2) @bounds_offset = bounds_offset @entity = @child.element || @child @background_class = layer_background_class @text_align = nil @badge = nil end |
Instance Attribute Details
#background_class ⇒ Object (readonly)
Returns the value of attribute background_class.
13 14 15 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 13 def background_class @background_class end |
#badge ⇒ Object (readonly)
Returns the value of attribute badge.
12 13 14 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 12 def badge @badge end |
#badge_bounds ⇒ Object (readonly)
Returns the value of attribute badge_bounds.
11 12 13 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 11 def badge_bounds @badge_bounds end |
#bounds_offset ⇒ Object (readonly)
Returns the value of attribute bounds_offset.
9 10 11 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 9 def bounds_offset @bounds_offset end |
#child ⇒ Object (readonly)
Returns the value of attribute child.
7 8 9 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 7 def child @child end |
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
8 9 10 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 8 def entity @entity end |
#text_bounds ⇒ Object (readonly)
Returns the value of attribute text_bounds.
10 11 12 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 10 def text_bounds @text_bounds end |
Instance Method Details
#entity_badge(xml) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 88 def entity_badge(xml) return if badge.nil? xml.use( badge_bounds .to_h .merge("xlink:href" => badge) ) end |
#entity_label(xml) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 65 def entity_label(xml) return if (entity.nil? || entity.name.nil? || entity.name.strip.empty?) && (child.content.nil? || child.content.strip.empty?) xml.foreignObject(text_bounds.to_h) do xml.table(xmlns: "http://www.w3.org/1999/xhtml", style: "height:#{text_bounds.height}px;width:#{text_bounds.width}px;") do xml.tr(style: "height:#{text_bounds.height}px;") do xml.td(class: "entity-name") do xml.div(class: "archimate-badge-spacer") unless badge.nil? xml.p(class: "entity-name", style: text_style) do text_lines(entity.name || child.content).each do |line| xml.text(line) xml.br end end end end end end end |
#group_attrs ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 122 def group_attrs attrs = { id: @entity.id } # TODO: Transform only needed only for Archi file types attrs[:transform] = "translate(#{@bounds_offset.x || 0}, #{@bounds_offset.y || 0})" unless @bounds_offset.nil? attrs[:class] = "archimate-#{@entity.type}" if @entity.type || !@entity.type.empty? attrs end |
#layer_background_class ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 25 def layer_background_class case child.element&.layer when "Strategy", DataModel::Layers::Strategy "archimate-strategy-background" when "Business", DataModel::Layers::Business "archimate-business-background" when "Application", DataModel::Layers::Application "archimate-application-background" when "Technology", DataModel::Layers::Technology "archimate-infrastructure-background" when "Physical", DataModel::Layers::Physical "archimate-physical-background" when "Motivation", DataModel::Layers::Motivation "archimate-motivation-background" when "Implementation and Migration", DataModel::Layers::Implementation_and_migration "archimate-implementation-background" when "Connectors", DataModel::Layers::Connectors "archimate-connectors-background" else puts "Unexpected layer #{child.element&.layer.inspect}" if child.element&.layer end end |
#optional_link(xml, &block) ⇒ Object
61 62 63 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 61 def optional_link(xml, &block) block.call end |
#shape_style ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 97 def shape_style style = child.style return "" if style.nil? { "fill": style.fill_color&.to_rgba, "stroke": style.line_color&.to_rgba, "stroke-width": style.line_width }.delete_if { |_key, value| value.nil? } .map { |key, value| "#{key}:#{value};" } .join("") end |
#text_lines(text) ⇒ Object
84 85 86 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 84 def text_lines(text) text.tr("\r\n", "\n").split(/[\r\n]/) end |
#text_style ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 109 def text_style style = child.style || DataModel::Style.new { "fill": style.font_color&.to_rgba, "color": style.font_color&.to_rgba, "font-family": style.font&.name, "font-size": style.font&.size, "text-align": style.text_align || @text_align }.delete_if { |_key, value| value.nil? } .map { |key, value| "#{key}:#{value};" } .join("") end |
#to_svg(xml) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/archimate/svg/entity/base_entity.rb', line 48 def to_svg(xml) optional_link(xml) { xml.g(group_attrs) do xml.title { xml.text @entity.name } unless @entity.name.nil? || @entity.name.empty? xml.desc { xml.text(@entity.documentation.to_s) } if @entity.documentation && !@entity.documentation.empty? entity_shape(xml, child.bounds) entity_badge(xml) entity_label(xml) child.nodes.each { |c| Svg::EntityFactory.make_entity(c, child.bounds).to_svg(xml) } end } end |