Skip to content

Commit

Permalink
add comments and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
bricaud committed Jul 10, 2017
1 parent 38cfc73 commit 5d537da
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 167 deletions.
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Graphexp: graph explorer with D3.js

Graphexp is a web interface to explore and display a graph stored in the Gremlin graph database via the Gremlin server. Graphexp is under the Apache 2.0 licence.
Graphexp is a lightweight web interface to explore and display a graph stored in a Gremlin graph database, via the Gremlin server.

Graphexp is under the Apache 2.0 license.

![graphexp](https://github.com/bricaud/graphexp/blob/master/images/graphexp2.png "Graph exploration")

Expand All @@ -18,7 +20,7 @@ If the access to the Gremlin server is not `localhost:8182`, the address can be

## Getting started

### Intalling a Gremlin server
### Installing a Gremlin server

If you have not yet installed a gremlin server, download the last release of the [Gremlin server](http://tinkerpop.apache.org/) and follow the [documentation](http://tinkerpop.apache.org/docs/current/reference/#gremlin-server). In the server folder just run
```
Expand All @@ -29,10 +31,10 @@ or on windows
bin/gremlin-server.bat conf/gremlin-server-rest-modern.yaml
```
This default server comes with a small graph database of 6 nodes.
The server shoud start on port `8182`. Replace `gremlin-server-rest-modern.yaml` by `gremlin-server-modern.yaml` if you want to use websocket.
The server should start on port `8182`. Replace `gremlin-server-rest-modern.yaml` by `gremlin-server-modern.yaml` if you want to use websocket.


Alternatively, if you have Docker installed on your machine, you may run a Docker container with an already configured Gremlin server. You can find one on [this page](https://hub.docker.com/r/bricaud/gremlin-server-rest/). This server have a graph database containing a demo graph: the tree of life, with 35960 nodes and 35959 edges. You can download it and run it using
Alternatively, if you have Docker installed on your machine, you may run a Docker container with an already configured Gremlin server. You can find one on [this page](https://hub.docker.com/r/bricaud/gremlin-server-rest/). This server has a graph database containing a demo graph: the tree of life, with 35960 nodes and 35959 edges. You can download it and run it using
```
docker pull bricaud/gremlin-server-rest
docker run -p 8182:8182 -it --name gremlin-server-rest bricaud/gremlin-server-rest
Expand All @@ -49,26 +51,27 @@ To display a node, type in a property name and value, then click on the search b
Leaving a blank value will display a part of the graph limited to the first 50 nodes found (with their connections).
The node and edge properties can be automatically retrieved using the `get graph info` button. Pushing this button will also display some graph properties on the left side of the page.

When a node of the visualization is clicked, it will become 'active' with a circle surround it and its information will be display on the right side of the page. Moreover, this action will trigger the display of its neighbors.
When a node of the visualization is clicked, it will become 'active' with a circle surrounding it and its information will be display on the right side of the page. Moreover, this action will trigger the display of its neighbors.
Clicking on an edge will show its properties (without highlighting the edge).

When appearing for the first time the nodes will be positioned following a force layout. Drag and drop can be used to pin them in a particular position. Once dragged the nodes will stay at their position. Drag and drop is allowed only for the nodes on the active layer (most recent layer) with no connection with nodes in other layers. See "Visualization concepts" section for more information on the layers.

## Visualization concept

The visualization is based on a concept of layers of visualisation. The idea is to progress in the graph as in a jungle. The clicked node will show its neighbors, opening new paths for the exploration. If not clicked, the other displayed nodes will vanish little by little as we progress in the exploration. Coming back in the exploration paths allowed. Before it completely disappears, a node can be clicked and it will become active again. As in a jungle, you can not see the full jungle and there are so many things that you must focus on your direction and what is in front of you if you do not want to get lost.
The visualization is based on a concept of layers of visualization. The idea is to progress in the graph as in a jungle. The clicked node immediately shows its neighbors, opening new paths for the exploration. If not clicked, a node vanishes little by little as we progress in the exploration. Coming back during the exploration is allowed. Before it completely disappears, a node can be clicked and will become active again.
This visualization concept is aimed at providing a precise, local view rather than a global one.

During your exploration you can set up milestones by clicking on the small circle on the upper right side of a node. This will pin the node in time, preventing it to disappear.
During your exploration, you can set up milestones by clicking on the small circle on the upper right side of a node. This will pin the node in time, preventing it from disappearing.

You may also freeze the exploration, by ticking the appropriate checkbox. The evolution of the exploration will stop, allowing to gather information on the nodes displayed, without displaying their neighbors.

## Node and edge information

The Id and label of each node can be displayed by hovering the cursor over the node. The full information on the properties are displayed on the right of the page when clicking on the node or edges. Once the `get graph info` button has been clicked, a choice of properties to display appear on the left side.
The Id and label of each node can be displayed by hovering the cursor over the node. The full information on the properties is displayed on the right of the page when clicking on the node or edges. Once the `get graph info` button has been clicked, a choice of properties to display appears on the left side.

## Node color

If a node property called 'color' exists in the node properties with an hexadecimal color code (string), it will be displayed automatically on the graph. Otherwise, the default node color can be set in the `graphConf.js` file. The node color can be set interactively after the `get graph info` button has been pressed. A select tab appears on the left side bar allowing to set the color according to one of the property values present in the graph.
If a node property called 'color' exists in the node properties with a hexadecimal color code (string), it will be displayed automatically on the graph. Otherwise, the default node color can be set in the `graphConf.js` file. The node color can be set interactively after the `get graph info` button has been pressed. A select tab appears on the left sidebar allowing to set the color according to one of the property values present in the graph.

## Program description

Expand All @@ -84,24 +87,28 @@ This graph has a single type of nodes (label 'vertex') and a single type of edge
The different node properties are displayed on the left.
* `CHILDCOUNT` the number of descendent nodes
* `name` the name of the species
* `HASPAGE` whether there is an page of information on the [Tree Of Life Project website](http://tolweb.org/tree/home.pages/downloadtree.html)
* `HASPAGE` whether there is a page of information on the [Tree Of Life Project website](http://tolweb.org/tree/home.pages/downloadtree.html)
* `ID` Tree of Life Project unique id
* `CONFIDENCE` confidence in classification, from confident (0) to less confident (1) and (2)
* `EXTINCT` wether the node is extinct (2) or not (0)
* `EXTINCT` whether the node is extinct (2) or not (0)
* `LEAF` the node is a leaf of the tree (1) or the node does not represent a leaf (it has or will have descendent nodes on the Tree of Life) (0)
* `PHYLESIS` (0) monophylectic, (1) uncertain, (2) not monophylectic
* `PHYLESIS` (0) monophyletic, (1) uncertain, (2) not monophyletic

On the top navigation bar, choose the field `name`, enter 'Dinosauria' as value in the input and click on the `Search` button. Do not forget the capital letter, as the search is case-sensitive. A single node, corresponding to the Dinosaurs clade, should appear in the middle of the page. Click on the node to display node details on the right as well as its ancestors and descendants on the graph.
Check the box `name` on the left bar to display the node names.
You should see appearing the two subgroups of dinosaurs `Sauriscia` and `Ornithischia`, as in the [Wikipedia dinosaur page](https://en.wikipedia.org/wiki/Dinosaur_classification) and an additional `none` node which is the ancestor. This latter node is a taxon that has ancestors and descendants but does not have a name. Note that there are different version of the tree of life and it is always evolving as researchers find new species.
You should see appearing the two subgroups of dinosaurs `Saurischia` and `Ornithischia`, as in the [Wikipedia dinosaur page](https://en.wikipedia.org/wiki/Dinosaur_classification) and an additional `none` node which is the ancestor. This latter node is a taxon that has ancestors and descendants but does not have a name. Note that there are different versions of the tree of life and it is always evolving as researchers find new species.
![graphexptol2](https://github.com/bricaud/graphexp/blob/master/images/graphexptol2.png "Graph exploration Tree of life")
You may now enjoy the exploration of the dinosaur order by clicking on nodes and following ascendant and descendant lines. The oldest nodes will vanish as you explore the data and if you want more nodes to be displayed, just increase the number of layers on the top navigation bar.

You may also color the nodes according to the values of some of their properties by clicking on the color tab on the left side. The color scale is computed using the range of values of the nodes already displayed and a palette of 20 colors. You should refresh the color after a few steps of exploration.

![graphexptol3](https://github.com/bricaud/graphexp/blob/master/images/graphexptol3.png "Graph exploration Tree of life")

If you want to explore the world of insects, you may start with the taxon 'Insecta' and follow the links.
During the exploration of the `Dinosauria` clade you may find the [bird](https://en.wikipedia.org/wiki/Bird) class `Aves`. They are the only survivors of the Dinosaur group and descendant of dinosaurs with feathers. To see it, enter `Aves` in the value field, press search and climb up the tree.

If you want to explore the world of insects, you may start with the taxon `Insecta` and follow the links. Did you know that spiders are not insects but have they own group `Arachnida`? Can you tell what is the common ancestor between spiders and insects?

You may also be interested in the `Homo` group.

Have a try on the live demo of Graphexp on the [project Github page](https://bricaud.github.io/graphexp/).

Expand Down
4 changes: 2 additions & 2 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Layout styles
{
padding: 0em 0em;
background-color: #fff;
height: 70vh;
height: 80vh;
}

.main, .aside
Expand All @@ -115,7 +115,7 @@ Layout styles
position: absolute;
left: 0;
width: 100%;
height: 70vh;
height: 80vh;
}

.left_bar
Expand Down
31 changes: 4 additions & 27 deletions scripts/graphShapes.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ var graphShapes = (function(){

// Create the circle shape
var node_base_circle = node_deco.append("circle").classed("base_circle",true)
//.attr("r", 12)
.attr("r",node_size)
.style("stroke-width",node_stroke_width)
.style("stroke","black")
Expand All @@ -109,15 +108,11 @@ var graphShapes = (function(){

// Add the text to the nodes
node_deco.append("text").classed("text_details",true)
//.attr("x", 12)
.attr("x",function(d){return node_size(d)+2;})
//.attr("y", ".31em")
.text(node_text)
.style("visibility", "hidden");

node_deco.append("text").classed("text_details",true)
//.attr("x", 12)
//.attr("y", 15)
.attr("x",function(d){return node_size(d)+2;})
.attr("y",node_size)
.text(node_subtext)
Expand Down Expand Up @@ -208,14 +203,15 @@ var graphShapes = (function(){
// Attach the edge actions
attach_edge_actions(edges_deco)

// add property info if checkbox checked
// Add property info if checkbox checked
add_checkbox_prop('edges',edgelabels_deco)

return [edges_deco,edgepaths_deco,edgelabels_deco]

}

function add_checkbox_prop(item,selected_items){
// Add text from a property if the checkbox is checked on the sidebar
if (item=='edges'){
var item_properties = graphioGremlin.get_edge_properties();
} else if (item=='nodes'){
Expand All @@ -232,18 +228,15 @@ var graphShapes = (function(){
}

function create_edge_label(edgepaths,edgelabels){

var edgepaths_deco = edgepaths.append('path')
.attr('class','edgepath').classed("active_edgepath",true)
.attr('fill-opacity',0)
.attr('stroke-opacity',0)
//.attr('stroke-width',10)
.attr('id',function (d, i) {return 'edgepath' + d.id;})
.attr("ID",function(d) { return d.id;})
.style("pointer-events", "none");

var edgelabels_deco = edgelabels.append('text')
//.attr('x',10)
.attr('dy',-3)
.style("pointer-events", "none")
.attr('class','edgelabel').classed("active_edgelabel",true)
Expand Down Expand Up @@ -272,13 +265,10 @@ var graphShapes = (function(){


function decorate_old_elements(nb_layers){
// old links and nodes become older
// and move to the next layer
// Decrease the opacity of nodes and edges when they get old
for (var k=0;k<nb_layers;k++) {
d3.selectAll(".old_edge"+k)
.style("opacity",function(){return 0.8*(1-k/nb_layers)});
//edges_to_push.style("fill-opacity",function(){console.log(0.9*(1-k/nb_layers));return 0.9*(1-k/nb_layers)});

d3.selectAll(".old_node"+k)
.style("opacity",function(){return 0.8*(1-k/nb_layers)});
d3.selectAll(".old_edgelabel"+k)
Expand All @@ -288,10 +278,9 @@ var graphShapes = (function(){
}

function colorize(prop_name){
// Color the nodes according the value of the property 'prop_name'
colored_prop = prop_name;
var value_list = d3.selectAll(".node").data();


if (prop_name =="none"){
d3.selectAll(".base_circle").style("fill",function(d){
return node_color(d);
Expand All @@ -310,17 +299,13 @@ var graphShapes = (function(){
return color_palette(node_code_color(d.label));
});
}

else{

var value_set = new Set(value_list.map(function(d){
if (typeof d.properties[prop_name]!=="undefined"){
return d.properties[prop_name][0].value;
}
}));

node_code_color = d3.scaleOrdinal().domain(value_set).range(d3.range(0,value_set.size))//value_set.length])

d3.selectAll(".base_circle").style("fill",function(d){
if (typeof d.properties[prop_name] !=="undefined"){
return color_palette(node_code_color(d.properties[prop_name][0].value));
Expand All @@ -334,14 +319,6 @@ var graphShapes = (function(){
return node_color(d);
});
}


//console.log(value_set.map(function(d){return d.label;}))
//d3.selectAll(".node").style("fill",function(d){
// console.log('hello')
// console.log(d.properties[prop_name][0].value);
// return color(d.properties[prop_name][0].value);
//})
}
///////////////////////////////////////
// https://github.com/wbkd/d3-extended
Expand Down
Loading

0 comments on commit 5d537da

Please sign in to comment.