HTML
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<script type="application/json" id="mis">
{"directed": false, "multigraph": false, "graph": {},
"nodes":
[{"color": 1, "id": "seats"},
{"color": 1, "id": "admin"},
{"color": 1, "id": "ticket_flights"},
{"color": 1, "id": "flights"},
{"color": 1, "id": "airports_data"},
{"color": 1, "id": "bookings"},
{"color": 1, "id": "boarding_passes"},
{"color": 1, "id": "tickets"},
{"color": 1, "id": "pg_statistic"},
{"color": 1, "id": "pg_type"},
{"color": 10, "id": "PUBLIC"}, {"color": 1, "id": "aircrafts_data"}, {"color": 1, "id": "pg_policy"}, {"color": 1, "id": "pg_authid"}, {"color": 1, "id": "pg_user_mapping"}, {"color": 1, "id": "pg_subscription"}, {"color": 1, "id": "pg_attribute"}, {"color": 1, "id": "pg_proc"}, {"color": 1, "id": "pg_class"}, {"color": 1, "id": "pg_attrdef"}, {"color": 1, "id": "pg_constraint"}, {"color": 1, "id": "pg_inherits"}, {"color": 1, "id": "pg_index"}, {"color": 1, "id": "pg_operator"}, {"color": 1, "id": "pg_opfamily"}, {"color": 1, "id": "pg_opclass"}, {"color": 1, "id": "pg_am"}, {"color": 1, "id": "pg_amop"}, {"color": 1, "id": "pg_amproc"}, {"color": 1, "id": "pg_language"}, {"color": 1, "id": "pg_largeobject_metadata"}, {"color": 1, "id": "pg_aggregate"}, {"color": 1, "id": "pg_statistic_ext"}, {"color": 1, "id": "pg_rewrite"}, {"color": 1, "id": "pg_trigger"}, {"color": 1, "id": "pg_event_trigger"}, {"color": 1, "id": "pg_description"}, {"color": 1, "id": "pg_cast"}, {"color": 1, "id": "pg_enum"}, {"color": 1, "id": "pg_namespace"}, {"color": 1, "id": "pg_conversion"}, {"color": 1, "id": "pg_depend"}, {"color": 1, "id": "pg_database"}, {"color": 1, "id": "pg_db_role_setting"}, {"color": 1, "id": "pg_tablespace"}, {"color": 1, "id": "pg_pltemplate"}, {"color": 1, "id": "pg_auth_members"}, {"color": 1, "id": "pg_shdepend"}, {"color": 1, "id": "pg_shdescription"}, {"color": 1, "id": "pg_ts_config"},...
JavaScript
//Constants for the SVG
var width = 500,
height = 500;
//Set up the colour scale
var color = d3.scale.category20();
//Set up the force layout
var force = d3.layout.force()
.charge(-120)
.linkDistance(30)
.size([width, height]);
//Append a SVG to the body of the html page. Assign this SVG as an object to svg
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.on("dblclick", threshold);
//Read the data from the mis element
var mis = document.getElementById('mis').innerHTML;
graph = JSON.parse(mis);
graphRec=JSON.parse(JSON.stringify(graph)); //Add this line
//Creates the graph data structure out of the json data
force.nodes(graph.nodes)
.links(graph.links)
.start();
//Create all the line svgs but without locations yet
var link = svg.selectAll(".link")
.data(graph.links)
.enter().append("line")
.attr("class", "link")
.style("stroke-width", function (d) {
return Math.sqrt(d.value);
});
//Do the same with the circles for the nodes - no
var node = svg.selectAll(".node")
.data(graph.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("r", 8)
.style("fill", function (d) {
return color(d.group);
})
.call(force.drag);
//Now we are giving the SVGs co-ordinates - the force layout is generating the co-ordinates which this code is using to update the attributes of the SVG elements
force.on("tick", function () {
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;
});
});
//---Insert-------
//adjust threshold
function threshold(thresh) {
graph.links.splice(0, graph.links.length);
for (var i =...