3232
3333\*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ * //////////////////////////////////////*/
3434
35- var DBG = false ;
35+ var DBG = false ;
3636
3737/// SYSTEM LIBRARIES //////////////////////////////////////////////////////////
3838/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -52,9 +52,9 @@ let m_forceProperties = { // values for all forces
5252 } ,
5353 charge : {
5454 enabled : true ,
55- strength : - 1000 , // -20,
56- distanceMin : 50 , // 1,
57- distanceMax : 2000
55+ strength : - 1500 , //- 1000, // -20,
56+ distanceMin : 20 , // 50, // 1,
57+ distanceMax : 1000 // 2000
5858 } ,
5959 collide : {
6060 enabled : true ,
@@ -74,8 +74,8 @@ let m_forceProperties = { // values for all forces
7474 } ,
7575 link : {
7676 enabled : true ,
77- distance : 30 , // 30,
78- iterations : 1
77+ distance : 60 , // 30,
78+ iterations : 2 // 1
7979 }
8080 } ; // m_forceProperties
8181
@@ -233,14 +233,13 @@ class D3NetGraph {
233233 // enter node: also append 'circle' element of a calculated size
234234 elementG
235235 . append ( "circle" )
236- . attr ( "r" ,
237- ( d ) => {
236+ // "r" has to be set here or circles don't draw.
237+ . attr ( "r" , ( d ) => {
238238 let count = 1
239239 this . data . edges . map ( ( l ) => { l . source == d . id || l . target == d . id ? count ++ : 0 } )
240240 d . weight = count
241- // save the calculated size
242- d . size = count
243- return this . defaultSize * d . weight
241+ d . size = count // save the calculated size
242+ return this . defaultSize + this . defaultSize * d . weight / 2
244243 } )
245244 // .attr("r", (d) => { return this.defaultSize }) // d.size ? d.size/10 : this.defaultSize; })
246245 . attr ( "fill" , ( d ) => { return d . color ? d . color : this . defaultColor ; } ) ;
@@ -250,8 +249,8 @@ class D3NetGraph {
250249 . append ( "text" )
251250 . classed ( 'noselect' , true )
252251 . attr ( "font-size" , 10 )
253- . attr ( "dx" , 8 )
254- . attr ( "dy" , ".15em" )
252+ . attr ( "dx" , ( d => { return this . defaultSize + 5 } ) ) // 8)
253+ . attr ( "dy" , "0.35em" ) // " .15em")
255254 . text ( ( d ) => { return d . label } ) ;
256255
257256 // enter node: also append a 'title' tag
@@ -306,12 +305,13 @@ class D3NetGraph {
306305 . attr ( "stroke-width" , ( d ) => {
307306 if ( d . selected || d . strokeColor ) return '5px' ;
308307 } )
309- . attr ( "r" ,
310- ( d ) => {
308+ // this "r" is necessary to resize aftger a link is added
309+ . attr ( "r" , ( d ) => {
311310 let count = 1
312311 this . data . edges . map ( ( l ) => { l . source . id == d . id || l . target . id == d . id ? count ++ : 0 } )
313312 d . weight = count
314- return this . defaultSize * d . weight
313+ d . size = count // save the calculated size
314+ return this . defaultSize + this . defaultSize * d . weight / 2
315315 } ) ;
316316
317317 // UPDATE text in each node for all nodes
@@ -347,19 +347,24 @@ class D3NetGraph {
347347 this . simulation . force ( "link" ) . links ( this . data . edges )
348348
349349 }
350+
350351/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
351352/*/ Apply new force properties
352353 Call this on construct and if forceProperties have changed.
353- /*/ _UpdateForces ( data ) {
354+ /*/ _UpdateForces ( data ) {
354355 this . simulation
355356 . force ( "link" , d3 . forceLink ( )
356357 . id ( ( d ) => { return d . id } )
357- . distance ( ( d ) => { return m_forceProperties . link . distance * ( 1 / d . size ) } )
358- // .distance(m_forceProperties.link.distance)
358+ . distance ( ( d ) => { return m_forceProperties . link . distance } )
359+ // this doesn't seem to change anything?!? The m_forceProperties.link.distance is the only value that seems to matter?
360+ // .distance( (d)=>{return m_forceProperties.link.distance+d.size*10 } )
361+ // .distance( (d)=>{return m_forceProperties.link.distance * (1/d.size) } )
362+ // .distance( m_forceProperties.link.distance )
359363 . iterations ( m_forceProperties . link . iterations ) )
360364 . force ( "charge" , d3 . forceManyBody ( )
361- // .strength(m_forceProperties.charge.strength * m_forceProperties.charge.enabled)
362- . strength ( ( d ) => { return d . size / 6 * m_forceProperties . charge . strength * m_forceProperties . charge . enabled } )
365+ // .strength(m_forceProperties.charge.strength * m_forceProperties.charge.enabled)
366+ // .strength( (d)=>{return d.size/6 * m_forceProperties.charge.strength * m_forceProperties.charge.enabled} )
367+ . strength ( ( d ) => { return d . size / 4 * m_forceProperties . charge . strength * m_forceProperties . charge . enabled } )
363368 . distanceMin ( m_forceProperties . charge . distanceMin )
364369 . distanceMax ( m_forceProperties . charge . distanceMax ) )
365370 . force ( "collide" , d3 . forceCollide ( )
0 commit comments