├── .github └── workflows │ └── docker-build.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── css ├── bootstrap.css ├── graphStyle.css └── styles.css ├── graphexp.html ├── images ├── bootstrapthemec.png ├── concrete_seamless.png ├── curved_links.png ├── graphexp2.png ├── graphexp2018.png ├── graphexptol1.png ├── graphexptol2.png ├── graphexptol3.png ├── graphexpzoom.png ├── qbkls.png └── ticks.png ├── index.html └── scripts ├── bootstrap.min.js ├── d3.v4.min.js ├── editGraph.js ├── graphConf.js ├── graphShapes.js ├── graph_viz.js ├── graphioGremlin.js ├── infobox.js ├── jquery-3.2.1.min.js └── utils.js /.github/workflows/docker-build.yml: -------------------------------------------------------------------------------- 1 | name: docker-build-push 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | tags: 8 | - '*' 9 | 10 | pull_request: 11 | branches: 12 | - 'master' 13 | 14 | workflow_dispatch: 15 | 16 | env: 17 | IMAGE_NAME: "graphexp" 18 | 19 | jobs: 20 | docker: 21 | runs-on: ubuntu-latest 22 | steps: 23 | 24 | - name: Checkout 25 | uses: actions/checkout@v2 26 | 27 | - name: Prepare 28 | id: prep 29 | run: | 30 | BASE_DIR=. 31 | IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME 32 | 33 | # Change all uppercase to lowercase 34 | IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') 35 | 36 | # Strip git ref prefix from version 37 | VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') 38 | 39 | # Strip "v" prefix from tag name 40 | [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') 41 | 42 | # Use Docker `latest` tag convention 43 | [ "$VERSION" == "master" ] && VERSION=latest 44 | 45 | VERSION=$VERSION 46 | IMAGE_ID=$IMAGE_ID 47 | echo ::set-output name=version::${VERSION} 48 | echo ::set-output name=image_id::${IMAGE_ID} 49 | echo ::set-output name=base_dir::${BASE_DIR} 50 | 51 | - name: Set up QEMU 52 | uses: docker/setup-qemu-action@v1 53 | with: 54 | platforms: all 55 | 56 | - name: Set up Docker Buildx 57 | id: buildx 58 | uses: docker/setup-buildx-action@v1 59 | with: 60 | install: true 61 | version: latest 62 | 63 | - name: Log into registry 64 | run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin 65 | 66 | - name: Build and Push 67 | uses: docker/build-push-action@v2 68 | with: 69 | build-args: VERSION=${{ steps.prep.outputs.version }} 70 | context: ${{ steps.prep.outputs.base_dir }}/ 71 | file: ${{ steps.prep.outputs.base_dir }}/Dockerfile 72 | platforms: linux/amd64,linux/arm64 73 | push: true 74 | tags: | 75 | ${{ steps.prep.outputs.image_id }}:${{ steps.prep.outputs.version }} 76 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | d3/ 2 | font-awesome-4.7.0/ 3 | jquery* -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:stable 2 | 3 | LABEL maintainer="armand.leopold@outlook.com" 4 | 5 | WORKDIR /usr/share/nginx/html 6 | COPY . /usr/share/nginx/html 7 | 8 | RUN sed -i 's/const HOST = "localhost"/const HOST = self.location.hostname/' scripts/graphConf.js -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Benjamin RICAUD 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Graphexp: graph explorer with D3.js 2 | 3 | Graphexp is a lightweight web interface to explore and display a graph stored in a Gremlin graph database, via the Gremlin server (version 3.2.x, 3.3.x or 3.4.x). 4 | 5 | Graphexp is under the Apache 2.0 license. 6 | 7 | # Bootstrap Version : 8 | 9 | Versions of Graphexp with the same backend but a nicer UI (using bootstrap) are available here [github.com/erandal/graphexp](https://github.com/erandal/graphexp) and here [github.com/ddmx/graphexp](https://github.com/ddmx/graphexp). 10 | ![Preview](https://github.com/erandal/graphexp/blob/master/images/bootstrapthemec.png) 11 | 12 | ## Installation : 13 | 14 | ```bash 15 | docker pull ghcr.io/armandleopold/graphexp:0.8.3 16 | ``` 17 | 18 | ## Configuration 19 | 20 | To use Graph Explorer, you need a [Gremlin server](http://tinkerpop.apache.org/) running with REST or websocket protocol and a *recent* web browser to display the visualization. 21 | On your web browser, just access the file `graphexp.html`. 22 | 23 | Next step, configure the server settings on the bottom of the page. The default Gremlin server address is `localhost:8182`. You will have to specify the communication protocol `websocket` or `REST` and the gremlin server version. Graphexp is not able to handle secure connections yet and a contribution on this topic would be welcome. 24 | 25 | Graphexp works with [Amazon Neptune](https://aws.amazon.com/neptune) thanks to a pull request of [jwalton922](https://github.com/jwalton922). With this database, set `SINGLE_COMMANDS_AND_NO_VARS = true` in the file `graphConf.js`. 26 | 27 | Make sure you choose the correct version of Gremlin on the bottom right corner. Setting a wrong version may lead to unexpected problems such as not displaying the edges. 28 | 29 | Additional parameters can be configured inside the file `graphConf.js`. 30 | 31 | ![graphexpzoom](https://github.com/bricaud/graphexp/blob/master/images/graphexpzoom.png "Exploration of the Tinkerpop modern graph") 32 | ![graphexpzoom with curved edges](https://github.com/bricaud/graphexp/blob/master/images/curved_links.png "Exploration of the Tinkerpop modern graph with curved links and multiple edges between node 1 and 2") 33 | 34 | ## Getting started 35 | 36 | ### Installing a Gremlin server 37 | 38 | 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 39 | ``` 40 | bin/gremlin-server.sh conf/gremlin-server-rest-modern.yaml 41 | ``` 42 | or on windows 43 | ``` 44 | bin/gremlin-server.bat conf/gremlin-server-rest-modern.yaml 45 | ``` 46 | This default server comes with a small graph database of 6 nodes. 47 | The server should start on port `8182`. Replace `gremlin-server-rest-modern.yaml` by `gremlin-server-modern.yaml` if you want to use websocket. 48 | 49 | 50 | 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-with-demo-graph/). 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 51 | ``` 52 | docker pull bricaud/gremlin-server-with-demo-graph 53 | docker run -p 8182:8182 -it --name gremlin-server-rest bricaud/gremlin-server-with-demo-graph 54 | ``` 55 | or for the websocket version: 56 | ``` 57 | docker pull bricaud/gremlin-server-with-demo-graph:websocket 58 | docker run -p 8182:8182 -it --name gremlin-server-websocket bricaud/gremlin-server-with-demo-graph:websocket 59 | ``` 60 | ### Running a graphexp Demo with Docker 61 | 62 | You may also try out a Graphexp demo on [joov's Github repository](https://github.com/joov/gremlin-demo). It uses Docker compose and can work on Windows. 63 | 64 | ### Graphexp guidelines 65 | To get some first visualization of your graph, you may click on the `Search` button, without filling any box. Graphexp will then send a query to the graph DB, asking for the first 50 nodes and their edges. 66 | 67 | 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. If it is not the case, check your configuration, it means Graphexp can not query the graphDB. To get the properties, Graphexp should consider all the nodes and edges. This may be overwhelming for the server if the graph is very large. A limit to the 10000 first nodes and edges is set to avoid that. You may change it in `graphConf.js` with the parameter `limit_graphinfo_request`. 68 | 69 | When a node of the visualization is clicked, it will become 'active' with a circle surrounding it and its information will be displayed on the right side of the page. Moreover, this action will trigger the display of its neighbors. 70 | Clicking on an edge will show its properties (without highlighting the edge). 71 | 72 | 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. 73 | 74 | ### Querying the graphDB 75 | In the top bar, you can search the graphDB to display a particular node or group of nodes. 76 | 77 | * The box `Node label` allows to filter nodes with a particular label during the search. 78 | * The box `Node property`, in combination with the `Property value` box, allows to find nodes with a particular keyword or value in their properties. The `Type of search` allows for a perfect (equals) or partial match (Contains). *Note that the 'contains' option will only work with Janusgraph*. 79 | * The box `Traverse by edge` acts directly in the interactive visualization. If an edge label is entered in the box, clicking on a node will only display its neighbors connected with that type of edge label. 80 | * The `Results limit` is here to avoid overwhelming the visualization. It fixes the maximal le number of nodes to display per query. 81 | * If `Freeze exploration` is ticked, the graph displayed will stay the same even if nodes are clicked on. It is useful when you just need to display the node properties. 82 | * `Number of layers` is explained below in the "Visualization concept" section. 83 | 84 | Note that the input is case-sensitive. 85 | 86 | ### URL query string parameters 87 | 88 | * `ts` specifies [TraversalSource](http://tinkerpop.apache.org/docs/current/reference/#the-graph-process) in case of multiple different graphs stored in the same database. If unspecified, the default is just `g`. For Example `http://localhost:8183/graphexp.html?ts=gTreeOfLife` replaces `g` by `gTreeOfLife` in all the gremlin queries (for example `g.V()` becomes `gTreeOfLife.V()`). 89 | 90 | ### Editing the graph 91 | 92 | There is now the possibility to add/edit the vertices and edges of the graph. A small button was added by [sandecho](https://github.com/sandecho) at the bottom `Edit Graph`. You can modify your graph using Graphexp but you have to update the view to see the result. You can check if the modification has been taken into account by the server in the message window on the top right of the interface. 93 | 94 | ## Visualization concept 95 | 96 | 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. 97 | This visualization concept is aimed at providing a precise, local view rather than a global one. 98 | 99 | 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. 100 | 101 | 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. 102 | 103 | ## Node and edge information 104 | 105 | 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. 106 | 107 | ## Node color 108 | 109 | 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. 110 | 111 | ## Predefined node positions 112 | 113 | Graphexp can display nodes at specific positions if they are stored in the DB. For that, modify `node_position_x` and `node_position_y` in `graphConf.js` (by default `graphexpx` and `graphexpy`), to whatever keys are refering to the node positions in the graphDB. Values must be numbers. According to [Sim Bamford](https://github.com/bricaud/graphexp/pull/24), reasonable values should be below 500 to stay within the page limits. Node with predefined positions are not subject to the force layout and will stay at the same position, while the others may move. It may be useful for plotting a hierarchical graph for example. 114 | 115 | ## Curved edges 116 | 117 | GraphExp has now curved links and can display multiple edges between 2 nodes, thanks to a contribution from [agussman](https://github.com/agussman). This is the default, you can still come back to straight edges by setting `use_curved_edges = false` in `graphConf.js`. 118 | 119 | ## Program description 120 | 121 | The program uses: 122 | * the D3.js library to visualize a graph in an interactive manner, [API Reference](https://github.com/d3/d3/blob/master/API.md), 123 | * an ajax request (with Jquery) that query the graph database (Gremlin Tinkerpop via REST). 124 | 125 | 126 | ## Contributing 127 | Contribution as pull requests are very welcome. 128 | If you want to contribute, you may have a look at the [issues](https://github.com/bricaud/graphexp/issues). You can also submit a pull request with a new feature. When contributing, keep in mind that graphexp must stays simple. The idea is to have a simple tool for a quick (and efficient) graph exploration. 129 | 130 | 131 | ## Tutorial with the tree of life 132 | Once your gremlin server is up and running (from the [Docker repository](https://hub.docker.com/r/bricaud/gremlin-server-with-demo-graph/)), click on the `get graph info` button. Information should appear on the left side of the page, like on the following image. 133 | ![graphexptol1](https://github.com/bricaud/graphexp/blob/master/images/graphexptol1.png "Graph exploration Tree of life") 134 | 135 | This graph has a single type of nodes (label 'vertex') and a single type of edges (label 'edge'). Each node is a species (taxon) living on earth or extinct, and directed edges represent the link ancestor-descendant. 136 | The different node properties are displayed on the left. 137 | * `CHILDCOUNT` the number of descendent nodes 138 | * `name` the name of the species 139 | * `HASPAGE` whether there is a page of information on the [Tree Of Life Project website](http://tolweb.org/tree/home.pages/downloadtree.html) 140 | * `ID` Tree of Life Project unique id 141 | * `CONFIDENCE` confidence in classification, from confident (0) to less confident (1) and (2) 142 | * `EXTINCT` whether the node is extinct (2) or not (0) 143 | * `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) 144 | * `PHYLESIS` (0) monophyletic, (1) uncertain, (2) not monophyletic 145 | 146 | 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. 147 | Check the box `name` on the left bar to display the node names. 148 | 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. 149 | ![graphexptol2](https://github.com/bricaud/graphexp/blob/master/images/graphexptol2.png "Graph exploration Tree of life") 150 | 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. 151 | 152 | 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. 153 | 154 | ![graphexptol3](https://github.com/bricaud/graphexp/blob/master/images/graphexptol3.png "Graph exploration Tree of life") 155 | 156 | 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. 157 | 158 | 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? 159 | 160 | You may also be interested in the `Homo` group. 161 | 162 | Have a try on the live demo of Graphexp on the [project Github page](https://bricaud.github.io/graphexp/). 163 | -------------------------------------------------------------------------------- /css/graphStyle.css: -------------------------------------------------------------------------------- 1 | .edge { 2 | stroke: #999; 3 | stroke-opacity: 0.8; 4 | } 5 | 6 | .old_edge0 { 7 | stroke: #999; 8 | stroke-opacity: 0.6; 9 | } 10 | 11 | .node circle { 12 | stroke: #000; 13 | stroke-width: 1.5px; 14 | } 15 | 16 | .node text { 17 | font: 10px sans-serif; 18 | } 19 | 20 | .node:hover circle { 21 | stroke-opacity: 0.6; 22 | } 23 | 24 | .pinned circle { 25 | stroke: #000; 26 | stroke-width: 1.5px; 27 | } 28 | 29 | .pinned text { 30 | font: 10px sans-serif; 31 | } 32 | 33 | .pinned:hover circle { 34 | stroke-opacity: 0.6; 35 | } 36 | 37 | .old_node0 circle { 38 | stroke-opacity: 0.9; 39 | } 40 | 41 | .old_node0 text { 42 | font: 10px sans-serif; 43 | opacity: 0.9; 44 | color: #000;/* Fallback for older browsers */ 45 | color: rgba(0,0,0,0.5); 46 | } 47 | 48 | .cell { 49 | fill: none; 50 | pointer-events: all; 51 | } 52 | 53 | .links line { 54 | stroke: #999; 55 | stroke-opacity: 0.6; 56 | } 57 | 58 | path { 59 | fill: none; 60 | } 61 | 62 | /* 63 | 64 | .nodes circle { 65 | stroke: #fff; 66 | stroke-width: 1.5px; 67 | } 68 | 69 | .text1 text{ 70 | font: 10px sans-serif; 71 | } 72 | */ 73 | /*.table { border:0px solid black; padding:10px; width:1400px; overflow:hidden;border-spacing:0;border-collapse:collapse;} 74 | .left { float:left; width:960px; } 75 | .right { float:right; width:400px; } 76 | 77 | td, th { 78 | padding: 1px 4px; 79 | } 80 | */ -------------------------------------------------------------------------------- /css/styles.css: -------------------------------------------------------------------------------- 1 | /* ----------------------- 2 | Base styles 3 | ------------------------*/ 4 | body 5 | { 6 | margin: 0; 7 | padding: 0; 8 | color: #333; 9 | background-color: #eee; 10 | font: 1em/1.2 "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif; 11 | height: 100%; 12 | } 13 | 14 | h1,h2,h3,h4,h5,h6 15 | { 16 | margin: 0 0 .5em; 17 | font-weight: 500; 18 | line-height: 1.1; 19 | } 20 | 21 | h1 { font-size: 2.25em; } /* 36px */ 22 | h2 { font-size: 1.75em; } /* 28px */ 23 | h3 { font-size: 1.375em; } /* 22px */ 24 | h4 { font-size: 1.125em; } /* 18px */ 25 | h5 { font-size: 1em; } /* 16px */ 26 | h6 { font-size: .875em; } /* 14px */ 27 | 28 | p 29 | { 30 | margin: 0 0 1.5em; 31 | line-height: 1.5; 32 | } 33 | 34 | blockquote 35 | { 36 | padding: 1em 2em; 37 | margin: 0 0 2em; 38 | border-left: 5px solid #eee; 39 | } 40 | 41 | hr 42 | { 43 | height: 0; 44 | margin-top: 1em; 45 | margin-bottom: 2em; 46 | border: 0; 47 | border-top: 1px solid #ddd; 48 | } 49 | 50 | table 51 | { 52 | background-color: transparent; 53 | border-spacing: 0; 54 | border-collapse: collapse; 55 | border-top: 1px solid #ddd; 56 | } 57 | 58 | th, td 59 | { 60 | padding: .5em 1em; 61 | vertical-align: top; 62 | text-align: left; 63 | border-bottom: 1px solid #ddd; 64 | } 65 | 66 | a:link { color: royalblue; } 67 | a:visited { color: purple; } 68 | a:focus { color: black; } 69 | a:hover { color: green; } 70 | a:active { color: red; } 71 | 72 | input[type="number"] { 73 | width:50px; 74 | } 75 | 76 | /* ----------------------- 77 | Layout styles 78 | ------------------------*/ 79 | 80 | .header 81 | { 82 | color: #000; 83 | background: #ddd; 84 | padding: 0.2em 1.25em; 85 | } 86 | 87 | .header-heading { margin: 0; } 88 | 89 | .nav-bar 90 | { 91 | color: #ddd; 92 | background: #17649a; 93 | padding: 0; 94 | } 95 | 96 | .container 97 | { 98 | padding: 1em 1.25em; 99 | margin: 0 auto; 100 | } 101 | 102 | .nav.container { 103 | display: grid; 104 | grid-template-rows: auto 15%; 105 | } 106 | 107 | .nav.inputs_container_top { 108 | grid-row: 1 / 2; 109 | display: grid; 110 | grid-template-columns: auto auto auto auto auto; 111 | grid-auto-flow: row; 112 | } 113 | 114 | .nav.inputs_container_bottom { 115 | grid-row: 1 / 2; 116 | display: grid; 117 | grid-template-columns: auto auto auto auto; 118 | grid-auto-flow: row; 119 | } 120 | .nav.input_unit_container { 121 | padding: 5px; 122 | align-self: center; 123 | } 124 | 125 | .nav.input_label { 126 | white-space:nowrap; 127 | } 128 | 129 | .nav.controls { 130 | grid-row: 1 / span 3; 131 | justify-self: center; 132 | align-self: center; 133 | } 134 | 135 | .content 136 | { 137 | padding: 0em 0em; 138 | height: 100%; 139 | } 140 | 141 | .main, .aside 142 | { 143 | margin-bottom: 1em; 144 | padding: 0em; 145 | font: 12px sans-serif; 146 | position: absolute; 147 | top: 0; 148 | } 149 | 150 | .main 151 | { 152 | position: absolute; 153 | top:0; 154 | left: 0; 155 | width: 100%; 156 | height: 100%; 157 | } 158 | 159 | .left_bar { 160 | margin: 0; 161 | position: absolute; 162 | left: 0; 163 | max-width: 275px; 164 | background-color: #fff; 165 | padding: 20px; 166 | padding-top: 7px; 167 | border-bottom-right-radius: 15px; 168 | overflow: auto; 169 | max-height: 100%; 170 | top: 0px; 171 | display: block; 172 | z-index: 1; 173 | padding-top: 61px; 174 | } 175 | 176 | .right_bar { 177 | position: absolute; 178 | right: 0; 179 | top: 56px; 180 | max-width: 275px; 181 | background-color: #fff; 182 | padding: 10px; 183 | border-bottom-left-radius: 15px; 184 | padding-left: 15px; 185 | } 186 | 187 | .left_bar_edit { 188 | position: relative; 189 | background-color: white; 190 | border-bottom-right-radius: 15px; 191 | z-index: 2; 192 | box-shadow: 1px 1px 15px #888; 193 | } 194 | 195 | /* ----------------------- 196 | Nav 197 | ------------------------*/ 198 | 199 | .nav 200 | { 201 | margin: 0; 202 | padding: 0; 203 | list-style: none; 204 | } 205 | 206 | .nav li 207 | { 208 | display: inline; 209 | margin: 0; 210 | } 211 | 212 | .nav a 213 | { 214 | display: block; 215 | padding: .7em 1.25em; 216 | color: #fff; 217 | text-decoration: none; 218 | border-bottom: 1px solid gray; 219 | } 220 | 221 | .nav a:link { color: white; } 222 | .nav a:visited { color: white; } 223 | 224 | .nav a:focus 225 | { 226 | color: black; 227 | background-color: white; 228 | } 229 | 230 | .nav a:hover 231 | { 232 | color: white; 233 | background-color: green; 234 | } 235 | 236 | .nav a:active 237 | { 238 | color: white; 239 | background-color: red; 240 | } 241 | 242 | /* ----------------------- 243 | Side styles 244 | ------------------------*/ 245 | .aside li 246 | { 247 | padding-left: 0; 248 | margin-left: -5px; 249 | list-style: none; 250 | } 251 | .aside div 252 | { 253 | margin: 1em 0 1em 0; 254 | } 255 | /* ----------------------- 256 | Single styles 257 | ------------------------*/ 258 | 259 | .img-responsive { max-width: 100%; } 260 | 261 | .btn 262 | { 263 | color: #fff !important; 264 | background-color: royalblue; 265 | border-color: #222; 266 | display: inline-block; 267 | padding: .5em 1em; 268 | margin-bottom: 0; 269 | font-weight: 400; 270 | line-height: 1.2; 271 | text-align: center; 272 | white-space: nowrap; 273 | vertical-align: middle; 274 | cursor: pointer; 275 | border: 1px solid transparent; 276 | border-radius: .2em; 277 | text-decoration: none; 278 | } 279 | 280 | .btn:hover 281 | { 282 | color: #fff !important; 283 | background-color: green; 284 | } 285 | 286 | .btn:focus 287 | { 288 | color: #fff !important; 289 | background-color: black; 290 | } 291 | 292 | .btn:active 293 | { 294 | color: #fff !important; 295 | background-color: red; 296 | } 297 | 298 | .table 299 | { 300 | width: 100%; 301 | max-width: 100%; 302 | margin-bottom: 20px; 303 | } 304 | 305 | .list-unstyled 306 | { 307 | padding-left: 0; 308 | list-style: none; 309 | } 310 | 311 | .list-inline 312 | { 313 | padding-left: 0; 314 | margin-left: -5px; 315 | list-style: none; 316 | } 317 | 318 | .list-inline > li 319 | { 320 | display: inline-block; 321 | padding-right: 5px; 322 | padding-left: 5px; 323 | } 324 | 325 | /* ----------------------- 326 | Wide styles 327 | ------------------------*/ 328 | 329 | @media (max-width: 1024px) 330 | { 331 | .left_bar { 332 | padding-top: 90px; 333 | } 334 | .right_bar { 335 | top: 86px; 336 | } 337 | } 338 | 339 | @media (min-width: 55em) 340 | { 341 | .header { padding: 0.2em 3em; } 342 | .nav-bar { padding: 0.5em 3em; } 343 | .content { padding: 0em 0em; } 344 | 345 | .main 346 | { 347 | margin-right: 0%; 348 | margin-bottom: 1em; 349 | } 350 | 351 | .aside 352 | { 353 | float: left; 354 | margin-bottom: 1em; 355 | } 356 | 357 | .nav li 358 | { 359 | display: inline; 360 | margin: 0 1em 0 0; 361 | } 362 | 363 | .nav a 364 | { 365 | display: inline; 366 | padding: 0; 367 | border-bottom: 0; 368 | } 369 | } 370 | 371 | 372 | 373 | .nav label { 374 | margin-right: 15px; 375 | } 376 | 377 | /* width */ 378 | ::-webkit-scrollbar { 379 | width: 10px; 380 | } 381 | 382 | /* Track */ 383 | ::-webkit-scrollbar-track { 384 | background: #f1f1f1; 385 | } 386 | 387 | /* Handle */ 388 | ::-webkit-scrollbar-thumb { 389 | background: #888; 390 | } 391 | 392 | /* Handle on hover */ 393 | ::-webkit-scrollbar-thumb:hover { 394 | background: #555; 395 | } 396 | 397 | .middle { 398 | z-index: 999; 399 | color: white; 400 | font-size: large; 401 | display: block; 402 | position: relative; 403 | text-align: center; 404 | margin: 0 !important; 405 | padding: 0 !important; 406 | opacity: 0.9; 407 | } 408 | 409 | #addVertexForm , #editVertexForm, #addEditEdgeForm{ 410 | padding: 15px; 411 | padding-bottom: 6px; 412 | } 413 | 414 | #messageArea { 415 | background-color: #31795e; 416 | } 417 | #messageArea p { 418 | margin:0; 419 | } 420 | 421 | #outputArea p { 422 | margin: 0; 423 | padding: 10px; 424 | padding-left: 15px; 425 | } 426 | 427 | #outputArea { 428 | display: block; 429 | position: relative; 430 | float: right; 431 | background-color: darkslategrey; 432 | border-bottom-left-radius: 15px; 433 | } 434 | 435 | -------------------------------------------------------------------------------- /graphexp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Graphexp, graph explorer 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 36 | 37 | 38 |
39 | 76 | 110 |
111 |
112 |
113 |
114 | 115 |
116 |
175 |
176 |
177 | 178 |
179 | 180 | 183 |
184 |
185 |
186 |
187 |
188 | 189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 | 197 |
198 | 199 | 200 | 246 | 247 | 434 |
435 | 436 | 437 | -------------------------------------------------------------------------------- /images/bootstrapthemec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/bootstrapthemec.png -------------------------------------------------------------------------------- /images/concrete_seamless.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/concrete_seamless.png -------------------------------------------------------------------------------- /images/curved_links.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/curved_links.png -------------------------------------------------------------------------------- /images/graphexp2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/graphexp2.png -------------------------------------------------------------------------------- /images/graphexp2018.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/graphexp2018.png -------------------------------------------------------------------------------- /images/graphexptol1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/graphexptol1.png -------------------------------------------------------------------------------- /images/graphexptol2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/graphexptol2.png -------------------------------------------------------------------------------- /images/graphexptol3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/graphexptol3.png -------------------------------------------------------------------------------- /images/graphexpzoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/graphexpzoom.png -------------------------------------------------------------------------------- /images/qbkls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/qbkls.png -------------------------------------------------------------------------------- /images/ticks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandleopold/graphexp/4614f7ff93b052bc7b848e4916a78f4a15ec23c1/images/ticks.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | Page Redirection 10 | 11 | 12 | If you are not redirected automatically, follow this link to example. 13 | 14 | 15 | -------------------------------------------------------------------------------- /scripts/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.7 (http://getbootstrap.com) 3 | * Copyright 2011-2016 Twitter, Inc. 4 | * Licensed under the MIT license 5 | */ 6 | if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1||b[0]>3)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){if(a(b.target).is(this))return b.handleObj.handler.apply(this,arguments)}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.7",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a("#"===f?[]:f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.7",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c).prop(c,!0)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c).prop(c,!1))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target).closest(".btn");b.call(d,"toggle"),a(c.target).is('input[type="radio"], input[type="checkbox"]')||(c.preventDefault(),d.is("input,button")?d.trigger("focus"):d.find("input:visible,button:visible").first().trigger("focus"))}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==typeof b?e.to(b):g?e[g]():f.interval&&e.pause().cycle()})}var c=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=null,this.sliding=null,this.interval=null,this.$active=null,this.$items=null,this.options.keyboard&&this.$element.on("keydown.bs.carousel",a.proxy(this.keydown,this)),"hover"==this.options.pause&&!("ontouchstart"in document.documentElement)&&this.$element.on("mouseenter.bs.carousel",a.proxy(this.pause,this)).on("mouseleave.bs.carousel",a.proxy(this.cycle,this))};c.VERSION="3.3.7",c.TRANSITION_DURATION=600,c.DEFAULTS={interval:5e3,pause:"hover",wrap:!0,keyboard:!0},c.prototype.keydown=function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.prev();break;case 39:this.next();break;default:return}a.preventDefault()}},c.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},c.prototype.getItemIndex=function(a){return this.$items=a.parent().children(".item"),this.$items.index(a||this.$active)},c.prototype.getItemForDirection=function(a,b){var c=this.getItemIndex(b),d="prev"==a&&0===c||"next"==a&&c==this.$items.length-1;if(d&&!this.options.wrap)return b;var e="prev"==a?-1:1,f=(c+e)%this.$items.length;return this.$items.eq(f)},c.prototype.to=function(a){var b=this,c=this.getItemIndex(this.$active=this.$element.find(".item.active"));if(!(a>this.$items.length-1||a<0))return this.sliding?this.$element.one("slid.bs.carousel",function(){b.to(a)}):c==a?this.pause().cycle():this.slide(a>c?"next":"prev",this.$items.eq(a))},c.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},c.prototype.next=function(){if(!this.sliding)return this.slide("next")},c.prototype.prev=function(){if(!this.sliding)return this.slide("prev")},c.prototype.slide=function(b,d){var e=this.$element.find(".item.active"),f=d||this.getItemForDirection(b,e),g=this.interval,h="next"==b?"left":"right",i=this;if(f.hasClass("active"))return this.sliding=!1;var j=f[0],k=a.Event("slide.bs.carousel",{relatedTarget:j,direction:h});if(this.$element.trigger(k),!k.isDefaultPrevented()){if(this.sliding=!0,g&&this.pause(),this.$indicators.length){this.$indicators.find(".active").removeClass("active");var l=a(this.$indicators.children()[this.getItemIndex(f)]);l&&l.addClass("active")}var m=a.Event("slid.bs.carousel",{relatedTarget:j,direction:h});return a.support.transition&&this.$element.hasClass("slide")?(f.addClass(b),f[0].offsetWidth,e.addClass(h),f.addClass(h),e.one("bsTransitionEnd",function(){f.removeClass([b,h].join(" ")).addClass("active"),e.removeClass(["active",h].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger(m)},0)}).emulateTransitionEnd(c.TRANSITION_DURATION)):(e.removeClass("active"),f.addClass("active"),this.sliding=!1,this.$element.trigger(m)),g&&this.cycle(),this}};var d=a.fn.carousel;a.fn.carousel=b,a.fn.carousel.Constructor=c,a.fn.carousel.noConflict=function(){return a.fn.carousel=d,this};var e=function(c){var d,e=a(this),f=a(e.attr("data-target")||(d=e.attr("href"))&&d.replace(/.*(?=#[^\s]+$)/,""));if(f.hasClass("carousel")){var g=a.extend({},f.data(),e.data()),h=e.attr("data-slide-to");h&&(g.interval=!1),b.call(f,g),h&&f.data("bs.carousel").to(h),c.preventDefault()}};a(document).on("click.bs.carousel.data-api","[data-slide]",e).on("click.bs.carousel.data-api","[data-slide-to]",e),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var c=a(this);b.call(c,c.data())})})}(jQuery),+function(a){"use strict";function b(b){var c,d=b.attr("data-target")||(c=b.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"");return a(d)}function c(b){return this.each(function(){var c=a(this),e=c.data("bs.collapse"),f=a.extend({},d.DEFAULTS,c.data(),"object"==typeof b&&b);!e&&f.toggle&&/show|hide/.test(b)&&(f.toggle=!1),e||c.data("bs.collapse",e=new d(this,f)),"string"==typeof b&&e[b]()})}var d=function(b,c){this.$element=a(b),this.options=a.extend({},d.DEFAULTS,c),this.$trigger=a('[data-toggle="collapse"][href="#'+b.id+'"],[data-toggle="collapse"][data-target="#'+b.id+'"]'),this.transitioning=null,this.options.parent?this.$parent=this.getParent():this.addAriaAndCollapsedClass(this.$element,this.$trigger),this.options.toggle&&this.toggle()};d.VERSION="3.3.7",d.TRANSITION_DURATION=350,d.DEFAULTS={toggle:!0},d.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},d.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b,e=this.$parent&&this.$parent.children(".panel").children(".in, .collapsing");if(!(e&&e.length&&(b=e.data("bs.collapse"),b&&b.transitioning))){var f=a.Event("show.bs.collapse");if(this.$element.trigger(f),!f.isDefaultPrevented()){e&&e.length&&(c.call(e,"hide"),b||e.data("bs.collapse",null));var g=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[g](0).attr("aria-expanded",!0),this.$trigger.removeClass("collapsed").attr("aria-expanded",!0),this.transitioning=1;var h=function(){this.$element.removeClass("collapsing").addClass("collapse in")[g](""),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return h.call(this);var i=a.camelCase(["scroll",g].join("-"));this.$element.one("bsTransitionEnd",a.proxy(h,this)).emulateTransitionEnd(d.TRANSITION_DURATION)[g](this.$element[0][i])}}}},d.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse in").attr("aria-expanded",!1),this.$trigger.addClass("collapsed").attr("aria-expanded",!1),this.transitioning=1;var e=function(){this.transitioning=0,this.$element.removeClass("collapsing").addClass("collapse").trigger("hidden.bs.collapse")};return a.support.transition?void this.$element[c](0).one("bsTransitionEnd",a.proxy(e,this)).emulateTransitionEnd(d.TRANSITION_DURATION):e.call(this)}}},d.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()},d.prototype.getParent=function(){return a(this.options.parent).find('[data-toggle="collapse"][data-parent="'+this.options.parent+'"]').each(a.proxy(function(c,d){var e=a(d);this.addAriaAndCollapsedClass(b(e),e)},this)).end()},d.prototype.addAriaAndCollapsedClass=function(a,b){var c=a.hasClass("in");a.attr("aria-expanded",c),b.toggleClass("collapsed",!c).attr("aria-expanded",c)};var e=a.fn.collapse;a.fn.collapse=c,a.fn.collapse.Constructor=d,a.fn.collapse.noConflict=function(){return a.fn.collapse=e,this},a(document).on("click.bs.collapse.data-api",'[data-toggle="collapse"]',function(d){var e=a(this);e.attr("data-target")||d.preventDefault();var f=b(e),g=f.data("bs.collapse"),h=g?"toggle":e.data();c.call(f,h)})}(jQuery),+function(a){"use strict";function b(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}function c(c){c&&3===c.which||(a(e).remove(),a(f).each(function(){var d=a(this),e=b(d),f={relatedTarget:this};e.hasClass("open")&&(c&&"click"==c.type&&/input|textarea/i.test(c.target.tagName)&&a.contains(e[0],c.target)||(e.trigger(c=a.Event("hide.bs.dropdown",f)),c.isDefaultPrevented()||(d.attr("aria-expanded","false"),e.removeClass("open").trigger(a.Event("hidden.bs.dropdown",f)))))}))}function d(b){return this.each(function(){var c=a(this),d=c.data("bs.dropdown");d||c.data("bs.dropdown",d=new g(this)),"string"==typeof b&&d[b].call(c)})}var e=".dropdown-backdrop",f='[data-toggle="dropdown"]',g=function(b){a(b).on("click.bs.dropdown",this.toggle)};g.VERSION="3.3.7",g.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=b(e),g=f.hasClass("open");if(c(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a(document.createElement("div")).addClass("dropdown-backdrop").insertAfter(a(this)).on("click",c);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;e.trigger("focus").attr("aria-expanded","true"),f.toggleClass("open").trigger(a.Event("shown.bs.dropdown",h))}return!1}},g.prototype.keydown=function(c){if(/(38|40|27|32)/.test(c.which)&&!/input|textarea/i.test(c.target.tagName)){var d=a(this);if(c.preventDefault(),c.stopPropagation(),!d.is(".disabled, :disabled")){var e=b(d),g=e.hasClass("open");if(!g&&27!=c.which||g&&27==c.which)return 27==c.which&&e.find(f).trigger("focus"),d.trigger("click");var h=" li:not(.disabled):visible a",i=e.find(".dropdown-menu"+h);if(i.length){var j=i.index(c.target);38==c.which&&j>0&&j--,40==c.which&&jdocument.documentElement.clientHeight;this.$element.css({paddingLeft:!this.bodyIsOverflowing&&a?this.scrollbarWidth:"",paddingRight:this.bodyIsOverflowing&&!a?this.scrollbarWidth:""})},c.prototype.resetAdjustments=function(){this.$element.css({paddingLeft:"",paddingRight:""})},c.prototype.checkScrollbar=function(){var a=window.innerWidth;if(!a){var b=document.documentElement.getBoundingClientRect();a=b.right-Math.abs(b.left)}this.bodyIsOverflowing=document.body.clientWidth
',trigger:"hover focus",title:"",delay:0,html:!1,container:!1,viewport:{selector:"body",padding:0}},c.prototype.init=function(b,c,d){if(this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d),this.$viewport=this.options.viewport&&a(a.isFunction(this.options.viewport)?this.options.viewport.call(this,this.$element):this.options.viewport.selector||this.options.viewport),this.inState={click:!1,hover:!1,focus:!1},this.$element[0]instanceof document.constructor&&!this.options.selector)throw new Error("`selector` option must be specified when initializing "+this.type+" on the window.document object!");for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},c.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},c.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);return c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusin"==b.type?"focus":"hover"]=!0),c.tip().hasClass("in")||"in"==c.hoverState?void(c.hoverState="in"):(clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show())},c.prototype.isInStateTrue=function(){for(var a in this.inState)if(this.inState[a])return!0;return!1},c.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget).data("bs."+this.type);if(c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c)),b instanceof a.Event&&(c.inState["focusout"==b.type?"focus":"hover"]=!1),!c.isInStateTrue())return clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide()},c.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(b);var d=a.contains(this.$element[0].ownerDocument.documentElement,this.$element[0]);if(b.isDefaultPrevented()||!d)return;var e=this,f=this.tip(),g=this.getUID(this.type);this.setContent(),f.attr("id",g),this.$element.attr("aria-describedby",g),this.options.animation&&f.addClass("fade");var h="function"==typeof this.options.placement?this.options.placement.call(this,f[0],this.$element[0]):this.options.placement,i=/\s?auto?\s?/i,j=i.test(h);j&&(h=h.replace(i,"")||"top"),f.detach().css({top:0,left:0,display:"block"}).addClass(h).data("bs."+this.type,this),this.options.container?f.appendTo(this.options.container):f.insertAfter(this.$element),this.$element.trigger("inserted.bs."+this.type);var k=this.getPosition(),l=f[0].offsetWidth,m=f[0].offsetHeight;if(j){var n=h,o=this.getPosition(this.$viewport);h="bottom"==h&&k.bottom+m>o.bottom?"top":"top"==h&&k.top-mo.width?"left":"left"==h&&k.left-lg.top+g.height&&(e.top=g.top+g.height-i)}else{var j=b.left-f,k=b.left+f+c;jg.right&&(e.left=g.left+g.width-k)}return e},c.prototype.getTitle=function(){var a,b=this.$element,c=this.options;return a=b.attr("data-original-title")||("function"==typeof c.title?c.title.call(b[0]):c.title)},c.prototype.getUID=function(a){do a+=~~(1e6*Math.random());while(document.getElementById(a));return a},c.prototype.tip=function(){if(!this.$tip&&(this.$tip=a(this.options.template),1!=this.$tip.length))throw new Error(this.type+" `template` option must consist of exactly 1 top-level element!");return this.$tip},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")},c.prototype.enable=function(){this.enabled=!0},c.prototype.disable=function(){this.enabled=!1},c.prototype.toggleEnabled=function(){this.enabled=!this.enabled},c.prototype.toggle=function(b){var c=this;b&&(c=a(b.currentTarget).data("bs."+this.type),c||(c=new this.constructor(b.currentTarget,this.getDelegateOptions()),a(b.currentTarget).data("bs."+this.type,c))),b?(c.inState.click=!c.inState.click,c.isInStateTrue()?c.enter(c):c.leave(c)):c.tip().hasClass("in")?c.leave(c):c.enter(c)},c.prototype.destroy=function(){var a=this;clearTimeout(this.timeout),this.hide(function(){a.$element.off("."+a.type).removeData("bs."+a.type),a.$tip&&a.$tip.detach(),a.$tip=null,a.$arrow=null,a.$viewport=null,a.$element=null})};var d=a.fn.tooltip;a.fn.tooltip=b,a.fn.tooltip.Constructor=c,a.fn.tooltip.noConflict=function(){return a.fn.tooltip=d,this}}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof b&&b;!e&&/destroy|hide/.test(b)||(e||d.data("bs.popover",e=new c(this,f)),"string"==typeof b&&e[b]())})}var c=function(a,b){this.init("popover",a,b)};if(!a.fn.tooltip)throw new Error("Popover requires tooltip.js");c.VERSION="3.3.7",c.DEFAULTS=a.extend({},a.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:''}),c.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content").children().detach().end()[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},c.prototype.hasContent=function(){return this.getTitle()||this.getContent()},c.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},c.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};var d=a.fn.popover;a.fn.popover=b,a.fn.popover.Constructor=c,a.fn.popover.noConflict=function(){return a.fn.popover=d,this}}(jQuery),+function(a){"use strict";function b(c,d){this.$body=a(document.body),this.$scrollElement=a(a(c).is(document.body)?window:c),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||"")+" .nav li > a",this.offsets=[],this.targets=[],this.activeTarget=null,this.scrollHeight=0,this.$scrollElement.on("scroll.bs.scrollspy",a.proxy(this.process,this)),this.refresh(),this.process()}function c(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})}b.VERSION="3.3.7",b.DEFAULTS={offset:10},b.prototype.getScrollHeight=function(){return this.$scrollElement[0].scrollHeight||Math.max(this.$body[0].scrollHeight,document.documentElement.scrollHeight)},b.prototype.refresh=function(){var b=this,c="offset",d=0;this.offsets=[],this.targets=[],this.scrollHeight=this.getScrollHeight(),a.isWindow(this.$scrollElement[0])||(c="position",d=this.$scrollElement.scrollTop()),this.$body.find(this.selector).map(function(){var b=a(this),e=b.data("target")||b.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[c]().top+d,e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){b.offsets.push(this[0]),b.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.getScrollHeight(),d=this.options.offset+c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(this.scrollHeight!=c&&this.refresh(),b>=d)return g!=(a=f[f.length-1])&&this.activate(a);if(g&&b=e[a]&&(void 0===e[a+1]||b .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.7",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return e=a-d&&"bottom"},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affixed=h,this.unpin="bottom"==h?this.getPinnedOffset():null,this.$element.removeClass(c.RESET).addClass(i).trigger(i.replace("affix","affixed")+".bs.affix")}"bottom"==h&&this.$element.offset({top:g-b-f})}};var d=a.fn.affix;a.fn.affix=b,a.fn.affix.Constructor=c,a.fn.affix.noConflict=function(){return a.fn.affix=d,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var c=a(this),d=c.data();d.offset=d.offset||{},null!=d.offsetBottom&&(d.offset.bottom=d.offsetBottom),null!=d.offsetTop&&(d.offset.top=d.offsetTop),b.call(c,d)})})}(jQuery); -------------------------------------------------------------------------------- /scripts/editGraph.js: -------------------------------------------------------------------------------- 1 | function editGraph() { 2 | var x = document.getElementById("editGraph") 3 | if(x.style.display == "none"){ 4 | x.style.display = "block"; 5 | } 6 | else{ 7 | x.style.display ="none" ; 8 | } 9 | document.getElementById("addVertexForm").style.display='none'; 10 | document.getElementById("editVertexForm").style.display='none'; 11 | document.getElementById("addEditEdgeForm").style.display='none'; 12 | 13 | } 14 | 15 | function addVertexForm() { 16 | document.getElementById("addVertexForm").style.display='block'; 17 | document.getElementById("editVertexForm").style.display='none'; 18 | document.getElementById("addEditEdgeForm").style.display='none'; 19 | } 20 | 21 | function editVertexForm() { 22 | document.getElementById("addVertexForm").style.display='none'; 23 | document.getElementById("editVertexForm").style.display='block'; 24 | document.getElementById("addEditEdgeForm").style.display='none'; 25 | } 26 | 27 | 28 | function addEditEdgeForm() { 29 | document.getElementById("addVertexForm").style.display='none'; 30 | document.getElementById("editVertexForm").style.display='none'; 31 | document.getElementById("addEditEdgeForm").style.display='block'; 32 | 33 | } 34 | 35 | function addVertex() { 36 | 37 | let vertexLabel = $('#vertexLabel').val(); 38 | let vertexPropertyName = $('#vertexPropertyName').val(); 39 | //vertexPropertyName = vertexPropertyName.replace(/\s/g,''); 40 | let vertexPropertyValue = $('#vertexPropertyValue').val(); 41 | //vertexPropertyValue = vertexPropertyValue.replace(/\s/g,''); 42 | propertyName = vertexPropertyName.split(","); 43 | propertyValue = vertexPropertyValue.split(","); 44 | var valueLen = propertyValue.length; 45 | var nameLen = propertyName.length; 46 | if(nameLen != valueLen){ 47 | alert("Please enter same number of property name and property value") 48 | } 49 | else{ 50 | document.getElementById('vertexLabel').value=''; 51 | document.getElementById('vertexPropertyName').value=''; 52 | document.getElementById('vertexPropertyValue').value=''; 53 | var gremlin_query = "g.addV('"+vertexLabel+"')" 54 | for(count =0; count 0; k--) { 157 | var kp = k - 1; 158 | _svg.selectAll(".old_edge" + kp).classed("old_edge" + k, true); 159 | _svg.selectAll(".old_node" + kp).classed("old_node" + k, true); 160 | _svg.selectAll(".old_edgepath" + kp).classed("old_edgepath" + k, true); 161 | _svg.selectAll(".old_edgelabel" + kp).classed("old_edgelabel" + k, true); 162 | }; 163 | } 164 | 165 | function clear_old() { 166 | old_Nodes = []; 167 | old_Links = []; 168 | } 169 | 170 | function update_data(d) { 171 | // Save the data 172 | var previous_nodes = _svg.selectAll("g").filter(".active_node"); 173 | var previous_nodes_data = previous_nodes.data(); 174 | old_Nodes = updateAdd(old_Nodes, previous_nodes_data); 175 | var previous_links = _svg.selectAll(".active_edge"); 176 | var previous_links_data = previous_links.data(); 177 | old_Links = updateAdd(old_Links, previous_links_data); 178 | 179 | // handle the pinned nodes 180 | var pinned_Nodes = _svg.selectAll("g").filter(".pinned"); 181 | var pinned_nodes_data = pinned_Nodes.data(); 182 | // get the node data and merge it with the pinned nodes 183 | _Nodes = d.nodes; 184 | _Nodes = updateAdd(_Nodes, pinned_nodes_data); 185 | // add coordinates to the new active nodes that already existed in the previous step 186 | _Nodes = transfer_coordinates(_Nodes, old_Nodes); 187 | // retrieve the links between nodes and pinned nodes 188 | _Links = d.links.concat(previous_links_data); // first gather the links 189 | _Links = find_active_links(_Links, _Nodes); // then find the ones that are between active nodes 190 | 191 | // Sort links by source, then target, then label 192 | // This is used to set linknum 193 | _Links.sort(function (a, b) { 194 | if (a.source > b.source) { return 1; } 195 | else if (a.source < b.source) { return -1; } 196 | else { 197 | if (a.target > b.target) { return 1; } 198 | if (a.target < b.target) { return -1; } 199 | else { 200 | if (a.label > b.label) { return 1; } 201 | if (a.label < b.label) { return -1; } 202 | else { return 0; } 203 | } 204 | } 205 | }); 206 | 207 | // Any links with duplicate source and target get an incremented 'linknum' 208 | for (var i = 0; i < _Links.length; i++) { 209 | if (i != 0 && 210 | _Links[i].source == _Links[i - 1].source && 211 | _Links[i].target == _Links[i - 1].target) { 212 | _Links[i].linknum = _Links[i - 1].linknum + 1; 213 | } 214 | else { _Links[i].linknum = 1; }; 215 | }; 216 | } 217 | 218 | function updateAdd(array1, array2) { 219 | // Update lines of array1 with the ones of array2 when the elements' id match 220 | // and add elements of array2 to array1 when they do not exist in array1 221 | var arraytmp = array2.slice(0); 222 | var removeValFromIndex = []; 223 | array1.forEach(function (d, index, thearray) { 224 | for (var i = 0; i < arraytmp.length; i++) { 225 | if (d.id == arraytmp[i].id) { 226 | thearray[index] = arraytmp[i]; 227 | removeValFromIndex.push(i); 228 | } 229 | } 230 | }); 231 | // remove the already updated values (in reverse order, not to mess up the indices) 232 | removeValFromIndex.sort(); 233 | for (var i = removeValFromIndex.length - 1; i >= 0; i--) 234 | arraytmp.splice(removeValFromIndex[i], 1); 235 | return array1.concat(arraytmp); 236 | } 237 | 238 | function find_active_links(list_of_links, active_nodes) { 239 | // find the links in the list_of_links that are between the active nodes and discard the others 240 | var active_links = []; 241 | list_of_links.forEach(function (row) { 242 | for (var i = 0; i < active_nodes.length; i++) { 243 | for (var j = 0; j < active_nodes.length; j++) { 244 | if (active_nodes[i].id == row.source.id && active_nodes[j].id == row.target.id) { 245 | var L_data = { source: row.source.id, target: row.target.id, type: row.type, value: row.value, id: row.id }; 246 | var L_data = row; 247 | L_data['source'] = row.source.id; 248 | L_data['target'] = row.target.id; 249 | active_links = active_links.concat(L_data); 250 | } 251 | else if (active_nodes[i].id == row.source && active_nodes[j].id == row.target) { 252 | var L_data = row; 253 | active_links = active_links.concat(L_data); 254 | } 255 | } 256 | } 257 | }); 258 | // the active links are in active_links but there can be some duplicates 259 | // remove duplicates links 260 | var dic = {}; 261 | for (var i = 0; i < active_links.length; i++) 262 | dic[active_links[i].id] = active_links[i]; // this will remove the duplicate links (with same id) 263 | var list_of_active_links = []; 264 | for (var key in dic) 265 | list_of_active_links.push(dic[key]); 266 | return list_of_active_links; 267 | } 268 | 269 | 270 | function transfer_coordinates(Nodes, old_Nodes) { 271 | // Transfer coordinates from old_nodes to the new nodes with the same id 272 | for (var i = 0; i < old_Nodes.length; i++) { 273 | var exists = 0; 274 | for (var j = 0; j < Nodes.length; j++) { 275 | if (Nodes[j].id == old_Nodes[i].id) { 276 | Nodes[j].x = old_Nodes[i].x; 277 | Nodes[j].y = old_Nodes[i].y; 278 | Nodes[j].fx = old_Nodes[i].x; 279 | Nodes[j].fy = old_Nodes[i].y; 280 | Nodes[j].vx = old_Nodes[i].vx; 281 | Nodes[j].vy = old_Nodes[i].vy; 282 | } 283 | } 284 | } 285 | return Nodes; 286 | } 287 | 288 | function remove_duplicates(elem_class, elem_class_old) { 289 | // Remove all the duplicate nodes and edges among the old_nodes and old_edges. 290 | // A node or an edge can not be on several layers at the same time. 291 | d3.selectAll(elem_class).each(function (d) { 292 | var ID = d.id; 293 | for (var n = 0; n < nb_layers; n++) { 294 | var list_old_elements = d3.selectAll(elem_class_old + n); 295 | //list_old_nodes_data = list_old_nodes.data(); 296 | list_old_elements.each(function (d) { 297 | if (d.id == ID) { 298 | d3.select(this).remove(); 299 | //console.log('Removed!!') 300 | } 301 | }) 302 | } 303 | }); 304 | } 305 | 306 | return { 307 | set_nb_layers: set_nb_layers, 308 | depth: depth, 309 | push_layers: push_layers, 310 | clear_old: clear_old, 311 | update_data: update_data, 312 | remove_duplicates: remove_duplicates 313 | } 314 | })(); 315 | 316 | //////////////////////////////////////////////////////////////////////////////////// 317 | function simulation_start(center_f) { 318 | // Define the force applied to the nodes 319 | _simulation = d3.forceSimulation() 320 | .force("charge", d3.forceManyBody().strength(force_strength)) 321 | .force("link", d3.forceLink().strength(link_strength).id(function (d) { return d.id; })); 322 | 323 | if (center_f == 1) { 324 | var force_y = force_x_strength; 325 | var force_x = force_y_strength; 326 | _simulation.force("center", d3.forceCenter(_svg_width / 2, _svg_height / 2)); 327 | } 328 | else { 329 | var force_y = 0; 330 | var force_x = 0; 331 | } 332 | _simulation.force("y", d3.forceY().strength(function (d) { 333 | return force_y; 334 | })) 335 | .force("x", d3.forceX().strength(function (d) { 336 | return force_x; 337 | })); 338 | return _simulation; 339 | } 340 | 341 | 342 | 343 | ////////////////////////////////////// 344 | function refresh_data(d, center_f, with_active_node) { 345 | // Main visualization function 346 | var svg_graph = svg_handle(); 347 | layers.push_layers(); 348 | layers.update_data(d); 349 | 350 | ////////////////////////////////////// 351 | // link handling 352 | 353 | //attach the data 354 | var all_links = svg_graph.selectAll(".active_edge") 355 | .data(_Links, function (d) { return d.id; }); 356 | var all_edgepaths = svg_graph.selectAll(".active_edgepath") 357 | .data(_Links, function (d) { return d.id; }); 358 | var all_edgelabels = svg_graph.selectAll(".active_edgelabel") 359 | .data(_Links, function (d) { return d.id; }); 360 | 361 | // links not active anymore are classified old_links 362 | all_links.exit().classed("old_edge0", true).classed("active_edge", false); 363 | all_edgepaths.exit().classed("old_edgepath0", true).classed("active_edgepath", false); 364 | all_edgelabels.exit().classed("old_edgelabel0", true).classed("active_edgelabel", false); 365 | 366 | 367 | // handling active links associated to the data 368 | var edgepaths_e = all_edgepaths.enter(), 369 | edgelabels_e = all_edgelabels.enter(), 370 | link_e = all_links.enter(); 371 | var decor_out = graphShapes.decorate_link(link_e, edgepaths_e, edgelabels_e); 372 | _links = decor_out[0]; 373 | 374 | var edgepaths = decor_out[1], 375 | edgelabels = decor_out[2]; 376 | 377 | 378 | // previous links plus new links are merged 379 | _links = _links.merge(all_links); 380 | edgepaths = edgepaths.merge(all_edgepaths); 381 | edgelabels = edgelabels.merge(all_edgelabels); 382 | 383 | /////////////////////////////////// 384 | // node handling 385 | 386 | var all_nodes = svg_graph.selectAll("g").filter(".active_node") 387 | .data(_Nodes, function (d) { return d.id; }); 388 | 389 | //console.log(data_node); 390 | // old nodes not active any more are tagged 391 | all_nodes.exit().classed("old_node0", true).classed("active_node", false);//;attr("class","old_node0"); 392 | 393 | 394 | // nodes associated to the data are constructed 395 | _nodes = all_nodes.enter(); 396 | 397 | // add node decoration 398 | var node_deco = graphShapes.decorate_node(_nodes, with_active_node); 399 | 400 | var _nodes = node_deco.merge(all_nodes); 401 | 402 | 403 | 404 | 405 | ////////////////////////////////// 406 | // Additional clean up 407 | graphShapes.decorate_old_elements(layers.depth()); 408 | svg_graph.selectAll("g").filter(".pinned").moveToFront(); 409 | 410 | 411 | layers.remove_duplicates(".active_node", ".old_node"); 412 | layers.remove_duplicates(".active_edge", ".old_edge"); 413 | layers.remove_duplicates(".active_edgepath", ".old_edgepath"); 414 | layers.remove_duplicates(".active_edgelabel", ".old_edgelabel"); 415 | 416 | 417 | /////////////////////////////// 418 | // Force simulation 419 | // simulation model and parameters 420 | 421 | 422 | _simulation = simulation_start(center_f); 423 | // Associate the simulation with the data 424 | _simulation.nodes(_Nodes).on("tick", ticked); 425 | _simulation.force("link").links(_Links); 426 | _simulation.alphaTarget(0); 427 | 428 | //////////////////////// 429 | // handling simulation steps 430 | // move the nodes and links at each simulation step, following this rule: 431 | function ticked() { 432 | _links.attr('d', function (d) { 433 | if (use_curved_edges) { 434 | var dx = d.target.x - d.source.x; 435 | var dy = d.target.y - d.source.y; 436 | var dr = Math.sqrt((dx * dx + dy * dy) / d.linknum); 437 | return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y; 438 | } else { 439 | return "M" + d.source.x + "," + d.source.y + "L" + d.target.x + "," + d.target.y; 440 | } 441 | }); 442 | _nodes 443 | .attr("transform", function (d) { return "translate(" + d.x + ", " + d.y + ")"; }); 444 | 445 | edgepaths.attr('d', function (d) { 446 | if (use_curved_edges) { 447 | var dx = d.target.x - d.source.x; 448 | var dy = d.target.y - d.source.y; 449 | var dr = Math.sqrt((dx * dx + dy * dy) / d.linknum); 450 | return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y; 451 | } else { 452 | return "M" + d.source.x + "," + d.source.y + "L" + d.target.x + "," + d.target.y; 453 | } 454 | }); 455 | 456 | edgelabels.attr('transform', function (d) { 457 | if (d.target.x < d.source.x) { 458 | var bbox = this.getBBox(); 459 | 460 | var rx = bbox.x + bbox.width / 2; 461 | var ry = bbox.y + bbox.height / 2; 462 | return 'rotate(180 ' + rx + ' ' + ry + ')'; 463 | } 464 | else { 465 | return 'rotate(0)'; 466 | } 467 | }); 468 | } 469 | 470 | } 471 | 472 | 473 | function get_node_edges(node_id) { 474 | // Return the in and out edges of node with id 'node_id' 475 | var connected_edges = d3.selectAll(".edge").filter( 476 | function (item) { 477 | if (item.source == node_id || item.source.id == node_id) { 478 | return item; 479 | } 480 | else if (item.target == node_id || item.target.id == node_id) { 481 | return item; 482 | } 483 | }); 484 | return connected_edges; 485 | } 486 | 487 | 488 | var graph_events = (function () { 489 | ////////////////////////////////// 490 | // Handling mouse events 491 | 492 | function dragstarted(d) { 493 | if (!d3.event.active) _simulation.alphaTarget(0.3).restart(); 494 | d.fx = d.x; 495 | d.fy = d.y; 496 | } 497 | 498 | function dragged(d) { 499 | var connected_edges = get_node_edges(d.id); 500 | var f_connected_edges = connected_edges.filter("*:not(.active_edge)") 501 | if (f_connected_edges._groups[0].length == 0) { 502 | d.fx = d3.event.x; 503 | d.fy = d3.event.y; 504 | } 505 | else { 506 | f_connected_edges 507 | .style("stroke-width", function () { return parseInt(d3.select(this).attr("stroke-width")) + 2; }) 508 | .style("stroke-opacity", 1) 509 | .classed("blocking", true) 510 | } 511 | } 512 | 513 | function dragended(d) { 514 | if (!d3.event.active) _simulation.alphaTarget(0); 515 | d3.selectAll(".blocking") 516 | .style("stroke-width", function () { return d3.select(this).attr("stroke-width"); }) 517 | .style("stroke-opacity", function () { return d3.select(this).attr("stroke-opacity"); }) 518 | .classed("blocking", false) 519 | // d.fx = null; 520 | // d.fy = null; 521 | } 522 | 523 | function clicked(d) { 524 | d3.select(".focus_node").remove(); 525 | var input = document.getElementById("freeze-in"); 526 | var isChecked = input.checked; 527 | if (isChecked) infobox.display_info(d); 528 | else { 529 | _simulation.stop(); 530 | // remove the oldest links and nodes 531 | var stop_layer = layers.depth() - 1; 532 | _svg.selectAll(".old_node" + stop_layer).remove(); 533 | _svg.selectAll(".old_edge" + stop_layer).remove(); 534 | _svg.selectAll(".old_edgepath" + stop_layer).remove(); 535 | _svg.selectAll(".old_edgelabel" + stop_layer).remove(); 536 | infobox.display_info(d); 537 | graphioGremlin.click_query(d); 538 | console.log('event!!') 539 | } 540 | } 541 | 542 | 543 | function pin_it(d) { 544 | d3.event.stopPropagation(); 545 | var node_pin = d3.select(this); 546 | var pinned_node = d3.select(this.parentNode); 547 | //console.log('Pinned!') 548 | //console.log(pinned_node.classed("node")); 549 | if (pinned_node.classed("active_node")) { 550 | if (!pinned_node.classed("pinned")) { 551 | pinned_node.classed("pinned", true); 552 | console.log('Pinned!'); 553 | node_pin.attr("fill", "#000"); 554 | pinned_node.moveToFront(); 555 | } 556 | else { 557 | pinned_node.classed("pinned", false); 558 | console.log('Unpinned!'); 559 | node_pin.attr("fill", graphShapes.node_color); 560 | } 561 | } 562 | } 563 | 564 | return { 565 | dragstarted: dragstarted, 566 | dragged: dragged, 567 | dragended: dragended, 568 | clicked: clicked, 569 | pin_it: pin_it 570 | } 571 | 572 | })(); 573 | 574 | return { 575 | svg_handle: svg_handle, 576 | nodes: nodes, 577 | links: links, 578 | nodes_data: nodes_data, 579 | node_data: node_data, 580 | links_data: links_data, 581 | init: init, 582 | create_arrows: create_arrows, 583 | addzoom: addzoom, 584 | clear: clear, 585 | get_simulation_handle: get_simulation_handle, 586 | simulation_start: simulation_start, 587 | refresh_data: refresh_data, 588 | layers: layers, 589 | graph_events: graph_events 590 | }; 591 | 592 | })(); 593 | -------------------------------------------------------------------------------- /scripts/graphioGremlin.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 Benjamin RICAUD 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Interface between the visualization and the Gremlin server. 18 | 19 | var traversal_source = getUrlParameter('ts'); 20 | if (traversal_source == null) { 21 | traversal_source = "g" 22 | } 23 | 24 | var graphioGremlin = (function(){ 25 | "use strict"; 26 | 27 | var _node_properties = []; 28 | var _edge_properties = []; 29 | 30 | 31 | function get_node_properties(){ 32 | return _node_properties; 33 | } 34 | function get_edge_properties(){ 35 | return _edge_properties; 36 | } 37 | 38 | function create_single_command(query){ 39 | var equalIndex = query.indexOf("="); 40 | var semiColonIndex = query.indexOf(";"); 41 | if( equalIndex >= 0){ 42 | if(semiColonIndex < 0){ 43 | query = query.substring(equalIndex+1); 44 | } else { 45 | query = query.substring(equalIndex+1,semiColonIndex); 46 | } 47 | } 48 | var returnQuery = query.trim(); 49 | // if(returnQuery.endsWith(".toList();")){ 50 | // returnQuery = returnQuery+".toList();"; 51 | // } 52 | return returnQuery; 53 | } 54 | 55 | function get_graph_info(){ 56 | var gremlin_query_nodes = "nodes = " + traversal_source + ".V().limit(" + limit_graphinfo_request + ").groupCount().by(label);" 57 | var gremlin_query_edges = "edges = " + traversal_source + ".E().limit(" + limit_graphinfo_request + ").groupCount().by(label);" 58 | var gremlin_query_nodes_prop = "nodesprop = " + traversal_source + ".V().limit(" + limit_graphinfo_request + ").valueMap().select(keys).groupCount();" 59 | var gremlin_query_edges_prop = "edgesprop = " + traversal_source + ".E().limit(" + limit_graphinfo_request + ").valueMap().select(keys).groupCount();" 60 | 61 | var gremlin_query = gremlin_query_nodes+gremlin_query_nodes_prop 62 | +gremlin_query_edges+gremlin_query_edges_prop 63 | + "[nodes.toList(),nodesprop.toList(),edges.toList(),edgesprop.toList()]" 64 | // while busy, show we're doing something in the messageArea. 65 | $('#messageArea').html('

(loading)

'); 66 | var message = "" 67 | if(SINGLE_COMMANDS_AND_NO_VARS){ 68 | var node_label_query = create_single_command(gremlin_query_nodes); 69 | var edge_label_query = create_single_command(gremlin_query_edges); 70 | var node_prop_query = create_single_command(gremlin_query_nodes_prop); 71 | var edge_prop_query = create_single_command(gremlin_query_edges_prop); 72 | send_to_server(node_label_query, null, null, null, function(nodeLabels){ 73 | send_to_server(edge_label_query, null, null, null, function(edgeLabels){ 74 | send_to_server(node_prop_query, null, null, null, function(nodeProps){ 75 | send_to_server(edge_prop_query, null, null, null, function(edgeProps){ 76 | var combinedData = [nodeLabels, nodeProps, edgeLabels, edgeProps]; 77 | console.log("Combined data", combinedData); 78 | handle_server_answer(combinedData,'graphInfo',null,message); 79 | }); 80 | }); 81 | }); 82 | }); 83 | } else { 84 | send_to_server(gremlin_query,'graphInfo',null,message) 85 | } 86 | } 87 | 88 | 89 | 90 | function search_query() { 91 | // Preprocess query 92 | let input_string = $('#search_value').val(); 93 | let input_field = $('#search_field').val(); 94 | let label_field = $('#label_field').val(); 95 | let limit_field = $('#limit_field').val(); 96 | let search_type = $('#search_type').val(); 97 | //console.log(input_field) 98 | var filtered_string = input_string;//You may add .replace(/\W+/g, ''); to refuse any character not in the alphabet 99 | if (filtered_string.length>50) filtered_string = filtered_string.substring(0,50); // limit string length 100 | // Translate to Gremlin query 101 | let has_str = ""; 102 | if (label_field !== "") { 103 | has_str = ".hasLabel('" + label_field + "')"; 104 | } 105 | if (input_field !== "" && input_string !== "") { 106 | has_str += ".has('" + input_field + "',"; 107 | switch (search_type) { 108 | case "eq": 109 | if (isInt(input_string)){ 110 | has_str += filtered_string + ")" 111 | } else { 112 | has_str += "'" + filtered_string + "')" 113 | } 114 | break; 115 | case "contains": 116 | has_str += "textContains('" + filtered_string + "'))"; 117 | break; 118 | } 119 | } else if (limit_field === "" || limit_field < 0) { 120 | limit_field = node_limit_per_request; 121 | } 122 | 123 | let gremlin_query_nodes = "nodes = " + traversal_source + ".V()" + has_str; 124 | if (limit_field !== "" && isInt(limit_field) && limit_field > 0) { 125 | gremlin_query_nodes += ".limit(" + limit_field + ").toList();"; 126 | } else { 127 | gremlin_query_nodes += ".toList();"; 128 | } 129 | let gremlin_query_edges = "edges = " + traversal_source + ".V(nodes).aggregate('node').outE().as('edge').inV().where(within('node')).select('edge').toList();"; 130 | let gremlin_query_edges_no_vars = "edges = " + traversal_source + ".V()"+has_str+".aggregate('node').outE().as('edge').inV().where(within('node')).select('edge').toList();"; 131 | //let gremlin_query_edges_no_vars = "edges = " + traversal_source + ".V()"+has_str+".bothE();"; 132 | let gremlin_query = gremlin_query_nodes + gremlin_query_edges + "[nodes,edges]"; 133 | console.log(gremlin_query); 134 | 135 | // while busy, show we're doing something in the messageArea. 136 | $('#messageArea').html('

(loading)

'); 137 | // To display the queries in the message area: 138 | //var message_nodes = "

Node query: '"+gremlin_query_nodes+"'

"; 139 | //var message_edges = "

Edge query: '"+gremlin_query_edges+"'

"; 140 | //var message = message_nodes + message_edges; 141 | var message = ""; 142 | if (SINGLE_COMMANDS_AND_NO_VARS) { 143 | var nodeQuery = create_single_command(gremlin_query_nodes); 144 | var edgeQuery = create_single_command(gremlin_query_edges_no_vars); 145 | console.log("Node query: "+nodeQuery); 146 | console.log("Edge query: "+edgeQuery); 147 | send_to_server(nodeQuery, null, null, null, function(nodeData){ 148 | send_to_server(edgeQuery, null, null, null, function(edgeData){ 149 | var combinedData = [nodeData,edgeData]; 150 | handle_server_answer(combinedData, 'search', null, message); 151 | }); 152 | }); 153 | } else { 154 | send_to_server(gremlin_query,'search',null,message); 155 | } 156 | } 157 | 158 | function isInt(value) { 159 | return !isNaN(value) && 160 | parseInt(Number(value)) == value && 161 | !isNaN(parseInt(value, 10)); 162 | } 163 | function click_query(d) { 164 | var edge_filter = $('#edge_filter').val(); 165 | // Gremlin query 166 | //var gremlin_query = traversal_source + ".V("+d.id+").bothE().bothV().path()" 167 | // 'inject' is necessary in case of an isolated node ('both' would lead to an empty answer) 168 | var id = d.id; 169 | if(isNaN(id)){ // Add quotes if id is a string (not a number). 170 | id = '"'+id+'"'; 171 | } 172 | var gremlin_query_nodes = 'nodes = ' + traversal_source + '.V('+id+').as("node").both('+(edge_filter?'"'+edge_filter+'"':'')+').as("node").select(all,"node").inject(' + traversal_source + '.V('+id+')).unfold()' 173 | var gremlin_query_edges = "edges = " + traversal_source + ".V("+id+").bothE("+(edge_filter?"'"+edge_filter+"'":"")+")"; 174 | var gremlin_query = gremlin_query_nodes+'\n'+gremlin_query_edges+'\n'+'[nodes.toList(),edges.toList()]' 175 | // while busy, show we're doing something in the messageArea. 176 | $('#messageArea').html('

(loading)

'); 177 | var message = "

Query ID: "+ d.id +"

" 178 | if(SINGLE_COMMANDS_AND_NO_VARS){ 179 | var nodeQuery = create_single_command(gremlin_query_nodes); 180 | var edgeQuery = create_single_command(gremlin_query_edges); 181 | send_to_server(nodeQuery, null, null, null, function(nodeData){ 182 | send_to_server(edgeQuery, null, null, null, function(edgeData){ 183 | var combinedData = [nodeData,edgeData]; 184 | handle_server_answer(combinedData, 'click', d.id, message); 185 | }); 186 | }); 187 | } else { 188 | send_to_server(gremlin_query,'click',d.id,message); 189 | } 190 | } 191 | 192 | function send_to_server(gremlin_query,query_type,active_node,message, callback){ 193 | 194 | let server_address = $('#server_address').val(); 195 | let server_port = $('#server_port').val(); 196 | let COMMUNICATION_PROTOCOL = $('#server_protocol').val(); 197 | if (COMMUNICATION_PROTOCOL == 'REST'){ 198 | let server_url = "http://"+server_address+":"+server_port; 199 | run_ajax_request(gremlin_query,server_url,query_type,active_node,message,callback); 200 | } 201 | else if (COMMUNICATION_PROTOCOL == 'websocket'){ 202 | let server_url = "ws://"+server_address+":"+server_port+"/gremlin" 203 | run_websocket_request(gremlin_query,server_url,query_type,active_node,message,callback); 204 | } 205 | else { 206 | console.log('Bad communication protocol. Check configuration file. Accept "REST" or "websocket" .') 207 | } 208 | 209 | } 210 | 211 | ///////////////////////////////////////////////////////////////////////////////////////////////// 212 | // AJAX request for the REST API 213 | //////////////////////////////////////////////////////////////////////////////////////////////// 214 | function run_ajax_request(gremlin_query,server_url,query_type,active_node,message, callback){ 215 | // while busy, show we're doing something in the messageArea. 216 | $('#messageArea').html('

(loading)

'); 217 | 218 | // Get the data from the server 219 | $.ajax({ 220 | type: "POST", 221 | accept: "application/json", 222 | //contentType:"application/json; charset=utf-8", 223 | url: server_url, 224 | //headers: GRAPH_DATABASE_AUTH, 225 | timeout: REST_TIMEOUT, 226 | data: JSON.stringify({"gremlin" : gremlin_query}), 227 | success: function(data, textStatus, jqXHR){ 228 | var Data = data.result.data; 229 | //console.log(Data) 230 | //console.log("Results received") 231 | if(callback){ 232 | callback(Data); 233 | } else { 234 | handle_server_answer(Data,query_type,active_node,message); 235 | } 236 | }, 237 | error: function(result, status, error){ 238 | console.log("Connection failed. "+status); 239 | 240 | // This will hold all error messages, to be printed in the 241 | // output area. 242 | let msgs = []; 243 | 244 | if (query_type == 'editGraph'){ 245 | msgs.push('Problem accessing the database using REST at ' + server_url); 246 | msgs.push('Message: ' + status + ', ' + error); 247 | msgs.push('Possible cause: creating an edge with bad node ids ' + 248 | '(linking nodes not existing in the DB).'); 249 | } else { 250 | msgs.push('Can\'t access database using REST at ' + server_url); 251 | msgs.push('Message: ' + status + ', ' + error); 252 | msgs.push('Check the server configuration ' + 253 | 'or try increasing the REST_TIMEOUT value in the config file.'); 254 | } 255 | 256 | // If a MalformedQueryException is received, user might be 257 | // trying to reach an Amazon Neptune DB. Point them to the 258 | // config file as a probable cause. 259 | if (result.status === 400 260 | && SINGLE_COMMANDS_AND_NO_VARS === false 261 | && result.hasOwnProperty('responseJSON') 262 | && result.responseJSON.code === 'MalformedQueryException') { 263 | msgs.push('If connecting to an Amazon Neptune databse, ensure that ' + 264 | 'SINGLE_COMMANDS_AND_NO_VARS is set to true in the config file.'); 265 | } 266 | 267 | $('#outputArea').html(msgs.map(function (i) {return '

