Class: GitStats::StatsView::Charts::Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/git_stats/stats_view/charts/chart.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Chart

Returns a new instance of Chart.

Yields:

  • (_self)

Yield Parameters:


11
12
13
14
# File 'lib/git_stats/stats_view/charts/chart.rb', line 11

def initialize
  @chart = LazyHighCharts::HighChart.new('graph')
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object


7
8
9
# File 'lib/git_stats/stats_view/charts/chart.rb', line 7

def method_missing(name, *args, &block)
  @chart.send(name, *args, &block)
end

Instance Method Details

#column_hash_chart(params) ⇒ Object


28
29
30
31
32
33
34
# File 'lib/git_stats/stats_view/charts/chart.rb', line 28

def column_hash_chart(params)
  simple_column_chart(params.merge(
                          data_x: params[:data].keys,
                          data_y: params[:data].values
                      )
  )
end

#date_chart(params) ⇒ Object


36
37
38
39
# File 'lib/git_stats/stats_view/charts/chart.rb', line 36

def date_chart(params)
  common_options(params)
  series(date_series(name: params[:title], data: params[:data]))
end

#date_column_chart(params) ⇒ Object


49
50
51
52
53
54
55
56
57
# File 'lib/git_stats/stats_view/charts/chart.rb', line 49

def date_column_chart(params)
  common_options(params)
  series(date_series({name: params[:title], data: params[:data]}, false).merge(
    {
      type: 'column',
      dataGrouping: {units: [['day', [1]], ['week', [1]]], forced: true}
    }
  ))
end

#default_legendObject


59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/git_stats/stats_view/charts/chart.rb', line 59

def default_legend
  legend(
      enabled: true,
      layout: 'vertical',
      backgroundColor: '#FFFFFF',
      align: 'left',
      verticalAlign: 'top',
      x: 100,
      y: 70,
      floating: true,
      shadow: true
  )
end

#multi_date_chart(params) ⇒ Object


41
42
43
44
45
46
47
# File 'lib/git_stats/stats_view/charts/chart.rb', line 41

def multi_date_chart(params)
  common_options(params)
  default_legend
  params[:data].each do |s|
    series(date_series(s))
  end
end

#multiple_column_chart(params) ⇒ Object


21
22
23
24
25
26
# File 'lib/git_stats/stats_view/charts/chart.rb', line 21

def multiple_column_chart(params)
  column_chart(params)
  params[:data_y].each do |s|
    series(name: s[:name], data: s[:data])
  end
end

#no_legendObject


73
74
75
76
77
# File 'lib/git_stats/stats_view/charts/chart.rb', line 73

def no_legend
  legend(
      enabled: false
  )
end

#simple_column_chart(params) ⇒ Object


16
17
18
19
# File 'lib/git_stats/stats_view/charts/chart.rb', line 16

def simple_column_chart(params)
  column_chart(params)
  series(name: params[:title], data: params[:data_y])
end

#title(title) ⇒ Object


95
96
97
# File 'lib/git_stats/stats_view/charts/chart.rb', line 95

def title(title)
  @chart.title!(text: title)
end

#type(type) ⇒ Object


79
80
81
# File 'lib/git_stats/stats_view/charts/chart.rb', line 79

def type(type)
  @chart.chart!(type: type)
end

#x_categories(categories) ⇒ Object


83
84
85
# File 'lib/git_stats/stats_view/charts/chart.rb', line 83

def x_categories(categories)
  @chart.xAxis!(categories: categories)
end

#x_text(text) ⇒ Object


87
88
89
# File 'lib/git_stats/stats_view/charts/chart.rb', line 87

def x_text(text)
  @chart.xAxis!(title: {text: text})
end

#y_text(text) ⇒ Object


91
92
93
# File 'lib/git_stats/stats_view/charts/chart.rb', line 91

def y_text(text)
  @chart.yAxis!(title: {text: text})
end