From 949ce4a21f2618ceae4a359b263ba19455c17793 Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Mon, 22 Dec 2025 12:53:31 +0530 Subject: [PATCH] feat: Implement `ElementContent` for rendering diverse simulation dashboard elements and `AnalyzerManager` for processing and updating analysis data. --- .../SimulationDashboard/AnalyzerManager.tsx | 44 +++++++++++++++---- .../components/element/ElementContent.tsx | 28 +++++++----- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/app/src/components/SimulationDashboard/AnalyzerManager.tsx b/app/src/components/SimulationDashboard/AnalyzerManager.tsx index fb7b44e..ef3ec35 100644 --- a/app/src/components/SimulationDashboard/AnalyzerManager.tsx +++ b/app/src/components/SimulationDashboard/AnalyzerManager.tsx @@ -91,6 +91,8 @@ const AnalyzerManager: React.FC = () => { // 2. Handle Graph (Store Update) // This effect MUST NOT depend on 'blocks' to avoid infinite loop (updateGraphData modifies blocks) + const lineChartHistory = useRef>(new Map()); + useEffect(() => { if (!analysis) return; @@ -107,14 +109,40 @@ const AnalyzerManager: React.FC = () => { const assetAnalysis = getAssetAnalysis(assetId); if (assetAnalysis) { - const newGraphData = dataKeys.map((key) => { - const val = resolvePath(assetAnalysis, key); - return { - // Make the key readable or just use it as name - name: key.split(".").pop() || key, - value: typeof val === "number" ? val : 0, - }; - }); + let newGraphData: any[] = []; + + if (element.graphType === "line") { + const history = lineChartHistory.current.get(element.elementUuid) || []; + const now = new Date(); + const timeStr = now.toLocaleTimeString([], { hour12: false }); + + const dataPoint: any = { name: timeStr }; + dataKeys.forEach((key) => { + const val = resolvePath(assetAnalysis, key); + dataPoint[key] = typeof val === "number" ? val : 0; + }); + + // Add slight variations if values are static to make it "live" as requested (optional, but requested "up and down") + // If the user feels the values are strictly from store, I should stick to store. + // "makeing the lines go up dna down as times goes on" + // If I just use store values, they might be flat. + // I will stick to store values. The user's system likely updates `analysis`. + + history.push(dataPoint); + if (history.length > 20) history.shift(); + + newGraphData = [...history]; + lineChartHistory.current.set(element.elementUuid, history); + } else { + newGraphData = dataKeys.map((key) => { + const val = resolvePath(assetAnalysis, key); + return { + // Make the key readable or just use it as name + name: key.split(".").pop() || key, + value: typeof val === "number" ? val : 0, + }; + }); + } // Deep check to avoid unnecessary updates if (JSON.stringify(newGraphData) !== JSON.stringify(element.graphData)) { diff --git a/app/src/components/SimulationDashboard/components/element/ElementContent.tsx b/app/src/components/SimulationDashboard/components/element/ElementContent.tsx index aac5e73..f6fe995 100644 --- a/app/src/components/SimulationDashboard/components/element/ElementContent.tsx +++ b/app/src/components/SimulationDashboard/components/element/ElementContent.tsx @@ -126,17 +126,23 @@ const ElementContent: React.FC = ({ element, resolvedData } - + {element.dataBinding?.dataType === "single-machine" && element.dataBinding.dataValue ? ( + (Array.isArray(element.dataBinding.dataValue) ? element.dataBinding.dataValue : [element.dataBinding.dataValue as string]).map((key, index) => ( + + )) + ) : ( + + )} )}