@@ -99,8 +99,19 @@ class GraphLayout {
9999
100100 if ( node instanceof Link ) {
101101 let anchors = node . words
102- . filter ( ( word , i ) => word !== source )
103- . map ( ( word ) => addNode ( word , depth + 1 , node ) ) ;
102+ . map ( ( word , i ) => {
103+ if ( word !== source ) {
104+ const newNode = addNode ( word , depth + 1 , node ) ;
105+
106+ if ( node . arrowDirections [ i ] === 1 ) {
107+ newNode . receivesArrow = true ;
108+ }
109+
110+ return newNode ;
111+ }
112+ return null ;
113+ } )
114+ . filter ( word => word ) ;
104115
105116 children = children . concat ( anchors ) ;
106117 }
@@ -194,20 +205,10 @@ class GraphLayout {
194205 d . source . data . type === 'Link' &&
195206 d . source . data . node . arrowDirections . indexOf ( - 1 ) > - 1 ) {
196207
197- let i = d . source . data . node . words . indexOf ( d . target . data . node ) ;
198- if ( d . source . data . node . arrowDirections [ i ] === - 1 ) {
199- return 'M' + [ x1 , y1 ] +
200- 'C' + [ x1 , ( y2 + y1 ) / 2 ] +
201- ',' + [ x2 , y2 ] +
202- ',' + [ x2 , y2 ] ;
203- }
204- else {
205- // receive an arrow
206- return 'M' + [ x1 , y1 ] +
207- 'C' + [ x1 , y2 ] +
208- ',' + [ x1 , y2 ] +
209- ',' + [ x2 , y2 ] ;
210- }
208+ return 'M' + [ x1 , y1 ] +
209+ 'C' + [ x1 , y2 ] +
210+ ',' + [ x1 , y2 ] +
211+ ',' + [ x2 , y2 ] ;
211212 }
212213
213214 return 'M' + [ x1 , y1 ] +
@@ -226,10 +227,8 @@ class GraphLayout {
226227 . append ( 'g' )
227228 . attr ( 'class' , ( d ) => 'node' + ( d . children ? ' node--internal' : ' node--leaf' ) + ( d . parent ? '' : ' node--root' ) ) ;
228229
229- nodeEnter . append ( 'path' )
230- . attr ( 'transform' , 'rotate(45)' ) ;
231-
232- nodeEnter . append ( 'text' ) ;
230+ nodeEnter . append ( 'path' ) ; // symbol
231+ nodeEnter . append ( 'text' ) ; // label
233232
234233 let nodeMerge = nodeEnter . merge ( node ) ;
235234
@@ -248,9 +247,10 @@ class GraphLayout {
248247
249248 nodeMerge . select ( 'path' )
250249 . attr ( 'd' , d3 . symbol ( )
251- . type ( ( d ) => d . data . type === 'Word' ? d3 . symbolSquare : d3 . symbolCircle )
250+ . type ( ( d ) => d . data . receivesArrow ? d3 . symbolTriangle : ( d . data . type === 'Word' ? d3 . symbolSquare : d3 . symbolCircle ) )
252251 . size ( 20 )
253252 )
253+ . attr ( 'transform' , ( d ) => d . data . receivesArrow ? 'rotate(-30)' : 'rotate(45)' )
254254 . attr ( 'stroke' , 'grey' )
255255 . attr ( 'fill' , ( d ) => d . data . type === 'Word' ? 'black' : 'white' )
256256 . on ( 'click' , ( d ) => {
0 commit comments