javascript

  • I have a drop down that let’s a user chose for Depth values between 1 to 5 and graph gets filtered .
  • Stack Overflow works best with JavaScript enabled
  • function isUnique(id, nodes) { for (var i = 0; i < nodes.length; i++) { if (nodes[i].id == id) { return false; } } return true; } var linksData = {}; setTimeout(function(){ linksData = d3.selectAll("line").data(); console.log(linksData); },200); var elem = document.getElementById('select_ID'); elem.addEventListener("change", onSelectChange); function onSelectChange(){ var value = this.value; var fdata = filteredData(value); d3.select('#Network_graph').
  • sign up log in tour help
  • Browse other questions tagged javascript d3.js or ask your own question .


@ng_real_ninja: Better way of handling the graph data while changing through the dropdown in d3.js force… …

I have a d3.js forced directed graph that has below properties for nodes and links:

nodes:d.type,d.id links: d.depth,d,Amount,d.SendTime,d.Paytime

I have a drop down that let’s a user chose for Depth values between 1 to 5 and graph gets filtered accordingly.

Now the corresponding javascript code:

function isUnique(id, nodes) { for (var i = 0; i < nodes.length; i++) { if (nodes[i].id == id) { return false; } } return true; } var linksData = {}; setTimeout(function(){ linksData = d3.selectAll("line").data(); console.log(linksData); },200); var elem = document.getElementById('select_ID'); elem.addEventListener("change", onSelectChange); function onSelectChange(){ var value = this.value; var fdata = filteredData(value); d3.select('#Network_graph').selectAll("*").remove(); makeGraph("#Network_graph", fdata); } function filteredData(value){ var filtered_data = {}; var nodes = []; var links = []; linksData.filter(function(d, i) { if (d.depth <= value) { if (isUnique(d.source.id, nodes)) { nodes.push(d.source); } if (isUnique(d.target.id, nodes)) { nodes.push(d.target); } links.push(d); } }); filtered_data.links = links; filtered_data.nodes = nodes; filtered_data.nodetype = final_data.nodetype; return filtered_data; } I am storing all the necessary graph data with linksData = d3.selectAll(“line”).data(); within the setTimeout function with a 200ms . This works in the fiddle but not when I try it locally. Looking for a better way to store this linksData. Below is the fiddle The first snippet below compiles, but the second doesn’t. Why?

javascript

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.