-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
155 lines (126 loc) · 4.89 KB
/
Copy pathindex.js
File metadata and controls
155 lines (126 loc) · 4.89 KB
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
152
153
154
155
var data = [30, 86, 168, 281, 303, 365];
d3.select(".chart")
.selectAll("div")
.data(data)
.enter()
.append("div")
.style("width", function(d) { return d*2 + "px"; })
.text(function(d) { return d; });
//handleFiles("file://home/amandy/Repos/WebTeam_2019/Documentation_make/process_csv_in_JS/contribution_june_2019.csv");
//handleFiles(null);
var allText = [];
var allTextLines = [];
var Lines = [];
var listOfFiles = [];
var currentChoice;
loadListOfFiles();
document.getElementById("rand_txt").innerHTML = "List of files:";
console.log(typeof(allTextLines));
function loadListOfFiles() {
let txtFile = new XMLHttpRequest();
txtFile.open("GET", "https://localhost/d3_testA/list_of_files.txt", true);
txtFile.setRequestHeader('Access-Control-Allow-Headers', '*');
txtFile.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
listOfFiles = txtFile.responseText;
console.log("listOfFile is : " + typeof(listOfFiles));
allTextLines = listOfFiles.split(/\n/);
console.log("what " + allTextLines.length);
for(let i = 0; i < allTextLines.length; i++) {
console.log(i);
if(allTextLines[i] != "") {
/* tmp = document.createElement('div');
tmp.className = 'files_' + i;
tmp.onclick = function() {
current_choice = this.innerHTML;
console.log("current_choice = " + current_choice + " or " + this.innerHTML);
};
tmp.innerHTML = allTextLines[i];
//document.getElementById("list_file").innerHTML = allTextLines[i];
document.getElementById("list_file").appendChild(tmp);
*/ }
tmp = document.createElement('div');
item = document.createElement('choice');
item.onclick = function() {
current_choice = this.innerHTML;
console.log("current_choice = " + current_choice + " or " + this.innerHTML);
};
item.innerHTML = allTextLines[i];
tmp.appendChild(item);
document.getElementById("list_file").appendChild(tmp);
}
console.log(listOfFiles);
console.log(allTextLines);
}
};
//txtFile.open("GET", "file://home/amandy/Repos/WebTeam_2019/Documentation_make/process_csv_in_JS/contribution_june_2019.csv", true);
txtFile.send(null);
console.log("YO!");
}
function loadDoc() {
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "https://localhost/d3_testA/contributions_june_2019.csv", true);
txtFile.setRequestHeader('Access-Control-Allow-Headers', '*');
txtFile.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
allText = txtFile.responseText;
allTextLines = allText.split(/\r\n|\n/);
console.log(allText);
}
};
//txtFile.open("GET", "file://home/amandy/Repos/WebTeam_2019/Documentation_make/process_csv_in_JS/contribution_june_2019.csv", true);
txtFile.send(null);
console.log("YEP!");
};
function handleFiles(files) {
// Check for the various File API support.
if (window.FileReader) {
alert('FileReader supported in this browser.');
getAsText(files[0]);
// FileReader are supported.
} else {
alert('FileReader are not supported in this browser.');
}
}
function getAsText(fileToRead) {
let reader = new FileReader();
reader.fileName = "file://home/amandy/Repos/WebTeam_2019/Documentation_make/process_csv_in_JS/contribution_june_2019.csv";
reader.readAsText();
reader.onload = loadHandler;
reader.onerror = errorHandler;
}
function loadHandler(event) {
let csv = event.target.results;
processData(csv);
}
function processData(csv) {
let allTextLines = csv.split(/\r\n|\n/);
let lines = [];
for (let i = 0; i < allTextLines.length; i++) {
let data = allTextLines[i].split(';');
let tarr = [];
for (let j = 0; j < data.length; j++) {
tarr.push(data[j]);
}
lines.push(tarr);
}
console.log(lines)
}
function errorHandler(evt) {
if(evt.target.error.name == "NotReadableError") {
alert("Cannot Read File!!!");
}
}
//d3.select("h1").text("hello_world");
/*let canvas = d3.select("body")
.append("svg")
.style("width", 500)
.style("height", 500);
let bars = canvas.selectAll("div")
.data(data)
.enter()
.append("div")
.style("width", function(d) { return d + "px"; })
.attr("y", function (d, i) {i * 50})
.text(function(d) { return d; });
*/