-
Notifications
You must be signed in to change notification settings - Fork 13
/
roadmap.min.js
3 lines (3 loc) · 6.44 KB
/
roadmap.min.js
1
2
3
/*! roadmap.js v0.0.1 - MIT license
2017-06-26 - Florent Solt */
!function(){function a(a){switch(a.type){case"people":return a.taskGroup;case"task":return a.group;case"group":return a.name}}var b=function(a,c){if(this.tasks.length>0){if(this.node.style.minHeight=this.node.clientHeight+"px",this.node.innerHTML="",a){c=150>c?0:c-150,this.node.innerHTML="<a style='margin: 5px; margin-top: "+c+"px; display: inline-block; float: right; border-radius: 3px; color: #fff; font-size: 12px; background: #999; padding: 6px 20px 6px 20px; text-decoration: none;' href='javascript:null'>← Back to the full roadmap</a>";var e=this;this.node.getElementsByTagName("A")[0].onclick=function(){b.apply(e)}}var f=d.apply(this,[this.tasks.filter(function(b){return a&&b.group!==a?!1:!0}),{}]);this.people.sort(function(a,b){return a.group>b.group?1:-1}),this.people.length>0&&d.apply(this,[this.people.filter(function(b){return a&&b.taskGroup!==a?!1:!0}),f])}},c=function(){var a=d3.scale.category20(),c=d3.time.format("%Y-%m-%d");d3.selectAll("div.roadmap").each(function(){for(var d,e={tasks:[],people:[],node:this},f={},g=(e.node.textContent||e.node.innerHTML||"").split("\n"),h=0;d=g[h],h<g.length;h++){var i;if(d=d.replace(/^\s+|\s+$/g,""),f.name||f.group)if(f.from||f.to)if(""===d)""===d&&f.name&&(e.tasks.push(f),f={});else{var j,k;j=d.match(/\s+(\d+)%\s*$/),j?(k=parseInt(j[1],10),d=d.substring(0,d.length-j[0].length).trim()):k=100,e.people.push({type:"people",group:d,from:f.from,to:f.to,name:f.group+" — "+f.name,taskGroup:f.group,color:a(f.group),involvement:k})}else i=d.replace(/[^0-9\-\/]+/," ").split(" "),f.from=c.parse(i[0]),f.to=c.parse(i[1]),f.to.setHours(f.to.getHours()+24);else i=d.split(","),f.type="task",f.group=i.slice(0,-1).join(",").trim(),f.name=i.slice(-1).join(",").trim(),f.style=f.group.match(/^\*/)?"bold":"normal",f.group=f.group.replace(/^\*\s+/,""),f.color=a(f.group)}b.apply(e)})},d=function(c,d){var e=this,f=20,g=f+4,h=20+(d.topPadding||0),i=c.length*g+40,j=this.node.clientWidth,k=d.svg||d3.select(this.node).append("svg").attr("width",j).attr("style","overflow: visible");k.attr("height",function(){return parseInt(k.attr("height")||0,10)+i}),c.sort(function(a,b){return a.group===b.group?a.from>b.from?1:-1:a.group>b.group?1:-1});for(var l=[],m=0,n=0;n<c.length;n++){for(var o=0,p=!1;o<l.length&&!p;)p=l[o].name===c[n].group,o++;if(!p){var q=0;for(o=0;o<c.length;)c[o].group===c[n].group&&q++,o++;l.push({type:"group",name:c[n].group,count:q,previous:m,style:c[n].style}),m+=q}}var r=0;for(n=0;n<c.length;n++)"people"===c[n].type&&100!==c[n].involvement&&(k.append("defs").append("pattern").attr({id:"pattern"+r,width:"8",height:"8",patternUnits:"userSpaceOnUse",patternTransform:"rotate(45)"}).append("rect").attr({width:Math.ceil(8*c[n].involvement/100),height:"8",transform:"translate(0,0)",fill:c[n].color,"fill-opacity":.8}),c[n].pattern="url(#pattern"+r+")",r++);k.append("g").selectAll("rect").data(l).enter().append("rect").attr("rx",3).attr("ry",3).attr("x",0).attr("y",function(a){return a.previous*g+h}).attr("width",function(){return j}).attr("height",function(a){return a.count*g-4}).attr("stroke","none").attr("fill","#999").attr("fill-opacity",.1);var s=k.append("g").selectAll("text").data(l).enter().append("text").text(function(a){return a.name}).attr("x",10).attr("y",function(a){return a.count*g/2+a.previous*g+h+2}).attr("font-size",11).attr("font-weight",function(a){return a.style}).attr("text-anchor","start").attr("text-height",14).attr("fill","#000"),t=d.sidePadding||s[0].parentNode.getBBox().width+15,u=d3.time.scale().clamp(!0).domain([d3.min(c,function(a){return a.from}),d3.max(c,function(a){return a.to})]).range([0,j-t-15]),v=d3.svg.axis().scale(u).orient("bottom").ticks(d3.time.monday).tickSize(-k.attr("height")+h+20,0,0).tickFormat(d3.time.format("%b %d")),w=k.append("g").attr("transform","translate("+t+", "+(k.attr("height")-20)+")").call(v),x=new Date;x>u.domain()[0]&&x<u.domain()[1]&&(w.append("line").attr("x1",u(x)).attr("y1",0).attr("x2",u(x)).attr("y2",-k.attr("height")+h+20).attr("class","now"),w.selectAll(".now").attr("stroke","red").attr("opacity",.5).attr("stroke-dasharray","2,2").attr("shape-rendering","crispEdges")),w.selectAll("text").style("text-anchor","middle").attr("fill","#000").attr("stroke","none").attr("font-size",10).attr("dy","1em"),w.selectAll(".tick line").attr("stroke","#dddddd").attr("shape-rendering","crispEdges");var y=k.append("g").attr("transform","translate("+t+", 0)").selectAll("rect").data(c).enter();if(y.append("rect").attr("rx",3).attr("ry",3).attr("x",function(a){return u(a.from)}).attr("y",function(a,b){return b*g+h}).attr("width",function(a){return u(a.to)-u(a.from)}).attr("height",f).attr("stroke","none").attr("fill",function(a){return a.pattern||a.color}).attr("fill-opacity",.5).on("mouseover",function(){d3.select(this).style({cursor:"pointer"})}).on("click",function(c){b.apply(e,[a(c),this.getBBox().y])}),y.append("text").text(function(a){return a.name}).attr("x",function(a){return u(a.from)+(u(a.to)-u(a.from))/2}).attr("y",function(a,b){return b*g+14+h}).attr("font-size",11).attr("font-weight",function(a){return a.style}).attr("text-anchor","middle").attr("text-height",f).attr("fill","#000").style("pointer-events","none"),d.svg){var z=k.append("line").attr("x1",0).attr("y1",0).attr("x2",0).attr("y2",0).style("stroke","black").style("stroke-width","1px").style("stroke-dasharray","2,2").style("shape-rendering","crispEdges").style("pointer-events","none").style("display","none"),A=k.append("rect").attr("rx",3).attr("ry",3).attr("width",50).attr("height",f).attr("stroke","none").attr("fill","black").attr("fill-opacity",.8).style("display","none"),B=k.append("text").attr("font-size",11).attr("font-weight","bold").attr("text-anchor","middle").attr("text-height",f).attr("fill","white").style("display","none"),C=40;k.on("mousemove",function(){var a=d3.mouse(this)[0],b=d3.mouse(this)[1];a>t?(z.attr("x1",a).attr("y1",10).attr("x2",a).attr("y2",k.attr("height")-20).style("display","block"),A.attr("x",a-25).attr("y",b-(f+8)/2+C).style("display","block"),B.attr("transform","translate("+a+","+(b+C)+")").text(d3.time.format("%b %d")(u.invert(a-t))).style("display","block")):(z.style("display","none"),A.style("display","none"),B.style("display","none"))}),k.on("mouseleave",function(){z.style("display","none"),A.style("display","none"),B.style("display","none")})}return{sidePadding:t,topPadding:i,svg:k}};document.addEventListener("DOMContentLoaded",function(){"undefined"==typeof window.__isRoadmapLoaded&&(c(),window.__isRoadmapLoaded=c)})}();