mirror of https://github.com/tomgi/git_stats.git
[closes #16] days without commits are not ommited on date charts anymore
This commit is contained in:
parent
74761f8750
commit
b5da25d52c
|
@ -6,4 +6,19 @@ class Hash
|
|||
default = params[:default]
|
||||
inject(Array.new(min_size, default)) { |acc, (k, v)| acc[k] = v; acc }.map { |e| e || default }
|
||||
end
|
||||
|
||||
def fill_empty_days!(params = {:aggregated => false})
|
||||
return self if self.empty?
|
||||
|
||||
days_with_data = self.keys.map(&:to_date).sort.uniq
|
||||
prev = 0
|
||||
days_with_data.first.upto(days_with_data.last) do |day|
|
||||
if days_with_data.include? day
|
||||
prev = self[day]
|
||||
else
|
||||
self[day] = params[:aggregated] ? prev : 0
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
end
|
||||
|
|
|
@ -50,17 +50,17 @@ module GitStats
|
|||
|
||||
def files_count_by_date
|
||||
@files_count_each_day ||= Hash[commits.map { |commit|
|
||||
[commit.date, commit.files_count]
|
||||
}]
|
||||
[commit.date.to_date, commit.files_count]
|
||||
}].fill_empty_days!(aggregated: true)
|
||||
end
|
||||
|
||||
def lines_count_by_date
|
||||
sum = 0
|
||||
Hash[commits.map { |commit|
|
||||
@lines_count_each_day ||= Hash[commits.map { |commit|
|
||||
sum += commit.short_stat.insertions
|
||||
sum -= commit.short_stat.deletions
|
||||
[commit.date, sum]
|
||||
}]
|
||||
[commit.date.to_date, sum]
|
||||
}].fill_empty_days!(aggregated: true)
|
||||
end
|
||||
|
||||
def last_commit
|
||||
|
|
|
@ -104,7 +104,7 @@ module GitStats
|
|||
series(
|
||||
name: params[:name],
|
||||
type: "spline",
|
||||
data: params[:data].map { |date, value| [date.to_i * 1000, value] }
|
||||
data: Hash[params[:data]].fill_empty_days!.map { |date, value| [date.to_datetime.to_i * 1000, value] }.sort_by { |d| d[0] }
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -113,6 +113,7 @@ module GitStats
|
|||
type "column"
|
||||
x_categories params[:data_x]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue