101
101
function drawGuideLine ( ctx , mouseX , mouseY ) {
102
102
ctx . beginPath ( ) ;
103
103
ctx . setLineDash ( [ 3 , 7 ] ) ;
104
- if ( mouseX > - 1 ) {
104
+ if ( mouseX > - 1 ) {
105
105
ctx . moveTo ( mouseX , 0 ) ;
106
106
ctx . lineTo ( mouseX , selectionCanvas . height ) ;
107
107
} else if ( mouseY > - 1 ) {
143
143
}
144
144
145
145
function saveSelectionAsPng ( ) {
146
+ graphDiv = document . getElementById ( 'network' ) ;
147
+ visDiv = graphDiv . firstElementChild ;
148
+ graphCanvas = visDiv . firstElementChild ;
149
+
146
150
// show the help text
147
151
helpTextDiv . style [ 'display' ] = 'block' ;
148
152
157
161
selection = { } ;
158
162
159
163
selectionLayer . addEventListener ( "mouseup" , mouseUpEventListener , true ) ;
160
- selectionLayer . addEventListener ( "mousedown" , mouseDownEventListener , true ) ;
164
+ selectionLayer . addEventListener ( "mousedown" , mouseDownEventListener , true ) ;
161
165
selectionLayer . addEventListener ( "mousemove" , mouseMoveEventListener , true ) ;
162
166
}
163
167
164
168
function saveAsPng ( ) {
165
169
graphDiv = document . getElementById ( 'network' ) ;
166
170
visDiv = graphDiv . firstElementChild ;
167
- graphCanvas = visDiv . firstElementChild ;
171
+ graphCanvas = visDiv . firstElementChild ;
168
172
// Calculate the bounding box of all the elements on the canvas
169
173
const boundingBox = getBoundingBox ( ) ;
170
174
173
177
finalSelectionCanvas . width = boundingBox . width ;
174
178
finalSelectionCanvas . height = boundingBox . height ;
175
179
const finalSelectionCanvasContext = finalSelectionCanvas . getContext ( '2d' ) ;
176
- finalSelectionCanvasContext . drawImage ( graphCanvas , boundingBox . top , boundingBox . left , boundingBox . width , boundingBox . height , 0 , 0 , boundingBox . width , boundingBox . height ) ;
180
+ finalSelectionCanvasContext . drawImage ( graphCanvas , boundingBox . top , boundingBox . left , boundingBox . width , boundingBox . height , 0 , 0 , boundingBox . width , boundingBox . height ) ;
177
181
178
182
// Call back to the extension context to save the image of the graph to the workspace folder.
179
183
vscode . postMessage ( {
192
196
var cWidth = graphCanvas . width * bytesPerPixels ;
193
197
var cHeight = graphCanvas . height ;
194
198
var minY = minX = maxY = maxX = - 1 ;
195
- for ( var y = cHeight ; y > 0 && maxY === - 1 ; y -- ) {
199
+ for ( var y = cHeight ; y > 0 && maxY === - 1 ; y -- ) {
196
200
for ( var x = 0 ; x < cWidth ; x += bytesPerPixels ) {
197
201
var arrayPos = x + y * cWidth ;
198
202
if ( imgData . data [ arrayPos + 3 ] > 0 && maxY === - 1 ) {
231
235
return {
232
236
'top' : minX ,
233
237
'left' : minY ,
234
- 'width' : maxX - minX ,
235
- 'height' : maxY - minY
238
+ 'width' : maxX - minX ,
239
+ 'height' : maxY - minY
236
240
} ;
237
241
}
238
242
239
243
function copyToClipboard ( ) {
240
244
console . log ( 'Not implemented yet...' ) ;
241
245
}
242
-
246
+
243
247
function setNetworkLayout ( ) {
244
248
const hierarchicalOptionsDirection = document . getElementById ( 'hierarchicalOptions_direction' ) ;
245
249
const hierarchicalOptionsSortMethod = document . getElementById ( 'hierarchicalOptions_sortmethod' ) ;
248
252
hierarchicalOptionsSortMethod . style [ 'display' ] = showHierarchicalOptionsCheckbox . checked ? 'block' : 'none' ;
249
253
const hierarchicalOptionsDirectionSelect = document . getElementById ( 'direction' ) ;
250
254
const hierarchicalOptionsSortMethodSelect = document . getElementById ( 'sortMethod' ) ;
251
- if ( showHierarchicalOptionsCheckbox . checked ) {
252
- options . layout = {
253
- hierarchical : {
254
- enabled : true ,
255
- direction : hierarchicalOptionsDirectionSelect . value ? hierarchicalOptionsDirectionSelect . value : 'UD' ,
256
- sortMethod : hierarchicalOptionsSortMethodSelect . value ? hierarchicalOptionsSortMethodSelect . value : 'hubsize'
257
- }
258
- } ;
255
+ if ( showHierarchicalOptionsCheckbox . checked ) {
256
+ if ( hierarchicalOptionsDirectionSelect . value && hierarchicalOptionsDirectionSelect . value === 'Random' ) {
257
+ options . layout = { } ;
258
+ seed = Math . random ( ) ;
259
+ } else {
260
+ options . layout = {
261
+ hierarchical : {
262
+ enabled : true ,
263
+ direction : hierarchicalOptionsDirectionSelect . value ? hierarchicalOptionsDirectionSelect . value : 'UD' ,
264
+ sortMethod : hierarchicalOptionsSortMethodSelect . value ? hierarchicalOptionsSortMethodSelect . value : 'hubsize'
265
+ }
266
+ } ;
267
+ }
259
268
} else {
260
269
options . layout = { } ;
261
270
}
262
271
options . layout . randomSeed = seed ;
263
272
network = new vis . Network ( container , data , options ) ;
264
273
}
265
-
274
+
266
275
} ( ) ) ;
0 commit comments