@@ -110,7 +110,8 @@ var cxtmenu = function cxtmenu(params) {
110
110
var canvas = createElement ( { tag : 'canvas' } ) ;
111
111
var commands = [ ] ;
112
112
var c2d = canvas . getContext ( '2d' ) ;
113
- var r = options . menuRadius ;
113
+
114
+ var r = 100 ; // defailt radius;
114
115
var containerSize = ( r + options . activePadding ) * 2 ;
115
116
var activeCommandI = void 0 ;
116
117
var offset = void 0 ;
@@ -209,13 +210,12 @@ var cxtmenu = function cxtmenu(params) {
209
210
}
210
211
}
211
212
212
- function queueDrawBg ( rspotlight ) {
213
- redrawQueue . drawBg = [ rspotlight ] ;
213
+ function queueDrawBg ( radius , rspotlight ) {
214
+ redrawQueue . drawBg = [ radius , rspotlight ] ;
214
215
}
215
216
216
- function drawBg ( rspotlight ) {
217
+ function drawBg ( radius , rspotlight ) {
217
218
rspotlight = rspotlight !== undefined ? rspotlight : rs ;
218
-
219
219
c2d . globalCompositeOperation = 'source-over' ;
220
220
221
221
c2d . clearRect ( 0 , 0 , containerSize , containerSize ) ;
@@ -233,8 +233,8 @@ var cxtmenu = function cxtmenu(params) {
233
233
c2d . fillStyle = command . fillColor ;
234
234
}
235
235
c2d . beginPath ( ) ;
236
- c2d . moveTo ( r + options . activePadding , r + options . activePadding ) ;
237
- c2d . arc ( r + options . activePadding , r + options . activePadding , r , 2 * Math . PI - theta1 , 2 * Math . PI - theta2 , true ) ;
236
+ c2d . moveTo ( radius + options . activePadding , radius + options . activePadding ) ;
237
+ c2d . arc ( radius + options . activePadding , radius + options . activePadding , radius , 2 * Math . PI - theta1 , 2 * Math . PI - theta2 , true ) ;
238
238
c2d . closePath ( ) ;
239
239
c2d . fill ( ) ;
240
240
@@ -252,11 +252,11 @@ var cxtmenu = function cxtmenu(params) {
252
252
theta2 = theta1 + dtheta ;
253
253
254
254
for ( var i = 0 ; i < commands . length ; i ++ ) {
255
- var rx1 = r * Math . cos ( theta1 ) ;
256
- var ry1 = r * Math . sin ( theta1 ) ;
255
+ var rx1 = radius * Math . cos ( theta1 ) ;
256
+ var ry1 = radius * Math . sin ( theta1 ) ;
257
257
c2d . beginPath ( ) ;
258
- c2d . moveTo ( r + options . activePadding , r + options . activePadding ) ;
259
- c2d . lineTo ( r + options . activePadding + rx1 , r + options . activePadding - ry1 ) ;
258
+ c2d . moveTo ( radius + options . activePadding , radius + options . activePadding ) ;
259
+ c2d . lineTo ( radius + options . activePadding + rx1 , radius + options . activePadding - ry1 ) ;
260
260
c2d . closePath ( ) ;
261
261
c2d . stroke ( ) ;
262
262
@@ -267,18 +267,18 @@ var cxtmenu = function cxtmenu(params) {
267
267
c2d . fillStyle = 'white' ;
268
268
c2d . globalCompositeOperation = 'destination-out' ;
269
269
c2d . beginPath ( ) ;
270
- c2d . arc ( r + options . activePadding , r + options . activePadding , rspotlight + options . spotlightPadding , 0 , Math . PI * 2 , true ) ;
270
+ c2d . arc ( radius + options . activePadding , radius + options . activePadding , rspotlight + options . spotlightPadding , 0 , Math . PI * 2 , true ) ;
271
271
c2d . closePath ( ) ;
272
272
c2d . fill ( ) ;
273
273
274
274
c2d . globalCompositeOperation = 'source-over' ;
275
275
}
276
276
277
- function queueDrawCommands ( rx , ry , theta ) {
278
- redrawQueue . drawCommands = [ rx , ry , theta ] ;
277
+ function queueDrawCommands ( rx , ry , radius , theta ) {
278
+ redrawQueue . drawCommands = [ rx , ry , radius , theta ] ;
279
279
}
280
280
281
- function drawCommands ( rx , ry , theta ) {
281
+ function drawCommands ( rx , ry , radius , theta ) {
282
282
var dtheta = 2 * Math . PI / commands . length ;
283
283
var theta1 = Math . PI / 2 ;
284
284
var theta2 = theta1 + dtheta ;
@@ -290,16 +290,16 @@ var cxtmenu = function cxtmenu(params) {
290
290
c2d . strokeStyle = 'black' ;
291
291
c2d . lineWidth = 1 ;
292
292
c2d . beginPath ( ) ;
293
- c2d . moveTo ( r + options . activePadding , r + options . activePadding ) ;
294
- c2d . arc ( r + options . activePadding , r + options . activePadding , r + options . activePadding , 2 * Math . PI - theta1 , 2 * Math . PI - theta2 , true ) ;
293
+ c2d . moveTo ( radius + options . activePadding , radius + options . activePadding ) ;
294
+ c2d . arc ( radius + options . activePadding , radius + options . activePadding , radius + options . activePadding , 2 * Math . PI - theta1 , 2 * Math . PI - theta2 , true ) ;
295
295
c2d . closePath ( ) ;
296
296
c2d . fill ( ) ;
297
297
298
298
c2d . fillStyle = 'white' ;
299
299
c2d . globalCompositeOperation = 'destination-out' ;
300
300
301
- var tx = r + options . activePadding + rx / r * ( rs + options . spotlightPadding - options . indicatorSize / 4 ) ;
302
- var ty = r + options . activePadding + ry / r * ( rs + options . spotlightPadding - options . indicatorSize / 4 ) ;
301
+ var tx = radius + options . activePadding + rx / radius * ( rs + options . spotlightPadding - options . indicatorSize / 4 ) ;
302
+ var ty = radius + options . activePadding + ry / radius * ( rs + options . spotlightPadding - options . indicatorSize / 4 ) ;
303
303
var rot = Math . PI / 4 - theta ;
304
304
305
305
c2d . translate ( tx , ty ) ;
@@ -318,7 +318,7 @@ var cxtmenu = function cxtmenu(params) {
318
318
319
319
// clear the spotlight
320
320
c2d . beginPath ( ) ;
321
- c2d . arc ( r + options . activePadding , r + options . activePadding , rs + options . spotlightPadding , 0 , Math . PI * 2 , true ) ;
321
+ c2d . arc ( radius + options . activePadding , radius + options . activePadding , rs + options . spotlightPadding , 0 , Math . PI * 2 , true ) ;
322
322
c2d . closePath ( ) ;
323
323
c2d . fill ( ) ;
324
324
@@ -497,8 +497,8 @@ var cxtmenu = function cxtmenu(params) {
497
497
rh = void 0 ;
498
498
if ( ! isCy && ele . isNode ( ) && ! ele . isParent ( ) && ! options . atMouse ) {
499
499
rp = ele . renderedPosition ( ) ;
500
- rw = ele . renderedWidth ( ) ;
501
- rh = ele . renderedHeight ( ) ;
500
+ rw = ele . renderedOuterWidth ( ) ;
501
+ rh = ele . renderedOuterHeight ( ) ;
502
502
} else {
503
503
rp = e . renderedPosition || e . cyRenderedPosition ;
504
504
rw = 1 ;
@@ -510,19 +510,24 @@ var cxtmenu = function cxtmenu(params) {
510
510
ctrx = rp . x ;
511
511
ctry = rp . y ;
512
512
513
- createMenuItems ( ) ;
513
+ r = rw / 2 + ( options . menuRadius instanceof Function ? options . menuRadius ( target ) : Number ( options . menuRadius ) ) ;
514
+ containerSize = ( r + options . activePadding ) * 2 ;
515
+ updatePixelRatio ( ) ;
514
516
515
517
setStyles ( parent , {
518
+ width : containerSize + 'px' ,
519
+ height : containerSize + 'px' ,
516
520
display : 'block' ,
517
521
left : rp . x - r + 'px' ,
518
522
top : rp . y - r + 'px'
519
523
} ) ;
524
+ createMenuItems ( ) ;
520
525
521
526
rs = Math . max ( rw , rh ) / 2 ;
522
527
rs = Math . max ( rs , options . minSpotlightRadius ) ;
523
528
rs = Math . min ( rs , options . maxSpotlightRadius ) ;
524
529
525
- queueDrawBg ( ) ;
530
+ queueDrawBg ( r ) ;
526
531
527
532
activeCommandI = undefined ;
528
533
@@ -554,12 +559,19 @@ var cxtmenu = function cxtmenu(params) {
554
559
var cosTheta = ( dy * dy - d * d - dx * dx ) / ( - 2 * d * dx ) ;
555
560
var theta = Math . acos ( cosTheta ) ;
556
561
562
+ var rw = void 0 ;
563
+ if ( target && target . isNode instanceof Function && target . isNode ( ) && ! target . isParent ( ) && ! options . atMouse ) {
564
+ rw = target . renderedOuterWidth ( ) ;
565
+ } else {
566
+ rw = 1 ;
567
+ }
568
+
569
+ r = rw / 2 + ( options . menuRadius instanceof Function ? options . menuRadius ( target ) : Number ( options . menuRadius ) ) ;
557
570
if ( d < rs + options . spotlightPadding ) {
558
- queueDrawBg ( ) ;
571
+ queueDrawBg ( r ) ;
559
572
return ;
560
573
}
561
-
562
- queueDrawBg ( ) ;
574
+ queueDrawBg ( r ) ;
563
575
564
576
var rx = dx * r / d ;
565
577
var ry = dy * r / d ;
@@ -590,7 +602,7 @@ var cxtmenu = function cxtmenu(params) {
590
602
theta2 += dtheta ;
591
603
}
592
604
593
- queueDrawCommands ( rx , ry , theta ) ;
605
+ queueDrawCommands ( rx , ry , r , theta ) ;
594
606
} ) . on ( 'tapdrag' , dragHandler ) . on ( 'cxttapend tapend' , function ( ) {
595
607
parent . style . display = 'none' ;
596
608
@@ -677,7 +689,9 @@ module.exports = Object.assign != null ? Object.assign.bind(Object) : function (
677
689
678
690
679
691
var defaults = {
680
- menuRadius : 100 , // the radius of the circular menu in pixels
692
+ menuRadius : function menuRadius ( ele ) {
693
+ return 100 ;
694
+ } , // the radius of the circular menu in pixels
681
695
selector : 'node' , // elements matching this Cytoscape.js selector will trigger cxtmenus
682
696
commands : [ // an array of commands to list in the menu or a function that returns the array
683
697
/*
0 commit comments