debian-mirror-gitlab/app/assets/javascripts/pages/projects/pipelines/charts/index.js

67 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-27 19:54:05 +05:30
import Chart from 'chart.js';
2019-05-30 16:15:17 +05:30
const options = {
scaleOverlay: true,
responsive: true,
maintainAspectRatio: false,
};
2018-03-27 19:54:05 +05:30
2019-05-30 16:15:17 +05:30
const buildChart = chartScope => {
2018-03-27 19:54:05 +05:30
const data = {
labels: chartScope.labels,
2018-12-13 13:39:08 +05:30
datasets: [
{
2019-05-30 16:15:17 +05:30
fillColor: '#707070',
strokeColor: '#707070',
pointColor: '#707070',
pointStrokeColor: '#EEE',
data: chartScope.totalValues,
2018-12-13 13:39:08 +05:30
},
{
2019-05-30 16:15:17 +05:30
fillColor: '#1aaa55',
strokeColor: '#1aaa55',
pointColor: '#1aaa55',
pointStrokeColor: '#fff',
data: chartScope.successValues,
2018-12-13 13:39:08 +05:30
},
2018-03-27 19:54:05 +05:30
],
};
2018-12-13 13:39:08 +05:30
const ctx = $(`#${chartScope.scope}Chart`)
.get(0)
.getContext('2d');
2018-03-27 19:54:05 +05:30
2019-05-30 16:15:17 +05:30
new Chart(ctx).Line(data, options);
2018-03-27 19:54:05 +05:30
};
2019-05-30 16:15:17 +05:30
document.addEventListener('DOMContentLoaded', () => {
const chartTimesData = JSON.parse(document.getElementById('pipelinesTimesChartsData').innerHTML);
const chartsData = JSON.parse(document.getElementById('pipelinesChartsData').innerHTML);
2018-03-27 19:54:05 +05:30
const data = {
labels: chartTimesData.labels,
2018-12-13 13:39:08 +05:30
datasets: [
{
2019-05-30 16:15:17 +05:30
fillColor: 'rgba(220,220,220,0.5)',
strokeColor: 'rgba(220,220,220,1)',
barStrokeWidth: 1,
2018-12-13 13:39:08 +05:30
barValueSpacing: 1,
barDatasetSpacing: 1,
data: chartTimesData.values,
},
],
2018-03-27 19:54:05 +05:30
};
2019-05-30 16:15:17 +05:30
if (window.innerWidth < 768) {
// Scale fonts if window width lower than 768px (iPad portrait)
options.scaleFontSize = 8;
}
new Chart(
2018-12-13 13:39:08 +05:30
$('#build_timesChart')
.get(0)
.getContext('2d'),
2019-05-30 16:15:17 +05:30
).Bar(data, options);
2018-03-27 19:54:05 +05:30
2019-05-30 16:15:17 +05:30
chartsData.forEach(scope => buildChart(scope));
2018-03-27 19:54:05 +05:30
});