class Nyaplot::Plot
Constants
- SVG_CLOSE
- SVG_HEADER
- TEMP_NAME
Public Instance Methods
export_contents(name=SecureRandom.uuid.to_s + ".svg")
click to toggle source
Export context of plot as SVG @param [String] name the name of svg file to export
# File lib/nyaplot/export_svg.rb, line 35 def export_contents(name=SecureRandom.uuid.to_s + ".svg") html = get_nodes contents = Nokogiri::HTML.parse(html).at('.context_child').to_s str = SVG_HEADER + contents + SVG_CLOSE path = File.expand_path("./" + name, Dir.pwd) File.write(path, str) end
export_svg(name=SecureRandom.uuid.to_s + ".svg")
click to toggle source
Export plot as SVG @param [String] name the name of svg file to export
# File lib/nyaplot/export_svg.rb, line 26 def export_svg(name=SecureRandom.uuid.to_s + ".svg") html = get_nodes str = Nokogiri::HTML.parse(html).xpath('//svg').to_s path = File.expand_path("./" + name, Dir.pwd) File.write(path, str) end
get_nodes()
click to toggle source
Get html nodes created by JavaScript with browsers @return [String] built html
# File lib/nyaplot/export_svg.rb, line 13 def get_nodes require 'watir' self.export_html(TEMP_NAME) path = File.expand_path("./" + TEMP_NAME, Dir.pwd) browser = Watir::Browser.start("file://" + path) html = browser.html browser.close FileUtils.rm_r(path) return html end