@@ -129,8 +129,8 @@ function MostFrequentKeywords() {
129129
130130 const getEllipseSize = text => {
131131 const len = text . length ;
132- if ( len > 14 ) return { rx : 48 , ry : 18 } ;
133- if ( len > 10 ) return { rx : 40 , ry : 16 } ;
132+ if ( len > 14 ) return { rx : 48 , ry : 22 } ;
133+ if ( len > 10 ) return { rx : 42 , ry : 22 } ;
134134 return { rx : 32 , ry : 16 } ;
135135 } ;
136136
@@ -139,9 +139,6 @@ function MostFrequentKeywords() {
139139 y : Math . max ( padding , Math . min ( height - padding , y ) ) ,
140140 } ) ;
141141
142- const truncateText = ( text , max = 14 ) =>
143- text . length <= max ? text : `${ text . slice ( 0 , max - 1 ) } …` ;
144-
145142 tags . forEach ( ( tag , i ) => {
146143 const angle = angles [ i ] ;
147144 const isLeftOrRight = Math . abs ( Math . cos ( angle ) ) > 0.9 ;
@@ -186,16 +183,44 @@ function MostFrequentKeywords() {
186183 window . open ( `/tags/${ tag . tag } ` , '_blank' ) ;
187184 } ) ;
188185
189- svg
186+ const textEl = svg
190187 . append ( 'text' )
191188 . attr ( 'x' , x )
192- . attr ( 'y' , y + 4 )
189+ . attr ( 'y' , y )
193190 . attr ( 'text-anchor' , 'middle' )
194191 . attr ( 'font-size' , '11px' )
195- . attr ( 'fill' , '#111' )
196- . text ( truncateText ( tag . tag ) )
197- . append ( 'title' )
198- . text ( tag . tag ) ;
192+ . attr ( 'fill' , '#111' ) ;
193+
194+ // Split text if it's longer than 14 characters
195+ let words = [ ] ;
196+ if ( tag . tag . length > 14 ) {
197+ const parts = tag . tag . split ( ' ' ) ;
198+ if ( parts . length > 1 ) {
199+ const mid = Math . ceil ( parts . length / 2 ) ;
200+ words = [ parts . slice ( 0 , mid ) . join ( ' ' ) , parts . slice ( mid ) . join ( ' ' ) ] ;
201+ } else {
202+ const midIndex = Math . ceil ( tag . tag . length / 2 ) ;
203+ words = [ tag . tag . slice ( 0 , midIndex ) , tag . tag . slice ( midIndex ) ] ;
204+ }
205+ } else {
206+ words = [ tag . tag ] ;
207+ }
208+
209+ if ( words . length > 1 ) {
210+ textEl . attr ( 'transform' , `translate(0, -7)` ) ;
211+ }
212+
213+ // Add tspans for each line
214+ words . forEach ( ( line , index ) => {
215+ textEl
216+ . append ( 'tspan' )
217+ . attr ( 'x' , x )
218+ . attr ( 'dy' , index === 0 ? 4 : 14 )
219+ . text ( line ) ;
220+ } ) ;
221+
222+ // Tooltip with full text
223+ textEl . append ( 'title' ) . text ( tag . tag ) ;
199224 } ) ;
200225 } , 100 ) ;
201226
0 commit comments