15
15
import java .util .LinkedList ;
16
16
17
17
/**
18
- * Created by Martijn van Meerten on 8-5-2017.
19
18
* Controller for drawing the graph.
20
19
*/
21
20
public class GraphController {
@@ -32,6 +31,7 @@ public class GraphController {
32
31
private double zoomLevel = 1 ;
33
32
34
33
private int centerNodeInt ;
34
+ private boolean drawSNP = false ;
35
35
36
36
/**
37
37
* Initialize controller object.
@@ -49,55 +49,45 @@ public int getCenterNodeInt() {
49
49
return this .centerNodeInt ;
50
50
}
51
51
52
+ /**
53
+ * Utility function for benchmarking purposes.
54
+ * @param description the description to print
55
+ * @param r the {@link Runnable} to run/benchmark
56
+ */
57
+ private void time (String description , Runnable r ) {
58
+ long start = System .nanoTime ();
59
+ r .run ();
60
+ Console .println (String .format ("%s: %d ms" , description , (System .nanoTime () - start ) / 1000000 ));
61
+ }
62
+
52
63
/**
53
64
* Method to draw the subGraph decided by a center node and radius.
54
65
* @param center the node of which the radius starts.
55
66
* @param radius the amount of layers to be drawn.
56
67
*/
57
68
public void draw (int center , int radius ) {
58
- long startTimeProgram = System .nanoTime ();
59
- GraphicsContext gc = canvas .getGraphicsContext2D ();
60
-
61
- long startTimeSubGraph = System .nanoTime ();
62
-
63
- DrawableSegment centerNode = new DrawableSegment (graph , center );
64
- centerNodeInt = centerNode .getIdentifier ();
65
- subGraph = new SubGraph (centerNode , radius );
66
-
67
- long finishTimeSubGraph = System .nanoTime ();
68
-
69
- long startLayoutTime = System .nanoTime ();
70
- subGraph .layout ();
71
- long finishTimeLayout = System .nanoTime ();
72
-
73
- long startTimeColorize = System .nanoTime ();
74
- colorize ();
75
- long finishTimeColorize = System .nanoTime ();
76
-
77
-
78
- long startTimeDrawing = System .nanoTime ();
79
- draw (gc );
80
- long finishTimeDrawing = System .nanoTime ();
81
-
82
- highlightNode (center , Color .DARKORANGE );
83
- centerOnNodeId (center );
84
-
85
- long finishTime = System .nanoTime ();
86
- long differenceTimeProgram = finishTime - startTimeProgram ;
87
- long differenceTimeDrawing = finishTimeDrawing - startTimeDrawing ;
88
- long differenceTimeLayout = finishTimeLayout - startLayoutTime ;
89
- long differenceTimeSubGraph = finishTimeSubGraph - startTimeSubGraph ;
90
- long differenceTimeColorize = finishTimeColorize - startTimeColorize ;
91
- long msDifferenceTimeProgram = differenceTimeProgram / 1000000 ;
92
- long millisecondTimeDrawing = differenceTimeDrawing / 1000000 ;
93
- long msDifferenceTimeLayout = differenceTimeLayout / 1000000 ;
94
- long msDifferenceTimeSubGraph = differenceTimeSubGraph / 1000000 ;
95
- long msDifferenceTimeColorize = differenceTimeColorize / 1000000 ;
96
- Console .println ("time of SubGraph: " + msDifferenceTimeSubGraph );
97
- Console .println ("Time of layout: " + msDifferenceTimeLayout );
98
- Console .println ("Time of Colorize: " + msDifferenceTimeColorize );
99
- Console .println ("Time of Drawing: " + millisecondTimeDrawing );
100
- Console .println ("Time of Total Program: " + msDifferenceTimeProgram );
69
+ time ("Total drawing" , () -> {
70
+ DrawableSegment centerNode = new DrawableSegment (graph , center );
71
+ centerNodeInt = centerNode .getIdentifier ();
72
+ GraphicsContext gc = canvas .getGraphicsContext2D ();
73
+
74
+ time ("Find subgraph" , () -> subGraph = new SubGraph (centerNode , radius ));
75
+
76
+ if (drawSNP ) {
77
+ time ("Replace SNPs" , subGraph ::replaceSNPs );
78
+ }
79
+ time ("Layout subgraph" , subGraph ::layout );
80
+
81
+ time ("Colorize" , this ::colorize );
82
+
83
+ time ("Calculate genomes through edges" , subGraph ::calculateGenomes );
84
+ time ("Drawing" , () -> {
85
+ draw (gc );
86
+ });
87
+
88
+ centerOnNodeId (center );
89
+ highlightNode (center , Color .DARKORANGE );
90
+ });
101
91
}
102
92
103
93
/**
@@ -357,6 +347,13 @@ public void highlightByGenome(int genomeID) {
357
347
highlightNodes (drawNodeList , Color .YELLOW );
358
348
}
359
349
350
+ /**
351
+ * Sets if the glyph snippets will be drawn or not.
352
+ */
353
+ void setSNP () {
354
+ drawSNP = !drawSNP ;
355
+ }
356
+
360
357
/**
361
358
* Returns the node clicked on else returns null.
362
359
* @param x position horizontally where clicked
0 commit comments