class Vifi

Constants

VERSION

Public Class Methods

version() click to toggle source
# File lib/vifi/version.rb, line 4
def self.version
  VERSION
end

Public Instance Methods

build_chart() click to toggle source
# File lib/vifi.rb, line 7
def build_chart
  chart = ChartJS.line do
    data do
      labels []
      dataset WillowRun::Status.new.getinfo.ssid do
        color :random
        data []
      end
    end
  end
  chart.to_html
end
build_updater(source: '/update_source', chart_obj: 'line_chart') click to toggle source
# File lib/vifi.rb, line 20
def build_updater(source: '/update_source', chart_obj: 'line_chart')
  # why not
  "<script>
    var source = new EventSource('#{source}');
    var json;
    source.onmessage = function(e) { 
      json = JSON.parse(e.data);
  #{chart_obj}.data.datasets[0].data.push(json.value);
  #{chart_obj}.data.labels.push(json.label);
  #{chart_obj}.update();
    };
  </script>
  "
end