Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
1109a5ce
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,发现更多精彩内容 >>
提交
1109a5ce
编写于
12月 12, 2017
作者:
W
Winnie Hellmann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move dateTickFormat to separate module
上级
3b679ef9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
94 addition
and
26 deletion
+94
-26
app/assets/javascripts/graphs/stat_graph_contributors_graph.js
...ssets/javascripts/graphs/stat_graph_contributors_graph.js
+3
-17
app/assets/javascripts/lib/utils/tick_formats.js
app/assets/javascripts/lib/utils/tick_formats.js
+39
-0
spec/javascripts/helpers/locale_helper.js
spec/javascripts/helpers/locale_helper.js
+11
-0
spec/javascripts/lib/utils/tick_formats_spec.js
spec/javascripts/lib/utils/tick_formats_spec.js
+40
-0
spec/javascripts/locale/index_spec.js
spec/javascripts/locale/index_spec.js
+1
-9
未找到文件。
app/assets/javascripts/graphs/stat_graph_contributors_graph.js
浏览文件 @
1109a5ce
/* 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 */
/* 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
_
from
'
underscore
'
;
import
_
from
'
underscore
'
;
import
d3
from
'
d3
'
;
import
d3
from
'
d3
'
;
import
{
createDateTimeFormat
}
from
'
../locale
'
;
import
{
dateTickFormat
}
from
'
../lib/utils/tick_formats
'
;
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
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
;
const
hasProp
=
{}.
hasOwnProperty
;
const
dayFormat
=
createDateTimeFormat
({
month
:
'
short
'
,
day
:
'
numeric
'
});
const
monthFormat
=
createDateTimeFormat
({
month
:
'
long
'
});
const
yearFormat
=
createDateTimeFormat
({
year
:
'
numeric
'
});
const
xTickFormat
=
(
date
)
=>
{
if
(
date
.
getDate
()
!==
1
)
{
return
dayFormat
.
format
(
date
);
}
else
if
(
date
.
getMonth
()
>
0
)
{
return
monthFormat
.
format
(
date
);
}
else
{
return
yearFormat
.
format
(
date
);
}
};
export
const
ContributorsGraph
=
(
function
()
{
export
const
ContributorsGraph
=
(
function
()
{
function
ContributorsGraph
()
{}
function
ContributorsGraph
()
{}
...
@@ -152,7 +138,7 @@ export const ContributorsMasterGraph = (function(superClass) {
...
@@ -152,7 +138,7 @@ export const ContributorsMasterGraph = (function(superClass) {
this
.
x_axis
=
d3
.
svg
.
axis
()
this
.
x_axis
=
d3
.
svg
.
axis
()
.
scale
(
this
.
x
)
.
scale
(
this
.
x
)
.
orient
(
'
bottom
'
)
.
orient
(
'
bottom
'
)
.
tickFormat
(
x
TickFormat
);
.
tickFormat
(
date
TickFormat
);
return
this
.
y_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
y
).
orient
(
"
left
"
).
ticks
(
5
);
return
this
.
y_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
y
).
orient
(
"
left
"
).
ticks
(
5
);
};
};
...
@@ -244,7 +230,7 @@ export const ContributorsAuthorGraph = (function(superClass) {
...
@@ -244,7 +230,7 @@ export const ContributorsAuthorGraph = (function(superClass) {
.
scale
(
this
.
x
)
.
scale
(
this
.
x
)
.
orient
(
'
bottom
'
)
.
orient
(
'
bottom
'
)
.
ticks
(
8
)
.
ticks
(
8
)
.
tickFormat
(
x
TickFormat
);
.
tickFormat
(
date
TickFormat
);
return
this
.
y_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
y
).
orient
(
"
left
"
).
ticks
(
5
);
return
this
.
y_axis
=
d3
.
svg
.
axis
().
scale
(
this
.
y
).
orient
(
"
left
"
).
ticks
(
5
);
};
};
...
...
app/assets/javascripts/lib/utils/tick_formats.js
0 → 100644
浏览文件 @
1109a5ce
import
{
createDateTimeFormat
}
from
'
../../locale
'
;
let
dateTimeFormats
;
export
const
initDateFormats
=
()
=>
{
const
dayFormat
=
createDateTimeFormat
({
month
:
'
short
'
,
day
:
'
numeric
'
});
const
monthFormat
=
createDateTimeFormat
({
month
:
'
long
'
});
const
yearFormat
=
createDateTimeFormat
({
year
:
'
numeric
'
});
dateTimeFormats
=
{
dayFormat
,
monthFormat
,
yearFormat
,
};
};
initDateFormats
();
/**
Formats a localized date in way that it can be used for d3.js axis.tickFormat().
That is, it displays
- 4-digit for first of January
- full month name for first of every month
- day and abbreviated month otherwise
see also https://github.com/d3/d3-3.x-api-reference/blob/master/SVG-Axes.md#tickFormat
*/
export
const
dateTickFormat
=
(
date
)
=>
{
if
(
date
.
getDate
()
!==
1
)
{
return
dateTimeFormats
.
dayFormat
.
format
(
date
);
}
if
(
date
.
getMonth
()
>
0
)
{
return
dateTimeFormats
.
monthFormat
.
format
(
date
);
}
return
dateTimeFormats
.
yearFormat
.
format
(
date
);
};
spec/javascripts/helpers/locale_helper.js
0 → 100644
浏览文件 @
1109a5ce
/* eslint-disable import/prefer-default-export */
export
const
setLanguage
=
(
languageCode
)
=>
{
const
htmlElement
=
document
.
querySelector
(
'
html
'
);
if
(
languageCode
)
{
htmlElement
.
setAttribute
(
'
lang
'
,
languageCode
);
}
else
{
htmlElement
.
removeAttribute
(
'
lang
'
);
}
};
spec/javascripts/lib/utils/tick_formats_spec.js
0 → 100644
浏览文件 @
1109a5ce
import
{
dateTickFormat
,
initDateFormats
}
from
'
~/lib/utils/tick_formats
'
;
import
{
setLanguage
}
from
'
../../helpers/locale_helper
'
;
describe
(
'
tick formats
'
,
()
=>
{
describe
(
'
dateTickFormat
'
,
()
=>
{
beforeAll
(()
=>
{
setLanguage
(
'
de
'
);
initDateFormats
();
});
afterAll
(()
=>
{
setLanguage
(
null
);
});
it
(
'
returns year for first of January
'
,
()
=>
{
const
tick
=
dateTickFormat
(
new
Date
(
'
2001-01-01
'
));
expect
(
tick
).
toBe
(
'
2001
'
);
});
it
(
'
returns month for first of February
'
,
()
=>
{
const
tick
=
dateTickFormat
(
new
Date
(
'
2001-02-01
'
));
expect
(
tick
).
toBe
(
'
Februar
'
);
});
it
(
'
returns day and month for second of February
'
,
()
=>
{
const
tick
=
dateTickFormat
(
new
Date
(
'
2001-02-02
'
));
expect
(
tick
).
toBe
(
'
2. Feb.
'
);
});
it
(
'
ignores time
'
,
()
=>
{
const
tick
=
dateTickFormat
(
new
Date
(
'
2001-02-02 12:34:56
'
));
expect
(
tick
).
toBe
(
'
2. Feb.
'
);
});
});
});
spec/javascripts/locale/index_spec.js
浏览文件 @
1109a5ce
import
{
createDateTimeFormat
,
languageCode
}
from
'
~/locale
'
;
import
{
createDateTimeFormat
,
languageCode
}
from
'
~/locale
'
;
const
setLanguage
=
(
languageCode
)
=>
{
import
{
setLanguage
}
from
'
../helpers/locale_helper
'
;
const
htmlElement
=
document
.
querySelector
(
'
html
'
);
if
(
languageCode
)
{
htmlElement
.
setAttribute
(
'
lang
'
,
languageCode
);
}
else
{
htmlElement
.
removeAttribute
(
'
lang
'
);
}
};
describe
(
'
locale
'
,
()
=>
{
describe
(
'
locale
'
,
()
=>
{
afterEach
(()
=>
{
afterEach
(()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录