Skip to content

Commit 2686869

Browse files
authored
Merge pull request #347 from ProgrammingLife2017/minimap
Minimap updated to look better
2 parents 0be4617 + 53bfc8b commit 2686869

File tree

6 files changed

+79
-41
lines changed

6 files changed

+79
-41
lines changed

src/main/java/programminglife/gui/controller/GraphController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private void highlightNode(int nodeID, Color color) {
139139
* @param clickedOn boolean to check if the node was clicked on.
140140
*/
141141
private void highlightNode(DrawableNode node, Color color, Boolean clickedOn) {
142-
if (clickedOn){
142+
if (clickedOn) {
143143
node.setStrokeColor(color);
144144
}
145145
node.setStrokeWidth(5.0 * subGraph.getZoomLevel());

src/main/java/programminglife/gui/controller/GuiController.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class GuiController implements Observer {
7979
@FXML private TextField txtCenterNode;
8080

8181
@FXML private ResizableCanvas canvas;
82-
@FXML AnchorPane anchorLeftControlPanel;
82+
@FXML private AnchorPane anchorLeftControlPanel;
8383
@FXML private AnchorPane anchorGraphPanel;
8484
@FXML private AnchorPane anchorGraphInfo;
8585
@FXML private Canvas miniMap;
@@ -256,6 +256,7 @@ private void initMenuBar() {
256256
btnInstructions.setOnAction(event -> Alerts.infoInstructionAlert());
257257
btnInstructions.setAccelerator(new KeyCodeCombination(KeyCode.H, KeyCodeCombination.CONTROL_DOWN));
258258

259+
btnMiniMap.setSelected(true);
259260
btnMiniMap.setOnAction(event -> miniMapController.toggleVisibility(graphController.getCenterNodeInt()));
260261
btnMiniMap.setAccelerator(new KeyCodeCombination(KeyCode.M, KeyCodeCombination.CONTROL_DOWN));
261262
btnSNP.setOnAction(event -> {
@@ -801,4 +802,8 @@ public void setFile(File file) {
801802
GraphController getGraphController() {
802803
return this.graphController;
803804
}
805+
806+
public AnchorPane getAnchorLeftControlPanel() {
807+
return this.anchorLeftControlPanel;
808+
}
804809
}

src/main/java/programminglife/gui/controller/HighlightController.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,20 @@ public void initialize() {
8282
lstSelectedGenomes.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
8383
@Override
8484
public ListCell<String> call(ListView<String> param) {
85-
ListCell<String> cell = new ListCell<String>() {
85+
return new ListCell<String>() {
8686
@Override
8787
protected void updateItem(String t, boolean bln) {
8888
super.updateItem(t, bln);
8989
if (t != null) {
9090
setText(t);
91-
setStyle(String.format("-fx-background-color: %s;", hex(genomeColors[graphController.getGraph().getGenomeID(t)])));
91+
setStyle(String.format("-fx-background-color: %s;",
92+
hex(genomeColors[graphController.getGraph().getGenomeID(t)])));
9293
} else {
9394
setText("");
9495
setStyle("");
9596
}
9697
}
9798
};
98-
99-
return cell;
10099
}
101100
});
102101

@@ -111,6 +110,12 @@ protected void updateItem(String t, boolean bln) {
111110
btnUnselectGenomes.setOnMouseClicked(this::unselectGenomes);
112111
}
113112

113+
/**
114+
* Method to return the string of a colour.
115+
*
116+
* @param c Color to be converted.
117+
* @return String of the colour.
118+
*/
114119
private String hex(Color c) {
115120
return "#" + Integer.toHexString(c.hashCode()).substring(0, 6).toUpperCase() + "B4";
116121
}

src/main/java/programminglife/gui/controller/MiniMapController.java

+39-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import javafx.scene.canvas.Canvas;
55
import javafx.scene.canvas.GraphicsContext;
66
import javafx.scene.input.MouseEvent;
7+
import javafx.scene.layout.AnchorPane;
78
import javafx.scene.paint.Color;
89

910
/**
@@ -14,11 +15,11 @@ class MiniMapController {
1415
private final Canvas miniMap;
1516
private final int size;
1617

17-
private boolean visible = false;
18+
private boolean visible = true;
1819
private GraphController graphController;
1920
private GuiController guiController;
2021

21-
private final static int SPLIT_PANEL_WIDTH = 15;
22+
private static final int SPLIT_PANEL_WIDTH = 15;
2223

2324
/**
2425
* Constructor for the miniMap.
@@ -28,6 +29,9 @@ class MiniMapController {
2829
*/
2930
MiniMapController(Canvas miniMap, int size) {
3031
this.miniMap = miniMap;
32+
AnchorPane.setRightAnchor(miniMap, 0.d);
33+
AnchorPane.setLeftAnchor(miniMap, 0.d);
34+
AnchorPane.setBottomAnchor(miniMap, 0.d);
3135
Platform.runLater(this.miniMap::toFront);
3236
miniMap.setVisible(visible);
3337
this.size = size;
@@ -39,18 +43,32 @@ class MiniMapController {
3943
*/
4044
private void drawMiniMap() {
4145
GraphicsContext gc = miniMap.getGraphicsContext2D();
42-
gc.setFill(Color.LIGHTGRAY);
46+
gc.setFill(Color.BURLYWOOD);
4347
gc.fillRect(0, 0, miniMap.getWidth(), 50);
4448

4549
gc.setStroke(Color.BLACK);
4650
gc.setLineWidth(2);
47-
gc.strokeLine(0, 25, miniMap.getWidth(), 25);
51+
gc.strokeLine(0, 49, miniMap.getWidth(), 49);
52+
gc.strokeLine(0, 1, miniMap.getWidth(), 1);
53+
54+
for (int i = 0; i <= 10; i++) {
55+
gc.setStroke(Color.BLACK);
56+
gc.setLineWidth(1);
57+
gc.strokeLine(i * miniMap.getWidth() / 10, 50, i * miniMap.getWidth() / 10, 0);
58+
}
59+
for (int i = 0; i < 10; i++) {
60+
gc.setFill(Color.BLACK);
61+
gc.fillText(String.valueOf(i * graphController.getGraph().size() / 10),
62+
i * miniMap.getWidth() / 10, 45);
63+
}
4864
}
4965

5066
/**
5167
* Toggle the visibility of the MiniMap.
68+
*
69+
* @param centerNodeId node to be centered on.
5270
*/
53-
public void toggleVisibility(int centerNodeId) {
71+
void toggleVisibility(int centerNodeId) {
5472
visible = !visible;
5573
this.miniMap.setVisible(visible);
5674
if (visible) {
@@ -59,15 +77,23 @@ public void toggleVisibility(int centerNodeId) {
5977
}
6078
}
6179

62-
public void handleMouse(MouseEvent event) {
63-
double locX = event.getSceneX() - this.guiController.anchorLeftControlPanel.getWidth() - SPLIT_PANEL_WIDTH;
80+
/**
81+
* Method to handle the event of the mouse.
82+
*
83+
* @param event MouseEvent to be processed.
84+
*/
85+
private void handleMouse(MouseEvent event) {
86+
double locX = event.getSceneX() - this.guiController.getAnchorLeftControlPanel().getWidth() - SPLIT_PANEL_WIDTH;
6487
double ratio = locX / miniMap.getBoundsInParent().getMaxX();
6588
int centerNodeId = (int) Math.ceil(graphController.getGraph().size() * ratio);
66-
System.out.println("clicked");
67-
Platform.runLater(() -> graphController.draw(centerNodeId, 10));
89+
guiController.setText(centerNodeId);
90+
guiController.draw();
6891
}
6992

70-
public void initClick() {
93+
/**
94+
* Method to initialize the mouseEvent.
95+
*/
96+
private void initClick() {
7197
miniMap.setOnMousePressed(this::handleMouse);
7298
}
7399

@@ -77,19 +103,19 @@ public void initClick() {
77103
*
78104
* @param centerNode int of the centernode currently at.
79105
*/
80-
public void showPosition(int centerNode) {
106+
void showPosition(int centerNode) {
81107
GraphicsContext gc = miniMap.getGraphicsContext2D();
82108
gc.clearRect(0, 0, miniMap.getWidth(), miniMap.getHeight());
83109
drawMiniMap();
84110
gc.setFill(Color.RED);
85111
gc.fillOval((centerNode / (double) size) * miniMap.getWidth(), 20, 10, 10);
86112
}
87113

88-
public void setGraphController(GraphController graphController) {
114+
void setGraphController(GraphController graphController) {
89115
this.graphController = graphController;
90116
}
91117

92-
public void setGuiController(GuiController guiController) {
118+
void setGuiController(GuiController guiController) {
93119
this.guiController = guiController;
94120
}
95121
}

src/main/java/programminglife/model/drawing/DrawableSegment.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,8 @@ public void setDrawDimensions(double zoomLevel) {
109109
int segmentLength = this.getSequenceLength();
110110
double width, height;
111111

112-
113-
//VERSION 1
114-
// double minValue = min(10 * segmentLength, 100);
115-
// width = minValue + Math.pow(segmentLength * minValue, 1.0 / 2);
116-
117-
//VERSION 2
118-
width = Math.log(Math.max(segmentLength - 9, 1)) / Math.log(1.15) * 10 + min(10 * segmentLength, 100);
119-
120-
// width = 10 + Math.pow(segmentLength, 1.0 / 2);
121-
112+
width = Math.log(Math.max(segmentLength - 9, 1)) / Math.log(1.15) * 10 + Math.min(10 * segmentLength, 100);
113+
122114
height = NODE_HEIGHT;
123115

124116
this.setSize(width * zoomLevel, height * zoomLevel);

src/main/java/programminglife/model/drawing/SubGraph.java

+22-12
Original file line numberDiff line numberDiff line change
@@ -277,33 +277,40 @@ public boolean checkDynamicLoad(int leftBorder, double rightBorder) {
277277
return didLoad;
278278
}
279279

280+
/**
281+
* Method to update the centerNode.
282+
*
283+
* @param centerCanvasX double of the x center of the canvas.
284+
* @param oldCenterNode int of the old centerNode.
285+
* @return int of the new centerNode.
286+
*/
280287
public int updateCenterNode(double centerCanvasX, int oldCenterNode) {
281288
for (int i = 0; i < layers.size(); i++) {
282289
if (layers.get(i).getX() > centerCanvasX) {
283-
if (Math.abs(layers.get(i - 1).getX() - centerCanvasX) <
284-
Math.abs(layers.get(i).getX() - centerCanvasX)) {
290+
if (Math.abs(layers.get(i - 1).getX() - centerCanvasX)
291+
< Math.abs(layers.get(i).getX() - centerCanvasX)) {
285292
for (DrawableNode node : layers.get(i - 1)) {
286-
if (node instanceof DrawableSegment &&
287-
((DrawableSegment) node).getSequence().length() > 1) {
293+
if (node instanceof DrawableSegment
294+
&& ((DrawableSegment) node).getSequence().length() > 1) {
288295
return node.getIdentifier();
289296
}
290297
}
291298
for (DrawableNode node : layers.get(i)) {
292-
if (node instanceof DrawableSegment &&
293-
((DrawableSegment) node).getSequence().length() > 1) {
299+
if (node instanceof DrawableSegment
300+
&& ((DrawableSegment) node).getSequence().length() > 1) {
294301
return node.getIdentifier();
295302
}
296303
}
297304
} else {
298305
for (DrawableNode node : layers.get(i)) {
299-
if (node instanceof DrawableSegment &&
300-
((DrawableSegment) node).getSequence().length() > 1) {
306+
if (node instanceof DrawableSegment
307+
&& ((DrawableSegment) node).getSequence().length() > 1) {
301308
return node.getIdentifier();
302309
}
303310
}
304311
for (DrawableNode node : layers.get(i - 1)) {
305-
if (node instanceof DrawableSegment &&
306-
((DrawableSegment) node).getSequence().length() > 1) {
312+
if (node instanceof DrawableSegment
313+
&& ((DrawableSegment) node).getSequence().length() > 1) {
307314
return node.getIdentifier();
308315
}
309316
}
@@ -356,8 +363,11 @@ public void setZoomLevel(double zoomLevel) {
356363
*/
357364
public Drawable onClick(double x, double y) {
358365
for (DrawableNode drawableNode : this.getNodes().values()) {
359-
double edgeThickness = drawableNode.getStrokeWidth() / 2; //Devide by two because only half of the edge is outside the node other half falls on the inside but gets drawn over.
360-
if (x >= drawableNode.getLocation().getX() - edgeThickness && y >= drawableNode.getLocation().getY() - edgeThickness
366+
//Divide by 2 because only half of the edge is outside the node
367+
//the other half falls on the inside but gets drawn over.
368+
double edgeThickness = drawableNode.getStrokeWidth() / 2;
369+
if (x >= drawableNode.getLocation().getX() - edgeThickness
370+
&& y >= drawableNode.getLocation().getY() - edgeThickness
361371
&& x <= drawableNode.getLocation().getX() + drawableNode.getWidth() + edgeThickness
362372
&& y <= drawableNode.getLocation().getY() + drawableNode.getHeight() + edgeThickness) {
363373
return drawableNode;

0 commit comments

Comments
 (0)