Commit 32cb9d21 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'make-commit-graphs-responsive' into 'master'

Make commit graphs responsive to window width changes

Closes #2653

See merge request !1395
parents cfe66340 ef2679d0
......@@ -5,6 +5,7 @@ v 8.1.0 (unreleased)
v 8.0.1
- Improve CI migration procedure and documentation
- Make commit graphs responsive to window width changes (Stan Hu)
v 8.0.0
- Fix Markdown links not showing up in dashboard activity feed (Stan Hu)
......
......@@ -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()
chartData = (keys, values) ->
data = {
labels : #{@commits_per_month.keys.to_json},
labels : keys,
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}
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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment