Class: Mach5::Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/mach5-tools/chart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Chart

Returns a new instance of Chart.



13
14
15
# File 'lib/mach5-tools/chart.rb', line 13

def initialize(id)
  @id = id
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



10
11
12
# File 'lib/mach5-tools/chart.rb', line 10

def config
  @config
end

#data_typeObject

Returns the value of attribute data_type.



4
5
6
# File 'lib/mach5-tools/chart.rb', line 4

def data_type
  @data_type
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/mach5-tools/chart.rb', line 11

def id
  @id
end

#seriesObject

Returns the value of attribute series.



9
10
11
# File 'lib/mach5-tools/chart.rb', line 9

def series
  @series
end

#sizeObject

Returns the value of attribute size.



5
6
7
# File 'lib/mach5-tools/chart.rb', line 5

def size
  @size
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/mach5-tools/chart.rb', line 6

def title
  @title
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/mach5-tools/chart.rb', line 3

def type
  @type
end

#x_axisObject

Returns the value of attribute x_axis.



7
8
9
# File 'lib/mach5-tools/chart.rb', line 7

def x_axis
  @x_axis
end

#y_axisObject

Returns the value of attribute y_axis.



8
9
10
# File 'lib/mach5-tools/chart.rb', line 8

def y_axis
  @y_axis
end

Instance Method Details

#_series(series) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mach5-tools/chart.rb', line 44

def _series(series)
  result = []
  series.each do |s|
    commit_id = @config.benchmarks.tagged[s[:commit_id]]
    unless commit_id
      commit_id = s[:commit_id]
    end
    serie = {
      "label" => "#{s[:commit_id]}.#{s[:benchmark_id]}",
      "file" =>  File.join(Dir.pwd, @config.output_folder, "#{commit_id}.#{s[:benchmark_id]}.json")
    }
    serie["label"] = s[:label] if s[:label]
    serie["color"] = s[:color] if s[:color]
    result << serie
  end
  result
end

#buildObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mach5-tools/chart.rb', line 17

def build
  hash = {
    "type" => @type,
    "dataType" => @data_type,
    "size" => {
      "width" => size.split("x").map(&:to_i)[0],
      "height" => size.split("x").map(&:to_i)[1]
    },
    "title" => {
      "text" => @title
    },
    "xAxis" => {
      "title" => {
        "text" => @x_axis[:label]
      }
    },
    "yAxis" => {
      "title" => {
        "text" => @y_axis
      }
    },
    "series" => _series(@series)
  }
  hash["xAxis"]["categories"] = @x_axis[:categories] if @x_axis[:categories]
  hash
end