Skip to content

Instantly share code, notes, and snippets.

@Pragyagarg
Last active July 6, 2018 22:01
Show Gist options
  • Save Pragyagarg/b8efda37f741b6911c1e03846f66d524 to your computer and use it in GitHub Desktop.
Save Pragyagarg/b8efda37f741b6911c1e03846f66d524 to your computer and use it in GitHub Desktop.
Dendrogram - Java8 API (subset)
license: mit
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node circle {
fill: #999999;
}
.node text {
font: 12px sans-serif;
}
.node--internal circle {
fill: #545454;
}
.node--internal text {
text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff;
}
.link {
fill: none;
stroke: #727272;
stroke-opacity: 0.4;
stroke-width: 1.5px;
}
</style>
<svg width="960" height="2400"></svg>
<script src="//d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height"),
g = svg.append("g").attr("transform", "translate(40,0)");
var cluster = d3.cluster()
.size([height, width - 160]);
var stratify = d3.stratify()
.parentId(function(d) { return d.id.substring(0, d.id.lastIndexOf(".")); });
d3.csv("java8.csv", function(error, data) {
if (error) throw error;
var root = stratify(data)
.sort(function(a, b) { return (a.height - b.height) || a.id.localeCompare(b.id); });
cluster(root);
var link = g.selectAll(".link")
.data(root.descendants().slice(1))
.enter().append("path")
.attr("class", "link")
.attr("d", function(d) {
return "M" + d.y + "," + d.x
+ "C" + (d.parent.y + 100) + "," + d.x
+ " " + (d.parent.y + 100) + "," + d.parent.x
+ " " + d.parent.y + "," + d.parent.x;
});
var node = g.selectAll(".node")
.data(root.descendants())
.enter().append("g")
.attr("class", function(d) { return "node" + (d.children ? " node--internal" : " node--leaf"); })
.attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; })
node.append("circle")
.attr("r", 4);
node.append("text")
.attr("dy", 3)
.attr("x", function(d) { return d.children ? -8 : 8; })
.style("text-anchor", function(d) { return d.children ? "end" : "start"; })
.text(function(d) { return d.id.substring(d.id.lastIndexOf(".") + 1); });
});
</script>
id value
java
java.math
java.math.BigDecimal 183050.0
java.math.BigInteger 95882.0
java.math.MathContext 28396.0
java.math.RoundingMode 32564.0
java.sql
java.sql.Array 37843.0
java.sql.BatchUpdateException 49408.0
java.sql.Blob 33430.0
java.sql.CallableStatement 318307.0
java.sql.ClientInfoStatus 17571.0
java.sql.Clob 38258.0
java.sql.Connection 144904.0
java.sql.DatabaseMetaData 392654.0
java.sql.DataTruncation 23183.0
java.sql.Date 33522.0
java.sql.Driver 21108.0
java.sql.DriverAction 10935.0
java.sql.DriverManager 40073.0
java.sql.DriverPropertyInfo 15690.0
java.sql.JDBCType 41724.0
java.sql.NClob 9602.0
java.sql.ParameterMetaData 29457.0
java.sql.PreparedStatement 144657.0
java.sql.PseudoColumnUsage 17441.0
java.sql.Ref 17809.0
java.sql.ResultSet 441979.0
java.sql.ResultSetMetaData 41005.0
java.sql.RowId 16040.0
java.sql.RowIdLifetime 18045.0
java.sql.Savepoint 10930.0
java.sql.SQLClientInfoException 40141.0
java.sql.SQLData 17069.0
java.sql.SQLDataException 26067.0
java.sql.SQLException 33059.0
java.sql.SQLFeatureNotSupportedException 27576.0
java.sql.SQLInput 55223.0
java.sql.SQLIntegrityConstraintViolationException 28298.0
java.sql.SQLInvalidAuthorizationSpecException 28086.0
java.sql.SQLNonTransientConnectionException 27824.0
java.sql.SQLNonTransientException 27263.0
java.sql.SQLOutput 54405.0
java.sql.SQLPermission 18067.0
java.sql.SQLRecoverableException 26576.0
java.sql.SQLSyntaxErrorException 26686.0
java.sql.SQLTimeoutException 26338.0
java.sql.SQLTransactionRollbackException 27585.0
java.sql.SQLTransientConnectionException 27574.0
java.sql.SQLTransientException 26626.0
java.sql.SQLType 10980.0
java.sql.SQLWarning 28686.0
java.sql.SQLXML 36466.0
java.sql.Statement 133800.0
java.sql.Struct 14957.0
java.sql.Time 33881.0
java.sql.Timestamp 42875.0
java.sql.Types 45686.0
java.sql.Wrapper 14859.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment