Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use one drop location for all files #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion coloring/coloring.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,14 @@ function findMinMaxCoords (nodes) {

}

function isBenchmark(text){
return text.replace(/^\s+|\s+$/g, '').split(REGEX_NEWLINE).length > 2
}

function loadBenchmark(text){
parseInputText(text);
}

function loadSolution(text){
parseSolutionText(text);
}
}
7 changes: 3 additions & 4 deletions coloring/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
</head>
<body>
<div id="controls">
<div id="benchmark_zone" class="drop_zone" style="float:left; width:45%">Step 1 - Drop benchmark file here</div>
<div id="solution_zone" class="drop_zone" style="float:right; width:45%">Step 2 - Drop solution file here</div>
<div style="clear:both;"><p id="feedback"></p></div>
<div id="drop_zone" class="drop_zone">Drop benchmark and solution files here</div>
<div><p id="feedback"></p></div>
</div>

<div id="data">
Expand All @@ -52,4 +51,4 @@
<script type="text/javascript" src="../viz.js"></script>

</body>
</html>
</html>
8 changes: 6 additions & 2 deletions facility/facility.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ function vizSolution() {
}

}


function isBenchmark(text){
return text.replace(/^\s+|\s+$/g, '').split(REGEX_NEWLINE).length > 2
}

function loadBenchmark(text){
if (parseInputText(text));
vizBenchmark();
Expand Down Expand Up @@ -454,4 +458,4 @@ function checkValidity() {
reportError(errors.join(" "));
return true;
}


7 changes: 3 additions & 4 deletions facility/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
<body>

<div id="controls">
<div id="benchmark_zone" class="drop_zone">Step 1 - Drop benchmark file here</div>
<div id="solution_zone" class="drop_zone">Step 2 - Drop solution file here</div>
<div style="clear:both;"><p id="feedback"></p></div>
<div id="drop_zone" class="drop_zone">Drop benchmark and solution files here</div>
<div><p id="feedback"></p></div>
</div>

<div id="data">
Expand All @@ -38,4 +37,4 @@
<script type="text/javascript" src="../viz.js"></script>

</body>
</html>
</html>
7 changes: 3 additions & 4 deletions tsp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
</head>
<body>
<div id="controls">
<div id="benchmark_zone" class="drop_zone" style="float:left; width:45%">Step 1 - Drop benchmark file here</div>
<div id="solution_zone" class="drop_zone" style="float:right; width:45%">Step 2 - Drop solution file here</div>
<div style="clear:both;"><p id="feedback"></p></div>
<div id="drop_zone" class="drop_zone">Drop benchmark and solution files here</div>
<div><p id="feedback"></p></div>
</div>

<div id="data">
Expand All @@ -36,4 +35,4 @@
<script type="text/javascript" src="../viz.js"></script>

</body>
</html>
</html>
4 changes: 4 additions & 0 deletions tsp/tsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ function vizSolution(solution){

}

function isBenchmark(text){
return text.replace(/^\s+|\s+$/g, '').split(REGEX_NEWLINE).length > 2
}

function loadBenchmark(text){
console.log("loading data");
console.log(text);
Expand Down
2 changes: 0 additions & 2 deletions viz.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ SOFTWARE.
text-align:center;
font:20pt bold,"Vollkorn";
color:#bbb;
float: left;
width: 45%;
}

#viz {
Expand Down
120 changes: 48 additions & 72 deletions viz.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,62 +64,43 @@ function handleDragEnd(e) {
});
}


function getFile(e) {
var files = e.dataTransfer.files;
if(files.length <= 0){
reportError("please drop a file")
return null;
}
if(files.length > 1){
reportError("please drop only one file")
return null;
}
return files[0]
}

