Class: Prawn::Graph::Calculations::LayoutCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/graph/calculations/layout_calculator.rb

Defined Under Namespace

Classes: Dimensions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bounds, attributes = nil, theme = Prawn::Graph::Theme.default) ⇒ LayoutCalculator

Returns a new instance of LayoutCalculator.


19
20
21
22
23
24
25
26
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 19

def initialize(bounds, attributes = nil, theme = Prawn::Graph::Theme.default)
  @bounds = bounds
  @graph_area       = Dimensions.new({ width: 0, height: 0, x: 0, y: 0 })
  @title_area       = Dimensions.new({ width: 0, height: 0, x: 0, y: 0 })
  @series_key_area  = Dimensions.new({ width: 0, height: 0, x: 0, y: 0 })
  @theme            = theme
  set_from_attributes(attributes) if attributes
end

Instance Attribute Details

#boundsObject (readonly)

Returns the value of attribute bounds.


6
7
8
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 6

def bounds
  @bounds
end

#canvas_heightObject (readonly)

Returns the value of attribute canvas_height.


7
8
9
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 7

def canvas_height
  @canvas_height
end

#canvas_widthObject (readonly)

Returns the value of attribute canvas_width.


7
8
9
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 7

def canvas_width
  @canvas_width
end

#graph_areaObject (readonly)

Returns the value of attribute graph_area.


7
8
9
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 7

def graph_area
  @graph_area
end

#series_key_areaObject (readonly)

Returns the value of attribute series_key_area.


7
8
9
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 7

def series_key_area
  @series_key_area
end

#title_areaObject (readonly)

Returns the value of attribute title_area.


7
8
9
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 7

def title_area
  @title_area
end

Instance Method Details

#calculateObject


28
29
30
31
32
33
34
35
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 28

def calculate
  calculate_width_and_height_of_canvas
  calculate_key_area
  calculate_title_area
  calculate_graph_area
  
  self
end

#hpaddingObject


37
38
39
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 37

def hpadding
  ((BigDecimal(canvas_width) / 100) * 2).round
end

#invalid?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 45

def invalid?
  canvas_width > bounds[0] || canvas_height > bounds[1]
end

#vpaddingObject


41
42
43
# File 'lib/prawn/graph/calculations/layout_calculator.rb', line 41

def vpadding
  ((BigDecimal(canvas_height) / 100) * 2).round
end