Skip to content

Commit 1c18e60

Browse files
pietroalbiniJoshua Nelson
authored and
Joshua Nelson
committed
web: switch to chart.js for charts
1 parent e9f300a commit 1c18e60

File tree

4 files changed

+60
-31
lines changed

4 files changed

+60
-31
lines changed

templates/releases/activity.html

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,63 @@
99

1010
{%- block body -%}
1111
<div class="container">
12-
<div id="releases-activity-chart"></div>
12+
<canvas id="releases-activity-chart"></canvas>
1313
</div>
1414
{%- endblock body -%}
1515

1616
{# TODO: Do this with tera alone #}
17+
{%- block css -%}
18+
<link rel="stylesheet" href="/-/static/chartjs/chart.min.css">
19+
{%- endblock -%}
1720
{%- block javascript -%}
18-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.2.5/highcharts.js" type="text/javascript"
19-
charset="utf-8"></script>
21+
<script src="/-/static/chartjs/chart.min.js" type="text/javascript"></script>
2022

21-
<script type="text/javascript" charset="utf-8">
22-
new Highcharts.Chart({
23-
chart: {
24-
renderTo: 'releases-activity-chart',
25-
type: 'line'
26-
},
27-
title: {
28-
text: 'Monthly release activity',
29-
x: -20 //center
30-
},
31-
xAxis: {
32-
categories: [
23+
<script type="text/javascript">
24+
// We're including the CSS file manually to avoid issues with the CSP.
25+
Chart.platform.disableCSSInjection = true;
26+
27+
var ctx = document.getElementById("releases-activity-chart").getContext("2d");
28+
new Chart(ctx, {
29+
type: "line",
30+
data: {
31+
labels: [
3332
{% if activity_data.dates -%}
3433
{%- for date in activity_data.dates -%}
3534
{{ "'" ~ date ~ "'," }}
3635
{%- endfor -%}
3736
{%- endif %}
37+
],
38+
datasets: [
39+
{
40+
label: "Releases",
41+
borderColor: "#4d76ae",
42+
backgroundColor: "#4d76ae",
43+
fill: false,
44+
data: [{{ activity_data.counts | default(value=[]) | join(sep=", ") }}],
45+
},
46+
{
47+
label: "Build Failures",
48+
borderColor: "#434348",
49+
backgroundColor: "#434348",
50+
fill: false,
51+
data: [{{ activity_data.failures | default(value=[]) | join(sep=", ") }}],
52+
},
3853
]
3954
},
40-
yAxis: {
41-
title: {
42-
text: 'Crates'
55+
options: {
56+
animation: false,
57+
tooltips: {
58+
mode: "index",
59+
intersect: false,
4360
},
44-
plotLines: [{
45-
value: 0,
46-
width: 1,
47-
color: '#808080'
48-
}]
49-
},
50-
series: [{
51-
name: 'Releases',
52-
data: [{{ activity_data.counts | default(value=[]) | join(sep=", ") }}]
53-
}, {
54-
name: 'Build Failures',
55-
data: [{{ activity_data.failures | default(value=[]) | join(sep=", ") }}]
56-
}]
61+
scales: {
62+
yAxes: [{
63+
ticks: {
64+
beginAtZero: true,
65+
}
66+
}]
67+
}
68+
}
5769
});
5870
</script>
5971
{%- endblock javascript -%}

vendor/chartjs/LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Chart.js Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

vendor/chartjs/chart.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/chartjs/chart.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)