<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Multi parent hierarchy - custom visual D3.js in Custom Visuals Development Discussion</title>
    <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Multi-parent-hierarchy-custom-visual-D3-js/m-p/2185237#M4048</link>
    <description>&lt;P&gt;Hello Guys !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I create hierarchy table and what I want to achieve is something like this below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know how to build hierarchy level for two categories and draw it, but I have a problem with 3 or more categories.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset is flat array of objects. Every object has &lt;EM&gt;id&lt;/EM&gt; and &lt;EM&gt;parentId&lt;/EM&gt;. 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 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is my stratify function:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      const root = d3
        .stratify()
        .id(function (d: any) {
          return d.name;
        })
        .parentId(function (d: any) {
          return d.parentId;
        })(items);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my dataset transform when there is 3 categories:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    yAxis.map((d, i) =&amp;gt; {
      if (yAxis.length === 3) {
        if (i === 2) {
          const children = data.filter(
            (d) =&amp;gt; d.name === d.yAxis[d.yAxis.length - 1]
          );
          uniqArray.push(children);
        } else if (i === 1) {
          const children = data.filter((d) =&amp;gt; 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) =&amp;gt; !d.parentId);
          uniqArray.push(_.uniqBy(children, (d) =&amp;gt; d.name));
        }

        return [..._.flatten(uniqArray), { name: "root" }];
      }
    });

    return yAxis.length &amp;gt; 1
      ? [..._.flatten(uniqArray), { name: "root" }]
      : [...data, { name: "root" }];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you ever face that problem ? Or maybe you have some solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will be grateful for any advice how to do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 11 Nov 2021 12:29:21 GMT</pubDate>
    <dc:creator>filipwydra</dc:creator>
    <dc:date>2021-11-11T12:29:21Z</dc:date>
    <item>
      <title>Multi parent hierarchy - custom visual D3.js</title>
      <link>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Multi-parent-hierarchy-custom-visual-D3-js/m-p/2185237#M4048</link>
      <description>&lt;P&gt;Hello Guys !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I create hierarchy table and what I want to achieve is something like this below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know how to build hierarchy level for two categories and draw it, but I have a problem with 3 or more categories.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset is flat array of objects. Every object has &lt;EM&gt;id&lt;/EM&gt; and &lt;EM&gt;parentId&lt;/EM&gt;. 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 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is my stratify function:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;      const root = d3
        .stratify()
        .id(function (d: any) {
          return d.name;
        })
        .parentId(function (d: any) {
          return d.parentId;
        })(items);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my dataset transform when there is 3 categories:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    yAxis.map((d, i) =&amp;gt; {
      if (yAxis.length === 3) {
        if (i === 2) {
          const children = data.filter(
            (d) =&amp;gt; d.name === d.yAxis[d.yAxis.length - 1]
          );
          uniqArray.push(children);
        } else if (i === 1) {
          const children = data.filter((d) =&amp;gt; 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) =&amp;gt; !d.parentId);
          uniqArray.push(_.uniqBy(children, (d) =&amp;gt; d.name));
        }

        return [..._.flatten(uniqArray), { name: "root" }];
      }
    });

    return yAxis.length &amp;gt; 1
      ? [..._.flatten(uniqArray), { name: "root" }]
      : [...data, { name: "root" }];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you ever face that problem ? Or maybe you have some solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will be grateful for any advice how to do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 12:29:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Custom-Visuals-Development/Multi-parent-hierarchy-custom-visual-D3-js/m-p/2185237#M4048</guid>
      <dc:creator>filipwydra</dc:creator>
      <dc:date>2021-11-11T12:29:21Z</dc:date>
    </item>
  </channel>
</rss>

