diff --git a/frontend/components/dashboard/scan-terminal/AiCityTemperatureChart.tsx b/frontend/components/dashboard/scan-terminal/AiCityTemperatureChart.tsx index 81d8424d..f67834fb 100644 --- a/frontend/components/dashboard/scan-terminal/AiCityTemperatureChart.tsx +++ b/frontend/components/dashboard/scan-terminal/AiCityTemperatureChart.tsx @@ -1,5 +1,5 @@ import type { ChartConfiguration } from "chart.js"; -import { useEffect, useMemo, useRef, useState } from "react"; +import { useMemo, useRef } from "react"; import { BarChart3 } from "lucide-react"; import type { CityDetail } from "@/lib/dashboard-types"; import { useChart } from "@/hooks/useChart"; @@ -64,15 +64,14 @@ function buildTemperatureChartSignature(detail: CityDetail) { export function AiCityTemperatureChart({ detail }: { detail: CityDetail }) { const { locale } = useI18n(); const sectionRef = useRef(null); - const [shouldRenderChart, setShouldRenderChart] = useState(false); const cityKey = `${detail.name || detail.display_name || ""}:${detail.local_date || ""}`; const chartSignature = useMemo( - () => (shouldRenderChart ? buildTemperatureChartSignature(detail) : ""), - [detail, shouldRenderChart], + () => buildTemperatureChartSignature(detail), + [detail], ); const computedChartData = useMemo( - () => (shouldRenderChart ? getTemperatureChartData(detail, locale) : null), - [chartSignature, detail, locale, shouldRenderChart], + () => getTemperatureChartData(detail, locale), + [chartSignature, detail, locale], ); const lastChartDataRef = useRef<{ cityKey: string; @@ -233,26 +232,6 @@ export function AiCityTemperatureChart({ detail }: { detail: CityDetail }) { observationLabel, ]); - useEffect(() => { - if (shouldRenderChart) return; - if (typeof window === "undefined" || !("IntersectionObserver" in window)) { - setShouldRenderChart(true); - return; - } - const target = sectionRef.current; - if (!target) return; - const observer = new IntersectionObserver( - (entries) => { - if (!entries.some((entry) => entry.isIntersecting)) return; - setShouldRenderChart(true); - observer.disconnect(); - }, - { rootMargin: "220px 0px" }, - ); - observer.observe(target); - return () => observer.disconnect(); - }, [shouldRenderChart]); - return (
@@ -260,13 +239,7 @@ export function AiCityTemperatureChart({ detail }: { detail: CityDetail }) { {locale === "en-US" ? "Evidence · intraday path" : "证据 · 今日日内路径"}
- {shouldRenderChart ? ( - - ) : ( -
- {locale === "en-US" ? "Chart will render when visible" : "图表进入视口后再渲染"} -
- )} +
{chartData ? (