X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Femuvim%2Fdashboard%2Fjs%2Fgraph.js;h=fff88725519a576d2d0f4180e03e04409daa9fa9;hb=cc77502a9c6ff5f4e3676bb543861ada03bdeb8e;hp=58588334d4de1b73823c6dd22a5cc0af373f506c;hpb=807be58fa7a13781cdd895a9ab4694c426c00395;p=osm%2Fvim-emu.git diff --git a/src/emuvim/dashboard/js/graph.js b/src/emuvim/dashboard/js/graph.js old mode 100755 new mode 100644 index 5858833..fff8872 --- a/src/emuvim/dashboard/js/graph.js +++ b/src/emuvim/dashboard/js/graph.js @@ -1,3 +1,46 @@ +/* + Copyright (c) 2017 SONATA-NFV, IMEC and Paderborn University + ALL RIGHTS RESERVED. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Neither the name of the SONATA-NFV, Paderborn University + nor the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written + permission. + + This work has been performed in the framework of the SONATA project, + funded by the European Commission under Grant number 671517 through + the Horizon 2020 and 5G-PPP programmes. The authors would like to + acknowledge the contributions of their colleagues of the SONATA + partner consortium (www.sonata-nfv.eu). +*/ + + //functions to make the nodes stick after they have been manually maoved + function tick() { + link.attr("x1", function(d) { return d.source.x; }) + .attr("y1", function(d) { return d.source.y; }) + .attr("x2", function(d) { return d.target.x; }) + .attr("y2", function(d) { return d.target.y; }); + + node.attr("cx", function(d) { return d.x; }) + .attr("cy", function(d) { return d.y; }); + } + + function dragstart(d) { + d3.select(this).classed("fixed", d.fixed = true); + } + var width = 960, height = 500, color = d3.scale.category10(); @@ -10,9 +53,13 @@ var force = d3.layout.force() .gravity(0.05) .distance(100) .charge(-100) - .size([width, height]); + .size([width, height]) + .on("tick", tick); + +var drag = force.drag() + .on("dragstart", dragstart); -d3.json("http://127.0.0.1:5001/restapi/network/d3jsgraph", function(error, json) { +d3.json("/restapi/network/d3jsgraph", function(error, json) { if (error) throw error; force @@ -22,14 +69,14 @@ d3.json("http://127.0.0.1:5001/restapi/network/d3jsgraph", function(error, json) var link = svg.selectAll(".link") .data(json.links) - .enter().append("line") + .enter().append("line") .attr("class", "link"); var node = svg.selectAll(".node") .data(json.nodes) .enter().append("g") .attr("class", "node") - .call(force.drag) + .call(drag); node.append("circle") .attr("r", 10) @@ -50,4 +97,4 @@ d3.json("http://127.0.0.1:5001/restapi/network/d3jsgraph", function(error, json) }); -}); \ No newline at end of file +});