nvd3/nv.d3.min.js

4 lines
124 KiB
JavaScript
Raw Normal View History

(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===0&&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.dev&&(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.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==typeof 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]==typeof 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,g){var h=document.createElement("div");h.className="nvtooltip "+(g?g:"xy-tooltip"),d=d||"s",e=e||20;var i=f?f:document.getElementsByTagName("body")[0];h.innerHTML=c,h.style.left=0,h.style.top=0,h.style.opacity=0,i.appendChild(h);var j=parseInt(h.offsetHeight),k=parseInt(h.offsetWidth),l=a.utils.windowSize().width,m=a.utils.windowSize().height,n=i.scrollTop,o=i.scrollLeft,p,q;switch(d){case"e":p=b[0]-k-e,q=b[1]-j/2,p<o&&(p=b[0]+e),q<n&&(q=n+5),q+j>n+m&&(q=n-j-5);break;case"w":p=b[0]+e,q=b[1]-j/2,p+k>l&&(p=b[0]-k-e),q<n&&(q=n+5),q+j>n+m&&(q=n-j-5);break;case"n":p=b[0]-k/2,q=b[1]+e,p<o&&(p=o+5),p+k>l&&(p=l-k-5),q+j>n+m&&(q=b[1]-j-e);break;case"s":p=b[0]-k/2,q=b[1]-j-e,p<o&&(p=o+5),p+k>l&&(p=l-k-5),n>q&&(q=b[1]+20)}h.style.left=p+"px",h.style.top=q+"px",h.style.opacity=1,h.style.position="absolute",h.style.pointerEvents="none";return h},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.utils.getColor=function(b){if(!arguments.length)return a.utils.defaultColor();return Object.prototype.toString.call(b)==="[object Array]"?function(a,c){return a.color||b[c%b.length]}:b},a.utils.defaultColor=function(){var a=d3.scale.category20().range();return function(b,c){return b.color||a[c%a.length]}},a.utils.pjax=function(b,c){function d(d){d3.html(d,function(d){var e=d3.select(c).node();e.parentNode.replaceChild(d3.select(d).select(c).node(),e),a.utils.pjax(b,c)})}d3.selectAll(b).on("click",function(){history.pushState(this.href,this.textContent,this.href),d(this.href),d3.event.preventDefault()}),d3.select(window).on("popstate",function(){d3.event.state&&d(d3.event.state)})},
a){if(!arguments.length)return g;g=a;return r},r.tooltipContent=function(a){if(!arguments.length)return h;h=a;return r},r.noData=function(a){if(!arguments.length)return i;i=a;return r};return r},a.models.distribution=function(){function k(a){a.each(function(a){var h=c-(e==="x"?b.left+b.right:b.top+b.bottom),k=e=="x"?"y":"x";j=j||i;var l=d3.select(this).selectAll("g.nv-distribution").data([a]),m=l.enter().append("g").attr("class","nvd3 nv-distribution"),n=m.append("g"),o=l.select("g");l.attr("transform","translate("+b.left+","+b.top+")");var p=o.selectAll("g.nv-dist").data(function(a){return a},function(a){return a.key});p.enter().append("g"),p.attr("class",function(a,b){return"nv-dist nv-series-"+b}).style("stroke",function(a,b){return g(a,b)});var q=p.selectAll("line.nv-dist"+e).data(function(a){return a.values});q.enter().append("line").attr(e+"1",function(a,b){return j(f(a,b))}).attr(e+"2",function(a,b){return j(f(a,b))}),d3.transition(p.exit().selectAll("line.nv-dist"+e)).attr(e+"1",function(a,b){return i(f(a,b))}).attr(e+"2",function(a,b){return i(f(a,b))}).style("stroke-opacity",0).remove(),q.attr("class",function(a,b){return"nv-dist"+e+" nv-dist"+e+"-"+b}).attr(k+"1",0).attr(k+"2",d),d3.transition(q).attr(e+"1",function(a,b){return i(f(a,b))}).attr(e+"2",function(a,b){return i(f(a,b))}),j=i.copy()});return k}var b={top:0,right:0,bottom:0,left:0},c=400,d=8,e="x",f=function(a){return a[e]},g=a.utils.defaultColor(),h,i=d3.scale.linear(),j;k.margin=function(a){if(!arguments.length)return b;b=a;return k},k.width=function(a){if(!arguments.length)return c;c=a;return k},k.axis=function(a){if(!arguments.length)return e;e=a;return k},k.size=function(a){if(!arguments.length)return d;d=a;return k},k.getData=function(a){if(!arguments.length)return f;f=d3.functor(a);return k},k.scale=function(a){if(!arguments.length)return i;i=a;return k},k.color=function(b){if(!arguments.length)return g;g=a.utils.getColor(b);return k};return k},a.models.indentedTree=function(){function j(a){a.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}function z(a){return a._values&&a._values.length?iconOpen:a.values&&a.values.length?iconClose:""}function y(a,b,c){d3.event.stopPropagation();if(d3.event.shiftKey&&!c){d3.event.shiftKey=!1,a.values&&a.values.forEach(function(a){(a.values||a._values)&&y(a,0,!0)});return!0}if(!B(a))return!0;a.values?(a._values=a.values,a.values=null):(a.values=a._values,a._values=null),j.update()}var f=c-b.left-b.right,k=d-b.top-b.bottom;j.update=function(){a.transition().call(j)};var l=0,m=1,n=d3.layout.tree().children(function(a){return a.values}).size([d,childIndent]);e[0].key||(e[0].key=h);var o=n.nodes(e[0]),p=d3.select(this).selectAll("div").data([[o]]),q=p.enter().append("div").attr("class","nvd3 nv-wrap nv-indentedtree"),r=q.append("table"),s=p.select("table").attr("width","100%").attr("class",tableClass);if(g){var t=r.append("thead"),u=t.append("tr");columns.forEach(function(a){u.append("th").attr("width",a.width?a.width:"10%").style("text-align",a.type=="numeric"?"right":"left").append("span").text(a.label)})}var v=s.selectAll("tbody").data(function(a){return a});v.enter().append("tbody"),m=d3.max(o,function(a){return a.depth}),n.size([d,m*childIndent]);var w=v.selectAll("tr").data(function(a){return a},function(a){return a.id||a.id==++l});w.exit().remove(),w.select("img.nv-treeicon").attr("src",z).classed("folded",A);var x=w.enter().append("tr");columns.forEach(function(a,b){var c=x.append("td").style("padding-left",function(a){return(b?0:a.depth*childIndent+12+(z(a)?0:16))+"px"},"important").style("text-align",a.type=="numeric"?"right":"left");b==0&&c.append("img").classed("nv-treeicon",!0).classed("nv-folded",A).attr("src",z).style("width","14px").style("height","14px").style("padding","0 1px").style("display",function(a){return z(a)?"inline-block":"none"}).on("click",y),c.append("span").attr("class",d3.functor(a.classes)).text(function(b){return a.format?a.format(b):b[a.key]||"-"}),a.showCount&&c.append("span").attr("class","nv-children
a){if(!arguments.length)return o;o=a;return t},t.yDomain=function(a){if(!arguments.length)return p;p=a;return t},t.forceY=function(a){if(!arguments.length)return j;j=a;return t},t.stacked=function(a){if(!arguments.length)return l;l=a;return t},t.clipEdge=function(a){if(!arguments.length)return k;k=a;return t},t.color=function(b){if(!arguments.length)return m;m=a.utils.getColor(b);return t},t.id=function(a){if(!arguments.length)return g;g=a;return t},t.delay=function(a){if(!arguments.length)return n;n=a;return t};return t},a.models.multiBarChart=function(){function v(a){a.each(function(k){var w=d3.select(this),z=this,A=(c||parseInt(w.style("width"))||960)-b.left-b.right,B=(d||parseInt(w.style("height"))||400)-b.top-b.bottom;if(!k||!k.length||!k.filter(function(a){return a.values.length}).length){w.append("text").attr("class","nvd3 nv-noData").attr("x",A/2).attr("y",B/2).attr("dy","-.7em").style("text-anchor","middle").text(n);return v}w.select(".nv-noData").remove(),l=o.xScale(),m=o.yScale();var C=w.selectAll("g.nv-wrap.nv-multiBarWithLegend").data([k]),D=C.enter().append("g").attr("class","nvd3 nv-wrap nv-multiBarWithLegend").append("g");D.append("g").attr("class","nv-x nv-axis"),D.append("g").attr("class","nv-y nv-axis"),D.append("g").attr("class","nv-barsWrap"),D.append("g").attr("class","nv-legendWrap"),D.append("g").attr("class","nv-controlsWrap");var E=C.select("g");g&&(r.width(A/2),E.select(".nv-legendWrap").datum(k).call(r),b.top!=r.height()&&(b.top=r.height(),B=(d||parseInt(w.style("height"))||400)-b.top-b.bottom),E.select(".nv-legendWrap").attr("transform","translate("+A/2+","+ -b.top+")")),o.width(A).height(B).color(k.map(function(a,b){return a.color||e(a,b)}).filter(function(a,b){return!k[b].disabled}));if(f){var F=[{key:"Grouped",disabled:o.stacked()},{key:"Stacked",disabled:!o.stacked()}];s.width(180).color(["#444","#444","#444"]),E.select(".nv-controlsWrap").datum(F).attr("transform","translate(0,"+ -b.top+")").call(s)}E.attr("transform","translate("+b.left+","+b.top+")");var G=E.select(".nv-barsWrap").datum(k.filter(function(a){return!a.disabled}));d3.transition(G).call(o),p.scale(l).ticks(A/100).tickSize(-B,0),E.select(".nv-x.nv-axis").attr("transform","translate(0,"+m.range()[0]+")"),d3.transition(E.select(".nv-x.nv-axis")).call(p);var H=E.select(".nv-x.nv-axis > g").selectAll("g");H.selectAll("line, text").style("opacity",1),h&&H.filter(function(a,b){return b%Math.ceil(k[0].values.length/(A/100))!==0}).selectAll("text, line").style("opacity",0),i&&H.selectAll("text").attr("transform",function(a,b,c){return"rotate("+i+" 0,0)"}).attr("text-transform",i>0?"start":"end"),q.scale(m).ticks(B/36).tickSize(-A,0),d3.transition(E.select(".nv-y.nv-axis")).call(q),r.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,k.filter(function(a){return!a.disabled}).length||k.map(function(a){a.disabled=!1,C.selectAll(".nv-series").classed("disabled",!1);return a}),a.transition().call(v)}),s.dispatch.on("legendClick",function(b,c){if(!!b.disabled){F=F.map(function(a){a.disabled=!0;return a}),b.disabled=!1;switch(b.key){case"Grouped":o.stacked(!1);break;case"Stacked":o.stacked(!0)}a.transition().call(v)}}),t.on("tooltipShow",function(a){j&&u(a,z.parentNode)}),v.update=function(){a.transition().call(v)},v.container=this});return v}var b={top:30,right:20,bottom:50,left:60},c=null,d=null,e=a.utils.defaultColor(),f=!0,g=!0,h=!0,i=0,j=!0,k=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" on "+b+"</p>"},l,m,n="No Data Available.",o=a.models.multiBar().stacked(!1),p=a.models.axis().orient("bottom").highlightZero(!1).showMaxMin(!1),q=a.models.axis().orient("left"),r=a.models.legend().height(30),s=a.models.legend().height(30),t=d3.dispatch("tooltipShow","tooltipHide");p.tickFormat(function(a){return a}),q.tickFormat(d3.format(",.1f"));var u=function(b,c){var d=b.pos[0]+(c.offsetLeft||0),e=b.pos[1]+(c.offsetTop||0),f=p.tickFormat()(o.x()(b.point,b.pointIndex)),g=q.tickFormat()(o.y()(b.point,b.pointIndex)),h=k(b.series.key,f,g,b,v);a.tooltip.show([d,e],h,b.value<0?"n":"s",null,c)};o.dispatch.on("elementMouseover.tooltip2
pos=[a.pos[0]+b.left,a.pos[1]+b.top],l.tooltipShow(a)}),g&&l.on("tooltipShow",function(a){m(a)}),j.dispatch.on("elementMouseout.tooltip",function(a){l.tooltipHide(a)}),g&&l.on("tooltipHide",a.tooltip.cleanup),n.update=function(){f.transition().call(n)},n.container=this});return n}var b={top:30,right:20,bottom:20,left:20},c=null,d=null,e=!0,f=a.utils.defaultColor(),g=!0,h=function(a,b,c,d){return"<h3>"+a+"</h3>"+"<p>"+b+"</p>"},i="No Data Available.",j=a.models.pie(),k=a.models.legend().height(30),l=d3.dispatch("tooltipShow","tooltipHide"),m=function(b,c){var d=b.pos[0]+(c&&c.offsetLeft||0),e=b.pos[1]+(c&&c.offsetTop||0),f=j.valueFormat()(j.y()(b.point)),g=h(j.x()(b.point),f,b,n);a.tooltip.show([d,e],g,b.value<0?"n":"s",null,c)};n.dispatch=l,n.pie=j,d3.rebind(n,j,"valueFormat","values","x","y","id","showLabels","donutLabelsOutside","donut","labelThreshold"),n.margin=function(a){if(!arguments.length)return b;b=a;return n},n.width=function(a){if(!arguments.length)return c;c=a;return n},n.height=function(a){if(!arguments.length)return d;d=a;return n},n.color=function(b){if(!arguments.length)return f;f=a.utils.getColor(b),k.color(f),j.color(f);return n},n.showLegend=function(a){if(!arguments.length)return e;e=a;return n},n.tooltips=function(a){if(!arguments.length)return g;g=a;return n},n.tooltipContent=function(a){if(!arguments.length)return h;h=a;return n},n.noData=function(a){if(!arguments.length)return i;i=a;return n};return n},a.models.scatter=function(){function G(a){a.each(function(a){function P(){if(!q)return!1;var c,d=d3.merge(a.map(function(a,b){return a.values.filter(r).map(function(a,c){return[g(j(a,c))*(Math.random()/1e12+1),h(k(a,c))*(Math.random()/1e12+1),b,c]})}));if(t){M.append("clipPath").attr("id","nv-points-clip-"+f);var e=K.select("#nv-points-clip-"+f).selectAll("circle").data(d);e.enter().append("circle").attr("r",u),e.exit().remove(),e.attr("cx",function(a){return a[0]}).attr("cy",function(a){return a[1]}),K.select(".nv-point-paths").attr("clip-path","url(#nv-points-clip-"+f+")")}if(B===!0){var i=d3.geom.voronoi(d).map(function(a,b){return{data:a,series:d[b][2],point:d[b][3]}}),l=K.select(".nv-point-paths").selectAll("path").data(i);l.enter().append("path").attr("class",function(a,b){return"nv-path-"+b}),l.exit().remove(),l.attr("d",function(a){return"M"+a.data.join(",")+"Z"}),c=l}else{var m=d.map(function(a,b){return{data:a,series:d[b][2],point:d[b][3]}});c=K.select(".nv-groups").selectAll(".nv-group").selectAll("path.nv-point").data(m).style("pointer-events","auto")}c.on("click",function(c){var d=a[c.series],e=d.values[c.point];A.elementClick({point:e,series:d,pos:[g(j(e,c.point))+b.left,h(k(e,c.point))+b.top],seriesIndex:c.series,pointIndex:c.point})}).on("mouseover",function(c){var d=a[c.series],e=d.values[c.point];A.elementMouseover({point:e,series:d,pos:[g(j(e,c.point))+b.left,h(k(e,c.point))+b.top],seriesIndex:c.series,pointIndex:c.point})}).on("mouseout",function(b,c){var d=a[b.series],e=d.values[b.point];A.elementMouseout({point:e,series:d,seriesIndex:b.series,pointIndex:b.point})})}var G=c-b.left-b.right,H=d-b.top-b.bottom,I=d3.select(this);a=a.map(function(a,b){a.values=a.values.map(function(a){a.series=b;return a});return a});var J=v&&w&&x?[]:d3.merge(a.map(function(a){return a.values.map(function(a,b){return{x:j(a,b),y:k(a,b),size:l(a,b)}})}));g.domain(v||d3.extent(J.map(function(a){return a.x}).concat(n))).range([0,G]),h.domain(w||d3.extent(J.map(function(a){return a.y}).concat(o))).range([H,0]),i.domain(x||d3.extent(J.map(function(a){return a.size}).concat(p))).range(y||[16,256]);if(g.domain()[0]===g.domain()[1]||h.domain()[0]===h.domain()[1])z=!0;g.domain()[0]===g.domain()[1]&&(g.domain()[0]?g.domain([g.domain()[0]-g.domain()[0]*.01,g.domain()[1]+g.domain()[1]*.01]):g.domain([-1,1])),h.domain()[0]===h.domain()[1]&&(h.domain()[0]?h.domain([h.domain()[0]+h.domain()[0]*.01,h.domain()[1]-h.domain()[1]*.01]):h.domain([-1,1])),C=C||g,D=D||h,E=E||i;var K=I.selectAll("g.nv-wrap.nv-scatter").data([a]),L=K.enter().append("g").attr("class","nvd3 nv-wrap nv-scatter nv-chart-"+f+(z?" nv-single-point