Class: AsciidoctorDiagramLayout::Renderer::SvgRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor_diagram_layout/renderer/svg_renderer.rb

Overview

Renders a layout node tree to SVG.

Each cell produces a <rect> with a linear gradient fill and centered bold text.

Constant Summary collapse

DEFAULT_WIDTH =

:nodoc:

600
DEFAULT_HEIGHT =

:nodoc:

300
FONT_SIZE =

:nodoc:

14

Instance Method Summary collapse

Instance Method Details

#render(root, options = RenderOptions.new) ⇒ String

Returns SVG document.

Parameters:

Returns:

  • (String)

    SVG document



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/asciidoctor_diagram_layout/renderer/svg_renderer.rb', line 17

def render(root, options = RenderOptions.new)
  w = parse_px(options.width,  DEFAULT_WIDTH)
  h = parse_px(options.height, DEFAULT_HEIGHT)
  defs = +""
  body = +""
  render_node(root, defs, body, options.color_scheme, 0, 0, w, h)
  sb = +""
  sb << "<svg xmlns=\"http://www.w3.org/2000/svg\""
  sb << " width=\"#{w}\""
  sb << " height=\"#{h}\""
  sb << " style=\"font-family:sans-serif;\""
  sb << ">\n"
  if options.title && !options.title.empty?
    sb << "  <title>#{escape_xml(options.title)}</title>\n"
  end
  if defs.length > 0
    sb << "  <defs>\n" << defs << "  </defs>\n"
  end
  sb << body
  sb << "</svg>\n"
  sb
end