' + i + '

'}).join('')); 268 | $('#messageArea').html(''); 269 | } 270 | }); 271 | } 272 | 273 | ////////////////////////////////////////////////////////////////////////////////////////////////////// 274 | // Websocket connection 275 | ///////////////////////////////////////////////////////////////////////////////////////////////////// 276 | function run_websocket_request(gremlin_query,server_url,query_type,active_node,message,callback){ 277 | $('#messageArea').html('

(loading)

'); 278 | 279 | var msg = { "requestId": uuidv4(), 280 | "op":"eval", 281 | "processor":"", 282 | "args":{"gremlin": gremlin_query, 283 | "bindings":{}, 284 | "language":"gremlin-groovy"}} 285 | 286 | var data = JSON.stringify(msg); 287 | 288 | var ws = new WebSocket(server_url); 289 | ws.onopen = function (event){ 290 | ws.send(data,{ mask: true}); 291 | }; 292 | ws.onerror = function (err){ 293 | console.log('Connection error using websocket'); 294 | console.log(err); 295 | if (query_type == 'editGraph'){ 296 | $('#outputArea').html("

Connection error using websocket

" 297 | +"

Problem accessing "+server_url+ "

"+ 298 | "

Possible cause: creating a edge with bad node ids "+ 299 | "(linking nodes not existing in the DB).

