@@ -19,24 +19,6 @@ let prevLeft, prevTop
19
19
let quadrantScrollHandlerReference
20
20
let scrollFlag = false
21
21
22
- const createElement = ( tagName , text , attributes ) => {
23
- const tag = document . createElement ( tagName )
24
- Object . keys ( attributes ) . forEach ( ( keyName ) => {
25
- tag . setAttribute ( keyName , attributes [ keyName ] )
26
- } )
27
- tag . appendChild ( document . createTextNode ( text ) )
28
- return tag
29
- }
30
-
31
- const replaceChild = ( element , child ) => {
32
- let elementChild = element . lastElementChild
33
- while ( elementChild ) {
34
- element . removeChild ( elementChild )
35
- elementChild = element . lastElementChild
36
- }
37
- element . appendChild ( child )
38
- }
39
-
40
22
function selectRadarQuadrant ( order , startAngle , name ) {
41
23
const noOfBlips = d3 . selectAll ( '.quadrant-group-' + order + ' .blip-link' ) . size ( )
42
24
d3 . select ( '#radar' ) . classed ( 'no-blips' , noOfBlips === 0 )
@@ -217,19 +199,19 @@ function wrapQuadrantNameInMultiLine(elem, isTopQuadrants, quadrantNameGroup, ti
217
199
const words = text . split ( ' ' )
218
200
let line = ''
219
201
220
- replaceChild ( element , createElement ( ' tspan' , text , { id : ' text-width-check' } ) )
202
+ element . innerHTML = `< tspan id=" text-width-check"> ${ text } </tspan >`
221
203
const testElem = document . getElementById ( 'text-width-check' )
222
204
223
205
function maxCharactersToFit ( testLine , suffix ) {
224
206
let j = 1
225
207
let firstLineWidth = 0
226
208
const testElem1 = document . getElementById ( 'text-width-check' )
227
- testElem1 . textContent = testLine
209
+ testElem1 . innerHTML = testLine
228
210
if ( testElem1 . getBoundingClientRect ( ) . width < maxWidth ) {
229
211
return testLine . length
230
212
}
231
213
while ( firstLineWidth < maxWidth && testLine . length > j ) {
232
- testElem1 . textContent = testLine . substring ( 0 , j ) + suffix
214
+ testElem1 . innerHTML = testLine . substring ( 0 , j ) + suffix
233
215
firstLineWidth = testElem1 . getBoundingClientRect ( ) . width
234
216
235
217
j ++
@@ -250,33 +232,42 @@ function wrapQuadrantNameInMultiLine(elem, isTopQuadrants, quadrantNameGroup, ti
250
232
if ( testElem . getBoundingClientRect ( ) . width > maxWidth ) {
251
233
for ( let i = 0 ; i < words . length ; i ++ ) {
252
234
let testLine = line + words [ i ] + ' '
253
- testElem . textContent = testLine
235
+ testElem . innerHTML = testLine
254
236
const textWidth = testElem . getBoundingClientRect ( ) . width
255
237
256
238
if ( textWidth > maxWidth ) {
257
239
if ( i === 0 ) {
258
240
let lineBreakIndex = maxCharactersToFit ( testLine , '-' )
259
- const elementText = `${ words [ i ] . substring ( 0 , lineBreakIndex ) } -`
260
- element . appendChild ( createElement ( 'tspan' , elementText , { x : '0' , dy } ) )
241
+ element . innerHTML += '<tspan x="0" dy="' + dy + '">' + words [ i ] . substring ( 0 , lineBreakIndex ) + '-</tspan>'
261
242
const secondLine = words [ i ] . substring ( lineBreakIndex , words [ i ] . length ) + ' ' + words . slice ( i + 1 ) . join ( ' ' )
262
243
lineBreakIndex = maxCharactersToFit ( secondLine , '...' )
263
- const text = `${ secondLine . substring ( 0 , lineBreakIndex ) } ${ ellipsis ( lineBreakIndex , secondLine ) } `
264
- element . appendChild ( createElement ( 'tspan' , text , { x : '0' , dy : '20' } ) )
244
+ element . innerHTML +=
245
+ '<tspan x="0" dy="' +
246
+ 20 +
247
+ '">' +
248
+ secondLine . substring ( 0 , lineBreakIndex ) +
249
+ ellipsis ( lineBreakIndex , secondLine ) +
250
+ '</tspan>'
265
251
break
266
252
} else {
267
- element . appendChild ( createElement ( ' tspan' , line , { x : '0' , dy } ) )
253
+ element . innerHTML += '< tspan x="0" dy="' + dy + '">' + line + '</tspan>'
268
254
const secondLine = words . slice ( i ) . join ( ' ' )
269
255
const lineBreakIndex = maxCharactersToFit ( secondLine , '...' )
270
- const text = `${ secondLine . substring ( 0 , lineBreakIndex ) } ${ ellipsis ( lineBreakIndex , secondLine ) } `
271
- element . appendChild ( createElement ( 'tspan' , text , { x : '0' , dy : '20' } ) )
256
+ element . innerHTML +=
257
+ '<tspan x="0" dy="' +
258
+ 20 +
259
+ '">' +
260
+ secondLine . substring ( 0 , lineBreakIndex ) +
261
+ ellipsis ( lineBreakIndex , secondLine ) +
262
+ '</tspan>'
272
263
}
273
264
line = words [ i ] + ' '
274
265
} else {
275
266
line = testLine
276
267
}
277
268
}
278
269
} else {
279
- element . appendChild ( createElement ( ' tspan' , text , { x : '0' } ) )
270
+ element . innerHTML += '< tspan x="0">' + text + '</tspan>'
280
271
}
281
272
282
273
document . getElementById ( 'text-width-check' ) . remove ( )
0 commit comments