module Columbus3::FlotRenderer
make a track into a flot graph (speed and height)
Constants
- OUTPUT_FILENAME
Public Class Methods
show(hash)
click to toggle source
apply the ERB in html/flot.html.erb and save it in the current directory use filename if provided or the default OUTPUT_FILENAME
# File lib/columbus3/renderer/flot_renderer.rb, line 12 def self.show hash filename = hash[:filename] || OUTPUT_FILENAME files = hash[:files] || [] template = File.join(File.dirname(__FILE__), "/../../html/flot.html.erb") renderer = ERB.new(File.read(template)) # context: location of css and js + list of files to show bower_dir = File.join(File.dirname(__FILE__), "/../../../bower_components") @flot_js = [File.join(bower_dir, 'jquery/dist/jquery.min.js'), File.join(bower_dir, 'flot/jquery.flot.js'), File.join(bower_dir, 'flot/jquery.flot.resize.js'), File.join(bower_dir, 'flot/jquery.flot.time.js'), File.join(bower_dir, 'flot/jquery.flot.selection.js') ] @file = files[0] # TODO: manage the case of sidecar not existing @track_info = Sidecar.new @file @track_info.load # generate the output html = renderer.result(binding) # save it to file File.open(filename, "w") do |file| file << html end end
to_javascript_file(filename, force = false)
click to toggle source
make a v900 track into a graph layer cached to disk
# File lib/columbus3/renderer/flot_renderer.rb, line 42 def self.to_javascript_file filename, force = false target = to_javascript_filename filename if force or not File.exists? target track = V900Track.new filename: filename File.open(target, "w") do |file| id = Sanitizer::sanitize filename file.printf <<EOS min_time_#{id} = #{track.first.time.to_i * 1000};\n max_time_#{id} = #{track.last.time.to_i * 1000};\n speed_#{id} = #{track.range.each.map { |i| [track[i].time.to_i * 1000, track[i].speed] }};\n height_#{id} = #{track.range.each.map { |i|[track[i].time.to_i * 1000, track[i].height] }};\n EOS end end end
to_javascript_filename(filename)
click to toggle source
# File lib/columbus3/renderer/flot_renderer.rb, line 60 def self.to_javascript_filename filename filename + "_graph.js" end