Compare commits
2 Commits
8ac87e9edb
...
96cdac60eb
| Author | SHA1 | Date | |
|---|---|---|---|
| 96cdac60eb | |||
| 82901f623b |
@@ -9,12 +9,20 @@ import ecoparasite.nettoyage.Nettoyage;
|
|||||||
import ecoparasite.poisson.MackerelSerra;
|
import ecoparasite.poisson.MackerelSerra;
|
||||||
import ecoparasite.poisson.Poisson;
|
import ecoparasite.poisson.Poisson;
|
||||||
import ecoparasite.representation.ValeursXY;
|
import ecoparasite.representation.ValeursXY;
|
||||||
|
import ecoparasite.svg.IncorrectAxesPointsException;
|
||||||
|
import ecoparasite.svg.SVGAxes;
|
||||||
|
import ecoparasite.svg.SVGFactory;
|
||||||
|
import ecoparasite.svg.SVGResizing;
|
||||||
|
import ecoparasite.svg.elements.Element;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
public static void main(String[] args) throws InputFileException, RawDataOverflow {
|
public static void main(String[] args) throws InputFileException, RawDataOverflow {
|
||||||
|
|
||||||
RawData rawMackerel = InputFactory.readData("test2.csv", ",");
|
RawData rawMackerel = InputFactory.readData("test2.csv", ",");
|
||||||
@@ -31,6 +39,19 @@ public class Application {
|
|||||||
mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
|
mackerelSet = Completion.completeColumnsLinear( mackerelSet, getLength, getInfes, setInfes );
|
||||||
|
|
||||||
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
|
HashSet<ValeursXY> mackerelXY = ValeursXY.convertToXY( mackerelSet, getLength, getInfes );
|
||||||
|
HashMap<String, ArrayList<Double>> axes = SVGFactory.PointAXES( mackerelXY );
|
||||||
|
System.out.println( axes );
|
||||||
|
|
||||||
|
SVGAxes axesInstance;
|
||||||
|
try {
|
||||||
|
axesInstance = new SVGAxes(axes);
|
||||||
|
} catch (IncorrectAxesPointsException e) {
|
||||||
|
System.out.println( "Mauvais format communiqué" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Element> SVGElements = axesInstance.buildAll( "Length", "Infestation" );
|
||||||
|
SVGFactory.createSVG( SVGElements );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4
src/ecoparasite/svg/IncorrectAxesPointsException.java
Normal file
4
src/ecoparasite/svg/IncorrectAxesPointsException.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
public class IncorrectAxesPointsException extends Exception{
|
||||||
|
}
|
||||||
181
src/ecoparasite/svg/SVGAxes.java
Normal file
181
src/ecoparasite/svg/SVGAxes.java
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
import ecoparasite.svg.elements.Element;
|
||||||
|
import ecoparasite.svg.elements.ElementsFactory;
|
||||||
|
import ecoparasite.svg.elements.Line;
|
||||||
|
import ecoparasite.svg.elements.Text;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class SVGAxes {
|
||||||
|
|
||||||
|
final int SIZE_TICK_TEXT = ElementsFactory.AXES_TEXT_SIZE - 3;
|
||||||
|
|
||||||
|
private ArrayList<Double> pointsX;
|
||||||
|
private ArrayList<Double> pointsY;
|
||||||
|
private Double offsetX;
|
||||||
|
private Double offsetY;
|
||||||
|
private SVGResizing resizer;
|
||||||
|
|
||||||
|
private Double minPointsX;
|
||||||
|
private Double minPointsY;
|
||||||
|
private Double maxPointsX;
|
||||||
|
private Double maxPointsY;
|
||||||
|
|
||||||
|
public SVGAxes( HashMap<String, ArrayList<Double>> axesPoints ) throws IncorrectAxesPointsException {
|
||||||
|
|
||||||
|
if( axesPoints.get("AxeX") == null || axesPoints.get("AxeY") == null || axesPoints.get("OffsetX") == null || axesPoints.get("OffsetY") == null ){
|
||||||
|
throw new IncorrectAxesPointsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pointsX = axesPoints.get("AxeX");
|
||||||
|
this.pointsY = axesPoints.get("AxeY");
|
||||||
|
this.offsetX = axesPoints.get("OffsetX").getFirst();
|
||||||
|
this.offsetY = axesPoints.get("OffsetY").getFirst();
|
||||||
|
|
||||||
|
this.minPointsX = this.pointsX.getFirst();
|
||||||
|
this.minPointsY = this.pointsY.getFirst();
|
||||||
|
this.maxPointsX = this.pointsX.getLast();
|
||||||
|
this.maxPointsY = this.pointsY.getLast();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Double> getPointsX() {
|
||||||
|
return pointsX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Double> getPointsY() {
|
||||||
|
return pointsY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getOffsetX() {
|
||||||
|
return offsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getOffsetY() {
|
||||||
|
return offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SVGResizing getResizer() {
|
||||||
|
if( this.resizer == null ){
|
||||||
|
this.resizer = new SVGResizing( this.minPointsX, this.minPointsY, this.maxPointsX, this.maxPointsY );
|
||||||
|
}
|
||||||
|
return resizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResizer(SVGResizing resizer) {
|
||||||
|
this.resizer = resizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildAll(String XLabel, String YLabel){
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
elements.addAll(buildAxes(XLabel, YLabel));
|
||||||
|
elements.addAll(buildXTicks());
|
||||||
|
elements.addAll(buildYTicks());
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildAxes(String XLabel, String YLabel){
|
||||||
|
|
||||||
|
final int OFFSET_TEXT_AXISX_X = -20;
|
||||||
|
final int OFFSET_TEXT_AXISX_Y = -10;
|
||||||
|
final int OFFSET_TEXT_AXISY_X = +5;
|
||||||
|
final int OFFSET_TEXT_AXISY_Y = +10;
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
double beginAxeX = getBeginAxeX();
|
||||||
|
double beginAxeY = getBeginAxeY();
|
||||||
|
|
||||||
|
Coordonnees bottom = getResizer().resize( beginAxeX, minPointsY );
|
||||||
|
Coordonnees top = getResizer().resize( beginAxeX, maxPointsY );
|
||||||
|
Coordonnees left = getResizer().resize( minPointsX, beginAxeY );
|
||||||
|
Coordonnees right = getResizer().resize( maxPointsX, beginAxeY );
|
||||||
|
|
||||||
|
// Axes
|
||||||
|
elements.add( new Line( bottom, top, ElementsFactory.COLOR_BLACK, 2 ) );
|
||||||
|
elements.add( new Line( left, right, ElementsFactory.COLOR_BLACK, 2 ) );
|
||||||
|
|
||||||
|
// Labels.
|
||||||
|
elements.add( new Text(
|
||||||
|
new Coordonnees( right.getX() + OFFSET_TEXT_AXISX_X, right.getY() + OFFSET_TEXT_AXISX_Y ),
|
||||||
|
XLabel, ElementsFactory.COLOR_BLACK, ElementsFactory.AXES_TEXT_SIZE
|
||||||
|
) );
|
||||||
|
elements.add( new Text(
|
||||||
|
new Coordonnees( top.getX() + OFFSET_TEXT_AXISY_X, top.getY() + OFFSET_TEXT_AXISY_Y ),
|
||||||
|
YLabel, ElementsFactory.COLOR_BLACK, ElementsFactory.AXES_TEXT_SIZE
|
||||||
|
));
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildXTicks(){
|
||||||
|
|
||||||
|
final int OFFSET_TICK = -5;
|
||||||
|
final int OFFSET_TEXT_X = -10;
|
||||||
|
final int OFFSET_TEXT_Y = +15;
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
double beginAxeY = getBeginAxeY();
|
||||||
|
for( Double X : this.pointsX ){
|
||||||
|
Coordonnees coords = getResizer().resize( X, beginAxeY );
|
||||||
|
|
||||||
|
elements.add(new Line(
|
||||||
|
coords,
|
||||||
|
new Coordonnees( coords.getX(), coords.getY() + OFFSET_TICK ),
|
||||||
|
ElementsFactory.COLOR_BLACK, 1
|
||||||
|
));
|
||||||
|
elements.add(new Text(
|
||||||
|
new Coordonnees( coords.getX() + OFFSET_TEXT_X, coords.getY() + OFFSET_TEXT_Y ),
|
||||||
|
X.toString(),
|
||||||
|
ElementsFactory.COLOR_BLACK,
|
||||||
|
SIZE_TICK_TEXT
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Element> buildYTicks(){
|
||||||
|
|
||||||
|
final int OFFSET_TICK = +5;
|
||||||
|
final int OFFSET_TEXT_X = -35;
|
||||||
|
final int OFFSET_TEXT_Y = +5;
|
||||||
|
|
||||||
|
ArrayList<Element> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
double beginAxeX = getBeginAxeX();
|
||||||
|
for( Double Y : this.pointsY ){
|
||||||
|
Coordonnees coords = getResizer().resize( beginAxeX, Y );
|
||||||
|
|
||||||
|
elements.add(new Line(
|
||||||
|
new Coordonnees(coords.getX() + OFFSET_TICK, coords.getY() ),
|
||||||
|
coords,
|
||||||
|
ElementsFactory.COLOR_BLACK, 1
|
||||||
|
));
|
||||||
|
elements.add(new Text(
|
||||||
|
new Coordonnees( coords.getX() + OFFSET_TEXT_X, coords.getY() + OFFSET_TEXT_Y ),
|
||||||
|
Y.toString(),
|
||||||
|
ElementsFactory.COLOR_BLACK,
|
||||||
|
SIZE_TICK_TEXT
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getBeginAxeX(){
|
||||||
|
return ( minPointsX > 0 ) ? minPointsX : ( maxPointsX < 0 ? maxPointsX : 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getBeginAxeY(){
|
||||||
|
return ( minPointsY > 0 ) ? minPointsY : ( maxPointsY < 0 ? maxPointsY : 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -112,9 +112,9 @@ public class SVGFactory {
|
|||||||
* Avec la String "OffsetX", un Hashset de Double contenant uniquement la valeur de l'offset des points par rapport à l'axe X
|
* Avec la String "OffsetX", un Hashset de Double contenant uniquement la valeur de l'offset des points par rapport à l'axe X
|
||||||
* Avec la String "OffsetY", un Hashset de Double contenant uniquement la valeur de l'offset des points par rapport à l'axe Y
|
* Avec la String "OffsetY", un Hashset de Double contenant uniquement la valeur de l'offset des points par rapport à l'axe Y
|
||||||
*/
|
*/
|
||||||
public static HashMap< String ,HashSet<Double>> PointAXES(HashSet<ValeursXY> h){
|
public static HashMap< String ,ArrayList<Double>> PointAXES(HashSet<ValeursXY> h){
|
||||||
|
|
||||||
HashMap< String, HashSet<Double> > map = new HashMap<>();
|
HashMap< String, ArrayList<Double> > map = new HashMap<>();
|
||||||
|
|
||||||
//Définition des min et max
|
//Définition des min et max
|
||||||
double max_x = Double.MIN_VALUE;
|
double max_x = Double.MIN_VALUE;
|
||||||
@@ -127,13 +127,15 @@ public class SVGFactory {
|
|||||||
|
|
||||||
if (max_x < var.getX()){
|
if (max_x < var.getX()){
|
||||||
max_x = var.getX();
|
max_x = var.getX();
|
||||||
} else if (min_x > var.getX()){
|
}
|
||||||
|
if (min_x > var.getX()){
|
||||||
min_x = var.getX();
|
min_x = var.getX();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_y < var.getY()){
|
if (max_y < var.getY()){
|
||||||
max_y = var.getY();
|
max_y = var.getY();
|
||||||
} else if (min_y > var.getY()){
|
}
|
||||||
|
if (min_y > var.getY()){
|
||||||
min_y = var.getY();
|
min_y = var.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,10 +155,10 @@ public class SVGFactory {
|
|||||||
double nicemax_y = roundMax(max_y,step_y);
|
double nicemax_y = roundMax(max_y,step_y);
|
||||||
|
|
||||||
// Compléter un Hashset de Double pour X et pour Y et Offset X et Y. TODO
|
// Compléter un Hashset de Double pour X et pour Y et Offset X et Y. TODO
|
||||||
HashSet<Double> axeX = new HashSet<>();
|
ArrayList<Double> axeX = new ArrayList<>();
|
||||||
HashSet<Double> axeY = new HashSet<>();
|
ArrayList<Double> axeY = new ArrayList<>();
|
||||||
HashSet<Double> OffsetX = new HashSet<>();
|
ArrayList<Double> OffsetX = new ArrayList<>();
|
||||||
HashSet<Double> OffsetY = new HashSet<>();
|
ArrayList<Double> OffsetY = new ArrayList<>();
|
||||||
|
|
||||||
Double ix = nicemin_x;
|
Double ix = nicemin_x;
|
||||||
while ( ix <= nicemax_x ) {
|
while ( ix <= nicemax_x ) {
|
||||||
@@ -175,9 +177,9 @@ public class SVGFactory {
|
|||||||
double offsetX = min_x - nicemin_x;
|
double offsetX = min_x - nicemin_x;
|
||||||
double offsetY = min_y - nicemin_y;
|
double offsetY = min_y - nicemin_y;
|
||||||
|
|
||||||
HashSet<Double> offsetXHash = new HashSet<>();
|
ArrayList<Double> offsetXHash = new ArrayList<>();
|
||||||
offsetXHash.add(offsetX);
|
offsetXHash.add(offsetX);
|
||||||
HashSet<Double> offsetYHash = new HashSet<>();
|
ArrayList<Double> offsetYHash = new ArrayList<>();
|
||||||
offsetYHash.add(offsetY);
|
offsetYHash.add(offsetY);
|
||||||
|
|
||||||
map.put("OffsetX", offsetXHash);
|
map.put("OffsetX", offsetXHash);
|
||||||
|
|||||||
57
src/ecoparasite/svg/SVGResizing.java
Normal file
57
src/ecoparasite/svg/SVGResizing.java
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package ecoparasite.svg;
|
||||||
|
|
||||||
|
import ecoparasite.representation.ValeursXY;
|
||||||
|
import ecoparasite.svg.elements.ElementsFactory;
|
||||||
|
|
||||||
|
public class SVGResizing {
|
||||||
|
|
||||||
|
private double minX;
|
||||||
|
private double maxX;
|
||||||
|
private double minY;
|
||||||
|
private double maxY;
|
||||||
|
|
||||||
|
public SVGResizing(
|
||||||
|
double minXGrad,
|
||||||
|
double minYGrad,
|
||||||
|
double maxXGrad,
|
||||||
|
double maxYGrad
|
||||||
|
){
|
||||||
|
this.minX = minXGrad;
|
||||||
|
this.maxX = maxXGrad;
|
||||||
|
this.minY = minYGrad;
|
||||||
|
this.maxY = maxYGrad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinX() {
|
||||||
|
return minX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxX() {
|
||||||
|
return maxX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinY() {
|
||||||
|
return minY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaxY() {
|
||||||
|
return maxY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordonnees resize(ValeursXY vxy ){
|
||||||
|
return this.resize( vxy.getX(), vxy.getY() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordonnees resize( double X, double Y ){
|
||||||
|
double surface = ElementsFactory.SVG_SIZE - 2 * ElementsFactory.SVG_OFFSET;
|
||||||
|
|
||||||
|
double convX = ( X - minX ) / ( maxX - minX );
|
||||||
|
double convY = ( Y - minY ) / ( maxY - minY );
|
||||||
|
|
||||||
|
double SVG_X = ElementsFactory.SVG_OFFSET + convX * surface;
|
||||||
|
double SVG_Y = ElementsFactory.SVG_SIZE - ElementsFactory.SVG_OFFSET - convY * surface;
|
||||||
|
|
||||||
|
return new Coordonnees(SVG_X, SVG_Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,10 +16,7 @@ public class ElementsFactory {
|
|||||||
final public static String COLOR_BLUE = "blue";
|
final public static String COLOR_BLUE = "blue";
|
||||||
final public static String COLOR_BLACK = "black";
|
final public static String COLOR_BLACK = "black";
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Permet de générer les éléments axes du fichier SVG.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static ArrayList<Element> SVGAxes(String HName, String VName ){
|
public static ArrayList<Element> SVGAxes(String HName, String VName ){
|
||||||
|
|
||||||
final int begin = SVG_OFFSET + AXES_TEXT_SIZE + (AXES_TEXT_SIZE / 2);
|
final int begin = SVG_OFFSET + AXES_TEXT_SIZE + (AXES_TEXT_SIZE / 2);
|
||||||
@@ -65,4 +62,5 @@ public class ElementsFactory {
|
|||||||
return SVGAxes( "None", "None" );
|
return SVGAxes( "None", "None" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,8 @@ package ecoparasite.svg.elements;
|
|||||||
|
|
||||||
import ecoparasite.svg.Coordonnees;
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class Line extends Element {
|
public class Line extends Element {
|
||||||
|
|
||||||
private Coordonnees coordonneesB;
|
private Coordonnees coordonneesB;
|
||||||
@@ -59,7 +61,7 @@ public class Line extends Element {
|
|||||||
StringBuilder svg = new StringBuilder();
|
StringBuilder svg = new StringBuilder();
|
||||||
svg.append("<line ");
|
svg.append("<line ");
|
||||||
|
|
||||||
String params = String.format( "x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"stroke:%s;stroke-width:%d\"",
|
String params = String.format( Locale.US,"x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:%s;stroke-width:%d\"",
|
||||||
this.coordonnees.getX(),
|
this.coordonnees.getX(),
|
||||||
this.coordonnees.getY(),
|
this.coordonnees.getY(),
|
||||||
this.coordonneesB.getX(),
|
this.coordonneesB.getX(),
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package ecoparasite.svg.elements;
|
|||||||
|
|
||||||
import ecoparasite.svg.Coordonnees;
|
import ecoparasite.svg.Coordonnees;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class Text extends Element {
|
public class Text extends Element {
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
@@ -51,7 +53,7 @@ public class Text extends Element {
|
|||||||
StringBuilder svg = new StringBuilder();
|
StringBuilder svg = new StringBuilder();
|
||||||
svg.append("<text ");
|
svg.append("<text ");
|
||||||
|
|
||||||
String params = String.format( "x=\"%d\" y=\"%d\" fill=\"%s\" font-size=\"%s\"", coordonnees.getX(), coordonnees.getY(), color, size);
|
String params = String.format(Locale.US,"x=\"%f\" y=\"%f\" fill=\"%s\" font-size=\"%s\"", coordonnees.getX(), coordonnees.getY(), color, size);
|
||||||
svg.append(params);
|
svg.append(params);
|
||||||
svg.append(" >");
|
svg.append(" >");
|
||||||
svg.append( this.text );
|
svg.append( this.text );
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class SVGFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateSVGAxes(){
|
public void generateSVGAxes(){
|
||||||
SVGFactory.createSVG( ElementsFactory.SVGAxes() );
|
// SVGFactory.createSVG( ElementsFactory.SVGAxes() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user