You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nvd3/nv.d3.min.js

4 lines
104 KiB
JavaScript

(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){var c=[31,28,31,30,31,30,31,31,30,31,30,31];if(a!=2)return c[a-1];if(b%4!=0)return c[1];if(b%100==0&&b%400!=0)return c[1];return c[1]+1}var a={version:"0.0.1a",dev:!0};window.nv=a,a.tooltip={},a.utils={},a.models={},a.charts={},a.graphs=[],a.log={},a.dispatch=d3.dispatch("render_start","render_end"),a.dispatch.on("render_start",function(b){a.log.startTime=+(new Date)}),a.dispatch.on("render_end",function(b){a.log.endTime=+(new Date),a.log.totalTime=a.log.endTime-a.log.startTime,a.dev&&console.log&&console.log("total",a.log.totalTime)}),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){var f=document.createElement("div");f.className="nvtooltip",d=d||"s",e=e||20;var g=document.getElementsByTagName("body")[0];f.innerHTML=c,f.style.left=1,f.style.top=1,f.style.opacity=0,g.appendChild(f);var h=parseInt(f.offsetHeight),i=parseInt(f.offsetWidth),j=a.utils.windowSize().width,k=a.utils.windowSize().height,l=g.scrollTop,m=g.scrollLeft,n,o;switch(d){case"e":n=b[0]-i-e,o=b[1]-h/2,n<m&&(n=b[0]+e),o<l&&(o=l+5),o+h>l+k&&(o=l-h-5);break;case"w":n=b[0]+e,o=b[1]-h/2,n+i>j&&(n=b[0]-i-e),o<l&&(o=l+5),o+h>l+k&&(o=l-h-5);break;case"n":n=b[0]-i/2,o=b[1]+e,n<m&&(n=m+5),n+i>j&&(n=j-i-5),o+h>l+k&&(o=b[1]-h-e);break;case"s":n=b[0]-i/2,o=b[1]-h-e,n<m&&(n=m+5),n+i>j&&(n=j-i-5),l>o&&(o=b[1]+20)}f.style.left=n+"px",f.style.top=o+"px",f.style.opacity=1;return f},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 e(f){f.each(function(e){(d.orient()=="top"||d.orient()=="bottom")&&d.ticks(Math.abs(a.range()[1]-a.range()[0])/100);var f=d3.select(this).selectAll("text.axislabel").data([b||null]);f.exit().remove();switch(d.orient()){case"top":f.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",0),f.attr("x",a.range()[1]/2);break;case"right":f.enter().append("text").attr("class","axislabel").attr("transform","rotate(90)").attr("y",-40),f.attr("x",-a.range()[0]/2);break;case"bottom":f.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",25),f.attr("x",a.range()[1]/2);break;case"left":f.enter().append("text").attr("class","axislabel").attr("transform","rotate(-90)").attr("y",-40),f.attr("x",-a.ra
),p.margin=function(a){if(!arguments.length)return b;b=a;return p},p.width=function(a){if(!arguments.length)return c;c=a;return p},p.height=function(a){if(!arguments.length)return d;d=a;return p},p.x=function(a){if(!arguments.length)return g;g=a,j.x(a);return p},p.y=function(a){if(!arguments.length)return h;h=a,j.y(a);return p},p.clipEdge=function(a){if(!arguments.length)return i;i=a;return p},p.color=function(a){if(!arguments.length)return e;e=a,j.color(a);return p},p.id=function(a){if(!arguments.length)return f;f=a;return p};return p},a.models.lineChart=function(){function q(h){h.each(function(r){var s=d3.select(this),t=(d||parseInt(s.style("width"))||960)-b.left-b.right,u=(e||parseInt(s.style("height"))||400)-b.top-b.bottom,v=s.selectAll("g.wrap.lineWithLegend").data([r]),w=v.enter().append("g").attr("class","wrap nvd3 lineWithLegend").append("g");w.append("g").attr("class","x axis"),w.append("g").attr("class","y axis"),w.append("g").attr("class","linesWrap"),w.append("g").attr("class","legendWrap");var z=v.select("g");f&&(n.width(t),z.select(".legendWrap").datum(r).call(n),b.top!=n.height()&&(b.top=n.height(),u=(e||parseInt(s.style("height"))||400)-b.top-b.bottom),z.select(".legendWrap").attr("transform","translate(0,"+ -b.top+")")),i.width(t).height(u).color(r.map(function(a,b){return a.color||c[b%10]}).filter(function(a,b){return!r[b].disabled})),z.attr("transform","translate("+b.left+","+b.top+")");var A=z.select(".linesWrap").datum(r.filter(function(a){return!a.disabled}));d3.transition(A).call(i),l.scale(j).ticks(t/100).tickSize(-u,0),z.select(".x.axis").attr("transform","translate(0,"+k.range()[0]+")"),d3.transition(z.select(".x.axis")).call(l),m.scale(k).ticks(u/36).tickSize(-t,0),d3.transition(z.select(".y.axis")).call(m),n.dispatch.on("legendClick",function(a,b){a.disabled=!a.disabled,r.filter(function(a){return!a.disabled}).length||r.map(function(a){a.disabled=!1,v.selectAll(".series").classed("disabled",!1);return a}),h.transition().call(q)}),i.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],o.tooltipShow(a)}),g&&o.on("tooltipShow",function(a){p(a,s[0][0])}),i.dispatch.on("elementMouseout.tooltip",function(a){o.tooltipHide(a)}),g&&o.on("tooltipHide",a.tooltip.cleanup)}),q.update=function(){q(h)};return q}var b={top:30,right:20,bottom:50,left:60},c=d3.scale.category20().range(),d=null,e=null,f=!0,g=!0,h=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" at "+b+"</p>"},i=a.models.line(),j=i.xScale(),k=i.yScale(),l=a.models.axis().scale(j).orient("bottom"),m=a.models.axis().scale(k).orient("left"),n=a.models.legend().height(30),o=d3.dispatch("tooltipShow","tooltipHide"),p=function(b,c){var d=b.pos[0]+(c.offsetLeft||0),e=b.pos[1]+(c.offsetTop||0),f=l.tickFormat()(i.x()(b.point)),g=m.tickFormat()(i.y()(b.point)),j=h(b.series.key,f,g,b,q);a.tooltip.show([d,e],j)};q.dispatch=o,q.legend=n,q.xAxis=l,q.yAxis=m,d3.rebind(q,i,"x","y","size","xDomain","yDomain","forceX","forceY","interactive","clipEdge","clipVoronoi","id"),q.margin=function(a){if(!arguments.length)return b;b=a;return q},q.width=function(a){if(!arguments.length)return d;d=a;return q},q.height=function(a){if(!arguments.length)return e;e=a;return q},q.color=function(a){if(!arguments.length)return c;c=a,n.color(a);return q},q.showLegend=function(a){if(!arguments.length)return f;f=a;return q},q.tooltips=function(a){if(!arguments.length)return g;g=a;return q},q.tooltipContent=function(a){if(!arguments.length)return h;h=a;return q};return q},a.models.linePlusBar=function(){function s(a){a.each(function(e){var t=c(),u=d(),v=t-b.left-b.right,w=u-b.top-b.bottom,y=e.filter(function(a){return!a.disabled&&a.bar}).map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b)}})}),z=e.filter(function(a){return!a.disabled&&!a.bar}).map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b)}})});j.domain(d3.extent(d3.merge(y.concat(z)),function(a){return a.x})).range([0,v]),k.domain(d3.extent(d3.merge(y),function(a){return a.y})).range([w,0]),l.domain(d3.extent(d3.merge(z),function(a){return a.y}
.x})).rangeBands([0,s],.1),h.domain(d3.extent(d3.merge(t).map(function(a){return a.y}).concat(m.forceY))).range([0,r]),m.width(r).height(s).color(q.map(function(a,b){return a.color||e[b%10]}).filter(function(a,b){return!q[b].disabled}));var u=d3.select(this).selectAll("g.wrap").data([q]),v=u.enter().append("g").attr("class","wrap nvd3 multiBarHorizontalWithLegend").append("g");v.append("g").attr("class","x axis"),v.append("g").attr("class","y axis"),v.append("g").attr("class","linesWrap"),v.append("g").attr("class","legendWrap"),v.append("g").attr("class","controlsWrap"),b.top=k.height();var w=u.select("g").attr("transform","translate("+b.left+","+b.top+")");k.width(r/2),w.select(".legendWrap").datum(q).attr("transform","translate("+r/2+","+ -b.top+")").call(k),f&&(l.width(180).color(["#444","#444","#444"]),w.select(".controlsWrap").datum(o).attr("transform","translate(0,"+ -b.top+")").call(l));var z=w.select(".linesWrap").datum(q.filter(function(a){return!a.disabled}));d3.transition(z).call(m),i.scale(g).ticks(s/24).tickSize(-r,0),d3.transition(w.select(".x.axis")).call(i);var A=w.select(".x.axis").selectAll("g");A.selectAll("line, text").style("opacity",1),A.filter(function(a,b){return b%Math.ceil(q[0].values.length/(r/100))!==0}).selectAll("line, text").style("opacity",0),j.domain(h.domain()).range(h.range()).ticks(r/100).tickSize(-s,0),w.select(".y.axis").attr("transform","translate(0,"+s+")"),d3.transition(w.select(".y.axis")).call(j),k.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,q.filter(function(a){return!a.disabled}).length||q.map(function(a){a.disabled=!1,u.selectAll(".series").classed("disabled",!1);return a}),a.transition().call(p)}),l.dispatch.on("legendClick",function(b,c){if(!!b.disabled){o=o.map(function(a){a.disabled=!0;return a}),b.disabled=!1;switch(b.key){case"Grouped":m.stacked(!1);break;case"Stacked":m.stacked(!0)}a.transition().call(p)}}),m.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],n.tooltipShow(a)}),m.dispatch.on("elementMouseout.tooltip",function(a){n.tooltipHide(a)})});return p}var b={top:30,right:20,bottom:50,left:60},c=function(){return 960},d=function(){return 500},e=d3.scale.category20().range(),f=!0,g=d3.scale.ordinal(),h=d3.scale.linear(),i=a.models.axis().scale(g).orient("left").highlightZero(!1),j=a.models.axis().scale(h).orient("bottom"),k=a.models.legend().height(30),l=a.models.legend().height(30),m=a.models.multiBarHorizontal().stacked(!1),n=d3.dispatch("tooltipShow","tooltipHide"),o=[{key:"Grouped"},{key:"Stacked",disabled:!0}];p.dispatch=n,p.legend=k,p.xAxis=i,p.yAxis=j,d3.rebind(p,m,"x","y","xDomain","yDomain","forceX","forceY","clipEdge","id"),p.margin=function(a){if(!arguments.length)return b;b=a;return p},p.width=function(a){if(!arguments.length)return c;c=d3.functor(a);return p},p.height=function(a){if(!arguments.length)return d;d=d3.functor(a);return p},p.showControls=function(a){if(!arguments.length)return f;f=a;return p};return p},a.models.pie=function(){function p(m){m.each(function(m){function z(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return t(b(a))}}function y(a){var b=(a.startAngle+a.endAngle)*90/Math.PI-90;return b>90?b-180:b}var n=d3.select(this).on("click",function(a,b){o.chartClick({data:a,index:b,pos:d3.event,id:h})}),p=n.selectAll("svg.margin").data([m]),q=p.enter();q.append("text").attr("class","title").attr("dy",".91em").attr("text-anchor","start").text(l),q.append("svg").attr("class","margin").attr("x",a.left).attr("y",a.top).style("overflow","visible");var r=p.selectAll("g.wrap").data([m]);r.exit().remove();var s=r.enter();s.append("g").attr("class","wrap").attr("id","wrap-"+h).append("g").attr("class","pie"),r.attr("width",b).attr("height",c).attr("transform","translate("+e+","+e+")");var t=d3.svg.arc().outerRadius(e-e/5);k&&t.innerRadius(e/2);var u=d3.layout.pie().value(function(a){return a[g]}),v=p.select(".pie").selectAll(".slice").data(u);v.exit().remove();var w=v.enter().append("svg:g").attr("class","slice").on("mouseover",function(a,b){d3.se
c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c,c.pointIndex)),l=j(f.y()(c.point)),m=e(c.series.key,k,l,c,f);a.tooltip.show([g,h],m)};f.xAxis.tickFormat(function(a){return d3.time.format("%x")(new Date(c[0].values[a].x))}),f.yAxis.tickFormat(d3.format(",.2%")),h.build=function(){if(!b||!c.length)return h;a.addGraph({generate:function(){var a=d3.select(b),e=function(){return parseInt(a.style("width"))},g=function(){return parseInt(a.style("height"))},h=a.append("svg");f.width(e).height(g),h.attr("width",e()).attr("height",g()).datum(c).transition().duration(d).call(f);return f},callback:function(c){c.dispatch.on("tooltipShow",g),c.dispatch.on("tooltipHide",a.tooltip.cleanup),window.onresize=function(){d3.select(b+" svg").attr("width",c.width()()).attr("height",c.height()()).call(c)}}});return h},h.data=function(a){if(!arguments.length)return c;c=a;return h},h.selector=function(a){if(!arguments.length)return b;b=a;return h},h.duration=function(a){if(!arguments.length)return d;d=a;return h},h.tooltip=function(a){if(!arguments.length)return e;e=a;return h},h.xTickFormat=function(a){if(!arguments.length)return f.xAxis.tickFormat();f.xAxis.tickFormat(typeof a=="function"?a:d3.format(a));return h},h.yTickFormat=function(a){if(!arguments.length)return f.yAxis.tickFormat();f.yAxis.tickFormat(typeof a=="function"?a:d3.format(a));return h},h.xAxisLabel=function(a){if(!arguments.length)return f.xAxis.axisLabel();f.xAxis.axisLabel(a);return h},h.yAxisLabel=function(a){if(!arguments.length)return f.yAxis.axisLabel();f.yAxis.axisLabel(a);return h},d3.rebind(h,f,"x","y"),h.graph=f;return h},a.charts.line=function(){function h(){if(!b||!c.length)return h;d3.select(b).select("svg").datum(c).transition().duration(d).call(f);return h}var b=null,c=[],d=500,e=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" at "+b+"</p>"},f=a.models.lineWithLegend(),g=function(c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c.point)),l=j(f.y()(c.point)),m=e(c.series.key,k,l,c,f);a.tooltip.show([g,h],m)};f.xAxis.tickFormat(d3.format(",r")),f.yAxis.tickFormat(d3.format(",.2f")),h.build=function(){if(!b||!c.length)return h;a.addGraph({generate:function(){var a=d3.select(b),e=function(){return parseInt(a.style("width"))},g=function(){return parseInt(a.style("height"))},h=a.append("svg");f.width(e).height(g),h.attr("width",e()).attr("height",g()).datum(c).transition().duration(d).call(f);return f},callback:function(c){c.dispatch.on("tooltipShow",g),c.dispatch.on("tooltipHide",a.tooltip.cleanup),window.onresize=function(){d3.select(b+" svg").attr("width",c.width()()).attr("height",c.height()()).call(c)}}});return h},h.data=function(a){if(!arguments.length)return c;c=a;return h},h.selector=function(a){if(!arguments.length)return b;b=a;return h},h.duration=function(a){if(!arguments.length)return d;d=a;return h},h.tooltip=function(a){if(!arguments.length)return e;e=a;return h},h.xTickFormat=function(a){if(!arguments.length)return f.xAxis.tickFormat();f.xAxis.tickFormat(typeof a=="function"?a:d3.format(a));return h},h.yTickFormat=function(a){if(!arguments.length)return f.yAxis.tickFormat();f.yAxis.tickFormat(typeof a=="function"?a:d3.format(a));return h},h.xAxisLabel=function(a){if(!arguments.length)return f.xAxis.axisLabel();f.xAxis.axisLabel(a);return h},h.yAxisLabel=function(a){if(!arguments.length)return f.yAxis.axisLabel();f.yAxis.axisLabel(a);return h},d3.rebind(h,f,"x","y"),h.graph=f;return h},a.charts.lineChartDaily=function(){function h(){if(!b||!c.length)return h;d3.select(b).select("svg").datum(c).transition().duration(d).call(f);return h}var b=null,c=[],d=500,e=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" at "+b+"</p>"},f=a.models.lineWithLegend().x(function(a,b){return b}),g=function(c){var d=document.getElementById(b.substr(1)),g=c.pos[0]+d.offsetLeft,h=c.pos[1]+d.offsetTop,i=f.xAxis.tickFormat(),j=f.yAxis.tickFormat(),k=i(f.x()(c,c.pointInde