D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
pstuffa
Full window
Github gist
Oscilloscope
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { background: #2f3337 !important; padding: 0px; margin: 0px; } svg { padding: 0px; margin: 0px; } #chart { text-align: center; margin: 0px; padding: 0px; } .dots { fill: #53535f; } .line { stroke: #22ffc5; stroke-width: 1; stroke-opacity: .75; fill: none; } </style> </head> <body> <div id="chart"> </div> <script> var margin = {top: 60, right: 60, bottom: 60, left: 60}, width = window.innerHeight*2 - margin.left - margin.right, height = window.innerHeight - margin.top - margin.bottom, numTicks = 20, numDashes = 5, numDots = 20; tickSpace = 8; var y = d3.scaleLinear() .range([height, 0]) .domain([-1,1]) var x = d3.scaleLinear() .range([0, width]) .domain([-2,2]) var xConversion = d3.scaleLinear() .range([-2, 2]) .domain([0, 1]) var svg = d3.select("#chart").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .style("filter","url(#I)") .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var defs = svg.append("defs"); var filter = defs.append("filter").attr("id","spect"); var turbulence = filter.append("feTurbulence") .attr("baseFrequency",".4") .attr("numOctaves","2") .attr("seed", 201); var filterGoo = defs.append("filter").attr("id","gooeyCodeFilter"); filterGoo.append("feGaussianBlur") .attr("in","SourceGraphic") .attr("stdDeviation","5") .attr("color-interpolation-filters","sRGB") .attr("result","blur"); filterGoo.append("feColorMatrix") .attr("in","blur") .attr("mode","matrix") .attr("values","1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7") .attr("result","gooey"); var backgroundnoise = svg.append("rect") .attr("filter","url(#spect)") .style("opacity", .2) .attr("width", width) .attr("height", height); svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(x).tickSize(-height).ticks(numTicks)) .selectAll("line") .style("stroke-dasharray", function(d,i) { var dashArray = [] for (var k = 0; k < numTicks; k += 1) { dashArray.push((height/numTicks - (tickSpace/2) - (k > 0 ? (tickSpace/2) : 0))); dashArray.push(tickSpace) } return dashArray.join(",") }) svg.append("g") .attr("class", "y axis") .call(d3.axisLeft(y).tickSize(-width).ticks(numTicks)) .selectAll("line") .style("stroke-dasharray", function(d,i) { var dashArray = [] for (var k = 0; k < numTicks; k += 1) { dashArray.push((width/numTicks - (tickSpace/2) - (k > 0 ? (tickSpace/2) : 0))); dashArray.push(tickSpace) } return dashArray.join(",") }) var line = d3.line() .curve(d3.curveCatmullRom) .x(function(d) { return x(d.x); }) .y(function(d) { return y(d.y/10); }); var data = [] svg.append("path") .datum(data) .attr("class", "line") .attr("clip-path", "url(#clip)") .attr("d", line) .style("filter", "url(#gooeyCodeFilter)"); svg.selectAll(".verticalDashes") .data(d3.range(numTicks*numDashes).map(Object)) .enter().append("line") .attr("class", "verticalDashes") .attr("y1", function(d, i) { return i*(height/numTicks/numDashes); } ) .attr("y2", function(d, i) { return i*(height/numTicks/numDashes); } ) .attr("x1", x(-.025)) .attr("x2", x(.025)) .style("stroke", "#000") .style("stroke-dasharray", function() { var unit = x(.025) - x(0); return (unit - (tickSpace/4)) + "," + (tickSpace/2) + "," + (unit - (tickSpace/4)) }) svg.selectAll(".horizontalDashes") .data(d3.range(numTicks*numDashes).map(Object)) .enter().append("line") .attr("class", "horizontalDashes") .attr("x1", function(d, i) { return i*(width/numTicks/numDashes); } ) .attr("x2", function(d, i) { return i*(width/numTicks/numDashes); } ) .attr("y1", y(-.025)) .attr("y2", y(.025)) .style("stroke", "#000") .style("stroke-dasharray", function() { var unit = x(.025) - x(0); return (unit - (tickSpace/4)) + "," + (tickSpace/2) + "," + (unit - (tickSpace/4)) }) svg.selectAll(".rowOne dots") .data(d3.range(numTicks*numDots).map(Object)) .enter().append("circle") .attr("class", "rowOne dots") .attr("cx", function(d, i) { return i*(width/numTicks/numDots); } ) .attr("cy", function(d, i) { return i % 2 == 0 ? y(.28) : y(-.28) }) .attr("r", 1); svg.selectAll(".rowTwo") .data(d3.range(numTicks*numDots).map(Object)) .enter().append("circle") .attr("class", "rowTwo dots") .attr("cx", function(d, i) { return i*(width/numTicks/numDots); } ) .attr("cy", function(d, i) { return i % 2 == 0 ? y(.44) : y(-.44) }) .attr("r", 1); svg.append("clipPath") .attr("id", "clip") .append("rect") .attr("width", width) .attr("height", height); var strokeWidth = 10; var t = d3.interval(function(elapsed) { data.push({x: 0, y: 0}); xConversion.domain([0, data.length-1]) data.forEach(function(d, i) { d.x = xConversion(i) d.y = Math.tan(i+1) }); strokeWidth -= .01 svg.select(".line") .datum(data) .attr("d", line) .style("stroke-width", strokeWidth) if (elapsed > 30000) t.stop(); }, 10); </script> </body>
https://d3js.org/d3.v4.min.js