@ -18,20 +18,21 @@ class CanvasRenderer {
this . redrawRequested = false ;
this . redrawRequested = false ;
this . renderTimer = false ;
this . renderTimer = false ;
this . requiresTimeout = true ;
this . requiresTimeout = true ;
this . continueRendering = false ;
this . renderingActive = false ;
this . renderRequests = 0 ;
this . renderRequests = 0 ;
this . pixelRatio = undefined ;
this . canvasTopLeft = { x : 0 , y : 0 } ;
this . canvasTopLeft = { x : 0 , y : 0 } ;
this . canvasBottomRight = { x : 0 , y : 0 } ;
this . canvasBottomRight = { x : 0 , y : 0 } ;
this . dragging = false ;
this . dragging = false ;
this . body . emitter . on ( "dragStart" , ( ) => { this . dragging = true ; console . log ( "here" ) } ) ;
this . body . emitter . on ( "dragStart" , ( ) => { this . dragging = true ; } ) ;
this . body . emitter . on ( "dragEnd" , ( ) => this . dragging = false ) ;
this . body . emitter . on ( "dragEnd" , ( ) => this . dragging = false ) ;
this . body . emitter . on ( "_redraw" , this . _redraw . bind ( this ) ) ;
this . body . emitter . on ( "_redraw" , ( ) => { if ( this . renderingActive === false ) { this . _redraw ( ) ; } } ) ;
this . body . emitter . on ( "_requestRedraw" , this . _requestRedraw . bind ( this ) ) ;
this . body . emitter . on ( "_requestRedraw" , this . _requestRedraw . bind ( this ) ) ;
this . body . emitter . on ( "_startRendering" , ( ) => { this . renderRequests += 1 ; this . continueRendering = true ; this . startRendering ( ) ; } ) ;
this . body . emitter . on ( "_stopRendering" , ( ) => { this . renderRequests -= 1 ; this . continueRendering = this . renderRequests > 0 ; } ) ;
this . body . emitter . on ( "_startRendering" , ( ) => { this . renderRequests += 1 ; this . renderingActive = true ; this . startRendering ( ) ; } ) ;
this . body . emitter . on ( "_stopRendering" , ( ) => { this . renderRequests -= 1 ; this . renderingActive = this . renderRequests > 0 ; } ) ;
this . options = { } ;
this . options = { } ;
this . defaultOptions = {
this . defaultOptions = {
@ -40,7 +41,6 @@ class CanvasRenderer {
}
}
util . extend ( this . options , this . defaultOptions ) ;
util . extend ( this . options , this . defaultOptions ) ;
this . _determineBrowserMethod ( ) ;
this . _determineBrowserMethod ( ) ;
}
}
@ -52,7 +52,7 @@ class CanvasRenderer {
startRendering ( ) {
startRendering ( ) {
if ( this . continueRendering === true ) {
if ( this . renderingActive === true ) {
if ( ! this . renderTimer ) {
if ( ! this . renderTimer ) {
if ( this . requiresTimeout == true ) {
if ( this . requiresTimeout == true ) {
this . renderTimer = window . setTimeout ( this . renderStep . bind ( this ) , this . simulationInterval ) ; // wait this.renderTimeStep milliseconds and perform the animation step function
this . renderTimer = window . setTimeout ( this . renderStep . bind ( this ) , this . simulationInterval ) ; // wait this.renderTimeStep milliseconds and perform the animation step function
@ -99,7 +99,7 @@ class CanvasRenderer {
* @ private
* @ private
* /
* /
_requestRedraw ( ) {
_requestRedraw ( ) {
if ( this . redrawRequested !== true ) {
if ( this . redrawRequested !== true && this . renderingActive === false ) {
this . redrawRequested = true ;
this . redrawRequested = true ;
if ( this . requiresTimeout === true ) {
if ( this . requiresTimeout === true ) {
window . setTimeout ( this . _redraw . bind ( this , false ) , 0 ) ;
window . setTimeout ( this . _redraw . bind ( this , false ) , 0 ) ;
@ -116,6 +116,14 @@ class CanvasRenderer {
this . redrawRequested = false ;
this . redrawRequested = false ;
var ctx = this . canvas . frame . canvas . getContext ( '2d' ) ;
var ctx = this . canvas . frame . canvas . getContext ( '2d' ) ;
if ( this . pixelRation === undefined ) {
this . pixelRatio = ( window . devicePixelRatio || 1 ) / ( ctx . webkitBackingStorePixelRatio ||
ctx . mozBackingStorePixelRatio ||
ctx . msBackingStorePixelRatio ||
ctx . oBackingStorePixelRatio ||
ctx . backingStorePixelRatio || 1 ) ;
}
ctx . setTransform ( this . pixelRatio , 0 , 0 , this . pixelRatio , 0 , 0 ) ;
ctx . setTransform ( this . pixelRatio , 0 , 0 , this . pixelRatio , 0 , 0 ) ;
// clear the canvas
// clear the canvas
@ -133,8 +141,6 @@ class CanvasRenderer {
this . canvasTopLeft = this . canvas . DOMtoCanvas ( { x : 0 , y : 0 } ) ;
this . canvasTopLeft = this . canvas . DOMtoCanvas ( { x : 0 , y : 0 } ) ;
this . canvasBottomRight = this . canvas . DOMtoCanvas ( { x : this . canvas . frame . canvas . clientWidth , y : this . canvas . frame . canvas . clientHeight } ) ;
this . canvasBottomRight = this . canvas . DOMtoCanvas ( { x : this . canvas . frame . canvas . clientWidth , y : this . canvas . frame . canvas . clientHeight } ) ;
console . log ( this . dragging )
if ( hidden === false ) {
if ( hidden === false ) {
if ( this . dragging === false || ( this . dragging === true && this . options . hideEdgesOnDrag === false ) ) {
if ( this . dragging === false || ( this . dragging === true && this . options . hideEdgesOnDrag === false ) ) {
this . _drawEdges ( ctx ) ;
this . _drawEdges ( ctx ) ;
@ -145,14 +151,12 @@ class CanvasRenderer {
this . _drawNodes ( ctx , this . body . nodes , hidden ) ;
this . _drawNodes ( ctx , this . body . nodes , hidden ) ;
}
}
if ( hidden === false ) {
if ( this . controlNodesActive == true ) {
this . _drawControlNodes ( ctx ) ;
}
if ( this . controlNodesActive === true ) {
this . _drawControlNodes ( ctx ) ;
}
}
//this._drawNodes(ctx,this.body.supportNodes,true);
//this._drawNodes(ctx,this.body.supportNodes,true);
// this.physics.nodesSolver._debug(ctx,"#F00F0F");
//this.physics.nodesSolver._debug(ctx,"#F00F0F");
// restore original scaling and translation
// restore original scaling and translation
ctx . restore ( ) ;
ctx . restore ( ) ;