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
112 KiB
JavaScript

(function(){function b(a,b){return(new Date(b,a+1,0)).getDate()}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}}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(){return a.dev&&console.log&&console.log.apply(console,arguments),arguments[arguments.length-1]},a.render=function d(b){b=b||1,d.active=!0,a.dispatch.render_start(),setTimeout(function(){var c;for(var e=0;e<b&&(graph=d.queue[e]);e++)c=graph.generate(),typeof graph.callback=="function"&&graph.callback(c),a.graphs.push(c);d.queue.splice(0,e),d.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,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)}return h.style.left=p+"px",h.style.top=q+"px",h.style.opacity=1,h.style.position="absolute",h.style.pointerEvents="none",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};return 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),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 i(b){return b.each(function(b){var i=d3.select(this),j=i.selectAll("g.wrap.axis").data([b]),k=j.enter().append("g").attr("class","wrap axis"),l=k.append("g"),m=j.select("g");(g.orient()=="top"||g.orient()=="bottom")&&g.ticks(Math.abs(c.range()[1]-c.range()[0])/100),d3.transition(m).call(g),h=h||g.scale();var n=m.selectAll("text.axislabel").data([d||null]);n.exit().remove();switch(g.orient()){case"top":n.enter().append("text").attr("class","axislabel").attr("text-anchor","middle").attr("y",0);var o=c.range().length==2?c.range()[1]:c.range()[c.range().length-1]+(c.range()[1]-c.range()[0]);n.attr("x",o/2);if(e){var p=j.selectAll("g.axisMaxMin").data(
).data([o]),N=M.enter().append("g").attr("class","wrap nvd3 historicalStockChart"),O=N.append("defs"),P=N.append("g");P.append("g").attr("class","brushBackground"),P.append("g").attr("class","x axis"),P.append("g").attr("class","x2 axis"),P.append("g").attr("class","x3 axis"),P.append("g").attr("class","y1 axis"),P.append("g").attr("class","y2 axis"),P.append("g").attr("class","y3 axis"),P.append("g").attr("class","barsWrap"),P.append("g").attr("class","stocksWrap"),P.append("g").attr("class","linesWrap"),P.append("g").attr("class","legendWrap"),P.append("g").attr("class","x brush");var Q=M.select("g"),R=Q.select("defs");m&&(D.width(v/2),Q.select(".legendWrap").datum(o.map(function(a){return a.originalKey=a.originalKey===undefined?a.key:a.originalKey,a.key=a.originalKey,a})).call(D),b.top!=D.height()&&(b.top=D.height(),w=(f||parseInt(s.style("height"))||400)-b.top-b.bottom),Q.select(".legendWrap").attr("transform","translate("+v/2+","+ -b.top+")")),p.width(v).height(w).color(o.map(function(a,b){return a.color||l[b%l.length]}).filter(function(a,b){return!o[b].disabled&&!o[b].bar})),r.width(v).height(J).color(o.map(function(a,b){return a.color||l[b%l.length]}).filter(function(a,b){return!o[b].disabled&&!o[b].bar})),q.width(v).height(I).color(o.map(function(a,b){return a.color||l[b%l.length]}).filter(function(a,b){return!o[b].disabled&&o[b].bar}));var S=Q.select(".barsWrap").attr("transform","translate(0,"+(w+b.bottom)+")").datum(K.length?K:[{values:[]}]),T=Q.select(".stocksWrap").datum(L.length?L:[{values:[]}]),U=Q.select(".linesWrap").attr("transform","translate(0,"+(w+b.bottom+g)+")").datum(L.length?L:[{values:[]}]);d3.transition(S).call(q),d3.transition(T).call(p),d3.transition(U).call(r);var V=O.append("clipPath").attr("id","brushBackground-clip-"+k);V.append("rect").attr("class","left").attr("x",0).attr("y",0).attr("height",J),V.append("rect").attr("class","right").attr("x",0).attr("y",0).attr("height",J),M.select("#edge-clip-"+k+" rect").attr("width",v).attr("height",w),Q.select(".brushBackground").attr("clip-path","url(#brushBackground-clip-"+k+")").attr("transform","translate(0,"+(w+b.bottom+g)+")").append("rect").attr("width",v).attr("height",J),gBrush=Q.select(".x.brush").attr("transform","translate(0,"+(w+b.bottom+g)+")").call(F),gBrush.selectAll("rect").attr("height",J),gBrush.selectAll(".resize").append("path").attr("d",W),Q.attr("transform","translate("+b.left+","+b.top+")"),x.ticks(v/100).tickSize(-I,0),Q.select(".x.axis").attr("transform","translate(0,"+(w+b.bottom+I+c.top)+")"),d3.transition(Q.select(".x.axis")).call(x),y.ticks(v/100).tickSize(-w,0),Q.select(".x2.axis").attr("transform","translate(0,"+w+")"),d3.transition(Q.select(".x2.axis")).call(y),z.ticks(v/100).tickSize(-J,0),Q.select(".x3.axis").attr("transform","translate(0,"+(w+b.bottom+g+J+d.top)+")"),d3.transition(Q.select(".x3.axis")).call(z),A.ticks(I/36).tickSize(-v,0).width(c.left).axisLabel("Volume (K)"),Q.select(".y1.axis").attr("transform","translate(0,"+(w+b.bottom)+")"),d3.transition(Q.select(".y1.axis")).style("opacity",K.length?1:0).call(A),B.ticks(w/36).tickSize(-v,0).width(b.left).axisLabel("Price ($)"),Q.select(".y2.axis").style("opacity",L.length?1:0),d3.transition(Q.select(".y2.axis")).call(B),C.ticks(J/36).tickSize(-v,0).width(d.left),Q.select(".y3.axis").style("opacity",L.length?1:0).attr("transform","translate(0,"+(w+b.bottom+g)+")"),d3.transition(Q.select(".y3.axis")).call(C),p.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],E.tooltipShow(a)}),n&&E.on("tooltipShow",function(a){G(a,u.parentNode)}),p.dispatch.on("elementMouseout.tooltip",function(a){E.tooltipHide(a)}),n&&E.on("tooltipHide",a.tooltip.cleanup),q.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+c.left,a.pos[1]+w+b.top+b.bottom+c.top],E.tooltipShow(a)}),n&&E.on("tooltipShow",function(a){G(a,u.parentNode)}),q.dispatch.on("elementMouseout.tooltip",function(a){E.tooltipHide(a)}),n&&E.on("tooltipHide",a.tooltip.cleanup),H.update=function(){j.transition().call(H)},H.container=this}),H}var b={top:10,right:30,bot
(H).delay(function(a,b){return b*n/v[0].values.length}).attr("x",function(a,b){return a.series*e.rangeBand()/v.length}).attr("width",e.rangeBand()/v.length).each("end",function(){d3.transition(d3.select(this)).attr("y",function(a,b){return i(a,b)<0?f(0):f(i(a,b))}).attr("height",function(a,b){return Math.abs(f(i(a,b))-f(0))})}),t.update=function(){t(u)},r=e.copy(),s=f.copy()}),t}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=d3.scale.ordinal(),f=d3.scale.linear(),g=Math.floor(Math.random()*1e4),h=function(a){return a.x},i=function(a){return a.y},j=[0],k=!0,l=!1,m=d3.scale.category20().range(),n=1200,o,p,q=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout"),r,s;return t.dispatch=q,t.x=function(a){return arguments.length?(h=a,t):h},t.y=function(a){return arguments.length?(i=a,t):i},t.margin=function(a){return arguments.length?(b=a,t):b},t.width=function(a){return arguments.length?(c=a,t):c},t.height=function(a){return arguments.length?(d=a,t):d},t.xScale=function(a){return arguments.length?(e=a,t):e},t.yScale=function(a){return arguments.length?(f=a,t):f},t.xDomain=function(a){return arguments.length?(o=a,t):o},t.yDomain=function(a){return arguments.length?(p=a,t):p},t.forceY=function(a){return arguments.length?(j=a,t):j},t.stacked=function(a){return arguments.length?(l=a,t):l},t.clipEdge=function(a){return arguments.length?(k=a,t):k},t.color=function(a){return arguments.length?(m=a,t):m},t.id=function(a){return arguments.length?(g=a,t):g},t.delay=function(a){return arguments.length?(n=a,t):n},t},a.models.multiBarChart=function(){function t(a){return a.each(function(j){var u=d3.select(this),v=this,w=(c||parseInt(u.style("width"))||960)-b.left-b.right,z=(d||parseInt(u.style("height"))||400)-b.top-b.bottom;k=m.xScale(),l=m.yScale();var A=u.selectAll("g.wrap.multiBarWithLegend").data([j]),B=A.enter().append("g").attr("class","wrap nvd3 multiBarWithLegend").append("g");B.append("g").attr("class","x axis"),B.append("g").attr("class","y axis"),B.append("g").attr("class","barsWrap"),B.append("g").attr("class","legendWrap"),B.append("g").attr("class","controlsWrap");var C=A.select("g");g&&(p.width(w/2),C.select(".legendWrap").datum(j).call(p),b.top!=p.height()&&(b.top=p.height(),z=(d||parseInt(u.style("height"))||400)-b.top-b.bottom),C.select(".legendWrap").attr("transform","translate("+w/2+","+ -b.top+")")),m.width(w).height(z).color(j.map(function(a,b){return a.color||e[b%e.length]}).filter(function(a,b){return!j[b].disabled}));if(f){var D=[{key:"Grouped",disabled:m.stacked()},{key:"Stacked",disabled:!m.stacked()}];q.width(180).color(["#444","#444","#444"]),C.select(".controlsWrap").datum(D).attr("transform","translate(0,"+ -b.top+")").call(q)}C.attr("transform","translate("+b.left+","+b.top+")");var E=C.select(".barsWrap").datum(j.filter(function(a){return!a.disabled}));d3.transition(E).call(m),n.scale(k).ticks(w/100).tickSize(-z,0),C.select(".x.axis").attr("transform","translate(0,"+l.range()[0]+")"),d3.transition(C.select(".x.axis")).call(n);var F=C.select(".x.axis > g").selectAll("g");F.selectAll("line, text").style("opacity",1),h&&F.filter(function(a,b){return b%Math.ceil(j[0].values.length/(w/100))!==0}).selectAll("text, line").style("opacity",0),o.scale(l).ticks(z/36).tickSize(-w,0),d3.transition(C.select(".y.axis")).call(o),p.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,j.filter(function(a){return!a.disabled}).length||j.map(function(a){return a.disabled=!1,A.selectAll(".series").classed("disabled",!1),a}),a.transition().call(t)}),q.dispatch.on("legendClick",function(b,c){if(!b.disabled)return;D=D.map(function(a){return a.disabled=!0,a}),b.disabled=!1;switch(b.key){case"Grouped":m.stacked(!1);break;case"Stacked":m.stacked(!0)}a.transition().call(t)}),r.on("tooltipShow",function(a){i&&s(a,v.parentNode)}),t.update=function(){a.transition().call(t)},t.container=this}),t}var b={top:30,right:20,bottom:50,left:60},c=null,d=null,e=d3.scale.category20().range(),f=!0,g=!0,h=!0,i=!0,j=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" on "+b+"</p>"},k,l,m=a.model
a){return!a.disabled})).call(w),x.scale(g).width(q).color(h.map(function(a,b){return a.color||e[b%e.length]}).filter(function(a,b){return!h[b].disabled})),G.select(".distWrap").append("g").attr("class","distributionY").attr("transform","translate(-"+x.size()+",0)"),H.select(".distributionY").datum(h.filter(function(a){return!a.disabled})).call(x),H.select(".background").on("mousemove",I),H.select(".background").on("click",function(){m=!m}),r.dispatch.on("elementClick.freezeFisheye",function(){m=!m}),v.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,l=b.disabled?0:2.5,H.select(".background").style("pointer-events",b.disabled?"none":"all"),H.select(".point-paths").style("pointer-events",b.disabled?"all":"none"),b.disabled?(f.distortion(l).focus(0),g.distortion(l).focus(0),H.select(".scatterWrap").call(r),H.select(".x.axis").call(s),H.select(".y.axis").call(t)):m=!1,D(a)}),u.dispatch.on("legendClick",function(b,c,d){b.disabled=!b.disabled,h.filter(function(a){return!a.disabled}).length||h.map(function(a){return a.disabled=!1,E.selectAll(".series").classed("disabled",!1),a}),D(a)}),r.dispatch.on("elementMouseover.tooltip",function(a){d3.select(".chart-"+r.id()+" .series-"+a.seriesIndex+" .distx-"+a.pointIndex).attr("y1",a.pos[1]-q),d3.select(".chart-"+r.id()+" .series-"+a.seriesIndex+" .disty-"+a.pointIndex).attr("x2",a.pos[0]+w.size()),a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],y.tooltipShow(a)}),y.on("tooltipShow",function(a){n&&B(a,o.parentNode)}),z=f.copy(),A=g.copy(),D.update=function(){D(a)},D.container=this}),D}var b={top:30,right:20,bottom:50,left:60},c=null,d=null,e=d3.scale.category20().range(),f=d3.fisheye.scale(d3.scale.linear).distortion(0),g=d3.fisheye.scale(d3.scale.linear).distortion(0),h=!1,i=!1,j=!0,k=!0,l=0,m=!1,n=!0,o=function(a,b,c){return"<strong>"+b+"</strong>"},p=function(a,b,c){return"<strong>"+c+"</strong>"},q=null,r=a.models.scatter().xScale(f).yScale(g),s=a.models.axis().orient("bottom").tickPadding(10),t=a.models.axis().orient("left").tickPadding(10),u=a.models.legend().height(30),v=a.models.legend().height(30),w=a.models.distribution().axis("x"),x=a.models.distribution().axis("y"),y=d3.dispatch("tooltipShow","tooltipHide"),z,A,B=function(c,d){var e=c.pos[0]+(d.offsetLeft||0),h=c.pos[1]+(d.offsetTop||0),i=c.pos[0]+(d.offsetLeft||0),j=g.range()[0]+b.top+(d.offsetTop||0),k=f.range()[0]+b.left+(d.offsetLeft||0),l=c.pos[1]+(d.offsetTop||0),m=s.tickFormat()(r.x()(c.point,c.pointIndex)),n=t.tickFormat()(r.y()(c.point,c.pointIndex));o!=null&&a.tooltip.show([i,j],o(c.series.key,m,n,c,D),"n",1,null,"x-nvtooltip"),p!=null&&a.tooltip.show([k,l],p(c.series.key,m,n,c,D),"e",1,null,"y-nvtooltip"),q!=null&&a.tooltip.show([e,h],q(c.series.key,m,n,c,D),c.value<0?"n":"s")},C=[{key:"Magnify",disabled:!0}];return r.dispatch.on("elementMouseout.tooltip",function(a){y.tooltipHide(a),d3.select(".chart-"+r.id()+" .series-"+a.seriesIndex+" .distx-"+a.pointIndex).attr("y1",0),d3.select(".chart-"+r.id()+" .series-"+a.seriesIndex+" .disty-"+a.pointIndex).attr("x2",x.size())}),y.on("tooltipHide",function(){n&&a.tooltip.cleanup()}),D.dispatch=y,D.legend=u,D.controls=u,D.xAxis=s,D.yAxis=t,D.distX=w,D.distY=x,d3.rebind(D,r,"id","interactive","pointActive","shape","size","xScale","yScale","zScale","xDomain","yDomain","sizeDomain","forceX","forceY","forceSize","clipVoronoi","clipRadius"),D.margin=function(a){return arguments.length?(b=a,D):b},D.width=function(a){return arguments.length?(c=a,D):c},D.height=function(a){return arguments.length?(d=a,D):d},D.color=function(a){return arguments.length?(e=a,u.color(a),w.color(a),x.color(a),D):e},D.showDistX=function(a){return arguments.length?(h=a,D):h},D.showDistY=function(a){return arguments.length?(i=a,D):i},D.showControls=function(a){return arguments.length?(k=a,D):k},D.showLegend=function(a){return arguments.length?(j=a,D):j},D.fisheye=function(a){return arguments.length?(l=a,D):l},D.tooltips=function(a){return arguments.length?(n=a,D):n},D.tooltipContent=function(a){return arguments.length?(q=a,D):q},D.tooltipXContent=function(a){return arguments.length?(o=a,D):o},D.too