-
Notifications
You must be signed in to change notification settings - Fork 8
/
Etape.js
63 lines (60 loc) · 2.5 KB
/
Etape.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {minX,maxX,fleche,m,tracer} from "./Graphique.js"
import {graphe,Etat} from "./Etat.js";
const eq = (v1,v2) => Math.abs(v1-v2)<10 ; // à peu près égal...
export class Etape extends Etat{
constructor(nom, x, y, struct,suivant, nextPath) {
super(nom, x, y, struct);
this.suivant = suivant;
this.nextPath = nextPath;
}
realiser() {
if (this.struct === undefined)
return this.nom;
return this.struct() + "";
}
toString() {
return `Etape(${this.nom},${this.suivant})`;
}
getSuivant() { return graphe[this.suivant]; }
lier() {
if (this.nom == "Réfléchissez au prochain problème" ||
this.nom == " ATTENDEZ SIX MOIS " ||
this.suivant === undefined)
return;
const depart = this;
const arrivee = graphe[this.suivant];
let dx = depart.bbox.x, ax = arrivee.bbox.x;
let dy = depart.bbox.y, ay = arrivee.bbox.y;
if (depart.nextPath === undefined) {
if (eq(dy, ay)) { // flèche horizontale
if (dx < ax) { // d -> a vers la droite
this.suivant_path = tracer(depart.bbox, arrivee.bbox, "d");
} else { // a <- d vers la gauche
this.suivant_path = tracer(depart.bbox, arrivee.bbox, "g");
}
} else if (eq(dx, ax)) { // flèche verticale
if (dy < ay) { // flèche en bas
this.suivant_path = tracer(depart.bbox, arrivee.bbox, "b");
} else { // fleche en haut
this.suivant_path = tracer(depart.bbox, arrivee.bbox, "h");
}
} else { // faire une flèche par les côtés
const deltaMinX = Math.abs(dx - minX);
const deltaMaxX = Math.abs(dx + depart.bbox.width - maxX);
if (deltaMinX < deltaMaxX) { // vers le minX
this.suivant_path = tracer(depart.bbox, undefined, "g");
} else { // vers le maxX
this.suivant_path = tracer(depart.bbox, undefined, "d");
}
}
} else {
this.suivant_path = fleche(m(dx + depart.bbox.width / 2, dy + depart.bbox.height) + " " + depart.nextPath);
}
}
selectionner(oui, select) {
super.selectionner(select);
if (this.suivant_path !== undefined)
this.suivant_path.classed("selected", select)
.attr("marker-end", "url(#blue-arrow)");
}
}