
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
v0.1.8
Convenience functions for spinning up d3-powered charts. Not an automatic charting tool, just a way for code-lovers to reduce tedium.
By @wilson428 and @davejohn
Assuming you have a <div> in the body with the id "bar_chart":
// Data thanks to http://harrypotter.answers.wikia.com/wiki/Top_200_most_named_harry_potter_characters_s
var mentions = [ ["Harry", 18956], ["Ron", 6464], ["Hermione", 5486], ["Dumbledore", 2421], ["Hagrid", 2024], ["Snape", 1956], ["Voldemort", 1797], ["Sirius", 1471], ["Draco", 1198] ];
var chart = d3charts("#bar_chart", {
margin: { top: 35, right: 20, bottom: 20, left: 35 },
aspect: 0.75,
onChartResize: update_chart,
title: "Most-mentioned Characters in <em>Harry Potter</em>"
});
var x = chart.addAxis("x", {
domain: mentions.map(function(d) { return d[0]; }),
type: "ordinal"
});
var y = chart.addAxis("y", {
domain: [0, 20000],
rules: true,
tickFormat: function(d) { return (d / 1000) + "K" }
});
var bars = chart.data_layer.selectAll(".bar")
.data(mentions)
.enter()
.append("rect")
.attr("class", "bar");
function update_chart() {
chart.data_layer.selectAll(".bar")
.attr("x", function(d) {
return x.scale(d[0]);
})
.attr("width", function(d) {
return x.scale.bandwidth();
})
.attr("y", function(d) {
console.log(d[1], y.scale(d[1]), chart.height)
return y.scale(d[1]);
})
.attr("height", function(d) {
return chart.height - y.scale(d[1]);
})
}
update_chart();
The d3charts function creates a new blank chart without any axes or anything else, inside a responsive SVG courtesy of elastic-SVG. There are two layers: g.axes_layer and g.data_layer.
| property | description | default |
|---|---|---|
| margin | margin around charts | {top: 20, right: 50, bottom: 30, left: 30} |
| title | title of chart | "" |
opts also accepts some arguments for elastic-SVG:
| property | description | default |
|---|---|---|
| width | width of chart | container width |
| aspect | height/width | 0.618 |
| height | height of chart | width * 0.618 |
myChart.resize()elastic-svg after loadsetDomain for resetting the domain after constructionFAQs
Wrapper for D3 charts, now d3.v5 compliant
The npm package d3charts receives a total of 2 weekly downloads. As such, d3charts popularity was classified as not popular.
We found that d3charts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.