From 60d7eba6dba5011778433650fe129c371f06d350 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Tue, 11 Mar 2025 13:15:58 -0600 Subject: [PATCH] fixed svg by creating data arrays rahter than the react svg component arrays and then mapping those arrays out to svg tags, apparently it didn't like having mutliple react children --- src/bin/BinSVGV2.tsx | 334 +++++++++++++++++++++++++++++++------------ 1 file changed, 241 insertions(+), 93 deletions(-) diff --git a/src/bin/BinSVGV2.tsx b/src/bin/BinSVGV2.tsx index 7b60464..6e47511 100644 --- a/src/bin/BinSVGV2.tsx +++ b/src/bin/BinSVGV2.tsx @@ -125,6 +125,43 @@ interface GrainNodePoint { y: number; } +interface EllipseData { + key: string | number; + xCenter: string | number; + yCenter: string | number; + xRadius: string | number; + yRadius: string | number; + fillColour: string; +} + +interface NodeData { //this could be either a box or a circle depending + key: string | number + x: number; + y: number + width: string | number + height: string | number + borderRad: string | number + nodeNumber: number + nodeTemp: number +} + +interface CircleData { + key: string | number + centerX: string | number + centerY: string | number + radius: string | number + onClick?: () => void +} + +interface TextData { + key: number | string, + x: number, + y: number, + stroke: string, + filter?: string, + value: string +} + export default function BinSVGV2(props: Props) { const classes = useStyles(); const { @@ -399,6 +436,20 @@ export default function BinSVGV2(props: Props) { return classes.cableNode; }; + const renderText = (text: TextData[]) => { + return text.map(text => ( + + {text.value} + + )) + } + const multiCables = () => { if (!cables) return; //sort the cables by node number so the one with the most nodes is in the middle @@ -478,11 +529,17 @@ export default function BinSVGV2(props: Props) { const filledToY = (fillPercentage * (minNodeY - maxNodeY)) / 100 + maxNodeY; const nodeSpacingY = (maxNodeY - minNodeY) / (cable.temperatures.length + 1); //removing the +1 here would place the nodes starting at the bottom of the cable line rather than from the center - let nodeHeatMap: React.SVGProps[] = []; - let nodes: React.SVGProps[] = []; - let temps: React.SVGProps[] = []; - let hums: React.SVGProps[] = []; - let nodeClickers: React.SVGProps[] = []; + //let nodeHeatMap: React.SVGProps[] = []; + let nodeHeatMapData: EllipseData[] = []; + //let nodes: React.SVGProps[] = []; + let nodesData: NodeData[] = []; + + //let temps: React.SVGProps[] = []; + let tempData: TextData[] = [] + //let hums: React.SVGProps[] = []; + let humData: TextData[] = []; + //let nodeClickers: React.SVGProps[] = []; + let nodeClickData: CircleData[] = []; cable.temperatures.forEach((temp, index) => { //since the array goes from the top down set the nodeNumber we are currently working with to be the number of nodes we have left @@ -509,88 +566,141 @@ export default function BinSVGV2(props: Props) { //if we are using the auto top nodes only show the heatmap for nodes at or below the top node if (cable.topNode > 0) { if (nodeNumber <= cable.topNode) { - nodeHeatMap.push( - - ); + // nodeHeatMap.push( + // + // ); + nodeHeatMapData.push({ + key: index, + xCenter: cablePos, + yCenter: nodeY, + xRadius: "120", + yRadius: "60", + fillColour: getGrainGradient(temp) + }) } } else if (nodeY > filledToY) { //otherwise use the fill level of the bin - nodeHeatMap.push( - - ); + // nodeHeatMap.push( + // + // ); + nodeHeatMapData.push({ + key: index, + xCenter: cablePos, + yCenter: nodeY, + xRadius: "120", + yRadius: "60", + fillColour: getGrainGradient(temp) + }) } const displayWidth = 90; const displayHeight = 45; const cornerRad = 10; //add the boxes to display the temps in fulscreen view - nodes.push( - showTempHum ? ( - - ) : ( - - {nodeNumber === topNode && topNodeHat(cablePos, nodeY)} - - - ) - ); + // nodes.push( + // showTempHum ? ( + // + // ) : ( + // + // {nodeNumber === topNode && topNodeHat(cablePos, nodeY)} + // + // + // ) + // ); + //if showTempHum is true will render as a box otherwise will render as a circle which is why the x,y, and radius values will be different + nodesData.push({ + key: "node" + index, + x: showTempHum ? cablePos - displayWidth / 2 : cablePos, + y: showTempHum ? nodeY - displayHeight / 2 : nodeY, + height: displayHeight, + width: displayWidth, + borderRad: showTempHum ? cornerRad : "16", + nodeNumber: nodeNumber, + nodeTemp: temp + }) - temps.push( - - {displayTemp.toFixed(1)}° - - ); - hums.push( - - {ExtractMoisture(props.grainType, temp, cable.humidities[index] ?? 0).toFixed(1)}% - - ); + // temps.push( + // + // {displayTemp.toFixed(1)}° + // + // ); + tempData.push({ + key: "node" + index + "temp", + x: cablePos, + y: nodeY + 10, + stroke: "blue", + value: displayTemp.toFixed(1) +"°", + filter: "drop-shadow( 4px 4px 10px rgba(0, 0, 0, .7))" + }) + // hums.push( + // + // {ExtractMoisture(props.grainType, temp, cable.humidities[index] ?? 0).toFixed(1)}% + // + // ); + humData.push({ + key: "node" + index + "hum", + x: cablePos, + y: nodeY + 10, + stroke: "green", + value: ExtractMoisture(props.grainType, temp, cable.humidities[index] ?? 0).toFixed(1)+"%", + }) !showTempHum && - nodeClickers.push( - { - if (cable.key() !== "" && cableNodeClicked) { - cableNodeClicked(cable, nodeNumber); - } - }} - cx={cablePos} - cy={nodeY} - className={classes.clickableArea} - r="50" - /> - ); + // nodeClickers.push( + // { + // if (cable.key() !== "" && cableNodeClicked) { + // cableNodeClicked(cable, nodeNumber); + // } + // }} + // cx={cablePos} + // cy={nodeY} + // className={classes.clickableArea} + // r="50" + // /> + // ); + nodeClickData.push({ + key: "node"+index, + centerX: cablePos, + centerY: nodeY, + radius: "50", + onClick: () => { + if (cable.key() !== "" && cableNodeClicked) { + cableNodeClicked(cable, nodeNumber); + } + } + }) //if the current node is the top node of the cable use its x and y to add to the cable grain path if (nodeNumber === topNode) { @@ -617,22 +727,60 @@ export default function BinSVGV2(props: Props) { numNodes--; }); - // cableLines.push( - // - // {nodeHeatMap} - // - // {nodes} - // {showTempHum && (extraDetails === "temps" ? temps : hums)} - // {nodeClickers} - // - // ); + cableLines.push( + + {nodeHeatMapData.map(e => ( + + ))} + + {nodesData.map(e => { + if (showTempHum) { + return ( + + ) + } else { + return ( + + {e.nodeNumber === topNode && topNodeHat(cablePos, e.y)} + + + ) + } + })} + {showTempHum && (extraDetails === "temps" ? renderText(tempData) : renderText(humData))} + {nodeClickData.map((e) => ( + + ))} + + ); }); //for single cable bins the endY would still be 0 so just make it the startY to draw a straight line across the bin if (cableGrainEndY === 0) {