diff --git a/res/stages/main-stage.fxml b/res/stages/main-stage.fxml index e42d960c7d26fa4625d2d5b65df0184dca716c6b..e867ac83924ee95ffef3b2b01e4cf2d69183734f 100644 --- a/res/stages/main-stage.fxml +++ b/res/stages/main-stage.fxml @@ -59,16 +59,6 @@ </ImageView> </graphic> </Button> - <Button fx:id="ZoomIn" layoutX="27.0" layoutY="30.0" mnemonicParsing="false" onAction="#openAxesSetting" stylesheets="@../css/style.css" text="+" textFill="WHITE"> - <font> - <Font name="System Bold" size="20.0" /> - </font> - </Button> - <Button fx:id="ZoomOut" layoutX="27.0" layoutY="88.0" mnemonicParsing="false" onAction="#openAxesSetting" stylesheets="@../css/style.css" text="-" textFill="WHITE"> - <font> - <Font name="System Bold" size="22.0" /> - </font> - </Button> </children> <padding> <Insets top="20.0" /> diff --git a/src/main/java/fr/univlille/sae/classification/controller/AxesSettingsController.java b/src/main/java/fr/univlille/sae/classification/controller/AxesSettingsController.java index 223c3edd680ea77f58e484d054d8050b77b13815..b355ba3bb9c6528d2475e76edadb5ee4fd29bc08 100644 --- a/src/main/java/fr/univlille/sae/classification/controller/AxesSettingsController.java +++ b/src/main/java/fr/univlille/sae/classification/controller/AxesSettingsController.java @@ -123,6 +123,7 @@ public class AxesSettingsController{ } dataVisualizationView.reload(); + reset(); stage.close(); } diff --git a/src/main/java/fr/univlille/sae/classification/controller/DataStageController.java b/src/main/java/fr/univlille/sae/classification/controller/DataStageController.java index 829e3997056e62b3993d54f69488786e2d3b19c3..94c7e97cc0273ca8d7e2ea6367e0e7cc9554a1f3 100644 --- a/src/main/java/fr/univlille/sae/classification/controller/DataStageController.java +++ b/src/main/java/fr/univlille/sae/classification/controller/DataStageController.java @@ -4,6 +4,7 @@ import fr.univlille.sae.classification.model.ClassificationModel; import fr.univlille.sae.classification.view.AxesSettingsView; import fr.univlille.sae.classification.view.DataStageView; import javafx.fxml.FXML; +import javafx.scene.chart.NumberAxis; import javafx.scene.chart.ScatterChart; import javafx.scene.control.Label; import javafx.scene.control.ListView; @@ -32,6 +33,18 @@ public class DataStageController { */ private DataStageView dataStageView; + private double initialX; + private double initialY; + private double initialLowerBoundX; + private double initialUpperBoundX; + private double initialLowerBoundY; + private double initialUpperBoundY; + + public void initialize() { + setupZoom(); + setupDrag(); + } + /** * Ouvrir les paramètres des axes de la vue */ @@ -65,8 +78,89 @@ public class DataStageController { this.AxesSelected.setText(texte); } + public void setAxesSelectedDisable(){ + this.AxesSelected.setDisable(true); + } + public ListView getPointInfo(){ return this.PointInfo; }; + private void setupZoom() { + NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis(); + NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis(); + + scatterChart.setOnScroll(event -> { + xAxis.setAutoRanging(false); + yAxis.setAutoRanging(false); + + double delta = event.getDeltaY(); + double mouseX = event.getSceneX(); + double mouseY = event.getSceneY(); + + double chartX = xAxis.sceneToLocal(mouseX, mouseY).getX(); + double chartY = yAxis.sceneToLocal(mouseX, mouseY).getY(); + + double zoomFactor; + if (delta > 0) { + zoomFactor = 0.90; + } else { + zoomFactor = 1.05; + } + + double xLower = xAxis.getLowerBound(); + double xUpper = xAxis.getUpperBound(); + double yLower = yAxis.getLowerBound(); + double yUpper = yAxis.getUpperBound(); + + double rangeX = xUpper - xLower; + double rangeY = yUpper - yLower; + + double newRangeX = rangeX * zoomFactor; + double newRangeY = rangeY * zoomFactor; + + xAxis.setLowerBound(xLower + (chartX / xAxis.getWidth()) * (rangeX - newRangeX)); + xAxis.setUpperBound(xUpper - ((xAxis.getWidth() - chartX) / xAxis.getWidth()) * (rangeX - newRangeX)); + + yAxis.setLowerBound(yLower + ((yAxis.getHeight() - chartY) / yAxis.getHeight()) * (rangeY - newRangeY)); + yAxis.setUpperBound(yUpper - (chartY / yAxis.getHeight()) * (rangeY - newRangeY)); + }); + + xAxis.setAutoRanging(true); + yAxis.setAutoRanging(true); + } + + private void setupDrag() { + scatterChart.setOnMousePressed(event -> { + initialX = event.getSceneX(); + initialY = event.getSceneY(); + initialLowerBoundX = ((NumberAxis) scatterChart.getXAxis()).getLowerBound(); + initialUpperBoundX = ((NumberAxis) scatterChart.getXAxis()).getUpperBound(); + initialLowerBoundY = ((NumberAxis) scatterChart.getYAxis()).getLowerBound(); + initialUpperBoundY = ((NumberAxis) scatterChart.getYAxis()).getUpperBound(); + }); + + NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis(); + NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis(); + + scatterChart.setOnMouseDragged(event -> { + xAxis.setAutoRanging(false); + yAxis.setAutoRanging(false); + double deltaX = event.getSceneX() - initialX; + double deltaY = event.getSceneY() - initialY; + + double newLowerBoundX = initialLowerBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth(); + double newUpperBoundX = initialUpperBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth(); + double newLowerBoundY = initialLowerBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight(); + double newUpperBoundY = initialUpperBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight(); + + xAxis.setLowerBound(newLowerBoundX); + xAxis.setUpperBound(newUpperBoundX); + yAxis.setLowerBound(newLowerBoundY); + yAxis.setUpperBound(newUpperBoundY); + }); + xAxis.setAutoRanging(true); + yAxis.setAutoRanging(true); + } + } diff --git a/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java b/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java index 167f9e51a686d4b26cdeff081ff0932d41e2cd0b..d18c02d73d9952ef1fb300ddde0731b560ace749 100644 --- a/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java +++ b/src/main/java/fr/univlille/sae/classification/controller/MainStageController.java @@ -29,13 +29,19 @@ public class MainStageController { @FXML ListView PointInfo; - @FXML - Button ZoomIn; + private MainStageView mainStageView; - @FXML - Button ZoomOut; + private double initialX; + private double initialY; + private double initialLowerBoundX; + private double initialUpperBoundX; + private double initialLowerBoundY; + private double initialUpperBoundY; - private MainStageView mainStageView; + public void initialize() { + setupZoom(); + setupDrag(); + } /** * Ouvre l'interface de chargement des données. @@ -111,6 +117,10 @@ public class MainStageController { this.AxesSelected.setText(texte); } + public void setAxesSelectedDisable(){ + this.AxesSelected.setDisable(true); + } + /** * Renvoie le bouton de classification de données. * @return Bouton utilisé pour déclencher la classification des données. @@ -123,7 +133,82 @@ public class MainStageController { return this.PointInfo; }; - public void setZoomIn(){ - ((NumberAxis)getScatterChart().getXAxis()).getUpperBound(); + private void setupZoom() { + NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis(); + NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis(); + + scatterChart.setOnScroll(event -> { + xAxis.setAutoRanging(false); + yAxis.setAutoRanging(false); + + double delta = event.getDeltaY(); + double mouseX = event.getSceneX(); + double mouseY = event.getSceneY(); + + double chartX = xAxis.sceneToLocal(mouseX, mouseY).getX(); + double chartY = yAxis.sceneToLocal(mouseX, mouseY).getY(); + + double zoomFactor; + if (delta > 0) { + zoomFactor = 0.90; + } else { + zoomFactor = 1.05; + } + + double xLower = xAxis.getLowerBound(); + double xUpper = xAxis.getUpperBound(); + double yLower = yAxis.getLowerBound(); + double yUpper = yAxis.getUpperBound(); + + double rangeX = xUpper - xLower; + double rangeY = yUpper - yLower; + + double newRangeX = rangeX * zoomFactor; + double newRangeY = rangeY * zoomFactor; + + xAxis.setLowerBound(xLower + (chartX / xAxis.getWidth()) * (rangeX - newRangeX)); + xAxis.setUpperBound(xUpper - ((xAxis.getWidth() - chartX) / xAxis.getWidth()) * (rangeX - newRangeX)); + + yAxis.setLowerBound(yLower + ((yAxis.getHeight() - chartY) / yAxis.getHeight()) * (rangeY - newRangeY)); + yAxis.setUpperBound(yUpper - (chartY / yAxis.getHeight()) * (rangeY - newRangeY)); + }); + + xAxis.setAutoRanging(true); + yAxis.setAutoRanging(true); } + + + private void setupDrag() { + scatterChart.setOnMousePressed(event -> { + initialX = event.getSceneX(); + initialY = event.getSceneY(); + initialLowerBoundX = ((NumberAxis) scatterChart.getXAxis()).getLowerBound(); + initialUpperBoundX = ((NumberAxis) scatterChart.getXAxis()).getUpperBound(); + initialLowerBoundY = ((NumberAxis) scatterChart.getYAxis()).getLowerBound(); + initialUpperBoundY = ((NumberAxis) scatterChart.getYAxis()).getUpperBound(); + }); + + NumberAxis xAxis = (NumberAxis) scatterChart.getXAxis(); + NumberAxis yAxis = (NumberAxis) scatterChart.getYAxis(); + + scatterChart.setOnMouseDragged(event -> { + xAxis.setAutoRanging(false); + yAxis.setAutoRanging(false); + double deltaX = event.getSceneX() - initialX; + double deltaY = event.getSceneY() - initialY; + + double newLowerBoundX = initialLowerBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth(); + double newUpperBoundX = initialUpperBoundX - deltaX * (xAxis.getUpperBound() - xAxis.getLowerBound()) / scatterChart.getWidth(); + double newLowerBoundY = initialLowerBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight(); + double newUpperBoundY = initialUpperBoundY + deltaY * (yAxis.getUpperBound() - yAxis.getLowerBound()) / scatterChart.getHeight(); + + xAxis.setLowerBound(newLowerBoundX); + xAxis.setUpperBound(newUpperBoundX); + yAxis.setLowerBound(newLowerBoundY); + yAxis.setUpperBound(newUpperBoundY); + }); + xAxis.setAutoRanging(true); + yAxis.setAutoRanging(true); + } + } diff --git a/src/main/java/fr/univlille/sae/classification/view/DataStageView.java b/src/main/java/fr/univlille/sae/classification/view/DataStageView.java index e6b91e88256d83795f0d88e89671c0f2b6ea1357..08b8d8bdc84c1938ab0d21d91346d6af50ee0f1c 100644 --- a/src/main/java/fr/univlille/sae/classification/view/DataStageView.java +++ b/src/main/java/fr/univlille/sae/classification/view/DataStageView.java @@ -111,6 +111,7 @@ public class DataStageView extends DataVisualizationView implements Observer { controller.setAxesSelected("Aucuns axes sélectionnés"); } else { controller.setAxesSelected(""); + controller.setAxesSelectedDisable(); List<LoadableData> points = new ArrayList<>(model.getDatas()); points.addAll(model.getDataToClass().keySet()); diff --git a/src/main/java/fr/univlille/sae/classification/view/MainStageView.java b/src/main/java/fr/univlille/sae/classification/view/MainStageView.java index 7b46907b8f81c23de9b35c61e3ecb5e39bc91896..6b80a19d8507e2fe55ad38f6452471ff8e2c7bed 100644 --- a/src/main/java/fr/univlille/sae/classification/view/MainStageView.java +++ b/src/main/java/fr/univlille/sae/classification/view/MainStageView.java @@ -111,6 +111,7 @@ public class MainStageView extends DataVisualizationView implements Observer { controller.setAxesSelected("Aucuns axes sélectionnés"); } else { controller.setAxesSelected(""); + controller.setAxesSelectedDisable(); List<LoadableData> points = new ArrayList<>(model.getDatas()); points.addAll(model.getDataToClass().keySet());