@@ -8,26 +8,31 @@ export const seatSize = 28;
88export const seatLabelFontSize = seatSize / 3 ;
99
1010const Seat = forwardRef ( ( { x, y, id, label, categories, category, status, ...props } , ref ) => {
11- let textX = x - seatLabelFontSize / 3.5 ;
12-
13- const labelLength = label ?. toString ( ) ?. length ?? 0 ;
11+ const categoryObject = useMemo ( ( ) => categories ?. find ?. ( ( c ) => c . id === category ) , [ categories , category ] ) ;
1412
15- if ( labelLength >= 2 ) textX -= ( seatLabelFontSize / 2.75 ) * ( labelLength - 1 ) ;
13+ const textX = useMemo ( ( ) => {
14+ let value = ( + ref . current ?. getAttribute ( "cx" ) || x ) - seatLabelFontSize / 3.5 ;
15+ const labelLength = label ?. toString ( ) ?. length ?? 0 ;
16+ if ( labelLength >= 2 ) value -= ( seatLabelFontSize / 2.75 ) * ( labelLength - 1 ) ;
17+ return value ;
18+ } , [ ref , label , x ] ) ;
1619
17- const categoryObject = useMemo ( ( ) => categories ?. find ?. ( ( c ) => c . id === category ) , [ categories , category ] ) ;
20+ const textY = useMemo ( ( ) => {
21+ return ( + ref . current ?. getAttribute ( "cy" ) || y ) + seatLabelFontSize / 2.75 ;
22+ } , [ ref , label , y ] ) ;
1823
1924 useEffect ( ( ) => {
2025 if ( ref . current ) {
2126 const seat = d3Extended . select ( ref . current ) ;
2227 const seatLabel = d3Extended . selectById ( `${ id } -label` ) ;
2328 const status = seat . attr ( dataAttributes . status ) ;
2429 if ( status === SeatStatus . Unavailable || status === SeatStatus . Reserved ) {
25- seat . style ( "color" , seatStatusColors [ status ] . background , "important" ) ;
26- seatLabel ?. style ( "stroke" , seatStatusColors [ status ] . label , "important" ) ;
30+ seat . style ( "color" , seatStatusColors [ status ] . background ) ;
31+ seatLabel ?. style ( "stroke" , seatStatusColors [ status ] . label ) ;
2732 } else {
2833 if ( categoryObject ) {
29- seat . style ( "color" , categoryObject . color , "important" ) ;
30- seatLabel ?. style ( "stroke" , categoryObject . textColor , "important" ) ;
34+ seat . style ( "color" , categoryObject . color ) ;
35+ seatLabel ?. style ( "stroke" , categoryObject . textColor ) ;
3136 }
3237 }
3338 }
@@ -49,7 +54,7 @@ const Seat = forwardRef(({ x, y, id, label, categories, category, status, ...pro
4954 < text
5055 id = { `${ id } -label` }
5156 x = { textX }
52- y = { y + seatLabelFontSize / 2.75 }
57+ y = { textY }
5358 fontSize = { seatLabelFontSize }
5459 fontWeight = { 200 }
5560 letterSpacing = { 1 }
0 commit comments