"); 300 | $('#messageArea').html(''); 301 | } else {$('#outputArea').html("

Connection error using websocket

" 302 | +"

Cannot connect to "+server_url+ "

"); 303 | $('#messageArea').html(''); 304 | } 305 | 306 | }; 307 | ws.onmessage = function (event){ 308 | var response = JSON.parse(event.data); 309 | var code=Number(response.status.code) 310 | if(!isInt(code) || code<200 || code>299) { 311 | $('#outputArea').html(response.status.message); 312 | $('#messageArea').html("Error retrieving data"); 313 | return 1; 314 | } 315 | var data = response.result.data; 316 | if (data == null){ 317 | // No response data expected for flush query, so just validate status code. 318 | if (query_type == 'flushGraph' && response.status.code == 204) { 319 | $('#outputArea').html("

Successfully flushed existing DB data.

"); 320 | $('#messageArea').html(''); 321 | return 322 | } 323 | 324 | if (query_type == 'editGraph'){ 325 | $('#outputArea').html(response.status.message); 326 | $('#messageArea').html('Could not write data to DB.' + 327 | "

Possible cause: creating a edge with bad node ids "+ 328 | "(linking nodes not existing in the DB).

"); 329 | return 1; 330 | } else { 331 | //$('#outputArea').html(response.status.message); 332 | //$('#messageArea').html('Server error. No data.'); 333 | //return 1; 334 | } 335 | } 336 | //console.log(data) 337 | //console.log("Results received") 338 | if(callback){ 339 | callback(data); 340 | } else { 341 | handle_server_answer(data,query_type,active_node,message); 342 | } 343 | }; 344 | } 345 | 346 | // Generate uuid for websocket requestId. Code found here: 347 | // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript 348 | function uuidv4() { 349 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { 350 | var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); 351 | return v.toString(16); 352 | }); 353 | } 354 | 355 | ////////////////////////////////////////////////////////////////////////////////////////////////// 356 | function handle_server_answer(data,query_type,active_node,message){ 357 | let COMMUNICATION_METHOD = $('#communication_method').val(); 358 | if (query_type == 'editGraph'){ 359 | //console.log(data) 360 | $('#outputArea').html("