function readFileAndLoad(file, loader) {
function readFilesAndLoad(files, loader) {
if (!window.FileReader) {
reportError('your browser does not have the necessary file reader API.');
return;
}

var reader = new FileReader();

reader.onload = function(e) {
//document.getElementById('debug').innerHTML = e.target.result;
loader(e.target.result)
}
var left = files.length
var texts = []

reader.onerror = function(e) {
console.log(e.target);
}
for (var i = 0; i < files.length; i++) {
var reader = new FileReader();

reader.readAsText(file);
}
reader.onload = function(e) {
//document.getElementById('debug').innerHTML = e.target.result;
texts.push(e.target.result)
if (--left == 0) loader(texts)
}

function handleDropBenchmark(e) {
// this / e.target is current target element.
e.stopPropagation(); // stops the browser from redirecting.
e.preventDefault();

var cols = document.querySelectorAll('.drop_zone');
[].forEach.call(cols, function (col) {
col.classList.remove('over');
});

// See the section on the DataTransfer object.
file = getFile(e)
if(file == null){
return false;
reader.onerror = function(e) {
console.log(e.target);
if (--left == 0) loader(texts)
}

reader.readAsText(files[i]);
}
}

//document.getElementById('debug').innerHTML = file;
readFileAndLoad(file, loadBenchmark);
return false;
function loadTexts(texts){
for (var i = 0; i < texts.length; i++) {
if (isBenchmark(texts[i])) loadBenchmark(texts[i])
}
for (var i = 0; i < texts.length; i++) {
if (!isBenchmark(texts[i])) loadSolution(texts[i])
}
}

function handleDropSolution(e) {
function handleDrop(e) {
// this / e.target is current target element.
e.stopPropagation(); // stops the browser from redirecting.
e.preventDefault();
Expand All @@ -128,15 +109,18 @@ function handleDropSolution(e) {
[].forEach.call(cols, function (col) {
col.classList.remove('over');
});

// See the section on the DataTransfer object.
file = getFile(e)
if(file == null){
return false;

if (e.dataTransfer.files.length) {
readFilesAndLoad(e.dataTransfer.files, loadTexts)
} else {
var text = e.dataTransfer.getData('Text')
if (text) {
loadTexts([text])
} else {
reportError("please drop a file(s) or text")
}
}

readFileAndLoad(file, loadSolution);

return false;
}

Expand All @@ -145,28 +129,20 @@ function handleDropSolution(e) {
***/
function setup() {

var cols = document.querySelectorAll('.drop_zone');
[].forEach.call(cols, function(col) {
col.addEventListener('dragstart', handleDragStart, false);
col.addEventListener('dragenter', handleDragEnter, false);
col.addEventListener('dragleave', handleDragLeave, false);
col.addEventListener('dragover', handleDragOver, false);
col.addEventListener('dragend', handleDragEnd, false);
});

var cols = document.querySelectorAll('#benchmark_zone');
[].forEach.call(cols, function(col) {
col.addEventListener('drop', handleDropBenchmark, false);
});

var cols = document.querySelectorAll('#solution_zone');
[].forEach.call(cols, function(col) {
col.addEventListener('drop', handleDropSolution, false);
});
var cols = document.querySelectorAll('.drop_zone');
[].forEach.call(cols, function(col) {
col.addEventListener('dragstart', handleDragStart, false);
col.addEventListener('dragenter', handleDragEnter, false);
col.addEventListener('dragleave', handleDragLeave, false);
col.addEventListener('dragover', handleDragOver, false);
col.addEventListener('dragend', handleDragEnd, false);
});

var cols = document.querySelectorAll('#drop_zone');
[].forEach.call(cols, function(col) {
col.addEventListener('drop', handleDrop, false);
});

}

setup();



7 changes: 3 additions & 4 deletions vrp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
<body>

<div id="controls">
<div id="benchmark_zone" class="drop_zone">Step 1 - Drop benchmark file here</div>
<div id="solution_zone" class="drop_zone">Step 2 - Drop solution file here</div>
<div style="clear:both;"><p id="feedback"></p></div>
<div id="drop_zone" class="drop_zone">Drop benchmark and solution files here</div>
<div><p id="feedback"></p></div>
</div>

<div id="data">
Expand All @@ -39,4 +38,4 @@
<script type="text/javascript" src="../viz.js"></script>

</body>
</html>
</html>
9 changes: 7 additions & 2 deletions vrp/vrp.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,12 @@ function vizSolution() {
.attr("stroke-width", line_width);
});
}


function isBenchmark(text){
var lines = text.replace(/^\s+|\s+$/g, '').split(REGEX_NEWLINE)
return lines.length == parseInt(lines[0]) + 1
}

function loadBenchmark(text){
parseInputText(text);
vizBenchmark();
Expand All @@ -474,4 +479,4 @@ function loadSolution(text){
parseSolutionText(text);
vizSolution();
}