@@ -9,16 +9,16 @@ def global_options
99 end
1010
1111 def build_annual_dojos ( source , lang = 'ja' )
12- data = annual_chart_data_from ( source )
12+ data = annual_dojos_chart_data_from ( source )
1313 title_text = lang == 'en' ? 'Number of Dojos' : '道場数の推移'
1414
1515 LazyHighCharts ::HighChart . new ( 'graph' ) do |f |
1616 f . title ( text : title_text )
1717 f . xAxis ( categories : data [ :years ] )
18- f . series ( type : 'column' , name : lang == 'en' ? 'New' : '増加数 ' , yAxis : 0 , data : data [ :increase_nums ] )
18+ f . series ( type : 'column' , name : lang == 'en' ? 'New Dojos ' : '開設数 ' , yAxis : 0 , data : data [ :increase_nums ] )
1919 f . series ( type : 'line' , name : lang == 'en' ? 'Total' : '累積合計' , yAxis : 1 , data : data [ :cumulative_sums ] )
2020 f . yAxis [
21- { title : { text : lang == 'en' ? 'New' : '増加数 ' } , tickInterval : 15 , max : 75 } ,
21+ { title : { text : lang == 'en' ? 'New Dojos ' : '開設数 ' } , tickInterval : 15 , max : 75 } ,
2222 { title : { text : lang == 'en' ? 'Total' : '累積合計' } , tickInterval : 50 , max : 250 , opposite : true }
2323 ]
2424 f . chart ( width : HIGH_CHARTS_WIDTH , alignTicks : false )
@@ -71,14 +71,44 @@ def annual_chart_data_from(source)
7171 years = source_array . map ( &:first )
7272 counts = source_array . map ( &:last )
7373
74- # 増加数を計算(前年との差分)
75- increase_nums = counts . each_with_index . map do |count , i |
76- i == 0 ? count : count - counts [ i - 1 ]
77- end
74+ # 年間の値として扱う(イベント回数や参加者数用)
75+ increase_nums = counts
7876
79- # annual_dojos_with_historical_dataからの値は既にその時点での総数
80- # (累積値として扱う)
81- cumulative_sums = counts
77+ # 累積合計を計算
78+ cumulative_sums = counts . size . times . map { |i | counts [ 0 ..i ] . sum }
79+
80+ {
81+ years : years ,
82+ increase_nums : increase_nums ,
83+ cumulative_sums : cumulative_sums
84+ }
85+ end
86+
87+ # 道場数の推移用の特別なデータ処理
88+ # 新規開設数と累積数を表示
89+ def annual_dojos_chart_data_from ( source )
90+ # sourceが新しい形式(active_dojosとnew_dojosを含む)の場合
91+ if source . is_a? ( Hash ) && source . key? ( :active_dojos ) && source . key? ( :new_dojos )
92+ active_array = source [ :active_dojos ] . to_a
93+ new_array = source [ :new_dojos ] . to_a
94+
95+ years = active_array . map ( &:first )
96+ cumulative_sums = active_array . map ( &:last )
97+ increase_nums = new_array . map ( &:last ) # 新規開設数を使用
98+ else
99+ # 後方互換性のため、古い形式もサポート
100+ source_array = source . is_a? ( Hash ) ? source . to_a : source
101+
102+ years = source_array . map ( &:first )
103+ counts = source_array . map ( &:last )
104+
105+ # 増減数を計算(前年との差分)- 後方互換性のため
106+ increase_nums = counts . each_with_index . map do |count , i |
107+ i == 0 ? count : count - counts [ i - 1 ]
108+ end
109+
110+ cumulative_sums = counts
111+ end
82112
83113 {
84114 years : years ,
0 commit comments