Class: PostgreSQLFlameGraphSVG

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_flamegraph_svg.rb

Instance Method Summary collapse

Constructor Details

#initialize(explain_json, width = 1200, height = 600) ⇒ PostgreSQLFlameGraphSVG

Returns a new instance of PostgreSQLFlameGraphSVG.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/pg_flamegraph_svg.rb', line 5

def initialize(explain_json, width = 1200, height = 600)
  @explain_data = JSON.parse(explain_json)
  @width = width
  @height = height
  @font_size = 20
  @min_width = 1
  @colors = [
    '#e74c3c', '#3498db', '#2ecc71', '#f39c12', '#9b59b6',
    '#1abc9c', '#e67e22', '#95a5a6', '#34495e', '#e91e63'
  ]
end

Instance Method Details

#generate_svgObject



17
18
19
20
21
22
23
24
25
# File 'lib/pg_flamegraph_svg.rb', line 17

def generate_svg
  plan = @explain_data[0]['Plan']

  # Calculate the layout
  flamegraph_data = build_flamegraph_data(plan)

  # Generate SVG
  generate_svg_content(flamegraph_data)
end