2021-10-21 20:36:48 +00:00
|
|
|
<template>
|
2021-10-23 02:34:41 +00:00
|
|
|
<div class="cbbedffa">
|
|
|
|
<canvas ref="chartEl"></canvas>
|
|
|
|
<div v-if="fetching" class="fetching">
|
|
|
|
<MkLoading/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-21 20:36:48 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-01-31 12:07:33 +00:00
|
|
|
import { defineComponent, onMounted, ref, watch, PropType, onUnmounted, shallowRef } from 'vue';
|
2021-10-21 20:36:48 +00:00
|
|
|
import {
|
|
|
|
Chart,
|
|
|
|
ArcElement,
|
|
|
|
LineElement,
|
|
|
|
BarElement,
|
|
|
|
PointElement,
|
|
|
|
BarController,
|
|
|
|
LineController,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
Legend,
|
|
|
|
Title,
|
|
|
|
Tooltip,
|
|
|
|
SubTitle,
|
|
|
|
Filler,
|
|
|
|
} from 'chart.js';
|
|
|
|
import 'chartjs-adapter-date-fns';
|
|
|
|
import { enUS } from 'date-fns/locale';
|
|
|
|
import zoomPlugin from 'chartjs-plugin-zoom';
|
2021-11-11 17:02:25 +00:00
|
|
|
import * as os from '@/os';
|
|
|
|
import { defaultStore } from '@/store';
|
2022-01-31 12:07:33 +00:00
|
|
|
import MkChartTooltip from '@/components/chart-tooltip.vue';
|
2021-10-21 20:36:48 +00:00
|
|
|
|
|
|
|
Chart.register(
|
|
|
|
ArcElement,
|
|
|
|
LineElement,
|
|
|
|
BarElement,
|
|
|
|
PointElement,
|
|
|
|
BarController,
|
|
|
|
LineController,
|
|
|
|
CategoryScale,
|
|
|
|
LinearScale,
|
|
|
|
TimeScale,
|
|
|
|
Legend,
|
|
|
|
Title,
|
|
|
|
Tooltip,
|
|
|
|
SubTitle,
|
|
|
|
Filler,
|
|
|
|
zoomPlugin,
|
|
|
|
);
|
|
|
|
|
|
|
|
const sum = (...arr) => arr.reduce((r, a) => r.map((b, i) => a[i] + b));
|
|
|
|
const negate = arr => arr.map(x => -x);
|
|
|
|
const alpha = (hex, a) => {
|
|
|
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)!;
|
|
|
|
const r = parseInt(result[1], 16);
|
|
|
|
const g = parseInt(result[2], 16);
|
|
|
|
const b = parseInt(result[3], 16);
|
|
|
|
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
|
|
};
|
|
|
|
|
2022-02-05 21:24:06 +00:00
|
|
|
const colors = ['#008FFB', '#00E396', '#FEB019', '#FF4560', '#e300db'];
|
2021-10-21 20:36:48 +00:00
|
|
|
const getColor = (i) => {
|
|
|
|
return colors[i % colors.length];
|
|
|
|
};
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
src: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
args: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
limit: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 90
|
|
|
|
},
|
|
|
|
span: {
|
|
|
|
type: String as PropType<'hour' | 'day'>,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
detailed: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2021-10-24 03:32:41 +00:00
|
|
|
stacked: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2022-02-04 07:39:09 +00:00
|
|
|
bar: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2021-10-24 03:32:41 +00:00
|
|
|
aspectRatio: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: null
|
|
|
|
},
|
2021-10-21 20:36:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setup(props) {
|
|
|
|
const now = new Date();
|
|
|
|
let chartInstance: Chart = null;
|
|
|
|
let data: {
|
|
|
|
series: {
|
|
|
|
name: string;
|
|
|
|
type: 'line' | 'area';
|
|
|
|
color?: string;
|
|
|
|
borderDash?: number[];
|
|
|
|
hidden?: boolean;
|
|
|
|
data: {
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
}[];
|
|
|
|
}[];
|
|
|
|
} = null;
|
|
|
|
|
|
|
|
const chartEl = ref<HTMLCanvasElement>(null);
|
|
|
|
const fetching = ref(true);
|
|
|
|
|
|
|
|
const getDate = (ago: number) => {
|
|
|
|
const y = now.getFullYear();
|
|
|
|
const m = now.getMonth();
|
|
|
|
const d = now.getDate();
|
|
|
|
const h = now.getHours();
|
|
|
|
|
|
|
|
return props.span === 'day' ? new Date(y, m, d - ago) : new Date(y, m, d, h - ago);
|
|
|
|
};
|
|
|
|
|
|
|
|
const format = (arr) => {
|
|
|
|
return arr.map((v, i) => ({
|
|
|
|
x: getDate(i).getTime(),
|
|
|
|
y: v
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2022-01-31 12:07:33 +00:00
|
|
|
const tooltipShowing = ref(false);
|
|
|
|
const tooltipX = ref(0);
|
|
|
|
const tooltipY = ref(0);
|
|
|
|
const tooltipTitle = ref(null);
|
|
|
|
const tooltipSeries = ref(null);
|
|
|
|
let disposeTooltipComponent;
|
|
|
|
|
|
|
|
os.popup(MkChartTooltip, {
|
|
|
|
showing: tooltipShowing,
|
|
|
|
x: tooltipX,
|
|
|
|
y: tooltipY,
|
|
|
|
title: tooltipTitle,
|
|
|
|
series: tooltipSeries,
|
|
|
|
}, {}).then(({ dispose }) => {
|
|
|
|
disposeTooltipComponent = dispose;
|
|
|
|
});
|
|
|
|
|
|
|
|
function externalTooltipHandler(context) {
|
|
|
|
if (context.tooltip.opacity === 0) {
|
|
|
|
tooltipShowing.value = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltipTitle.value = context.tooltip.title[0];
|
|
|
|
tooltipSeries.value = context.tooltip.body.map((b, i) => ({
|
|
|
|
backgroundColor: context.tooltip.labelColors[i].backgroundColor,
|
|
|
|
borderColor: context.tooltip.labelColors[i].borderColor,
|
|
|
|
text: b.lines[0],
|
|
|
|
}));
|
|
|
|
|
|
|
|
const rect = context.chart.canvas.getBoundingClientRect();
|
|
|
|
|
|
|
|
tooltipShowing.value = true;
|
|
|
|
tooltipX.value = rect.left + window.pageXOffset + context.tooltip.caretX;
|
|
|
|
tooltipY.value = rect.top + window.pageYOffset + context.tooltip.caretY;
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:36:48 +00:00
|
|
|
const render = () => {
|
|
|
|
if (chartInstance) {
|
|
|
|
chartInstance.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
const gridColor = defaultStore.state.darkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)';
|
2022-01-28 02:19:18 +00:00
|
|
|
const vLineColor = defaultStore.state.darkMode ? 'rgba(255, 255, 255, 0.2)' : 'rgba(0, 0, 0, 0.2)';
|
2021-10-21 20:36:48 +00:00
|
|
|
|
|
|
|
// フォントカラー
|
|
|
|
Chart.defaults.color = getComputedStyle(document.documentElement).getPropertyValue('--fg');
|
|
|
|
|
|
|
|
chartInstance = new Chart(chartEl.value, {
|
2022-02-04 07:39:09 +00:00
|
|
|
type: props.bar ? 'bar' : 'line',
|
2021-10-21 20:36:48 +00:00
|
|
|
data: {
|
|
|
|
labels: new Array(props.limit).fill(0).map((_, i) => getDate(i).toLocaleString()).slice().reverse(),
|
|
|
|
datasets: data.series.map((x, i) => ({
|
|
|
|
parsing: false,
|
|
|
|
label: x.name,
|
|
|
|
data: x.data.slice().reverse(),
|
|
|
|
pointRadius: 0,
|
|
|
|
borderWidth: 2,
|
|
|
|
borderColor: x.color ? x.color : getColor(i),
|
|
|
|
borderDash: x.borderDash || [],
|
|
|
|
borderJoinStyle: 'round',
|
|
|
|
backgroundColor: alpha(x.color ? x.color : getColor(i), 0.1),
|
2022-02-04 07:39:09 +00:00
|
|
|
barPercentage: 0.9,
|
|
|
|
categoryPercentage: 0.9,
|
2021-10-21 20:36:48 +00:00
|
|
|
fill: x.type === 'area',
|
|
|
|
hidden: !!x.hidden,
|
|
|
|
})),
|
|
|
|
},
|
|
|
|
options: {
|
2021-10-24 03:32:41 +00:00
|
|
|
aspectRatio: props.aspectRatio || 2.5,
|
2021-10-21 20:36:48 +00:00
|
|
|
layout: {
|
|
|
|
padding: {
|
2022-01-04 06:36:14 +00:00
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
2021-10-21 20:36:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
type: 'time',
|
2022-02-04 07:39:09 +00:00
|
|
|
stacked: props.stacked,
|
2021-10-21 20:36:48 +00:00
|
|
|
time: {
|
|
|
|
stepSize: 1,
|
|
|
|
unit: props.span === 'day' ? 'month' : 'day',
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
color: gridColor,
|
|
|
|
borderColor: 'rgb(0, 0, 0, 0)',
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: props.detailed,
|
2022-02-07 05:56:49 +00:00
|
|
|
maxRotation: 0,
|
2021-10-21 20:36:48 +00:00
|
|
|
},
|
|
|
|
adapters: {
|
|
|
|
date: {
|
|
|
|
locale: enUS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
min: getDate(props.limit).getTime(),
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
position: 'left',
|
2021-10-24 03:32:41 +00:00
|
|
|
stacked: props.stacked,
|
2021-10-21 20:36:48 +00:00
|
|
|
grid: {
|
|
|
|
color: gridColor,
|
|
|
|
borderColor: 'rgb(0, 0, 0, 0)',
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
display: props.detailed,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
interaction: {
|
|
|
|
intersect: false,
|
2022-02-02 17:08:54 +00:00
|
|
|
mode: 'index',
|
2021-10-21 20:36:48 +00:00
|
|
|
},
|
2022-02-02 17:08:54 +00:00
|
|
|
elements: {
|
|
|
|
point: {
|
|
|
|
hoverRadius: 5,
|
|
|
|
hoverBorderWidth: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
animation: false,
|
2021-10-21 20:36:48 +00:00
|
|
|
plugins: {
|
|
|
|
legend: {
|
2021-10-24 03:32:41 +00:00
|
|
|
display: props.detailed,
|
2021-10-21 20:36:48 +00:00
|
|
|
position: 'bottom',
|
|
|
|
labels: {
|
|
|
|
boxWidth: 16,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tooltip: {
|
2022-01-31 12:07:33 +00:00
|
|
|
enabled: false,
|
2021-10-21 20:36:48 +00:00
|
|
|
mode: 'index',
|
|
|
|
animation: {
|
|
|
|
duration: 0,
|
|
|
|
},
|
2022-01-31 12:07:33 +00:00
|
|
|
external: externalTooltipHandler,
|
2021-10-21 20:36:48 +00:00
|
|
|
},
|
|
|
|
zoom: {
|
|
|
|
pan: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
zoom: {
|
|
|
|
wheel: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
pinch: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
drag: {
|
|
|
|
enabled: false,
|
|
|
|
},
|
|
|
|
mode: 'x',
|
|
|
|
},
|
|
|
|
limits: {
|
|
|
|
x: {
|
|
|
|
min: 'original',
|
|
|
|
max: 'original',
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
min: 'original',
|
|
|
|
max: 'original',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-28 02:19:18 +00:00
|
|
|
plugins: [{
|
|
|
|
id: 'vLine',
|
|
|
|
beforeDraw(chart, args, options) {
|
|
|
|
if (chart.tooltip._active && chart.tooltip._active.length) {
|
|
|
|
const activePoint = chart.tooltip._active[0];
|
|
|
|
const ctx = chart.ctx;
|
|
|
|
const x = activePoint.element.x;
|
|
|
|
const topY = chart.scales.y.top;
|
|
|
|
const bottomY = chart.scales.y.bottom;
|
|
|
|
|
|
|
|
ctx.save();
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(x, bottomY);
|
|
|
|
ctx.lineTo(x, topY);
|
|
|
|
ctx.lineWidth = 1;
|
|
|
|
ctx.strokeStyle = vLineColor;
|
|
|
|
ctx.stroke();
|
|
|
|
ctx.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]
|
2021-10-21 20:36:48 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const exportData = () => {
|
|
|
|
// TODO
|
|
|
|
};
|
|
|
|
|
2022-02-05 15:43:22 +00:00
|
|
|
const fetchFederationChart = async (): Promise<typeof data> => {
|
2021-10-21 20:36:48 +00:00
|
|
|
const raw = await os.api('charts/federation', { limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
2022-02-05 15:43:22 +00:00
|
|
|
name: 'Instances total',
|
2021-10-21 20:36:48 +00:00
|
|
|
type: 'area',
|
2022-02-05 15:43:22 +00:00
|
|
|
data: format(raw.instance.total),
|
|
|
|
}, {
|
|
|
|
name: 'Instances inc/dec',
|
|
|
|
type: 'area',
|
|
|
|
data: format(sum(raw.instance.inc, negate(raw.instance.dec))),
|
|
|
|
}, {
|
|
|
|
name: 'Delivered instances',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.deliveredInstances),
|
|
|
|
}, {
|
|
|
|
name: 'Inbox instances',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.inboxInstances),
|
2021-10-21 20:36:48 +00:00
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-05 15:43:22 +00:00
|
|
|
const fetchApRequestChart = async (): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/ap-request', { limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'In',
|
|
|
|
type: 'area',
|
|
|
|
color: '#008FFB',
|
|
|
|
data: format(raw.inboxReceived)
|
|
|
|
}, {
|
|
|
|
name: 'Out (succ)',
|
|
|
|
type: 'area',
|
|
|
|
color: '#00E396',
|
|
|
|
data: format(raw.deliverSucceeded)
|
|
|
|
}, {
|
|
|
|
name: 'Out (fail)',
|
|
|
|
type: 'area',
|
|
|
|
color: '#FEB019',
|
|
|
|
data: format(raw.deliverFailed)
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-21 20:36:48 +00:00
|
|
|
const fetchNotesChart = async (type: string): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/notes', { limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'All',
|
|
|
|
type: 'line',
|
|
|
|
borderDash: [5, 5],
|
|
|
|
data: format(type == 'combined'
|
|
|
|
? sum(raw.local.inc, negate(raw.local.dec), raw.remote.inc, negate(raw.remote.dec))
|
|
|
|
: sum(raw[type].inc, negate(raw[type].dec))
|
|
|
|
),
|
|
|
|
}, {
|
|
|
|
name: 'Renotes',
|
|
|
|
type: 'area',
|
|
|
|
data: format(type == 'combined'
|
|
|
|
? sum(raw.local.diffs.renote, raw.remote.diffs.renote)
|
|
|
|
: raw[type].diffs.renote
|
|
|
|
),
|
|
|
|
}, {
|
|
|
|
name: 'Replies',
|
|
|
|
type: 'area',
|
|
|
|
data: format(type == 'combined'
|
|
|
|
? sum(raw.local.diffs.reply, raw.remote.diffs.reply)
|
|
|
|
: raw[type].diffs.reply
|
|
|
|
),
|
|
|
|
}, {
|
|
|
|
name: 'Normal',
|
|
|
|
type: 'area',
|
|
|
|
data: format(type == 'combined'
|
|
|
|
? sum(raw.local.diffs.normal, raw.remote.diffs.normal)
|
|
|
|
: raw[type].diffs.normal
|
|
|
|
),
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchNotesTotalChart = async (): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/notes', { limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'Combined',
|
|
|
|
type: 'line',
|
|
|
|
data: format(sum(raw.local.total, raw.remote.total)),
|
|
|
|
}, {
|
|
|
|
name: 'Local',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.local.total),
|
|
|
|
}, {
|
|
|
|
name: 'Remote',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.remote.total),
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchUsersChart = async (total: boolean): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/users', { limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'Combined',
|
|
|
|
type: 'line',
|
|
|
|
data: format(total
|
|
|
|
? sum(raw.local.total, raw.remote.total)
|
|
|
|
: sum(raw.local.inc, negate(raw.local.dec), raw.remote.inc, negate(raw.remote.dec))
|
|
|
|
),
|
|
|
|
}, {
|
|
|
|
name: 'Local',
|
|
|
|
type: 'area',
|
|
|
|
data: format(total
|
|
|
|
? raw.local.total
|
|
|
|
: sum(raw.local.inc, negate(raw.local.dec))
|
|
|
|
),
|
|
|
|
}, {
|
|
|
|
name: 'Remote',
|
|
|
|
type: 'area',
|
|
|
|
data: format(total
|
|
|
|
? raw.remote.total
|
|
|
|
: sum(raw.remote.inc, negate(raw.remote.dec))
|
|
|
|
),
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchActiveUsersChart = async (): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/active-users', { limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
2022-02-05 21:24:06 +00:00
|
|
|
name: 'Users',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.users),
|
2021-10-21 20:36:48 +00:00
|
|
|
}, {
|
2022-02-05 21:24:06 +00:00
|
|
|
name: 'Noted',
|
2021-10-21 20:36:48 +00:00
|
|
|
type: 'area',
|
2022-02-05 21:24:06 +00:00
|
|
|
data: format(raw.notedUsers),
|
2021-10-21 20:36:48 +00:00
|
|
|
}, {
|
2022-02-05 21:24:06 +00:00
|
|
|
name: '< Week',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.registeredWithinWeek),
|
|
|
|
}, {
|
|
|
|
name: '< Month',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.registeredWithinMonth),
|
|
|
|
}, {
|
|
|
|
name: '< Year',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.registeredWithinYear),
|
|
|
|
}, {
|
|
|
|
name: '> Week',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.registeredOutsideWeek),
|
|
|
|
}, {
|
|
|
|
name: '> Month',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.registeredOutsideMonth),
|
|
|
|
}, {
|
|
|
|
name: '> Year',
|
2021-10-21 20:36:48 +00:00
|
|
|
type: 'area',
|
2022-02-05 21:24:06 +00:00
|
|
|
data: format(raw.registeredOutsideYear),
|
2021-10-21 20:36:48 +00:00
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchDriveChart = async (): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/drive', { limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
bytes: true,
|
|
|
|
series: [{
|
|
|
|
name: 'All',
|
|
|
|
type: 'line',
|
|
|
|
borderDash: [5, 5],
|
|
|
|
data: format(
|
|
|
|
sum(
|
|
|
|
raw.local.incSize,
|
|
|
|
negate(raw.local.decSize),
|
|
|
|
raw.remote.incSize,
|
|
|
|
negate(raw.remote.decSize)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
}, {
|
|
|
|
name: 'Local +',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.local.incSize),
|
|
|
|
}, {
|
|
|
|
name: 'Local -',
|
|
|
|
type: 'area',
|
|
|
|
data: format(negate(raw.local.decSize)),
|
|
|
|
}, {
|
|
|
|
name: 'Remote +',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.remote.incSize),
|
|
|
|
}, {
|
|
|
|
name: 'Remote -',
|
|
|
|
type: 'area',
|
|
|
|
data: format(negate(raw.remote.decSize)),
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchDriveFilesChart = async (): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/drive', { limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'All',
|
|
|
|
type: 'line',
|
|
|
|
borderDash: [5, 5],
|
|
|
|
data: format(
|
|
|
|
sum(
|
|
|
|
raw.local.incCount,
|
|
|
|
negate(raw.local.decCount),
|
|
|
|
raw.remote.incCount,
|
|
|
|
negate(raw.remote.decCount)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
}, {
|
|
|
|
name: 'Local +',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.local.incCount),
|
|
|
|
}, {
|
|
|
|
name: 'Local -',
|
|
|
|
type: 'area',
|
|
|
|
data: format(negate(raw.local.decCount)),
|
|
|
|
}, {
|
|
|
|
name: 'Remote +',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.remote.incCount),
|
|
|
|
}, {
|
|
|
|
name: 'Remote -',
|
|
|
|
type: 'area',
|
|
|
|
data: format(negate(raw.remote.decCount)),
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchInstanceRequestsChart = async (): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/instance', { host: props.args.host, limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'In',
|
|
|
|
type: 'area',
|
|
|
|
color: '#008FFB',
|
|
|
|
data: format(raw.requests.received)
|
|
|
|
}, {
|
|
|
|
name: 'Out (succ)',
|
|
|
|
type: 'area',
|
|
|
|
color: '#00E396',
|
|
|
|
data: format(raw.requests.succeeded)
|
|
|
|
}, {
|
|
|
|
name: 'Out (fail)',
|
|
|
|
type: 'area',
|
|
|
|
color: '#FEB019',
|
|
|
|
data: format(raw.requests.failed)
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchInstanceUsersChart = async (total: boolean): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/instance', { host: props.args.host, limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'Users',
|
|
|
|
type: 'area',
|
|
|
|
color: '#008FFB',
|
|
|
|
data: format(total
|
|
|
|
? raw.users.total
|
|
|
|
: sum(raw.users.inc, negate(raw.users.dec))
|
|
|
|
)
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchInstanceNotesChart = async (total: boolean): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/instance', { host: props.args.host, limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'Notes',
|
|
|
|
type: 'area',
|
|
|
|
color: '#008FFB',
|
|
|
|
data: format(total
|
|
|
|
? raw.notes.total
|
|
|
|
: sum(raw.notes.inc, negate(raw.notes.dec))
|
|
|
|
)
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchInstanceFfChart = async (total: boolean): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/instance', { host: props.args.host, limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'Following',
|
|
|
|
type: 'area',
|
|
|
|
color: '#008FFB',
|
|
|
|
data: format(total
|
|
|
|
? raw.following.total
|
|
|
|
: sum(raw.following.inc, negate(raw.following.dec))
|
|
|
|
)
|
|
|
|
}, {
|
|
|
|
name: 'Followers',
|
|
|
|
type: 'area',
|
|
|
|
color: '#00E396',
|
|
|
|
data: format(total
|
|
|
|
? raw.followers.total
|
|
|
|
: sum(raw.followers.inc, negate(raw.followers.dec))
|
|
|
|
)
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchInstanceDriveUsageChart = async (total: boolean): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/instance', { host: props.args.host, limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
bytes: true,
|
|
|
|
series: [{
|
|
|
|
name: 'Drive usage',
|
|
|
|
type: 'area',
|
|
|
|
color: '#008FFB',
|
|
|
|
data: format(total
|
|
|
|
? raw.drive.totalUsage
|
|
|
|
: sum(raw.drive.incUsage, negate(raw.drive.decUsage))
|
|
|
|
)
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetchInstanceDriveFilesChart = async (total: boolean): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/instance', { host: props.args.host, limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'Drive files',
|
|
|
|
type: 'area',
|
|
|
|
color: '#008FFB',
|
|
|
|
data: format(total
|
|
|
|
? raw.drive.totalFiles
|
|
|
|
: sum(raw.drive.incFiles, negate(raw.drive.decFiles))
|
|
|
|
)
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-24 03:32:41 +00:00
|
|
|
const fetchPerUserNotesChart = async (): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/user/notes', { userId: props.args.user.id, limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [...(props.args.withoutAll ? [] : [{
|
|
|
|
name: 'All',
|
|
|
|
type: 'line',
|
|
|
|
borderDash: [5, 5],
|
|
|
|
data: format(sum(raw.inc, negate(raw.dec))),
|
|
|
|
}]), {
|
|
|
|
name: 'Renotes',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.diffs.renote),
|
|
|
|
}, {
|
|
|
|
name: 'Replies',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.diffs.reply),
|
|
|
|
}, {
|
|
|
|
name: 'Normal',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.diffs.normal),
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-04 07:39:09 +00:00
|
|
|
const fetchPerUserDriveChart = async (): Promise<typeof data> => {
|
|
|
|
const raw = await os.api('charts/user/drive', { userId: props.args.user.id, limit: props.limit, span: props.span });
|
|
|
|
return {
|
|
|
|
series: [{
|
|
|
|
name: 'Inc',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.incSize),
|
|
|
|
}, {
|
|
|
|
name: 'Dec',
|
|
|
|
type: 'area',
|
|
|
|
data: format(raw.decSize),
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-10-21 20:36:48 +00:00
|
|
|
const fetchAndRender = async () => {
|
|
|
|
const fetchData = () => {
|
|
|
|
switch (props.src) {
|
2022-02-05 15:43:22 +00:00
|
|
|
case 'federation': return fetchFederationChart();
|
|
|
|
case 'ap-request': return fetchApRequestChart();
|
2021-10-21 20:36:48 +00:00
|
|
|
case 'users': return fetchUsersChart(false);
|
|
|
|
case 'users-total': return fetchUsersChart(true);
|
|
|
|
case 'active-users': return fetchActiveUsersChart();
|
|
|
|
case 'notes': return fetchNotesChart('combined');
|
|
|
|
case 'local-notes': return fetchNotesChart('local');
|
|
|
|
case 'remote-notes': return fetchNotesChart('remote');
|
|
|
|
case 'notes-total': return fetchNotesTotalChart();
|
|
|
|
case 'drive': return fetchDriveChart();
|
|
|
|
case 'drive-files': return fetchDriveFilesChart();
|
|
|
|
|
2021-10-22 06:34:02 +00:00
|
|
|
case 'instance-requests': return fetchInstanceRequestsChart();
|
|
|
|
case 'instance-users': return fetchInstanceUsersChart(false);
|
|
|
|
case 'instance-users-total': return fetchInstanceUsersChart(true);
|
|
|
|
case 'instance-notes': return fetchInstanceNotesChart(false);
|
|
|
|
case 'instance-notes-total': return fetchInstanceNotesChart(true);
|
|
|
|
case 'instance-ff': return fetchInstanceFfChart(false);
|
|
|
|
case 'instance-ff-total': return fetchInstanceFfChart(true);
|
|
|
|
case 'instance-drive-usage': return fetchInstanceDriveUsageChart(false);
|
|
|
|
case 'instance-drive-usage-total': return fetchInstanceDriveUsageChart(true);
|
|
|
|
case 'instance-drive-files': return fetchInstanceDriveFilesChart(false);
|
|
|
|
case 'instance-drive-files-total': return fetchInstanceDriveFilesChart(true);
|
2021-10-24 03:32:41 +00:00
|
|
|
|
|
|
|
case 'per-user-notes': return fetchPerUserNotesChart();
|
2022-02-04 07:39:09 +00:00
|
|
|
case 'per-user-drive': return fetchPerUserDriveChart();
|
2021-10-21 20:36:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
fetching.value = true;
|
|
|
|
data = await fetchData();
|
|
|
|
fetching.value = false;
|
|
|
|
render();
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => [props.src, props.span], fetchAndRender);
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
fetchAndRender();
|
|
|
|
});
|
|
|
|
|
2022-01-31 12:07:33 +00:00
|
|
|
onUnmounted(() => {
|
|
|
|
if (disposeTooltipComponent) disposeTooltipComponent();
|
|
|
|
});
|
|
|
|
|
2021-10-21 20:36:48 +00:00
|
|
|
return {
|
|
|
|
chartEl,
|
2021-10-23 02:34:41 +00:00
|
|
|
fetching,
|
2021-10-21 20:36:48 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
2021-10-23 02:34:41 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.cbbedffa {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .fetching {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
-webkit-backdrop-filter: var(--blur, blur(12px));
|
|
|
|
backdrop-filter: var(--blur, blur(12px));
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
cursor: wait;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|