title: Hierarchical Edge Cluster Group Name
body: <p>I have the following cluster graph which works mostly fine. AT a guess it's something to do with how I package things together?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var diameter = 900,
    radius = diameter / 2,
    innerRadius = radius - 180;
  
  var cluster = d3.cluster()
    .size([360, innerRadius]);
  
  
  var line = d3.radialLine()
    .curve(d3.curveBundle.beta(0.2))
    .radius(function(d) {
      return d.y;
    })
    .angle(function(d) {
      return d.x / 180 * Math.PI;
    });
  
  var svg = d3.select("body").append("svg")
    .attr("width", diameter)
    .attr("height", diameter)
    .append("g")
    .attr("transform", "translate(" + radius + "," + radius + ")");
  
  var link = svg.append("g").selectAll(".link"),
    node = svg.append("g").selectAll(".node");
  
  let samlDeps = [
    'dsi.backend.SAML-ASSERTIONS',
    'dsi.frontend.OIDC'
  ];
  
  var arc = d3.arc()
    .innerRadius(10)
    .outerRadius(15);
  
  var classes = [{
      'name': 'dsi.frontend.HELP',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.frontend.PROFILE',
        'dsi.frontend.INTERACTIONS',
        'dsi.frontend.SERVICES',
        'dsi.frontend.SUPPORT',
        'dsi.backend.APPLICATIONS',
        'dsi.cache.REDIS',
        'dsi.frontend.CDN',
      ]
    },
    {
      'name': 'dsi.frontend.INTERACTIONS',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.frontend.PROFILE',
        'dsi.frontend.HELP',
        'dsi.frontend.SERVICES',
        'dsi.frontend.SUPPORT',
        'dsi.db.DIRECTORIES',
        'dsi.frontend.OIDC',
        'dsi.backend.DEVICES',
        'dsi.backend.ORGANISATIONS',
        'dsi.backend.APPLICATIONS',
        'dsi.backend.ACCESS',
        'dsi.cache.REDIS',
        'dsi.frontend.CDN',
      ]
    },
    {
      'name': 'dsi.frontend.MANAGE',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.frontend.INTERACTIONS',
        'dsi.frontend.HELP',
        'dsi.frontend.SERVICES',
        'dsi.frontend.PROFILE',
        'dsi.backend.ACCESS',
        'dsi.backend.APPLICATIONS',
        'dsi.backend.DIRECTORIES',
        'dsi.db.ORGANISATION',
        'dsi.cache.SEARCH',
        'dsi.cache.REDIS',
        'dsi.frontend.CDN',
        'dsi.frontend.OIDC',
      ]
    },
    {
      'name': 'dsi.frontend.OIDC',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.backend.DIRECTORIES',
        'dsi.cache.REDIS',
        'dsi.frontend.HELP',
        'dsi.db.DIRECTORIES',
        'dsi.db.ORGANISATION',
        'dsi.backend.APPLICATIONS',
        'dsi.frontend.CDN',
        'dsi.frontend.INTERACTIONS',
      ]
    },
    {
      'name': 'dsi.frontend.PUBLIC-API',
      'size': 1000,
      'imports': [
        'dsi.cache.REDIS',
        'dsi.backend.DIRECTORIES',
        'dsi.backend.APPLICATIONS',
        'dsi.backend.ACCESS',
        'dsi.backend.ORGANISATIONS',
      ]
    },
    {
      'name': 'dsi.frontend.PROFILE',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.frontend.INTERACTIONS',
        'dsi.frontend.HELP',
        'dsi.frontend.SERVICES',
        'dsi.frontend.SUPPORT',
        'dsi.backend.DIRECTORIES',
        'dsi.backend.ORGANISATIONS',
        'dsi.backend.APPLICATIONS',
        'dsi.backend.ACCESS',
        'dsi.cache.SEARCH',
        'dsi.frontend.CDN',
        'dsi.frontend.OIDC',
      ]
    },
    {
      'name': 'dsi.frontend.SUPPORT',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.frontend.PROFILE',
        'dsi.frontend.INTERACTIONS',
        'dsi.frontend.HELP',
        'dsi.frontend.SERVICES',
        'dsi.frontend.OIDC',
        'dsi.cache.SEARCH',
        'dsi.cache.REDIS',
        'dsi.backend.DIRECTORIES',
        'dsi.backend.ORGANISATIONS',
        'dsi.backend.DEVICES',
        'dsi.backend.APPLICATIONS',
        'dsi.backend.ACCESS',
        'dsi.frontend.CDN',
      ]
    },
    {
      'name': 'dsi.frontend.SERVICES',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.frontend.PROFILE',
        'dsi.frontend.INTERACTIONS',
        'dsi.frontend.HELP',
        'dsi.frontend.SUPPORT',
        'dsi.backend.DIRECTORIES',
        'dsi.backend.ORGANISATIONS',
        'dsi.backend.ACCESS',
        'dsi.backend.APPLICATIONS',
        'dsi.cache.SEARCH',
        'dsi.db.ORGANISATION',
        'dsi.frontend.OIDC',
        'dsi.cache.REDIS',
        'dsi.db.DIRECTORIES',
        'dsi.db.ORGANISATION',
        'dsi.frontend.CDN',
      ]
    },
    {
      'name': 'dsi.frontend.CDN',
      'size': 1000,
      'imports': []
    },
  
    {
      'name': 'dsi.backend.ACCESS',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.db.ORGANISATION',
        'dsi.cache.REDIS',
      ]
    },
    {
      'name': 'dsi.backend.APPLICATIONS',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.db.ORGANISATION',
        'dsi.db.ORGANISATION',
      ]
    },
    {
      'name': 'dsi.backend.SAML-ASSERTIONS',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.backend.DIRECTORIES',
        'dsi.backend.ACCESS',
        'dsi.backend.APPLICATIONS',
      ]
    },
    {
      'name': 'dsi.backend.DEVICES',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.frontend.CDN',
        'dsi.db.DEVICES',
      ]
    },
    {
      'name': 'dsi.backend.DIRECTORIES',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.db.DIRECTORIES',
        'dsi.backend.APPLICATIONS',
        'dsi.cache.REDIS',
      ]
    },
    {
      'name': 'dsi.backend.ORGANISATIONS',
      'size': 1000,
      'imports': [
        'dsi.db.AUDIT',
        'dsi.db.ORGANISATION',
        'dsi.backend.DIRECTORIES',
        'dsi.cache.REDIS',
      ]
    },
    {
      'name': 'dsi.backend.sa',
      'size': 1000,
      'imports': [
        'dsi.backend.APPLICATIONS',
      ]
    },
  
    {
      'name': 'dsi.saml.A-FORMS',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.ASP',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.COLLECT',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.DQT',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.GIAS',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.INFORMATION-EXCHANGE',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.KEY-TO-SUCCESS',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.KEY-TO-SUCCESS_SECURE-ACCESS',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.psp',
      'size': 1000,
      'imports': samlDeps
    },
    {
      'name': 'dsi.saml.SCHOOL-2-SCHOOL',
      'size': 1000,
      'imports': samlDeps
    },
  
    {
      'name': 'dsi.db.AUDIT',
      'size': 1000,
      'imports': []
    },
    {
      'name': 'dsi.db.DIRECTORIES',
      'size': 1000,
      'imports': []
    },
    {
      'name': 'dsi.db.ORGANISATION',
      'size': 1000,
      'imports': []
    },
    {
      'name': 'dsi.db.DEVICES',
      'size': 1000,
      'imports': []
    },
  
    {
      'name': 'dsi.cache.REDIS',
      'size': 1000,
      'imports': []
    },
    {
      'name': 'dsi.cache.SEARCH',
      'size': 1000,
      'imports': []
    },
  ];
  
  var root = packageHierarchy(classes)
    .sum(function(d) {
      return d.size;
    });
  
  cluster(root);
  
  link = link
    .data(packageImports(root.leaves()))
    .enter().append("path")
    .each(function(d) {
      d.source = d[0], d.target = d[d.length - 1];
    })
    .attr("class", "link")
    .attr("d", line);
  
  node = node
    .data(root.leaves())
    .enter().append("text")
    .attr("class", "node")
    .attr("dy", "0.31em")
    .attr("transform", function(d) {
      return "rotate(" + (d.x - 90) + ")translate(" + (d.y + 8) + ",0)" + (d.x &lt; 180 ? "" : "rotate(180)");
    })
    .attr("text-anchor", function(d) {
      return d.x &lt; 180 ? "start" : "end";
    })
    .text(function(d) {
      return d.data.key;
    })
    .on("mouseover", mouseovered)
    .on("mouseout", mouseouted);
  
  
  
  function mouseovered(d) {
    node
      .each(function(n) {
        n.target = n.source = false;
      });
  
    link
      .classed("link--target", function(l) {
        if (l.target === d) return l.source.source = true;
      })
      .classed("link--source", function(l) {
        if (l.source === d) return l.target.target = true;
      })
      .filter(function(l) {
        return l.target === d || l.source === d;
      })
      .raise();
  
    node
      .classed("node--target", function(n) {
        return n.target;
      })
      .classed("node--source", function(n) {
        return n.source;
      });
  }
  
  function mouseouted(d) {
    link
      .classed("link--target", false)
      .classed("link--source", false);
  
    node
      .classed("node--target", false)
      .classed("node--source", false);
  }
  
  // Lazily construct the package hierarchy from class names.
  function packageHierarchy(classes) {
    var map = {};
  
    function find(name, data) {
      var node = map[name],
        i;
      if (!node) {
        node = map[name] = data || {
          name: name,
          children: []
        };
        if (name.length) {
          node.parent = find(name.substring(0, i = name.lastIndexOf(".")));
          node.parent.children.push(node);
          node.key = name.substring(i + 1);
        }
      }
      return node;
    }
  
    classes.forEach(function(d) {
      find(d.name, d);
    });
  
    return d3.hierarchy(map[""]);
  }
  
  // Return a list of imports for the given array of nodes.
  function packageImports(nodes) {
    var map = {},
      imports = [];
  
    // Compute a map from name to node.
    nodes.forEach(function(d) {
      map[d.data.name] = d;
    });
  
    // For each import, construct a link from the source to target node.
    nodes.forEach(function(d) {
      if (d.data.imports) d.data.imports.forEach(function(i) {
        imports.push(map[d.data.name].path(map[i]));
      });
    });
  
    return imports;
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.node {
    font: 300 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
    fill: #444;
  }
  
  .node:hover {
    fill: #000;
  }
  
  .link {
    stroke: steelblue;
    stroke-opacity: 0.5;
    fill: none;
    pointer-events: none;
    stroke-width: 1px;
    stroke-linecap: round;
  }
  
  .node:hover,
  .node--source,
  .node--target {
    font-weight: 700;
  }
  
  
  /* text color */
  
  .node--source {
    fill: red;
  }
  
  
  /* text color */
  
  .node--target {
    fill: red;
  }
  
  .link--source,
  .link--target {
    stroke-opacity: 1;
    stroke-width: 2px;
  }
  
  
  /* line color */
  
  .link--source {
    stroke: red;
  }
  
  
  /* line color */
  
  .link--target {
    stroke: red;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.13.0/d3.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>what I am after though is 2 things</p>
  <ol>
  <li>I need each group to have a title displayed. EG the databases to say they are databases</li>
  <li>3 colour lines (i have 2 coloured the same at present), 1 for depends on, 1 for depended by and one for both</li>
  </ol>
  <p>New to D3 so unsure how to achieve these?</p>
  <p>TIA</p>