Skip to content
Snippets Groups Projects
Commit bacc125b authored by Hugo Debuyser's avatar Hugo Debuyser
Browse files

Implémentation du zoom et du déplacement dans le scatterChart avec la souris

parent e88604e7
Branches
Tags
No related merge requests found
...@@ -4,6 +4,7 @@ import fr.univlille.sae.classification.model.ClassificationModel; ...@@ -4,6 +4,7 @@ import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.view.AxesSettingsView; import fr.univlille.sae.classification.view.AxesSettingsView;
import fr.univlille.sae.classification.view.DataStageView; import fr.univlille.sae.classification.view.DataStageView;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.ScatterChart; import javafx.scene.chart.ScatterChart;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
...@@ -32,6 +33,18 @@ public class DataStageController { ...@@ -32,6 +33,18 @@ public class DataStageController {
*/ */
private DataStageView dataStageView; 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 * Ouvrir les paramètres des axes de la vue
*/ */
...@@ -65,8 +78,89 @@ public class DataStageController { ...@@ -65,8 +78,89 @@ public class DataStageController {
this.AxesSelected.setText(texte); this.AxesSelected.setText(texte);
} }
public void setAxesSelectedDisable(){
this.AxesSelected.setDisable(true);
}
public ListView getPointInfo(){ public ListView getPointInfo(){
return this.PointInfo; 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);
}
} }
...@@ -37,6 +37,18 @@ public class MainStageController { ...@@ -37,6 +37,18 @@ public class MainStageController {
private MainStageView mainStageView; private MainStageView mainStageView;
private double initialX;
private double initialY;
private double initialLowerBoundX;
private double initialUpperBoundX;
private double initialLowerBoundY;
private double initialUpperBoundY;
public void initialize() {
setupZoom();
setupDrag();
}
/** /**
* Ouvre l'interface de chargement des données. * Ouvre l'interface de chargement des données.
* Permet à l'utilisateur de sélectionner des données à charger pour la classification. * Permet à l'utilisateur de sélectionner des données à charger pour la classification.
...@@ -111,6 +123,10 @@ public class MainStageController { ...@@ -111,6 +123,10 @@ public class MainStageController {
this.AxesSelected.setText(texte); this.AxesSelected.setText(texte);
} }
public void setAxesSelectedDisable(){
this.AxesSelected.setDisable(true);
}
/** /**
* Renvoie le bouton de classification de données. * Renvoie le bouton de classification de données.
* @return Bouton utilisé pour déclencher la classification des données. * @return Bouton utilisé pour déclencher la classification des données.
...@@ -123,7 +139,82 @@ public class MainStageController { ...@@ -123,7 +139,82 @@ public class MainStageController {
return this.PointInfo; return this.PointInfo;
}; };
public void setZoomIn(){ private void setupZoom() {
((NumberAxis)getScatterChart().getXAxis()).getUpperBound(); 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);
}
} }
...@@ -111,6 +111,7 @@ public class DataStageView extends DataVisualizationView implements Observer { ...@@ -111,6 +111,7 @@ public class DataStageView extends DataVisualizationView implements Observer {
controller.setAxesSelected("Aucuns axes sélectionnés"); controller.setAxesSelected("Aucuns axes sélectionnés");
} else { } else {
controller.setAxesSelected(""); controller.setAxesSelected("");
controller.setAxesSelectedDisable();
List<LoadableData> points = new ArrayList<>(model.getDatas()); List<LoadableData> points = new ArrayList<>(model.getDatas());
points.addAll(model.getDataToClass().keySet()); points.addAll(model.getDataToClass().keySet());
......
...@@ -111,6 +111,7 @@ public class MainStageView extends DataVisualizationView implements Observer { ...@@ -111,6 +111,7 @@ public class MainStageView extends DataVisualizationView implements Observer {
controller.setAxesSelected("Aucuns axes sélectionnés"); controller.setAxesSelected("Aucuns axes sélectionnés");
} else { } else {
controller.setAxesSelected(""); controller.setAxesSelected("");
controller.setAxesSelectedDisable();
List<LoadableData> points = new ArrayList<>(model.getDatas()); List<LoadableData> points = new ArrayList<>(model.getDatas());
points.addAll(model.getDataToClass().keySet()); points.addAll(model.getDataToClass().keySet());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment