package ecoparasite.svg; import ecoparasite.representation.ValeursXY; import ecoparasite.svg.elements.Element; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; 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 mesElements){ String code = createSVGCode(mesElements); try { createFile(code); } catch (Exception e) { return false; } return true; } public static boolean createSVG(ArrayList mesElements, String filename) { String code = createSVGCode(mesElements); try { createFile(code,filename); } catch (Exception e) { return false; } return true; } public static String createSVGCode(ArrayList mesElements){ String code = ""; for (Element e : mesElements){ code += e.toSVG(); } code += ""; 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."); } public static HashMap< String ,HashSet> PointAXES(HashSet h){ //Définition initial HashSet x = new HashSet<>(); HashSet y = new HashSet<>(); HashSet offset = new HashSet<>(); HashMap< String, HashSet > 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; } }