From 16608af18ac3582eee89a17449059b36ce4ae77a Mon Sep 17 00:00:00 2001 From: thekingofcity <3353040+thekingofcity@users.noreply.github.com> Date: Wed, 22 Sep 2021 23:00:42 +0800 Subject: [PATCH] #137 Incomplete render of text station in destination panel of Shanghai Metro (#138) --- src/svgs/destination/destination-shmetro.tsx | 62 +++++++++++++------- src/svgs/indoor/indoor-shmetro.tsx | 2 +- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/svgs/destination/destination-shmetro.tsx b/src/svgs/destination/destination-shmetro.tsx index e54aa9d71..a2fd8ac1f 100644 --- a/src/svgs/destination/destination-shmetro.tsx +++ b/src/svgs/destination/destination-shmetro.tsx @@ -135,43 +135,61 @@ const PlatformNum = () => { const param = useAppSelector(store => store.param); // Total width: 325 - return ( - - - - {param.platform_num} - - - 站台 - - + return useMemo( + ()=>( + + + + {param.platform_num} + + + 站台 + + + ), + // eslint-disable-next-line react-hooks/exhaustive-deps + [param.platform_num] ); }; const LineNameBoxText = () => { - const param = useAppSelector(store => store.param); - const { line_name } = param; + const { line_name, direction, svgWidth } = useAppSelector(store => store.param); - const boxX = param.direction === 'l' ? param.svgWidth.destination - 36 - 132 : 36 + 132; + const boxX = direction === 'l' ? svgWidth.destination - 42 : 42; + + // get the exact station name width so that the + // line color rectangle can be the right width. + const stnNameEl = useRef(null); + // the original name position + const [bBox, setBBox] = React.useState({ width: 0 } as DOMRect); + React.useEffect( + () => setBBox(stnNameEl.current!.getBBox()), + // eslint-disable-next-line react-hooks/exhaustive-deps + [...line_name] + ); + + const rectDx = (direction === 'l' ? -bBox.width : 0) - 6 + const stnNameEnDx = (direction === 'l' ? -1 : 1) * bBox.width / 2 - // Total width: 264 return useMemo( () => ( - - - - {line_name[0]} - - + + + + + {line_name[0]} + + + {line_name[1]} ), // eslint-disable-next-line react-hooks/exhaustive-deps - [boxX, ...line_name] - ); + [bBox, boxX, direction, line_name] + ) }; const LineNameBoxNumber = () => { diff --git a/src/svgs/indoor/indoor-shmetro.tsx b/src/svgs/indoor/indoor-shmetro.tsx index 3ce69d4e0..550f78023 100644 --- a/src/svgs/indoor/indoor-shmetro.tsx +++ b/src/svgs/indoor/indoor-shmetro.tsx @@ -194,7 +194,7 @@ const InfoElements = () => { ), // eslint-disable-next-line react-hooks/exhaustive-deps - [param.svgWidth.indoor, param.svg_height]); + [param.svgWidth.indoor, param.svg_height, param.line_name]); }; /* Some unused functions to split branches from the main line.