Skip to content

Commit

Permalink
Invert x-axis
Browse files Browse the repository at this point in the history
  • Loading branch information
Johana Supíková committed Apr 19, 2021
1 parent 15dd72f commit abf4e6b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main/java/GUI/FXMLLineChartController.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public void initialize(URL url, ResourceBundle rb) {
lineChart.setAnimated(false);
lineChart.setCreateSymbols(false);

//
NumberAxis xAxis = (NumberAxis)lineChart.getXAxis();
xAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(xAxis) {
@Override
public String toString(Number value) {
//minus value FIXME if you can
return String.format("%.1f", -value.doubleValue());
}
});

//-- Tooltip for lineChart
mouseLocationInScene = new SimpleObjectProperty<>();
tooltip = new Tooltip();
Expand All @@ -51,7 +61,7 @@ public void initialize(URL url, ResourceBundle rb) {
double x = getXMouseCoordinate();
double y = getYMouseCoordinate();
tooltip.show(lineChart, evt.getScreenX() + 50, evt.getScreenY());
tooltip.setText(String.format("[%.4f; %.4f]", x, y));
tooltip.setText(String.format("[%.4f; %.4f]", -x, y));
});
}

Expand All @@ -63,7 +73,7 @@ public void graphExited() {
@FXML
public void graphClicked() {
if (!lineChart.getData().isEmpty()) {
double x = Double.parseDouble(String.format("%.4f", getXMouseCoordinate())); //use showed values in tooltip
double x = -Double.parseDouble(String.format("%.4f", getXMouseCoordinate())); //use showed values in tooltip
double y = Double.parseDouble(String.format("%.4f", getYMouseCoordinate()));
mainController.manageInput(x, y, 0.0, 0.0, (short)2);
}
Expand Down Expand Up @@ -129,7 +139,8 @@ protected Void call() throws Exception {
int index = 0;
for (Star s : isochrone) {
if (index % 4 != 0) { index++; continue; } //faster rendering
series.getData().add(new XYChart.Data(s.getTemperature(), s.getLuminosity()));
//need to invert x-axis and this solution sucks, but FIXME later
series.getData().add(new XYChart.Data(-s.getTemperature(), s.getLuminosity()));
index++;
}

Expand All @@ -150,10 +161,10 @@ public void run() {

//ZAMS
XYChart.Series series = new XYChart.Series();
series.setName("ZAMS_track");
ArrayList<Star> track = GridFileParser.getCurrentData().getZAMS().getTrack();
for (int i = 0; i < track.size(); i++) {
series.getData().add(new XYChart.Data(track.get(i).getTemperature(), track.get(i).getLuminosity()));
//also need to invert x-axis and this solution sucks, but FIXME later
series.getData().add(new XYChart.Data(-track.get(i).getTemperature(), track.get(i).getLuminosity()));
}
lineChart.getData().add(series);
}
Expand Down

0 comments on commit abf4e6b

Please sign in to comment.