Module: CxExtractor::Chart

Included in:
CxExtractor
Defined in:
lib/cx_extractor/chart.rb

Overview

make a chart for block_distribution

Instance Method Summary collapse

Instance Method Details

#cal_color(index) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/cx_extractor/chart.rb', line 17

def cal_color(index)
  if index % 2 > 0
    '#85AF99'
  else
    '#E5E5E5'
  end
end

#cal_labels(distribution) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cx_extractor/chart.rb', line 5

def cal_labels(distribution)
  labels = {}
  index_distribution_length = distribution.length
  [0, 1, 2, 4, 8].each do |i|
    v = index_distribution_length / (2**i)
    labels[v] = v.to_s
  end
  percentile_seventy_five = index_distribution_length * 3 / 4
  labels[percentile_seventy_five] = percentile_seventy_five.to_s
  labels
end

#chart(distribution, chart_points, filename = chart_file_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/cx_extractor/chart.rb', line 25

def chart(distribution, chart_points, filename = chart_file_name)
  g = Gruff::Line.new
  g.theme = chart_theme
  g.labels = cal_labels(distribution)
  chart_points.unshift 0
  gruff_line(g, chart_points, distribution)
  g.hide_legend = true
  g.minimum_value = 0
  g.write(filename)
end

#gruff_line(gruff, chart_points, distribution) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/cx_extractor/chart.rb', line 36

def gruff_line(gruff, chart_points, distribution)
  start_point = end_point = 0
  chart_points.each_with_index do |break_point, index|
    start_point = break_point
    end_point = chart_points[index + 1] || distribution.length - 1
    gruff.dataxy('line' + break_point.to_s,
                 (start_point..end_point).to_a,
                 distribution[start_point..end_point], cal_color(index))
  end
end