@@ -70,6 +70,29 @@ function renderNeod3(id, $container, visualization) {
70
70
return styleContents + styleSheet ;
71
71
}
72
72
73
+ function applyZoom ( ) {
74
+ renderer . select ( ".nodes" ) . attr ( "transform" , "translate(" + d3 . event . translate + ")scale(" + d3 . event . scale + ")" ) ;
75
+ renderer . select ( ".relationships" ) . attr ( "transform" , "translate(" + d3 . event . translate + ")scale(" + d3 . event . scale + ")" ) ;
76
+ }
77
+
78
+ function zoomStart ( ) {
79
+ if ( d3 . event . sourceEvent . altKey ) {
80
+ zoomBehavior . on ( "zoom" , applyZoom ) ;
81
+ renderer . on ( "mousedown.zoom" , null )
82
+ }
83
+ else {
84
+ zoomBehavior
85
+ . on ( "mousedown.zoom" , null )
86
+ . on ( "mousewheel.zoom" , null )
87
+ . on ( "mousemove.zoom" , null )
88
+ . on ( "DOMMouseScroll.zoom" , null )
89
+ . on ( "dblclick.zoom" , null )
90
+ . on ( "touchstart.zoom" , null )
91
+ . on ( "touchmove.zoom" , null )
92
+ . on ( "touchend.zoom" , null ) ;
93
+ }
94
+ }
95
+
73
96
var links = visualization . links ;
74
97
var nodes = visualization . nodes ;
75
98
for ( var i = 0 ; i < links . length ; i ++ ) {
@@ -89,7 +112,11 @@ function renderNeod3(id, $container, visualization) {
89
112
. style ( styleSheet )
90
113
. width ( $container . width ( ) ) . height ( $container . height ( ) ) . on ( 'nodeClicked' , dummyFunc ) . on ( 'relationshipClicked' , dummyFunc ) . on ( 'nodeDblClicked' , dummyFunc ) ;
91
114
var renderer = d3 . select ( "#" + id ) . append ( "svg" ) . data ( [ graphModel ] ) ;
115
+ var zoomBehavior = d3 . behavior . zoom ( ) . on ( "zoomstart" , zoomStart ) . scaleExtent ( [ 0.2 , 8 ] )
116
+
92
117
renderer . call ( graphView ) ;
118
+ renderer . call ( zoomBehavior ) ;
119
+
93
120
return function ( ) {
94
121
graphView . height ( $container . height ( ) ) ;
95
122
graphView . width ( $container . width ( ) ) ;
0 commit comments