@@ -40,7 +40,7 @@ requirejs.config({
40
40
/**
41
41
* Make the graph pannable and zoomable
42
42
*/
43
- require ( [ 'jquery' , 'bootstrap.modal' , 'svg-pan-zoom' , 'hammerjs' ] ,
43
+ require ( [ 'jquery' , 'bootstrap.modal' , 'svg-pan-zoom' , 'hammerjs' , 'jquery.svg' ] ,
44
44
function ( $ , modal , svgPanZoom , hammerjs ) {
45
45
/**
46
46
* Custom hammer event handler to add mobile support
@@ -100,57 +100,62 @@ require(['jquery', 'bootstrap.modal', 'svg-pan-zoom', 'hammerjs'],
100
100
} ;
101
101
102
102
// Loading from external URL needs to be done to enable events
103
- $ ( selector ) . svg ( { loadURL : 'lion.svg' } ) ;
103
+ $ ( "#graph" ) . svg ( {
104
+ loadURL : $ ( "#graph" ) . attr ( "data-svgurl" ) ,
105
+ onLoad : enablePanZoom
106
+ } ) ;
104
107
105
108
/**
106
109
* Enable svg-pan-zoom on the graph
107
110
*/
108
- var graph = svgPanZoom ( '#graph' , {
109
- zoomEnabled : true ,
110
- controlIconsEnabled : true ,
111
- customEventsHandler : eventHandler ,
112
- preventMouseEventsDefault : false
113
- } ) ;
111
+ function enablePanZoom ( ) {
112
+ var graph = svgPanZoom ( '#graph svg' , {
113
+ zoomEnabled : true ,
114
+ controlIconsEnabled : true ,
115
+ customEventsHandler : eventHandler ,
116
+ preventMouseEventsDefault : false
117
+ } ) ;
114
118
115
- // Resizing window also resizes the graph
116
- $ ( window ) . resize ( function ( ) {
117
- graph . resize ( ) ;
118
- graph . fit ( ) ;
119
- graph . center ( ) ;
120
- } ) ;
119
+ // Resizing window also resizes the graph
120
+ $ ( window ) . resize ( function ( ) {
121
+ graph . resize ( ) ;
122
+ graph . fit ( ) ;
123
+ graph . center ( ) ;
124
+ } ) ;
121
125
122
- // Enable svg-pan-zoom on fullscreen modal when opened
123
- $ ( '#fullScreenGraphModal' ) . on ( 'shown.bs.modal' , function ( e ) {
124
- // Timeout allows for modal to show
125
- setTimeout ( function ( ) {
126
- var fullGraph = svgPanZoom ( '#graphFullscreen' , {
127
- zoomEnabled : true ,
128
- controlIconsEnabled : true ,
129
- customEventsHandler : eventHandler
130
- } ) ;
126
+ // Enable svg-pan-zoom on fullscreen modal when opened
127
+ $ ( '#fullScreenGraphModal' ) . on ( 'shown.bs.modal' , function ( e ) {
128
+ // Timeout allows for modal to show
129
+ setTimeout ( function ( ) {
130
+ var fullGraph = svgPanZoom ( '#graphFullscreen' , {
131
+ zoomEnabled : true ,
132
+ controlIconsEnabled : true ,
133
+ customEventsHandler : eventHandler
134
+ } ) ;
131
135
132
- // Set to same zoom/pan as other graph
133
- fullGraph . zoom ( graph . getZoom ( ) ) ;
134
- fullGraph . pan ( graph . getPan ( ) ) ;
136
+ // Set to same zoom/pan as other graph
137
+ fullGraph . zoom ( graph . getZoom ( ) ) ;
138
+ fullGraph . pan ( graph . getPan ( ) ) ;
135
139
136
- // Link the two graphs panning and zooming
137
- fullGraph . setOnZoom ( function ( level ) {
138
- graph . zoom ( level ) ;
139
- graph . pan ( fullGraph . getPan ( ) ) ;
140
- } ) ;
140
+ // Link the two graphs panning and zooming
141
+ fullGraph . setOnZoom ( function ( level ) {
142
+ graph . zoom ( level ) ;
143
+ graph . pan ( fullGraph . getPan ( ) ) ;
144
+ } ) ;
141
145
142
- fullGraph . setOnPan ( function ( point ) {
143
- graph . pan ( point ) ;
144
- } ) ;
146
+ fullGraph . setOnPan ( function ( point ) {
147
+ graph . pan ( point ) ;
148
+ } ) ;
145
149
146
- // Resizing window also resizes the graph
147
- $ ( window ) . resize ( function ( ) {
148
- fullGraph . resize ( ) ;
149
- fullGraph . fit ( ) ;
150
- fullGraph . center ( ) ;
151
- } ) ;
152
- } , 100 ) ;
153
- } ) ;
150
+ // Resizing window also resizes the graph
151
+ $ ( window ) . resize ( function ( ) {
152
+ fullGraph . resize ( ) ;
153
+ fullGraph . fit ( ) ;
154
+ fullGraph . center ( ) ;
155
+ } ) ;
156
+ } , 100 ) ;
157
+ } ) ;
158
+ } ;
154
159
} ) ;
155
160
156
161
/**
@@ -251,6 +256,7 @@ require(['jquery', 'jquery.svg', 'jquery.svgdom'],
251
256
*/
252
257
$ ( "tr" ) . not ( 'thead tr' ) . on ( {
253
258
click : function ( ) {
259
+ $ ( "polygon.selected, tr.selected" ) . removeClass ( "selected" ) ;
254
260
getGraphBox ( this ) . toggleClass ( "selected" ) ;
255
261
$ ( this ) . toggleClass ( "selected" ) ;
256
262
} ,
@@ -280,22 +286,19 @@ require(['jquery', 'jquery.svg', 'jquery.svgdom'],
280
286
/**
281
287
* When a graph box is hovered over/clicked, highlight
282
288
*/
283
- var svg = $ ( '#graph' ) . svg ( 'get' ) ;
284
- $ ( $ ( ".node" ) , svg . root ( ) ) . on ( {
289
+ $ ( document ) . on ( {
285
290
click : function ( ) {
286
- alert ( "click ") ;
291
+ $ ( "polygon.selected, tr.selected" ) . removeClass ( "selected ") ;
287
292
getTableRow ( this ) . toggleClass ( "selected" ) ;
288
293
$ ( this ) . find ( "polygon" ) . toggleClass ( "selected" ) ;
289
294
} ,
290
295
mouseenter : function ( ) {
291
- alert ( "mouseenter" ) ;
292
296
getTableRow ( this ) . addClass ( "hover" ) ;
293
297
$ ( this ) . find ( "polygon" ) . addClass ( "hover" ) ;
294
298
} ,
295
299
mouseleave : function ( ) {
296
- alert ( "mouseleave" ) ;
297
300
getTableRow ( this ) . removeClass ( "hover" ) ;
298
301
$ ( this ) . find ( "polygon" ) . removeClass ( "hover" ) ;
299
302
}
300
- } ) ;
303
+ } , ".node" ) ;
301
304
} ) ;
0 commit comments