Skip to content

Commit

Permalink
Merge pull request #2 from rostam/master
Browse files Browse the repository at this point in the history
Merging changes from rostam
  • Loading branch information
HKH515 authored Oct 3, 2017
2 parents b8e7942 + 9b698c1 commit 623f6b8
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 20 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<version>2.0.1</version>
</dependency>

<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.8</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
Expand Down
99 changes: 97 additions & 2 deletions src/main/java/server/RequestHandler.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package server;

import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
import graphtea.extensions.Centrality;
import graphtea.extensions.G6Format;
import graphtea.extensions.RandomTree;
import graphtea.extensions.io.LatexWriter;
import graphtea.extensions.io.SaveGraph;
import graphtea.graph.graph.*;
import graphtea.plugins.graphgenerator.core.extension.GraphGeneratorExtension;
import graphtea.plugins.main.saveload.core.GraphIOException;
import graphtea.plugins.reports.extension.GraphReportExtension;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.codehaus.jettison.json.JSONString;
import org.reflections.Reflections;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import javax.ws.rs.core.StreamingOutput;
import java.io.*;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;

/**
Expand Down Expand Up @@ -259,6 +269,67 @@ public Response clear(@PathParam("info") String info) {
return Response.ok("{}").header("Access-Control-Allow-Origin", "*").build();
}

@GET
@Path("/tea/{info}")
public Response saveTea(@PathParam("info") String info) {
String[] infos = info.split("--");
String name = infos[0];String sessionID = infos[1];
GraphModel g = sessionToGraph.get(sessionID);
try {
new SaveGraph().write(new File(name+".tea"),g);
} catch (GraphIOException e) {
e.printStackTrace();
}
StreamingOutput fileStream = new StreamingOutput() {
@Override
public void write(java.io.OutputStream output) throws IOException, WebApplicationException {
try {
java.nio.file.Path path = Paths.get(name+".tea");
byte[] data = Files.readAllBytes(path);
output.write(data);
output.flush();
} catch (Exception e) {
throw e;
}
}
};
return Response
.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename = " + name +".tea")
.build();
}

@GET
@Path("/tex/{info}")
public Response saveTex(@PathParam("info") String info) {
String[] infos = info.split("--");
String name = infos[0];String sessionID = infos[1];
GraphModel g = sessionToGraph.get(sessionID);
try {
new LatexWriter().write(new File(name+".tex"),g);
} catch (GraphIOException e) {
e.printStackTrace();
}
StreamingOutput fileStream = new StreamingOutput() {
@Override
public void write(java.io.OutputStream output) throws IOException, WebApplicationException {
try {
java.nio.file.Path path = Paths.get(name+".tex");
byte[] data = Files.readAllBytes(path);
output.write(data);
output.flush();
} catch (Exception e) {
throw e;
}
}
};
return Response
.ok(fileStream, MediaType.APPLICATION_OCTET_STREAM)
.header("content-disposition", "attachment; filename = " + name +".tex")
.build();
}


/**
* Adds a single edge between two given vertices
*
Expand Down Expand Up @@ -349,6 +420,7 @@ public Response edgeList(@PathParam("info") String info) {
g = getGraphFromEdgeList(graph);
break;
case "g6":
graph = graph.replaceAll("qqq","?");
g = G6Format.stringToGraphModel(graph);
break;
case "adj":
Expand Down Expand Up @@ -407,6 +479,30 @@ private GraphModel getGraphFromEdgeList(String info) {
return currentGraph;
}

@GET
@Path("/save/{info}")
@Produces("application/json;charset=utf-8")
public Response save(@PathParam("info") String info) {
String[] infos = info.split("--");
String sessionID = infos[1];
handleSession(sessionID);
String output = infos[0];
String result = "";
GraphModel g = sessionToGraph.get(sessionID);
if(g.getVerticesCount() != 0) {
if (output.equals("g6")) {
result=G6Format.graphToG6(g);
}
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("results",result);
} catch (JSONException e) {
e.printStackTrace();
}
return Response.ok(jsonObject.toString()).header("Access-Control-Allow-Origin", "*").build();
}

@GET
@Path("/draw/{info}")
@Produces("application/json;charset=utf-8")
Expand Down Expand Up @@ -598,5 +694,4 @@ private boolean handleSession(String sessionID) {
}
return false; // Session exists
}

}
34 changes: 34 additions & 0 deletions src/main/resources/web/dashboard/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function do_actions() {
var action = $('#actions').find('option:selected').text();
if(action == "Load and Draw") {
load_generator(true);
} else if(action == "Load Only") {
load_generator(false);
} else if(action == "Fit Canvas") {
cy.fit();
} else if(action == "Clear Canvas") {
clearCanvas();
} else if(action == "Canvas to Image") {
var jpg64 = cy.jpg();
window.open(jpg64);
}
}

function do_saves() {
var output = $('#output').find('option:selected').text();
if(output == "G6 Format") {
server(serverAddr + 'save/g6--'+uuid,function (data) {
$("#outputResults").html(data.results);
});
} else if(output == "Adjacency List") {

} else if(output == "Adjacency Matrix") {

} else if(output == "GraphTea Format") {
window.open(serverAddr + 'tea/currentGraph--'+uuid);
// server(serverAddr + 'tea/currentGraph--'+uuid,function (data) {
// });
} else if(output == "LaTeX") {
window.open(serverAddr + 'tex/currentGraph--'+uuid);
}
}
71 changes: 57 additions & 14 deletions src/main/resources/web/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,74 @@ <h5>GraphTea</h5>
<option>Adjacency matrix</option>
<option>G6 format</option>
<option>Freehand drawing</option>
<option>File</option>
</select>
<select id="graphType" onchange="selectType()">
<option>directed</option>
<option selected="selected">undirected</option></select>
<option>directed</option>
<option selected="selected">undirected</option>
</select>
<!--<button onclick="selectLoader()">Select</button>-->
<div id="generators" class="loaders">
<p id="strings-generator"></p>
<table><tr>
<td><select id="categories"><option>Select</option></select></td>
<td><div id="props"><span id="props_keys">n</span> : <input type="text" id="props_vals" placeholder="Integer"></div></td>
</tr></table>
<table>
<tr>
<td><select id="categories">
<option>Select</option>
</select></td>
<td>
<div id="props"><span id="props_keys">n</span> : <input type="text" id="props_vals"
placeholder="Integer"></div>
</td>
</tr>
</table>
<p id="strings-layout"></p>
<select id="layouts">
<option>Force Directed</option>
<option>Circular</option>
<option>Grid</option>
<option>Preset</option>
<option>Botanical Tree</option>
</select>
<button onclick="load_generator(false)">Load Only</button>
<button onclick="load_generator(true)">Load and Draw</button>
<button onclick="cy.fit()">Fit</button>
<select id="actions">
<option>Load and Draw</option>
<option>Load Only</option>
<option>Fit Canvas</option>
<option>Clear Canvas</option>
<option>Canvas to Image</option>
</select>
<button onclick="do_actions()">Go</button>
<!--<button onclick="load_generator(false)">Load Only</button>-->
<!--<button onclick="load_generator(true)">Load and Draw</button>-->
<!--<button onclick="cy.fit()">Fit</button>-->
</div>
<div id="elformat" class="loaders">
<p id="strings-elformat"></p>
Edge list in csv format: <br/><textarea id="elstring" name="Text1" cols="20" rows="5"></textarea>
<br/><button onclick="load_graph('el',false)">Load Only</button>
<button onclick="load_graph('el',true)">Load and Draw</button>
<br/>
<button onclick="load_graph('el',false)">Load Only</button>
<button onclick="load_graph('el',true)">Load and Draw</button>
</div>
<div id="adjMatformat" class="loaders">
<p id="strings-adjMatformat"></p>
<br/><textarea id="adjstring" name="Text1" cols="20" rows="5"></textarea>
<br/><button onclick="load_graph('adj',false)">Load Only</button>
<br/>
<button onclick="load_graph('adj',false)">Load Only</button>
<button onclick="load_graph('adj',true)">Load and Draw</button>
</div>
<div id="g6format" class="loaders">
<p id="strings-g6format"></p>
G6 Format: <input id="g6string" type="text">
<br/><button onclick="load_graph('g6',false)">Load Only</button>
<br/>
<button onclick="load_graph('g6',false)">Load Only</button>
<button onclick="load_graph('g6',true)">Load and Draw</button>
</div>
<div id="fileformat" class="loaders">
<p id="strings-fileformat"></p>
<form action="upload" method="post" enctype="multipart/form-data">
Select a file : <input type="file" name="file" size="45" /><br/>
<input type="submit" value="Upload It" />
</form>
</div>
<p id="strings-report"></p>
<select id="reports"></select>
<button onclick="Report()">Report</button>
Expand All @@ -80,7 +109,20 @@ <h5>GraphTea</h5>
<button id="myBtn">View Styled</button>
<button onclick="showOnGraph()">Show On Graph</button>
</div>
<button onclick="clearCanvas()">Clear</button>
<hr>
<p id="strings-save"></p>
<div>Save:
<select id="output">
<option>G6 Format</option>
<option>Adjacency Matrix</option>
<option>Adjacency List</option>
<option>GraphTea Format</option>
<option>LaTeX</option>
</select>
<button onclick="do_saves()">Go</button>
<textarea name="Text2" cols="50" rows="6" id="outputResults"></textarea>
</div>
<!--<button onclick="clearCanvas()">Clear</button>-->

<!--<div id="reportResults"></div>-->
<canvas id="paperCanvas"></canvas>
Expand Down Expand Up @@ -110,5 +152,6 @@ <h5>Modal Footer</h5>
<script src="modal.js"></script>
<script src="strings.js"></script>
<script src="distinctColors.js"></script>
<script src="actions.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions src/main/resources/web/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,18 @@ function selectLoader() {
case "G6 format":
$('#g6format').show();
break;
case "File":
$('#fileformat').show();
break;
}
}

function load_graph(type,isDraw) {
var str = $('#'+type+'string').val().replace(/\n/g,"-");
var isDirected = $('#graphType').find('option:selected').text();
if(type == "g6") {
str = str.replaceAll(/\?/g,"qqq");
}
server(serverAddr + 'loadGraph' + '/'+ type + "--"
+str+"--"+isDirected+"--"+uuid,function (data) {
if(isDraw) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,16 @@ function removeSingleEdge(edge) {
});
}


function applyLayout(){
var lay = $('#layouts').find('option:selected').text();
if (lay == "Preset") {
cy.layout({name: 'preset'}).run();
} else if (lay == "Force Directed") {
cy.layout({name: 'cose'}).run();
} else if (lay == "Circular") {
cy.layout({name: 'circle'}).run();
} else if (lay == "Grid") {
cy.layout({name: 'grid'}).run();
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/web/dashboard/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ var strings = {
g6format : "Here, you can paste your G6-formatted string to load that graph.",
layout : "Now, you can draw the graph in a layout which can be selected here. The preset layout " +
"here means the computed layout in GraphTea.",
report: "Here, you can compute the different reports on graph. When a report selected from" +
report: "Now, you can compute the different reports on graph. When a report selected from" +
" the list, the parameters, if any, appears near to it. " +
" After the computation, the results would appear as strings at the botton. " +
" A styled version can be also generated.",
adjMat: "The adjacency matrix should be written in the following format." +
" The elements in a row are separated with a comma." +
" Each row comes in a new line. "
" Each row comes in a new line. ",
save: "Here, you can save the current graph to different format. The outputs" +
" that are textual are shown on the text area."
};

$('#strings-intro').html(strings.intro);
Expand All @@ -22,4 +24,5 @@ $('#strings-g6format').html(strings.g6format);
$('#strings-freehand').html(strings.freehand);
$("#strings-layout").html(strings.layout);
$("#strings-report").html(strings.report);
$("#strings-adjMatformat").html(strings.adjMat);
$("#strings-adjMatformat").html(strings.adjMat);
$("#strings-save").html(strings.save);

0 comments on commit 623f6b8

Please sign in to comment.