Public
Edited
Nov 5
3 stars
Insert cell
Insert cell
height = 600
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

svg
.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height - margin.bottom)
.attr("fill", "black");

var noLines = width;
for (var i = 0; i < noLines; i++) {
var rand = Math.random();
var randHeight = Math.random();
const end = {
x: x(Math.floor(rand * 100 + 1)),
y: y(Math.floor(randHeight * 100 + 1))
};

//uncomment for drift effect
// var randomWind = Math.random();
// var maxDrift = 50;
svg
.append("line")
.attr("x1", function () {
var off = Math.random() * 0.5;
//half go left, half right
if (off < 0.15) off = -off;
return end.x + off * 100 * randHeight;
})
.attr("x2", end.x)
.attr("y1", y(0))
.attr("y2", end.y)
.attr("opacity", Math.random() + 0.1)
.style("mix-blend-mode", "screen")
.attr("stroke", d3.interpolateRainbow(rand));
//uncomment for drift effect
// .transition()
// .duration(4000)
// .attr('x2', end.x + randomWind*maxDrift);

svg
.append("circle")
.attr("class", "photon")
.attr("cx", end.x)
.attr("cy", end.y)
.style("mix-blend-mode", "screen")
.attr("opacity", Math.random() + 0.1)
.attr("fill", "white")
.attr("r", Math.floor(Math.random() * 5 + 2));
//uncomment for drift effect
// .transition()
// .duration(4000)
// .attr('cx', end.x + randomWind*maxDrift);
}

//Container for the gradients
var defs = svg.append("defs");

//Filter for the outside glow
var filter = defs.append("filter").attr("id", "glow");
filter
.append("feGaussianBlur")
.attr("stdDeviation", "2")
.attr("result", "coloredBlur");
var feMerge = filter.append("feMerge");
feMerge.append("feMergeNode").attr("in", "coloredBlur");
feMerge.append("feMergeNode").attr("in", "SourceGraphic");

//Apply to your element(s)
svg.selectAll(".photon").style("filter", "url(#glow)");

return svg.node();
}
Insert cell
x = d3.scaleLinear()
.domain([0,100])
.rangeRound([0, width])
Insert cell
y = d3.scaleLinear()
.domain([0, 100])
.rangeRound([height - margin.bottom, margin.top])
.clamp(true)
Insert cell
margin = ({top: 20, right: 30, bottom: 30, left: 40})
Insert cell
d3 = require("d3@5")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more