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