Class: Ea::Svg::EaEmitter::Canvas
- Inherits:
-
Struct
- Object
- Struct
- Ea::Svg::EaEmitter::Canvas
- Defined in:
- lib/ea/svg/ea_emitter/canvas.rb
Overview
Computes the canvas dimensions for the root
Constant Summary collapse
- PX_PER_CM =
28.3464567
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#min_x ⇒ Object
Returns the value of attribute min_x.
-
#min_y ⇒ Object
Returns the value of attribute min_y.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height
10 11 12 |
# File 'lib/ea/svg/ea_emitter/canvas.rb', line 10 def height @height end |
#min_x ⇒ Object
Returns the value of attribute min_x
10 11 12 |
# File 'lib/ea/svg/ea_emitter/canvas.rb', line 10 def min_x @min_x end |
#min_y ⇒ Object
Returns the value of attribute min_y
10 11 12 |
# File 'lib/ea/svg/ea_emitter/canvas.rb', line 10 def min_y @min_y end |
#width ⇒ Object
Returns the value of attribute width
10 11 12 |
# File 'lib/ea/svg/ea_emitter/canvas.rb', line 10 def width @width end |
Class Method Details
.from(diagram) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ea/svg/ea_emitter/canvas.rb', line 13 def self.from(diagram) points = [] (diagram.elements || []).each do |e| b = e.image_bounds || e.bounds next unless b points << [b.x, b.y] points << [b.x + b.width, b.y + b.height] end (diagram.connectors || []).each do |c| (c.waypoints || []).each do |wp| next unless wp.position points << [wp.position.x, wp.position.y] end end return new(min_x: 0, min_y: 0, width: 1, height: 1) if points.empty? xs = points.map(&:first) ys = points.map(&:last) margin = 10 new( min_x: (xs.min || 0) - margin, min_y: (ys.min || 0) - margin, width: (xs.max - xs.min) + (2 * margin), height: (ys.max - ys.min) + (2 * margin) ) end |
Instance Method Details
#height_cm ⇒ Object
50 51 52 |
# File 'lib/ea/svg/ea_emitter/canvas.rb', line 50 def height_cm format_cm(height) end |
#view_box ⇒ Object
42 43 44 |
# File 'lib/ea/svg/ea_emitter/canvas.rb', line 42 def view_box "#{min_x} #{min_y} #{width} #{height}" end |
#width_cm ⇒ Object
46 47 48 |
# File 'lib/ea/svg/ea_emitter/canvas.rb', line 46 def width_cm format_cm(width) end |