2012-07-16 17:52:24 +00:00
|
|
|
(function(){function c(a,b,c){return function(d,e,f){var g=a(d),h=[];g<d&&b(g);if(f>1)while(g<e){var i=new Date(+g);c(i)%f||h.push(i),b(g)}else while(g<e)h.push(new Date(+g)),b(g);return h}}function b(a,b){return(new Date(b,a+1,0)).getDate()}var a={version:"0.0.1a",dev:!0};window.nv=a,a.tooltip={},a.utils={},a.models={},a.charts={},a.graphs=[],a.logs={},a.dispatch=d3.dispatch("render_start","render_end"),a.dispatch.on("render_start",function(b){a.logs.startTime=+(new Date)}),a.dispatch.on("render_end",function(b){a.logs.endTime=+(new Date),a.logs.totalTime=a.logs.endTime-a.logs.startTime,a.dev&&console.log&&console.log("total",a.logs.totalTime)}),a.log=function(){a.dev&&console.log&&console.log.apply(console,arguments);return arguments[arguments.length-1]},a.render=function b(c){c=c||1,b.active=!0,a.dispatch.render_start(),setTimeout(function(){var d;for(var e=0;e<c&&(graph=b.queue[e]);e++)d=graph.generate(),typeof graph.callback=="function"&&graph.callback(d),a.graphs.push(d);b.queue.splice(0,e),b.queue.length?setTimeout(arguments.callee,0):(a.render.active=!1,a.dispatch.render_end())},0)},a.render.queue=[],a.addGraph=function(b){typeof arguments[0]=="function"&&(b={generate:arguments[0],callback:arguments[1]}),a.render.queue.push(b),a.render.active||a.render()},a.identity=function(a){return a},a.strip=function(a){return a.replace(/(\s|&)/g,"")},d3.time.monthEnd=function(a){return new Date(a.getFullYear(),a.getMonth(),0)},d3.time.monthEnds=c(d3.time.monthEnd,function(a){a.setUTCDate(a.getUTCDate()+1),a.setDate(b(a.getMonth()+1,a.getFullYear()))},function(a){return a.getMonth()}),function(){var b=window.nv.tooltip={};b.show=function(b,c,d,e,f){var g=document.createElement("div");g.className="nvtooltip",d=d||"s",e=e||20;var h=f?f:document.getElementsByTagName("body")[0];g.innerHTML=c,g.style.left=0,g.style.top=0,g.style.opacity=0,h.appendChild(g);var i=parseInt(g.offsetHeight),j=parseInt(g.offsetWidth),k=a.utils.windowSize().width,l=a.utils.windowSize().height,m=h.scrollTop,n=h.scrollLeft,o,p;switch(d){case"e":o=b[0]-j-e,p=b[1]-i/2,o<n&&(o=b[0]+e),p<m&&(p=m+5),p+i>m+l&&(p=m-i-5);break;case"w":o=b[0]+e,p=b[1]-i/2,o+j>k&&(o=b[0]-j-e),p<m&&(p=m+5),p+i>m+l&&(p=m-i-5);break;case"n":o=b[0]-j/2,p=b[1]+e,o<n&&(o=n+5),o+j>k&&(o=k-j-5),p+i>m+l&&(p=b[1]-i-e);break;case"s":o=b[0]-j/2,p=b[1]-i-e,o<n&&(o=n+5),o+j>k&&(o=k-j-5),m>p&&(p=b[1]+20)}g.style.left=o+"px",g.style.top=p+"px",g.style.opacity=1,g.style.position="absolute",g.style.pointerEvents="none";return g},b.cleanup=function(){var a=document.getElementsByClassName("nvtooltip"),b=[];while(a.length)b.push(a[0]),a[0].style.transitionDelay="0 !important",a[0].style.opacity=0,a[0].className="nvtooltip-pending-removal";setTimeout(function(){while(b.length){var a=b.pop();a.parentNode.removeChild(a)}},500)}}(),a.utils.windowSize=function(){var a={width:640,height:480};document.body&&document.body.offsetWidth&&(a.width=document.body.offsetWidth,a.height=document.body.offsetHeight),document.compatMode=="CSS1Compat"&&document.documentElement&&document.documentElement.offsetWidth&&(a.width=document.documentElement.offsetWidth,a.height=document.documentElement.offsetHeight),window.innerWidth&&window.innerHeight&&(a.width=window.innerWidth,a.height=window.innerHeight);return a},a.utils.windowResize=function(a){var b=window.onresize;window.onresize=function(c){typeof b=="function"&&b(c),a(c)}},a.models.axis=function(){function g(h){h.each(function(g){var h=d3.select(this),i=h.selectAll("g.wrap.axis").data([g]),j=i.enter().append("g").attr("class","wrap axis"),k=j.append("g"),l=i.select("g");(e.orient()=="top"||e.orient()=="bottom")&&e.ticks(Math.abs(a.range()[1]-a.range()[0])/100),d3.transition(l).call(e),f=f||e.scale();var m=l.selectAll("text.axislabel").data([b||null]);m.exit().remove();switch(e.orient()){case"top":m.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",0),m.attr("x",a.range()[1]/2);if(c){var n=i.selectAll("g.axisMaxMin").data(a.domain());n.enter().append("g").attr("class","axisMaxMin").append("text"),n.exit().remove(),n.attr("transform",fu
|
|
|
|
q)*20}else{var w=5,x=5,y=0,z;n.attr("transform",function(c,d){var e=d3.select(this).select("text").node().getComputedTextLength()+28;z=x,b<a.left+a.right+z+e&&(x=z=5,w+=20),x+=e,x>y&&(y=x);return"translate("+z+","+w+")"}),m.attr("transform","translate("+(b-a.right-y)+","+a.top+")"),c=a.top+a.bottom+w+15}});return h}var a={top:5,right:0,bottom:5,left:0},b=400,c=20,d=function(a){return a.key},e=d3.scale.category20().range(),f=!0,g=d3.dispatch("legendClick","legendDblclick","legendMouseover","legendMouseout");h.dispatch=g,h.margin=function(b){if(!arguments.length)return a;a=b;return h},h.width=function(a){if(!arguments.length)return b;b=a;return h},h.height=function(a){if(!arguments.length)return c;c=a;return h},h.key=function(a){if(!arguments.length)return d;d=a;return h},h.color=function(a){if(!arguments.length)return e;e=a;return h},h.align=function(a){if(!arguments.length)return f;f=a;return h};return h},a.models.line=function(){function r(a){a.each(function(a){var q=c-b.left-b.right,r=d-b.top-b.bottom,s=d3.select(this);k=n.xScale(),l=n.yScale(),o=o||k,p=p||l;var t=s.selectAll("g.wrap.line").data([a]),u=t.enter().append("g").attr("class","wrap nvd3 line"),v=u.append("defs"),w=u.append("g"),z=t.select("g");w.append("g").attr("class","groups"),w.append("g").attr("class","scatterWrap");var A=t.select(".scatterWrap");n.width(q).height(r),d3.transition(A).call(n),t.attr("transform","translate("+b.left+","+b.top+")"),v.append("clipPath").attr("id","edge-clip-"+f).append("rect"),t.select("#edge-clip-"+f+" rect").attr("width",q).attr("height",r),z.attr("clip-path",j?"url(#edge-clip-"+f+")":""),A.attr("clip-path",j?"url(#edge-clip-"+f+")":"");var B=t.select(".groups").selectAll(".group").data(function(a){return a},function(a){return a.key});B.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(B.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),B.attr("class",function(a,b){return"group series-"+b}).classed("hover",function(a){return a.hover}).style("fill",function(a,b){return e[b%e.length]}).style("stroke",function(a,b){return e[b%e.length]}),d3.transition(B).style("stroke-opacity",1).style("fill-opacity",.5);var C=B.selectAll("path").data(function(a,b){return[a.values]});C.enter().append("path").attr("class","line").attr("d",d3.svg.line().interpolate(m).defined(i).x(function(a,b){return o(g(a,b))}).y(function(a,b){return p(h(a,b))})),d3.transition(B.exit().selectAll("path")).attr("d",d3.svg.line().interpolate(m).defined(i).x(function(a,b){return k(g(a,b))}).y(function(a,b){return l(h(a,b))})),d3.transition(C).attr("d",d3.svg.line().interpolate(m).defined(i).x(function(a,b){return k(g(a,b))}).y(function(a,b){return l(h(a,b))})),o=k.copy(),p=l.copy()});return r}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=d3.scale.category20().range(),f=Math.floor(Math.random()*1e4),g=function(a){return a.x},h=function(a){return a.y},i=function(a,b){return!isNaN(h(a,b))&&h(a,b)!==null},j=!1,k,l,m="linear",n=a.models.scatter().id(f).size(16).sizeDomain([16,256]),o,p,q;r.dispatch=n.dispatch,d3.rebind(r,n,"interactive","size","xScale","yScale","zScale","xDomain","yDomain","sizeDomain","forceX","forceY","forceSize","clipVoronoi","clipRadius"),r.margin=function(a){if(!arguments.length)return b;b=a;return r},r.width=function(a){if(!arguments.length)return c;c=a;return r},r.height=function(a){if(!arguments.length)return d;d=a;return r},r.x=function(a){if(!arguments.length)return g;g=a,n.x(a);return r},r.y=function(a){if(!arguments.length)return h;h=a,n.y(a);return r},r.clipEdge=function(a){if(!arguments.length)return j;j=a;return r},r.color=function(a){if(!arguments.length)return e;e=a,n.color(a);return r},r.id=function(a){if(!arguments.length)return f;f=a;return r},r.interpolate=function(a){if(!arguments.length)return m;m=a;return r},r.defined=function(a){if(!arguments.length)return i;i=a;return r};return r},a.models.indentedTree=function(){function i(d){d.each(function(e){function B(a){var b=a.values||a._values;return b&&b.length}function A(a){return a._values&&a._values.length}funct
|
|
|
|
I.append("text").attr("text-anchor",function(a,b){return h(a,b)<0?"end":"start"}),H.select("text").attr("y",e.rangeBand()/2).attr("dy","-.32em").text(function(a,b){return o(h(a,b))}),d3.transition(H).select("text").attr("x",function(a,b){return h(a,b)<0?-4:f(h(a,b))-f(0)+4})):H.selectAll("text").remove(),H.attr("class",function(a,b){return h(a,b)<0?"bar negative":"bar positive"}),l?d3.transition(H).attr("transform",function(a,b){return"translate("+f(a.y0)+","+(l?0:j*e.rangeBand()/p.length)+")"}).select("rect").attr("width",function(a,b){return Math.abs(f(h(a,b)+a.y0)-f(a.y0))}).attr("height",e.rangeBand()):d3.transition(H).attr("transform",function(a,b){return"translate("+(h(a,b)<0?f(h(a,b)):f(0))+","+(a.series*e.rangeBand()/p.length+e(g(a,b)))+")"}).select("rect").attr("height",e.rangeBand()/p.length).attr("width",function(a,b){return Math.abs(f(h(a,b))-f(0))}),v.update=function(){d.transition().call(v)},s=e.copy(),t=f.copy()});return v}var a={top:0,right:0,bottom:0,left:0},b=960,c=500,d=Math.floor(Math.random()*1e4),e=d3.scale.ordinal(),f=d3.scale.linear(),g=function(a){return a.x},h=function(a){return a.y},i=[0],k=d3.scale.category20().range(),l=!1,m=!1,n=60,o=d3.format(",.2f"),p=1200,q,r,s,t,u=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout");v.dispatch=u,v.x=function(a){if(!arguments.length)return g;g=a;return v},v.y=function(a){if(!arguments.length)return h;h=a;return v},v.margin=function(b){if(!arguments.length)return a;a=b;return v},v.width=function(a){if(!arguments.length)return b;b=a;return v},v.height=function(a){if(!arguments.length)return c;c=a;return v},v.xScale=function(a){if(!arguments.length)return e;e=a;return v},v.yScale=function(a){if(!arguments.length)return f;f=a;return v},v.xDomain=function(a){if(!arguments.length)return q;q=a;return v},v.yDomain=function(a){if(!arguments.length)return r;r=a;return v},v.forceY=function(a){if(!arguments.length)return i;i=a;return v},v.stacked=function(a){if(!arguments.length)return l;l=a;return v},v.color=function(a){if(!arguments.length)return k;k=a;return v},v.id=function(a){if(!arguments.length)return d;d=a;return v},v.delay=function(a){if(!arguments.length)return p;p=a;return v},v.showValues=function(a){if(!arguments.length)return m;m=a;return v},v.valueFormat=function(a){if(!arguments.length)return o;o=a;return v},v.valuePadding=function(a){if(!arguments.length)return n;n=a;return v};return v},a.models.multiBarHorizontalChart=function(){function t(i){i.each(function(k){var l=d3.select(this),u=this,v=(c||parseInt(l.style("width"))||960)-b.left-b.right,w=(d||parseInt(l.style("height"))||400)-b.top-b.bottom,x=l.selectAll("g.wrap.multiBarHorizontalChart").data([k]),y=x.enter().append("g").attr("class","wrap nvd3 multiBarHorizontalChart").append("g");y.append("g").attr("class","x axis"),y.append("g").attr("class","y axis"),y.append("g").attr("class","barsWrap"),y.append("g").attr("class","legendWrap"),y.append("g").attr("class","controlsWrap"),b.top=o.height();var z=x.select("g");g&&(o.width(v/2),z.select(".legendWrap").datum(k).call(o),b.top!=o.height()&&(b.top=o.height(),w=(d||parseInt(l.style("height"))||400)-b.top-b.bottom),z.select(".legendWrap").attr("transform","translate("+v/2+","+ -b.top+")")),j.width(v).height(w).color(k.map(function(a,b){return a.color||e[b%e.length]}).filter(function(a,b){return!k[b].disabled})),f&&(p.width(180).color(["#444","#444","#444"]),z.select(".controlsWrap").datum(s).attr("transform","translate(0,"+ -b.top+")").call(p)),z.attr("transform","translate("+b.left+","+b.top+")");var A=z.select(".barsWrap").datum(k.filter(function(a){return!a.disabled}));d3.transition(A).call(j),m.ticks(w/24).tickSize(-v,0),z.select(".x.axis").transition().duration(0).call(m);var B=z.select(".x.axis").selectAll("g");B.selectAll("line, text").style("opacity",1),n.ticks(v/100).tickSize(-w,0),z.select(".y.axis").attr("transform","translate(0,"+w+")"),d3.transition(z.select(".y.axis")).call(n),o.dispatch.on("legendClick",function(a,b){a.disabled=!a.disabled,k.filter(function(a){return!a.disabled}).length||k.ma
|
|
|
|
switch(i){case"stack":r.offset("zero"),r.order("default");break;case"stream":r.offset("wiggle"),r.order("inside-out");break;case"expand":r.offset("expand"),r.order("default")}return r};return r},a.models.stackedAreaChart=function(){function t(a){a.each(function(e){var i=d3.select(this),u=this,v=(c||parseInt(i.style("width"))||960)-b.left-b.right,w=(d||parseInt(i.style("height"))||400)-b.top-b.bottom;j=l.xScale(),k=l.yScale();var z=i.selectAll("g.wrap.stackedAreaChart").data([e]),A=z.enter().append("g").attr("class","wrap nvd3 stackedAreaChart").append("g");A.append("g").attr("class","x axis"),A.append("g").attr("class","y axis"),A.append("g").attr("class","stackedWrap"),A.append("g").attr("class","legendWrap"),A.append("g").attr("class","controlsWrap");var B=z.select("g");g&&(o.width(v/2),B.select(".legendWrap").datum(e).call(o),b.top!=o.height()&&(b.top=o.height(),w=(d||parseInt(i.style("height"))||400)-b.top-b.bottom),B.select(".legendWrap").attr("transform","translate("+v/2+","+ -b.top+")")),l.width(v).height(w),f&&(p.width(280).color(["#444","#444","#444"]),B.select(".controlsWrap").datum(r).attr("transform","translate(0,"+ -b.top+")").call(p)),B.attr("transform","translate("+b.left+","+b.top+")");var C=B.select(".stackedWrap").datum(e);d3.transition(C).call(l),m.scale(j).ticks(v/100).tickSize(-w,0),B.select(".x.axis").attr("transform","translate(0,"+w+")"),d3.transition(B.select(".x.axis")).call(m),n.scale(k).ticks(l.offset()=="wiggle"?0:w/36).tickSize(-v,0).tickFormat(l.offset()=="expand"?d3.format("%"):d3.format(",.2f")),d3.transition(B.select(".y.axis")).call(n),l.dispatch.on("areaClick.toggle",function(b){e.filter(function(a){return!a.disabled}).length===1?e=e.map(function(a){a.disabled=!1;return a}):e=e.map(function(a,c){a.disabled=c!=b.seriesIndex;return a}),a.transition().call(t)}),o.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,e.filter(function(a){return!a.disabled}).length||e.map(function(a){a.disabled=!1;return a}),a.transition().call(t)}),p.dispatch.on("legendClick",function(b,c){if(!!b.disabled){r=r.map(function(a){a.disabled=!0;return a}),b.disabled=!1;switch(b.key){case"Stacked":l.style("stack");break;case"Stream":l.style("stream");break;case"Expanded":l.style("expand")}a.transition().call(t)}}),q.on("tooltipShow",function(a){h&&s(a,u.parentNode)})}),t.update=function(){a.transition().call(t)},t.container=this;return t}var b={top:30,right:25,bottom:50,left:60},c=null,d=null,e=d3.scale.category20().range(),f=!0,g=!0,h=!0,i=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" on "+b+"</p>"},j,k,l=a.models.stackedArea(),m=a.models.axis().orient("bottom").tickPadding(5),n=a.models.axis().orient("left"),o=a.models.legend().height(30),p=a.models.legend().height(30),q=d3.dispatch("tooltipShow","tooltipHide"),r=[{key:"Stacked"},{key:"Stream",disabled:!0},{key:"Expanded",disabled:!0}],s=function(b,c){var d=b.pos[0]+(c.offsetLeft||0),e=b.pos[1]+(c.offsetTop||0),f=m.tickFormat()(l.x()(b.point,b.pointIndex)),g=n.tickFormat()(l.y()(b.point,b.pointIndex)),h=i(b.series.key,f,g,b,t);a.tooltip.show([d,e],h,b.value<0?"n":"s")};l.dispatch.on("tooltipShow",function(a){if(!Math.round(l.y()(a.point)*100)){setTimeout(function(){d3.selectAll(".point.hover").classed("hover",!1)},0);return!1}a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],q.tooltipShow(a)}),l.dispatch.on("tooltipHide",function(a){q.tooltipHide(a)}),q.on("tooltipHide",function(){h&&a.tooltip.cleanup()}),t.dispatch=q,t.stacked=l,t.xAxis=m,t.yAxis=n,d3.rebind(t,l,"x","y","size","xScale","yScale","xDomain","yDomain","sizeDomain","interactive","offset","order","style","clipEdge","forceX","forceY","forceSize"),t.margin=function(a){if(!arguments.length)return b;b=a;return t},t.width=function(a){if(!arguments.length)return getWidth;c=a;return t},t.height=function(a){if(!arguments.length)return getHeight;d=a;return t},t.color=function(a){if(!arguments.length)return e;e=a,o.color(a);return t},t.showControls=function(a){if(!arguments.length)return f;f=a;return t},t.showLegend=function(a){if(!arguments.length)return g;g=a;return t},t.tooltips=function(a){if(!argu
|