Data successfully written to the DB.

"); 361 | $('#messageArea').html(''); 362 | return // TODO handle answer to check if data has been written 363 | } 364 | //console.log(COMMUNICATION_METHOD) 365 | if (COMMUNICATION_METHOD == 'GraphSON3'){ 366 | //console.log(data) 367 | data = graphson3to1(data); 368 | var arrange_data = arrange_datav3; 369 | } else if (COMMUNICATION_METHOD == 'GraphSON2'){ 370 | var arrange_data = arrange_datav2; 371 | } else { 372 | console.log('Bad communication protocol. Accept "GraphSON2" or "GraphSON3".' 373 | +' Using default GraphSON3.') 374 | data = graphson3to1(data); 375 | var arrange_data = arrange_datav3; 376 | } 377 | if (!(0 in data)) { 378 | message = 'No data. Check the communication protocol. (Try changing Gremlin version to 3.3.*).' 379 | console.log(message) 380 | $('#outputArea').html(message); 381 | $('#messageArea').html(''); 382 | 383 | } 384 | if (query_type=='graphInfo'){ 385 | infobox.display_graph_info(data); 386 | _node_properties = make_properties_list(data[1][0]); 387 | _edge_properties = make_properties_list(data[3][0]); 388 | change_nav_bar(_node_properties,_edge_properties); 389 | display_properties_bar(_node_properties,'nodes','Node properties:'); 390 | display_properties_bar(_edge_properties,'edges','Edge properties:'); 391 | display_color_choice(_node_properties,'nodes','Node color by:'); 392 | } else { 393 | //console.log(data); 394 | var graph = arrange_data(data); 395 | //console.log(graph) 396 | if (query_type=='click') var center_f = 0; //center_f=0 mean no attraction to the center for the nodes 397 | else if (query_type=='search') var center_f = 1; 398 | else return; 399 | graph_viz.refresh_data(graph,center_f,active_node); 400 | } 401 | 402 | $('#outputArea').html(message); 403 | $('#messageArea').html(''); 404 | } 405 | 406 | 407 | 408 | ////////////////////////////////////////////////////////////////////////////////////////////////// 409 | function make_properties_list(data){ 410 | var prop_dic = {}; 411 | for (var prop_str in data){ 412 | prop_str = prop_str.replace(/[\[\ \"\'\]]/g,''); // get rid of symbols [,",',] and spaces 413 | var prop_list = prop_str.split(','); 414 | //prop_list = prop_list.map(function (e){e=e.slice(1); return e;}); 415 | for (var prop_idx in prop_list){ 416 | prop_dic[prop_list[prop_idx]] = 0; 417 | } 418 | } 419 | var properties_list = []; 420 | for (var key in prop_dic){ 421 | properties_list.push(key); 422 | } 423 | return properties_list; 424 | } 425 | 426 | /////////////////////////////////////////////////// 427 | function idIndex(list,elem) { 428 | // find the element in list with id equal to elem 429 | // return its index or null if there is no 430 | for (var i=0;i