Skip to content

Commit f516112

Browse files
committed
#910 Fix gzmtr int 2024 anchorAt and textOffset
1 parent 2c5dfbe commit f516112

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/components/svgs/stations/gzmtr-int-2024.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ const GzmtrInt2024Station = (props: StationComponentProps) => {
5858
// temporary fix for the missing id on the top element of the station
5959
const iconEl = React.useRef<SVGGElement | null>(null);
6060
iconEl.current?.querySelectorAll('path')?.forEach(elem => elem.setAttribute('id', `stn_core_${id}`));
61+
const iconOffset = iconEl.current
62+
?.querySelector('g')
63+
?.getAttribute('transform')
64+
?.slice(10, -1)
65+
?.split(',')
66+
?.map(s => Number(s)) ?? [0, 0];
6167

6268
const [iconBBox, setIconBBox] = React.useState({ x1: 0, x2: 0, y1: 0, y2: 0 });
6369
React.useEffect(() => {
@@ -74,11 +80,17 @@ const GzmtrInt2024Station = (props: StationComponentProps) => {
7480
strokeColour: s[2],
7581
}));
7682

77-
const textX = nameOffsetX === 'left' ? iconBBox.x1 + textDX : nameOffsetX === 'right' ? iconBBox.x2 - textDX : 0;
83+
const textX =
84+
nameOffsetX === 'left'
85+
? -(iconBBox.x2 - iconBBox.x1) / 2 + iconOffset[0] / 2 + textDX
86+
: nameOffsetX === 'right'
87+
? (iconBBox.x2 - iconBBox.x1) / 2 + iconOffset[0] / 2 - textDX
88+
: 0;
7889
const textY =
7990
(names[NAME_DY[nameOffsetY].namesPos].split('\n').length * NAME_DY[nameOffsetY].lineHeight +
8091
(iconBBox.y2 - iconBBox.y1) / 2) *
81-
NAME_DY[nameOffsetY].polarity;
92+
NAME_DY[nameOffsetY].polarity +
93+
iconOffset[1] / 2;
8294
const textAnchor =
8395
nameOffsetX === 'left'
8496
? 'end'

0 commit comments

Comments
 (0)