Skip to content

Commit ad9fed4

Browse files
committed
Chart of event histories
1 parent 8fa12bf commit ad9fed4

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

app/controllers/static_pages_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def stats
3434
end
3535

3636
@annual_dojos_chart = HighChartsBuilder.build_annual_dojos
37+
@annual_event_histories_chart = HighChartsBuilder.build_annual_event_histories
3738
end
3839

3940
def letsencrypt

app/models/high_charts_builder.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ def build_annual_dojos
1818
end
1919
end
2020

21+
def build_annual_event_histories
22+
source = EventHistory.where('evented_at < ?', Time.current.beginning_of_year).group("DATE_TRUNC('year', evented_at)").count
23+
data = annual_chart_data_from(source)
24+
25+
LazyHighCharts::HighChart.new('graph') do |f|
26+
f.title(text: '開催回数の推移')
27+
f.xAxis(categories: data[:years])
28+
f.series(type: 'column', name: '開催回数', yAxis: 0, data: data[:increase_nums])
29+
f.series(type: 'line', name: '累積合計', yAxis: 1, data: data[:cumulative_sums])
30+
f.yAxis [
31+
{ title: { text: '開催回数' } },
32+
{ title: { text: '累積合計' }, opposite: true }
33+
]
34+
f.chart(width: 600)
35+
f.colors(["#8085e9", "#f7a35c"])
36+
end
37+
end
38+
2139
private
2240

2341
def annual_chart_data_from(source)

app/views/static_pages/stats.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
%td= @participants[year]
6262
%td= @participants.values.inject(:+)
6363
= high_chart("annual_dojos", @annual_dojos_chart)
64+
= high_chart("annual_event_histories", @annual_event_histories_chart)
6465

6566
%h3 関連リンク
6667
%ul{:style => "list-style: none; margin-left: -40px;"}

0 commit comments

Comments
 (0)