Skip to content

Commit

Permalink
チャートの連合グラフで割合を表示 (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozakura913 authored Sep 14, 2024
1 parent 641c923 commit 142f9e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_YOJO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Cherrypick 4.11.1

### Client
- Fix: リアクションが閲覧できる状態でも見れない問題を修正 [#429](https://github.com/yojo-art/cherrypick/pull/429)
- Enhance: チャートの連合グラフで割合を表示

### Server
-
Expand Down
17 changes: 10 additions & 7 deletions packages/frontend/src/components/MkInstanceStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ const heatmapSrc = ref<HeatmapSource>('active-users');
const subDoughnutEl = shallowRef<HTMLCanvasElement>();
const pubDoughnutEl = shallowRef<HTMLCanvasElement>();

const { handler: externalTooltipHandler1 } = useChartTooltip({
position: 'middle',
});
const { handler: externalTooltipHandler2 } = useChartTooltip({
position: 'middle',
});

function createDoughnut(chartEl, tooltip, data) {
const chartInstance = new Chart(chartEl, {
type: 'doughnut',
Expand Down Expand Up @@ -171,7 +164,17 @@ onMounted(() => {
value: number,
onClick?: () => void,
}[];
let totalFollowersCount = fedStats.topSubInstances.reduce((partialSum, a) => partialSum + a.followersCount, 0);
let totalFollowingCount = fedStats.topPubInstances.reduce((partialSum, a) => partialSum + a.followingCount, 0);

const { handler: externalTooltipHandler1 } = useChartTooltip({
position: 'middle',
total: totalFollowersCount,
});
const { handler: externalTooltipHandler2 } = useChartTooltip({
position: 'middle',
total: totalFollowingCount,
});
const subs: ChartData = fedStats.topSubInstances.map(x => ({
name: x.host,
color: x.themeColor,
Expand Down
19 changes: 12 additions & 7 deletions packages/frontend/src/scripts/use-chart-tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { onUnmounted, onDeactivated, ref } from 'vue';
import * as os from '@/os.js';
import MkChartTooltip from '@/components/MkChartTooltip.vue';

export function useChartTooltip(opts: { position: 'top' | 'middle' } = { position: 'top' }) {
export function useChartTooltip(opts: { position: 'top' | 'middle', total?:number} = { position: 'top' }) {
const tooltipShowing = ref(false);
const tooltipX = ref(0);
const tooltipY = ref(0);
Expand Down Expand Up @@ -38,13 +38,18 @@ export function useChartTooltip(opts: { position: 'top' | 'middle' } = { positio
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],
}));
tooltipSeries.value = context.tooltip.body.map((b, i) => {
let ratio = '';
if (opts.total !== undefined) {
ratio = '(' + String(Math.round(Number(b.lines[0]) / opts.total * 1000) / 10) + '%)';
}
return ({
backgroundColor: context.tooltip.labelColors[i].backgroundColor,
borderColor: context.tooltip.labelColors[i].borderColor,
text: b.lines[0] + ratio,
});
});

const rect = context.chart.canvas.getBoundingClientRect();

Expand Down

0 comments on commit 142f9e5

Please sign in to comment.