@@ -33,7 +33,6 @@ export default class Target{
3333 }
3434
3535 setGraph ( graph ) {
36- // add 'show' and 'optional' flags
3736 condenseVisualization ( graph ) ;
3837 console . log ( graph ) ;
3938
@@ -43,6 +42,7 @@ export default class Target{
4342 svg . attr ( "transform" , "translate(" + d3 . event . translate + ")scale(" + d3 . event . scale + ")" ) ;
4443 } ) ;
4544
45+ //add SVG container
4646 var svg = d3 . select ( this . id ) . call ( zoom ) . append ( "svg:g" ) ;
4747 svg . append ( "defs" ) . append ( "marker" )
4848 . attr ( "id" , "endArrow" )
@@ -55,32 +55,24 @@ export default class Target{
5555 . attr ( "d" , "M0,-5L10,0L0,5" )
5656 . attr ( "fill" , "#999" )
5757 . attr ( "opacity" , "0.5" ) ;
58- var force = ( this . layout = d3 . layout . force ( ) ) ;
59- force . drag ( ) . on ( "dragstart" , ( ) => {
60- d3 . event . sourceEvent . stopPropagation ( ) ;
61- } ) ;
62- force . charge ( - 400 ) . linkDistance ( 100 ) ;
63- force . nodes ( graph . nodes ) . links ( graph . links ) . size ( [
64- $ ( this . id ) . parent ( ) . width ( ) , $ ( this . id ) . parent ( ) . height ( )
65- ] ) . start ( ) ;
6658
67- var linksEnter = svg . selectAll ( ".link" )
68- . data ( graph . links . filter ( link => link . show ) )
69- . enter ( ) ;
70-
71- var links = linksEnter . append ( "path" )
72- . attr ( "class" , ( l ) => {
73- if ( l . optional ) {
74- return "link dashed-link" ;
75- }
76- return "link"
77- } ) ;
59+ let force = ( this . layout = d3 . layout . force ( ) )
60+ . charge ( - 400 )
61+ . linkDistance ( 100 )
62+ . nodes ( graph . nodes )
63+ . links ( graph . links )
64+ . size ( [ $ ( this . id ) . parent ( ) . width ( ) , $ ( this . id ) . parent ( ) . height ( ) ] )
65+ . start ( ) ;
66+ force . drag ( ) . on ( "dragstart" , ( ) => {
67+ d3 . event . sourceEvent . stopPropagation ( ) ;
68+ } ) ;
7869
79- var nodesEnter = svg . selectAll ( ".node" )
70+ // add nodes (circles)
71+ let nodesEnter = svg . selectAll ( ".node" )
8072 . data ( graph . nodes )
8173 . enter ( ) ;
8274
83- var circles = nodesEnter . append ( "circle" )
75+ let circles = nodesEnter . append ( "circle" )
8476 . attr ( "class" , function ( d ) {
8577 if ( d . nodeTypes . length === 0 ) {
8678 return "node" ;
@@ -90,10 +82,25 @@ export default class Target{
9082 return "accept-node" ;
9183 }
9284 } )
93- . attr ( "r" , 7 ) . call ( force . drag ) ;
85+ . attr ( "r" , 7 ) //radius
86+ . call ( force . drag ) ;
9487
95- const sbolImgSize = 30 ;
88+ // Filter out links if the "show" flag is false
89+ let linksEnter = svg . selectAll ( ".link" )
90+ . data ( graph . links . filter ( link => link . show ) )
91+ . enter ( ) ;
92+
93+ // Optional links will be rendered as dashed lines
94+ let links = linksEnter . append ( "path" )
95+ . attr ( "class" , ( l ) => {
96+ if ( l . optional ) {
97+ return "link dashed-link" ;
98+ }
99+ return "link"
100+ } ) ;
96101
102+ //place SBOL svg on links
103+ const sbolImgSize = 30 ;
97104 let images = linksEnter . append ( "svg:image" )
98105 . attr ( "height" , sbolImgSize )
99106 . attr ( "width" , sbolImgSize )
@@ -112,21 +119,24 @@ export default class Target{
112119 return titleStr ;
113120 }
114121 } )
115- . attr ( "xlink: href" , ( d ) => {
122+ . attr ( "href" , ( d ) => {
116123 if ( d . hasOwnProperty ( "componentRoles" ) ) {
117124 if ( d [ "componentRoles" ] . length > 0 ) {
118- let role = d [ "componentRoles" ] [ 0 ] ;
119- return getSBOLImage ( role ) ;
125+ return getSBOLImage ( d [ "componentRoles" ] [ 0 ] ) ;
120126 }
121127 }
122128 return "" ;
123- } ) ;
129+ } ) ;
124130
131+ //place tooltip on the SVG images
125132 $ ( '.sboltip' ) . tooltipster ( {
126133 theme : 'tooltipster-shadow'
127134 } ) ;
128135
136+ // Handles positioning when moved
129137 force . on ( "tick" , function ( ) {
138+
139+ // Position links
130140 links . attr ( 'd' , function ( d ) {
131141 var deltaX = d . target . x - d . source . x ,
132142 deltaY = d . target . y - d . source . y ,
@@ -142,18 +152,27 @@ export default class Target{
142152 return 'M' + sourceX + ',' + sourceY + 'L' + targetX + ',' + targetY ;
143153 } ) ;
144154
155+ // Position circles
145156 circles . attr ( "cx" , function ( d ) {
146157 return d . x ;
147158 } )
148159 . attr ( "cy" , function ( d ) {
149160 return d . y ;
150161 } ) ;
151162
163+ // Position SBOL images
152164 images . attr ( "x" , function ( d ) {
153165 return ( d . source . x + d . target . x ) / 2 - sbolImgSize / 2 ;
154166 } )
155167 . attr ( "y" , function ( d ) {
156168 return ( d . source . y + d . target . y ) / 2 - sbolImgSize / 2 ;
169+ } )
170+ . attr ( 'transform' , function ( d ) {
171+ if ( d . orientation === "REVERSE_COMPLEMENT" ) {
172+ let x1 = ( d . source . x + d . target . x ) / 2 ; //the center x about which you want to rotate
173+ let y1 = ( d . source . y + d . target . y ) / 2 ; //the center y about which you want to rotate
174+ return `rotate(180, ${ x1 } , ${ y1 } )` ;
175+ }
157176 } ) ;
158177 } ) ;
159178 }
0 commit comments