Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
filipwydra
Frequent Visitor

Multi parent hierarchy - custom visual D3.js

Hello Guys !

 

I create hierarchy table and what I want to achieve is something like this below:

 

filipwydra_0-1636632720500.png

 

I know how to build hierarchy level for two categories and draw it, but I have a problem with 3 or more categories. 

My dataset is flat array of objects. Every object has id and parentId. I'm using d3.stratify() to make hierarchy nodes. It works properly but once I add third category which has two or more parents it crush. I found somewhere that hierarchy where children have many parents is not hierarchy anymore but graph. Is it right ?

 

 This is my stratify function:

      const root = d3
        .stratify()
        .id(function (d: any) {
          return d.name;
        })
        .parentId(function (d: any) {
          return d.parentId;
        })(items);

 

This is my dataset transform when there is 3 categories: 

    yAxis.map((d, i) => {
      if (yAxis.length === 3) {
        if (i === 2) {
          const children = data.filter(
            (d) => d.name === d.yAxis[d.yAxis.length - 1]
          );
          uniqArray.push(children);
        } else if (i === 1) {
          const children = data.filter((d) => d.name === d.yAxis[1]);

          const filteredChildren = children.filter(function (a) {
            var key = a.name + "|" + a.parentName;
            if (!this[key]) {
              this[key] = true;
              return true;
            }
          }, Object.create(null));

          uniqArray.push(filteredChildren);
        } else {
          const children = data.filter((d) => !d.parentId);
          uniqArray.push(_.uniqBy(children, (d) => d.name));
        }

        return [..._.flatten(uniqArray), { name: "root" }];
      }
    });

    return yAxis.length > 1
      ? [..._.flatten(uniqArray), { name: "root" }]
      : [...data, { name: "root" }];

 

Did you ever face that problem ? Or maybe you have some solution.

 

I will be grateful for any advice how to do this.

 

Thanks!

0 REPLIES 0

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.