i18n in charts

This commit is contained in:
Tomasz Gieniusz 2012-10-20 11:08:03 +02:00
parent 89c27a666e
commit af3d93aab9
5 changed files with 53 additions and 28 deletions

View file

@ -7,4 +7,12 @@ en:
total_files: Total files total_files: Total files
total_lines: Total lines total_lines: Total lines
total_commits: Total commits total_commits: Total commits
authors: Authors authors: Authors
commits: Commits
commits_by_hour: Commits by hour
files: Files
lines: Lines
files_by_date: Files by date
lines_by_date: Lines by date
files_by_extension: Files by extension
lines_by_extension: Lines by extension

View file

@ -8,11 +8,12 @@ module GitStats
def activity_by_hour def activity_by_hour
Chart.new do |f| Chart.new do |f|
f.type "column" f.simple_column_chart(
f.title "Commits" title: :commits_by_hour.t,
f.x_categories (0..23) y_text: :commits.t,
f.y_text 'Commits' data_x: (0..23),
f.series(name: "commits", data: @activity.by_hour.to_key_indexed_array) data_y: @activity.by_hour.to_key_indexed_array
)
end end
end end
end end

View file

@ -7,16 +7,14 @@ module GitStats
end end
def by_authors_wday def by_authors_wday
Chart.new do |c| Chart.new do |f|
c.type "column" f.multiple_column_chart(
c.title 'by_wday_authors' title: :by_authors_wday.t,
c.x_categories Date::ABBR_DAYNAMES y_text: :commits.t,
c.y_text 'y_text' data_x: Date::ABBR_DAYNAMES,
c.default_legend data_y: @authors.map { |author| {name: author.email, data: author.activity.by_wday.to_key_indexed_array} }
)
@authors.each do |author| f.default_legend
c.series(name: author.email, data: author.activity.by_wday.to_key_indexed_array)
end
end end
end end
end end

View file

@ -12,11 +12,24 @@ module GitStats
yield self if block_given? yield self if block_given?
end end
def simple_column_chart(params)
column_chart(params)
series(name: params[:title], data: params[:data_y])
end
def multiple_column_chart(params)
column_chart(params)
params[:data_y].each do |s|
series(name: s[:name], data: s[:data])
end
end
def column_hash_chart(params) def column_hash_chart(params)
common_params(params) simple_column_chart(params.merge(
type "column" data_x: params[:data].keys,
x_categories params[:data].keys data_y: params[:data].values
series(name: params[:title], data: params[:data].values) )
)
end end
def day_chart(params) def day_chart(params)
@ -66,6 +79,11 @@ module GitStats
y_text params[:y_text] y_text params[:y_text]
end end
def column_chart(params)
common_params(params)
type "column"
x_categories params[:data_x]
end
end end
end end
end end

View file

@ -10,8 +10,8 @@ module GitStats
Chart.new do |f| Chart.new do |f|
f.column_hash_chart( f.column_hash_chart(
data: @repo.files_by_extension_count, data: @repo.files_by_extension_count,
title: "files_by_extension", title: :files_by_extension.t,
y_text: "files" y_text: :files.t
) )
end end
end end
@ -20,8 +20,8 @@ module GitStats
Chart.new do |f| Chart.new do |f|
f.column_hash_chart( f.column_hash_chart(
data: @repo.lines_by_extension, data: @repo.lines_by_extension,
title: "lines_by_extension", title: :lines_by_extension.t,
y_text: "lines" y_text: :lines.t
) )
end end
end end
@ -31,8 +31,8 @@ module GitStats
f.day_chart( f.day_chart(
data: @repo.files_count_each_day, data: @repo.files_count_each_day,
start_day: @repo.commits.first.date, start_day: @repo.commits.first.date,
title: "files_by_date", title: :files_by_date.t,
y_text: "files" y_text: :files.t
) )
end end
end end
@ -42,8 +42,8 @@ module GitStats
f.day_chart( f.day_chart(
data: @repo.lines_count_each_day, data: @repo.lines_count_each_day,
start_day: @repo.commits.first.date, start_day: @repo.commits.first.date,
title: "lines_by_date", title: :lines_by_date.t,
y_text: "lines" y_text: :lines.t
) )
end end
end end