2020-01-20 10:07:30 +00:00
|
|
|
<script>
|
2024-07-18 20:05:02 +00:00
|
|
|
import {Bar} from 'vue-chartjs';
|
|
|
|
import {
|
|
|
|
Chart,
|
|
|
|
Tooltip,
|
|
|
|
BarElement,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
} from 'chart.js';
|
|
|
|
import {chartJsColors} from '../utils/color.js';
|
2023-03-14 04:09:06 +00:00
|
|
|
import {createApp} from 'vue';
|
2020-01-20 10:07:30 +00:00
|
|
|
|
2024-07-18 20:05:02 +00:00
|
|
|
Chart.defaults.color = chartJsColors.text;
|
|
|
|
Chart.defaults.borderColor = chartJsColors.border;
|
|
|
|
|
|
|
|
Chart.register(
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
BarElement,
|
|
|
|
Tooltip,
|
|
|
|
);
|
|
|
|
|
2021-10-15 02:35:26 +00:00
|
|
|
const sfc = {
|
2024-07-18 20:05:02 +00:00
|
|
|
components: {Bar},
|
|
|
|
props: {
|
|
|
|
locale: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2020-11-07 15:11:09 +00:00
|
|
|
data: () => ({
|
|
|
|
colors: {
|
|
|
|
barColor: 'green',
|
2020-01-20 10:07:30 +00:00
|
|
|
},
|
2021-10-15 02:35:26 +00:00
|
|
|
|
|
|
|
// possible keys:
|
|
|
|
// * avatar_link: (...)
|
|
|
|
// * commits: (...)
|
|
|
|
// * home_link: (...)
|
|
|
|
// * login: (...)
|
|
|
|
// * name: (...)
|
|
|
|
activityTopAuthors: window.config.pageData.repoActivityTopAuthors || [],
|
2024-07-18 20:05:02 +00:00
|
|
|
i18nCommitActivity: this,
|
2020-11-07 15:11:09 +00:00
|
|
|
}),
|
2024-07-18 20:05:02 +00:00
|
|
|
methods: {
|
2021-10-15 02:35:26 +00:00
|
|
|
graphPoints() {
|
2024-07-18 20:05:02 +00:00
|
|
|
return {
|
|
|
|
datasets: [{
|
|
|
|
label: this.locale.commitActivity,
|
|
|
|
data: this.activityTopAuthors.map((item) => item.commits),
|
|
|
|
backgroundColor: this.colors.barColor,
|
|
|
|
barThickness: 40,
|
|
|
|
borderWidth: 0,
|
|
|
|
tension: 0.3,
|
|
|
|
}],
|
|
|
|
labels: this.activityTopAuthors.map((item) => item.name),
|
|
|
|
};
|
2020-01-20 10:07:30 +00:00
|
|
|
},
|
2024-07-18 20:05:02 +00:00
|
|
|
getOptions() {
|
|
|
|
return {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
animation: true,
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
type: 'category',
|
|
|
|
grid: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
color: 'transparent', // Disable drawing of labels on the x-axis.
|
|
|
|
},
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
ticks: {
|
|
|
|
stepSize: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-01-20 10:07:30 +00:00
|
|
|
},
|
2020-11-07 15:11:09 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2021-10-15 02:35:26 +00:00
|
|
|
const refStyle = window.getComputedStyle(this.$refs.style);
|
|
|
|
this.colors.barColor = refStyle.backgroundColor;
|
2024-07-18 20:05:02 +00:00
|
|
|
|
|
|
|
for (const item of this.activityTopAuthors) {
|
|
|
|
const img = new Image();
|
|
|
|
img.src = item.avatar_link;
|
|
|
|
item.avatar_img = img;
|
|
|
|
}
|
|
|
|
|
|
|
|
Chart.register({
|
|
|
|
id: 'image_label',
|
|
|
|
afterDraw: (chart) => {
|
|
|
|
const xAxis = chart.boxes[0];
|
|
|
|
const yAxis = chart.boxes[1];
|
|
|
|
for (const [index] of xAxis.ticks.entries()) {
|
|
|
|
const x = xAxis.getPixelForTick(index);
|
|
|
|
const img = this.activityTopAuthors[index].avatar_img;
|
|
|
|
|
|
|
|
chart.ctx.save();
|
|
|
|
chart.ctx.drawImage(img, 0, 0, img.naturalWidth, img.naturalHeight, x - 10, yAxis.bottom + 10, 20, 20);
|
|
|
|
chart.ctx.restore();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeEvent: (chart, args) => {
|
|
|
|
const event = args.event;
|
|
|
|
if (event.type !== 'mousemove' && event.type !== 'click') return;
|
|
|
|
|
|
|
|
const yAxis = chart.boxes[1];
|
|
|
|
if (event.y < yAxis.bottom + 10 || event.y > yAxis.bottom + 30) {
|
|
|
|
chart.canvas.style.cursor = '';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const xAxis = chart.boxes[0];
|
|
|
|
const pointIdx = xAxis.ticks.findIndex((_, index) => {
|
|
|
|
const x = xAxis.getPixelForTick(index);
|
|
|
|
return event.x >= x - 10 && event.x <= x + 10;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (pointIdx === -1) {
|
|
|
|
chart.canvas.style.cursor = '';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
chart.canvas.style.cursor = 'pointer';
|
|
|
|
if (event.type === 'click' && this.activityTopAuthors[pointIdx].home_link) {
|
|
|
|
window.location.href = this.activityTopAuthors[pointIdx].home_link;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2024-03-22 14:06:53 +00:00
|
|
|
},
|
2020-11-07 15:11:09 +00:00
|
|
|
};
|
2021-10-15 02:35:26 +00:00
|
|
|
|
2021-10-16 17:28:04 +00:00
|
|
|
export function initRepoActivityTopAuthorsChart() {
|
2023-03-14 04:09:06 +00:00
|
|
|
const el = document.getElementById('repo-activity-top-authors-chart');
|
|
|
|
if (el) {
|
2024-07-18 20:05:02 +00:00
|
|
|
createApp(sfc, {
|
|
|
|
locale: {
|
|
|
|
commitActivity: el.getAttribute('data-locale-commit-activity'),
|
|
|
|
},
|
|
|
|
}).mount(el);
|
2023-03-14 04:09:06 +00:00
|
|
|
}
|
2021-10-15 02:35:26 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 04:09:06 +00:00
|
|
|
export default sfc; // activate the IDE's Vue plugin
|
2020-11-07 15:11:09 +00:00
|
|
|
</script>
|
2023-09-02 14:59:07 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div class="activity-bar-graph" ref="style" style="width: 0; height: 0;"/>
|
2024-07-18 20:05:02 +00:00
|
|
|
<Bar height="150px" :data="graphPoints()" :options="getOptions()"/>
|
2023-09-02 14:59:07 +00:00
|
|
|
</div>
|
|
|
|
</template>
|