11const d3 = require ( 'd3' )
2- const { getElementWidth, getElementHeight, decodeHTML } = require ( '../../util/htmlUtil' )
3- const { toRadian } = require ( '../../util/mathUtils' )
4- const { getRingIdString } = require ( '../../util/stringUtil' )
2+ const { getElementWidth, getElementHeight, decodeHTML} = require ( '../../util/htmlUtil' )
3+ const { toRadian} = require ( '../../util/mathUtils' )
4+ const { getRingIdString} = require ( '../../util/stringUtil' )
55const {
66 graphConfig,
77 getGraphSize,
@@ -13,12 +13,32 @@ const {
1313
1414const ANIMATION_DURATION = 1000
1515
16- const { quadrantHeight, quadrantWidth, quadrantsGap, effectiveQuadrantWidth } = graphConfig
16+ const { quadrantHeight, quadrantWidth, quadrantsGap, effectiveQuadrantWidth} = graphConfig
1717
1818let prevLeft , prevTop
1919let quadrantScrollHandlerReference
2020let scrollFlag = false
2121
22+
23+ const createElement = ( tagName , text , attributes ) => {
24+ const tag = document . createElement ( tagName )
25+ Object . keys ( attributes ) . forEach ( ( keyName ) => {
26+ tag . setAttribute ( keyName , attributes [ keyName ] )
27+ } )
28+ tag . appendChild ( document . createTextNode ( text ) )
29+ return tag
30+ }
31+
32+ const replaceChild = ( element , child ) => {
33+ let elementChild = element . lastElementChild ;
34+ while ( elementChild ) {
35+ element . removeChild ( elementChild ) ;
36+ elementChild = e . lastElementChild ;
37+ }
38+ element . appendChild ( child )
39+ }
40+
41+
2242function selectRadarQuadrant ( order , startAngle , name ) {
2343 const noOfBlips = d3 . selectAll ( '.quadrant-group-' + order + ' .blip-link' ) . size ( )
2444 d3 . select ( '#radar' ) . classed ( 'no-blips' , noOfBlips === 0 )
@@ -100,10 +120,10 @@ function selectRadarQuadrant(order, startAngle, name) {
100120 svg . classed ( 'quadrant-view' , true )
101121
102122 const quadrantGroupTranslate = {
103- first : { x : 0 , y : 0 } ,
104- second : { x : 0 , y : - quadrantHeight } ,
105- third : { x : - ( quadrantWidth + quadrantsGap ) , y : 0 } ,
106- fourth : { x : - ( quadrantWidth + quadrantsGap ) , y : - quadrantHeight } ,
123+ first : { x : 0 , y : 0 } ,
124+ second : { x : 0 , y : - quadrantHeight } ,
125+ third : { x : - ( quadrantWidth + quadrantsGap ) , y : 0 } ,
126+ fourth : { x : - ( quadrantWidth + quadrantsGap ) , y : - quadrantHeight } ,
107127 }
108128
109129 d3 . select ( '.quadrant-group-' + order )
@@ -199,7 +219,7 @@ function wrapQuadrantNameInMultiLine(elem, isTopQuadrants, quadrantNameGroup, ti
199219 const words = text . split ( ' ' )
200220 let line = ''
201221
202- element . innerHTML = `< tspan id=" text-width-check"> ${ text } </tspan >`
222+ replaceChild ( element , createElement ( ' tspan' , text , { id : ' text-width-check' } ) )
203223 const testElem = document . getElementById ( 'text-width-check' )
204224
205225 function maxCharactersToFit ( testLine , suffix ) {
@@ -238,36 +258,27 @@ function wrapQuadrantNameInMultiLine(elem, isTopQuadrants, quadrantNameGroup, ti
238258 if ( textWidth > maxWidth ) {
239259 if ( i === 0 ) {
240260 let lineBreakIndex = maxCharactersToFit ( testLine , '-' )
241- element . innerHTML += '<tspan x="0" dy="' + dy + '">' + words [ i ] . substring ( 0 , lineBreakIndex ) + '-</tspan>'
261+ const elementText = `${ words [ i ] . substring ( 0 , lineBreakIndex ) } -`
262+ element . appendChild ( createElement ( 'tspan' , elementText , { x : '0' , dy} ) )
242263 const secondLine = words [ i ] . substring ( lineBreakIndex , words [ i ] . length ) + ' ' + words . slice ( i + 1 ) . join ( ' ' )
243264 lineBreakIndex = maxCharactersToFit ( secondLine , '...' )
244- element . innerHTML +=
245- '<tspan x="0" dy="' +
246- 20 +
247- '">' +
248- secondLine . substring ( 0 , lineBreakIndex ) +
249- ellipsis ( lineBreakIndex , secondLine ) +
250- '</tspan>'
265+ const text = `${ secondLine . substring ( 0 , lineBreakIndex ) } ${ ellipsis ( lineBreakIndex , secondLine ) } `
266+ element . appendChild ( createElement ( 'tspan' , text , { x : '0' , dy : '20' } ) )
251267 break
252268 } else {
253- element . innerHTML += '< tspan x="0" dy="' + dy + '">' + line + '</tspan>'
269+ element . appendChild ( createElement ( ' tspan' , line , { x : '0' , dy } ) )
254270 const secondLine = words . slice ( i ) . join ( ' ' )
255271 const lineBreakIndex = maxCharactersToFit ( secondLine , '...' )
256- element . innerHTML +=
257- '<tspan x="0" dy="' +
258- 20 +
259- '">' +
260- secondLine . substring ( 0 , lineBreakIndex ) +
261- ellipsis ( lineBreakIndex , secondLine ) +
262- '</tspan>'
272+ const text = `${ secondLine . substring ( 0 , lineBreakIndex ) } ${ ellipsis ( lineBreakIndex , secondLine ) } `
273+ element . appendChild ( createElement ( 'tspan' , text , { x : '0' , dy : '20' } ) )
263274 }
264275 line = words [ i ] + ' '
265276 } else {
266277 line = testLine
267278 }
268279 }
269280 } else {
270- element . innerHTML += '< tspan x="0">' + text + '</tspan>'
281+ element . appendChild ( createElement ( ' tspan' , text , { x : '0' } ) )
271282 }
272283
273284 document . getElementById ( 'text-width-check' ) . remove ( )
@@ -327,7 +338,7 @@ function renderRadarQuadrants(size, svg, quadrant, rings, ringCalculator, tip) {
327338 } )
328339
329340 const rectCoordMap = {
330- first : { x : 0 , y : 0 , strokeDashArray : `0, ${ quadrantWidth } , ${ quadrantHeight + quadrantWidth } , ${ quadrantHeight } ` } ,
341+ first : { x : 0 , y : 0 , strokeDashArray : `0, ${ quadrantWidth } , ${ quadrantHeight + quadrantWidth } , ${ quadrantHeight } ` } ,
331342 second : {
332343 x : 0 ,
333344 y : quadrantHeight + quadrantsGap ,
0 commit comments