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