block by EE2dev 54fe30f1213b216575dcf300ee3ad4c0

d3-indented-tree API example #13

Full Screen

API examples for d3-indented-tree


myChart.linkColor()

This example shows how to set the color of the links based on values of the column color.


Acknowledgements:

index.html

<!DOCTYPE html>
  <meta charset="utf-8">
  <head>
    <script src="https://d3js.org/d3.v6.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/EE2dev/d3-indented-tree/dist/latest/d3-indented-tree.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/EE2dev/d3-indented-tree/dist/latest/d3-indented-tree.css">
  </head>
  
  <body>
    <!-- paste data in aside tag -->
    <aside id="data">
key,parent,size,color
Eve,,3,orange
Cain,Eve,4,black
Seth,Eve,3,steelblue
Enos,Seth,4,orange
Noam,Seth,5,green
Abel,Eve,4,brown
Awan,Eve,3,deeppink
Enoch,Awan,7,blue
Azura,Eve,2,red
    </aside>
  
    <script>
      const dataSpec = {
        source: "aside#data",
      };
      const myChart = d3.indentedTree(dataSpec)
        .propagateValue("size")
        .linkColor("color")
      ;

      showChart(myChart); 
      
      window.setTimeout(function() {
        myChart.linkWidth(100);
      }, 2000);
      
      function showChart(_chart) {
        d3.select("body")
          .append("div")
          .attr("class", "chart")
          .call(_chart);
      }         
    </script>
  </body>
</html>