Class: Marvi::Diagram::FlowchartRenderer

Inherits:
Object
  • Object
show all
Includes:
BoxDrawing
Defined in:
lib/marvi/diagram.rb

Overview

Renders ‘graph`/`flowchart` diagrams (TD/TB and LR/RL) as connected boxes.

Constant Summary collapse

BOX_GAP =

horizontal spacing between boxes in a TD layer

3
LAYER_GAP =

connector rows between TD layers

3
LR_BOX_GAP =

vertical spacing between boxes in an LR layer

1
LR_LAYER_GAP =

connector columns between LR layers

6

Constants included from BoxDrawing

BoxDrawing::BOX_HEIGHT

Instance Method Summary collapse

Methods included from BoxDrawing

#box_width, #draw_box

Constructor Details

#initialize(direction, lines, max_width) ⇒ FlowchartRenderer

Returns a new instance of FlowchartRenderer.



140
141
142
143
144
145
146
147
# File 'lib/marvi/diagram.rb', line 140

def initialize(direction, lines, max_width)
  @direction = direction
  @lines = lines
  @max_width = max_width
  @labels = {}
  @order = []
  @edges = []
end

Instance Method Details

#renderObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/marvi/diagram.rb', line 149

def render
  return nil unless parse
  return nil if @order.empty?

  layers = assign_layers
  return nil unless layers

  grid = horizontal? ? layout_lr(layers) : layout_td(layers)
  spans = grid.to_spans
  return nil if spans.empty?
  return nil if spans.any? { |line| Unicode::DisplayWidth.of(line.first.text) > @max_width }

  spans
end