8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/predictability_engine/report/image_generator.rb', line 8
def self.generate(report, base_dir, width: 800, height: 600, scale: 1)
images_path = File.join(base_dir, 'images')
FileUtils.mkdir_p(images_path)
temp_html = "tmp/images_#{report.object_id}.html"
File.write(temp_html, report.render_html(layout: :standard))
require 'playwright'
Playwright.create(playwright_cli_executable_path: report.playwright_bin) do |playwright|
playwright.chromium.launch(**report.playwright_chromium_launch_opts) do |browser|
page = browser.new_page(viewport: { width: width, height: height },
deviceScaleFactor: scale)
page.goto("file://#{File.expand_path(temp_html)}")
sleep 2
Constants::CHART_CONFIG.each_key { |id| capture_chart(page, id, images_path) }
end
end
images_path
ensure
FileUtils.rm_f(temp_html) if temp_html
end
|