Make commit graphs responsive to window width changes

Closes #2653
This commit is contained in:
Stan Hu 2015-09-22 11:17:36 -07:00
parent 9e1392553b
commit ef2679d0b9
2 changed files with 38 additions and 43 deletions

View file

@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.0.1 v 8.0.1
- Improve CI migration procedure and documentation - Improve CI migration procedure and documentation
- Make commit graphs responsive to window width changes (Stan Hu)
v 8.0.0 v 8.0.0
- Fix Markdown links not showing up in dashboard activity feed (Stan Hu) - Fix Markdown links not showing up in dashboard activity feed (Stan Hu)

View file

@ -32,61 +32,55 @@
%div %div
%p.slead %p.slead
Commits per day of month Commits per day of month
%canvas#month-chart{width: 800, height: 400} %canvas#month-chart
.row .row
.col-md-6 .col-md-6
%div %div
%p.slead %p.slead
Commits per day hour (UTC) Commits per day hour (UTC)
%canvas#hour-chart{width: 800, height: 400} %canvas#hour-chart
.col-md-6 .col-md-6
%div %div
%p.slead %p.slead
Commits per weekday Commits per weekday
%canvas#weekday-chart{width: 800, height: 400} %canvas#weekday-chart
:coffeescript :coffeescript
data = { responsiveChart = (selector, data) ->
labels : #{@commits_per_time.keys.to_json}, options = { "scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2, maintainAspectRatio: false }
datasets : [{
fillColor : "rgba(220,220,220,0.5)", # get selector by context
strokeColor : "rgba(220,220,220,1)", ctx = selector.get(0).getContext("2d")
barStrokeWidth: 1, # pointing parent container to make chart.js inherit its width
barValueSpacing: 1, container = $(selector).parent()
barDatasetSpacing: 1,
data : #{@commits_per_time.values.to_json} generateChart = ->
}] selector.attr('width', $(container).width())
new Chart(ctx).Bar(data, options)
# enabling auto-resizing
$(window).resize( generateChart )
generateChart()
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 = $("#hour-chart").get(0).getContext("2d"); hourData = chartData(#{@commits_per_time.keys.to_json}, #{@commits_per_time.values.to_json})
new Chart(ctx).Bar(data,{"scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2}) responsiveChart($('#hour-chart'), hourData)
data = { dayData = chartData(#{@commits_per_week_days.keys.to_json}, #{@commits_per_week_days.values.to_json})
labels : #{@commits_per_week_days.keys.to_json}, responsiveChart($('#weekday-chart'), dayData)
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}
}]
}
ctx = $("#weekday-chart").get(0).getContext("2d"); monthData = chartData(#{@commits_per_month.keys.to_json}, #{@commits_per_month.values.to_json})
new Chart(ctx).Bar(data,{"scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2}) responsiveChart($('#month-chart'), monthData)
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}
}]
}
ctx = $("#month-chart").get(0).getContext("2d");
new Chart(ctx).Bar(data, {"scaleOverlay": true, responsive: true, pointHitDetectionRadius: 2})