Class: Wavefront::Response::Highcharts

Inherits:
Ruby
  • Object
show all
Includes:
JSON
Defined in:
lib/wavefront/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, options = {}) ⇒ Highcharts

Returns a new instance of Highcharts.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/wavefront/response.rb', line 86

def initialize(response, options={})
  super

  @response = JSON.parse(response)
 @highcharts = []
 self.timeseries.each do |series|
    # Highcharts expects the time in milliseconds since the epoch
    # And for some reason the first value tends to be BS
    # We also have to deal with missing (null/nil) data points.
    amended_data = Array.new
    next unless series['data'].size > 0
    series['data'][1..-1].each do |time_value_pair|
      if time_value_pair[0]
        time_value_pair[0] = time_value_pair[0] * 1000
      else
        time_value_pair[0] = "null"
      end
      amended_data << time_value_pair
    end
    @highcharts << { 'name' => series['label'],  'data' => amended_data }
  end
end

Instance Attribute Details

#highchartsObject (readonly)

Returns the value of attribute highcharts.



84
85
86
# File 'lib/wavefront/response.rb', line 84

def highcharts
  @highcharts
end

#optionsObject (readonly)

Returns the value of attribute options.



84
85
86
# File 'lib/wavefront/response.rb', line 84

def options
  @options
end

#responseObject (readonly)

Returns the value of attribute response.



84
85
86
# File 'lib/wavefront/response.rb', line 84

def response
  @response
end

Instance Method Details

#to_jsonObject



109
110
111
# File 'lib/wavefront/response.rb', line 109

def to_json
  @highcharts.to_json
end