javascript - Pack layout isn't binding to updated dataset properly -


i have pack layout chart displays firms , users web application. chart has separate dataset symbolizing different periods of time.

example -

  1. all users
  2. only users logged in within last week
  3. only users logged in within last 30 days
  4. ...

my dataset structured this-

{   all: {     name: "web app",     children: [       {         name: "firm 1",         size: 2,         children: [           {             name: "cathy",             size: 1           },           {             name: "paula",             size: 1           }         ]       },       {         name: "firm 2",         size: 1,         children: [           {             name: "sean",             size: 1           }         ]       },       {         name: "firm 3",         size: 2,         children: [           {             name: "jennifer",             size: 1           },           {             name: "amy",             size: 1           }         ]       }     ]   },   loggedin7day: {     name: "web app",     children: [       {         name: "firm 1",         size: 1,         children: [           {             name: "paula",             size: 1           }         ]       },       {         name: "firm 3",         size: 1,         children: [           {             name: "kristin",             size: 1           }         ]       }     ]   } } 

i cannot figure out how bind circles after updating dataset.

after dataset updated of parent nodes bound child nodes , child nodes bound parents.

here how update dataset , bind circles-

//change property pack based on filter switch (filter) {     case "1":         root = alldata.loggedin90day;         break;     case "2":         root = alldata.loggedin30day;         break;     case "3":         root = alldata.loggedin7day;         break;     default:         root = alldata.all; }  circle = svg.selectall(".node")     .data(pack.nodes(root));  circle     .enter()     .append("circle");  circle     .transition()     .duration(1500)     .attr("class", function (d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; })     .attr("transform", function (d) { return "translate(" + (d.x - view[0]) * k + "," + (d.y - view[1]) * k + ")"; })     .attr("r", function (d) { return d.r * k; });  circle.exit()     .transition()     .remove(); 

i have feeling i'm missing simple cannot figure out.

here js-fiddle showing problem - https://jsfiddle.net/t989hfp9/

any appreciated!!!!

the problem nodes didn't have unique identifier.

i added id property nodes in dataset -

{   all: {     name: "web app",     id: 0,     children: [       {         name: "firm 1",         id: 1;         size: 2,         children: [           {             name: "cathy",             id: 2,             size: 1           },           {             name: "paula",             id: 3,             size: 1           }         ]       },       {         name: "firm 2",         size: 1,         id: 4;         children: [           {             name: "sean",             id: 5,             size: 1           }         ]       },       {         name: "firm 3",         size: 2,         id: 7,         children: [           {             name: "jennifer",             id: 8,             size: 1           },           {             name: "amy",             id: 9,             size: 1           }         ]       }     ]   },   loggedin7day: {     name: "web app",     id: 0,     children: [       {         name: "firm 1",         id: 1;         size: 1,         children: [           {             name: "paula",             id: 3,             size: 1           }         ]       },       {         name: "firm 3",         size: 1,         id: 7;         children: [           {             name: "amy",             id: 9,             size: 1           }         ]       }     ]   } } 

then specify property use unique identifier when bind dataset pack -

circle = svg.selectall("circle")     .data(pack.nodes(root), function (d) { return d.id; });  

here fixed fiddle - https://jsfiddle.net/ferlin_husky/wzuvob6m/


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -