Module: Marvi::Diagram::BoxDrawing
- Included in:
- FlowchartRenderer, SequenceRenderer
- Defined in:
- lib/marvi/diagram.rb
Overview
Shared helpers for renderers that lay nodes out as labelled boxes.
Constant Summary collapse
- BOX_HEIGHT =
3
Instance Method Summary collapse
- #box_width(label) ⇒ Object
-
#draw_box(grid, top, left, label) ⇒ Object
Draws a three-line box with its top-left corner at (top, left).
Instance Method Details
#box_width(label) ⇒ Object
103 104 105 |
# File 'lib/marvi/diagram.rb', line 103 def box_width(label) Unicode::DisplayWidth.of(label) + 4 end |
#draw_box(grid, top, left, label) ⇒ Object
Draws a three-line box with its top-left corner at (top, left).
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/marvi/diagram.rb', line 108 def draw_box(grid, top, left, label) inner = Unicode::DisplayWidth.of(label) + 2 grid.set(top, left, "┌") grid.set(top, left + inner + 1, "┐") grid.set(top + 2, left, "└") grid.set(top + 2, left + inner + 1, "┘") (1..inner).each do |i| grid.set(top, left + i, "─") grid.set(top + 2, left + i, "─") end grid.set(top + 1, left, "│") grid.set(top + 1, left + inner + 1, "│") col = left + 2 label.each_char do |ch| grid.set(top + 1, col, ch) width = Unicode::DisplayWidth.of(ch) grid.set(top + 1, col + 1, WIDE_FILLER) if width == 2 col += width end end |