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:



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

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



32
33
34
35
36
37
# File 'lib/git_stats/stats_view/charts/chart.rb', line 32

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



39
40
41
42
# File 'lib/git_stats/stats_view/charts/chart.rb', line 39

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

#date_column_chart(params) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/git_stats/stats_view/charts/chart.rb', line 52

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

#default_legendObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/git_stats/stats_view/charts/chart.rb', line 62

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



44
45
46
47
48
49
50
# File 'lib/git_stats/stats_view/charts/chart.rb', line 44

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



25
26
27
28
29
30
# File 'lib/git_stats/stats_view/charts/chart.rb', line 25

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



76
77
78
79
80
# File 'lib/git_stats/stats_view/charts/chart.rb', line 76

def no_legend
  legend(
    enabled: false
  )
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(name, include_private = false)
  @chart.respond_to?(name, include_private)
end

#simple_column_chart(params) ⇒ Object



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

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

#title(title) ⇒ Object



98
99
100
# File 'lib/git_stats/stats_view/charts/chart.rb', line 98

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

#type(type) ⇒ Object



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

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

#x_categories(categories) ⇒ Object



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

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

#x_text(text) ⇒ Object



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

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

#y_text(text) ⇒ Object



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

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