diff --git a/coloring/coloring.js b/coloring/coloring.js index 08d3cc8..8f1b502 100644 --- a/coloring/coloring.js +++ b/coloring/coloring.js @@ -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); -} \ No newline at end of file +} diff --git a/coloring/index.html b/coloring/index.html index d5912e2..c18ca97 100644 --- a/coloring/index.html +++ b/coloring/index.html @@ -26,9 +26,8 @@
-
Step 1 - Drop benchmark file here
-
Step 2 - Drop solution file here
-

+
Drop benchmark and solution files here
+

@@ -52,4 +51,4 @@ - \ No newline at end of file + diff --git a/facility/facility.js b/facility/facility.js index 9fd5add..1cab752 100644 --- a/facility/facility.js +++ b/facility/facility.js @@ -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(); @@ -454,4 +458,4 @@ function checkValidity() { reportError(errors.join(" ")); return true; } - \ No newline at end of file + diff --git a/facility/index.html b/facility/index.html index a42bc37..b17ee60 100644 --- a/facility/index.html +++ b/facility/index.html @@ -16,9 +16,8 @@
-
Step 1 - Drop benchmark file here
-
Step 2 - Drop solution file here
-

+
Drop benchmark and solution files here
+

@@ -38,4 +37,4 @@ - \ No newline at end of file + diff --git a/tsp/index.html b/tsp/index.html index a252a80..d2257f0 100644 --- a/tsp/index.html +++ b/tsp/index.html @@ -14,9 +14,8 @@
-
Step 1 - Drop benchmark file here
-
Step 2 - Drop solution file here
-

+
Drop benchmark and solution files here
+

@@ -36,4 +35,4 @@ - \ No newline at end of file + diff --git a/tsp/tsp.js b/tsp/tsp.js index c674712..433c5ed 100644 --- a/tsp/tsp.js +++ b/tsp/tsp.js @@ -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); diff --git a/viz.css b/viz.css index 9a1d75f..c13f737 100644 --- a/viz.css +++ b/viz.css @@ -39,8 +39,6 @@ SOFTWARE. text-align:center; font:20pt bold,"Vollkorn"; color:#bbb; - float: left; - width: 45%; } #viz { diff --git a/viz.js b/viz.js index 9639bab..54fab3b 100644 --- a/viz.js +++ b/viz.js @@ -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(); @@ -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; } @@ -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(); - - - diff --git a/vrp/index.html b/vrp/index.html index 28ac77e..1a8070b 100644 --- a/vrp/index.html +++ b/vrp/index.html @@ -17,9 +17,8 @@
-
Step 1 - Drop benchmark file here
-
Step 2 - Drop solution file here
-

+
Drop benchmark and solution files here
+

@@ -39,4 +38,4 @@ - \ No newline at end of file + diff --git a/vrp/vrp.js b/vrp/vrp.js index 83d36c0..26f4b9a 100644 --- a/vrp/vrp.js +++ b/vrp/vrp.js @@ -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(); @@ -474,4 +479,4 @@ function loadSolution(text){ parseSolutionText(text); vizSolution(); } - \ No newline at end of file +