mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-10 07:53:09 +02:00
improve instance doughnut charts
This commit is contained in:
parent
553d644781
commit
5c3e782d29
2 changed files with 20 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { MoreThan } from 'typeorm';
|
import { IsNull, MoreThan, Not } from 'typeorm';
|
||||||
import { Instances } from '@/models/index.js';
|
import { Followings, Instances } from '@/models/index.js';
|
||||||
import { awaitAll } from '@/prelude/await-all.js';
|
import { awaitAll } from '@/prelude/await-all.js';
|
||||||
import define from '../../define.js';
|
import define from '../../define.js';
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ export const paramDef = {
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
export default define(meta, paramDef, async (ps) => {
|
export default define(meta, paramDef, async (ps) => {
|
||||||
const [topSubInstances, topPubInstances] = await Promise.all([
|
const [topSubInstances, topPubInstances, allSubCount, allPubCount] = await Promise.all([
|
||||||
Instances.find({
|
Instances.find({
|
||||||
where: {
|
where: {
|
||||||
followersCount: MoreThan(0),
|
followersCount: MoreThan(0),
|
||||||
|
@ -40,10 +40,25 @@ export default define(meta, paramDef, async (ps) => {
|
||||||
},
|
},
|
||||||
take: 10,
|
take: 10,
|
||||||
}),
|
}),
|
||||||
|
Followings.count({
|
||||||
|
where: {
|
||||||
|
followeeHost: Not(IsNull()),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
Followings.count({
|
||||||
|
where: {
|
||||||
|
followerHost: Not(IsNull()),
|
||||||
|
},
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const gotSubCount = topSubInstances.map(x => x.followersCount).reduce((a, b) => a + b, 0);
|
||||||
|
const gotPubCount = topSubInstances.map(x => x.followingCount).reduce((a, b) => a + b, 0);
|
||||||
|
|
||||||
return await awaitAll({
|
return await awaitAll({
|
||||||
topSubInstances: Instances.packMany(topSubInstances),
|
topSubInstances: Instances.packMany(topSubInstances),
|
||||||
|
otherFollowersCount: Math.max(0, allSubCount - gotSubCount),
|
||||||
topPubInstances: Instances.packMany(topPubInstances),
|
topPubInstances: Instances.packMany(topPubInstances),
|
||||||
|
otherFollowingCount: Math.max(0, allPubCount - gotPubCount),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -112,12 +112,12 @@
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<div class="chart deliver">
|
<div class="chart deliver">
|
||||||
<div class="title">Sub</div>
|
<div class="title">Sub</div>
|
||||||
<XPie :data="fedStats.topSubInstances.map(x => ({ name: x.host, color: x.themeColor, value: x.followersCount }))"/>
|
<XPie :data="fedStats.topSubInstances.map(x => ({ name: x.host, color: x.themeColor, value: x.followersCount })).concat([{ name: '(other)', color: '#808080', value: fedStats.otherFollowersCount }])"/>
|
||||||
<div class="subTitle">Top 10</div>
|
<div class="subTitle">Top 10</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="chart inbox">
|
<div class="chart inbox">
|
||||||
<div class="title">Pub</div>
|
<div class="title">Pub</div>
|
||||||
<XPie :data="fedStats.topPubInstances.map(x => ({ name: x.host, color: x.themeColor, value: x.followingCount }))"/>
|
<XPie :data="fedStats.topPubInstances.map(x => ({ name: x.host, color: x.themeColor, value: x.followingCount })).concat([{ name: '(other)', color: '#808080', value: fedStats.otherFollowingCount }])"/>
|
||||||
<div class="subTitle">Top 10</div>
|
<div class="subTitle">Top 10</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue