Class: Ea::Svg::BoundsCalculator

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

Overview

Computes the actual drawing-area bounding box of an Ea::Model::Diagram. EA stores bounds in pixel space with two quirks: element rects can be inverted (rectbottom < recttop, producing negative height), and elements/connectors can sit outside the canvas bounds. The drawing area is the union of all element rects and connector waypoint positions.

Defined Under Namespace

Classes: Bounds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diagram) ⇒ BoundsCalculator

Returns a new instance of BoundsCalculator.



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

def initialize(diagram)
  @diagram = diagram
end

Instance Attribute Details

#diagramObject (readonly)

Returns the value of attribute diagram.



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

def diagram
  @diagram
end

Instance Method Details

#computeObject



18
19
20
21
22
23
24
25
26
# File 'lib/ea/svg/bounds_calculator.rb', line 18

def compute
  points = all_points
  return fallback_bounds if points.empty?

  xs = points.map(&:first)
  ys = points.map(&:last)
  Bounds.new(x: xs.min, y: ys.min, width: xs.max - xs.min,
              height: ys.max - ys.min)
end