problem: merits and satflow graph doesn't highlight on hover

solution: trigger the `toggleDataPointSelection` method when the table row is hovered

resolve https://github.com/nostrocket/hypergolic/issues/76
This commit is contained in:
Bob
2024-08-20 17:26:37 +08:00
parent 2a1a523a60
commit f139ec8d39
3 changed files with 41 additions and 19 deletions

View File

@@ -122,6 +122,16 @@
function c(i: number) { function c(i: number) {
return COLORS[i]; return COLORS[i];
} }
let hoveredPubkey: string | null = null;
function handleRowHover(pubkey: string) {
hoveredPubkey = pubkey;
}
function handleRowLeave() {
hoveredPubkey = null;
}
</script> </script>
<Card.Root class="sm:col-span-3"> <Card.Root class="sm:col-span-3">
@@ -131,7 +141,7 @@
<div class="col-span-1"> <div class="col-span-1">
This graph displays the Meritization of equity in {rocket.Name()}. These npubs own the {rocket.Name()} This graph displays the Meritization of equity in {rocket.Name()}. These npubs own the {rocket.Name()}
satflow. satflow.
<Pie data={$merits} /> <Pie data={$merits} {hoveredPubkey} />
</div> </div>
<Table.Root class="col-span-1 text-black"> <Table.Root class="col-span-1 text-black">
@@ -144,7 +154,11 @@
</Table.Header> </Table.Header>
<Table.Body> <Table.Body>
{#each $merits as { pubkey, merits, sats }, i (pubkey)} {#each $merits as { pubkey, merits, sats }, i (pubkey)}
<Table.Row class="{c(i)} hover:{c(i)} hover:brightness-125 hover:contrast-150"> <Table.Row
class="{c(i)} hover:{c(i)} filter transition duration-300 hover:brightness-50"
on:mouseenter={() => handleRowHover(pubkey)}
on:mouseleave={handleRowLeave}
>
<Table.Cell> <Table.Cell>
<div class="flex flex-nowrap items-center gap-2"> <div class="flex flex-nowrap items-center gap-2">
<Avatar ndk={$ndk} {pubkey} class="h-8 w-8 flex-none rounded-full object-cover" /> <Avatar ndk={$ndk} {pubkey} class="h-8 w-8 flex-none rounded-full object-cover" />

View File

@@ -1,12 +1,16 @@
<script lang="ts"> <script lang="ts">
import { ndk } from '@/ndk.js'; import { ndk } from '@/ndk.js';
import { Chart } from 'flowbite-svelte'; import { Chart } from 'flowbite-svelte';
import type { ApexOptions } from 'apexcharts';
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import { Toaster } from '$lib/components/ui/sonner'; import { Toaster } from '$lib/components/ui/sonner';
export let data: { pubkey: string; merits: number; sats: number }[]; export let data: { pubkey: string; merits: number; sats: number }[];
export let hoveredPubkey: string | null = null;
let pubkeys = Array.from(data, (x) => x.pubkey); let pubkeys = Array.from(data, (x) => x.pubkey);
let options = { let chartInstance: ApexCharts;
let options: ApexOptions = {
series: Array.from(data, (x) => x.merits), series: Array.from(data, (x) => x.merits),
colors: [ colors: [
'#f43f5e', '#f43f5e',
@@ -23,11 +27,16 @@
chart: { chart: {
height: 320, height: 320,
width: '100%', width: '100%',
type: 'donut' type: 'donut',
events: {
mounted: function (chartContext, config) {
chartInstance = chartContext;
}
}
}, },
stroke: { stroke: {
colors: ['transparent'], colors: ['transparent'],
lineCap: '' lineCap: undefined
}, },
plotOptions: { plotOptions: {
pie: { pie: {
@@ -45,7 +54,7 @@
label: 'Merit Distribution', label: 'Merit Distribution',
fontFamily: 'Inter, sans-serif', fontFamily: 'Inter, sans-serif',
formatter: function (w) { formatter: function (w) {
const sum = w.globals.seriesTotals.reduce((a, b) => { const sum = w.globals.seriesTotals.reduce((a: number, b: number) => {
return a + b; return a + b;
}, 0); }, 0);
return `${sum}`; return `${sum}`;
@@ -71,7 +80,7 @@
}, },
labels: ['Direct', 'Sponsor', 'Affiliate', 'Email marketing'], labels: ['Direct', 'Sponsor', 'Affiliate', 'Email marketing'],
dataLabels: { dataLabels: {
enabled: false enabled: true
}, },
legend: { legend: {
show: false, show: false,
@@ -118,21 +127,18 @@
}); });
} }
// <Card> $: {
// <div class="flex justify-between items-start w-full"> if (chartInstance && hoveredPubkey !== null) {
// <div class="flex-col items-center"> const index = data.findIndex((item) => item.pubkey === hoveredPubkey);
// <div class="flex items-center mb-1"> if (index !== -1) {
// <h5 class="text-xl font-bold leading-none text-gray-900 dark:text-white me-1">Merit Distribution</h5> chartInstance.toggleDataPointSelection(index);
}
// </div> }
// </div> }
// </div>
// </Card>
</script> </script>
<div class="relative h-full w-full"> <div class="relative h-full w-full">
<Chart options={$o} class="py-6" /> <Chart options={$o} class="py-6" bind:chart={chartInstance} />
<div class="absolute -top-10 left-1/2 z-20 w-[356px] -translate-x-1/2 transform"> <div class="absolute -top-10 left-1/2 z-20 w-[356px] -translate-x-1/2 transform">
<Toaster position="top-center" id="purchase" duration={3000} /> <Toaster position="top-center" id="purchase" duration={3000} />
</div> </div>

View File

@@ -18,6 +18,8 @@
{...$$restProps} {...$$restProps}
on:click on:click
on:keydown on:keydown
on:mouseenter
on:mouseleave
> >
<slot /> <slot />
</tr> </tr>