31
31
} ,
32
32
layout : { } // The layout of the directed graph
33
33
} ;
34
+ var defaultGraphDirection = '' ; // The graph direction from the dgml file itself
35
+ setDefaultGraphDirection ( ) ;
34
36
var container = document . getElementById ( 'network' ) ;
35
37
var network = new vis . Network ( container , data , options ) ;
36
38
var seed = network . getSeed ( ) ;
57
59
copyToClipboardButton . addEventListener ( 'click' , copyToClipboard ) ;
58
60
copyToClipboardButton . style [ 'display' ] = 'none' ; // TODO: Remove when copyToClipboard is implemented
59
61
const showHierarchicalOptionsButton = document . getElementById ( 'showHierarchicalOptions' ) ;
60
- showHierarchicalOptionsButton . addEventListener ( 'click' , setNetworkLayout ) ;
62
+ showHierarchicalOptionsButton . addEventListener ( 'click' , showHierarchicalOptions ) ;
61
63
const hierarchicalDirectionSelect = document . getElementById ( 'direction' ) ;
62
64
hierarchicalDirectionSelect . addEventListener ( 'change' , setNetworkLayout ) ;
63
65
const hierarchicalSortMethodSelect = document . getElementById ( 'sortMethod' ) ;
101
103
function drawGuideLine ( ctx , mouseX , mouseY ) {
102
104
ctx . beginPath ( ) ;
103
105
ctx . setLineDash ( [ 3 , 7 ] ) ;
104
- if ( mouseX > - 1 ) {
106
+ if ( mouseX > - 1 ) {
105
107
ctx . moveTo ( mouseX , 0 ) ;
106
108
ctx . lineTo ( mouseX , selectionCanvas . height ) ;
107
109
} else if ( mouseY > - 1 ) {
143
145
}
144
146
145
147
function saveSelectionAsPng ( ) {
148
+ graphDiv = document . getElementById ( 'network' ) ;
149
+ visDiv = graphDiv . firstElementChild ;
150
+ graphCanvas = visDiv . firstElementChild ;
151
+
146
152
// show the help text
147
153
helpTextDiv . style [ 'display' ] = 'block' ;
148
154
157
163
selection = { } ;
158
164
159
165
selectionLayer . addEventListener ( "mouseup" , mouseUpEventListener , true ) ;
160
- selectionLayer . addEventListener ( "mousedown" , mouseDownEventListener , true ) ;
166
+ selectionLayer . addEventListener ( "mousedown" , mouseDownEventListener , true ) ;
161
167
selectionLayer . addEventListener ( "mousemove" , mouseMoveEventListener , true ) ;
162
168
}
163
169
164
170
function saveAsPng ( ) {
165
171
graphDiv = document . getElementById ( 'network' ) ;
166
172
visDiv = graphDiv . firstElementChild ;
167
- graphCanvas = visDiv . firstElementChild ;
173
+ graphCanvas = visDiv . firstElementChild ;
174
+
168
175
// Calculate the bounding box of all the elements on the canvas
169
176
const boundingBox = getBoundingBox ( ) ;
170
177
173
180
finalSelectionCanvas . width = boundingBox . width ;
174
181
finalSelectionCanvas . height = boundingBox . height ;
175
182
const finalSelectionCanvasContext = finalSelectionCanvas . getContext ( '2d' ) ;
176
- finalSelectionCanvasContext . drawImage ( graphCanvas , boundingBox . top , boundingBox . left , boundingBox . width , boundingBox . height , 0 , 0 , boundingBox . width , boundingBox . height ) ;
183
+ finalSelectionCanvasContext . drawImage ( graphCanvas , boundingBox . top , boundingBox . left , boundingBox . width , boundingBox . height , 0 , 0 , boundingBox . width , boundingBox . height ) ;
177
184
178
185
// Call back to the extension context to save the image of the graph to the workspace folder.
179
186
vscode . postMessage ( {
192
199
var cWidth = graphCanvas . width * bytesPerPixels ;
193
200
var cHeight = graphCanvas . height ;
194
201
var minY = minX = maxY = maxX = - 1 ;
195
- for ( var y = cHeight ; y > 0 && maxY === - 1 ; y -- ) {
202
+ for ( var y = cHeight ; y > 0 && maxY === - 1 ; y -- ) {
196
203
for ( var x = 0 ; x < cWidth ; x += bytesPerPixels ) {
197
204
var arrayPos = x + y * cWidth ;
198
205
if ( imgData . data [ arrayPos + 3 ] > 0 && maxY === - 1 ) {
231
238
return {
232
239
'top' : minX ,
233
240
'left' : minY ,
234
- 'width' : maxX - minX ,
235
- 'height' : maxY - minY
241
+ 'width' : maxX - minX ,
242
+ 'height' : maxY - minY
236
243
} ;
237
244
}
238
245
239
246
function copyToClipboard ( ) {
240
247
console . log ( 'Not implemented yet...' ) ;
241
248
}
242
-
249
+
250
+ function showHierarchicalOptions ( ) {
251
+ setDefaultGraphDirection ( ) ;
252
+ setNetworkLayout ( ) ;
253
+ }
254
+
255
+ function setDefaultGraphDirection ( ) {
256
+ const hierarchicalOptionsDirection = document . getElementById ( 'direction' ) ;
257
+ for ( var i , j = 0 ; i = hierarchicalOptionsDirection . options [ j ] ; j ++ ) {
258
+ if ( i . value === defaultGraphDirection ) {
259
+ hierarchicalOptionsDirection . selectedIndex = j ;
260
+ break ;
261
+ }
262
+ }
263
+ }
264
+
243
265
function setNetworkLayout ( ) {
244
266
const hierarchicalOptionsDirection = document . getElementById ( 'hierarchicalOptions_direction' ) ;
245
267
const hierarchicalOptionsSortMethod = document . getElementById ( 'hierarchicalOptions_sortmethod' ) ;
248
270
hierarchicalOptionsSortMethod . style [ 'display' ] = showHierarchicalOptionsCheckbox . checked ? 'block' : 'none' ;
249
271
const hierarchicalOptionsDirectionSelect = document . getElementById ( 'direction' ) ;
250
272
const hierarchicalOptionsSortMethodSelect = document . getElementById ( 'sortMethod' ) ;
251
- if ( showHierarchicalOptionsCheckbox . checked ) {
252
- options . layout = {
253
- hierarchical : {
254
- enabled : true ,
255
- direction : hierarchicalOptionsDirectionSelect . value ? hierarchicalOptionsDirectionSelect . value : 'LR' ,
256
- sortMethod : hierarchicalOptionsSortMethodSelect . value ? hierarchicalOptionsSortMethodSelect . value : 'hubsize'
257
- }
258
- } ;
273
+ if ( showHierarchicalOptionsCheckbox . checked ) {
274
+ if ( hierarchicalOptionsDirectionSelect . value && hierarchicalOptionsDirectionSelect . value === 'Random' ) {
275
+ options . layout = { } ;
276
+ seed = Math . random ( ) ;
277
+ } else {
278
+ options . layout = {
279
+ hierarchical : {
280
+ enabled : true ,
281
+ direction : hierarchicalOptionsDirectionSelect . value ? hierarchicalOptionsDirectionSelect . value : defaultGraphDirection ,
282
+ sortMethod : hierarchicalOptionsSortMethodSelect . value ? hierarchicalOptionsSortMethodSelect . value : 'hubsize'
283
+ }
284
+ } ;
285
+ }
259
286
} else {
260
- options . layout = { } ;
287
+ if ( defaultGraphDirection === '' ) {
288
+ options . layout = { } ;
289
+ } else {
290
+ options . layout = {
291
+ hierarchical : {
292
+ enabled : true ,
293
+ direction : defaultGraphDirection ,
294
+ sortMethod : 'hubsize'
295
+ }
296
+ } ;
297
+ }
261
298
}
262
299
options . layout . randomSeed = seed ;
263
300
network = new vis . Network ( container , data , options ) ;
264
301
}
265
-
302
+
266
303
} ( ) ) ;
0 commit comments