summaryrefslogtreecommitdiff
path: root/app/views/projects/graphs
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-24 09:40:32 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-24 09:40:32 +0200
commitea583955252d04ad89819c335e77f811b3d3b3c7 (patch)
tree66480eeecf3c6f06707dfe2e334230143ec1621c /app/views/projects/graphs
parentd538955ac89c0bffd5b0d5ebff73f81c4efb21ee (diff)
parenta58c6e9a9561ffbb3d16a3a9a45bd90a34735b50 (diff)
downloadgitlab-ce-ea583955252d04ad89819c335e77f811b3d3b3c7.tar.gz
Merge branch 'master' into move-ci-charts
Diffstat (limited to 'app/views/projects/graphs')
-rw-r--r--app/views/projects/graphs/commits.html.haml76
1 files changed, 35 insertions, 41 deletions
diff --git a/app/views/projects/graphs/commits.html.haml b/app/views/projects/graphs/commits.html.haml
index bf0cac539b8..112be875b6b 100644
--- a/app/views/projects/graphs/commits.html.haml
+++ b/app/views/projects/graphs/commits.html.haml
@@ -32,61 +32,55 @@
%div
%p.slead
Commits per day of month
- %canvas#month-chart{width: 800, height: 400}
+ %canvas#month-chart
.row
.col-md-6
%div
%p.slead
Commits per day hour (UTC)
- %canvas#hour-chart{width: 800, height: 400}
+ %canvas#hour-chart
.col-md-6
%div
%p.slead
Commits per weekday
- %canvas#weekday-chart{width: 800, height: 400}
+ %canvas#weekday-chart
:coffeescript
- data = {
- labels : #{@commits_per_time.keys.to_json},
- datasets : [{
- fillColor : "rgba(220,220,220,0.5)",
- strokeColor : "rgba(220,220,220,1)",
- barStrokeWidth: 1,
- barValueSpacing: 1,
- barDatasetSpacing: 1,
- data : #{@commits_per_time.values.to_json}
- }]
- }
+ responsiveChart = (selector, data) ->
+ options = { "scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2, maintainAspectRatio: false }
- ctx = $("#hour-chart").get(0).getContext("2d");
- new Chart(ctx).Bar(data,{"scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2})
+ # get selector by context
+ ctx = selector.get(0).getContext("2d")
+ # pointing parent container to make chart.js inherit its width
+ container = $(selector).parent()
- data = {
- labels : #{@commits_per_week_days.keys.to_json},
- datasets : [{
- fillColor : "rgba(220,220,220,0.5)",
- strokeColor : "rgba(220,220,220,1)",
- barStrokeWidth: 1,
- barValueSpacing: 1,
- barDatasetSpacing: 1,
- data : #{@commits_per_week_days.values.to_json}
- }]
- }
+ generateChart = ->
+ selector.attr('width', $(container).width())
+ new Chart(ctx).Bar(data, options)
+
+ # enabling auto-resizing
+ $(window).resize( generateChart )
- ctx = $("#weekday-chart").get(0).getContext("2d");
- new Chart(ctx).Bar(data,{"scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2})
+ generateChart()
- data = {
- labels : #{@commits_per_month.keys.to_json},
- datasets : [{
- fillColor : "rgba(220,220,220,0.5)",
- strokeColor : "rgba(220,220,220,1)",
- barStrokeWidth: 1,
- barValueSpacing: 1,
- barDatasetSpacing: 1,
- data : #{@commits_per_month.values.to_json}
- }]
+ chartData = (keys, values) ->
+ data = {
+ labels : keys,
+ datasets : [{
+ fillColor : "rgba(220,220,220,0.5)",
+ strokeColor : "rgba(220,220,220,1)",
+ barStrokeWidth: 1,
+ barValueSpacing: 1,
+ barDatasetSpacing: 1,
+ data : values
+ }]
}
- ctx = $("#month-chart").get(0).getContext("2d");
- new Chart(ctx).Bar(data, {"scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2})
+ hourData = chartData(#{@commits_per_time.keys.to_json}, #{@commits_per_time.values.to_json})
+ responsiveChart($('#hour-chart'), hourData)
+
+ dayData = chartData(#{@commits_per_week_days.keys.to_json}, #{@commits_per_week_days.values.to_json})
+ responsiveChart($('#weekday-chart'), dayData)
+
+ monthData = chartData(#{@commits_per_month.keys.to_json}, #{@commits_per_month.values.to_json})
+ responsiveChart($('#month-chart'), monthData)