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

158 lines
4.2 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { GlColumnChart } from '@gitlab/ui/dist/charts';
2021-01-03 14:25:43 +05:30
import Vue from 'vue';
import { waitForCSSLoaded } from '~/helpers/startup_css_helper';
2020-10-24 23:57:45 +05:30
import { __ } from '~/locale';
2020-06-23 00:09:42 +05:30
import CodeCoverage from '../components/code_coverage.vue';
2020-03-13 15:44:24 +05:30
import SeriesDataMixin from './series_data_mixin';
2019-07-07 11:18:12 +05:30
2021-01-29 00:20:46 +05:30
const seriesDataToBarData = raw => Object.entries(raw).map(([name, data]) => ({ name, data }));
2017-09-10 17:25:29 +05:30
document.addEventListener('DOMContentLoaded', () => {
2020-11-24 15:15:51 +05:30
waitForCSSLoaded(() => {
const languagesContainer = document.getElementById('js-languages-chart');
const codeCoverageContainer = document.getElementById('js-code-coverage-chart');
const monthContainer = document.getElementById('js-month-chart');
const weekdayContainer = document.getElementById('js-weekday-chart');
const hourContainer = document.getElementById('js-hour-chart');
const LANGUAGE_CHART_HEIGHT = 300;
const reorderWeekDays = (weekDays, firstDayOfWeek = 0) => {
if (firstDayOfWeek === 0) {
return weekDays;
}
2019-07-07 11:18:12 +05:30
2020-11-24 15:15:51 +05:30
return Object.keys(weekDays).reduce((acc, dayName, idx, arr) => {
const reorderedDayName = arr[(idx + firstDayOfWeek) % arr.length];
2017-09-10 17:25:29 +05:30
2020-11-24 15:15:51 +05:30
return {
...acc,
[reorderedDayName]: weekDays[reorderedDayName],
};
}, {});
};
2019-03-02 22:35:43 +05:30
2020-11-24 15:15:51 +05:30
// eslint-disable-next-line no-new
new Vue({
el: languagesContainer,
components: {
GlColumnChart,
2020-03-13 15:44:24 +05:30
},
2020-11-24 15:15:51 +05:30
data() {
return {
chartData: JSON.parse(languagesContainer.dataset.chartData),
};
},
computed: {
seriesData() {
2021-01-29 00:20:46 +05:30
return [{ name: 'full', data: this.chartData.map(d => [d.label, d.value]) }];
2020-03-13 15:44:24 +05:30
},
2020-11-24 15:15:51 +05:30
},
render(h) {
return h(GlColumnChart, {
props: {
2021-01-29 00:20:46 +05:30
bars: this.seriesData,
2020-11-24 15:15:51 +05:30
xAxisTitle: __('Used programming language'),
yAxisTitle: __('Percentage'),
xAxisType: 'category',
},
attrs: {
height: LANGUAGE_CHART_HEIGHT,
},
});
},
});
2017-09-10 17:25:29 +05:30
2020-11-24 15:15:51 +05:30
// eslint-disable-next-line no-new
new Vue({
el: codeCoverageContainer,
render(h) {
return h(CodeCoverage, {
props: {
graphEndpoint: codeCoverageContainer.dataset?.graphEndpoint,
},
});
},
});
2020-06-23 00:09:42 +05:30
2020-11-24 15:15:51 +05:30
// eslint-disable-next-line no-new
new Vue({
el: monthContainer,
components: {
GlColumnChart,
},
mixins: [SeriesDataMixin],
data() {
return {
chartData: JSON.parse(monthContainer.dataset.chartData),
};
},
render(h) {
return h(GlColumnChart, {
props: {
2021-01-29 00:20:46 +05:30
bars: seriesDataToBarData(this.seriesData),
2020-11-24 15:15:51 +05:30
xAxisTitle: __('Day of month'),
yAxisTitle: __('No. of commits'),
xAxisType: 'category',
},
});
},
});
2017-09-10 17:25:29 +05:30
2020-11-24 15:15:51 +05:30
// eslint-disable-next-line no-new
new Vue({
el: weekdayContainer,
components: {
GlColumnChart,
2019-07-07 11:18:12 +05:30
},
2020-11-24 15:15:51 +05:30
data() {
return {
chartData: JSON.parse(weekdayContainer.dataset.chartData),
};
},
computed: {
seriesData() {
const weekDays = reorderWeekDays(this.chartData, gon.first_day_of_week);
const data = Object.keys(weekDays).reduce((acc, key) => {
acc.push([key, weekDays[key]]);
return acc;
}, []);
2021-01-29 00:20:46 +05:30
return [{ name: 'full', data }];
2020-03-13 15:44:24 +05:30
},
2020-11-24 15:15:51 +05:30
},
render(h) {
return h(GlColumnChart, {
props: {
2021-01-29 00:20:46 +05:30
bars: this.seriesData,
2020-11-24 15:15:51 +05:30
xAxisTitle: __('Weekday'),
yAxisTitle: __('No. of commits'),
xAxisType: 'category',
},
});
},
});
2020-03-13 15:44:24 +05:30
2020-11-24 15:15:51 +05:30
// eslint-disable-next-line no-new
new Vue({
el: hourContainer,
components: {
GlColumnChart,
},
mixins: [SeriesDataMixin],
data() {
return {
chartData: JSON.parse(hourContainer.dataset.chartData),
};
},
render(h) {
return h(GlColumnChart, {
props: {
2021-01-29 00:20:46 +05:30
bars: seriesDataToBarData(this.seriesData),
2020-11-24 15:15:51 +05:30
xAxisTitle: __('Hour (UTC)'),
yAxisTitle: __('No. of commits'),
xAxisType: 'category',
},
});
},
});
2020-03-13 15:44:24 +05:30
});
2017-09-10 17:25:29 +05:30
});