Skip to content
Snippets Groups Projects
Commit 7c85d2a5 authored by Matias Mennecart's avatar Matias Mennecart
Browse files

Fix legend & change colors

parent a8c42238
Branches
No related tags found
No related merge requests found
...@@ -44,11 +44,11 @@ ...@@ -44,11 +44,11 @@
</Label> </Label>
<VBox layoutY="345.0" prefHeight="78.0" prefWidth="678.0"> <VBox layoutY="345.0" prefHeight="78.0" prefWidth="678.0">
<children> <children>
<HBox fx:id="legend" alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="10.0"> <VBox fx:id="legend" alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="10.0">
<padding> <padding>
<Insets left="2.0" right="2.0" /> <Insets left="2.0" right="2.0" />
</padding> </padding>
</HBox> </VBox>
</children></VBox> </children></VBox>
</children> </children>
<HBox.margin> <HBox.margin>
......
...@@ -8,6 +8,7 @@ import javafx.scene.chart.NumberAxis; ...@@ -8,6 +8,7 @@ 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.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
public abstract class DataVisualizationController { public abstract class DataVisualizationController {
...@@ -20,7 +21,7 @@ public abstract class DataVisualizationController { ...@@ -20,7 +21,7 @@ public abstract class DataVisualizationController {
Label AxesSelected; Label AxesSelected;
@FXML @FXML
HBox legend; VBox legend;
@FXML @FXML
...@@ -147,9 +148,9 @@ public abstract class DataVisualizationController { ...@@ -147,9 +148,9 @@ public abstract class DataVisualizationController {
public void loadLegend(HBox hbox) { public void loadLegend(VBox vBox) {
this.legend.getChildren().clear(); this.legend.getChildren().clear();
this.legend.getChildren().addAll(hbox.getChildren()); this.legend.getChildren().addAll(vBox.getChildren());
} }
......
...@@ -50,18 +50,40 @@ public abstract class LoadableData { ...@@ -50,18 +50,40 @@ public abstract class LoadableData {
public static void setClassificationTypes(Set<String> classificationTypes) { public static void setClassificationTypes(Set<String> classificationTypes) {
LoadableData.classificationTypes = classificationTypes; LoadableData.classificationTypes = classificationTypes;
LoadableData.classification.clear(); LoadableData.classification.clear();
int nbOfColors = classificationTypes.size() + 1;
int nb = 0; int nb = 0;
for(String s : classificationTypes) { for(String s : classificationTypes) {
// Génération de couleurs avec une plage évitant le blanc // Génération de couleurs avec une plage évitant le blanc
LoadableData.classification.put(s, getColor(nb++)); LoadableData.classification.put(s, getColor(nb++, nbOfColors));
}
LoadableData.classification.put("undefined", getColor(nb,nbOfColors));
} }
LoadableData.classification.put("undefined", getColor(nb));
private static Color getColor(int nb, int totalColors) {
// Ratio pour répartir les couleurs uniformément
double ratio = (double) nb / (double) totalColors;
// Utilisation de fonctions trigonométriques pour des transitions douces
double red = 0.5 + 0.4 * Math.sin(2 * Math.PI * ratio); // Oscille entre 0.1 et 0.9
double green = 0.5 + 0.4 * Math.sin(2 * Math.PI * ratio + Math.PI / 3); // Décalage de phase
double blue = 0.5 + 0.4 * Math.sin(2 * Math.PI * ratio + 2 * Math.PI / 3); // Décalage de phase
// Réduction de la luminosité pour éviter le blanc et gris clair
double maxComponent = Math.max(red, Math.max(green, blue));
if (maxComponent > 0.8) {
red *= 0.8 / maxComponent;
green *= 0.8 / maxComponent;
blue *= 0.8 / maxComponent;
} }
private static Color getColor(int i) { // Conversion en objet Color
return Color.color(red, green, blue);
}
/* private static Color getColor(int i) {
double ratio = (double) i / classificationTypes.size(); double ratio = (double) i / classificationTypes.size();
// Réduire les composantes pour éviter les tons clairs // Réduire les composantes pour éviter les tons clairs
...@@ -73,6 +95,8 @@ public abstract class LoadableData { ...@@ -73,6 +95,8 @@ public abstract class LoadableData {
} }
*/
/** /**
* Définit la classification de l'objet. * Définit la classification de l'objet.
* @param classification classification à définir. * @param classification classification à définir.
......
...@@ -4,12 +4,14 @@ import fr.univlille.sae.classification.controller.DataStageController; ...@@ -4,12 +4,14 @@ import fr.univlille.sae.classification.controller.DataStageController;
import fr.univlille.sae.classification.controller.MainStageController; import fr.univlille.sae.classification.controller.MainStageController;
import fr.univlille.sae.classification.model.ClassificationModel; import fr.univlille.sae.classification.model.ClassificationModel;
import fr.univlille.sae.classification.model.LoadableData; import fr.univlille.sae.classification.model.LoadableData;
import javafx.geometry.Pos;
import javafx.scene.chart.ScatterChart; import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import javafx.scene.control.ContextMenu; import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
...@@ -56,19 +58,46 @@ public class ViewUtil { ...@@ -56,19 +58,46 @@ public class ViewUtil {
} }
public static HBox loadLegend() { public static VBox loadLegend() {
//Color //Color
Map<String, Color> colors = new HashMap<>(Map.copyOf(LoadableData.getClassifications())); Map<String, Color> colors = new HashMap<>(Map.copyOf(LoadableData.getClassifications()));
Rectangle rectangle = new Rectangle(10, 10); Rectangle rectangle = new Rectangle(10, 10);
rectangle.setFill(colors.remove("undefined")); rectangle.setFill(colors.remove("undefined"));
Label label = new Label("undefined"); Label label = new Label("undefined");
HBox hbox = new HBox(); VBox legend = new VBox();
legend.setAlignment(Pos.CENTER);
HBox line = new HBox();
line.setSpacing(10);
line.setAlignment(Pos.CENTER);
HBox tempHBox = new HBox(); HBox tempHBox = new HBox();
tempHBox.getChildren().addAll(rectangle, label); tempHBox.getChildren().addAll(rectangle, label);
hbox.getChildren().add(tempHBox); line.getChildren().add(tempHBox);
String[] colorsString = colors.keySet().toArray(new String[0]);
for(int i = 0 ; i < colorsString.length ; i+= 7) {
for(int j = 0 ; i+j < colorsString.length && j < i+7 ; j++) {
if(j%7 == 0 && i != 0 ) {
legend.getChildren().add(line);
line = new HBox();
line.setSpacing(10);
line.setAlignment(Pos.CENTER);
}
tempHBox = new HBox();
label = new Label(colorsString[i+j]);
rectangle = new Rectangle(10, 10);
rectangle.setFill(colors.get(colorsString[i+j]));
tempHBox.getChildren().addAll(rectangle, label);
line.getChildren().add(tempHBox);
}
}
if(colorsString.length < 7) legend.getChildren().add(line);
/**
for(String s : colors.keySet()) { for(String s : colors.keySet()) {
Circle c = new Circle(5); Circle c = new Circle(5);
c.setFill(colors.get(s)); c.setFill(colors.get(s));
...@@ -78,8 +107,9 @@ public class ViewUtil { ...@@ -78,8 +107,9 @@ public class ViewUtil {
hbox.getChildren().add(tempHBox); hbox.getChildren().add(tempHBox);
} }
*/
return hbox; return legend;
} }
} }
...@@ -14,6 +14,7 @@ import javafx.scene.Node; ...@@ -14,6 +14,7 @@ import javafx.scene.Node;
import javafx.scene.chart.ScatterChart; import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle; import javafx.scene.shape.Rectangle;
import javafx.stage.Stage; import javafx.stage.Stage;
...@@ -155,8 +156,8 @@ public class DataStageView extends DataVisualizationView implements Observer { ...@@ -155,8 +156,8 @@ public class DataStageView extends DataVisualizationView implements Observer {
} }
scatterChart.getData().addAll(serieList.values()); scatterChart.getData().addAll(serieList.values());
HBox hBox = ViewUtil.loadLegend(); VBox vBox = ViewUtil.loadLegend();
controller.loadLegend(hBox); controller.loadLegend(vBox);
} }
} catch (Exception e) { } catch (Exception e) {
System.err.println("Erreur de mise à jour : " + e.getMessage()); System.err.println("Erreur de mise à jour : " + e.getMessage());
...@@ -199,8 +200,8 @@ public class DataStageView extends DataVisualizationView implements Observer { ...@@ -199,8 +200,8 @@ public class DataStageView extends DataVisualizationView implements Observer {
series4.setName("indéfini"); series4.setName("indéfini");
scatterChart.getData().add(series4); scatterChart.getData().add(series4);
} }
HBox hBox = ViewUtil.loadLegend(); VBox vBox = ViewUtil.loadLegend();
controller.loadLegend(hBox); controller.loadLegend(vBox);
} catch (Exception e) { } catch (Exception e) {
System.err.println("Erreur de mise à jour : " + e.getMessage()); System.err.println("Erreur de mise à jour : " + e.getMessage());
} }
......
...@@ -13,6 +13,7 @@ import javafx.scene.chart.ScatterChart; ...@@ -13,6 +13,7 @@ import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.shape.*; import javafx.scene.shape.*;
import javafx.stage.Stage; import javafx.stage.Stage;
...@@ -169,8 +170,8 @@ public class MainStageView extends DataVisualizationView implements Observer { ...@@ -169,8 +170,8 @@ public class MainStageView extends DataVisualizationView implements Observer {
scatterChart.getData().addAll(serieList.values()); scatterChart.getData().addAll(serieList.values());
HBox hBox = ViewUtil.loadLegend(); VBox vBox = ViewUtil.loadLegend();
controller.loadLegend(hBox); controller.loadLegend(vBox);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment