2024-02-24 07:41:24 +08:00
|
|
|
<script>
|
|
|
|
import {SvgIcon} from '../svg.js';
|
|
|
|
import {
|
|
|
|
Chart,
|
|
|
|
Legend,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
PointElement,
|
|
|
|
LineElement,
|
|
|
|
Filler,
|
|
|
|
} from 'chart.js';
|
|
|
|
import {GET} from '../modules/fetch.js';
|
|
|
|
import {Line as ChartLine} from 'vue-chartjs';
|
|
|
|
import {
|
|
|
|
startDaysBetween,
|
|
|
|
firstStartDateAfterDate,
|
|
|
|
fillEmptyStartDaysWithZeroes,
|
|
|
|
} from '../utils/time.js';
|
|
|
|
import {chartJsColors} from '../utils/color.js';
|
|
|
|
import {sleep} from '../utils.js';
|
|
|
|
import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm';
|
|
|
|
|
|
|
|
const {pageData} = window.config;
|
|
|
|
|
|
|
|
Chart.defaults.color = chartJsColors.text;
|
|
|
|
Chart.defaults.borderColor = chartJsColors.border;
|
|
|
|
|
|
|
|
Chart.register(
|
|
|
|
TimeScale,
|
|
|
|
LinearScale,
|
|
|
|
Legend,
|
|
|
|
PointElement,
|
|
|
|
LineElement,
|
|
|
|
Filler,
|
|
|
|
);
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {ChartLine, SvgIcon},
|
|
|
|
props: {
|
|
|
|
locale: {
|
|
|
|
type: Object,
|
2024-03-22 22:06:53 +08:00
|
|
|
required: true,
|
2024-02-24 07:41:24 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
isLoading: false,
|
|
|
|
errorText: '',
|
|
|
|
repoLink: pageData.repoLink || [],
|
|
|
|
data: [],
|
|
|
|
}),
|
|
|
|
mounted() {
|
|
|
|
this.fetchGraphData();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async fetchGraphData() {
|
|
|
|
this.isLoading = true;
|
|
|
|
try {
|
|
|
|
let response;
|
|
|
|
do {
|
|
|
|
response = await GET(`${this.repoLink}/activity/code-frequency/data`);
|
|
|
|
if (response.status === 202) {
|
|
|
|
await sleep(1000); // wait for 1 second before retrying
|
|
|
|
}
|
|
|
|
} while (response.status === 202);
|
|
|
|
if (response.ok) {
|
|
|
|
this.data = await response.json();
|
|
|
|
const weekValues = Object.values(this.data);
|
|
|
|
const start = weekValues[0].week;
|
|
|
|
const end = firstStartDateAfterDate(new Date());
|
2024-05-06 10:01:22 +08:00
|
|
|
const startDays = startDaysBetween(start, end);
|
2024-02-24 07:41:24 +08:00
|
|
|
this.data = fillEmptyStartDaysWithZeroes(startDays, this.data);
|
|
|
|
this.errorText = '';
|
|
|
|
} else {
|
|
|
|
this.errorText = response.statusText;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
this.errorText = err.message;
|
|
|
|
} finally {
|
|
|
|
this.isLoading = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
toGraphData(data) {
|
|
|
|
return {
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
data: data.map((i) => ({x: i.week, y: i.additions})),
|
|
|
|
pointRadius: 0,
|
|
|
|
pointHitRadius: 0,
|
|
|
|
fill: true,
|
|
|
|
label: 'Additions',
|
|
|
|
backgroundColor: chartJsColors['additions'],
|
|
|
|
borderWidth: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: data.map((i) => ({x: i.week, y: -i.deletions})),
|
|
|
|
pointRadius: 0,
|
|
|
|
pointHitRadius: 0,
|
|
|
|
fill: true,
|
|
|
|
label: 'Deletions',
|
|
|
|
backgroundColor: chartJsColors['deletions'],
|
|
|
|
borderWidth: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getOptions() {
|
|
|
|
return {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
animation: true,
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
display: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
type: 'time',
|
|
|
|
grid: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
time: {
|
|
|
|
minUnit: 'month',
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
maxRotation: 0,
|
2024-03-22 22:06:53 +08:00
|
|
|
maxTicksLimit: 12,
|
2024-02-24 07:41:24 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
ticks: {
|
2024-03-22 22:06:53 +08:00
|
|
|
maxTicksLimit: 6,
|
2024-02-24 07:41:24 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<div>
|
2024-03-23 03:51:29 +08:00
|
|
|
<div class="ui header tw-flex tw-items-center tw-justify-between">
|
2024-02-24 07:41:24 +08:00
|
|
|
{{ isLoading ? locale.loadingTitle : errorText ? locale.loadingTitleFailed: `Code frequency over the history of ${repoLink.slice(1)}` }}
|
|
|
|
</div>
|
2024-03-22 21:45:10 +08:00
|
|
|
<div class="tw-flex ui segment main-graph">
|
2024-03-18 22:47:05 +08:00
|
|
|
<div v-if="isLoading || errorText !== ''" class="gt-tc tw-m-auto">
|
2024-02-24 07:41:24 +08:00
|
|
|
<div v-if="isLoading">
|
Migrate margin and padding helpers to tailwind (#30043)
This will conclude the refactor of 1:1 class replacements to tailwind,
except `gt-hidden`. Commands ran:
```bash
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-0#tw-$1$2-0#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-1#tw-$1$2-0.5#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-2#tw-$1$2-1#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-3#tw-$1$2-2#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-4#tw-$1$2-4#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-5#tw-$1$2-8#g' {web_src/js,templates,routers,services}/**/*
```
2024-03-25 00:42:49 +08:00
|
|
|
<SvgIcon name="octicon-sync" class="tw-mr-2 job-status-rotate"/>
|
2024-02-24 07:41:24 +08:00
|
|
|
{{ locale.loadingInfo }}
|
|
|
|
</div>
|
|
|
|
<div v-else class="text red">
|
|
|
|
<SvgIcon name="octicon-x-circle-fill"/>
|
|
|
|
{{ errorText }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ChartLine
|
|
|
|
v-memo="data" v-if="data.length !== 0"
|
|
|
|
:data="toGraphData(data)" :options="getOptions()"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<style scoped>
|
|
|
|
.main-graph {
|
|
|
|
height: 440px;
|
|
|
|
}
|
|
|
|
</style>
|