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

2 lines
56 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.models.axis=function(){function g(h){h.each(function(g){e.domain(a).range(b),f.orient(c);var h=d3.select(this).selectAll("text.axislabel").data([d||null]);switch(c){case"top":h.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",0),h.attr("x",b[1]/2);break;case"right":h.enter().append("text").attr("class","axislabel").attr("transform","rotate(90)").attr("y",-40),h.attr("x",-b[0]/2);break;case"bottom":h.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",25),h.attr("x",b[1]/2);break;case"left":h.enter().append("text").attr("class","axislabel").attr("transform","rotate(-90)").attr("y",-40),h.attr("x",-b[0]/2)}h.exit().remove(),h.text(function(a){return a}),d3.transition(d3.select(this)).call(f),d3.select(this).selectAll("line.tick").filter(function(a){return!parseFloat(Math.round(a*1e5)/1e6)}).classed("zero",!0)});return g}var a
.random()*1e4),i=d3.scale.category20(),j=!0,k=!1,l="",m=0,n=0,o=d3.dispatch("chartClick","elementClick","elementDblClick","tooltipShow","tooltipHide");p.margin=function(b){if(!arguments.length)return a;a=b;return p},p.width=function(d){if(!arguments.length)return b;a.left+a.right+20>d?b=a.left+a.right+20:b=d,e=Math.min(b-(a.left+a.right),c-(a.top+a.bottom))/2;return p},p.height=function(d){if(!arguments.length)return c;a.top+a.bottom+20>d?c=a.top+a.bottom+20:c=d,e=Math.min(b-(a.left+a.right),c-(a.top+a.bottom))/2;return p},p.animate=function(a){if(!arguments.length)return d;d=a;return p},p.labelField=function(a){if(!arguments.length)return f;f=a;return p},p.dataField=function(a){if(!arguments.length)return g;g=a;return p},p.showLabels=function(a){if(!arguments.length)return j;j=a;return p},p.donut=function(a){if(!arguments.length)return k;k=a;return p},p.title=function(a){if(!arguments.length)return l;l=a;return p},p.id=function(a){if(!arguments.length)return h;h=a;return p},p.dispatch=o;return p},a.models.scatter=function(){function z(n){n.each(function(n){function G(){if(!l){C.select("#points-clip-"+e).remove(),C.select(".point-paths").remove();return!1}E.append("clipPath").attr("id","points-clip-"+e),F.append("g").attr("class","point-paths");var b=d3.merge(n.map(function(a,b){return a.values.map(function(a,c){return[r(f(a,c))*(Math.random()/1e12+1),s(g(a,c))*(Math.random()/1e12+1),b,c]})})),c=C.select("#points-clip-"+e).selectAll("circle").data(b);c.enter().append("circle").attr("r",25),c.exit().remove(),c.attr("cx",function(a){return a[0]}).attr("cy",function(a){return a[1]}),C.select(".point-paths").attr("clip-path","url(#points-clip-"+e+")");var d=d3.geom.voronoi(b).map(function(a,c){return{data:a,series:b[c][2],point:b[c][3]}}),h=C.select(".point-paths").selectAll("path").data(d);h.enter().append("path").attr("class",function(a,b){return"path-"+b}),h.exit().remove(),h.attr("d",function(a){return"M"+a.data.join(",")+"Z"}).on("mouseover",function(b){var c=n[b.series],d=c.values[b.point];u.pointMouseover({point:d,series:c,pos:[r(f(d,b.point))+a.left,s(g(d,b.point))+a.top],seriesIndex:b.series,pointIndex:b.point})}).on("mouseout",function(a,b){u.pointMouseout({point:n[a.series].values[a.point],series:n[a.series],seriesIndex:a.series,pointIndex:a.point})}),u.on("pointMouseover.point",function(b){C.select(".series-"+b.seriesIndex+" .point-"+b.pointIndex).classed("hover",!0),C.select(".series-"+b.seriesIndex+" .distX-"+b.pointIndex).attr("y1",b.pos[1]-a.top),C.select(".series-"+b.seriesIndex+" .distY-"+b.pointIndex).attr("x1",b.pos[0]-a.left)}),u.on("pointMouseout.point",function(a){C.select(".series-"+a.seriesIndex+" circle.point-"+a.pointIndex).classed("hover",!1),C.select(".series-"+a.seriesIndex+" .distX-"+a.pointIndex).attr("y1",s.range()[0]),C.select(".series-"+a.seriesIndex+" .distY-"+a.pointIndex).attr("x1",r.range()[0])})}var z=n.map(function(a){return a.values.map(function(a,b){return{x:f(a,b),y:g(a,b),size:h(a,b)}})}),A=b-a.left-a.right,B=c-a.top-a.bottom;v=v||r,w=w||s,x=x||t,n=n.map(function(a,b){a.values=a.values.map(function(a){a.series=b;return a});return a}),r.domain(o||d3.extent(d3.merge(z).map(function(a){return a.x}).concat(i))).range([0,A]),s.domain(p||d3.extent(d3.merge(z).map(function(a){return a.y}).concat(j))).range([B,0]),t.domain(q||d3.extent(d3.merge(z).map(function(a){return a.size}).concat(k))).range([2,10]);var C=d3.select(this).selectAll("g.d3scatter").data([n]),D=C.enter().append("g").attr("class","d3scatter"),E=D.append("defs"),F=D.append("g");F.append("g").attr("class","groups"),F.append("g").attr("class","distribution"),C.attr("transform","translate("+a.left+","+a.top+")"),E.append("clipPath").attr("id","edge-clip-"+e).append("rect"),C.select("#edge-clip-"+e+" rect").attr("width",A).attr("height",B),F.attr("clip-path",m?"url(#edge-clip-"+e+")":null);var H=C.select(".groups").selectAll(".group").data(function(a){return a},function(a){return a.key});H.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(H.exit()).style("stroke-opacity",1e-6).style("fi