javascript - d3.js filter force layout by node attributes -


my goal add filter force layout graph based on attributes of nodes, choose "type". have implement filter function, not working. have @ , suggest fix?

here jsfiddle regarding question:

https://jsfiddle.net/marcelius/j5lmmrcg/1/

     //-----------------filter start   // call method create filter   createfilter();    // method create filter   function createfilter()   {       d3.select(".filtercontainer").selectall("div")           .data(["entreprise", "academique", "unknown"])           .enter()           .append("div")           .attr("class", "checkbox-container")           .append("label")           .each(function(d) {               // create checkbox each data               d3.select(this)                   .append("input")                   .attr("type", "checkbox")                   .attr("id", function(d) {return "chk_" + d;})                   .attr("checked", true)                   .on("click", function(d, i) {                       // register on click event                       var lvisibility = this.checked? "visible":"hidden";                       filtergraph(d, lvisibility);                   })               d3.select(this).append("span")                   .text(function(d){return d;});           });    }    // method filter graph   function filtergraph(atype, avisibility)   {       // change visibility of connection path       link.style("visibility", function(o) {           var originviz = $(this).css("visibility");           return o.type === atype ? avisibility : originviz;       });         labellink.style("visibility", function(o, i) {           var cachenode = true;           pathlink.each(function(d, i){               if(d.source.id === o || d.target.id === o)               {                   if($(this).css("visibility") === "visible")                   {                       cachenode = false;                       // need show text circle                       d3.select(d3.selectall(".link")[0][i]).style("visibility","visible");                       return "visible";                   }               }           });           if(cachenode)           {               // need hide text circle               d3.select(d3.selectall(".nodetext")[0][i]).style("visibility","hidden");               return "hidden";           }       });   } //-----------------filter end 

by way, code showing force layout on local machine, show on jsfiddle, dataset needs wired up, don't know how in jsfiddle, have added data.json file google drive link , pastebin link in external resources. if can it, please update link , share it.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -