D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
miniblin
Full window
Github gist
FlowChartAutomatedLinks
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0;background-color:#152512; } svg { width: 100%; height: 100%; } </style> </head> <body> <svg> </svg> <script> // Feel free to change or delete any of the code you see in this editor! const margin = { top: 0, right: 50, bottom: 40, left: 50 } var index=0 var data =[ [5,2,3,6,12], [7,1,4,6,12], [4,5,3,7,14] ] var headerText =["New","Tender Review","Manager Review", "Investigation Required", "Closed"] var height=150; var colors = d3.scaleOrdinal() .range(["#387898","#c79b18","#c79b18","#50863b","#50863b"]) var pathColors = d3.scaleOrdinal() .range(["#c79b18","#c79b18","#c79b18","#50863b","#50863b","#c79b18","#c79b18"]) var outlineColors = d3.scaleOrdinal() .range(["#b4d3e3","#d2c488","#d2c488","#b2d6a7","#b2d6a7"]) var svg= d3.select('svg'); var background = svg.append('g') var foreground =svg.append('g') var distanceBetweenX = 200 var distanceBetweenY = 75 var linePositions = [ [0,1], [1,2], [2,3], [1,4], [2,4], [3,1], [4,1], [4,0] ] svg.append("defs").append("marker") .attr("id", "arrow") .attr("viewBox", "0 -5 10 10") .attr("refX",130) .attr("refY", 0) .attr("markerWidth", 8) .attr("markerHeight", 8) .attr("orient", "auto") .append("svg:path") .attr("d", "M0,-5L10,0L0,5") .attr("fill", "#fff") .attr('stroke','#b2d6a7') .attr("fill-opacity","0.1") svg.append("defs").append("marker") .attr("id", "arrow2") .attr("viewBox", "0 -5 10 10") .attr("refX",-60) .attr("refY", 0) .attr("markerWidth", 8) .attr("markerHeight", 8) .attr("orient", "auto") .append("svg:path") .attr("d", "M0,-5L10,0L0,5") .attr("fill", "#fff") .attr("fill-opacity","0.1") .attr('stroke','#b2d6a7') var line = d3.line() .x((d,i) =>(d* distanceBetweenX) +margin.left) .y( (d,i)=>height + d*distanceBetweenY) .curve(d3.curveStepBefore) linePositions.forEach(function(element, index){ background.append('path') .attr('d', line(element)) .attr('fill', 'none') .attr('stroke', pathColors(index)) .style("stroke-dasharray", ("2, 2")) .attr("marker-start", "url(#arrow2)") .attr("marker-end", "url(#arrow)"); }) function updateGraph(data){ var headers =svg.selectAll('text') .data(data, d=>d) headers.exit().remove() var headersEnter =headers.enter().append('text') var headers = headersEnter.merge(headers) .attr('x', (d,i) =>(i* distanceBetweenX) +margin.left) .attr('y', (d,i)=>height/1.65) .text((d,i)=>d+" "+headerText[i]) .attr('fill', '#fff') .style("font-family","roboto") .attr("text-anchor", "middle") var circles =svg.selectAll('circle') .data(data) circles.exit().remove() var circlesEnter =circles.enter().append('circle') var t = d3.transition() .duration(1000) circles = circlesEnter.merge(circles) .attr('cx', (d,i) =>(i* distanceBetweenX) +margin.left) .attr('cy', (d,i)=>height + i*distanceBetweenY) .attr('stroke-width', 3) .transition(t) .attr('r', d=>d*3) .attr('fill', (d,i)=>colors(i)) .attr('stroke',(d,i)=>outlineColors(i)) } updateGraph(data[0]) setInterval(() => { index += 1; updateGraph(data[index % 3]); }, 3000); </script> </body>
https://d3js.org/d3.v4.min.js