-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.html
151 lines (125 loc) · 3.76 KB
/
backup.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<script>
/*
* always try to put branches as far away from each other as possible
* up to 8 branches to reflect 3 x 3 grid around a position
*/
function draw_arrow(parent_node, child_node){
if(parent_node !== null){
new LeaderLine(
/*
document.getElementById(parent_node),
document.getElementById(row.location),
*/
document.getElementById(parent_node),
document.getElementById(child_node),
{
color: "red",
size: 2,
startSocket: "auto",
endSocket: "top",
path: "straight",
startPlug: 'behind',
endPlug: 'arrow1'
}
);
}
}
function draw_button(row, parent_node, branch_index){
var top_pixels = 0;
var left_pixels = branch_index * 100;
if(parent_node !== null){
var parent_node_top = $("#" + parent_node).css("top").replace("px","");
var parent_node_left = $("#" + parent_node).css("left").replace("px","");
parent_node_top = parseFloat(parent_node_top);
parent_node_left = parseFloat(parent_node_left);
top_pixels = parent_node_top + 100;
left_pixels = left_pixels + parent_node_left;
console.log("left_pixels");
console.log(left_pixels);
}
var this_button = $("<button>");
this_button.html(row.text)
.addClass("btn")
.addClass("btn-primary")
.addClass("flow-node")
.css("position", "absolute")
.css("top", top_pixels + "px")
.css("left", left_pixels + "px")
.css("display", "none")
.prop("id",row.location);
return this_button;
}
function add_button(this_button, row){
$("#map").append(this_button[0].outerHTML);
$("#" + row.location).fadeIn(500);
if(row.branches == ""){
// do nothing
} else {
var branches = row.branches.split(",");
branches.forEach(function(branch, branch_index){
console.log(this_button[0].outerHTML);
console.log("branch_index");
console.log(branch_index);
var this_row = csv_data.filter(csv_row => csv_row.location == branch)[0];
setTimeout(function(){
draw_node([this_row, row_no+1, row.location, branch_index/branches.length]);
},200);
//rows_to_process.push();
});
}
}
function draw_node(this_row){
console.log("this_row");
console.log(this_row);
[row, row_no, parent_node, branch_index] = this_row;
/*
* move everything down if branch_index == 0
*/
if(branch_index == 0){
$(".flow-node").animate({
left: "+=100",
top: "+=100"
},function(){
this_button = draw_button(row, parent_node, branch_index);
add_button(this_button, row);
})
} else {
this_button = draw_button(row, parent_node, branch_index);
add_button(this_button, row)
}
}
var csv_data;
$.get("flowdata.csv", function(data){
csv_data = Papa.parse(data, {
header: true }
).data;
console.log(csv_data);
var this_row = [
csv_data[0], // first row
0, // row_no
null, // location
1 // branch_index/branches.length
];
draw_node(this_row);
/*
//console.log(csv_data);
csv_data.forEach(function(row){
/*
var flow_row = flow_map.findIndex(flow_row => flow_row.indexOf(row.location) !== -1);
if(typeof(flow_map[flow_row + 1]) == "undefined"){
flow_map[flow_row + 1] = [];
}
*/
//});
});
/*
* draw button
var button_html = $("<button>");
button_html.addClass("btn btn-primary")
.html(row.text);
$("#map").html($("#map").html() + button_html[0].outerHTML);
/*
* draw lines
var branches = row.branches.split(",");
*/
</script>