Navigation Menu

Skip to content

Commit

Permalink
Update chart.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonBarnabe committed Nov 5, 2016
1 parent 32615a8 commit fe66165
Show file tree
Hide file tree
Showing 109 changed files with 37,079 additions and 1,360 deletions.
40 changes: 20 additions & 20 deletions app/views/scripts/stats.html.erb
Expand Up @@ -20,28 +20,11 @@ label_skip = max_labels > @stats.keys.length ? 1 : (@stats.keys.length / 30)
<h3><%=t(heading_key)%></h3>
<div id="<%=container_id%>"></div>

<%
data = @stats.map{|k, v| [k, v[data_key]]}.to_h

max_installs = data.values.select{|v| !v.nil?}.max
if max_installs > 0
x = Math.log10(max_installs).floor
scale_top=(max_installs/(10.0**x)).ceil*10**x
scale_steps = [10,max_installs].min
scale_step_width = scale_top / scale_steps
else
scale_top = 1
scale_steps = 1
scale_step_width = 1
end

<% data = @stats.map{|k, v| [k, v[data_key]]}.to_h
%>
<script>
var data = {
labels: [<%=data.keys.each_with_index.map{ |d, i|
'"' + ((i % label_skip == 0) ? escape_javascript(d.to_s): '') + '"'
}.join(',').html_safe%>
],
labels: [<%=data.keys.each.map{|d| '"' + escape_javascript(d.to_s) + '"'}.join(',').html_safe%>],
datasets: [{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
Expand All @@ -57,7 +40,24 @@ label_skip = max_labels > @stats.keys.length ? 1 : (@stats.keys.length / 30)
container.appendChild(canvas)

var ctx = canvas.getContext("2d");
var myNewChart = new Chart(ctx).Bar(data, {barValueSpacing: 0, scaleOverride: true, scaleStartValue: 0, scaleSteps: <%=scale_steps%>, scaleStepWidth: <%=scale_step_width%>});
var myNewChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
scaleStartValue: 0,
legend: {display: false},
scales: {
xAxes: [{
gridLines: {display: false}
}],
yAxes: [{
ticks: {
suggestedMax: 10
}
}]
}
}
});
</script>
<% end %>

Expand Down

Large diffs are not rendered by default.

0 comments on commit fe66165

Please sign in to comment.