2012-07-18 05:59:09 +00:00
|
|
|
(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(
|
|
|
|
),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),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=a.models.axis().scale(v).orie
|
2012-07-19 03:34:47 +00:00
|
|
|
).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.dispatch=r,t.legend=p,t.xAxis=n,t.yAxis=o,d3.rebind(t,m,"x","y","xDomain","yDomain","forceX","forceY","clipEdge","id","stacked","delay"),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.color=function(a){return arguments.length?(e=a,p.color(a),t):e},t.showControls=function(a){return arguments.length?(f=a,t):f},t.showLegend=function(a){return arguments.length?(g=a,t):g},t.reduceXTicks=function(a){return arguments.length?(h=a,t):h},t.tooltips=function(a){return arguments.length?(i=a,t):i},t.tooltipContent=function(a){return arguments.length?(j=a,t):j},t},a.models.multiBarHorizontal=function(){function v(d){return d.each(function(p){var w=b-a.left-a.right,z=c-a.top-a.bottom;l&&(p=d3.layout.stack().offset("zero").values(function(a){return a.values}).y(h)(p)),p=p.map(function(a,b){return a.values=a.values.map(function(a){return a.series=b,a}),a});var A=q&&r?[]:p.map(function(a){return a.values.map(function(a,b){return{x:g(a,b),y:h(a,b),y0:a.y0}})});e.domain(q||d3.merge(A).map(function(a){return a.x})).rangeBands(
|
|
|
|
(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().indexOf(f(a,b))!=-1||e(a,b)==j.domain()[1]})});q.enter().append("circle").attr("class","point"),q.exit().remove(),q.attr("cx",function(a,b){return j(e(a,b))}).attr("cy",function(a,b){return k(f(a,b))}).attr("r",2).style("stroke",function(a,b){return a.x==j.domain()[1]?"#444":a.y==k.domain()[0]?"#d62728":"#2ca02c"}).style("fill",function(a,b){return a.x==j.domain()[1]?"#444":a.y==k.domain()[0]?"#d62728":"#2ca02c"})}),l}var a={top:0,right:0,bottom:0,left:0},b=400,c=32,d=!0,e=function(a){return a.x},f=function(a){return a.y},g=d3.scale.category20().range(),h,i,j=d3.scale.linear(),k=d3.scale.linear();return l.margin=function(b){return arguments.length?(a=b,l):a},l.width=function(a){return arguments.length?(b=a,l):b},l.height=function(a){return arguments.length?(c=a,l):c},l.x=function(a){return arguments.length?(e=d3.functor(a),l):e},l.y=function(a){return arguments.length?(f=d3.functor(a),l):f},l.xDomain=function(a){return arguments.length?(h=a,l):h},l.yDomain=function(a){return arguments.length?(i=a,l):i},l.animate=function(a){return arguments.length?(d=a,l):d},l},a.models.sparklinePlus=function(){function o(a){return a.each(function(a){function w(){var c=d3.event.offsetX-b.
|