Skip to content

Instantly share code, notes, and snippets.

@EE2dev
Last active December 30, 2020 23:22
Show Gist options
  • Save EE2dev/10a3dba82372163a96de6632ca72c7a0 to your computer and use it in GitHub Desktop.
Save EE2dev/10a3dba82372163a96de6632ca72c7a0 to your computer and use it in GitHub Desktop.
d3-indented-tree API example #18
license: mit
<!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,weight,color
Eve,,3.45,25,yellow
Cain,Eve,4.647,20.3,black
Seth,Eve,3,20.3,steelblue
Enos,Seth,4,3000,orange
Noam,Seth,50000,30,green
Abel,Eve,4,30,brown
Awan,Eve,3,30,deeppink
Enoch,Awan,7,30,blue
Azura,Eve,2,30,red
</aside>
<script>
const dataSpec = {
source: "aside#data",
};
const localeGerman = {
"decimal": ",",
"thousands": ".",
"grouping": [3],
"currency": ["", " €"]
};
const myChart = d3.indentedTree(dataSpec)
.propagateValue("size")
.formatDefaultLocale(localeGerman)
.linkLabel("weight",{unit: " Euro", onTop: true, format: ",.2f"})
.linkWidth(100)
;
showChart(myChart);
function showChart(_chart) {
d3.select("body")
.append("div")
.attr("class", "chart")
.call(_chart);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment