From e1cd7c94fb13f8e49667b17554d22ce8de627a2a Mon Sep 17 00:00:00 2001 From: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Sat, 10 May 2025 07:58:26 +0900 Subject: refactor(frontend): use* 関数の格納場所のフォルダ名を composables に変更 (#16004) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor(frontend): use* 関数の格納場所を正式名称(composables)に変更 * migrate * move useLoading --- .../frontend/src/composables/use-chart-tooltip.ts | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 packages/frontend/src/composables/use-chart-tooltip.ts (limited to 'packages/frontend/src/composables/use-chart-tooltip.ts') diff --git a/packages/frontend/src/composables/use-chart-tooltip.ts b/packages/frontend/src/composables/use-chart-tooltip.ts new file mode 100644 index 0000000000..bba64fc6ee --- /dev/null +++ b/packages/frontend/src/composables/use-chart-tooltip.ts @@ -0,0 +1,63 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +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' }) { + const tooltipShowing = ref(false); + const tooltipX = ref(0); + const tooltipY = ref(0); + const tooltipTitle = ref(null); + const tooltipSeries = ref<{ + backgroundColor: string; + borderColor: string; + text: string; + }[] | null>(null); + const { dispose: disposeTooltipComponent } = os.popup(MkChartTooltip, { + showing: tooltipShowing, + x: tooltipX, + y: tooltipY, + title: tooltipTitle, + series: tooltipSeries, + }, {}); + + onUnmounted(() => { + disposeTooltipComponent(); + }); + + onDeactivated(() => { + tooltipShowing.value = false; + }); + + function handler(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.scrollX + context.tooltip.caretX; + if (opts.position === 'top') { + tooltipY.value = rect.top + window.scrollY; + } else if (opts.position === 'middle') { + tooltipY.value = rect.top + window.scrollY + context.tooltip.caretY; + } + } + + return { + handler, + }; +} -- cgit v1.3.1-freya