2018-11-02 11:00:23 -07:00
|
|
|
<template>
|
2022-01-03 22:36:14 -08:00
|
|
|
<div class="zbcjwnqg">
|
2022-06-28 23:41:06 -07:00
|
|
|
<div class="main">
|
|
|
|
<div class="body">
|
|
|
|
<div class="selects" style="display: flex;">
|
|
|
|
<MkSelect v-model="chartSrc" style="margin: 0; flex: 1;">
|
|
|
|
<optgroup :label="$ts.federation">
|
|
|
|
<option value="federation">{{ $ts._charts.federation }}</option>
|
|
|
|
<option value="ap-request">{{ $ts._charts.apRequest }}</option>
|
|
|
|
</optgroup>
|
|
|
|
<optgroup :label="$ts.users">
|
|
|
|
<option value="users">{{ $ts._charts.usersIncDec }}</option>
|
|
|
|
<option value="users-total">{{ $ts._charts.usersTotal }}</option>
|
|
|
|
<option value="active-users">{{ $ts._charts.activeUsers }}</option>
|
|
|
|
</optgroup>
|
|
|
|
<optgroup :label="$ts.notes">
|
|
|
|
<option value="notes">{{ $ts._charts.notesIncDec }}</option>
|
|
|
|
<option value="local-notes">{{ $ts._charts.localNotesIncDec }}</option>
|
|
|
|
<option value="remote-notes">{{ $ts._charts.remoteNotesIncDec }}</option>
|
|
|
|
<option value="notes-total">{{ $ts._charts.notesTotal }}</option>
|
|
|
|
</optgroup>
|
|
|
|
<optgroup :label="$ts.drive">
|
|
|
|
<option value="drive-files">{{ $ts._charts.filesIncDec }}</option>
|
|
|
|
<option value="drive">{{ $ts._charts.storageUsageIncDec }}</option>
|
|
|
|
</optgroup>
|
|
|
|
</MkSelect>
|
|
|
|
<MkSelect v-model="chartSpan" style="margin: 0 0 0 10px;">
|
|
|
|
<option value="hour">{{ $ts.perHour }}</option>
|
|
|
|
<option value="day">{{ $ts.perDay }}</option>
|
|
|
|
</MkSelect>
|
|
|
|
</div>
|
|
|
|
<div class="chart">
|
|
|
|
<MkChart :src="chartSrc" :span="chartSpan" :limit="chartLimit" :detailed="detailed"></MkChart>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-02-16 09:21:27 -08:00
|
|
|
</div>
|
2022-06-28 23:41:06 -07:00
|
|
|
<div class="subpub">
|
|
|
|
<div class="sub">
|
|
|
|
<div class="title">Sub</div>
|
|
|
|
<canvas ref="subDoughnutEl"></canvas>
|
|
|
|
</div>
|
|
|
|
<div class="pub">
|
|
|
|
<div class="title">Pub</div>
|
|
|
|
<canvas ref="pubDoughnutEl"></canvas>
|
|
|
|
</div>
|
2022-01-03 22:36:14 -08:00
|
|
|
</div>
|
2018-11-02 11:00:23 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-06-28 23:41:06 -07:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted } from 'vue';
|
|
|
|
import {
|
|
|
|
Chart,
|
|
|
|
ArcElement,
|
|
|
|
LineElement,
|
|
|
|
BarElement,
|
|
|
|
PointElement,
|
|
|
|
BarController,
|
|
|
|
LineController,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
Legend,
|
|
|
|
Title,
|
|
|
|
Tooltip,
|
|
|
|
SubTitle,
|
|
|
|
Filler,
|
|
|
|
DoughnutController,
|
|
|
|
} from 'chart.js';
|
2021-11-11 09:02:25 -08:00
|
|
|
import MkSelect from '@/components/form/select.vue';
|
|
|
|
import MkChart from '@/components/chart.vue';
|
2022-06-28 23:41:06 -07:00
|
|
|
import { useChartTooltip } from '@/scripts/use-chart-tooltip';
|
|
|
|
import * as os from '@/os';
|
2018-11-02 11:00:23 -07:00
|
|
|
|
2022-06-28 23:41:06 -07:00
|
|
|
Chart.register(
|
|
|
|
ArcElement,
|
|
|
|
LineElement,
|
|
|
|
BarElement,
|
|
|
|
PointElement,
|
|
|
|
BarController,
|
|
|
|
LineController,
|
|
|
|
DoughnutController,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
Legend,
|
|
|
|
Title,
|
|
|
|
Tooltip,
|
|
|
|
SubTitle,
|
|
|
|
Filler,
|
|
|
|
);
|
2020-01-29 11:37:25 -08:00
|
|
|
|
2022-06-28 23:41:06 -07:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
chartLimit?: number;
|
|
|
|
detailed?: boolean;
|
|
|
|
}>(), {
|
|
|
|
chartLimit: 90,
|
|
|
|
});
|
|
|
|
|
|
|
|
const chartSpan = $ref<'hour' | 'day'>('hour');
|
|
|
|
const chartSrc = $ref('active-users');
|
|
|
|
let subDoughnutEl = $ref<HTMLCanvasElement>();
|
|
|
|
let pubDoughnutEl = $ref<HTMLCanvasElement>();
|
|
|
|
|
|
|
|
const { handler: externalTooltipHandler1 } = useChartTooltip();
|
|
|
|
const { handler: externalTooltipHandler2 } = useChartTooltip();
|
|
|
|
|
|
|
|
function createDoughnut(chartEl, tooltip, data) {
|
2022-06-30 06:02:08 -07:00
|
|
|
const chartInstance = new Chart(chartEl, {
|
2022-06-28 23:41:06 -07:00
|
|
|
type: 'doughnut',
|
|
|
|
data: {
|
|
|
|
labels: data.map(x => x.name),
|
|
|
|
datasets: [{
|
|
|
|
backgroundColor: data.map(x => x.color),
|
2022-06-30 05:38:34 -07:00
|
|
|
borderColor: getComputedStyle(document.documentElement).getPropertyValue('--panel'),
|
|
|
|
borderWidth: 2,
|
|
|
|
hoverOffset: 0,
|
2022-06-28 23:41:06 -07:00
|
|
|
data: data.map(x => x.value),
|
|
|
|
}],
|
2020-08-08 23:51:02 -07:00
|
|
|
},
|
2022-06-28 23:41:06 -07:00
|
|
|
options: {
|
2022-07-01 01:08:45 -07:00
|
|
|
maintainAspectRatio: false,
|
2022-06-28 23:41:06 -07:00
|
|
|
layout: {
|
|
|
|
padding: {
|
2022-06-30 04:15:14 -07:00
|
|
|
left: 16,
|
|
|
|
right: 16,
|
|
|
|
top: 16,
|
|
|
|
bottom: 16,
|
2022-06-28 23:41:06 -07:00
|
|
|
},
|
|
|
|
},
|
2022-06-30 06:02:08 -07:00
|
|
|
onClick: (ev) => {
|
|
|
|
const hit = chartInstance.getElementsAtEventForMode(ev, 'nearest', { intersect: true }, false)[0];
|
|
|
|
if (hit && data[hit.index].onClick) {
|
|
|
|
data[hit.index].onClick();
|
|
|
|
}
|
|
|
|
},
|
2022-06-28 23:41:06 -07:00
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
enabled: false,
|
|
|
|
mode: 'index',
|
|
|
|
animation: {
|
|
|
|
duration: 0,
|
|
|
|
},
|
|
|
|
external: tooltip,
|
|
|
|
},
|
|
|
|
},
|
2020-08-08 23:51:02 -07:00
|
|
|
},
|
2022-06-28 23:41:06 -07:00
|
|
|
});
|
2022-06-30 06:02:08 -07:00
|
|
|
|
|
|
|
return chartInstance;
|
2022-06-28 23:41:06 -07:00
|
|
|
}
|
2018-11-02 11:00:23 -07:00
|
|
|
|
2022-06-28 23:41:06 -07:00
|
|
|
onMounted(() => {
|
2022-07-07 01:55:47 -07:00
|
|
|
os.apiGet('federation/stats', { limit: 30 }).then(fedStats => {
|
2022-06-30 06:02:08 -07:00
|
|
|
createDoughnut(subDoughnutEl, externalTooltipHandler1, fedStats.topSubInstances.map(x => ({
|
|
|
|
name: x.host,
|
|
|
|
color: x.themeColor,
|
|
|
|
value: x.followersCount,
|
|
|
|
onClick: () => {
|
|
|
|
os.pageWindow(`/instance-info/${x.host}`);
|
|
|
|
},
|
|
|
|
})).concat([{ name: '(other)', color: '#80808080', value: fedStats.otherFollowersCount }]));
|
|
|
|
|
|
|
|
createDoughnut(pubDoughnutEl, externalTooltipHandler2, fedStats.topPubInstances.map(x => ({
|
|
|
|
name: x.host,
|
|
|
|
color: x.themeColor,
|
|
|
|
value: x.followingCount,
|
|
|
|
onClick: () => {
|
|
|
|
os.pageWindow(`/instance-info/${x.host}`);
|
|
|
|
},
|
|
|
|
})).concat([{ name: '(other)', color: '#80808080', value: fedStats.otherFollowingCount }]));
|
2022-06-28 23:41:06 -07:00
|
|
|
});
|
2018-11-02 11:00:23 -07:00
|
|
|
});
|
|
|
|
</script>
|
2020-02-16 09:21:27 -08:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.zbcjwnqg {
|
2022-06-28 23:41:06 -07:00
|
|
|
> .main {
|
|
|
|
background: var(--panel);
|
|
|
|
border-radius: var(--radius);
|
|
|
|
padding: 24px;
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
> .chart {
|
|
|
|
padding: 8px 0 0 0;
|
|
|
|
}
|
|
|
|
}
|
2022-01-03 22:36:14 -08:00
|
|
|
}
|
|
|
|
|
2022-06-28 23:41:06 -07:00
|
|
|
> .subpub {
|
|
|
|
display: flex;
|
|
|
|
gap: 16px;
|
|
|
|
|
|
|
|
> .sub, > .pub {
|
2022-07-01 01:08:45 -07:00
|
|
|
flex: 1;
|
|
|
|
min-width: 0;
|
2022-06-28 23:41:06 -07:00
|
|
|
position: relative;
|
|
|
|
background: var(--panel);
|
|
|
|
border-radius: var(--radius);
|
|
|
|
padding: 24px;
|
2022-07-01 01:08:45 -07:00
|
|
|
max-height: 300px;
|
2022-06-28 23:41:06 -07:00
|
|
|
|
|
|
|
> .title {
|
|
|
|
position: absolute;
|
|
|
|
top: 24px;
|
|
|
|
left: 24px;
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 01:08:45 -07:00
|
|
|
|
|
|
|
@media (max-width: 600px) {
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
2020-02-16 09:21:27 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|