public void draw() { 
	
	 //Capture the current frame drawn on the screen, if 'r' was pressed
	 if (recording){
		  beginRecord(PDF,"frame-####.pdf");
	  }
	  
	 scale(scaleFactor); //Zooming in and out, re-scale the mouse coordinates 
	 if (mouseX !=pmouseX && mouseY!=pmouseY){ //http://forum.processing.org/two/discussion/1015/scaling-up-1-5-the-whole-sketch-problems-with-non-working-buttons-/p1
		 mouseX = (int)(mouseX/scaleFactor);
		 mouseY = (int)(mouseY/scaleFactor);
	 }
	 
	 if (this.editModeButton.toggle==1){ //Reposition nodes by dragging
		  drawBackground();    	    
		  this.graph.clearQueries();
		  this.graph.drawAllElements();
	  }else if (timeSlider.dragging){ //Dragging the slider
    	drawBackground();    	    	
    	timeSlider.drawSlider();  
    	timeSlider.drag(mouseX);
    	this.graph.updateView(timeSlider.currentView, timeSlider.nextView, timeSlider.drawingView);	
    	this.graph.animateGraph(timeSlider.currentView, timeSlider.nextView, timeSlider.interpAmount);       	
    }else if (graph.draggingNode){ //Dragging around a node    		 
    	drawBackground();    	
    	timeSlider.drawSlider();    	
    	this.graph.dragAroundNode();  
    	timeSlider.animateTick(graph.interpAmount, graph.currentView, graph.nextView);
    }else if (graph.onDraggingEdge){    	
    	drawBackground();    	
    	timeSlider.drawSlider();    	
    	timeSlider.animateTick(graph.interpAmount, graph.currentView, graph.nextView);
    	this.graph.dragAlongEdge();    		
    }else if (graph.dragging){ //Issue query sketching   
    	sketch();
    }else if (this.globalViewButton.toggle ==1){ //Global view mode
    	drawBackground(); 
    	this.graph.showGlobalPersistence(); 
    }else{ //Draw the graph (with hint paths if anything is selected)
    	drawBackground();    	
        timeSlider.drawSlider();          
    	this.graph.drawGraph(graph.drawingView);    	
    } 
	  
	if (recording){
		endRecord();
		recording=false;
	}
  }