Class: Ea::Svg::EaEmitter::BoundsCalculator
- Inherits:
-
Object
- Object
- Ea::Svg::EaEmitter::BoundsCalculator
- Defined in:
- lib/ea/svg/ea_emitter/bounds_calculator.rb
Overview
Computes the (min_x, min_y, width, height) tuple for a Diagram's canvas. Encapsulates the union rules so Canvas stays a small value-object with just coordinate translation and formatting concerns.
Sources contributing to the bounds:
- ElementBounds: logical x-extent, logical+image y-extent
- ConnectorBounds: waypoint positions
- MarkerExtent: MARKER_EXTENT padding around end points
- PackageTabExtent: extra space above Package elements for
the tab polygon (which sits above the
element's logical top).
Each source is a method returning an Array<[x, y]> points. Composing new sources = adding a method, no modification of existing ones (OCP).
Constant Summary collapse
- MARKER_EXTENT =
15- PACKAGE_TAB_HEIGHT =
20- INSET_LEFT =
EA's canvas includes non-uniform frame insets around the element content. Reverse-engineered from reference SVG byte-diff: maintenance diagram has element 169x80 at logical (0,0), ref canvas is 254x177 with element at (35, 40). So:
canvas_width = element_width + INSET_LEFT + INSET_RIGHT canvas_height = element_height + INSET_TOP + INSET_BOTTOMThe top inset accommodates the frame tab + label space above the element.
35- INSET_RIGHT =
50- INSET_TOP =
40- INSET_BOTTOM =
57
Instance Attribute Summary collapse
-
#diagram ⇒ Object
readonly
Returns the value of attribute diagram.
-
#model_index ⇒ Object
readonly
Returns the value of attribute model_index.
Instance Method Summary collapse
- #compute ⇒ Object
-
#initialize(diagram, model_index: nil) ⇒ BoundsCalculator
constructor
A new instance of BoundsCalculator.
Constructor Details
#initialize(diagram, model_index: nil) ⇒ BoundsCalculator
Returns a new instance of BoundsCalculator.
41 42 43 44 |
# File 'lib/ea/svg/ea_emitter/bounds_calculator.rb', line 41 def initialize(diagram, model_index: nil) @diagram = diagram @model_index = model_index end |
Instance Attribute Details
#diagram ⇒ Object (readonly)
Returns the value of attribute diagram.
39 40 41 |
# File 'lib/ea/svg/ea_emitter/bounds_calculator.rb', line 39 def diagram @diagram end |
#model_index ⇒ Object (readonly)
Returns the value of attribute model_index.
39 40 41 |
# File 'lib/ea/svg/ea_emitter/bounds_calculator.rb', line 39 def model_index @model_index end |
Instance Method Details
#compute ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ea/svg/ea_emitter/bounds_calculator.rb', line 46 def compute points = [] points.concat(element_points) points.concat(connector_points) points.concat(marker_points) points.concat(package_tab_points) return [0, 0, 1, 1] if points.empty? xs = points.map(&:first) ys = points.map(&:last) min_x = xs.min || 0 min_y = ys.min || 0 [ min_x, min_y, (xs.max - min_x) + INSET_LEFT + INSET_RIGHT, (ys.max - min_y) + INSET_TOP + INSET_BOTTOM ] end |