From ac0ac3910427a72afdfbd7f8d2447858478b7d03 Mon Sep 17 00:00:00 2001 From: cesarLima1 Date: Tue, 17 Dec 2024 15:01:45 -0400 Subject: [PATCH] [TM-1467] show tooltip over the land use type chart --- .../components/MonitoredCharts.tsx | 5 ++- .../components/GraphicIconDashboard.tsx | 33 ++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/admin/components/ResourceTabs/MonitoredTab/components/MonitoredCharts.tsx b/src/admin/components/ResourceTabs/MonitoredTab/components/MonitoredCharts.tsx index 8cca6618..16cbee3f 100644 --- a/src/admin/components/ResourceTabs/MonitoredTab/components/MonitoredCharts.tsx +++ b/src/admin/components/ResourceTabs/MonitoredTab/components/MonitoredCharts.tsx @@ -86,6 +86,9 @@ const MonitoredCharts = ({ const [hasNoData, setHasNoData] = useState(false); useEffect(() => { + if (isLoadingIndicator) { + setHasNoData(false); + } const noData = selected.some(chartId => { switch (chartId) { case "1": @@ -102,7 +105,7 @@ const MonitoredCharts = ({ } }); setHasNoData(noData); - }, [selected, parsedData, ecoRegionData, strategiesData, landUseData]); + }, [selected, parsedData, ecoRegionData, strategiesData, landUseData, isLoadingIndicator]); const renderChart = (chartId: React.Key) => { switch (chartId) { diff --git a/src/pages/dashboard/components/GraphicIconDashboard.tsx b/src/pages/dashboard/components/GraphicIconDashboard.tsx index 0ead992d..fc123b7f 100644 --- a/src/pages/dashboard/components/GraphicIconDashboard.tsx +++ b/src/pages/dashboard/components/GraphicIconDashboard.tsx @@ -11,11 +11,14 @@ import { DashboardTableDataProps } from "../index.page"; const GraphicIconDashboard = ({ data, maxValue }: { data: DashboardTableDataProps[]; maxValue: number }) => { const t = useT(); - const [tooltip, setTooltip] = useState<{ text: string | null; label: string | null; x: number; y: number }>({ + const [tooltip, setTooltip] = useState<{ + text: string | null; + label: string | null; + position: { top: number; left: number } | null; + }>({ text: null, label: null, - x: 0, - y: 0 + position: null }); const colorIconLabel = (label: string): { color: string; icon: keyof typeof IconNames } => { @@ -43,17 +46,23 @@ const GraphicIconDashboard = ({ data, maxValue }: { data: DashboardTableDataProp } }; - const handleMouseEnter = (event: MouseEvent, label: string, valueText: string) => { + const handleMouseMove = (event: MouseEvent, label: string, valueText: string) => { setTooltip({ text: valueText, label, - x: event.pageX, - y: event.pageY + position: { + top: event.clientY - 70, + left: event.clientX + } }); }; const handleMouseLeave = () => { - setTooltip({ text: null, label: null, x: 0, y: 0 }); + setTooltip({ + text: null, + label: null, + position: null + }); }; return ( @@ -72,18 +81,18 @@ const GraphicIconDashboard = ({ data, maxValue }: { data: DashboardTableDataProp )} style={{ width: `${percentage}%` }} key={index} - onMouseEnter={e => handleMouseEnter(e, item.label, item.valueText)} + onMouseMove={e => handleMouseMove(e, item.label, item.valueText)} onMouseLeave={handleMouseLeave} /> ); })} - {tooltip.text && ( + {tooltip.text && tooltip.position && (
@@ -109,7 +118,7 @@ const GraphicIconDashboard = ({ data, maxValue }: { data: DashboardTableDataProp
handleMouseEnter(e, item.label, item.valueText)} + onMouseMove={e => handleMouseMove(e, item.label, item.valueText)} onMouseLeave={handleMouseLeave} >