Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
d3plus-hierarchy
Advanced tools
Nested, hierarchical, and cluster charts built on D3
If you use NPM, run npm install d3plus-hierarchy --save
. Otherwise, download the latest release. The released bundle supports AMD, CommonJS, and vanilla environments. You can also load directly from d3plus.org:
<script src="https://d3plus.org/js/d3plus-hierarchy.v0.7.full.min.js"></script>
Creating a tree map using d3plus is super simple. Given an array of data objects that looks something like this:
var data = [
{parent: "Group 1", id: "alpha", value: 29},
{parent: "Group 1", id: "beta", value: 10},
{parent: "Group 1", id: "gamma", value: 2},
{parent: "Group 2", id: "delta", value: 29},
{parent: "Group 2", id: "eta", value: 25}
];
Only a few lines of code are needed to transform it into an interactive TreeMap:
new d3plus.Treemap()
.data(data)
.groupBy(["parent", "id"])
.sum("value")
.render();
Colors are assigned to each unique ID using the color assign function, and the rectangles are created using the Rect class.
Click here to view this example live on the web.
This is a global class, and extends all of the methods and functionality of Pie
.
# new Donut()
Extends the Pie visualization to create a donut chart.
This is a global class, and extends all of the methods and functionality of Viz
.
Viz
# new Pack()
Uses the d3 pack layout to creates Circle Packing chart based on an array of data.
If value is specified, sets the hover method to the specified function and returns the current class instance.
This is a static method of Pack
, and is chainable with other methods of this Class.
# Pack.layoutPadding([value]) <>
If value is specified, sets the opacity accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current pack opacity accessor.
This is a static method of Pack
.
# Pack.packOpacity([value]) <>
If value is specified, sets the padding accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current pack opacity accessor.
This is a static method of Pack
.
If comparator is specified, sets the sort order for the pack using the specified comparator function. If comparator is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.
This is a static method of Pack
.
function comparator(a, b) {
return b.value - a.value;
}
If value is specified, sets the sum accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current sum accessor.
This is a static method of Pack
.
function sum(d) {
return d.sum;
}
This is a global class, and extends all of the methods and functionality of Viz
.
Viz
# new Pie()
Uses the d3 pie layout to creates SVG arcs based on an array of data.
If value is specified, sets the inner radius accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current inner radius accessor.
This is a static method of Pie
.
If value is specified, sets the arc padding to the specified radian value and returns the current class instance. If value is not specified, returns the current radian padding.
This is a static method of Pie
.
If value is specified, sets the arc padding to the specified pixel value and returns the current class instance. If value is not specified, returns the current pixel padding.
This is a static method of Pie
.
If comparator is specified, sets the sort order for the pie slices using the specified comparator function. If comparator is not specified, returns the current sort order, which defaults to descending order by the associated input data's numeric value attribute.
This is a static method of Pie
.
function comparator(a, b) {
return b.value - a.value;
}
If value is specified, sets the value accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current value accessor.
This is a static method of Pie
.
function value(d) {
return d.value;
}
This is a global class, and extends all of the methods and functionality of Viz
.
# new Tree()
Uses d3's tree layout to create a tidy tree chart based on an array of data.
If value is specified, sets the orientation to the specified value. If value is not specified, returns the current orientation.
This is a static method of Tree
.
If value is specified, sets the separation accessor to the specified function. If value is not specified, returns the current separation accessor.
From the d3-hierarchy documentation:
The separation accessor is used to separate neighboring nodes. The separation function is passed two nodes a and b, and must return the desired separation. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.
This is a static method of Tree
.
function separation(a, b) {
return a.parent === b.parent ? 1 : 2;
}
This is a global class, and extends all of the methods and functionality of Viz
.
# new Treemap()
Uses the d3 treemap layout to creates SVG rectangles based on an array of data. See this example for help getting started using the treemap generator.
# Treemap.layoutPadding([value]) <>
If value is specified, sets the inner and outer padding accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current padding accessor.
This is a static method of Treemap
.
# Treemap.sort([comparator]) <>
If comparator is specified, sets the sort order for the treemap using the specified comparator function. If comparator is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute.
This is a static method of Treemap
.
function comparator(a, b) {
return b.value - a.value;
}
If value is specified, sets the sum accessor to the specified function or number and returns the current class instance. If value is not specified, returns the current sum accessor.
This is a static method of Treemap
.
function sum(d) {
return d.sum;
}
If value is specified, sets the tiling method to the specified function and returns the current class instance. If value is not specified, returns the current tiling method.
This is a static method of Treemap
.
This is a global function.
Param | Type | Description |
---|---|---|
data | Array | The data array to be nested. |
keys | Array | An array of key accessors that signify each nest level. |
FAQs
Nested, hierarchical, and cluster charts built on D3
The npm package d3plus-hierarchy receives a total of 444 weekly downloads. As such, d3plus-hierarchy popularity was classified as not popular.
We found that d3plus-hierarchy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.