2019-10-14 20:00:42 +02:00
|
|
|
let l_count = 0;
|
|
|
|
let lines = [];
|
2018-06-22 16:09:43 +02:00
|
|
|
console.log("started2");
|
2019-10-14 20:00:42 +02:00
|
|
|
|
|
|
|
function edge(start, end) {
|
|
|
|
this.id = l_count.toString() + "line";
|
|
|
|
l_count++;
|
|
|
|
this.start = start;
|
|
|
|
this.end = end;
|
|
|
|
console.log(start + end);
|
|
|
|
|
|
|
|
console.log(this.end);
|
|
|
|
console.log(this.start);
|
|
|
|
|
|
|
|
lines[lines.length] = this;
|
|
|
|
|
|
|
|
let g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
|
|
$(g).attr({
|
2018-06-22 16:09:43 +02:00
|
|
|
width: "100%",
|
|
|
|
height: "100%"
|
|
|
|
});
|
2019-10-14 20:00:42 +02:00
|
|
|
let el = $(document.createElementNS('http://www.w3.org/2000/svg', 'line')).attr({
|
2018-06-22 16:09:43 +02:00
|
|
|
x1: "50",
|
2019-10-14 20:00:42 +02:00
|
|
|
y1: "50",
|
|
|
|
x2: "55",
|
|
|
|
y2: "55",
|
2018-06-22 16:09:43 +02:00
|
|
|
id: this.id,
|
2019-10-14 20:00:42 +02:00
|
|
|
fill: "yellow",
|
|
|
|
stroke: "black"
|
2018-06-22 16:09:43 +02:00
|
|
|
});
|
2019-10-14 20:00:42 +02:00
|
|
|
$(el).attr("stroke-width", "2");
|
|
|
|
$(g).append(el);
|
|
|
|
let elem = document.getElementById("svg1");
|
2018-06-22 16:09:43 +02:00
|
|
|
elem.appendChild(g);
|
|
|
|
|
2019-10-14 20:00:42 +02:00
|
|
|
//console.log("succes"+lines);
|
2018-06-22 16:09:43 +02:00
|
|
|
|
2019-10-14 20:00:42 +02:00
|
|
|
this.rep = el;
|
|
|
|
this.name = "#" + this.id;
|
2018-06-22 16:09:43 +02:00
|
|
|
|
2019-10-14 20:00:42 +02:00
|
|
|
this.update = function() {
|
|
|
|
let adr = this.start.name;
|
|
|
|
let temp = $(adr).attr("x");
|
|
|
|
let n = this.name;
|
|
|
|
//console.log("updating"+adr+temp+n);
|
|
|
|
temp = (parseFloat(temp)).toString();
|
|
|
|
$(n).attr("x1", temp);
|
|
|
|
temp = $(adr).attr("y");
|
|
|
|
temp = (parseFloat(temp) + 10).toString();
|
|
|
|
$(n).attr("y1", temp);
|
|
|
|
adr = this.end.name;
|
|
|
|
temp = $(adr).attr("x");
|
|
|
|
temp = (parseFloat(temp) + 20).toString();
|
|
|
|
$(n).attr("x2", temp);
|
|
|
|
temp = $(adr).attr("y");
|
|
|
|
temp = (parseFloat(temp) + 10).toString();
|
|
|
|
$(n).attr("y2", temp);
|
2018-06-22 16:09:43 +02:00
|
|
|
|
2019-10-14 20:00:42 +02:00
|
|
|
//and the color based on the state
|
|
|
|
if (this.start.val) {
|
|
|
|
$((this.rep)).attr("stroke", "yellow");
|
|
|
|
} else {
|
|
|
|
$((this.rep)).attr("stroke", "black");
|
|
|
|
}
|
|
|
|
}
|
2018-06-22 16:09:43 +02:00
|
|
|
|
2019-10-14 20:00:42 +02:00
|
|
|
|
|
|
|
rem_edge(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function rem_edge(ob) {
|
|
|
|
$((ob.rep)).on("click touchstart", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
//removing the edge from the array
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
if (lines[i] == (ob.id)) {
|
|
|
|
lines.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//removing the visual
|
|
|
|
$((ob.rep)).remove();
|
|
|
|
|
|
|
|
//fixing the actual start and end pins
|
|
|
|
ob.start.nei = "yay";
|
|
|
|
ob.start.val = false;
|
|
|
|
ob.start.state = true;
|
|
|
|
ob.end.val = false;
|
|
|
|
ob.end.state = true;
|
|
|
|
});
|
|
|
|
}
|