Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9f6660b1
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9f6660b1
编写于
2月 24, 2017
作者:
F
Filipa Lacerda
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'refactor-graphs-bundle' into 'master'
Refactor graphs bundle to ES module syntax See merge request !9502
上级
c49ee361
52426c65
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
507 addition
and
558 deletion
+507
-558
app/assets/javascripts/graphs/graphs_bundle.js
app/assets/javascripts/graphs/graphs_bundle.js
+4
-4
app/assets/javascripts/graphs/stat_graph.js
app/assets/javascripts/graphs/stat_graph.js
+0
-18
app/assets/javascripts/graphs/stat_graph_contributors.js
app/assets/javascripts/graphs/stat_graph_contributors.js
+98
-103
app/assets/javascripts/graphs/stat_graph_contributors_graph.js
...ssets/javascripts/graphs/stat_graph_contributors_graph.js
+269
-273
app/assets/javascripts/graphs/stat_graph_contributors_util.js
...assets/javascripts/graphs/stat_graph_contributors_util.js
+132
-133
spec/javascripts/graphs/stat_graph_contributors_graph_spec.js
.../javascripts/graphs/stat_graph_contributors_graph_spec.js
+3
-5
spec/javascripts/graphs/stat_graph_contributors_util_spec.js
spec/javascripts/graphs/stat_graph_contributors_util_spec.js
+1
-2
spec/javascripts/graphs/stat_graph_spec.js
spec/javascripts/graphs/stat_graph_spec.js
+0
-20
未找到文件。
app/assets/javascripts/graphs/graphs_bundle.js
浏览文件 @
9f6660b1
require
(
'
./stat_graph_contributors_graph
'
)
;
require
(
'
./stat_graph_contributors_util
'
);
require
(
'
./stat_graph_contributors
'
);
require
(
'
./stat_graph
'
)
;
import
ContributorsStatGraph
from
'
./stat_graph_contributors
'
;
// export to global scope
window
.
ContributorsStatGraph
=
ContributorsStatGraph
;
app/assets/javascripts/graphs/stat_graph.js
已删除
100644 → 0
浏览文件 @
c49ee361
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-return-assign, max-len */
(
function
()
{
this
.
StatGraph
=
(
function
()
{
function
StatGraph
()
{}
StatGraph
.
log
=
{};
StatGraph
.
get_log
=
function
()
{
return
this
.
log
;
};
StatGraph
.
set_log
=
function
(
data
)
{
return
this
.
log
=
data
;
};
return
StatGraph
;
})();
}).
call
(
window
);
app/assets/javascripts/graphs/stat_graph_contributors.js
浏览文件 @
9f6660b1
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, camelcase, one-var-declaration-per-line, quotes, no-param-reassign, quote-props, comma-dangle, prefer-template, max-len, no-return-assign */
/* global ContributorsGraph */
/* global ContributorsAuthorGraph */
/* global ContributorsMasterGraph */
/* global ContributorsStatGraphUtil */
/* global d3 */
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, camelcase, one-var-declaration-per-line, quotes, no-param-reassign, quote-props, comma-dangle, prefer-template, max-len, no-return-assign, no-shadow */
window
.
d3
=
require
(
'
d3
'
);
import
d3
from
'
d3
'
;
import
{
ContributorsGraph
,
ContributorsAuthorGraph
,
ContributorsMasterGraph
}
from
'
./stat_graph_contributors_graph
'
;
import
ContributorsStatGraphUtil
from
'
./stat_graph_contributors_util
'
;
(
function
()
{
this
.
ContributorsStatGraph
=
(
function
()
{
function
ContributorsStatGraph
()
{}
export
default
(
function
()
{
function
ContributorsStatGraph
()
{}
ContributorsStatGraph
.
prototype
.
init
=
function
(
log
)
{
var
author_commits
,
total_commits
;
this
.
parsed_log
=
ContributorsStatGraphUtil
.
parse_log
(
log
);
this
.
set_current_field
(
"
commits
"
);
total_commits
=
ContributorsStatGraphUtil
.
get_total_data
(
this
.
parsed_log
,
this
.
field
);
author_commits
=
ContributorsStatGraphUtil
.
get_author_data
(
this
.
parsed_log
,
this
.
field
);
this
.
add_master_graph
(
total_commits
);
this
.
add_authors_graph
(
author_commits
);
return
this
.
change_date_header
();
};
ContributorsStatGraph
.
prototype
.
init
=
function
(
log
)
{
var
author_commits
,
total_commits
;
this
.
parsed_log
=
ContributorsStatGraphUtil
.
parse_log
(
log
);
this
.
set_current_field
(
"
commits
"
);
total_commits
=
ContributorsStatGraphUtil
.
get_total_data
(
this
.
parsed_log
,
this
.
field
);
author_commits
=
ContributorsStatGraphUtil
.
get_author_data
(
this
.
parsed_log
,
this
.
field
);
this
.
add_master_graph
(
total_commits
);
this
.
add_authors_graph
(
author_commits
);
return
this
.
change_date_header
();
};
ContributorsStatGraph
.
prototype
.
add_master_graph
=
function
(
total_data
)
{
this
.
master_graph
=
new
ContributorsMasterGraph
(
total_data
);
return
this
.
master_graph
.
draw
();
};
ContributorsStatGraph
.
prototype
.
add_master_graph
=
function
(
total_data
)
{
this
.
master_graph
=
new
ContributorsMasterGraph
(
total_data
);
return
this
.
master_graph
.
draw
();
};
ContributorsStatGraph
.
prototype
.
add_authors_graph
=
function
(
author_data
)
{
var
limited_author_data
;
this
.
authors
=
[];
limited_author_data
=
author_data
.
slice
(
0
,
100
);
return
_
.
each
(
limited_author_data
,
(
function
(
_this
)
{
return
function
(
d
)
{
var
author_graph
,
author_header
;
author_header
=
_this
.
create_author_header
(
d
);
$
(
"
.contributors-list
"
).
append
(
author_header
);
_this
.
authors
[
d
.
author_name
]
=
author_graph
=
new
ContributorsAuthorGraph
(
d
.
dates
);
return
author_graph
.
draw
();
};
})(
this
));
};
ContributorsStatGraph
.
prototype
.
add_authors_graph
=
function
(
author_data
)
{
var
limited_author_data
;
this
.
authors
=
[];
limited_author_data
=
author_data
.
slice
(
0
,
100
);
return
_
.
each
(
limited_author_data
,
(
function
(
_this
)
{
return
function
(
d
)
{
var
author_graph
,
author_header
;
author_header
=
_this
.
create_author_header
(
d
);
$
(
"
.contributors-list
"
).
append
(
author_header
);
_this
.
authors
[
d
.
author_name
]
=
author_graph
=
new
ContributorsAuthorGraph
(
d
.
dates
);
return
author_graph
.
draw
();
};
})(
this
));
};
ContributorsStatGraph
.
prototype
.
format_author_commit_info
=
function
(
author
)
{
var
commits
;
commits
=
$
(
'
<span/>
'
,
{
"
class
"
:
'
graph-author-commits-count
'
});
commits
.
text
(
author
.
commits
+
"
commits
"
);
return
$
(
'
<span/>
'
).
append
(
commits
);
};
ContributorsStatGraph
.
prototype
.
format_author_commit_info
=
function
(
author
)
{
var
commits
;
commits
=
$
(
'
<span/>
'
,
{
"
class
"
:
'
graph-author-commits-count
'
});
commits
.
text
(
author
.
commits
+
"
commits
"
);
return
$
(
'
<span/>
'
).
append
(
commits
);
};
ContributorsStatGraph
.
prototype
.
create_author_header
=
function
(
author
)
{
var
author_commit_info
,
author_commit_info_span
,
author_email
,
author_name
,
list_item
;
list_item
=
$
(
'
<li/>
'
,
{
"
class
"
:
'
person
'
,
style
:
'
display: block;
'
});
author_name
=
$
(
'
<h4>
'
+
author
.
author_name
+
'
</h4>
'
);
author_email
=
$
(
'
<p class="graph-author-email">
'
+
author
.
author_email
+
'
</p>
'
);
author_commit_info_span
=
$
(
'
<span/>
'
,
{
"
class
"
:
'
commits
'
});
author_commit_info
=
this
.
format_author_commit_info
(
author
);
author_commit_info_span
.
html
(
author_commit_info
);
list_item
.
append
(
author_name
);
list_item
.
append
(
author_email
);
list_item
.
append
(
author_commit_info_span
);
return
list_item
;
};
ContributorsStatGraph
.
prototype
.
create_author_header
=
function
(
author
)
{
var
author_commit_info
,
author_commit_info_span
,
author_email
,
author_name
,
list_item
;
list_item
=
$
(
'
<li/>
'
,
{
"
class
"
:
'
person
'
,
style
:
'
display: block;
'
});
author_name
=
$
(
'
<h4>
'
+
author
.
author_name
+
'
</h4>
'
);
author_email
=
$
(
'
<p class="graph-author-email">
'
+
author
.
author_email
+
'
</p>
'
);
author_commit_info_span
=
$
(
'
<span/>
'
,
{
"
class
"
:
'
commits
'
});
author_commit_info
=
this
.
format_author_commit_info
(
author
);
author_commit_info_span
.
html
(
author_commit_info
);
list_item
.
append
(
author_name
);
list_item
.
append
(
author_email
);
list_item
.
append
(
author_commit_info_span
);
return
list_item
;
};
ContributorsStatGraph
.
prototype
.
redraw_master
=
function
()
{
var
total_data
;
total_data
=
ContributorsStatGraphUtil
.
get_total_data
(
this
.
parsed_log
,
this
.
field
);
this
.
master_graph
.
set_data
(
total_data
);
return
this
.
master_graph
.
redraw
();
};
ContributorsStatGraph
.
prototype
.
redraw_master
=
function
()
{
var
total_data
;
total_data
=
ContributorsStatGraphUtil
.
get_total_data
(
this
.
parsed_log
,
this
.
field
);
this
.
master_graph
.
set_data
(
total_data
);
return
this
.
master_graph
.
redraw
();
};
ContributorsStatGraph
.
prototype
.
redraw_authors
=
function
()
{
var
author_commits
,
x_domain
;
$
(
"
ol
"
).
html
(
""
);
x_domain
=
ContributorsGraph
.
prototype
.
x_domain
;
author_commits
=
ContributorsStatGraphUtil
.
get_author_data
(
this
.
parsed_log
,
this
.
field
,
x_domain
);
return
_
.
each
(
author_commits
,
(
function
(
_this
)
{
return
function
(
d
)
{
_this
.
redraw_author_commit_info
(
d
);
$
(
_this
.
authors
[
d
.
author_name
].
list_item
).
appendTo
(
"
ol
"
);
_this
.
authors
[
d
.
author_name
].
set_data
(
d
.
dates
);
return
_this
.
authors
[
d
.
author_name
].
redraw
();
};
})(
this
));
};
ContributorsStatGraph
.
prototype
.
redraw_authors
=
function
()
{
var
author_commits
,
x_domain
;
$
(
"
ol
"
).
html
(
""
);
x_domain
=
ContributorsGraph
.
prototype
.
x_domain
;
author_commits
=
ContributorsStatGraphUtil
.
get_author_data
(
this
.
parsed_log
,
this
.
field
,
x_domain
);
return
_
.
each
(
author_commits
,
(
function
(
_this
)
{
return
function
(
d
)
{
_this
.
redraw_author_commit_info
(
d
);
$
(
_this
.
authors
[
d
.
author_name
].
list_item
).
appendTo
(
"
ol
"
);
_this
.
authors
[
d
.
author_name
].
set_data
(
d
.
dates
);
return
_this
.
authors
[
d
.
author_name
].
redraw
();
};
})(
this
));
};
ContributorsStatGraph
.
prototype
.
set_current_field
=
function
(
field
)
{
return
this
.
field
=
field
;
};
ContributorsStatGraph
.
prototype
.
set_current_field
=
function
(
field
)
{
return
this
.
field
=
field
;
};
ContributorsStatGraph
.
prototype
.
change_date_header
=
function
()
{
var
print
,
print_date_format
,
x_domain
;
x_domain
=
ContributorsGraph
.
prototype
.
x_domain
;
print_date_format
=
d3
.
time
.
format
(
"
%B %e %Y
"
);
print
=
print_date_format
(
x_domain
[
0
])
+
"
-
"
+
print_date_format
(
x_domain
[
1
]);
return
$
(
"
#date_header
"
).
text
(
print
);
};
ContributorsStatGraph
.
prototype
.
change_date_header
=
function
()
{
var
print
,
print_date_format
,
x_domain
;
x_domain
=
ContributorsGraph
.
prototype
.
x_domain
;
print_date_format
=
d3
.
time
.
format
(
"
%B %e %Y
"
);
print
=
print_date_format
(
x_domain
[
0
])
+
"
-
"
+
print_date_format
(
x_domain
[
1
]);
return
$
(
"
#date_header
"
).
text
(
print
);
};
ContributorsStatGraph
.
prototype
.
redraw_author_commit_info
=
function
(
author
)
{
var
author_commit_info
,
author_list_item
;
author_list_item
=
$
(
this
.
authors
[
author
.
author_name
].
list_item
);
author_commit_info
=
this
.
format_author_commit_info
(
author
);
return
author_list_item
.
find
(
"
span
"
).
html
(
author_commit_info
);
};
ContributorsStatGraph
.
prototype
.
redraw_author_commit_info
=
function
(
author
)
{
var
author_commit_info
,
author_list_item
;
author_list_item
=
$
(
this
.
authors
[
author
.
author_name
].
list_item
);
author_commit_info
=
this
.
format_author_commit_info
(
author
);
return
author_list_item
.
find
(
"
span
"
).
html
(
author_commit_info
);
};
return
ContributorsStatGraph
;
})();
}).
call
(
window
);
return
ContributorsStatGraph
;
})();
app/assets/javascripts/graphs/stat_graph_contributors_graph.js
浏览文件 @
9f6660b1
/* eslint-disable func-names, space-before-function-paren, one-var, no-var, prefer-rest-params, max-len, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, comma-dangle, no-return-assign, prefer-arrow-callback, quotes, prefer-template, newline-per-chained-call, no-else-return */
/* global d3 */
/* global ContributorsGraph */
window
.
d3
=
require
(
'
d3
'
);
(
function
()
{
var
bind
=
function
(
fn
,
me
)
{
return
function
()
{
return
fn
.
apply
(
me
,
arguments
);
};
},
extend
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
},
hasProp
=
{}.
hasOwnProperty
;
this
.
ContributorsGraph
=
(
function
()
{
function
ContributorsGraph
()
{}
ContributorsGraph
.
prototype
.
MARGIN
=
{
top
:
20
,
right
:
20
,
bottom
:
30
,
left
:
50
};
ContributorsGraph
.
prototype
.
x_domain
=
null
;
ContributorsGraph
.
prototype
.
y_domain
=
null
;
ContributorsGraph
.
prototype
.
dates
=
[];
ContributorsGraph
.
set_x_domain
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
x_domain
=
data
;
};
ContributorsGraph
.
set_y_domain
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
y_domain
=
[
0
,
d3
.
max
(
data
,
function
(
d
)
{
return
d
.
commits
=
d
.
commits
||
d
.
additions
||
d
.
deletions
;
})
];
};
ContributorsGraph
.
init_x_domain
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
x_domain
=
d3
.
extent
(
data
,
function
(
d
)
{
return
d
.
date
;
});
};
ContributorsGraph
.
init_y_domain
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
y_domain
=
[
0
,
d3
.
max
(
data
,
function
(
d
)
{
return
d
.
commits
=
d
.
commits
||
d
.
additions
||
d
.
deletions
;
})
];
};
ContributorsGraph
.
init_domain
=
function
(
data
)
{
ContributorsGraph
.
init_x_domain
(
data
);
return
ContributorsGraph
.
init_y_domain
(
data
);
};
ContributorsGraph
.
set_dates
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
dates
=
data
;
};
ContributorsGraph
.
prototype
.
set_x_domain
=
function
()
{
return
this
.
x
.
domain
(
this
.
x_domain
);
};
ContributorsGraph
.
prototype
.
set_y_domain
=
function
()
{
return
this
.
y
.
domain
(
this
.
y_domain
);
};
ContributorsGraph
.
prototype
.
set_domain
=
function
()
{
this
.
set_x_domain
();
return
this
.
set_y_domain
();
};
ContributorsGraph
.
prototype
.
create_scale
=
function
(
width
,
height
)
{
this
.
x
=
d3
.
time
.
scale
().
range
([
0
,
width
]).
clamp
(
true
);
return
this
.
y
=
d3
.
scale
.
linear
().
range
([
height
,
0
]).
nice
();
};
ContributorsGraph
.
prototype
.
draw_x_axis
=
function
()
{
return
this
.
svg
.
append
(
"
g
"
).
attr
(
"
class
"
,
"
x axis
"
).
attr
(
"
transform
"
,
"
translate(0,
"
+
this
.
height
+
"
)
"
).
call
(
this
.
x_axis
);
};
ContributorsGraph
.
prototype
.
draw_y_axis
=
function
()
{
return
this
.
svg
.
append
(
"
g
"
).
attr
(
"
class
"
,
"
y axis
"
).
call
(
this
.
y_axis
);
};
ContributorsGraph
.
prototype
.
set_data
=
function
(
data
)
{
return
this
.
data
=
data
;
};
return
ContributorsGraph
;
})();
this
.
ContributorsMasterGraph
=
(
function
(
superClass
)
{
extend
(
ContributorsMasterGraph
,
superClass
);
function
ContributorsMasterGraph
(
data1
)
{
this
.
data
=
data1
;
this
.
update_content
=
bind
(
this
.
update_content
,
this
);
this
.
width
=
$
(
'
.content
'
).
width
()
-
70
;
this
.
height
=
200
;
this
.
x
=
null
;
this
.
y
=
null
;
this
.
x_axis
=
null
;
this
.
y_axis
=
null
;
this
.
area
=
null
;
this
.
svg
=
null
;
this
.
brush
=
null
;
this
.
x_max_domain
=
null
;
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, max-len, no-restricted-syntax, vars-on-top, no-use-before-define, no-param-reassign, new-cap, no-underscore-dangle, wrap-iife, comma-dangle, no-return-assign, prefer-arrow-callback, quotes, prefer-template, newline-per-chained-call, no-else-return, no-shadow */
import
d3
from
'
d3
'
;
const
bind
=
function
(
fn
,
me
)
{
return
function
()
{
return
fn
.
apply
(
me
,
arguments
);
};
};
const
extend
=
function
(
child
,
parent
)
{
for
(
var
key
in
parent
)
{
if
(
hasProp
.
call
(
parent
,
key
))
child
[
key
]
=
parent
[
key
];
}
function
ctor
()
{
this
.
constructor
=
child
;
}
ctor
.
prototype
=
parent
.
prototype
;
child
.
prototype
=
new
ctor
();
child
.
__super__
=
parent
.
prototype
;
return
child
;
};
const
hasProp
=
{}.
hasOwnProperty
;
export
const
ContributorsGraph
=
(
function
()
{
function
ContributorsGraph
()
{}
ContributorsGraph
.
prototype
.
MARGIN
=
{
top
:
20
,
right
:
20
,
bottom
:
30
,
left
:
50
};
ContributorsGraph
.
prototype
.
x_domain
=
null
;
ContributorsGraph
.
prototype
.
y_domain
=
null
;
ContributorsGraph
.
prototype
.
dates
=
[];
ContributorsGraph
.
set_x_domain
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
x_domain
=
data
;
};
ContributorsGraph
.
set_y_domain
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
y_domain
=
[
0
,
d3
.
max
(
data
,
function
(
d
)
{
return
d
.
commits
=
d
.
commits
||
d
.
additions
||
d
.
deletions
;
})
];
};
ContributorsGraph
.
init_x_domain
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
x_domain
=
d3
.
extent
(
data
,
function
(
d
)
{
return
d
.
date
;
});
};
ContributorsGraph
.
init_y_domain
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
y_domain
=
[
0
,
d3
.
max
(
data
,
function
(
d
)
{
return
d
.
commits
=
d
.
commits
||
d
.
additions
||
d
.
deletions
;
})
];
};
ContributorsGraph
.
init_domain
=
function
(
data
)
{
ContributorsGraph
.
init_x_domain
(
data
);
return
ContributorsGraph
.
init_y_domain
(
data
);
};
ContributorsGraph
.
set_dates
=
function
(
data
)
{
return
ContributorsGraph
.
prototype
.
dates
=
data
;
};
ContributorsGraph
.
prototype
.
set_x_domain
=
function
()
{
return
this
.
x
.
domain
(
this
.
x_domain
);
};
ContributorsGraph
.
prototype
.
set_y_domain
=
function
()
{
return
this
.
y
.
domain
(
this
.
y_domain
);
};
ContributorsGraph
.
prototype
.
set_domain
=
function
()
{
this
.
set_x_domain
();
return
this
.
set_y_domain
();
};
ContributorsGraph
.
prototype
.
create_scale
=
function
(
width
,
height
)
{
this
.
x
=
d3
.
time
.
scale
().
range
([
0
,
width
]).
clamp
(
true
);
return
this
.
y
=
d3
.
scale
.
linear
().
range
([
height
,
0
]).
nice
();
};
ContributorsGraph
.
prototype
.
draw_x_axis
=
function
()
{
return
this
.
svg
.
append
(
"
g
"
).
attr
(
"
class
"
,
"
x axis
"
).
attr
(
"
transform
"
,
"
translate(0,
"
+
this
.
height
+
"
)
"
).
call
(
this
.
x_axis
);
};
ContributorsGraph
.
prototype
.
draw_y_axis
=
function
()
{
return
this
.
svg
.
append
(
"
g
"
).
attr
(
"
class
"
,
"
y axis
"
).
call
(
this
.
y_axis
);
};
ContributorsGraph
.
prototype
.
set_data
=
function
(
data
)
{
return
this
.
data
=
data
;
};
return
ContributorsGraph
;
})();
export
const
ContributorsMasterGraph
=
(
function
(
superClass
)
{
extend
(
ContributorsMasterGraph
,
superClass
);
function
ContributorsMasterGraph
(
data1
)
{
this
.
data
=
data1
;
this
.
update_content
=
bind
(
this
.
update_content
,
this
);
this
.
width
=
$
(
'
.content
'
).
width
()
-
70
;
this
.
height
=
200
;
this
.
x
=
null
;
this
.
y
=
null
;
this
.
x_axis
=
null
;
this
.
y_axis
=
null
;
this
.
area
=
null
;
this
.
svg
=
null
;
this
.
brush
=
null
;
this
.
x_max_domain
=
null
;
}
ContributorsMasterGraph
.
prototype
.
process_dates
=
function
(
data
)
{
var
dates
;
dates
=
this
.
get_dates
(
data
);
this
.
parse_dates
(
data
);
return
ContributorsGraph
.
set_dates
(
dates
);
};
ContributorsMasterGraph
.
prototype
.
get_dates
=
function
(
data
)
{
return
_
.
pluck
(
data
,
'
date
'
);
};
ContributorsMasterGraph
.
prototype
.
parse_dates
=
function
(
data
)
{
var
parseDate
;
parseDate
=
d3
.
time
.
format
(
"
%Y-%m-%d
"
).
parse
;
return
data
.
forEach
(
function
(
d
)
{
return
d
.
date
=
parseDate
(
d
.
date
);
});
};
ContributorsMasterGraph
.
prototype
.
create_scale
=
function
()
{
return
ContributorsMasterGraph
.
__super__
.
create_scale
.
call
(
this
,
this
.
width
,
this
.
height
);
};
ContributorsMasterGraph
.
prototype
.
create_axes
=
function
()
{
this
.
x_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
x
).
orient
(
"
bottom
"
);
return
this
.
y_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
y
).
orient
(
"
left
"
).
ticks
(
5
);
};
ContributorsMasterGraph
.
prototype
.
create_svg
=
function
()
{
return
this
.
svg
=
d3
.
select
(
"
#contributors-master
"
).
append
(
"
svg
"
).
attr
(
"
width
"
,
this
.
width
+
this
.
MARGIN
.
left
+
this
.
MARGIN
.
right
).
attr
(
"
height
"
,
this
.
height
+
this
.
MARGIN
.
top
+
this
.
MARGIN
.
bottom
).
attr
(
"
class
"
,
"
tint-box
"
).
append
(
"
g
"
).
attr
(
"
transform
"
,
"
translate(
"
+
this
.
MARGIN
.
left
+
"
,
"
+
this
.
MARGIN
.
top
+
"
)
"
);
};
ContributorsMasterGraph
.
prototype
.
create_area
=
function
(
x
,
y
)
{
return
this
.
area
=
d3
.
svg
.
area
().
x
(
function
(
d
)
{
return
x
(
d
.
date
);
}).
y0
(
this
.
height
).
y1
(
function
(
d
)
{
d
.
commits
=
d
.
commits
||
d
.
additions
||
d
.
deletions
;
return
y
(
d
.
commits
);
}).
interpolate
(
"
basis
"
);
};
ContributorsMasterGraph
.
prototype
.
create_brush
=
function
()
{
return
this
.
brush
=
d3
.
svg
.
brush
().
x
(
this
.
x
).
on
(
"
brushend
"
,
this
.
update_content
);
};
ContributorsMasterGraph
.
prototype
.
draw_path
=
function
(
data
)
{
return
this
.
svg
.
append
(
"
path
"
).
datum
(
data
).
attr
(
"
class
"
,
"
area
"
).
attr
(
"
d
"
,
this
.
area
);
};
ContributorsMasterGraph
.
prototype
.
add_brush
=
function
()
{
return
this
.
svg
.
append
(
"
g
"
).
attr
(
"
class
"
,
"
selection
"
).
call
(
this
.
brush
).
selectAll
(
"
rect
"
).
attr
(
"
height
"
,
this
.
height
);
};
ContributorsMasterGraph
.
prototype
.
update_content
=
function
()
{
ContributorsGraph
.
set_x_domain
(
this
.
brush
.
empty
()
?
this
.
x_max_domain
:
this
.
brush
.
extent
());
return
$
(
"
#brush_change
"
).
trigger
(
'
change
'
);
};
ContributorsMasterGraph
.
prototype
.
draw
=
function
()
{
this
.
process_dates
(
this
.
data
);
this
.
create_scale
();
this
.
create_axes
();
ContributorsGraph
.
init_domain
(
this
.
data
);
this
.
x_max_domain
=
this
.
x_domain
;
this
.
set_domain
();
this
.
create_area
(
this
.
x
,
this
.
y
);
this
.
create_svg
();
this
.
create_brush
();
this
.
draw_path
(
this
.
data
);
this
.
draw_x_axis
();
this
.
draw_y_axis
();
return
this
.
add_brush
();
};
ContributorsMasterGraph
.
prototype
.
redraw
=
function
()
{
this
.
process_dates
(
this
.
data
);
ContributorsGraph
.
set_y_domain
(
this
.
data
);
this
.
set_y_domain
();
this
.
svg
.
select
(
"
path
"
).
datum
(
this
.
data
);
this
.
svg
.
select
(
"
path
"
).
attr
(
"
d
"
,
this
.
area
);
return
this
.
svg
.
select
(
"
.y.axis
"
).
call
(
this
.
y_axis
);
};
return
ContributorsMasterGraph
;
})(
ContributorsGraph
);
export
const
ContributorsAuthorGraph
=
(
function
(
superClass
)
{
extend
(
ContributorsAuthorGraph
,
superClass
);
function
ContributorsAuthorGraph
(
data1
)
{
this
.
data
=
data1
;
// Don't split graph size in half for mobile devices.
if
(
$
(
window
).
width
()
<
768
)
{
this
.
width
=
$
(
'
.content
'
).
width
()
-
80
;
}
else
{
this
.
width
=
(
$
(
'
.content
'
).
width
()
/
2
)
-
100
;
}
ContributorsMasterGraph
.
prototype
.
process_dates
=
function
(
data
)
{
var
dates
;
dates
=
this
.
get_dates
(
data
);
this
.
parse_dates
(
data
);
return
ContributorsGraph
.
set_dates
(
dates
);
};
ContributorsMasterGraph
.
prototype
.
get_dates
=
function
(
data
)
{
return
_
.
pluck
(
data
,
'
date
'
);
};
ContributorsMasterGraph
.
prototype
.
parse_dates
=
function
(
data
)
{
this
.
height
=
200
;
this
.
x
=
null
;
this
.
y
=
null
;
this
.
x_axis
=
null
;
this
.
y_axis
=
null
;
this
.
area
=
null
;
this
.
svg
=
null
;
this
.
list_item
=
null
;
}
ContributorsAuthorGraph
.
prototype
.
create_scale
=
function
()
{
return
ContributorsAuthorGraph
.
__super__
.
create_scale
.
call
(
this
,
this
.
width
,
this
.
height
);
};
ContributorsAuthorGraph
.
prototype
.
create_axes
=
function
()
{
this
.
x_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
x
).
orient
(
"
bottom
"
).
ticks
(
8
);
return
this
.
y_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
y
).
orient
(
"
left
"
).
ticks
(
5
);
};
ContributorsAuthorGraph
.
prototype
.
create_area
=
function
(
x
,
y
)
{
return
this
.
area
=
d3
.
svg
.
area
().
x
(
function
(
d
)
{
var
parseDate
;
parseDate
=
d3
.
time
.
format
(
"
%Y-%m-%d
"
).
parse
;
return
data
.
forEach
(
function
(
d
)
{
return
d
.
date
=
parseDate
(
d
.
date
);
});
};
ContributorsMasterGraph
.
prototype
.
create_scale
=
function
()
{
return
ContributorsMasterGraph
.
__super__
.
create_scale
.
call
(
this
,
this
.
width
,
this
.
height
);
};
ContributorsMasterGraph
.
prototype
.
create_axes
=
function
()
{
this
.
x_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
x
).
orient
(
"
bottom
"
);
return
this
.
y_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
y
).
orient
(
"
left
"
).
ticks
(
5
);
};
ContributorsMasterGraph
.
prototype
.
create_svg
=
function
()
{
return
this
.
svg
=
d3
.
select
(
"
#contributors-master
"
).
append
(
"
svg
"
).
attr
(
"
width
"
,
this
.
width
+
this
.
MARGIN
.
left
+
this
.
MARGIN
.
right
).
attr
(
"
height
"
,
this
.
height
+
this
.
MARGIN
.
top
+
this
.
MARGIN
.
bottom
).
attr
(
"
class
"
,
"
tint-box
"
).
append
(
"
g
"
).
attr
(
"
transform
"
,
"
translate(
"
+
this
.
MARGIN
.
left
+
"
,
"
+
this
.
MARGIN
.
top
+
"
)
"
);
};
ContributorsMasterGraph
.
prototype
.
create_area
=
function
(
x
,
y
)
{
return
this
.
area
=
d3
.
svg
.
area
().
x
(
function
(
d
)
{
return
x
(
d
.
date
);
}).
y0
(
this
.
height
).
y1
(
function
(
d
)
{
d
.
commits
=
d
.
commits
||
d
.
additions
||
d
.
deletions
;
return
y
(
d
.
commits
);
}).
interpolate
(
"
basis
"
);
};
ContributorsMasterGraph
.
prototype
.
create_brush
=
function
()
{
return
this
.
brush
=
d3
.
svg
.
brush
().
x
(
this
.
x
).
on
(
"
brushend
"
,
this
.
update_content
);
};
ContributorsMasterGraph
.
prototype
.
draw_path
=
function
(
data
)
{
return
this
.
svg
.
append
(
"
path
"
).
datum
(
data
).
attr
(
"
class
"
,
"
area
"
).
attr
(
"
d
"
,
this
.
area
);
};
ContributorsMasterGraph
.
prototype
.
add_brush
=
function
()
{
return
this
.
svg
.
append
(
"
g
"
).
attr
(
"
class
"
,
"
selection
"
).
call
(
this
.
brush
).
selectAll
(
"
rect
"
).
attr
(
"
height
"
,
this
.
height
);
};
ContributorsMasterGraph
.
prototype
.
update_content
=
function
()
{
ContributorsGraph
.
set_x_domain
(
this
.
brush
.
empty
()
?
this
.
x_max_domain
:
this
.
brush
.
extent
());
return
$
(
"
#brush_change
"
).
trigger
(
'
change
'
);
};
ContributorsMasterGraph
.
prototype
.
draw
=
function
()
{
this
.
process_dates
(
this
.
data
);
this
.
create_scale
();
this
.
create_axes
();
ContributorsGraph
.
init_domain
(
this
.
data
);
this
.
x_max_domain
=
this
.
x_domain
;
this
.
set_domain
();
this
.
create_area
(
this
.
x
,
this
.
y
);
this
.
create_svg
();
this
.
create_brush
();
this
.
draw_path
(
this
.
data
);
this
.
draw_x_axis
();
this
.
draw_y_axis
();
return
this
.
add_brush
();
};
ContributorsMasterGraph
.
prototype
.
redraw
=
function
()
{
this
.
process_dates
(
this
.
data
);
ContributorsGraph
.
set_y_domain
(
this
.
data
);
this
.
set_y_domain
();
this
.
svg
.
select
(
"
path
"
).
datum
(
this
.
data
);
this
.
svg
.
select
(
"
path
"
).
attr
(
"
d
"
,
this
.
area
);
return
this
.
svg
.
select
(
"
.y.axis
"
).
call
(
this
.
y_axis
);
};
return
ContributorsMasterGraph
;
})(
ContributorsGraph
);
this
.
ContributorsAuthorGraph
=
(
function
(
superClass
)
{
extend
(
ContributorsAuthorGraph
,
superClass
);
function
ContributorsAuthorGraph
(
data1
)
{
this
.
data
=
data1
;
// Don't split graph size in half for mobile devices.
if
(
$
(
window
).
width
()
<
768
)
{
this
.
width
=
$
(
'
.content
'
).
width
()
-
80
;
}
else
{
this
.
width
=
(
$
(
'
.content
'
).
width
()
/
2
)
-
100
;
}
this
.
height
=
200
;
this
.
x
=
null
;
this
.
y
=
null
;
this
.
x_axis
=
null
;
this
.
y_axis
=
null
;
this
.
area
=
null
;
this
.
svg
=
null
;
this
.
list_item
=
null
;
}
ContributorsAuthorGraph
.
prototype
.
create_scale
=
function
()
{
return
ContributorsAuthorGraph
.
__super__
.
create_scale
.
call
(
this
,
this
.
width
,
this
.
height
);
};
ContributorsAuthorGraph
.
prototype
.
create_axes
=
function
()
{
this
.
x_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
x
).
orient
(
"
bottom
"
).
ticks
(
8
);
return
this
.
y_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
y
).
orient
(
"
left
"
).
ticks
(
5
);
};
ContributorsAuthorGraph
.
prototype
.
create_area
=
function
(
x
,
y
)
{
return
this
.
area
=
d3
.
svg
.
area
().
x
(
function
(
d
)
{
var
parseDate
;
parseDate
=
d3
.
time
.
format
(
"
%Y-%m-%d
"
).
parse
;
return
x
(
parseDate
(
d
));
}).
y0
(
this
.
height
).
y1
((
function
(
_this
)
{
return
function
(
d
)
{
if
(
_this
.
data
[
d
]
!=
null
)
{
return
y
(
_this
.
data
[
d
]);
}
else
{
return
y
(
0
);
}
};
})(
this
)).
interpolate
(
"
basis
"
);
};
ContributorsAuthorGraph
.
prototype
.
create_svg
=
function
()
{
this
.
list_item
=
d3
.
selectAll
(
"
.person
"
)[
0
].
pop
();
return
this
.
svg
=
d3
.
select
(
this
.
list_item
).
append
(
"
svg
"
).
attr
(
"
width
"
,
this
.
width
+
this
.
MARGIN
.
left
+
this
.
MARGIN
.
right
).
attr
(
"
height
"
,
this
.
height
+
this
.
MARGIN
.
top
+
this
.
MARGIN
.
bottom
).
attr
(
"
class
"
,
"
spark
"
).
append
(
"
g
"
).
attr
(
"
transform
"
,
"
translate(
"
+
this
.
MARGIN
.
left
+
"
,
"
+
this
.
MARGIN
.
top
+
"
)
"
);
};
ContributorsAuthorGraph
.
prototype
.
draw_path
=
function
(
data
)
{
return
this
.
svg
.
append
(
"
path
"
).
datum
(
data
).
attr
(
"
class
"
,
"
area-contributor
"
).
attr
(
"
d
"
,
this
.
area
);
};
ContributorsAuthorGraph
.
prototype
.
draw
=
function
()
{
this
.
create_scale
();
this
.
create_axes
();
this
.
set_domain
();
this
.
create_area
(
this
.
x
,
this
.
y
);
this
.
create_svg
();
this
.
draw_path
(
this
.
dates
);
this
.
draw_x_axis
();
return
this
.
draw_y_axis
();
};
ContributorsAuthorGraph
.
prototype
.
redraw
=
function
()
{
this
.
set_domain
();
this
.
svg
.
select
(
"
path
"
).
datum
(
this
.
dates
);
this
.
svg
.
select
(
"
path
"
).
attr
(
"
d
"
,
this
.
area
);
this
.
svg
.
select
(
"
.x.axis
"
).
call
(
this
.
x_axis
);
return
this
.
svg
.
select
(
"
.y.axis
"
).
call
(
this
.
y_axis
);
};
return
ContributorsAuthorGraph
;
})(
ContributorsGraph
);
}).
call
(
window
);
return
x
(
parseDate
(
d
));
}).
y0
(
this
.
height
).
y1
((
function
(
_this
)
{
return
function
(
d
)
{
if
(
_this
.
data
[
d
]
!=
null
)
{
return
y
(
_this
.
data
[
d
]);
}
else
{
return
y
(
0
);
}
};
})(
this
)).
interpolate
(
"
basis
"
);
};
ContributorsAuthorGraph
.
prototype
.
create_svg
=
function
()
{
this
.
list_item
=
d3
.
selectAll
(
"
.person
"
)[
0
].
pop
();
return
this
.
svg
=
d3
.
select
(
this
.
list_item
).
append
(
"
svg
"
).
attr
(
"
width
"
,
this
.
width
+
this
.
MARGIN
.
left
+
this
.
MARGIN
.
right
).
attr
(
"
height
"
,
this
.
height
+
this
.
MARGIN
.
top
+
this
.
MARGIN
.
bottom
).
attr
(
"
class
"
,
"
spark
"
).
append
(
"
g
"
).
attr
(
"
transform
"
,
"
translate(
"
+
this
.
MARGIN
.
left
+
"
,
"
+
this
.
MARGIN
.
top
+
"
)
"
);
};
ContributorsAuthorGraph
.
prototype
.
draw_path
=
function
(
data
)
{
return
this
.
svg
.
append
(
"
path
"
).
datum
(
data
).
attr
(
"
class
"
,
"
area-contributor
"
).
attr
(
"
d
"
,
this
.
area
);
};
ContributorsAuthorGraph
.
prototype
.
draw
=
function
()
{
this
.
create_scale
();
this
.
create_axes
();
this
.
set_domain
();
this
.
create_area
(
this
.
x
,
this
.
y
);
this
.
create_svg
();
this
.
draw_path
(
this
.
dates
);
this
.
draw_x_axis
();
return
this
.
draw_y_axis
();
};
ContributorsAuthorGraph
.
prototype
.
redraw
=
function
()
{
this
.
set_domain
();
this
.
svg
.
select
(
"
path
"
).
datum
(
this
.
dates
);
this
.
svg
.
select
(
"
path
"
).
attr
(
"
d
"
,
this
.
area
);
this
.
svg
.
select
(
"
.x.axis
"
).
call
(
this
.
x_axis
);
return
this
.
svg
.
select
(
"
.y.axis
"
).
call
(
this
.
y_axis
);
};
return
ContributorsAuthorGraph
;
})(
ContributorsGraph
);
app/assets/javascripts/graphs/stat_graph_contributors_util.js
浏览文件 @
9f6660b1
/* eslint-disable func-names, space-before-function-paren, object-shorthand, no-var, one-var, camelcase, one-var-declaration-per-line, comma-dangle, no-param-reassign, no-return-assign, quotes, prefer-arrow-callback, wrap-iife, consistent-return, no-unused-vars, max-len, no-cond-assign, no-else-return, max-len */
(
function
()
{
window
.
ContributorsStatGraphUtil
=
{
parse_log
:
function
(
log
)
{
var
by_author
,
by_email
,
data
,
entry
,
i
,
len
,
total
,
normalized_email
;
total
=
{};
by_author
=
{};
by_email
=
{};
for
(
i
=
0
,
len
=
log
.
length
;
i
<
len
;
i
+=
1
)
{
entry
=
log
[
i
];
if
(
total
[
entry
.
date
]
==
null
)
{
this
.
add_date
(
entry
.
date
,
total
);
}
normalized_email
=
entry
.
author_email
.
toLowerCase
();
data
=
by_author
[
entry
.
author_name
]
||
by_email
[
normalized_email
];
if
(
data
==
null
)
{
data
=
this
.
add_author
(
entry
,
by_author
,
by_email
);
}
if
(
!
data
[
entry
.
date
])
{
this
.
add_date
(
entry
.
date
,
data
);
}
this
.
store_data
(
entry
,
total
[
entry
.
date
],
data
[
entry
.
date
]);
}
total
=
_
.
toArray
(
total
);
by_author
=
_
.
toArray
(
by_author
);
return
{
total
:
total
,
by_author
:
by_author
};
},
add_date
:
function
(
date
,
collection
)
{
collection
[
date
]
=
{};
return
collection
[
date
].
date
=
date
;
},
add_author
:
function
(
author
,
by_author
,
by_email
)
{
var
data
,
normalized_email
;
data
=
{};
data
.
author_name
=
author
.
author_name
;
data
.
author_email
=
author
.
author_email
;
normalized_email
=
author
.
author_email
.
toLowerCase
();
by_author
[
author
.
author_name
]
=
data
;
by_email
[
normalized_email
]
=
data
;
return
data
;
},
store_data
:
function
(
entry
,
total
,
by_author
)
{
this
.
store_commits
(
total
,
by_author
);
this
.
store_additions
(
entry
,
total
,
by_author
);
return
this
.
store_deletions
(
entry
,
total
,
by_author
);
},
store_commits
:
function
(
total
,
by_author
)
{
this
.
add
(
total
,
"
commits
"
,
1
);
return
this
.
add
(
by_author
,
"
commits
"
,
1
);
},
add
:
function
(
collection
,
field
,
value
)
{
if
(
collection
[
field
]
==
null
)
{
collection
[
field
]
=
0
;
}
return
collection
[
field
]
+=
value
;
},
store_additions
:
function
(
entry
,
total
,
by_author
)
{
if
(
entry
.
additions
==
null
)
{
entry
.
additions
=
0
;
export
default
{
parse_log
:
function
(
log
)
{
var
by_author
,
by_email
,
data
,
entry
,
i
,
len
,
total
,
normalized_email
;
total
=
{};
by_author
=
{};
by_email
=
{};
for
(
i
=
0
,
len
=
log
.
length
;
i
<
len
;
i
+=
1
)
{
entry
=
log
[
i
];
if
(
total
[
entry
.
date
]
==
null
)
{
this
.
add_date
(
entry
.
date
,
total
);
}
this
.
add
(
total
,
"
additions
"
,
entry
.
additions
);
return
this
.
add
(
by_author
,
"
additions
"
,
entry
.
additions
);
},
store_deletions
:
function
(
entry
,
total
,
by_author
)
{
if
(
entry
.
deletions
==
null
)
{
entry
.
deletions
=
0
;
normalized_email
=
entry
.
author_email
.
toLowerCase
();
data
=
by_author
[
entry
.
author_name
]
||
by_email
[
normalized_email
];
if
(
data
==
null
)
{
data
=
this
.
add_author
(
entry
,
by_author
,
by_email
);
}
this
.
add
(
total
,
"
deletions
"
,
entry
.
deletions
);
return
this
.
add
(
by_author
,
"
deletions
"
,
entry
.
deletions
);
},
get_total_data
:
function
(
parsed_log
,
field
)
{
var
log
,
total_data
;
log
=
parsed_log
.
total
;
total_data
=
this
.
pick_field
(
log
,
field
);
return
_
.
sortBy
(
total_data
,
function
(
d
)
{
return
d
.
date
;
});
},
pick_field
:
function
(
log
,
field
)
{
var
total_data
;
total_data
=
[];
_
.
each
(
log
,
function
(
d
)
{
return
total_data
.
push
(
_
.
pick
(
d
,
[
field
,
'
date
'
]));
});
return
total_data
;
},
get_author_data
:
function
(
parsed_log
,
field
,
date_range
)
{
var
author_data
,
log
;
if
(
date_range
==
null
)
{
date_range
=
null
;
}
log
=
parsed_log
.
by_author
;
author_data
=
[];
_
.
each
(
log
,
(
function
(
_this
)
{
return
function
(
log_entry
)
{
var
parsed_log_entry
;
parsed_log_entry
=
_this
.
parse_log_entry
(
log_entry
,
field
,
date_range
);
if
(
!
_
.
isEmpty
(
parsed_log_entry
.
dates
))
{
return
author_data
.
push
(
parsed_log_entry
);
}
};
})(
this
));
return
_
.
sortBy
(
author_data
,
function
(
d
)
{
return
d
[
field
];
}).
reverse
();
},
parse_log_entry
:
function
(
log_entry
,
field
,
date_range
)
{
var
parsed_entry
;
parsed_entry
=
{};
parsed_entry
.
author_name
=
log_entry
.
author_name
;
parsed_entry
.
author_email
=
log_entry
.
author_email
;
parsed_entry
.
dates
=
{};
parsed_entry
.
commits
=
parsed_entry
.
additions
=
parsed_entry
.
deletions
=
0
;
_
.
each
(
_
.
omit
(
log_entry
,
'
author_name
'
,
'
author_email
'
),
(
function
(
_this
)
{
return
function
(
value
,
key
)
{
if
(
_this
.
in_range
(
value
.
date
,
date_range
))
{
parsed_entry
.
dates
[
value
.
date
]
=
value
[
field
];
parsed_entry
.
commits
+=
value
.
commits
;
parsed_entry
.
additions
+=
value
.
additions
;
return
parsed_entry
.
deletions
+=
value
.
deletions
;
}
};
})(
this
));
return
parsed_entry
;
},
in_range
:
function
(
date
,
date_range
)
{
var
ref
;
if
(
date_range
===
null
||
(
date_range
[
0
]
<=
(
ref
=
new
Date
(
date
))
&&
ref
<=
date_range
[
1
]))
{
return
true
;
}
else
{
return
false
;
if
(
!
data
[
entry
.
date
])
{
this
.
add_date
(
entry
.
date
,
data
);
}
this
.
store_data
(
entry
,
total
[
entry
.
date
],
data
[
entry
.
date
]);
}
total
=
_
.
toArray
(
total
);
by_author
=
_
.
toArray
(
by_author
);
return
{
total
:
total
,
by_author
:
by_author
};
},
add_date
:
function
(
date
,
collection
)
{
collection
[
date
]
=
{};
return
collection
[
date
].
date
=
date
;
},
add_author
:
function
(
author
,
by_author
,
by_email
)
{
var
data
,
normalized_email
;
data
=
{};
data
.
author_name
=
author
.
author_name
;
data
.
author_email
=
author
.
author_email
;
normalized_email
=
author
.
author_email
.
toLowerCase
();
by_author
[
author
.
author_name
]
=
data
;
by_email
[
normalized_email
]
=
data
;
return
data
;
},
store_data
:
function
(
entry
,
total
,
by_author
)
{
this
.
store_commits
(
total
,
by_author
);
this
.
store_additions
(
entry
,
total
,
by_author
);
return
this
.
store_deletions
(
entry
,
total
,
by_author
);
},
store_commits
:
function
(
total
,
by_author
)
{
this
.
add
(
total
,
"
commits
"
,
1
);
return
this
.
add
(
by_author
,
"
commits
"
,
1
);
},
add
:
function
(
collection
,
field
,
value
)
{
if
(
collection
[
field
]
==
null
)
{
collection
[
field
]
=
0
;
}
return
collection
[
field
]
+=
value
;
},
store_additions
:
function
(
entry
,
total
,
by_author
)
{
if
(
entry
.
additions
==
null
)
{
entry
.
additions
=
0
;
}
this
.
add
(
total
,
"
additions
"
,
entry
.
additions
);
return
this
.
add
(
by_author
,
"
additions
"
,
entry
.
additions
);
},
store_deletions
:
function
(
entry
,
total
,
by_author
)
{
if
(
entry
.
deletions
==
null
)
{
entry
.
deletions
=
0
;
}
this
.
add
(
total
,
"
deletions
"
,
entry
.
deletions
);
return
this
.
add
(
by_author
,
"
deletions
"
,
entry
.
deletions
);
},
get_total_data
:
function
(
parsed_log
,
field
)
{
var
log
,
total_data
;
log
=
parsed_log
.
total
;
total_data
=
this
.
pick_field
(
log
,
field
);
return
_
.
sortBy
(
total_data
,
function
(
d
)
{
return
d
.
date
;
});
},
pick_field
:
function
(
log
,
field
)
{
var
total_data
;
total_data
=
[];
_
.
each
(
log
,
function
(
d
)
{
return
total_data
.
push
(
_
.
pick
(
d
,
[
field
,
'
date
'
]));
});
return
total_data
;
},
get_author_data
:
function
(
parsed_log
,
field
,
date_range
)
{
var
author_data
,
log
;
if
(
date_range
==
null
)
{
date_range
=
null
;
}
log
=
parsed_log
.
by_author
;
author_data
=
[];
_
.
each
(
log
,
(
function
(
_this
)
{
return
function
(
log_entry
)
{
var
parsed_log_entry
;
parsed_log_entry
=
_this
.
parse_log_entry
(
log_entry
,
field
,
date_range
);
if
(
!
_
.
isEmpty
(
parsed_log_entry
.
dates
))
{
return
author_data
.
push
(
parsed_log_entry
);
}
};
})(
this
));
return
_
.
sortBy
(
author_data
,
function
(
d
)
{
return
d
[
field
];
}).
reverse
();
},
parse_log_entry
:
function
(
log_entry
,
field
,
date_range
)
{
var
parsed_entry
;
parsed_entry
=
{};
parsed_entry
.
author_name
=
log_entry
.
author_name
;
parsed_entry
.
author_email
=
log_entry
.
author_email
;
parsed_entry
.
dates
=
{};
parsed_entry
.
commits
=
parsed_entry
.
additions
=
parsed_entry
.
deletions
=
0
;
_
.
each
(
_
.
omit
(
log_entry
,
'
author_name
'
,
'
author_email
'
),
(
function
(
_this
)
{
return
function
(
value
,
key
)
{
if
(
_this
.
in_range
(
value
.
date
,
date_range
))
{
parsed_entry
.
dates
[
value
.
date
]
=
value
[
field
];
parsed_entry
.
commits
+=
value
.
commits
;
parsed_entry
.
additions
+=
value
.
additions
;
return
parsed_entry
.
deletions
+=
value
.
deletions
;
}
};
})(
this
));
return
parsed_entry
;
},
in_range
:
function
(
date
,
date_range
)
{
var
ref
;
if
(
date_range
===
null
||
(
date_range
[
0
]
<=
(
ref
=
new
Date
(
date
))
&&
ref
<=
date_range
[
1
]))
{
return
true
;
}
else
{
return
false
;
}
}
;
}
).
call
(
window
)
;
}
};
spec/javascripts/graphs/stat_graph_contributors_graph_spec.js
浏览文件 @
9f6660b1
/* eslint-disable quotes, jasmine/no-suite-dupes, vars-on-top, no-var, max-len */
/* global d3 */
/* global ContributorsGraph */
/* global ContributorsMasterGraph */
/* eslint-disable quotes, jasmine/no-suite-dupes, vars-on-top, no-var */
require
(
'
~/graphs/stat_graph_contributors_graph
'
);
import
d3
from
'
d3
'
;
import
{
ContributorsGraph
,
ContributorsMasterGraph
}
from
'
~/graphs/stat_graph_contributors_graph
'
;
describe
(
"
ContributorsGraph
"
,
function
()
{
describe
(
"
#set_x_domain
"
,
function
()
{
...
...
spec/javascripts/graphs/stat_graph_contributors_util_spec.js
浏览文件 @
9f6660b1
/* eslint-disable quotes, no-var, camelcase, object-property-newline, comma-dangle, max-len, vars-on-top, quote-props */
/* global ContributorsStatGraphUtil */
require
(
'
~/graphs/stat_graph_contributors_util
'
)
;
import
ContributorsStatGraphUtil
from
'
~/graphs/stat_graph_contributors_util
'
;
describe
(
"
ContributorsStatGraphUtil
"
,
function
()
{
describe
(
"
#parse_log
"
,
function
()
{
...
...
spec/javascripts/graphs/stat_graph_spec.js
已删除
100644 → 0
浏览文件 @
c49ee361
/* eslint-disable quotes */
/* global StatGraph */
require
(
'
~/graphs/stat_graph
'
);
describe
(
"
StatGraph
"
,
function
()
{
describe
(
"
#get_log
"
,
function
()
{
it
(
"
returns log
"
,
function
()
{
StatGraph
.
log
=
"
test
"
;
expect
(
StatGraph
.
get_log
()).
toBe
(
"
test
"
);
});
});
describe
(
"
#set_log
"
,
function
()
{
it
(
"
sets the log
"
,
function
()
{
StatGraph
.
set_log
(
"
test
"
);
expect
(
StatGraph
.
log
).
toBe
(
"
test
"
);
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录