class SvgDrawer::Row
Public Instance Methods
add_cell(cell)
click to toggle source
# File lib/svg_drawer/table/row.rb, line 42 def add_cell(cell) raise TypeError, "Expected Cell, got: #{cell.class}" unless cell.is_a?(Cell) cell.update_params!(inherited: cell_params) cells << cell self end
cell(params = {}) { |cell| ... }
click to toggle source
@param params [Hash] cell params. @return [Row] self
# File lib/svg_drawer/table/row.rb, line 53 def cell(params = {}) raise 'Cannot add more cells' unless incomplete cell = Cell.new(params.merge(inherited: cell_params)) yield(cell) cells << cell self end
cell_heights()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 29 def cell_heights ensure_complete! cells.map(&:height) end
cell_widths()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 24 def cell_widths ensure_complete! cells.map(&:width) end
cells()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 38 def cells @cells ||= [] end
circle_cell(center, radius, params = {})
click to toggle source
# File lib/svg_drawer/table/row.rb, line 81 def circle_cell(center, radius, params = {}) cell(params) { |c| c.circle(center, radius) } end
col_widths()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 34 def col_widths Table.col_widths(param(:col_widths), param(:width), param(:columns)) end
height()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 15 def height ensure_complete! [param(:height, 0), cell_heights.max].max end
image_cell(href, params = {})
click to toggle source
# File lib/svg_drawer/table/row.rb, line 85 def image_cell(href, params = {}) cell(params) { |c| c.image(href) } end
incomplete()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 20 def incomplete cells.size != param(:columns) ? self : find_incomplete_descendant end
line_cell(points, params = {})
click to toggle source
# File lib/svg_drawer/table/row.rb, line 69 def line_cell(points, params = {}) cell(params) { |c| c.line(points) } end
multipolyline_cell(strokes, params = {})
click to toggle source
# File lib/svg_drawer/table/row.rb, line 77 def multipolyline_cell(strokes, params = {}) cell(params) { |c| c.multipolyline(strokes) } end
path_cell(path_components, params = {})
click to toggle source
# File lib/svg_drawer/table/row.rb, line 65 def path_cell(path_components, params = {}) cell(params) { |c| c.path(path_components) } end
polyline_cell(points, params = {})
click to toggle source
# File lib/svg_drawer/table/row.rb, line 73 def polyline_cell(points, params = {}) cell(params) { |c| c.polyline(points) } end
text_cell(text, params = {})
click to toggle source
# File lib/svg_drawer/table/row.rb, line 61 def text_cell(text, params = {}) cell(params) { |c| c.text_box(text) } end
width()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 9 def width ensure_complete! sum_width = cell_widths.reduce(&:+) [param(:width, 0), sum_width].max end
Private Instance Methods
_draw(parent, max_col_widths)
click to toggle source
A note on cell widths: Cells are drawed not with their initial widths, but with the table-wide maximum width for the corresponding columns. This must happen at draw time, as we can't know what the max col width is until we have added all rows for the entire table.
Similarly, for the heights: Cells are not drawed with their initial heigths, but with the row-wide maximum height. This must happen at draw time, as we can't know what the max cell height is until we have added all cells for this row.
@param parent [Rasem::SVGTagWithParent] @param col_widths
[Array] Table-wide max column widths @return [Rasem::SVGTagWithParent]
# File lib/svg_drawer/table/row.rb, line 108 def _draw(parent, max_col_widths) Utils::RasemWrapper.group(parent, class: param(:class), id: param(:id)) do |row_group| draw_border(row_group, width_override: max_col_widths.reduce(&:+)) cells.zip(max_col_widths).reduce(0) do |x, (cell, col_width)| cell.draw(row_group, debug: @debug).translate(x, 0) x + col_width end end end
cell_params()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 119 def cell_params return child_params unless col_widths && col_widths[cells.size] child_params.merge(width: col_widths[cells.size]) end
find_incomplete_descendant()
click to toggle source
# File lib/svg_drawer/table/row.rb, line 124 def find_incomplete_descendant cells.each.with_object(nil) do |cell, _| res = cell.incomplete break res if res end end