From 0788de7fc5eb2853681932dba212fb35343a5821 Mon Sep 17 00:00:00 2001 From: Schankula Christopher <schankuc@mcmaster.ca> Date: Sun, 1 Apr 2018 18:56:05 -0400 Subject: [PATCH] somewhat working histogram for the slides --- src/Main.java | 2 +- src/TrawlExpert.java | 1 - src/sort/KDT.java | 26 ++++++++++++++++++++++++++ tomcat/webapps/Trawl/WEB-INF/web.xml | 1 + tomcat/webapps/Trawl/histogram.js | 4 +--- tomcat/webapps/Trawl/index.jsp | 14 +++++++++----- tomcat/webapps/Trawl/script.js | 26 ++++++++++++++++++++++++++ tomcat/webapps/Trawl/style.css | 23 +++++++++++++++++------ 8 files changed, 81 insertions(+), 16 deletions(-) diff --git a/src/Main.java b/src/Main.java index ec16db1..8c91e26 100644 --- a/src/Main.java +++ b/src/Main.java @@ -114,7 +114,7 @@ public class Main { } catch (NumberFormatException e) { if (taxonId == null) { try { - taxonId = WormsAPI.nameToRecordID(matcher.group(2)); + taxonId = BioTree.nameToTaxonId(matcher.group(2)); } catch (IOException e1) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/TrawlExpert.java b/src/TrawlExpert.java index 1df3aab..3cf9fb8 100644 --- a/src/TrawlExpert.java +++ b/src/TrawlExpert.java @@ -24,6 +24,5 @@ public class TrawlExpert { BioTree.write("data/biotree/"); DataStore.records.writeToFile("data/kdt.ser"); }; - BasicSearch.init(); } } diff --git a/src/sort/KDT.java b/src/sort/KDT.java index 242a5af..b8e79ed 100644 --- a/src/sort/KDT.java +++ b/src/sort/KDT.java @@ -211,4 +211,30 @@ public class KDT<KeyVal extends Comparable<KeyVal>> implements Serializable { public int getK() { return axes.size(); } + public String toString() { + return toString(root, ""); + } + + public void writeToFile(String fn) { + try { + FileOutputStream fileOut = + new FileOutputStream(fn); + ObjectOutputStream out = new ObjectOutputStream(fileOut); + out.writeObject(this); + out.close(); + fileOut.close(); + System.out.printf("Serialized data is saved in /tmp/kdtree.ser"); + } catch (IOException i) { + i.printStackTrace(); + } + } + + private String toString(KDNode x, String depth) { + if (x == null) return depth + "null\n"; + String result = ""; + result += depth + x.keyval.toString() + "\n"; + result += toString(x.left, depth + " "); + result += toString(x.right, depth + " "); + return result; + } } diff --git a/tomcat/webapps/Trawl/WEB-INF/web.xml b/tomcat/webapps/Trawl/WEB-INF/web.xml index e647d8d..cecfe09 100644 --- a/tomcat/webapps/Trawl/WEB-INF/web.xml +++ b/tomcat/webapps/Trawl/WEB-INF/web.xml @@ -12,5 +12,6 @@ <servlet-mapping> <servlet-name>Trawl</servlet-name> <url-pattern>/doBioLookup.do</url-pattern> + <url-pattern>/doHist.do</url-pattern> </servlet-mapping> </web-app> \ No newline at end of file diff --git a/tomcat/webapps/Trawl/histogram.js b/tomcat/webapps/Trawl/histogram.js index 60ab9c4..e30cc6d 100644 --- a/tomcat/webapps/Trawl/histogram.js +++ b/tomcat/webapps/Trawl/histogram.js @@ -5,7 +5,7 @@ function histogram(x,y){ y: y, type: 'bar', marker: { - color: 'blue', + color: '#76ADD6', }, } ]; @@ -32,5 +32,3 @@ function histogram(x,y){ } -window.onload = histogram([1990,1991,1992],[54656,65654,32555]); - diff --git a/tomcat/webapps/Trawl/index.jsp b/tomcat/webapps/Trawl/index.jsp index 927313e..6b9843d 100644 --- a/tomcat/webapps/Trawl/index.jsp +++ b/tomcat/webapps/Trawl/index.jsp @@ -16,6 +16,9 @@ Double Handle Slider Modified from: http://jqueryui.com/slider/#range <!--JQuery--> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> + <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> + <script src="histogram.js"></script> + <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <!-- MUST load JQuery Library before loading this--> @@ -33,7 +36,7 @@ Double Handle Slider Modified from: http://jqueryui.com/slider/#range <a href="index.jsp" >TrawlExpert</a> <span class="nav-bar"> <a href="about.html">About</a> | - <a href="index.html" target="_blank">Gitlab/Github Nonfunc!</a> + <a href="index.html" target="_blank">GitHub</a> </span> </div> </header> @@ -63,7 +66,7 @@ Double Handle Slider Modified from: http://jqueryui.com/slider/#range <section id="yearIn"> Year Range: - <span id="fromtoYear">InnerHtml</span> + <span id="fromtoYear"></span> <form> <div id="slider-range"></div> </form> @@ -80,9 +83,10 @@ Double Handle Slider Modified from: http://jqueryui.com/slider/#range <section id="outputWrapper"> - <section id="outputDetails">Stuff like population count, entries found, etc. go here</section> - <section id="outputBox">Map, Histogram Box. Histogram selected by default but we might want to have a loading screen instead. - <div id="console">~~~ PSEUDO-CONSOLE ~~~<br></div> + <section id="outputDetails"><bold>Found 278143 results (0.204 seconds)</bold><br><bold>Total population:</bold> 66122855<br><!-- Stuff like population count, entries found, etc. go here --></section> + <section id="outputBox"><!-- Map, Histogram Box. Histogram selected by default but we might want to have a loading screen instead.--> + <!-- <div id="console">~~~ PSEUDO-CONSOLE ~~~<br></div> --> + <div id="histogram"></div> </section> </section> </section> diff --git a/tomcat/webapps/Trawl/script.js b/tomcat/webapps/Trawl/script.js index be3f2c8..79add29 100644 --- a/tomcat/webapps/Trawl/script.js +++ b/tomcat/webapps/Trawl/script.js @@ -1,6 +1,7 @@ // Initialization function init() { callUpdateSci({id:"pickAnimalia", value:2}); // Propagate Dropdowns on Startup + reqHistogram(2); } function resolveAny(obj) { @@ -105,6 +106,31 @@ function reqBioLookup(tagID, parentId){ // document.getElementById("console").innerHTML += "Sent request to " + path + ": " + jsonString + "<br>"; //RME } +//This function will get the new nodelist from the server. +//ParentId is the taxId of the node that holds the list of children we want. +function reqHistogram(taxonId){ + var path = 'doHist.do'; + var params = {taxId: Number(taxonId)}; + var xhr = new XMLHttpRequest(); + xhr.open("POST", path); + xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //Send the proper header info + + xhr.onreadystatechange = function() {//Call a function when the state changes (i.e. response comes back) + // Update the dropdown when response is ready + if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) { + var nodeList = JSON.parse(this.responseText); + histogram(nodeList["x"], nodeList["y"]); + } + else{ + console.log("Server Response: Error"); //RME + } + }; + + var jsonString= JSON.stringify(params); //generate JSON string + xhr.send(jsonString); //send request to server + // document.getElementById("console").innerHTML += "Sent request to " + path + ": " + jsonString + "<br>"; //RME +} + // JQuery for Range Slider $( function() { $( "#slider-range" ).slider({ diff --git a/tomcat/webapps/Trawl/style.css b/tomcat/webapps/Trawl/style.css index c45ad01..30a7f72 100644 --- a/tomcat/webapps/Trawl/style.css +++ b/tomcat/webapps/Trawl/style.css @@ -74,30 +74,41 @@ a:hover{ } #pickSci{ - border: 1px solid olivedrab; + /*border: 1px solid olivedrab;*/ } #yearIn{ - width: 80%; + width: 30%; +} + +#slider-range{ + margin-left:4%; } #outputIn{ - border: 1px solid blueviolet; + margin-left:1%; + /*border: 1px solid blueviolet;*/ } #outputWrapper{ - border: 1px solid grey; + /*border: 1px solid grey;*/ height: 100%; margin-top: 3%; } #outputDetails{ - border: 1px solid saddlebrown; + /*border: 1px solid saddlebrown;*/ } #outputBox{ - border: 1px solid darkred; + /*border: 1px solid darkred;*/ + min-height: 60vh; /*TODO Perhaps replace this with something less volatile*/ +} + +#histogram{ + /*border: 1px solid darkred;*/ min-height: 60vh; /*TODO Perhaps replace this with something less volatile*/ + width:100%; } /*300/400/600/700*/ -- GitLab