mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
highstock date chart
This commit is contained in:
parent
99921c44ea
commit
4a590ddd40
13 changed files with 75 additions and 73 deletions
2
Gemfile
2
Gemfile
|
@ -2,3 +2,5 @@ source 'https://rubygems.org'
|
|||
|
||||
# Specify your gem's dependencies in git_stats.gemspec
|
||||
gemspec
|
||||
|
||||
gem 'lazy_high_charts', git: 'git://github.com/tomgi/lazy_high_charts.git', branch: 'deep_merge'
|
|
@ -15,4 +15,6 @@ en:
|
|||
files_by_date: Files by date
|
||||
lines_by_date: Lines by date
|
||||
files_by_extension: Files by extension
|
||||
lines_by_extension: Lines by extension
|
||||
lines_by_extension: Lines by extension
|
||||
hour_of_day: Hour of day
|
||||
hour: Hour
|
|
@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
|
|||
gem.add_dependency('tilt')
|
||||
gem.add_dependency('haml')
|
||||
gem.add_dependency('launchy')
|
||||
gem.add_dependency('lazy_high_charts')
|
||||
#gem.add_dependency('lazy_high_charts')
|
||||
gem.add_dependency('i18n')
|
||||
|
||||
gem.add_development_dependency('rake')
|
||||
|
|
|
@ -6,7 +6,10 @@ require 'action_pack'
|
|||
require 'action_view'
|
||||
require 'fileutils'
|
||||
require 'tilt'
|
||||
require 'lazy_high_charts'
|
||||
#require 'lazy_high_charts'
|
||||
require 'launchy'
|
||||
require 'i18n'
|
||||
|
||||
require 'bundler'
|
||||
Bundler.require(:default)
|
||||
Dir['lib/**/*.rb'].each { |r| require File.expand_path(r) }
|
|
@ -45,28 +45,16 @@ module GitStats
|
|||
Hash[authors.map { |author| [author, author.lines_deleted] }]
|
||||
end
|
||||
|
||||
def files_count_each_day
|
||||
@files_count_each_day ||= commits_period_range.map { |day|
|
||||
files_count_at day
|
||||
}
|
||||
def files_count_by_date
|
||||
@files_count_each_day ||= Hash[commits.map { |commit|
|
||||
[commit.date, commit.files_count]
|
||||
}]
|
||||
end
|
||||
|
||||
def files_count_at(day)
|
||||
last_commit_at(day).try(:files_count) || 0
|
||||
end
|
||||
|
||||
def lines_count_each_day
|
||||
@lines_count_each_day ||= commits_period_range.map { |day|
|
||||
lines_count_at day
|
||||
}
|
||||
end
|
||||
|
||||
def lines_count_at(day)
|
||||
last_commit_at(day).try(:lines_count) || 0
|
||||
end
|
||||
|
||||
def last_commit_at(day)
|
||||
commits.reverse.find { |c| c.date < day }
|
||||
def lines_count_by_date
|
||||
@lines_count_each_day ||= Hash[commits.map { |commit|
|
||||
[commit.date, commit.lines_count]
|
||||
}]
|
||||
end
|
||||
|
||||
def last_commit
|
||||
|
@ -138,11 +126,6 @@ module GitStats
|
|||
command_observers.each { |o| o.call(command, result) }
|
||||
end
|
||||
|
||||
def commits_period_range
|
||||
period = commits_period.map(&:midnight)
|
||||
period.first.upto (period.last + 1.day)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,6 +11,7 @@ module GitStats
|
|||
f.simple_column_chart(
|
||||
title: :commits_by_hour.t,
|
||||
y_text: :commits.t,
|
||||
x_text: :hour.t,
|
||||
data_x: (0..23),
|
||||
data_y: @activity.by_hour.to_key_indexed_array
|
||||
)
|
||||
|
|
|
@ -26,21 +26,19 @@ module GitStats
|
|||
|
||||
def column_hash_chart(params)
|
||||
simple_column_chart(params.merge(
|
||||
data_x: params[:data].keys,
|
||||
data_y: params[:data].values
|
||||
)
|
||||
data_x: params[:data].keys,
|
||||
data_y: params[:data].values
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def day_chart(params)
|
||||
common_params(params)
|
||||
xAxis(type: "datetime")
|
||||
def date_chart(params)
|
||||
common_options(params)
|
||||
rangeSelector(selected: 1)
|
||||
series(
|
||||
type: "area",
|
||||
name: "commits",
|
||||
pointInterval: 1.day * 1000,
|
||||
pointStart: params[:start_day].to_i * 1000,
|
||||
data: params[:data]
|
||||
name: params[:title],
|
||||
type: "spline",
|
||||
data: params[:data].map {|date, value| [date.to_i * 1000, value]}
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -57,30 +55,42 @@ module GitStats
|
|||
)
|
||||
end
|
||||
|
||||
def no_legend
|
||||
legend(
|
||||
enabled: false
|
||||
)
|
||||
end
|
||||
|
||||
def type(type)
|
||||
@chart.chart(type: type)
|
||||
@chart.chart!(type: type)
|
||||
end
|
||||
|
||||
def x_categories(categories)
|
||||
@chart.xAxis(categories: categories)
|
||||
@chart.xAxis!(categories: categories)
|
||||
end
|
||||
|
||||
def x_text(text)
|
||||
@chart.xAxis!(title: {text: text})
|
||||
end
|
||||
|
||||
def y_text(text)
|
||||
@chart.yAxis(min: 0, title: {text: text})
|
||||
@chart.yAxis!(title: {text: text})
|
||||
end
|
||||
|
||||
def title(title)
|
||||
@chart.title(text: title)
|
||||
@chart.title!(text: title)
|
||||
end
|
||||
|
||||
private
|
||||
def common_params(params)
|
||||
title params[:title]
|
||||
def common_options(params)
|
||||
no_legend
|
||||
title ""
|
||||
y_text params[:y_text]
|
||||
x_text params[:x_text]
|
||||
end
|
||||
|
||||
def column_chart(params)
|
||||
common_params(params)
|
||||
common_options(params)
|
||||
type "column"
|
||||
x_categories params[:data_x]
|
||||
end
|
||||
|
|
|
@ -28,9 +28,8 @@ module GitStats
|
|||
|
||||
def files_by_date
|
||||
Chart.new do |f|
|
||||
f.day_chart(
|
||||
data: @repo.files_count_each_day,
|
||||
start_day: @repo.commits.first.date,
|
||||
f.date_chart(
|
||||
data: @repo.files_count_by_date,
|
||||
title: :files_by_date.t,
|
||||
y_text: :files.t
|
||||
)
|
||||
|
@ -39,9 +38,8 @@ module GitStats
|
|||
|
||||
def lines_by_date
|
||||
Chart.new do |f|
|
||||
f.day_chart(
|
||||
data: @repo.lines_count_each_day,
|
||||
start_day: @repo.commits.first.date,
|
||||
f.date_chart(
|
||||
data: @repo.lines_count_by_date,
|
||||
title: :lines_by_date.t,
|
||||
y_text: :lines.t
|
||||
)
|
||||
|
|
|
@ -2,6 +2,18 @@ require 'spec_helper'
|
|||
|
||||
describe GitStats::GitData::Repo do
|
||||
let(:repo) { build(:test_repo, last_commit_sha: '872955c') }
|
||||
let(:commit_dates) { [
|
||||
DateTime.parse('2012-10-19 10:44:34 +0200'),
|
||||
DateTime.parse('2012-10-19 10:46:10 +0200'),
|
||||
DateTime.parse('2012-10-19 10:46:56 +0200'),
|
||||
DateTime.parse('2012-10-19 10:47:35 +0200'),
|
||||
DateTime.parse('2012-10-20 12:49:02 +0200'),
|
||||
DateTime.parse('2012-10-21 12:49:02 +0200'),
|
||||
DateTime.parse('2012-10-21 12:54:02 +0200'),
|
||||
DateTime.parse('2012-10-21 13:20:00 +0200'),
|
||||
DateTime.parse('2012-10-24 15:49:02 +0200'),
|
||||
DateTime.parse('2012-10-26 17:05:25 +0200'),
|
||||
] }
|
||||
|
||||
it 'should gather all authors' do
|
||||
repo.authors.should =~ [
|
||||
|
@ -31,11 +43,13 @@ describe GitStats::GitData::Repo do
|
|||
end
|
||||
|
||||
it 'should count files by date' do
|
||||
repo.files_count_each_day.should == [0, 3, 3, 5, 5, 5, 6, 6, 6]
|
||||
repo.files_count_by_date.keys.should == commit_dates
|
||||
repo.files_count_by_date.values.should == [1, 2, 2, 3, 3, 4, 5, 5, 6, 6]
|
||||
end
|
||||
|
||||
it 'should count lines by date' do
|
||||
repo.lines_count_each_day.should == [0, 11, 11, 1014, 1014, 1014, 1114, 1114, 1114]
|
||||
repo.lines_count_by_date.keys.should == commit_dates
|
||||
repo.files_count_by_date.values.should == [1, 2, 2, 3, 3, 4, 5, 5, 6, 6]
|
||||
end
|
||||
|
||||
it 'should count all lines in repo' do
|
||||
|
|
|
@ -7,13 +7,6 @@ shared_examples_for "column_chart" do
|
|||
end
|
||||
end
|
||||
|
||||
shared_examples_for "datetime_chart" do
|
||||
it 'should be a datetime chart' do
|
||||
chart.should be_a GitStats::StatsView::Charts::Chart
|
||||
chart.options[:xAxis][:type].should == "datetime"
|
||||
end
|
||||
end
|
||||
|
||||
describe GitStats::StatsView::Charts::RepoCharts do
|
||||
let(:charts) { GitStats::StatsView::Charts::All.new(repo) }
|
||||
|
||||
|
@ -44,28 +37,22 @@ describe GitStats::StatsView::Charts::RepoCharts do
|
|||
end
|
||||
|
||||
context 'files_by_date chart' do
|
||||
let(:repo) { double(commits: [double(date: 5)], files_count_each_day: [10, 15, 12, 20]) }
|
||||
let(:repo) { double(commits: [double(date: 5)], files_count_by_date: {1 => 10, 2 => 15, 3 => 12, 5 => 20}) }
|
||||
let(:chart) { charts.files_by_date }
|
||||
|
||||
it_behaves_like "datetime_chart"
|
||||
|
||||
it 'should have 1 data series with files_by_date' do
|
||||
chart.should have(1).data
|
||||
chart.data[0][:data].should == [10, 15, 12, 20]
|
||||
chart.data[0][:pointStart].should == 5000
|
||||
chart.data[0][:data].should == [[1000, 10], [2000, 15], [3000, 12], [5000, 20]]
|
||||
end
|
||||
end
|
||||
|
||||
context 'lines_by_date chart' do
|
||||
let(:repo) { double(commits: [double(date: 6)], lines_count_each_day: [100, 150, 120, 200]) }
|
||||
let(:repo) { double(commits: [double(date: 6)], lines_count_by_date: {1 => 100, 2 => 150, 3 => 120, 5 => 200}) }
|
||||
let(:chart) { charts.lines_by_date }
|
||||
|
||||
it_behaves_like "datetime_chart"
|
||||
|
||||
it 'should have 1 data series with lines_by_date' do
|
||||
chart.should have(1).data
|
||||
chart.data[0][:data].should == [100, 150, 120, 200]
|
||||
chart.data[0][:pointStart].should == 6000
|
||||
chart.data[0][:data].should == [[1000, 100], [2000, 150], [3000, 120], [5000, 200]]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
.page-header
|
||||
%h1.pagination-centered= :hour_of_day.t
|
||||
= high_chart("activity_by_hour", charts.activity_by_hour)
|
|
@ -1,2 +1,2 @@
|
|||
= high_chart("files_by_date", charts.files_by_date)
|
||||
= high_stock("files_by_date", charts.files_by_date)
|
||||
= high_chart("files_by_extension", charts.files_by_extension)
|
|
@ -1,2 +1,2 @@
|
|||
= high_chart("lines_by_date", charts.lines_by_date)
|
||||
= high_stock("lines_by_date", charts.lines_by_date)
|
||||
= high_chart("lines_by_extension", charts.lines_by_extension)
|
Loading…
Reference in a new issue