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
111 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(
("class","x2 axis"),M.append("g").attr("class","x3 axis"),M.append("g").attr("class","y1 axis"),M.append("g").attr("class","y2 axis"),M.append("g").attr("class","y3 axis"),M.append("g").attr("class","barsWrap"),M.append("g").attr("class","stocksWrap"),M.append("g").attr("class","linesWrap"),M.append("g").attr("class","legendWrap"),M.append("g").attr("class","x brush");var N=L.select("g");l&&(C.width(u/2),N.select(".legendWrap").datum(n.map(function(a){return a.originalKey=a.originalKey===undefined?a.key:a.originalKey,a.key=a.originalKey,a})).call(C),b.top!=C.height()&&(b.top=C.height(),v=(f||parseInt(r.style("height"))||400)-b.top-b.bottom),N.select(".legendWrap").attr("transform","translate("+u/2+","+ -b.top+")")),o.width(u).height(v).color(n.map(function(a,b){return a.color||k[b%k.length]}).filter(function(a,b){return!n[b].disabled&&!n[b].bar})),q.width(u).height(I).color(n.map(function(a,b){return a.color||k[b%k.length]}).filter(function(a,b){return!n[b].disabled&&!n[b].bar})),p.width(u).height(H).color(n.map(function(a,b){return a.color||k[b%k.length]}).filter(function(a,b){return!n[b].disabled&&n[b].bar}));var O=N.select(".barsWrap").attr("transform","translate(0,"+(v+b.bottom)+")").datum(J.length?J:[{values:[]}]),P=N.select(".stocksWrap").datum(K.length?K:[{values:[]}]),Q=N.select(".linesWrap").attr("transform","translate(0,"+(v+b.bottom+g)+")").datum(K.length?K:[{values:[]}]);d3.transition(O).call(p),d3.transition(P).call(o),d3.transition(Q).call(q),gBrush=N.select(".x.brush").attr("transform","translate(0,"+(v+b.bottom+g)+")").call(E),gBrush.selectAll("rect").attr("height",I),gBrush.selectAll(".resize").append("path").attr("d",R),N.attr("transform","translate("+b.left+","+b.top+")"),w.ticks(u/100).tickSize(-H,0),N.select(".x.axis").attr("transform","translate(0,"+(v+b.bottom+H+c.top)+")"),d3.transition(N.select(".x.axis")).call(w),x.ticks(u/100).tickSize(-v,0),N.select(".x2.axis").attr("transform","translate(0,"+v+")"),d3.transition(N.select(".x2.axis")).call(x),y.ticks(u/100).tickSize(-I,0),N.select(".x3.axis").attr("transform","translate(0,"+(v+b.bottom+g+I+d.top)+")"),d3.transition(N.select(".x3.axis")).call(y),z.ticks(H/36).tickSize(-u,0).width(c.left).axisLabel("Volume (K)"),N.select(".y1.axis").attr("transform","translate(0,"+(v+b.bottom)+")"),d3.transition(N.select(".y1.axis")).style("opacity",J.length?1:0).call(z),A.ticks(v/36).tickSize(-u,0).width(b.left).axisLabel("Price ($)"),N.select(".y2.axis").style("opacity",K.length?1:0),d3.transition(N.select(".y2.axis")).call(A),B.ticks(I/36).tickSize(-u,0).width(d.left),N.select(".y3.axis").style("opacity",K.length?1:0).attr("transform","translate(0,"+(v+b.bottom+g)+")"),d3.transition(N.select(".y3.axis")).call(B),o.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],D.tooltipShow(a)}),m&&D.on("tooltipShow",function(a){F(a,t.parentNode)}),o.dispatch.on("elementMouseout.tooltip",function(a){D.tooltipHide(a)}),m&&D.on("tooltipHide",a.tooltip.cleanup),p.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+c.left,a.pos[1]+v+b.top+b.bottom+c.top],D.tooltipShow(a)}),m&&D.on("tooltipShow",function(a){F(a,t.parentNode)}),p.dispatch.on("elementMouseout.tooltip",function(a){D.tooltipHide(a)}),m&&D.on("tooltipHide",a.tooltip.cleanup),G.update=function(){j.transition().call(G)},G.container=this}),G}var b={top:10,right:30,bottom:25,left:80},c={top:0,right:30,bottom:10,left:80},d={top:0,right:30,bottom:20,left:80},e=null,f=null,g=100,h=80,i=function(a){return a.x},j=function(a){return a.y},k=d3.scale.category20().range(),l=!1,m=!0,n=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>Closed at "+c+" on "+b+"</p>"},o=a.models.ohlcBar(),p=a.models.historicalBar(),q=a.models.line().interactive(!1).isArea(!0),r=o.xScale(),s=q.xScale(),t=p.yScale(),u=o.yScale(),v=q.yScale(),w=a.models.axis().scale(r).orient("bottom").tickPadding(5),x=a.models.axis().scale(r).orient("bottom").tickPadding(5),y=a.models.axis().scale(s).orient("bottom").tickPadding(5),z=a.models.axis().scale(t).orient("left"),A=a.models.axis().scale(u).orient("left"),B=
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.models.multiBar().stacked(!1),n=a.models.axis().orient("bottom").highlightZero(!1).showMaxMin(!1),o=a.models.axis().orient("left"),p=a.models.legend().height(30),q=a.models.legend().height(30),r=d3.dispatch("tooltipShow","tooltipHide");n.tickFormat(function(a){return a}),o.tickFormat(d3.format(",.1f"));var s=function(b,c){var d=b.pos[0]+(c.offsetLeft||0),e=b.pos[1]+(c.offsetTop||0),f=n.tickFormat()(m.x()(b.point,b.pointIndex)),g=o.tickFormat()(m.y()(b.point,b.pointIndex)),h=j(b.series.key,f,g,b,t);a.tooltip.show([d,e],h,b.value<0?"n":"s")};return m.dispatch.on("elementMouseover.tooltip2",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],r.tooltipShow(a)}),m.dispatch.on("elementMouseout.tooltip",function(a){r.tooltipHide(a)}),r.on("tooltipHide",function(){i&&a.tooltip.cleanup()}),t.d
(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.tooltipYContent=function(a){return arguments.length?(p=a,D):p},D},a.models.sparkline=function(){function l(d){return d.each(function(d){var l=b-a.left-a.right,m=c-a.top-a.bottom;j.domain(h||d3.extent(d,e)).range([0,l]),k.domain(i||d3.extent(d,f)).range([m,0]);var n=d3.select(this).selectAll("g.sparkline").data([d]),o=n.enter().append("g").attr("class","nvd3 sparkline");o.attr("transform","translate("+a.left+","+a.top+")").style("stroke",function(a,b){return a.color||g[b*g.length]});var p=o.selectAll("path").data(function(a){return[a]});p.enter().append("path"),p.exit().remove(),p.attr("d",d3.svg.line().x(function(a,b){return j(e(a,b))}).y(function(a,b){return k(f(a,b))}));var q=o.selectAll("circle.point").data(function(a){return a.filter(function(a,b){return k.domain().indexO