class ChartJS::EventStream

Public Class Methods

new(path, chart) click to toggle source
# File lib/chart_js/chart/event_stream.rb, line 49
          def initialize(path, chart)
@push = nil
chart(chart)
                  path(path)
build(block) if block_given?
          end

Public Instance Methods

build(&block) click to toggle source
# File lib/chart_js/chart/event_stream.rb, line 56
def build(&block)
                    instance_eval(&block)
  self
end
chart(chart_obj = nil) click to toggle source
# File lib/chart_js/chart/event_stream.rb, line 44
def chart(chart_obj = nil)
  return @chart if chart_obj.nil?
  @chart = chart_obj
end
counter(dataset:, chart: @chart, counter: "counter") click to toggle source
# File lib/chart_js/chart/event_stream.rb, line 38
def counter(dataset:, chart: @chart, counter: "counter")
  str = ""
  str << "var #{counter} = 0;\n"
                    str << "source.onmessage = function(e) { #{counter} += 1 };\n"
end
path(value = nil) click to toggle source
# File lib/chart_js/chart/event_stream.rb, line 61
def path(value = nil)
        return @path if value.nil?
        @path = value
end
push(dataset: 0, chart: @chart, &block) click to toggle source
# File lib/chart_js/chart/event_stream.rb, line 19
def push(dataset: 0, chart: @chart, &block)
  @push = EventStreams.push(dataset: dataset, chart: @chart, &block)
end
raw(chart: @chart, str: nil, file: nil, without_source: true, update: true) click to toggle source

end

# File lib/chart_js/chart/event_stream.rb, line 28
def raw(chart: @chart, str: nil, file: nil, without_source: true, update: true)
  @raw = ""
  @raw = @raw + "source.onmessage = function(e) { json = JSON.parse(e.data);"
  return @raw if str.nil? and file.nil?
  @raw = @raw + str unless str.nil?
  @raw = @raw + File.readlines(file) unless file.nil?
  @rar = @raw + "#{chart}.update();" if update
  @raw = @raw + "};"
end
to_html(source: @path, chart: @chart) click to toggle source
# File lib/chart_js/chart/event_stream.rb, line 7
          def to_html(source: @path, chart: @chart)
                  str = ""
str << "<script>\n"
str << "var source = new EventSource('#{path}');\n"
str << "var json;\n"
str << @counter if @counter
str << @push.to_s if @push
            str << @pop     if @pop
str << @raw     if @raw
str << "</script>\n"
          end