Files
ecoparasite-data-analyse/src/ecoparasite/svg/SVGFactory.java

135 lines
3.2 KiB
Java
Raw Normal View History

2026-04-08 14:47:42 +02:00
package ecoparasite.svg;
2026-04-08 16:00:42 +02:00
import ecoparasite.representation.ValeursXY;
2026-04-08 14:47:42 +02:00
import ecoparasite.svg.elements.Element;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
2026-04-08 16:00:42 +02:00
import java.util.HashMap;
import java.util.HashSet;
2026-04-08 14:47:42 +02:00
import java.util.UUID;
public class SVGFactory {
static final private String EXPORT_PATH = "export/";
static final private String EXTENSION = ".svg";
public static boolean createSVG(ArrayList<Element> mesElements){
String code = createSVGCode(mesElements);
try {
createFile(code);
} catch (Exception e) {
return false;
}
return true;
}
public static boolean createSVG(ArrayList<Element> mesElements, String filename) {
String code = createSVGCode(mesElements);
try {
createFile(code,filename);
} catch (Exception e) {
return false;
}
return true;
}
public static String createSVGCode(ArrayList<Element> mesElements){
String code = "<svg height=\"800\" width=\"800\" >";
for (Element e : mesElements){
code += e.toSVG();
}
code += "</svg>";
return code;
}
public static void createFile(String data) throws IOException {
String id = UUID.randomUUID().toString();
createFile(data,id);
}
public static void createFile(String data, String filename) throws IOException {
// create a FileWriter object with the file name
FileWriter writer = new FileWriter(EXPORT_PATH + filename + EXTENSION);
// write the string to the file
writer.write(data);
// close the writer
writer.close();
System.out.println("Successfully wrote text to file.");
}
2026-04-08 16:00:42 +02:00
public static HashMap< String ,HashSet<ValeursXY>> PointAXES(HashSet<ValeursXY> h){
//Définition initial
HashSet<ValeursXY> x = new HashSet<>();
HashSet<ValeursXY> y = new HashSet<>();
HashSet<ValeursXY> offset = new HashSet<>();
HashMap< String, HashSet<ValeursXY> > map = new HashMap<>();
//Définition des min et max
double max_x = Double.MIN_VALUE;
double min_x = Double.MAX_VALUE;
double max_y = Double.MIN_VALUE;
double min_y = Double.MAX_VALUE;
//Trouvé les min et max
for (ValeursXY var : h) {
if (max_x < var.getX()){
max_x = var.getX();
} else if (min_x > var.getX()){
min_x = var.getX();
}
if (max_y < var.getY()){
max_y = var.getY();
} else if (min_y > var.getY()){
min_y = var.getY();
}
}
double step_x = (max_x - min_x); //TODO
double step_y = (max_y - min_y); //TODO
//TODO
return null;
}
/**
* retourne une valeur arrondi "joli" adapter à un graphique
* @param value
* @param step
* @return
*/
public static double roundMin(double value, double step) {
return Math.floor(value / step) * step;
}
public static double roundMax(double value, double step) {
return Math.ceil(value / step) * step;
}
2026-04-08 14:47:42 +02:00
}