class Thinreports::SectionReport::Renderer::StackViewRenderer

Constants

RowLayout

Attributes

pdf[R]
row_renderer[R]

Public Class Methods

new(pdf) click to toggle source
# File lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb, line 9
def initialize(pdf)
  @pdf = pdf
  @row_renderer = Renderer::StackViewRowRenderer.new(pdf)
end

Public Instance Methods

render(shape) click to toggle source
# File lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb, line 27
def render(shape)
  doc = pdf.pdf

  x, y, w = shape.format.attributes.values_at('x', 'y', 'width')
  doc.bounding_box([x, doc.bounds.height - y], width: w, height: section_height(shape)) do
    shape.rows.each do |row|
      row_renderer.render(row)
    end
  end
end
section_height(shape) click to toggle source
# File lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb, line 16
def section_height(shape)
  row_layouts = build_row_layouts(shape.rows)

  total_row_height = row_layouts.sum(0, &:height)
  float_content_bottom = row_layouts
    .map { |l| row_renderer.calc_float_content_bottom(l.row) + l.top }
    .max.to_f

  [total_row_height, float_content_bottom].max
end

Private Instance Methods

build_row_layouts(rows) click to toggle source
# File lib/thinreports/section_report/pdf/renderer/stack_view_renderer.rb, line 42
def build_row_layouts(rows)
  row_layouts = rows.map { |row| RowLayout.new(row, row_renderer.section_height(row)) }

  row_layouts.inject(0) do |top, row_layout|
    row_layout.top = top
    top + row_layout.height
  end

  row_layouts
end