redmon 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -4
- data/.travis.yml +9 -1
- data/README.md +11 -9
- data/bin/redmon +9 -3
- data/lib/redmon.rb +15 -19
- data/lib/redmon/app.rb +14 -5
- data/lib/redmon/config.rb +4 -3
- data/lib/redmon/helpers.rb +1 -3
- data/lib/redmon/public/redmon.css +15 -1
- data/lib/redmon/public/redmon.js +88 -80
- data/lib/redmon/public/vendor/bootstrap.min.css +1 -1
- data/lib/redmon/public/vendor/d3.v3.min.js +4 -0
- data/lib/redmon/public/vendor/nv.d3.css +656 -0
- data/lib/redmon/public/vendor/nv.d3.min.js +5 -0
- data/lib/redmon/redis.rb +1 -1
- data/lib/redmon/version.rb +1 -1
- data/lib/redmon/views/app.haml +9 -3
- data/redmon.gemspec +0 -1
- data/spec/app_spec.rb +7 -1
- data/spec/config_spec.rb +3 -3
- metadata +8 -22
- data/lib/redmon/public/vendor/jquery.flot.js +0 -2651
@@ -0,0 +1,5 @@
|
|
1
|
+
(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===0&&h.push(i),b(g)}else while(g<e)h.push(new Date(+g)),b(g);return h}}var a=window.nv||{};a.version="0.0.1a",a.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(){if(a.dev&&console.log&&console.log.apply)console.log.apply(console,arguments);else if(a.dev&&console.log&&Function.prototype.bind){var b=Function.prototype.bind.call(console.log,console);b.apply(console,arguments)}return arguments[arguments.length-1]},a.render=function(c){c=c||1,a.render.active=!0,a.dispatch.render_start(),setTimeout(function(){var b,d;for(var e=0;e<c&&(d=a.render.queue[e]);e++)b=d.generate(),typeof d.callback==typeof Function&&d.callback(b),a.graphs.push(b);a.render.queue.splice(0,e),a.render.queue.length?setTimeout(arguments.callee,0):(a.render.active=!1,a.dispatch.render_end())},0)},a.render.active=!1,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=window.scrollY,o=window.scrollX,p,q;m=window.innerWidth>=document.body.scrollWidth?m:m-16,l=window.innerHeight>=document.body.scrollHeight?l:l-16;var r=function(a){var b=q;do isNaN(a.offsetTop)||(b+=a.offsetTop);while(a=a.offsetParent);return b},s=function(a){var b=p;do isNaN(a.offsetLeft)||(b+=a.offsetLeft);while(a=a.offsetParent);return b};switch(d){case"e":p=b[0]-k-e,q=b[1]-j/2;var t=s(h),u=r(h);t<o&&(p=b[0]+e>o?b[0]+e:o-t+p),u<n&&(q=n-u+q),u+j>n+m&&(q=n+m-u+q-j);break;case"w":p=b[0]+e,q=b[1]-j/2,t+k>l&&(p=b[0]-k-e),u<n&&(q=n+5),u+j>n+m&&(q=n-j-5);break;case"n":p=b[0]-k/2-5,q=b[1]+e;var t=s(h),u=r(h);t<o&&(p=o+5),t+k>l&&(p=p-k/2+5),u+j>n+m&&(q=n+m-u+q-j);break;case"s":p=b[0]-k/2,q=b[1]-j-e;var t=s(h),u=r(h);t<o&&(p=o+5),t+k>l&&(p=p-k/2+5),n>u&&(q=n)}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.utils.getColor=function(b){return arguments.length?Object.prototype.toString.call(b)==="[object Array]"?function(a,c){return a.color||b[c%b.length]}:b:a.utils.defaultColor()},a.utils.defaultColor=function(){var a=d3.scale.category20().range();return function(b,c){return b.color||a[c%a.length]}},a.utils.customTheme=function(a,b,c){b=b||function(a){return a.key},c=c||d3.scale.category20().range();var d=c.length;return function(e,f){var g=b(e);return d||(d=c.length),typeof a[g]!="undefined"?typeof a[g]=="function"?a[g]():a[g]:c[--d]}},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.models.axis=function(){function o(d){return d.each(function(d){var o=d3.select(this),p=o.selectAll("g.nv-wrap.nv-axis").data([d]),q=p.enter().append("g").attr("class","nvd3 nv-wrap nv-axis"),r=q.append("g"),s=p.select("g");m!==null?a.ticks(m):(a.orient()=="top"||a.orient()=="bottom")&&a.ticks(Math.abs(e.range()[1]-e.range()[0])/100),d3.transition(s).call(a),n=n||a.scale();var t=a.tickFormat();t==null&&(t=n.tickFormat());var u=s.selectAll("text.nv-axislabel").data([f||null]);u.exit().remove();switch(a.orient()){case"top":u.enter().append("text").attr("class","nv-axislabel").attr("text-anchor","middle").attr("y",0);var v=e.range().length==2?e.range()[1]:e.range()[e.range().length-1]+(e.range()[1]-e.range()[0]);u.attr("x",v/2);if(g){var w=p.selectAll("g.nv-axisMaxMin").data(e.domain());w.enter().append("g").attr("class","nv-axisMaxMin").append("text"),w.exit().remove(),w.attr("transform",function(a,b){return"translate("+e(a)+",0)"}).select("text").attr("dy","0em").attr("y",-a.tickPadding()).attr("text-anchor","middle").text(function(a,b){var c=t(a);return(""+c).match("NaN")?"":c}),d3.transition(w).attr("transform",function(a,b){return"translate("+e.range()[b]+",0)"})}break;case"bottom":var x=36,y=30,z=s.selectAll("g").select("text");if(i%360){z.each(function(a,b){var c=this.getBBox().width;c>y&&(y=c)});var A=Math.abs(Math.sin(i*Math.PI/180)),x=(A?A*y:y)+30;z.attr("transform",function(a,b,c){return"rotate("+i+" 0,0)"}).attr("text-anchor",i%360>0?"start":"end")}u.enter().append("text").attr("class","nv-axislabel").attr("text-anchor","middle").attr("y",x);var v=e.range().length==2?e.range()[1]:e.range()[e.range().length-1]+(e.range()[1]-e.range()[0]);u.attr("x",v/2);if(g){var w=p.selectAll("g.nv-axisMaxMin").data([e.domain()[0],e.domain()[e.domain().length-1]]);w.enter().append("g").attr("class","nv-axisMaxMin").append("text"),w.exit().remove(),w.attr("transform",function(a,b){return"translate("+(e(a)+(l?e.rangeBand()/2:0))+",0)"}).select("text").attr("dy",".71em").attr("y",a.tickPadding()).attr("transform",function(a,b,c){return"rotate("+i+" 0,0)"}).attr("text-anchor",i?i%360>0?"start":"end":"middle").text(function(a,b){var c=t(a);return(""+c).match("NaN")?"":c}),d3.transition(w).attr("transform",function(a,b){return"translate("+(e(a)+(l?e.rangeBand()/2:0))+",0)"})}k&&z.attr("transform",function(a,b){return"translate(0,"+(b%2==0?"0":"12")+")"});break;case"right":u.enter().append("text").attr("class","nv-axislabel").attr("text-anchor",j?"middle":"begin").attr("transform",j?"rotate(90)":"").attr("y",j?-Math.max(b.right,c)+12:-10),u.attr("x",j?e.range()[0]/2:a.tickPadding());if(g){var w=p.selectAll("g.nv-axisMaxMin").data(e.domain());w.enter().append("g").attr("class","nv-axisMaxMin").append("text").style("opacity",0),w.exit().remove(),w.attr("transform",function(a,b){return"translate(0,"+e(a)+")"}).select("text").attr("dy",".32em").attr("y",0).attr("x",a.tickPadding()).attr("text-anchor","start").text(function(a,b){var c=t(a);return(""+c).match("NaN")?"":c}),d3.transition(w).attr("transform",function(a,b){return"translate(0,"+e.range()[b]+")"}).select("text").style("opacity",1)}break;case"left":u.enter().append("text").attr("class","nv-axislabel").attr("text-anchor",j?"middle":"end").attr("transform",j?"rotate(-90)":"").attr("y",j?-Math.max(b.left,c)+12:-10),u.attr("x",j?-e.range()[0]/2:-a.tickPadding());if(g){var w=p.selectAll("g.nv-axisMaxMin").data(e.domain());w.enter().append("g").attr("class","nv-axisMaxMin").append("text").style("opacity",0),w.exit().remove(),w.attr("transform",function(a,b){return"translate(0,"+n(a)+")"}).select("text").attr("dy",".32em").attr("y",0).attr("x",-a.tickPadding()).attr("text-anchor","end").text(function(a,b){var c=t(a);return(""+c).match("NaN")?"":c}),d3.transition(w).attr("transform",function(a,b){return"translate(0,"+e.range()[b]+")"}).select("text").style("opacity",1)}}u.text(function(a){return a}),g&&(a.orient()==="left"||a.orient()==="right")&&(s.selectAll("g").each(function(a,b){d3.select(this).select("text").attr("opacity",1);if(e(a)<e.range()[1]+10||e(a)>e.range()[0]-10)(a>1e-10||a<-1e-10)&&d3.select(this).attr("opacity",0),d3.select(this).select("text").attr("opacity",0)}),e.domain()[0]==e.domain()[1]&&e.domain()[0]==0&&p.selectAll("g.nv-axisMaxMin").style("opacity",function(a,b){return b?0:1}));if(g&&(a.orient()==="top"||a.orient()==="bottom")){var B=[];p.selectAll("g.nv-axisMaxMin").each(function(a,b){try{b?B.push(e(a)-this.getBBox().width-4):B.push(e(a)+this.getBBox().width+4)}catch(c){b?B.push(e(a)-4):B.push(e(a)+4)}}),s.selectAll("g").each(function(a,b){if(e(a)<B[0]||e(a)>B[1])a>1e-10||a<-1e-10?d3.select(this).remove():d3.select(this).select("text").remove()})}h&&s.selectAll("line.tick").filter(function(a){return!parseFloat(Math.round(a*1e5)/1e6)}).classed("zero",!0),n=e.copy()}),o}var a=d3.svg.axis(),b={top:0,right:0,bottom:0,left:0},c=75,d=60,e=d3.scale.linear(),f=null,g=!0,h=!0,i=0,j=!0,k=!1,l=!1,m=null;a.scale(e).orient("bottom").tickFormat(function(a){return a});var n;return o.axis=a,d3.rebind(o,a,"orient","tickValues","tickSubdivide","tickSize","tickPadding","tickFormat"),d3.rebind(o,e,"domain","range","rangeBand","rangeBands"),o.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,o):b},o.width=function(a){return arguments.length?(c=a,o):c},o.ticks=function(a){return arguments.length?(m=a,o):m},o.height=function(a){return arguments.length?(d=a,o):d},o.axisLabel=function(a){return arguments.length?(f=a,o):f},o.showMaxMin=function(a){return arguments.length?(g=a,o):g},o.highlightZero=function(a){return arguments.length?(h=a,o):h},o.scale=function(b){return arguments.length?(e=b,a.scale(e),l=typeof e.rangeBands=="function",d3.rebind(o,e,"domain","range","rangeBand","rangeBands"),o):e},o.rotateYLabel=function(a){return arguments.length?(j=a,o):j},o.rotateLabels=function(a){return arguments.length?(i=a,o):i},o.staggerLabels=function(a){return arguments.length?(k=a,o):k},o},a.models.historicalBar=function(){function r(a){return a.each(function(a){var r=c-b.left-b.right,s=d-b.top-b.bottom,t=d3.select(this);f.domain(o||d3.extent(a[0].values.map(h).concat(j))),l?f.range([r*.5/a[0].values.length,r*(a[0].values.length-.5)/a[0].values.length]):f.range([0,r]),g.domain(p||d3.extent(a[0].values.map(i).concat(k))).range([s,0]);if(f.domain()[0]===f.domain()[1]||g.domain()[0]===g.domain()[1])singlePoint=!0;f.domain()[0]===f.domain()[1]&&(f.domain()[0]?f.domain([f.domain()[0]-f.domain()[0]*.01,f.domain()[1]+f.domain()[1]*.01]):f.domain([-1,1])),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]));var u=t.selectAll("g.nv-wrap.nv-bar").data([a[0].values]),v=u.enter().append("g").attr("class","nvd3 nv-wrap nv-bar"),w=v.append("defs"),z=v.append("g"),A=u.select("g");z.append("g").attr("class","nv-bars"),u.attr("transform","translate("+b.left+","+b.top+")"),t.on("click",function(a,b){q.chartClick({data:a,index:b,pos:d3.event,id:e})}),w.append("clipPath").attr("id","nv-chart-clip-path-"+e).append("rect"),u.select("#nv-chart-clip-path-"+e+" rect").attr("width",r).attr("height",s),A.attr("clip-path",m?"url(#nv-chart-clip-path-"+e+")":"");var B=u.select(".nv-bars").selectAll(".nv-bar").data(function(a){return a});B.exit().remove();var C=B.enter().append("rect").attr("x",0).attr("y",function(a,b){return g(Math.max(0,i(a,b)))}).attr("height",function(a,b){return Math.abs(g(i(a,b))-g(0))}).on("mouseover",function(b,c){d3.select(this).classed("hover",!0),q.elementMouseover({point:b,series:a[0],pos:[f(h(b,c)),g(i(b,c))],pointIndex:c,seriesIndex:0,e:d3.event})}).on("mouseout",function(b,c){d3.select(this).classed("hover",!1),q.elementMouseout({point:b,series:a[0],pointIndex:c,seriesIndex:0,e:d3.event})}).on("click",function(a,b){q.elementClick({value:i(a,b),data:a,index:b,pos:[f(h(a,b)),g(i(a,b))],e:d3.event,id:e}),d3.event.stopPropagation()}).on("dblclick",function(a,b){q.elementDblClick({value:i(a,b),data:a,index:b,pos:[f(h(a,b)),g(i(a,b))],e:d3.event,id:e}),d3.event.stopPropagation()});B.attr("fill",function(a,b){return n(a,b)}).attr("class",function(a,b,c){return(i(a,b)<0?"nv-bar negative":"nv-bar positive")+" nv-bar-"+c+"-"+b}).attr("transform",function(b,c){return"translate("+(f(h(b,c))-r/a[0].values.length*.45)+",0)"}).attr("width",r/a[0].values.length*.9),d3.transition(B).attr("y",function(a,b){return i(a,b)<0?g(0):g(0)-g(i(a,b))<1?g(0)-1:g(i(a,b))}).attr("height",function(a,b){return Math.max(Math.abs(g(i(a,b))-g(0)),1)})}),r}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=Math.floor(Math.random()*1e4),f=d3.scale.linear(),g=d3.scale.linear(),h=function(a){return a.x},i=function(a){return a.y},j=[],k=[0],l=!1,m=!0,n=a.utils.defaultColor(),o,p,q=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout");return r.dispatch=q,r.x=function(a){return arguments.length?(h=a,r):h},r.y=function(a){return arguments.length?(i=a,r):i},r.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,r):b},r.width=function(a){return arguments.length?(c=a,r):c},r.height=function(a){return arguments.length?(d=a,r):d},r.xScale=function(a){return arguments.length?(f=a,r):f},r.yScale=function(a){return arguments.length?(g=a,r):g},r.xDomain=function(a){return arguments.length?(o=a,r):o},r.yDomain=function(a){return arguments.length?(p=a,r):p},r.forceX=function(a){return arguments.length?(j=a,r):j},r.forceY=function(a){return arguments.length?(k=a,r):k},r.padData=function(a){return arguments.length?(l=a,r):l},r.clipEdge=function(a){return arguments.length?(m=a,r):m},r.color=function(b){return arguments.length?(n=a.utils.getColor(b),r):n},r.id=function(a){return arguments.length?(e=a,r):e},r},a.models.bullet=function(){function n(a){return a.each(function(a,c){var k=i-b.left-b.right,n=j-b.top-b.bottom,o=d3.select(this),p=e.call(this,a,c).slice().sort(d3.descending),q=f.call(this,a,c).slice().sort(d3.descending),r=g.call(this,a,c).slice().sort(d3.descending),s=d3.scale.linear().domain(d3.extent(d3.merge([h,p]))).range(d?[k,0]:[0,k]),t=this.__chart__||d3.scale.linear().domain([0,Infinity]).range(s.range());this.__chart__=s;var u=d3.min(p),v=d3.max(p),w=p[1],x=o.selectAll("g.nv-wrap.nv-bullet").data([a]),y=x.enter().append("g").attr("class","nvd3 nv-wrap nv-bullet"),z=y.append("g"),A=x.select("g");z.append("rect").attr("class","nv-range nv-rangeMax"),z.append("rect").attr("class","nv-range nv-rangeAvg"),z.append("rect").attr("class","nv-range nv-rangeMin"),z.append("rect").attr("class","nv-measure"),z.append("path").attr("class","nv-markerTriangle"),x.attr("transform","translate("+b.left+","+b.top+")");var B=function(a){return Math.abs(t(a)-t(0))},C=function(a){return Math.abs(s(a)-s(0))},D=function(a){return a<0?t(a):t(0)},E=function(a){return a<0?s(a):s(0)};A.select("rect.nv-rangeMax").attr("height",n).attr("width",C(v>0?v:u)).attr("x",E(v>0?v:u)).datum(v>0?v:u),A.select("rect.nv-rangeAvg").attr("height",n).attr("width",C(w)).attr("x",E(w)).datum(w),A.select("rect.nv-rangeMin").attr("height",n).attr("width",C(v)).attr("x",E(v)).attr("width",C(v>0?u:v)).attr("x",E(v>0?u:v)).datum(v>0?u:v),A.select("rect.nv-measure").style("fill",l).attr("height",n/3).attr("y",n/3).attr("width",r<0?s(0)-s(r[0]):s(r[0])-s(0)).attr("x",E(r)).on("mouseover",function(){m.elementMouseover({value:r[0],label:"Current",pos:[s(r[0]),n/2]})}).on("mouseout",function(){m.elementMouseout({value:r[0],label:"Current"})});var F=n/6;q[0]?A.selectAll("path.nv-markerTriangle").attr("transform",function(a){return"translate("+s(q[0])+","+n/2+")"}).attr("d","M0,"+F+"L"+F+","+ -F+" "+ -F+","+ -F+"Z").on("mouseover",function(){m.elementMouseover({value:q[0],label:"Previous",pos:[s(q[0]),n/2]})}).on("mouseout",function(){m.elementMouseout({value:q[0],label:"Previous"})}):A.selectAll("path.nv-markerTriangle").remove(),x.selectAll(".nv-range").on("mouseover",function(a,b){var c=b?b==1?"Mean":"Minimum":"Maximum";m.elementMouseover({value:a,label:c,pos:[s(a),n/2]})}).on("mouseout",function(a,b){var c=b?b==1?"Mean":"Minimum":"Maximum";m.elementMouseout({value:a,label:c})})}),n}var b={top:0,right:0,bottom:0,left:0},c="left",d=!1,e=function(a){return a.ranges},f=function(a){return a.markers},g=function(a){return a.measures},h=[0],i=380,j=30,k=null,l=a.utils.getColor(["#1f77b4"]),m=d3.dispatch("elementMouseover","elementMouseout");return n.dispatch=m,n.orient=function(a){return arguments.length?(c=a,d=c=="right"||c=="bottom",n):c},n.ranges=function(a){return arguments.length?(e=a,n):e},n.markers=function(a){return arguments.length?(f=a,n):f},n.measures=function(a){return arguments.length?(g=a,n):g},n.forceX=function(a){return arguments.length?(h=a,n):h},n.width=function(a){return arguments.length?(i=a,n):i},n.height=function(a){return arguments.length?(j=a,n):j},n.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,n):b},n.tickFormat=function(a){return arguments.length?(k=a,n):k},n.color=function(b){return arguments.length?(l=a.utils.getColor(b),n):l},n},a.models.bulletChart=function(){function q(a){return a.each(function(c,m){var r=d3.select(this),s=(i||parseInt(r.style("width"))||960)-e.left-e.right,t=j-e.top-e.bottom,u=this;q.update=function(){q(a)},q.container=this;if(!c||!f.call(this,c,m)){var v=r.selectAll(".nv-noData").data([n]);return v.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),v.attr("x",e.left+s/2).attr("y",18+e.top+t/2).text(function(a){return a}),q}r.selectAll(".nv-noData").remove();var w=f.call(this,c,m).slice().sort(d3.descending),x=g.call(this,c,m).slice().sort(d3.descending),y=h.call(this,c,m).slice().sort(d3.descending),z=r.selectAll("g.nv-wrap.nv-bulletChart").data([c]),A=z.enter().append("g").attr("class","nvd3 nv-wrap nv-bulletChart"),B=A.append("g"),C=z.select("g");B.append("g").attr("class","nv-bulletWrap"),B.append("g").attr("class","nv-titles"),z.attr("transform","translate("+e.left+","+e.top+")");var D=d3.scale.linear().domain([0,Math.max(w[0],x[0],y[0])]).range(d?[s,0]:[0,s]),E=this.__chart__||d3.scale.linear().domain([0,Infinity]).range(D.range());this.__chart__=D;var F=function(a){return Math.abs(E(a)-E(0))},G=function(a){return Math.abs(D(a)-D(0))},H=B.select(".nv-titles").append("g").attr("text-anchor","end").attr("transform","translate(-6,"+(j-e.top-e.bottom)/2+")");H.append("text").attr("class","nv-title").text(function(a){return a.title}),H.append("text").attr("class","nv-subtitle").attr("dy","1em").text(function(a){return a.subtitle}),b.width(s).height(t);var I=C.select(".nv-bulletWrap");d3.transition(I).call(b);var J=k||D.tickFormat(s/100),K=C.selectAll("g.nv-tick").data(D.ticks(s/50),function(a){return this.textContent||J(a)}),L=K.enter().append("g").attr("class","nv-tick").attr("transform",function(a){return"translate("+E(a)+",0)"}).style("opacity",1e-6);L.append("line").attr("y1",t).attr("y2",t*7/6),L.append("text").attr("text-anchor","middle").attr("dy","1em").attr("y",t*7/6).text(J);var M=d3.transition(K).attr("transform",function(a){return"translate("+D(a)+",0)"}).style("opacity",1);M.select("line").attr("y1",t).attr("y2",t*7/6),M.select("text").attr("y",t*7/6),d3.transition(K.exit()).attr("transform",function(a){return"translate("+D(a)+",0)"}).style("opacity",1e-6).remove(),o.on("tooltipShow",function(a){a.key=data[0].title,l&&p(a,u.parentNode)})}),d3.timer.flush(),q}var b=a.models.bullet(),c="left",d=!1,e={top:5,right:40,bottom:20,left:120},f=function(a){return a.ranges},g=function(a){return a.markers},h=function(a){return a.measures},i=null,j=55,k=null,l=!0,m=function(a,b,c,d,e){return"<h3>"+b+"</h3>"+"<p>"+c+"</p>"},n="No Data Available.",o=d3.dispatch("tooltipShow","tooltipHide"),p=function(b,c){var d=b.pos[0]+(c.offsetLeft||0)+e.left,f=b.pos[1]+(c.offsetTop||0)+e.top,g=m(b.key,b.label,b.value,b,q);a.tooltip.show([d,f],g,b.value<0?"e":"w",null,c)};return b.dispatch.on("elementMouseover.tooltip",function(a){o.tooltipShow(a)}),b.dispatch.on("elementMouseout.tooltip",function(a){o.tooltipHide(a)}),o.on("tooltipHide",function(){l&&a.tooltip.cleanup()}),q.dispatch=o,q.bullet=b,d3.rebind(q,b,"color"),q.orient=function(a){return arguments.length?(c=a,d=c=="right"||c=="bottom",q):c},q.ranges=function(a){return arguments.length?(f=a,q):f},q.markers=function(a){return arguments.length?(g=a,q):g},q.measures=function(a){return arguments.length?(h=a,q):h},q.width=function(a){return arguments.length?(i=a,q):i},q.height=function(a){return arguments.length?(j=a,q):j},q.margin=function(a){return arguments.length?(e.top=typeof a.top!="undefined"?a.top:e.top,e.right=typeof a.right!="undefined"?a.right:e.right,e.bottom=typeof a.bottom!="undefined"?a.bottom:e.bottom,e.left=typeof a.left!="undefined"?a.left:e.left,q):e},q.tickFormat=function(a){return arguments.length?(k=a,q):k},q.tooltips=function(a){return arguments.length?(l=a,q):l},q.tooltipContent=function(a){return arguments.length?(m=a,q):m},q.noData=function(a){return arguments.length?(n=a,q):n},q},a.models.cumulativeLineChart=function(){function y(a){return a.each(function(o){function F(a,b){d3.select(y.container).style("cursor","ew-resize")}function G(a,b){w.x=d3.event.x,w.i=Math.round(v.invert(w.x)),S()}function H(a,b){d3.select(y.container).style("cursor","auto"),s.index=w.i,u.stateChange(s)}function S(){R.data([w]),y.update()}var A=d3.select(this).classed("nv-chart-"+r,!0),B=this,C=(i||parseInt(A.style("width"))||960)-g.left-g.right,D=(j||parseInt(A.style("height"))||400)-g.top-g.bottom;y.update=function(){y(a)},y.container=this;var E=d3.behavior.drag().on("dragstart",F).on("drag",G).on("dragend",H);if(!o||!o.length||!o.filter(function(a){return a.values.length}).length){var I=A.selectAll(".nv-noData").data([t]);return I.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),I.attr("x",g.left+C/2).attr("y",g.top+D/2).text(function(a){return a}),y}A.selectAll(".nv-noData").remove(),p=b.xScale(),q=b.yScale();if(!n){var J=o.filter(function(a){return!a.disabled}).map(function(a,c){var d=d3.extent(a.values,b.y());return d[0]<-0.95&&(d[0]=-0.95),[(d[0]-d[1])/(1+d[1]),(d[1]-d[0])/(1+d[0])]}),K=[d3.min(J,function(a){return a[0]}),d3.max(J,function(a){return a[1]})];b.yDomain(K)}else b.yDomain(null);v.domain([0,o[0].values.length-1]).range([0,C]).clamp(!0);var o=z(w.i,o),L=A.selectAll("g.nv-wrap.nv-cumulativeLine").data([o]),M=L.enter().append("g").attr("class","nvd3 nv-wrap nv-cumulativeLine").append("g"),N=L.select("g");M.append("g").attr("class","nv-x nv-axis"),M.append("g").attr("class","nv-y nv-axis"),M.append("g").attr("class","nv-background"),M.append("g").attr("class","nv-linesWrap"),M.append("g").attr("class","nv-legendWrap"),M.append("g").attr("class","nv-controlsWrap"),k&&(e.width(C),N.select(".nv-legendWrap").datum(o).call(e),g.top!=e.height()&&(g.top=e.height(),D=(j||parseInt(A.style("height"))||400)-g.top-g.bottom),N.select(".nv-legendWrap").attr("transform","translate(0,"+ -g.top+")"));if(m){var O=[{key:"Re-scale y-axis",disabled:!n}];f.width(140).color(["#444","#444","#444"]),N.select(".nv-controlsWrap").datum(O).attr("transform","translate(0,"+ -g.top+")").call(f)}L.attr("transform","translate("+g.left+","+g.top+")");var P=o.filter(function(a){return a.tempDisabled});L.select(".tempDisabled").remove(),P.length&&L.append("text").attr("class","tempDisabled").attr("x",C/2).attr("y","-.71em").style("text-anchor","end").text(P.map(function(a){return a.key}).join(", ")+" values cannot be calculated for this time period."),M.select(".nv-background").append("rect"),N.select(".nv-background rect").attr("width",C).attr("height",D),b.y(function(a){return a.display.y}).width(C).height(D).color(o.map(function(a,b){return a.color||h(a,b)}).filter(function(a,b){return!o[b].disabled&&!o[b].tempDisabled}));var Q=N.select(".nv-linesWrap").datum(o.filter(function(a){return!a.disabled&&!a.tempDisabled}));Q.call(b);var R=Q.selectAll(".nv-indexLine").data([w]);R.enter().append("rect").attr("class","nv-indexLine").attr("width",3).attr("x",-2).attr("fill","red").attr("fill-opacity",.5).call(E),R.attr("transform",function(a){return"translate("+v(a.i)+",0)"}).attr("height",D),c.scale(p).ticks(Math.min(o[0].values.length,C/70)).tickSize(-D,0),N.select(".nv-x.nv-axis").attr("transform","translate(0,"+q.range()[0]+")"),d3.transition(N.select(".nv-x.nv-axis")).call(c),d.scale(q).ticks(D/36).tickSize(-C,0),d3.transition(N.select(".nv-y.nv-axis")).call(d),N.select(".nv-background rect").on("click",function(){w.x=d3.mouse(this)[0],w.i=Math.round(v.invert(w.x)),s.index=w.i,u.stateChange(s),S()}),b.dispatch.on("elementClick",function(a){w.i=a.pointIndex,w.x=v(w.i),s.index=w.i,u.stateChange(s),S()}),f.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,n=!b.disabled,s.rescaleY=n,u.stateChange(s),a.call(y)}),e.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,o.filter(function(a){return!a.disabled}).length||o.map(function(a){return a.disabled=!1,L.selectAll(".nv-series").classed("disabled",!1),a}),s.disabled=o.map(function(a){return!!a.disabled}),u.stateChange(s),a.call(y)}),u.on("tooltipShow",function(a){l&&x(a,B.parentNode)}),u.on("changeState",function(b){typeof b.disabled!="undefined"&&(o.forEach(function(a,c){a.disabled=b.disabled[c]}),s.disabled=b.disabled),typeof b.index!="undefined"&&(w.i=b.index,w.x=v(w.i),s.index=b.index,R.data([w])),typeof b.rescaleY!="undefined"&&(n=b.rescaleY),a.call(y)})}),y}function z(a,c){return c.map(function(c,d){var e=b.y()(c.values[a],a);return e<-0.95?(c.tempDisabled=!0,c):(c.tempDisabled=!1,c.values=c.values.map(function(a,c){return a.display={y:(b.y()(a,c)-e)/(1+e)},a}),c)})}var b=a.models.line(),c=a.models.axis(),d=a.models.axis(),e=a.models.legend(),f=a.models.legend(),g={top:30,right:30,bottom:50,left:60},h=a.utils.defaultColor(),i=null,j=null,k=!0,l=!0,m=!0,n=!0,o=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" at "+b+"</p>"},p,q,r=b.id(),s={index:0,rescaleY:n},t="No Data Available.",u=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState");c.orient("bottom").tickPadding(7),d.orient("left");var v=d3.scale.linear(),w={i:0,x:0},x=function(e,f){var g=e.pos[0]+(f.offsetLeft||0),h=e.pos[1]+(f.offsetTop||0),i=c.tickFormat()(b.x()(e.point,e.pointIndex)),j=d.tickFormat()(b.y()(e.point,e.pointIndex)),k=o(e.series.key,i,j,e,y);a.tooltip.show([g,h],k,null,null,f)};return b.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+g.left,a.pos[1]+g.top],u.tooltipShow(a)}),b.dispatch.on("elementMouseout.tooltip",function(a){u.tooltipHide(a)}),u.on("tooltipHide",function(){l&&a.tooltip.cleanup()}),y.dispatch=u,y.lines=b,y.legend=e,y.xAxis=c,y.yAxis=d,d3.rebind(y,b,"defined","isArea","x","y","size","xDomain","yDomain","forceX","forceY","interactive","clipEdge","clipVoronoi","id"),y.margin=function(a){return arguments.length?(g.top=typeof a.top!="undefined"?a.top:g.top,g.right=typeof a.right!="undefined"?a.right:g.right,g.bottom=typeof a.bottom!="undefined"?a.bottom:g.bottom,g.left=typeof a.left!="undefined"?a.left:g.left,y):g},y.width=function(a){return arguments.length?(i=a,y):i},y.height=function(a){return arguments.length?(j=a,y):j},y.color=function(b){return arguments.length?(h=a.utils.getColor(b),e.color(h),y):h},y.rescaleY=function(a){return arguments.length?(n=a,n):n},y.showControls=function(a){return arguments.length?(m=a,y):m},y.showLegend=function(a){return arguments.length?(k=a,y):k},y.tooltips=function(a){return arguments.length?(l=a,y):l},y.tooltipContent=function(a){return arguments.length?(o=a,y):o},y.state=function(a){return arguments.length?(s=a,y):s},y.noData=function(a){return arguments.length?(t=a,y):t},y},a.models.discreteBar=function(){function t(a){return a.each(function(a){var e=c-b.left-b.right,t=d-b.top-b.bottom,u=d3.select(this);a=a.map(function(a,b){return a.values=a.values.map(function(a){return a.series=b,a}),a});var v=n&&o?[]:a.map(function(a){return a.values.map(function(a,b){return{x:h(a,b),y:i(a,b),y0:a.y0}})});f.domain(n||d3.merge(v).map(function(a){return a.x})).rangeBands([0,e],.1),g.domain(o||d3.extent(d3.merge(v).map(function(a){return a.y}).concat(j))),l?g.range([t-(g.domain()[0]<0?12:0),g.domain()[1]>0?12:0]):g.range([t,0]),r=r||f,s=s||g.copy().range([g(0),g(0)]);var w=u.selectAll("g.nv-wrap.nv-discretebar").data([a]),z=w.enter().append("g").attr("class","nvd3 nv-wrap nv-discretebar"),A=z.append("g"),B=w.select("g");A.append("g").attr("class","nv-groups"),w.attr("transform","translate("+b.left+","+b.top+")");var C=w.select(".nv-groups").selectAll(".nv-group").data(function(a){return a},function(a){return a.key});C.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(C.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),C.attr("class",function(a,b){return"nv-group nv-series-"+b}).classed("hover",function(a){return a.hover}),d3.transition(C).style("stroke-opacity",1).style("fill-opacity",.75);var D=C.selectAll("g.nv-bar").data(function(a){return a.values});D.exit().remove();var E=D.enter().append("g").attr("transform",function(a,b,c){return"translate("+(f(h(a,b))+f.rangeBand()*.05)+", "+g(0)+")"}).on("mouseover",function(b,c){d3.select(this).classed("hover",!0),p.elementMouseover({value:i(b,c),point:b,series:a[b.series],pos:[f(h(b,c))+f.rangeBand()*(b.series+.5)/a.length,g(i(b,c))],pointIndex:c,seriesIndex:b.series,e:d3.event})}).on("mouseout",function(b,c){d3.select(this).classed("hover",!1),p.elementMouseout({value:i(b,c),point:b,series:a[b.series],pointIndex:c,seriesIndex:b.series,e:d3.event})}).on("click",function(b,c){p.elementClick({value:i(b,c),point:b,series:a[b.series],pos:[f(h(b,c))+f.rangeBand()*(b.series+.5)/a.length,g(i(b,c))],pointIndex:c,seriesIndex:b.series,e:d3.event}),d3.event.stopPropagation()}).on("dblclick",function(b,c){p.elementDblClick({value:i(b,c),point:b,series:a[b.series],pos:[f(h(b,c))+f.rangeBand()*(b.series+.5)/a.length,g(i(b,c))],pointIndex:c,seriesIndex:b.series,e:d3.event}),d3.event.stopPropagation()});E.append("rect").attr("height",0).attr("width",f.rangeBand()*.9/a.length),l?(E.append("text").attr("text-anchor","middle"),D.select("text").attr("x",f.rangeBand()*.9/2).attr("y",function(a,b){return i(a,b)<0?g(i(a,b))-g(0)+12:-4}).text(function(a,b){return m(i(a,b))})):D.selectAll("text").remove(),D.attr("class",function(a,b){return i(a,b)<0?"nv-bar negative":"nv-bar positive"}).style("fill",function(a,b){return a.color||k(a,b)}).style("stroke",function(a,b){return a.color||k(a,b)}).select("rect").attr("class",q).attr("width",f.rangeBand()*.9/a.length),d3.transition(D).attr("transform",function(a,b){var c=f(h(a,b))+f.rangeBand()*.05,d=i(a,b)<0?g(0):g(0)-g(i(a,b))<1?g(0)-1:g(i(a,b));return"translate("+c+", "+d+")"}).select("rect").attr("height",function(a,b){return Math.max(Math.abs(g(i(a,b))-g(0))||1)}),r=f.copy(),s=g.copy()}),t}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=Math.floor(Math.random()*1e4),f=d3.scale.ordinal(),g=d3.scale.linear(),h=function(a){return a.x},i=function(a){return a.y},j=[0],k=a.utils.defaultColor(),l=!1,m=d3.format(",.2f"),n,o,p=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout"),q="discreteBar",r,s;return t.dispatch=p,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(
|
2
|
+
a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,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?(f=a,t):f},t.yScale=function(a){return arguments.length?(g=a,t):g},t.xDomain=function(a){return arguments.length?(n=a,t):n},t.yDomain=function(a){return arguments.length?(o=a,t):o},t.forceY=function(a){return arguments.length?(j=a,t):j},t.color=function(b){return arguments.length?(k=a.utils.getColor(b),t):k},t.id=function(a){return arguments.length?(e=a,t):e},t.showValues=function(a){return arguments.length?(l=a,t):l},t.valueFormat=function(a){return arguments.length?(m=a,t):m},t.rectClass=function(a){return arguments.length?(q=a,t):q},t},a.models.discreteBarChart=function(){function q(a){return a.each(function(h){var k=d3.select(this),r=this,s=(f||parseInt(k.style("width"))||960)-e.left-e.right,t=(g||parseInt(k.style("height"))||400)-e.top-e.bottom;q.update=function(){o.beforeUpdate(),a.transition().call(q)},q.container=this;if(!h||!h.length||!h.filter(function(a){return a.values.length}).length){var u=k.selectAll(".nv-noData").data([n]);return u.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),u.attr("x",e.left+s/2).attr("y",e.top+t/2).text(function(a){return a}),q}k.selectAll(".nv-noData").remove(),l=b.xScale(),m=b.yScale();var v=k.selectAll("g.nv-wrap.nv-discreteBarWithAxes").data([h]),w=v.enter().append("g").attr("class","nvd3 nv-wrap nv-discreteBarWithAxes").append("g"),z=w.append("defs"),A=v.select("g");w.append("g").attr("class","nv-x nv-axis"),w.append("g").attr("class","nv-y nv-axis"),w.append("g").attr("class","nv-barsWrap"),A.attr("transform","translate("+e.left+","+e.top+")"),b.width(s).height(t);var B=A.select(".nv-barsWrap").datum(h.filter(function(a){return!a.disabled}));d3.transition(B).call(b),z.append("clipPath").attr("id","nv-x-label-clip-"+b.id()).append("rect"),A.select("#nv-x-label-clip-"+b.id()+" rect").attr("width",l.rangeBand()*(i?2:1)).attr("height",16).attr("x",-l.rangeBand()/(i?1:2)),c.scale(l).ticks(s/100).tickSize(-t,0),A.select(".nv-x.nv-axis").attr("transform","translate(0,"+(m.range()[0]+(b.showValues()&&m.domain()[0]<0?16:0))+")"),A.select(".nv-x.nv-axis").transition().duration(0).call(c);var C=A.select(".nv-x.nv-axis").selectAll("g");i&&C.selectAll("text").attr("transform",function(a,b,c){return"translate(0,"+(c%2==0?"5":"17")+")"}),d.scale(m).ticks(t/36).tickSize(-s,0),d3.transition(A.select(".nv-y.nv-axis")).call(d),o.on("tooltipShow",function(a){j&&p(a,r.parentNode)})}),q}var b=a.models.discreteBar(),c=a.models.axis(),d=a.models.axis(),e={top:15,right:10,bottom:50,left:60},f=null,g=null,h=a.utils.getColor(),i=!1,j=!0,k=function(a,b,c,d,e){return"<h3>"+b+"</h3>"+"<p>"+c+"</p>"},l,m,n="No Data Available.",o=d3.dispatch("tooltipShow","tooltipHide","beforeUpdate");c.orient("bottom").highlightZero(!1).showMaxMin(!1).tickFormat(function(a){return a}),d.orient("left").tickFormat(d3.format(",.1f"));var p=function(e,f){var g=e.pos[0]+(f.offsetLeft||0),h=e.pos[1]+(f.offsetTop||0),i=c.tickFormat()(b.x()(e.point,e.pointIndex)),j=d.tickFormat()(b.y()(e.point,e.pointIndex)),l=k(e.series.key,i,j,e,q);a.tooltip.show([g,h],l,e.value<0?"n":"s",null,f)};return b.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+e.left,a.pos[1]+e.top],o.tooltipShow(a)}),b.dispatch.on("elementMouseout.tooltip",function(a){o.tooltipHide(a)}),o.on("tooltipHide",function(){j&&a.tooltip.cleanup()}),q.dispatch=o,q.discretebar=b,q.xAxis=c,q.yAxis=d,d3.rebind(q,b,"x","y","xDomain","yDomain","forceX","forceY","id","showValues","valueFormat"),q.margin=function(a){return arguments.length?(e.top=typeof a.top!="undefined"?a.top:e.top,e.right=typeof a.right!="undefined"?a.right:e.right,e.bottom=typeof a.bottom!="undefined"?a.bottom:e.bottom,e.left=typeof a.left!="undefined"?a.left:e.left,q):e},q.width=function(a){return arguments.length?(f=a,q):f},q.height=function(a){return arguments.length?(g=a,q):g},q.color=function(c){return arguments.length?(h=a.utils.getColor(c),b.color(h),q):h},q.staggerLabels=function(a){return arguments.length?(i=a,q):i},q.tooltips=function(a){return arguments.length?(j=a,q):j},q.tooltipContent=function(a){return arguments.length?(k=a,q):k},q.noData=function(a){return arguments.length?(n=a,q):n},q},a.models.distribution=function(){function k(a){return a.each(function(a){var i=c-(e==="x"?b.left+b.right:b.top+b.bottom),k=e=="x"?"y":"x",l=d3.select(this);j=j||h;var m=l.selectAll("g.nv-distribution").data([a]),n=m.enter().append("g").attr("class","nvd3 nv-distribution"),o=n.append("g"),p=m.select("g");m.attr("transform","translate("+b.left+","+b.top+")");var q=p.selectAll("g.nv-dist").data(function(a){return a},function(a){return a.key});q.enter().append("g"),q.attr("class",function(a,b){return"nv-dist nv-series-"+b}).style("stroke",function(a,b){return g(a,b)});var r=q.selectAll("line.nv-dist"+e).data(function(a){return a.values});r.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(q.exit().selectAll("line.nv-dist"+e)).attr(e+"1",function(a,b){return h(f(a,b))}).attr(e+"2",function(a,b){return h(f(a,b))}).style("stroke-opacity",0).remove(),r.attr("class",function(a,b){return"nv-dist"+e+" nv-dist"+e+"-"+b}).attr(k+"1",0).attr(k+"2",d),d3.transition(r).attr(e+"1",function(a,b){return h(f(a,b))}).attr(e+"2",function(a,b){return h(f(a,b))}),j=h.copy()}),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=d3.scale.linear(),i,j;return k.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,k):b},k.width=function(a){return arguments.length?(c=a,k):c},k.axis=function(a){return arguments.length?(e=a,k):e},k.size=function(a){return arguments.length?(d=a,k):d},k.getData=function(a){return arguments.length?(f=d3.functor(a),k):f},k.scale=function(a){return arguments.length?(h=a,k):h},k.color=function(b){return arguments.length?(g=a.utils.getColor(b),k):g},k},a.models.indentedTree=function(){function o(a){return a.each(function(b){function z(a,b,c){d3.event.stopPropagation();if(d3.event.shiftKey&&!c)return d3.event.shiftKey=!1,a.values&&a.values.forEach(function(a){(a.values||a._values)&&z(a,0,!0)}),!0;if(!C(a))return!0;a.values?(a._values=a.values,a.values=null):(a.values=a._values,a._values=null),o.update()}function A(a){return a._values&&a._values.length?l:a.values&&a.values.length?m:""}function B(a){return a._values&&a._values.length}function C(a){var b=a.values||a._values;return b&&b.length}var c=0,e=1,f=d3.layout.tree().children(function(a){return a.values}).size([d,i]);o.update=function(){a.transition().call(o)},o.container=this,b[0]||(b[0]={key:h});var p=f.nodes(b[0]),q=d3.select(this).selectAll("div").data([[p]]),r=q.enter().append("div").attr("class","nvd3 nv-wrap nv-indentedtree"),s=r.append("table"),t=q.select("table").attr("width","100%").attr("class",k);if(g){var u=s.append("thead"),v=u.append("tr");j.forEach(function(a){v.append("th").attr("width",a.width?a.width:"10%").style("text-align",a.type=="numeric"?"right":"left").append("span").text(a.label)})}var w=t.selectAll("tbody").data(function(a){return a});w.enter().append("tbody"),e=d3.max(p,function(a){return a.depth}),f.size([d,e*i]);var x=w.selectAll("tr").data(function(a){return a},function(a){return a.id||a.id==++c});x.exit().remove(),x.select("img.nv-treeicon").attr("src",A).classed("folded",B);var y=x.enter().append("tr");j.forEach(function(a,b){var c=y.append("td").style("padding-left",function(a){return(b?0:a.depth*i+12+(A(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",B).attr("src",A).style("width","14px").style("height","14px").style("padding","0 1px").style("display",function(a){return A(a)?"inline-block":"none"}).on("click",z),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-childrenCount").text(function(a){return a.values&&a.values.length||a._values&&a._values.length?"("+(a.values&&a.values.length||a._values&&a._values.length)+")":""}),a.click&&c.select("span").on("click",a.click)}),x.order().on("click",function(a){n.elementClick({row:this,data:a,pos:[a.x,a.y]})}).on("dblclick",function(a){n.elementDblclick({row:this,data:a,pos:[a.x,a.y]})}).on("mouseover",function(a){n.elementMouseover({row:this,data:a,pos:[a.x,a.y]})}).on("mouseout",function(a){n.elementMouseout({row:this,data:a,pos:[a.x,a.y]})})}),o}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=a.utils.defaultColor(),f=Math.floor(Math.random()*1e4),g=!0,h="No Data Available.",i=20,j=[{key:"key",label:"Name",type:"text"}],k=null,l="images/grey-plus.png",m="images/grey-minus.png",n=d3.dispatch("elementClick","elementDblclick","elementMouseover","elementMouseout");return o.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,o):b},o.width=function(a){return arguments.length?(c=a,o):c},o.height=function(a){return arguments.length?(d=a,o):d},o.color=function(b){return arguments.length?(e=a.utils.getColor(b),scatter.color(e),o):e},o.id=function(a){return arguments.length?(f=a,o):f},o.header=function(a){return arguments.length?(g=a,o):g},o.noData=function(a){return arguments.length?(h=a,o):h},o.columns=function(a){return arguments.length?(j=a,o):j},o.tableClass=function(a){return arguments.length?(k=a,o):k},o.iconOpen=function(a){return arguments.length?(l=a,o):l},o.iconClose=function(a){return arguments.length?(m=a,o):m},o},a.models.legend=function(){function i(a){return a.each(function(a){var i=c-b.left-b.right,j=d3.select(this),l=j.selectAll("g.nv-legend").data([a]),m=l.enter().append("g").attr("class","nvd3 nv-legend").append("g"),n=l.select("g");l.attr("transform","translate("+b.left+","+b.top+")");var o=n.selectAll(".nv-series").data(function(a){return a}),p=o.enter().append("g").attr("class","nv-series").on("mouseover",function(a,b){h.legendMouseover(a,b)}).on("mouseout",function(a,b){h.legendMouseout(a,b)}).on("click",function(a,b){h.legendClick(a,b)}).on("dblclick",function(a,b){h.legendDblclick(a,b)});p.append("circle").style("stroke-width",2).attr("r",5),p.append("text").attr("text-anchor","start").attr("dy",".32em").attr("dx","8"),o.classed("disabled",function(a){return a.disabled}),o.exit().remove(),o.select("circle").style("fill",function(a,b){return a.color||f(a,b)}).style("stroke",function(a,b){return a.color||f(a,b)}),o.select("text").text(e);if(g){var q=[];o.each(function(a,b){q.push(d3.select(this).select("text").node().getComputedTextLength()+28)});var r=0,s=0,t=[];while(s<i&&r<q.length)t[r]=q[r],s+=q[r++];while(s>i&&r>1){t=[],r--;for(k=0;k<q.length;k++)q[k]>(t[k%r]||0)&&(t[k%r]=q[k]);s=t.reduce(function(a,b,c,d){return a+b})}var u=[];for(var v=0,w=0;v<r;v++)u[v]=w,w+=t[v];o.attr("transform",function(a,b){return"translate("+u[b%r]+","+(5+Math.floor(b/r)*20)+")"}),n.attr("transform","translate("+(c-b.right-s)+","+b.top+")"),d=b.top+b.bottom+Math.ceil(q.length/r)*20}else{var x=5,y=5,z=0,A;o.attr("transform",function(a,d){var e=d3.select(this).select("text").node().getComputedTextLength()+28;return A=y,c<b.left+b.right+A+e&&(y=A=5,x+=20),y+=e,y>z&&(z=y),"translate("+A+","+x+")"}),n.attr("transform","translate("+(c-b.right-z)+","+b.top+")"),d=b.top+b.bottom+x+15}}),i}var b={top:5,right:0,bottom:5,left:0},c=400,d=20,e=function(a){return a.key},f=a.utils.defaultColor(),g=!0,h=d3.dispatch("legendClick","legendDblclick","legendMouseover","legendMouseout");return i.dispatch=h,i.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,i):b},i.width=function(a){return arguments.length?(c=a,i):c},i.height=function(a){return arguments.length?(d=a,i):d},i.key=function(a){return arguments.length?(e=a,i):e},i.color=function(b){return arguments.length?(f=a.utils.getColor(b),i):f},i.align=function(a){return arguments.length?(g=a,i):g},i},a.models.line=function(){function q(a){return a.each(function(a){var q=d-c.left-c.right,r=e-c.top-c.bottom,s=d3.select(this);l=b.xScale(),m=b.yScale(),o=o||l,p=p||m;var t=s.selectAll("g.nv-wrap.nv-line").data([a]),u=t.enter().append("g").attr("class","nvd3 nv-wrap nv-line"),v=u.append("defs"),w=u.append("g"),z=t.select("g");w.append("g").attr("class","nv-groups"),w.append("g").attr("class","nv-scatterWrap"),t.attr("transform","translate("+c.left+","+c.top+")"),b.width(q).height(r);var A=t.select(".nv-scatterWrap");d3.transition(A).call(b),v.append("clipPath").attr("id","nv-edge-clip-"+b.id()).append("rect"),t.select("#nv-edge-clip-"+b.id()+" rect").attr("width",q).attr("height",r),z.attr("clip-path",k?"url(#nv-edge-clip-"+b.id()+")":""),A.attr("clip-path",k?"url(#nv-edge-clip-"+b.id()+")":"");var B=t.select(".nv-groups").selectAll(".nv-group").data(function(a){return a},function(a){return a.key});B.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(B.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),B.attr("class",function(a,b){return"nv-group nv-series-"+b}).classed("hover",function(a){return a.hover}).style("fill",function(a,b){return f(a,b)}).style("stroke",function(a,b){return f(a,b)}),d3.transition(B).style("stroke-opacity",1).style("fill-opacity",.5);var C=B.selectAll("path.nv-area").data(function(a){return j(a)?[a]:[]});C.enter().append("path").attr("class","nv-area").attr("d",function(a){return d3.svg.area().interpolate(n).defined(i).x(function(a,b){return o(g(a,b))}).y0(function(a,b){return p(h(a,b))}).y1(function(a,b){return p(m.domain()[0]<=0?m.domain()[1]>=0?0:m.domain()[1]:m.domain()[0])}).apply(this,[a.values])}),d3.transition(B.exit().selectAll("path.nv-area")).attr("d",function(a){return d3.svg.area().interpolate(n).defined(i).x(function(a,b){return o(g(a,b))}).y0(function(a,b){return p(h(a,b))}).y1(function(a,b){return p(m.domain()[0]<=0?m.domain()[1]>=0?0:m.domain()[1]:m.domain()[0])}).apply(this,[a.values])}),d3.transition(C).attr("d",function(a){return d3.svg.area().interpolate(n).defined(i).x(function(a,b){return o(g(a,b))}).y0(function(a,b){return p(h(a,b))}).y1(function(a,b){return p(m.domain()[0]<=0?m.domain()[1]>=0?0:m.domain()[1]:m.domain()[0])}).apply(this,[a.values])});var D=B.selectAll("path.nv-line").data(function(a){return[a.values]});D.enter().append("path").attr("class","nv-line").attr("d",d3.svg.line().interpolate(n).defined(i).x(function(a,b){return o(g(a,b))}).y(function(a,b){return p(h(a,b))})),d3.transition(B.exit().selectAll("path.nv-line")).attr("d",d3.svg.line().interpolate(n).defined(i).x(function(a,b){return l(g(a,b))}).y(function(a,b){return m(h(a,b))})),d3.transition(D).attr("d",d3.svg.line().interpolate(n).defined(i).x(function(a,b){return l(g(a,b))}).y(function(a,b){return m(h(a,b))})),o=l.copy(),p=m.copy()}),q}var b=a.models.scatter(),c={top:0,right:0,bottom:0,left:0},d=960,e=500,f=a.utils.defaultColor(),g=function(a){return a.x},h=function(a){return a.y},i=function(a,b){return!isNaN(h(a,b))&&h(a,b)!==null},j=function(a){return a.area},k=!1,l,m,n="linear";b.size(16).sizeDomain([16,256]);var o,p;return q.dispatch=b.dispatch,q.scatter=b,d3.rebind(q,b,"id","interactive","size","xScale","yScale","zScale","xDomain","yDomain","sizeDomain","forceX","forceY","forceSize","clipVoronoi","clipRadius","padData"),q.margin=function(a){return arguments.length?(c.top=typeof a.top!="undefined"?a.top:c.top,c.right=typeof a.right!="undefined"?a.right:c.right,c.bottom=typeof a.bottom!="undefined"?a.bottom:c.bottom,c.left=typeof a.left!="undefined"?a.left:c.left,q):c},q.width=function(a){return arguments.length?(d=a,q):d},q.height=function(a){return arguments.length?(e=a,q):e},q.x=function(a){return arguments.length?(g=a,b.x(a),q):g},q.y=function(a){return arguments.length?(h=a,b.y(a),q):h},q.clipEdge=function(a){return arguments.length?(k=a,q):k},q.color=function(c){return arguments.length?(f=a.utils.getColor(c),b.color(f),q):f},q.interpolate=function(a){return arguments.length?(n=a,q):n},q.defined=function(a){return arguments.length?(i=a,q):i},q.isArea=function(a){return arguments.length?(j=d3.functor(a),q):j},q},a.models.lineChart=function(){function s(a){return a.each(function(l){var t=d3.select(this),u=this,v=(h||parseInt(t.style("width"))||960)-f.left-f.right,w=(i||parseInt(t.style("height"))||400)-f.top-f.bottom;s.update=function(){s(a)},s.container=this;if(!l||!l.length||!l.filter(function(a){return a.values.length}).length){var z=t.selectAll(".nv-noData").data([p]);return z.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),z.attr("x",f.left+v/2).attr("y",f.top+w/2).text(function(a){return a}),s}t.selectAll(".nv-noData").remove(),m=b.xScale(),n=b.yScale();var A=t.selectAll("g.nv-wrap.nv-lineChart").data([l]),B=A.enter().append("g").attr("class","nvd3 nv-wrap nv-lineChart").append("g"),C=A.select("g");B.append("g").attr("class","nv-x nv-axis"),B.append("g").attr("class","nv-y nv-axis"),B.append("g").attr("class","nv-linesWrap"),B.append("g").attr("class","nv-legendWrap"),j&&(e.width(v),C.select(".nv-legendWrap").datum(l).call(e),f.top!=e.height()&&(f.top=e.height(),w=(i||parseInt(t.style("height"))||400)-f.top-f.bottom),A.select(".nv-legendWrap").attr("transform","translate(0,"+ -f.top+")")),A.attr("transform","translate("+f.left+","+f.top+")"),b.width(v).height(w).color(l.map(function(a,b){return a.color||g(a,b)}).filter(function(a,b){return!l[b].disabled}));var D=C.select(".nv-linesWrap").datum(l.filter(function(a){return!a.disabled}));d3.transition(D).call(b),c.scale(m).ticks(v/100).tickSize(-w,0),C.select(".nv-x.nv-axis").attr("transform","translate(0,"+n.range()[0]+")"),d3.transition(C.select(".nv-x.nv-axis")).call(c),d.scale(n).ticks(w/36).tickSize(-v,0),d3.transition(C.select(".nv-y.nv-axis")).call(d),e.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,l.filter(function(a){return!a.disabled}).length||l.map(function(a){return a.disabled=!1,A.selectAll(".nv-series").classed("disabled",!1),a}),o.disabled=l.map(function(a){return!!a.disabled}),q.stateChange(o),a.transition().call(s)}),q.on("tooltipShow",function(a){k&&r(a,u.parentNode)}),q.on("changeState",function(b){typeof b.disabled!="undefined"&&(l.forEach(function(a,c){a.disabled=b.disabled[c]}),o.disabled=b.disabled),a.call(s)})}),s}var b=a.models.line(),c=a.models.axis(),d=a.models.axis(),e=a.models.legend(),f={top:30,right:20,bottom:50,left:60},g=a.utils.defaultColor(),h=null,i=null,j=!0,k=!0,l=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" at "+b+"</p>"},m,n,o={},p="No Data Available.",q=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState");c.orient("bottom").tickPadding(7),d.orient("left");var r=function(e,f){if(f){var g=d3.select(f).select("svg"),h=g.attr("viewBox");if(h){h=h.split(" ");var i=parseInt(g.style("width"))/h[2];e.pos[0]=e.pos[0]*i,e.pos[1]=e.pos[1]*i}}var j=e.pos[0]+(f.offsetLeft||0),k=e.pos[1]+(f.offsetTop||0),m=c.tickFormat()(b.x()(e.point,e.pointIndex)),n=d.tickFormat()(b.y()(e.point,e.pointIndex)),o=l(e.series.key,m,n,e,s);a.tooltip.show([j,k],o,null,null,f)};return b.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+f.left,a.pos[1]+f.top],q.tooltipShow(a)}),b.dispatch.on("elementMouseout.tooltip",function(a){q.tooltipHide(a)}),q.on("tooltipHide",function(){k&&a.tooltip.cleanup()}),s.dispatch=q,s.lines=b,s.legend=e,s.xAxis=c,s.yAxis=d,d3.rebind(s,b,"defined","isArea","x","y","size","xScale","yScale","xDomain","yDomain","forceX","forceY","interactive","clipEdge","clipVoronoi","id","interpolate"),s.margin=function(a){return arguments.length?(f.top=typeof a.top!="undefined"?a.top:f.top,f.right=typeof a.right!="undefined"?a.right:f.right,f.bottom=typeof a.bottom!="undefined"?a.bottom:f.bottom,f.left=typeof a.left!="undefined"?a.left:f.left,s):f},s.width=function(a){return arguments.length?(h=a,s):h},s.height=function(a){return arguments.length?(i=a,s):i},s.color=function(b){return arguments.length?(g=a.utils.getColor(b),e.color(g),s):g},s.showLegend=function(a){return arguments.length?(j=a,s):j},s.tooltips=function(a){return arguments.length?(k=a,s):k},s.tooltipContent=function(a){return arguments.length?(l=a,s):l},s.state=function(a){return arguments.length?(o=a,s):o},s.noData=function(a){return arguments.length?(p=a,s):p},s},a.models.linePlusBarChart=function(){function x(a){return a.each(function(k){var l=d3.select(this),p=this,y=(i||parseInt(l.style("width"))||960)-h.left-h.right,z=(j||parseInt(l.style("height"))||400)-h.top-h.bottom;x.update=function(){x(a)},x.container=this;if(!k||!k.length||!k.filter(function(a){return a.values.length}).length){var A=l.selectAll(".nv-noData").data([t]);return A.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),A.attr("x",h.left+y/2).attr("y",h.top+z/2).text(function(a){return a}),x}l.selectAll(".nv-noData").remove();var B=k.filter(function(a){return!a.disabled&&a.bar}),C=k.filter(function(a){return!a.bar});q=C.filter(function(a){return!a.disabled}).length&&C.filter(function(a){return!a.disabled})[0].values.length?b.xScale():c.xScale(),r=c.yScale(),s=b.yScale();var D=d3.select(this).selectAll("g.nv-wrap.nv-linePlusBar").data([k]),E=D.enter().append("g").attr("class","nvd3 nv-wrap nv-linePlusBar").append("g"),F=D.select("g");E.append("g").attr("class","nv-x nv-axis"),E.append("g").attr("class","nv-y1 nv-axis"),E.append("g").attr("class","nv-y2 nv-axis"),E.append("g").attr("class","nv-barsWrap"),E.append("g").attr("class","nv-linesWrap"),E.append("g").attr("class","nv-legendWrap"),n&&(g.width(y/2),F.select(".nv-legendWrap").datum(k.map(function(a){return a.originalKey=a.originalKey===undefined?a.key:a.originalKey,a.key=a.originalKey+(a.bar?" (left axis)":" (right axis)"),a})).call(g),h.top!=g.height()&&(h.top=g.height(),z=(j||parseInt(l.style("height"))||400)-h.top-h.bottom),F.select(".nv-legendWrap").attr("transform","translate("+y/2+","+ -h.top+")")),D.attr("transform","translate("+h.left+","+h.top+")"),b.width(y).height(z).color(k.map(function(a,b){return a.color||m(a,b)}).filter(function(a,b){return!k[b].disabled&&!k[b].bar})),c.width(y).height(z).color(k.map(function(a,b){return a.color||m(a,b)}).filter(function(a,b){return!k[b].disabled&&k[b].bar}));var G=F.select(".nv-barsWrap").datum(B.length?B:[{values:[]}]),H=F.select(".nv-linesWrap").datum(C[0].disabled?[{values:[]}]:C);d3.transition(G).call(c),d3.transition(H).call(b),d.scale(q).ticks(y/100).tickSize(-z,0),F.select(".nv-x.nv-axis").attr("transform","translate(0,"+r.range()[0]+")"),d3.transition(F.select(".nv-x.nv-axis")).call(d),e.scale(r).ticks(z/36).tickSize(-y,0),d3.transition(F.select(".nv-y1.nv-axis")).style("opacity",B.length?1:0).call(e),f.scale(s).ticks(z/36).tickSize(B.length?0:-y,0),F.select(".nv-y2.nv-axis").style("opacity",C.length?1:0).attr("transform","translate("+y+",0)"),d3.transition(F.select(".nv-y2.nv-axis")).call(f),g.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,k.filter(function(a){return!a.disabled}).length||k.map(function(a){return a.disabled=!1,D.selectAll(".nv-series").classed("disabled",!1),a}),v.disabled=k.map(function(a){return!!a.disabled}),u.stateChange(v),a.transition().call(x)}),u.on("tooltipShow",function(a){o&&w(a,p.parentNode)}),u.on("changeState",function(b){typeof b.disabled!="undefined"&&(k.forEach(function(a,c){a.disabled=b.disabled[c]}),v.disabled=b.disabled),a.call(x)})}),x}var b=a.models.line(),c=a.models.historicalBar(),d=a.models.axis(),e=a.models.axis(),f=a.models.axis(),g=a.models.legend(),h={top:30,right:60,bottom:50,left:60},i=null,j=null,k=function(a){return a.x},l=function(a){return a.y},m=a.utils.defaultColor(),n=!0,o=!0,p=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" at "+b+"</p>"},q,r,s,t="No Data Available.",u=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState");c.padData(!0),b.clipEdge(!1).padData(!0),d.orient("bottom").tickPadding(7).highlightZero(!1),e.orient("left"),f.orient("right");var v={},w=function(c,g){var h=c.pos[0]+(g.offsetLeft||0),i=c.pos[1]+(g.offsetTop||0),j=d.tickFormat()(b.x()(c.point,c.pointIndex)),k=(c.series.bar?e:f).tickFormat()(b.y()(c.point,c.pointIndex)),l=p(c.series.key,j,k,c,x);a.tooltip.show([h,i],l,c.value<0?"n":"s",null,g)};return b.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+h.left,a.pos[1]+h.top],u.tooltipShow(a)}),b.dispatch.on("elementMouseout.tooltip",function(a){u.tooltipHide(a)}),c.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+h.left,a.pos[1]+h.top],u.tooltipShow(a)}),c.dispatch.on("elementMouseout.tooltip",function(a){u.tooltipHide(a)}),u.on("tooltipHide",function(){o&&a.tooltip.cleanup()}),x.dispatch=u,x.legend=g,x.lines=b,x.bars=c,x.xAxis=d,x.y1Axis=e,x.y2Axis=f,d3.rebind(x,b,"defined","size","clipVoronoi","interpolate"),x.x=function(a){return arguments.length?(k=a,b.x(a),c.x(a),x):k},x.y=function(a){return arguments.length?(l=a,b.y(a),c.y(a),x):l},x.margin=function(a){return arguments.length?(h.top=typeof a.top!="undefined"?a.top:h.top,h.right=typeof a.right!="undefined"?a.right:h.right,h.bottom=typeof a.bottom!="undefined"?a.bottom:h.bottom,h.left=typeof a.left!="undefined"?a.left:h.left,x):h},x.width=function(a){return arguments.length?(i=a,x):i},x.height=function(a){return arguments.length?(j=a,x):j},x.color=function(b){return arguments.length?(m=a.utils.getColor(b),g.color(m),x):m},x.showLegend=function(a){return arguments.length?(n=a,x):n},x.tooltips=function(a){return arguments.length?(o=a,x):o},x.tooltipContent=function(a){return arguments.length?(p=a,x):p},x.state=function(a){return arguments.length?(v=a,x):v},x.noData=function(a){return arguments.length?(t=a,x):t},x},a.models.lineWithFocusChart=function(){function A(a){return a.each(function(w){function P(a){var b=+(a=="e"),c=b?1:-1,d=F/3;return"M"+.5*c+","+d+"A6,6 0 0 "+b+" "+6.5*c+","+(d+6)+"V"+(2*d-6)+"A6,6 0 0 "+b+" "+.5*c+","+2*d+"Z"+"M"+2.5*c+","+(d+8)+"V"+(2*d-8)+"M"+4.5*c+","+(d+8)+"V"+(2*d-8)}function Q(){i.empty()||i.extent(u),N.data([i.empty()?r.domain():u]).each(function(a,b){var c=r(a[0])-p.range()[0],d=p.range()[1]-r(a[1]);d3.select(this).select(".left").attr("width",c<0?0:c),d3.select(this).select(".right").attr("x",r(a[1])).attr("width",d<0?0:d)})}function R(){u=i.empty()?null:i.extent(),extent=i.empty()?r.domain():i.extent(),y.brush({extent:extent,brush:i}),Q();var a=J.select(".nv-focus .nv-linesWrap").datum(w.filter(function(a){return!a.disabled}).map(function(a,c){return{key:a.key,values:a.values.filter(function(a,c){return b.x()(a,c)>=extent[0]&&b.x()(a,c)<=extent[1]})}}));d3.transition(a).call(b),d3.transition(J.select(".nv-focus .nv-x.nv-axis")).call(d),d3.transition(J.select(".nv-focus .nv-y.nv-axis")).call(e)}var B=d3.select(this),C=this,D=(m||parseInt(B.style("width"))||960)-j.left-j.right,E=(n||parseInt(B.style("height"))||400)-j.top-j.bottom-o,F=o-k.top-k.bottom;A.update=function(){A(a)},A.container=this;if(!w||!w.length||!w.filter(function(a){return a.values.length}).length){var G=B.selectAll(".nv-noData").data([x]);return G.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),G.attr("x",j.left+D/2).attr("y",j.top+E/2).text(function(a){return a}),A}B.selectAll(".nv-noData").remove(),p=b.xScale(),q=b.yScale(),r=c.xScale(),s=c.yScale();var H=B.selectAll("g.nv-wrap.nv-lineWithFocusChart").data([w]),I=H.enter().append("g").attr("class","nvd3 nv-wrap nv-lineWithFocusChart").append("g"),J=H.select("g");I.append("g").attr("class","nv-legendWrap");var K=I.append("g").attr("class","nv-focus");K.append("g").attr("class","nv-x nv-axis"),K.append("g").attr("class","nv-y nv-axis"),K.append("g").attr("class","nv-linesWrap");var L=I.append("g").attr("class","nv-context");L.append("g").attr("class","nv-x nv-axis"),L.append("g").attr("class","nv-y nv-axis"),L.append("g").attr("class","nv-linesWrap"),L.append("g").attr("class","nv-brushBackground"),L.append("g").attr("class","nv-x nv-brush"),t&&(h.width(D),J.select(".nv-legendWrap").datum(w).call(h),j.top!=h.height()&&(j.top=h.height(),E=(n||parseInt(B.style("height"))||400)-j.top-j.bottom-o),J.select(".nv-legendWrap").attr("transform","translate(0,"+ -j.top+")")),H.attr("transform","translate("+j.left+","+j.top+")"),b.width(D).height(E).color(w.map(function(a,b){return a.color||l(a,b)}).filter(function(a,b){return!w[b].disabled})),c.defined(b.defined()).width(D).height(F).color(w.map(function(a,b){return a.color||l(a,b)}).filter(function(a,b){return!w[b].disabled})),J.select(".nv-context").attr("transform","translate(0,"+(E+j.bottom+k.top)+")");var M=J.select(".nv-context .nv-linesWrap").datum(w.filter(function(a){return!a.disabled}));d3.transition(M).call(c),d.scale(p).ticks(D/100).tickSize(-E,0),e.scale(q).ticks(E/36).tickSize(-D,0),J.select(".nv-focus .nv-x.nv-axis").attr("transform","translate(0,"+E+")"),i.x(r).on("brush",R),u&&i.extent(u);var N=J.select(".nv-brushBackground").selectAll("g").data([u||i.extent()]),O=N.enter().append("g");O.append("rect").attr("class","left").attr("x",0).attr("y",0).attr("height",F),O.append("rect").attr("class","right").attr("x",0).attr("y",0).attr("height",F),gBrush=J.select(".nv-x.nv-brush").call(i),gBrush.selectAll("rect").attr("height",F),gBrush.selectAll(".resize").append("path").attr("d",P),R(),f.scale(r).ticks(D/100).tickSize(-F,0),J.select(".nv-context .nv-x.nv-axis").attr("transform","translate(0,"+s.range()[0]+")"),d3.transition(J.select(".nv-context .nv-x.nv-axis")).call(f),g.scale(s).ticks(F/36).tickSize(-D,0),d3.transition(J.select(".nv-context .nv-y.nv-axis")).call(g),J.select(".nv-context .nv-x.nv-axis").attr("transform","translate(0,"+s.range()[0]+")"),h.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,w.filter(function(a){return!a.disabled}).length||w.map(function(a){return a.disabled=!1,H.selectAll(".nv-series").classed("disabled",!1),a}),a.transition().call(A)}),y.on("tooltipShow",function(a){v&&z(a,C.parentNode)})}),A}var b=a.models.line(),c=a.models.line(),d=a.models.axis(),e=a.models.axis(),f=a.models.axis(),g=a.models.axis(),h=a.models.legend(),i=d3.svg.brush(),j={top:30,right:30,bottom:30,left:60},k={top:0,right:30,bottom:20,left:60},l=a.utils.defaultColor(),m=null,n=null,o=100,p,q,r,s,t=!0,u=null,v=!0,w=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" at "+b+"</p>"},x="No Data Available.",y=d3.dispatch("tooltipShow","tooltipHide","brush");b.clipEdge(!0),c.interactive(!1),d.orient("bottom").tickPadding(5),e.orient("left"),f.orient("bottom").tickPadding(5),g.orient("left");var z=function(c,f){var g=c.pos[0]+(f.offsetLeft||0),h=c.pos[1]+(f.offsetTop||0),i=d.tickFormat()(b.x()(c.point,c.pointIndex)),j=e.tickFormat()(b.y()(c.point,c.pointIndex)),k=w(c.series.key,i,j,c,A);a.tooltip.show([g,h],k,null,null,f)};return b.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+j.left,a.pos[1]+j.top],y.tooltipShow(a)}),b.dispatch.on("elementMouseout.tooltip",function(a){y.tooltipHide(a)}),y.on("tooltipHide",function(){v&&a.tooltip.cleanup()}),A.dispatch=y,A.legend=h,A.lines=b,A.lines2=c,A.xAxis=d,A.yAxis=e,A.x2Axis=f,A.y2Axis=g,d3.rebind(A,b,"defined","isArea","size","xDomain","yDomain","forceX","forceY","interactive","clipEdge","clipVoronoi","id"),A.x=function(a){return arguments.length?(b.x(a),c.x(a),A):b.x},A.y=function(a){return arguments.length?(b.y(a),c.y(a),A):b.y},A.margin=function(a){return arguments.length?(j.top=typeof a.top!="undefined"?a.top:j.top,j.right=typeof a.right!="undefined"?a.right:j.right,j.bottom=typeof a.bottom!="undefined"?a.bottom:j.bottom,j.left=typeof a.left!="undefined"?a.left:j.left,A):j},A.margin2=function(a){return arguments.length?(k=a,A):k},A.width=function(a){return arguments.length?(m=a,A):m},A.height=function(a){return arguments.length?(n=a,A):n},A.height2=function(a){return arguments.length?(o=a,A):o},A.color=function(b){return arguments.length?(l=a.utils.getColor(b),h.color(l),A):l},A.showLegend=function(a){return arguments.length?(t=
|
3
|
+
a,A):t},A.tooltips=function(a){return arguments.length?(v=a,A):v},A.tooltipContent=function(a){return arguments.length?(w=a,A):w},A.interpolate=function(a){return arguments.length?(b.interpolate(a),c.interpolate(a),A):b.interpolate()},A.noData=function(a){return arguments.length?(x=a,A):x},A.xTickFormat=function(a){return arguments.length?(d.tickFormat(a),f.tickFormat(a),A):d.tickFormat()},A.yTickFormat=function(a){return arguments.length?(e.tickFormat(a),g.tickFormat(a),A):e.tickFormat()},A},a.models.multiBar=function(){function t(a){return a.each(function(a){var t=c-b.left-b.right,u=d-b.top-b.bottom,v=d3.select(this);l&&(a=d3.layout.stack().offset("zero").values(function(a){return a.values}).y(i)(a)),a=a.map(function(a,b){return a.values=a.values.map(function(a){return a.series=b,a}),a}),l&&a[0].values.map(function(b,c){var d=0,e=0;a.map(function(a){var b=a.values[c];b.size=Math.abs(b.y),b.y<0?(b.y1=e,e-=b.size):(b.y1=b.size+d,d+=b.size)})});var w=o&&p?[]:a.map(function(a){return a.values.map(function(a,b){return{x:h(a,b),y:i(a,b),y0:a.y0,y1:a.y1}})});e.domain(d3.merge(w).map(function(a){return a.x})).rangeBands([0,t],.1),f.domain(p||d3.extent(d3.merge(w).map(function(a){return a.y+(l?a.y1:0)}).concat(j))).range([u,0]);if(e.domain()[0]===e.domain()[1]||f.domain()[0]===f.domain()[1])singlePoint=!0;e.domain()[0]===e.domain()[1]&&(e.domain()[0]?e.domain([e.domain()[0]-e.domain()[0]*.01,e.domain()[1]+e.domain()[1]*.01]):e.domain([-1,1])),f.domain()[0]===f.domain()[1]&&(f.domain()[0]?f.domain([f.domain()[0]+f.domain()[0]*.01,f.domain()[1]-f.domain()[1]*.01]):f.domain([-1,1])),r=r||e,s=s||f;var z=v.selectAll("g.nv-wrap.nv-multibar").data([a]),A=z.enter().append("g").attr("class","nvd3 nv-wrap nv-multibar"),B=A.append("defs"),C=A.append("g"),D=z.select("g");C.append("g").attr("class","nv-groups"),z.attr("transform","translate("+b.left+","+b.top+")"),B.append("clipPath").attr("id","nv-edge-clip-"+g).append("rect"),z.select("#nv-edge-clip-"+g+" rect").attr("width",t).attr("height",u),D.attr("clip-path",k?"url(#nv-edge-clip-"+g+")":"");var E=z.select(".nv-groups").selectAll(".nv-group").data(function(a){return a},function(a){return a.key});E.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(E.exit()).selectAll("rect.nv-bar").delay(function(b,c){return c*n/a[0].values.length}).attr("y",function(a){return l?s(a.y0):s(0)}).attr("height",0).remove(),E.attr("class",function(a,b){return"nv-group nv-series-"+b}).classed("hover",function(a){return a.hover}).style("fill",function(a,b){return m(a,b)}).style("stroke",function(a,b){return m(a,b)}),d3.transition(E).style("stroke-opacity",1).style("fill-opacity",.75);var F=E.selectAll("rect.nv-bar").data(function(a){return a.values});F.exit().remove();var G=F.enter().append("rect").attr("class",function(a,b){return i(a,b)<0?"nv-bar negative":"nv-bar positive"}).attr("x",function(b,c,d){return l?0:d*e.rangeBand()/a.length}).attr("y",function(a){return s(l?a.y0:0)}).attr("height",0).attr("width",e.rangeBand()/(l?1:a.length));F.style("fill",function(a,b,c){return m(a,c,b)}).style("stroke",function(a,b,c){return m(a,c,b)}).on("mouseover",function(b,c){d3.select(this).classed("hover",!0),q.elementMouseover({value:i(b,c),point:b,series:a[b.series],pos:[e(h(b,c))+e.rangeBand()*(l?a.length/2:b.series+.5)/a.length,f(i(b,c)+(l?b.y0:0))],pointIndex:c,seriesIndex:b.series,e:d3.event})}).on("mouseout",function(b,c){d3.select(this).classed("hover",!1),q.elementMouseout({value:i(b,c),point:b,series:a[b.series],pointIndex:c,seriesIndex:b.series,e:d3.event})}).on("click",function(b,c){q.elementClick({value:i(b,c),point:b,series:a[b.series],pos:[e(h(b,c))+e.rangeBand()*(l?a.length/2:b.series+.5)/a.length,f(i(b,c)+(l?b.y0:0))],pointIndex:c,seriesIndex:b.series,e:d3.event}),d3.event.stopPropagation()}).on("dblclick",function(b,c){q.elementDblClick({value:i(b,c),point:b,series:a[b.series],pos:[e(h(b,c))+e.rangeBand()*(l?a.length/2:b.series+.5)/a.length,f(i(b,c)+(l?b.y0:0))],pointIndex:c,seriesIndex:b.series,e:d3.event}),d3.event.stopPropagation()}),F.attr("class",function(a,b){return i(a,b)<0?"nv-bar negative":"nv-bar positive"}).attr("transform",function(a,b){return"translate("+e(h(a,b))+",0)"}),l?d3.transition(F).delay(function(b,c){return c*n/a[0].values.length}).attr("y",function(a,b){return f(l?a.y1:0)}).attr("height",function(a,b){return Math.max(Math.abs(f(a.y+(l?a.y0:0))-f(l?a.y0:0)),1)}).each("end",function(){d3.transition(d3.select(this)).attr("x",function(b,c){return l?0:b.series*e.rangeBand()/a.length}).attr("width",e.rangeBand()/(l?1:a.length))}):d3.transition(F).delay(function(b,c){return c*n/a[0].values.length}).attr("x",function(b,c){return b.series*e.rangeBand()/a.length}).attr("width",e.rangeBand()/a.length).each("end",function(){d3.transition(d3.select(this)).attr("y",function(a,b){return i(a,b)<0?f(0):f(0)-f(i(a,b))<1?f(0)-1:f(i(a,b))}).attr("height",function(a,b){return Math.max(Math.abs(f(i(a,b))-f(0)),1)})}),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=a.utils.defaultColor(),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.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,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(b){return arguments.length?(m=a.utils.getColor(b),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 w(a){return a.each(function(p){var z=d3.select(this),A=this,B=(h||parseInt(z.style("width"))||960)-g.left-g.right,C=(i||parseInt(z.style("height"))||400)-g.top-g.bottom;w.update=function(){a.transition().call(w)},w.container=this;if(!p||!p.length||!p.filter(function(a){return a.values.length}).length){var D=z.selectAll(".nv-noData").data([t]);return D.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),D.attr("x",g.left+B/2).attr("y",g.top+C/2).text(function(a){return a}),w}z.selectAll(".nv-noData").remove(),q=b.xScale(),r=b.yScale();var E=z.selectAll("g.nv-wrap.nv-multiBarWithLegend").data([p]),F=E.enter().append("g").attr("class","nvd3 nv-wrap nv-multiBarWithLegend").append("g"),G=E.select("g");F.append("g").attr("class","nv-x nv-axis"),F.append("g").attr("class","nv-y nv-axis"),F.append("g").attr("class","nv-barsWrap"),F.append("g").attr("class","nv-legendWrap"),F.append("g").attr("class","nv-controlsWrap"),l&&(e.width(B/2),G.select(".nv-legendWrap").datum(p).call(e),g.top!=e.height()&&(g.top=e.height(),C=(i||parseInt(z.style("height"))||400)-g.top-g.bottom),G.select(".nv-legendWrap").attr("transform","translate("+B/2+","+ -g.top+")"));if(k){var H=[{key:"Grouped",disabled:b.stacked()},{key:"Stacked",disabled:!b.stacked()}];f.width(180).color(["#444","#444","#444"]),G.select(".nv-controlsWrap").datum(H).attr("transform","translate(0,"+ -g.top+")").call(f)}E.attr("transform","translate("+g.left+","+g.top+")"),b.width(B).height(C).color(p.map(function(a,b){return a.color||j(a,b)}).filter(function(a,b){return!p[b].disabled}));var I=G.select(".nv-barsWrap").datum(p.filter(function(a){return!a.disabled}));d3.transition(I).call(b),c.scale(q).ticks(B/100).tickSize(-C,0),G.select(".nv-x.nv-axis").attr("transform","translate(0,"+r.range()[0]+")"),d3.transition(G.select(".nv-x.nv-axis")).call(c);var J=G.select(".nv-x.nv-axis > g").selectAll("g");J.selectAll("line, text").style("opacity",1),m&&J.filter(function(a,b){return b%Math.ceil(p[0].values.length/(B/100))!==0}).selectAll("text, line").style("opacity",0),n&&J.selectAll("text").attr("transform",function(a,b,c){return"rotate("+n+" 0,0)"}).attr("text-transform",n>0?"start":"end"),G.select(".nv-x.nv-axis").selectAll("g.nv-axisMaxMin text").style("opacity",1),d.scale(r).ticks(C/36).tickSize(-B,0),d3.transition(G.select(".nv-y.nv-axis")).call(d),e.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,p.filter(function(a){return!a.disabled}).length||p.map(function(a){return a.disabled=!1,E.selectAll(".nv-series").classed("disabled",!1),a}),s.disabled=p.map(function(a){return!!a.disabled}),u.stateChange(s),a.transition().call(w)}),f.dispatch.on("legendClick",function(c,d){if(!c.disabled)return;H=H.map(function(a){return a.disabled=!0,a}),c.disabled=!1;switch(c.key){case"Grouped":b.stacked(!1);break;case"Stacked":b.stacked(!0)}s.stacked=b.stacked(),u.stateChange(s),a.transition().call(w)}),u.on("tooltipShow",function(a){o&&v(a,A.parentNode)}),u.on("changeState",function(c){typeof c.disabled!="undefined"&&(p.forEach(function(a,b){a.disabled=c.disabled[b]}),s.disabled=c.disabled),typeof c.stacked!="undefined"&&(b.stacked(c.stacked),s.stacked=c.stacked),a.call(w)})}),w}var b=a.models.multiBar(),c=a.models.axis(),d=a.models.axis(),e=a.models.legend(),f=a.models.legend(),g={top:30,right:20,bottom:30,left:60},h=null,i=null,j=a.utils.defaultColor(),k=!0,l=!0,m=!0,n=0,o=!0,p=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" on "+b+"</p>"},q,r,s={stacked:!1},t="No Data Available.",u=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState");b.stacked(!1),c.orient("bottom").tickPadding(7).highlightZero(!1).showMaxMin(!1).tickFormat(function(a){return a}),d.orient("left").tickFormat(d3.format(",.1f"));var v=function(e,f){var g=e.pos[0]+(f.offsetLeft||0),h=e.pos[1]+(f.offsetTop||0),i=c.tickFormat()(b.x()(e.point,e.pointIndex)),j=d.tickFormat()(b.y()(e.point,e.pointIndex)),k=p(e.series.key,i,j,e,w);a.tooltip.show([g,h],k,e.value<0?"n":"s",null,f)};return b.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+g.left,a.pos[1]+g.top],u.tooltipShow(a)}),b.dispatch.on("elementMouseout.tooltip",function(a){u.tooltipHide(a)}),u.on("tooltipHide",function(){o&&a.tooltip.cleanup()}),w.dispatch=u,w.multibar=b,w.legend=e,w.xAxis=c,w.yAxis=d,d3.rebind(w,b,"x","y","xDomain","yDomain","forceX","forceY","clipEdge","id","stacked","delay"),w.margin=function(a){return arguments.length?(g.top=typeof a.top!="undefined"?a.top:g.top,g.right=typeof a.right!="undefined"?a.right:g.right,g.bottom=typeof a.bottom!="undefined"?a.bottom:g.bottom,g.left=typeof a.left!="undefined"?a.left:g.left,w):g},w.width=function(a){return arguments.length?(h=a,w):h},w.height=function(a){return arguments.length?(i=a,w):i},w.color=function(b){return arguments.length?(j=a.utils.getColor(b),e.color(j),w):j},w.showControls=function(a){return arguments.length?(k=a,w):k},w.showLegend=function(a){return arguments.length?(l=a,w):l},w.reduceXTicks=function(a){return arguments.length?(m=a,w):m},w.rotateLabels=function(a){return arguments.length?(n=a,w):n},w.tooltip=function(a){return arguments.length?(p=a,w):p},w.tooltips=function(a){return arguments.length?(o=a,w):o},w.tooltipContent=function(a){return arguments.length?(p=a,w):p},w.state=function(a){return arguments.length?(s=a,w):s},w.noData=function(a){return arguments.length?(t=a,w):t},w},a.models.multiBarHorizontal=function(){function v(a){return a.each(function(a){var e=c-b.left-b.right,p=d-b.top-b.bottom,v=d3.select(this);l&&(a=d3.layout.stack().offset("zero").values(function(a){return a.values}).y(i)(a)),a=a.map(function(a,b){return a.values=a.values.map(function(a){return a.series=b,a}),a});var w=q&&r?[]:a.map(function(a){return a.values.map(function(a,b){return{x:h(a,b),y:i(a,b),y0:a.y0}})});f.domain(q||d3.merge(w).map(function(a){return a.x})).rangeBands([0,p],.1),g.domain(r||d3.extent(d3.merge(w).map(function(a){return a.y+(l?a.y0:0)}).concat(j))),m&&!l?g.range([g.domain()[0]<0?n:0,e-(g.domain()[1]>0?n:0)]):g.range([0,e]),t=t||f,u=u||d3.scale.linear().domain(g.domain()).range([g(0),g(0)]);var z=d3.select(this).selectAll("g.nv-wrap.nv-multibarHorizontal").data([a]),A=z.enter().append("g").attr("class","nvd3 nv-wrap nv-multibarHorizontal"),B=A.append("defs"),C=A.append("g"),D=z.select("g");C.append("g").attr("class","nv-groups"),z.attr("transform","translate("+b.left+","+b.top+")");var E=z.select(".nv-groups").selectAll(".nv-group").data(function(a){return a},function(a){return a.key});E.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(E.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),E.attr("class",function(a,b){return"nv-group nv-series-"+b}).classed("hover",function(a){return a.hover}).style("fill",function(a,b){return k(a,b)}).style("stroke",function(a,b){return k(a,b)}),d3.transition(E).style("stroke-opacity",1).style("fill-opacity",.75);var F=E.selectAll("g.nv-bar").data(function(a){return a.values});F.exit().remove();var G=F.enter().append("g").attr("transform",function(b,c,d){return"translate("+u(l?b.y0:0)+","+(l?0:d*f.rangeBand()/a.length+f(h(b,c)))+")"});G.append("rect").attr("width",0).attr("height",f.rangeBand()/(l?1:a.length)),F.on("mouseover",function(b,c){d3.select(this).classed("hover",!0),s.elementMouseover({value:i(b,c),point:b,series:a[b.series],pos:[g(i(b,c)+(l?b.y0:0)),f(h(b,c))+f.rangeBand()*(l?a.length/2:b.series+.5)/a.length],pointIndex:c,seriesIndex:b.series,e:d3.event})}).on("mouseout",function(b,c){d3.select(this).classed("hover",!1),s.elementMouseout({value:i(b,c),point:b,series:a[b.series],pointIndex:c,seriesIndex:b.series,e:d3.event})}).on("click",function(b,c){s.elementClick({value:i(b,c),point:b,series:a[b.series],pos:[f(h(b,c))+f.rangeBand()*(l?a.length/2:b.series+.5)/a.length,g(i(b,c)+(l?b.y0:0))],pointIndex:c,seriesIndex:b.series,e:d3.event}),d3.event.stopPropagation()}).on("dblclick",function(b,c){s.elementDblClick({value:i(b,c),point:b,series:a[b.series],pos:[f(h(b,c))+f.rangeBand()*(l?a.length/2:b.series+.5)/a.length,g(i(b,c)+(l?b.y0:0))],pointIndex:c,seriesIndex:b.series,e:d3.event}),d3.event.stopPropagation()}),m&&!l?(G.append("text").attr("text-anchor",function(a,b){return i(a,b)<0?"end":"start"}),F.select("text").attr("y",f.rangeBand()/2).attr("dy","-.32em").text(function(a,b){return o(i(a,b))}),d3.transition(F).select("text").attr("x",function(a,b){return i(a,b)<0?-4:g(i(a,b))-g(0)+4})):F.selectAll("text").remove(),F.attr("class",function(a,b){return i(a,b)<0?"nv-bar negative":"nv-bar positive"}),l?d3.transition(F).attr("transform",function(a,b){return"translate("+g(a.y0)+","+f(h(a,b))+")"}).select("rect").attr("width",function(a,b){return Math.abs(g(i(a,b)+a.y0)-g(a.y0))}).attr("height",f.rangeBand()):d3.transition(F).attr("transform",function(b,c){return"translate("+(i(b,c)<0?g(i(b,c)):g(0))+","+(b.series*f.rangeBand()/a.length+f(h(b,c)))+")"}).select("rect").attr("height",f.rangeBand()/a.length).attr("width",function(a,b){return Math.max(Math.abs(g(i(a,b))-g(0)),1)}),t=f.copy(),u=g.copy()}),v}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=Math.floor(Math.random()*1e4),f=d3.scale.ordinal(),g=d3.scale.linear(),h=function(a){return a.x},i=function(a){return a.y},j=[0],k=a.utils.defaultColor(),l=!1,m=!1,n=60,o=d3.format(",.2f"),p=1200,q,r,s=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout"),t,u;return v.dispatch=s,v.x=function(a){return arguments.length?(h=a,v):h},v.y=function(a){return arguments.length?(i=a,v):i},v.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,v):b},v.width=function(a){return arguments.length?(c=a,v):c},v.height=function(a){return arguments.length?(d=a,v):d},v.xScale=function(a){return arguments.length?(f=a,v):f},v.yScale=function(a){return arguments.length?(g=a,v):g},v.xDomain=function(a){return arguments.length?(q=a,v):q},v.yDomain=function(a){return arguments.length?(r=a,v):r},v.forceY=function(a){return arguments.length?(j=a,v):j},v.stacked=function(a){return arguments.length?(l=a,v):l},v.color=function(b){return arguments.length?(k=a.utils.getColor(b),v):k},v.id=function(a){return arguments.length?(e=a,v):e},v.delay=function(a){return arguments.length?(p=a,v):p},v.showValues=function(a){return arguments.length?(m=a,v):m},v.valueFormat=function(a){return arguments.length?(o=a,v):o},v.valuePadding=function(a){return arguments.length?(n=a,v):n},v},a.models.multiBarHorizontalChart=function(){function v(a){return a.each(function(m){var o=d3.select(this),w=this,z=(h||parseInt(o.style("width"))||960)-g.left-g.right,A=(i||parseInt(o.style("height"))||400)-g.top-g.bottom;v.update=function(){a.transition().call(v)},v.container=this;if(!m||!m.length||!m.filter(function(a){return a.values.length}).length){var B=o.selectAll(".nv-noData").data([s]);return B.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),B.attr("x",g.left+z/2).attr("y",g.top+A/2).text(function(a){return a}),v}o.selectAll(".nv-noData").remove(),p=b.xScale(),q=b.yScale();var C=o.selectAll("g.nv-wrap.nv-multiBarHorizontalChart").data([m]),D=C.enter().append("g").attr("class","nvd3 nv-wrap nv-multiBarHorizontalChart").append("g"),E=C.select("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"),l&&(e.width(z/2),E.select(".nv-legendWrap").datum(m).call(e),g.top!=e.height()&&(g.top=e.height(),A=(i||parseInt(o.style("height"))||400)-g.top-g.bottom),E.select(".nv-legendWrap").attr("transform","translate("+z/2+","+ -g.top+")"));if(k){var F=[{key:"Grouped",disabled:b.stacked()},{key:"Stacked",disabled:!b.stacked()}];f.width(180).color(["#444","#444","#444"]),E.select(".nv-controlsWrap").datum(F).attr("transform","translate(0,"+ -g.top+")").call(f)}C.attr("transform","translate("+g.left+","+g.top+")"),b.width(z).height(A).color(m.map(function(a,b){return a.color||j(a,b)}).filter(function(a,b){return!m[b].disabled}));var G=E.select(".nv-barsWrap").datum(m.filter(function(a){return!a.disabled}));d3.transition(G).call(b),c.scale(p).ticks(A/24).tickSize(-z,0),d3.transition(E.select(".nv-x.nv-axis")).call(c);var H=E.select(".nv-x.nv-axis").selectAll("g");H.selectAll("line, text").style("opacity",1),d.scale(q).ticks(z/100).tickSize(-A,0),E.select(".nv-y.nv-axis").attr("transform","translate(0,"+A+")"),d3.transition(E.select(".nv-y.nv-axis")).call(d),e.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,m.filter(function(a){return!a.disabled}).length||m.map(function(a){return a.disabled=!1,C.selectAll(".nv-series").classed("disabled",!1),a}),r.disabled=m.map(function(a){return!!a.disabled}),t.stateChange(r),a.transition().call(v)}),f.dispatch.on("legendClick",function(c,d){if(!c.disabled)return;F=F.map(function(a){return a.disabled=!0,a}),c.disabled=!1;switch(c.key){case"Grouped":b.stacked(!1);break;case"Stacked":b.stacked(!0)}r.stacked=b.stacked(),t.stateChange(r),a.transition().call(v)}),t.on("tooltipShow",function(a){n&&u(a,w.parentNode)}),t.on("changeState",function(c){typeof c.disabled!="undefined"&&(m.forEach(function(a,b){a.disabled=c.disabled[b]}),r.disabled=c.disabled),typeof c.stacked!="undefined"&&(b.stacked(c.stacked),r.stacked=c.stacked),a.call(v)})}),v}var b=a.models.multiBarHorizontal(),c=a.models.axis(),d=a.models.axis(),e=a.models.legend().height(30),f=a.models.legend().height(30),g={top:30,right:20,bottom:50,left:60},h=null,i=null,j=a.utils.defaultColor(),k=!0,l=!0,m=!1,n=!0,o=function(a,b,c,d,e){return"<h3>"+a+" - "+b+"</h3>"+"<p>"+c+"</p>"},p,q,r={stacked:m},s="No Data Available.",t=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState");b.stacked(m),c.orient("left").tickPadding(5).highlightZero(!1).showMaxMin(!1).tickFormat(function(a){return a}),d.orient("bottom").tickFormat(d3.format(",.1f"));var u=function(e,f){var g=e.pos[0]+(f.offsetLeft||0),h=e.pos[1]+(f.offsetTop||0),i=c.tickFormat()(b.x()(e.point,e.pointIndex)),j=d.tickFormat()(b.y()(e.point,e.pointIndex)),k=o(e.series.key,i,j,e,v);a.tooltip.show([g,h],k,e.value<0?"e":"w",null,f)};return b.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+g.left,a.pos[1]+g.top],t.tooltipShow(a)}),b.dispatch.on("elementMouseout.tooltip",function(a){t.tooltipHide(a)}),t.on("tooltipHide",function(){n&&a.tooltip.cleanup()}),v.dispatch=t,v.multibar=b,v.legend=e,v.xAxis=c,v.yAxis=d,d3.rebind(v,b,"x","y","xDomain","yDomain","forceX","forceY","clipEdge","id","delay","showValues","valueFormat","stacked"),v.margin=function(a){return arguments.length?(g.top=typeof a.top!="undefined"?a.top:g.top,g.right=typeof a.right!="undefined"?a.right:g.right,g.bottom=typeof a.bottom!="undefined"?a.bottom:g.bottom,g.left=typeof a.left!="undefined"?a.left:g.left,v):g},v.width=function(a){return arguments.length?(h=a,v):h},v.height=function(a){return arguments.length?(i=a,v):i},v.color=function(b){return arguments.length?(j=a.utils.getColor(b),e.color(j),v):j},v.showControls=function(a){return arguments.length?(k=a,v):k},v.showLegend=function(a){return arguments.length?(l=a,v):l},v.tooltip=function(a){return arguments.length?(o=a,v):o},v.tooltips=function(a){return arguments.length?(n=a,v):n},v.tooltipContent=function(a){return arguments.length?(o=a,v):o},v.state=function(a){return arguments.length?(r=a,v):r},v.noData=function(a){return arguments.length?(s=a,v):s},v},a.models.multiChart=function(){function y(a){return a.each(function(h){var j=d3.select(this),z=this,A=(d||parseInt(j.style("width"))||960)-b.left-b.right,B=(e||parseInt(j.style("height"))||400)-b.top-b.bottom,C=h.filter(function(a){return!a.disabled&&a.type=="line"&&a.yAxis==1}),D=h.filter(function(a){return!a.disabled&&a.type=="line"&&a.yAxis==2}),E=h.filter(function(a){return!a.disabled&&a.type=="bar"&&a.yAxis==1}),F=h.filter(function(a){return!a.disabled&&a.type=="bar"&&a.yAxis==2}),G=h.filter(function(a){return!a.disabled&&a.type=="area"&&a.yAxis==1}),H=h.filter(function(a){return!a.disabled&&a.type=="area"&&a.yAxis==2}),I=h.filter(function(a){return!a.disabled&&a.yAxis==1}).map(function(a){return a.values.map(function(a,b){return{x:a.x,y:a.y}})}),J=h.filter(function(a){return!a.disabled&&a.yAxis==2}).map(function(a){return a.values.map(function(a,b){return{x:a.x,y:a.y}})});i.domain(d3.extent(d3.merge(I.concat(J)),function(a){return a.x})).range([0,A]);var K=j.selectAll("g.wrap.multiChart").data([h]),L=K.enter().append("g").attr("class","wrap nvd3 multiChart").append("g");L.append("g").attr("class","x axis"),L.append("g").attr("class","y1 axis"),L.append("g").attr("class","y2 axis"),L.append("g").attr("class","lines1Wrap"),L.append("g").attr("class","lines2Wrap"),L.append("g").attr("class","bars1Wrap"),L.append("g").attr("class","bars2Wrap"),L.append("g").attr("class","stack1Wrap"),L.append("g").attr("class","stack2Wrap"),L.append("g").attr("class","legendWrap");var M=K.select("g");f&&(v.width(A/2),M.select(".legendWrap").datum(h.map(function(a){return a.originalKey=a.originalKey===undefined?a.key:a.originalKey,a.key=a.originalKey+(a.yAxis==1?"":" (right axis)"),a})).call(v),b.top!=v.height()&&(b.top=v.height(),B=(e||parseInt(j.style("height"))||400)-b.top-b.bottom),M.select(".legendWrap").attr("transform","translate("+A/2+","+ -b.top+")")),m.width(A).height(B).interpolate("monotone").color(h.map(function(a,b){return a.color||c[b%c.length]}).filter(function(a,b){return!h[b].disabled&&h[b].yAxis==1&&h[b].type=="line"})),n.width(A).height(B).interpolate("monotone").color(h.map(function(a,b){return a.color||c[b%c.length]}).filter(function(a,b){return!h[b].disabled&&h[b].yAxis==2&&h[b].type=="line"})),o.width(A).height(B).color(h.map(function(a,b){return a.color||c[b%c.length]}).filter(function(a,b){return!h[b].disabled&&h[b].yAxis==1&&h[b].type=="bar"})),p.width(A).height(B).color(h.map(function(a,b){return a.color||c[b%c.length]}).filter(function(a,b){return!h[b].disabled&&h[b].yAxis==2&&h[b].type=="bar"})),q.width(A).height(B).color(h.map(function(a,b){return a.color||c[b%c.length]}).filter(function(a,b){return!h[b].disabled&&h[b].yAxis==1&&h[b].type=="area"})),r.width(A).height(B).color(h.map(function(a,b){return a.color||c[b%c.length]}).filter(function(a,b){return!h[b].disabled&&h[b].yAxis==2&&h[b].type=="area"})),M.attr("transform","translate("+b.left+","+b.top+")");var N=M.select(".lines1Wrap").datum(C),O=M.select(".bars1Wrap").datum(E),P=M.select(".stack1Wrap").datum(G),Q=M.select(".lines2Wrap").datum(D),R=M.select(".bars2Wrap").datum(F),S=M.select(".stack2Wrap").datum(H),T=G.length?G.map(function(a){return a.values}).reduce(function(a,b){return a.map(function(a,c){return{x:a.x,y:a.y+b[c].y}})}).concat([{x:0,y:0}]):[],U=H.length?H.map(function(a){return a.values}).reduce(function(a,b){return a.map(function(a,c){return{x:a.x,y:a.y+b[c].y}})}).concat([{x:0,y:0}]):[];k.domain(d3.extent(d3.merge(I).concat(T),function(a){return a.y})).range([0,B]),l.domain(d3.extent(d3.merge(J).concat(U),function(a){return a.y})).range([0,B]),m.yDomain(k.domain()),o.yDomain(k.domain()),q.yDomain(k.domain()),n.yDomain(l.domain()),p.yDomain(l.domain()),r.yDomain(l.domain()),G.length&&d3.transition(P).call(q),H.length&&d3.transition(S).call(r),E.length&&d3.transition(O).call(o),F.length&&d3.transition(R).call(p),C.length&&d3.transition(N).call(m),D.length&&d3.transition(Q).call(n),s.ticks(A/100).tickSize(-B,0),M.select(".x.axis").attr("transform","translate(0,"+B+")"),d3.transition(M.select(".x.axis")).call(s),t.ticks(B/36).tickSize(-A,0),d3.transition(M.select(".y1.axis")).call(t),u.ticks(B/36).tickSize(-A,0),d3.transition(M.select(".y2.axis")).call(u),M.select(".y2.axis").style("opacity",J.length?1:0).attr("transform","translate("+i.range()[1]+",0)"),v.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,h.filter(function(a){return!a.disabled}).length||h.map(function(a){return a.disabled=!1,K.selectAll(".series").classed("disabled",!1),a}),a.transition().call(y)}),w.on("tooltipShow",function(a){g&&x(a,z.parentNode)})}),y.update=function(){y(a)},y.container=this,y}var b={top:30,right:20,bottom:50,left:60},c=d3.scale.category20().range(),d=null,e=null,f=!0,g=!0,h=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" at "+b+"</p>"},i,j,i=d3.scale.linear(),k=d3.scale.linear(),l=d3.scale.linear(),m=a.models.line().yScale(k),n=a.models.line().yScale(l),o=a.models.multiBar().stacked(!1).yScale(k),p=a.models.multiBar().stacked(!1).yScale(l),q=a.models.stackedArea().yScale(k),r=a.models.stackedArea().yScale(l),s=a.models.axis().scale(i).orient("bottom").tickPadding(5),t=a.models.axis().scale(k).orient("left"),u=a.models.axis().scale(l).orient("right"),v=a.models.legend().height(30),w=d3.dispatch("tooltipShow","tooltipHide"),x=function(b,c){var d=b.pos[0]+(c.offsetLeft||0),e=b.pos[1]+(c.offsetTop||0),f=s.tickFormat()(m.x()(b.point,b.pointIndex)),g=(b.series.bar?t:u).tickFormat()(m.y()(b.point,b.pointIndex)),i=h(b.series.key,f,g,b,y);a.tooltip.show([d,e],i,undefined,undefined,c.offsetParent)};return m.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],w.tooltipShow(a)}),m.dispatch.on("elementMouseout.tooltip",function(a){w.tooltipHide(a)}),n.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],w.tooltipShow(a)}),n.dispatch.on("elementMouseout.tooltip",function(a){w.tooltipHide(a)}),o.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],w.tooltipShow(a)}),o.dispatch.on("elementMouseout.tooltip",function(a){w.tooltipHide(a)}),p.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],w.tooltipShow(a)}),p.dispatch.on("elementMouseout.tooltip",function(a){w.tooltipHide(a)}),q.dispatch.on("tooltipShow",function(a){if(!Math.round(q.y()(a.point)*100))return setTimeout(function(){d3.selectAll(".point.hover").classed("hover",!1)},0),!1;a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],w.tooltipShow(a)}),q.dispatch.on("tooltipHide",function(a){w.tooltipHide(a)}),r.dispatch.on("tooltipShow",function(a){if(!Math.round(r.y()(a.point)*100))return setTimeout(function(){d3.selectAll(".point.hover").classed("hover",!1)},0),!1;a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],w.tooltipShow(a)}),r.dispatch.on("tooltipHide",function(a){w.tooltipHide(a)}),m.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],w.tooltipShow(a)}),m.dispatch.on("elementMouseout.tooltip",function(a){w.tooltipHide(a)}),n.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],w.tooltipShow(a)}),n.dispatch.on("elementMouseout.tooltip",function(a){w.tooltipHide(a)}),w.on("tooltipHide",function(){g&&a.tooltip.cleanup()}),y.dispatch=w,y.lines1=m,y.lines2=n,y.bars1=o,y.bars2=p,y.stack1=q,y.stack2=r,y.xAxis=s,y.yAxis1=t,y.yAxis2=u,y.x=function(a){return arguments.length?(getX=a,m.x(a),o.x(a),y):getX},y.y=function(a){return arguments.length?(getY=a,m.y(a),o.y(a),y):getY},y.margin=function(a){return arguments.length?(b=a,y):b},y.width=function(a){return arguments.length?(d=a,y):d},y.height=function(a){return arguments.length?(e=a,y):e},y.color=function(a){return arguments.length?(c=a,v.color(a),y):c},y.showLegend=function(a){return arguments.length?(f=a,y):f},y.tooltips=function(a){return arguments.length?(g=a,y):g},y.tooltipContent=function(a){return arguments.length?(h=a,y):h},y},a.models.ohlcBar=function(){function v(a){return a.each(function(a){var r=c-b.left-b.right,v=d-b.top-b.bottom,w=d3.select(this);f.domain(s||d3.extent(a[0].values.map(h).concat(n))),p?f.range([r*.5/a[0].values.length,r*(a[0].values.length-.5)/a[0].values.length]):f.range([0,r]),g.domain(t||[d3.min(a[0].values.map(m).concat(o)),d3.max(a[0].values.map(l).concat(o))]).range([v,0]);if(f.domain()[0]===f.domain()[1]||g.domain()[0]===g.domain()[1])singlePoint=!0;f.domain()[0]===f.domain()[1]&&(f.domain()[0]?f.domain([f.domain()[0]-f.domain()[0]*.01,f.domain()[1]+f.domain()[1]*.01]):f.domain([-1,1])),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]));var z=d3.select(this).selectAll("g.nv-wrap.nv-ohlcBar").data([a[0].values]),A=z.enter().append("g").attr("class","nvd3 nv-wrap nv-ohlcBar"),B=A.append("defs"),C=A.append("g"),D=z.select("g");C.append("g").attr("class","nv-ticks"),z.attr("transform","translate("+b.left+","+b.top+")"),w.on("click",function(a,b){u.chartClick({data:a,index:b,pos:d3.event,id:e})}),B.append("clipPath").attr("id","nv-chart-clip-path-"+e).append("rect"),z.select("#nv-chart-clip-path-"+e+" rect").attr("width",r).attr("height",v),D.attr("clip-path",q?"url(#nv-chart-clip-path-"+e+")":"");var E=z.select(".nv-ticks").selectAll(".nv-tick").data(function(a){return a});E.exit().remove();var F=E.enter().append("path").attr("class",function(a,b,c){return(j(a,b)>k(a,b)?"nv-tick negative":"nv-tick positive")+" nv-tick-"+c+"-"+b}).attr("d",function(b,c){var d=r/a[0].values.length*.9;return"m0,0l0,"+(g(j(b,c))-g(l(b,c)))+"l"+ -d/2+",0l"+d/2+",0l0,"+(g(m(b,c))-g(j(b,c)))+"l0,"+(g(k(b,c))-g(m(b,c)))+"l"+d/2+",0l"+ -d/2+",0z"}).attr("transform",function(a,b){return"translate("+f(h(a,b))+","+g(l(a,b))+")"}).on("mouseover",function(b,c){d3.select(this).classed("hover",!0),u.elementMouseover({point:b,series:a[0],pos:[f(h(b,c)),g(i(b,c))],pointIndex:c,seriesIndex:0,e:d3.event})}).on("mouseout",function(b,c){d3.select(this).classed("hover",!1),u.elementMouseout({point:b,series:a[0],pointIndex:c,seriesIndex:0,e:d3.event})}).on("click",function(a,b){u.elementClick({value:i(a,b),data:a,index:b,pos:[f(h(a,b)),g(i(a,b))],e:d3.event,id:e}),d3.event.stopPropagation()}).on("dblclick",function(a,b){u.elementDblClick({value:i(a,b),data:a,index:b,pos:[f(h(a,b)),g(i(a,b))],e:d3.event,id:e}),d3.event.stopPropagation()});E.attr("class",function(a,b,c){return(j(a,b)>k(a,b)?"nv-tick negative":"nv-tick positive")+" nv-tick-"+c+"-"+b}),d3.transition(E).attr("transform",function(a,b){return"translate("+f(h(a,b))+","+g(l(a,b))+")"}).attr("d",function(b,c){var d=r/a[0].values.length*.9
|
4
|
+
;return"m0,0l0,"+(g(j(b,c))-g(l(b,c)))+"l"+ -d/2+",0l"+d/2+",0l0,"+(g(m(b,c))-g(j(b,c)))+"l0,"+(g(k(b,c))-g(m(b,c)))+"l"+d/2+",0l"+ -d/2+",0z"})}),v}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=Math.floor(Math.random()*1e4),f=d3.scale.linear(),g=d3.scale.linear(),h=function(a){return a.x},i=function(a){return a.y},j=function(a){return a.open},k=function(a){return a.close},l=function(a){return a.high},m=function(a){return a.low},n=[],o=[],p=!1,q=!0,r=a.utils.defaultColor(),s,t,u=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout");return v.dispatch=u,v.x=function(a){return arguments.length?(h=a,v):h},v.y=function(a){return arguments.length?(i=a,v):i},v.open=function(a){return arguments.length?(j=a,v):j},v.close=function(a){return arguments.length?(k=a,v):k},v.high=function(a){return arguments.length?(l=a,v):l},v.low=function(a){return arguments.length?(m=a,v):m},v.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,v):b},v.width=function(a){return arguments.length?(c=a,v):c},v.height=function(a){return arguments.length?(d=a,v):d},v.xScale=function(a){return arguments.length?(f=a,v):f},v.yScale=function(a){return arguments.length?(g=a,v):g},v.xDomain=function(a){return arguments.length?(s=a,v):s},v.yDomain=function(a){return arguments.length?(t=a,v):t},v.forceX=function(a){return arguments.length?(n=a,v):n},v.forceY=function(a){return arguments.length?(o=a,v):o},v.padData=function(a){return arguments.length?(p=a,v):p},v.clipEdge=function(a){return arguments.length?(q=a,v):q},v.color=function(b){return arguments.length?(r=a.utils.getColor(b),v):r},v.id=function(a){return arguments.length?(e=a,v):e},v},a.models.pie=function(){function q(a){return a.each(function(a){function E(a){var b=(a.startAngle+a.endAngle)*90/Math.PI-90;return b>90?b-180:b}function F(a){n||(a.innerRadius=0);var b=d3.interpolate(this._current,a);return this._current=b(0),function(a){return y(b(a))}}function G(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return y(b(a))}}var j=c-b.left-b.right,q=d-b.top-b.bottom,r=Math.min(j,q)/2,s=r-r/5,t=d3.select(this),u=t.selectAll(".nv-wrap.nv-pie").data([e(a[0])]),v=u.enter().append("g").attr("class","nvd3 nv-wrap nv-pie nv-chart-"+h),w=v.append("g"),x=u.select("g");w.append("g").attr("class","nv-pie"),u.attr("transform","translate("+b.left+","+b.top+")"),x.select(".nv-pie").attr("transform","translate("+j/2+","+q/2+")"),t.on("click",function(a,b){p.chartClick({data:a,index:b,pos:d3.event,id:h})});var y=d3.svg.arc().outerRadius(s);n&&y.innerRadius(r/2);var z=d3.layout.pie().sort(null).value(function(a){return a.disabled?0:g(a)}),A=u.select(".nv-pie").selectAll(".nv-slice").data(z);A.exit().remove();var B=A.enter().append("g").attr("class","nv-slice").on("mouseover",function(a,b){d3.select(this).classed("hover",!0),p.elementMouseover({label:f(a.data),value:g(a.data),point:a.data,pointIndex:b,pos:[d3.event.pageX,d3.event.pageY],id:h})}).on("mouseout",function(a,b){d3.select(this).classed("hover",!1),p.elementMouseout({label:f(a.data),value:g(a.data),point:a.data,index:b,id:h})}).on("click",function(a,b){p.elementClick({label:f(a.data),value:g(a.data),point:a.data,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()}).on("dblclick",function(a,b){p.elementDblClick({label:f(a.data),value:g(a.data),point:a.data,index:b,pos:d3.event,id:h}),d3.event.stopPropagation()});A.attr("fill",function(a,b){return i(a,b)}).attr("stroke",function(a,b){return i(a,b)});var C=B.append("path").each(function(a){this._current=a});d3.transition(A.select("path")).attr("d",y).attrTween("d",F);if(k){var D=y;l&&(D=d3.svg.arc().outerRadius(y.outerRadius())),B.append("g").classed("nv-label",!0).each(function(a,b){var c=d3.select(this);c.attr("transform",function(a){if(o){a.outerRadius=s+10,a.innerRadius=s+15;var b=(a.startAngle+a.endAngle)/2*(180/Math.PI);return(a.startAngle+a.endAngle)/2<Math.PI?b-=90:b+=90,"translate("+D.centroid(a)+") rotate("+b+")"}return a.outerRadius=r+10,a.innerRadius=r+15,"translate("+D.centroid(a)+")"}),c.append("rect").style("stroke","#fff").style("fill","#fff").attr("rx",3).attr("ry",3),c.append("text").style("text-anchor",o?(a.startAngle+a.endAngle)/2<Math.PI?"start":"end":"middle").style("fill","#000")}),A.select(".nv-label").transition().attr("transform",function(a){if(o){a.outerRadius=s+10,a.innerRadius=s+15;var b=(a.startAngle+a.endAngle)/2*(180/Math.PI);return(a.startAngle+a.endAngle)/2<Math.PI?b-=90:b+=90,"translate("+D.centroid(a)+") rotate("+b+")"}return a.outerRadius=r+10,a.innerRadius=r+15,"translate("+D.centroid(a)+")"}),A.each(function(a,b){var c=d3.select(this);c.select(".nv-label text").style("text-anchor",o?(a.startAngle+a.endAngle)/2<Math.PI?"start":"end":"middle").text(function(a,b){var c=(a.endAngle-a.startAngle)/(2*Math.PI);return a.value&&c>m?f(a.data):""});var d=c.select("text").node().getBBox();c.select(".nv-label rect").attr("width",d.width+10).attr("height",d.height+10).attr("transform",function(){return"translate("+[d.x-5,d.y-5]+")"})})}}),q}var b={top:0,right:0,bottom:0,left:0},c=500,d=500,e=function(a){return a.values},f=function(a){return a.x},g=function(a){return a.y},h=Math.floor(Math.random()*1e4),i=a.utils.defaultColor(),j=d3.format(",.2f"),k=!0,l=!1,m=.02,n=!1,o=!1,p=d3.dispatch("chartClick","elementClick","elementDblClick","elementMouseover","elementMouseout");return q.dispatch=p,q.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,q):b},q.width=function(a){return arguments.length?(c=a,q):c},q.height=function(a){return arguments.length?(d=a,q):d},q.values=function(a){return arguments.length?(e=a,q):e},q.x=function(a){return arguments.length?(f=a,q):f},q.y=function(a){return arguments.length?(g=d3.functor(a),q):g},q.showLabels=function(a){return arguments.length?(k=a,q):k},q.labelSunbeamLayout=function(a){return arguments.length?(o=a,q):o},q.donutLabelsOutside=function(a){return arguments.length?(l=a,q):l},q.donut=function(a){return arguments.length?(n=a,q):n},q.id=function(a){return arguments.length?(h=a,q):h},q.color=function(b){return arguments.length?(i=a.utils.getColor(b),q):i},q.valueFormat=function(a){return arguments.length?(j=a,q):j},q.labelThreshold=function(a){return arguments.length?(m=a,q):m},q},a.models.pieChart=function(){function o(a){return a.each(function(h){var i=d3.select(this),j=this,n=(e||parseInt(i.style("width"))||960)-d.left-d.right,p=(f||parseInt(i.style("height"))||400)-d.top-d.bottom;o.update=function(){o(a)},o.container=this;if(!h||!h.length){var q=i.selectAll(".nv-noData").data([l]);return q.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),q.attr("x",d.left+n/2).attr("y",d.top+p/2).text(function(a){return a}),o}i.selectAll(".nv-noData").remove();var r=i.selectAll("g.nv-wrap.nv-pieChart").data([h]),s=r.enter().append("g").attr("class","nvd3 nv-wrap nv-pieChart").append("g"),t=r.select("g");s.append("g").attr("class","nv-pieWrap"),s.append("g").attr("class","nv-legendWrap"),g&&(c.width(n).key(b.x()),r.select(".nv-legendWrap").datum(b.values()(h[0])).call(c),d.top!=c.height()&&(d.top=c.height(),p=(f||parseInt(i.style("height"))||400)-d.top-d.bottom),r.select(".nv-legendWrap").attr("transform","translate(0,"+ -d.top+")")),r.attr("transform","translate("+d.left+","+d.top+")"),b.width(n).height(p);var u=t.select(".nv-pieWrap").datum(h);d3.transition(u).call(b),c.dispatch.on("legendClick",function(c,d,e){c.disabled=!c.disabled,b.values()(h[0]).filter(function(a){return!a.disabled}).length||b.values()(h[0]).map(function(a){return a.disabled=!1,r.selectAll(".nv-series").classed("disabled",!1),a}),k.disabled=h[0].map(function(a){return!!a.disabled}),m.stateChange(k),a.transition().call(o)}),b.dispatch.on("elementMouseout.tooltip",function(a){m.tooltipHide(a)}),m.on("changeState",function(b){typeof b.disabled!="undefined"&&(h[0].forEach(function(a,c){a.disabled=b.disabled[c]}),k.disabled=b.disabled),a.call(o)})}),o}var b=a.models.pie(),c=a.models.legend(),d={top:30,right:20,bottom:20,left:20},e=null,f=null,g=!0,h=a.utils.defaultColor(),i=!0,j=function(a,b,c,d){return"<h3>"+a+"</h3>"+"<p>"+b+"</p>"},k={},l="No Data Available.",m=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),n=function(c,d){var e=c.pos[0]+(d&&d.offsetLeft||0),f=c.pos[1]+(d&&d.offsetTop||0),g=b.valueFormat()(b.y()(c.point)),h=j(b.x()(c.point),g,c,o);a.tooltip.show([e,f],h,c.value<0?"n":"s",null,d)};return b.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+d.left,a.pos[1]+d.top],m.tooltipShow(a)}),m.on("tooltipShow",function(a){i&&n(a)}),m.on("tooltipHide",function(){i&&a.tooltip.cleanup()}),o.legend=c,o.dispatch=m,o.pie=b,d3.rebind(o,b,"valueFormat","values","x","y","id","showLabels","donutLabelsOutside","donut","labelThreshold"),o.margin=function(a){return arguments.length?(d.top=typeof a.top!="undefined"?a.top:d.top,d.right=typeof a.right!="undefined"?a.right:d.right,d.bottom=typeof a.bottom!="undefined"?a.bottom:d.bottom,d.left=typeof a.left!="undefined"?a.left:d.left,o):d},o.width=function(a){return arguments.length?(e=a,o):e},o.height=function(a){return arguments.length?(f=a,o):f},o.color=function(d){return arguments.length?(h=a.utils.getColor(d),c.color(h),b.color(h),o):h},o.showLegend=function(a){return arguments.length?(g=a,o):g},o.tooltips=function(a){return arguments.length?(i=a,o):i},o.tooltipContent=function(a){return arguments.length?(j=a,o):j},o.state=function(a){return arguments.length?(k=a,o):k},o.noData=function(a){return arguments.length?(l=a,o):l},o},a.models.scatter=function(){function J(a){return a.each(function(a){function S(){if(!r)return!1;var e,i=d3.merge(a.map(function(a,b){return a.values.map(function(a,c){return[g(j(a,c))*(Math.random()/1e12+1),h(k(a,c))*(Math.random()/1e12+1),b,c,a]}).filter(function(a,b){return s(a[4],b)})}));if(D===!0){if(v){var l=N.select("defs").selectAll(".nv-point-clips").data([f]).enter();l.append("clipPath").attr("class","nv-point-clips").attr("id","nv-points-clip-"+f);var m=N.select("#nv-points-clip-"+f).selectAll("circle").data(i);m.enter().append("circle").attr("r",w),m.exit().remove(),m.attr("cx",function(a){return a[0]}).attr("cy",function(a){return a[1]}),N.select(".nv-point-paths").attr("clip-path","url(#nv-points-clip-"+f+")")}i.push([g.range()[0]-20,h.range()[0]-20,null,null]),i.push([g.range()[1]+20,h.range()[1]+20,null,null]),i.push([g.range()[0]-20,h.range()[0]+20,null,null]),i.push([g.range()[1]+20,h.range()[1]-20,null,null]);var n=d3.geom.polygon([[-10,-10],[-10,d+10],[c+10,d+10],[c+10,-10]]),o=d3.geom.voronoi(i).map(function(a,b){return{data:n.clip(a),series:i[b][2],point:i[b][3]}}),p=N.select(".nv-point-paths").selectAll("path").data(o);p.enter().append("path").attr("class",function(a,b){return"nv-path-"+b}),p.exit().remove(),p.attr("d",function(a){return"M"+a.data.join("L")+"Z"}),p.on("click",function(c){if(I)return 0;var d=a[c.series],e=d.values[c.point];C.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){if(I)return 0;var d=a[c.series],e=d.values[c.point];C.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){if(I)return 0;var d=a[b.series],e=d.values[b.point];C.elementMouseout({point:e,series:d,seriesIndex:b.series,pointIndex:b.point})})}else N.select(".nv-groups").selectAll(".nv-group").selectAll(".nv-point").on("click",function(c,d){if(I)return 0;var e=a[c.series],f=e.values[d];C.elementClick({point:f,series:e,pos:[g(j(f,d))+b.left,h(k(f,d))+b.top],seriesIndex:c.series,pointIndex:d})}).on("mouseover",function(c,d){if(I)return 0;var e=a[c.series],f=e.values[d];C.elementMouseover({point:f,series:e,pos:[g(j(f,d))+b.left,h(k(f,d))+b.top],seriesIndex:c.series,pointIndex:d})}).on("mouseout",function(b,c){if(I)return 0;var d=a[b.series],e=d.values[c];C.elementMouseout({point:e,series:d,seriesIndex:b.series,pointIndex:c})});I=!1}var J=c-b.left-b.right,K=d-b.top-b.bottom,L=d3.select(this);a=a.map(function(a,b){return a.values=a.values.map(function(a){return a.series=b,a}),a});var M=x&&y&&z?[]: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(x||d3.extent(M.map(function(a){return a.x}).concat(o))),t?g.range([J*.5/a[0].values.length,J*(a[0].values.length-.5)/a[0].values.length]):g.range([0,J]),h.domain(y||d3.extent(M.map(function(a){return a.y}).concat(p))).range([K,0]),i.domain(z||d3.extent(M.map(function(a){return a.size}).concat(q))).range(A||[16,256]);if(g.domain()[0]===g.domain()[1]||h.domain()[0]===h.domain()[1])B=!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])),E=E||g,F=F||h,G=G||i;var N=L.selectAll("g.nv-wrap.nv-scatter").data([a]),O=N.enter().append("g").attr("class","nvd3 nv-wrap nv-scatter nv-chart-"+f+(B?" nv-single-point":"")),P=O.append("defs"),Q=O.append("g"),R=N.select("g");Q.append("g").attr("class","nv-groups"),Q.append("g").attr("class","nv-point-paths"),N.attr("transform","translate("+b.left+","+b.top+")"),P.append("clipPath").attr("id","nv-edge-clip-"+f).append("rect"),N.select("#nv-edge-clip-"+f+" rect").attr("width",J).attr("height",K),R.attr("clip-path",u?"url(#nv-edge-clip-"+f+")":""),I=!0;var T=N.select(".nv-groups").selectAll(".nv-group").data(function(a){return a},function(a){return a.key});T.enter().append("g").style("stroke-opacity",1e-6).style("fill-opacity",1e-6),d3.transition(T.exit()).style("stroke-opacity",1e-6).style("fill-opacity",1e-6).remove(),T.attr("class",function(a,b){return"nv-group nv-series-"+b}).classed("hover",function(a){return a.hover}),d3.transition(T).style("fill",function(a,b){return e(a,b)}).style("stroke",function(a,b){return e(a,b)}).style("stroke-opacity",1).style("fill-opacity",.5);if(n){var U=T.selectAll("circle.nv-point").data(function(a){return a.values});U.enter().append("circle").attr("cx",function(a,b){return E(j(a,b))}).attr("cy",function(a,b){return F(k(a,b))}).attr("r",function(a,b){return Math.sqrt(i(l(a,b))/Math.PI)}),U.exit().remove(),d3.transition(T.exit().selectAll("path.nv-point")).attr("cx",function(a,b){return g(j(a,b))}).attr("cy",function(a,b){return h(k(a,b))}).remove(),U.attr("class",function(a,b){return"nv-point nv-point-"+b}),d3.transition(U).attr("cx",function(a,b){return g(j(a,b))}).attr("cy",function(a,b){return h(k(a,b))}).attr("r",function(a,b){return Math.sqrt(i(l(a,b))/Math.PI)})}else{var U=T.selectAll("path.nv-point").data(function(a){return a.values});U.enter().append("path").attr("transform",function(a,b){return"translate("+E(j(a,b))+","+F(k(a,b))+")"}).attr("d",d3.svg.symbol().type(m).size(function(a,b){return i(l(a,b))})),U.exit().remove(),d3.transition(T.exit().selectAll("path.nv-point")).attr("transform",function(a,b){return"translate("+g(j(a,b))+","+h(k(a,b))+")"}).remove(),U.attr("class",function(a,b){return"nv-point nv-point-"+b}),d3.transition(U).attr("transform",function(a,b){return"translate("+g(j(a,b))+","+h(k(a,b))+")"}).attr("d",d3.svg.symbol().type(m).size(function(a,b){return i(l(a,b))}))}clearTimeout(H),H=setTimeout(S,300),E=g.copy(),F=h.copy(),G=i.copy()}),J}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=a.utils.defaultColor(),f=Math.floor(Math.random()*1e5),g=d3.scale.linear(),h=d3.scale.linear(),i=d3.scale.linear(),j=function(a){return a.x},k=function(a){return a.y},l=function(a){return a.size||1},m=function(a){return a.shape||"circle"},n=!0,o=[],p=[],q=[],r=!0,s=function(a){return!a.notActive},t=!1,u=!1,v=!0,w=function(){return 25},x=null,y=null,z=null,A=null,B=!1,C=d3.dispatch("elementClick","elementMouseover","elementMouseout"),D=!0,E,F,G,H,I=!1;return C.on("elementMouseover.point",function(a){r&&d3.select(".nv-chart-"+f+" .nv-series-"+a.seriesIndex+" .nv-point-"+a.pointIndex).classed("hover",!0)}),C.on("elementMouseout.point",function(a){r&&d3.select(".nv-chart-"+f+" .nv-series-"+a.seriesIndex+" .nv-point-"+a.pointIndex).classed("hover",!1)}),J.dispatch=C,J.x=function(a){return arguments.length?(j=d3.functor(a),J):j},J.y=function(a){return arguments.length?(k=d3.functor(a),J):k},J.size=function(a){return arguments.length?(l=d3.functor(a),J):l},J.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,J):b},J.width=function(a){return arguments.length?(c=a,J):c},J.height=function(a){return arguments.length?(d=a,J):d},J.xScale=function(a){return arguments.length?(g=a,J):g},J.yScale=function(a){return arguments.length?(h=a,J):h},J.zScale=function(a){return arguments.length?(i=a,J):i},J.xDomain=function(a){return arguments.length?(x=a,J):x},J.yDomain=function(a){return arguments.length?(y=a,J):y},J.sizeDomain=function(a){return arguments.length?(z=a,J):z},J.sizeRange=function(a){return arguments.length?(A=a,J):A},J.forceX=function(a){return arguments.length?(o=a,J):o},J.forceY=function(a){return arguments.length?(p=a,J):p},J.forceSize=function(a){return arguments.length?(q=a,J):q},J.interactive=function(a){return arguments.length?(r=a,J):r},J.pointActive=function(a){return arguments.length?(s=a,J):s},J.padData=function(a){return arguments.length?(t=a,J):t},J.clipEdge=function(a){return arguments.length?(u=a,J):u},J.clipVoronoi=function(a){return arguments.length?(v=a,J):v},J.useVoronoi=function(a){return arguments.length?(D=a,D===!1&&(v=!1),J):D},J.clipRadius=function(a){return arguments.length?(w=a,J):w},J.color=function(b){return arguments.length?(e=a.utils.getColor(b),J):e},J.shape=function(a){return arguments.length?(m=a,J):m},J.onlyCircles=function(a){return arguments.length?(n=a,J):n},J.id=function(a){return arguments.length?(f=a,J):f},J.singlePoint=function(a){return arguments.length?(B=a,J):B},J},a.models.scatterChart=function(){function H(a){return a.each(function(x){function R(){if(v)return O.select(".nv-point-paths").style("pointer-events","all"),!1;O.select(".nv-point-paths").style("pointer-events","none");var a=d3.mouse(this);m.distortion(u).focus(a[0]),n.distortion(u).focus(a[1]),O.select(".nv-scatterWrap").call(b),O.select(".nv-x.nv-axis").call(c),O.select(".nv-y.nv-axis").call(d),O.select(".nv-distributionX").datum(x.filter(function(a){return!a.disabled})).call(g),O.select(".nv-distributionY").datum(x.filter(function(a){return!a.disabled})).call(h)}var y=d3.select(this),z=this,I=(j||parseInt(y.style("width"))||960)-i.left-i.right,J=(k||parseInt(y.style("height"))||400)-i.top-i.bottom;H.update=function(){H(a)},H.container=this;if(!x||!x.length||!x.filter(function(a){return a.values.length}).length){var K=y.selectAll(".nv-noData").data([B]);return K.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),K.attr("x",i.left+I/2).attr("y",i.top+J/2).text(function(a){return a}),H}y.selectAll(".nv-noData").remove(),D=D||m,E=E||n;var L=y.selectAll("g.nv-wrap.nv-scatterChart").data([x]),M=L.enter().append("g").attr("class","nvd3 nv-wrap nv-scatterChart nv-chart-"+b.id()),N=M.append("g"),O=L.select("g");N.append("rect").attr("class","nvd3 nv-background"),N.append("g").attr("class","nv-x nv-axis"),N.append("g").attr("class","nv-y nv-axis"),N.append("g").attr("class","nv-scatterWrap"),N.append("g").attr("class","nv-distWrap"),N.append("g").attr("class","nv-legendWrap"),N.append("g").attr("class","nv-controlsWrap"),s&&(e.width(I/2),L.select(".nv-legendWrap").datum(x).call(e),i.top!=e.height()&&(i.top=e.height(),J=(k||parseInt(y.style("height"))||400)-i.top-i.bottom),L.select(".nv-legendWrap").attr("transform","translate("+I/2+","+ -i.top+")")),t&&(f.width(180).color(["#444"]),O.select(".nv-controlsWrap").datum(G).attr("transform","translate(0,"+ -i.top+")").call(f)),L.attr("transform","translate("+i.left+","+i.top+")"),b.width(I).height(J).color(x.map(function(a,b){return a.color||l(a,b)}).filter(function(a,b){return!x[b].disabled})),L.select(".nv-scatterWrap").datum(x.filter(function(a){return!a.disabled})).call(b);if(o){var P=m.domain()[1]-m.domain()[0];m.domain([m.domain()[0]-o*P,m.domain()[1]+o*P])}if(p){var Q=n.domain()[1]-n.domain()[0];n.domain([n.domain()[0]-p*Q,n.domain()[1]+p*Q])}c.scale(m).ticks(c.ticks()&&c.ticks().length?c.ticks():I/100).tickSize(-J,0),O.select(".nv-x.nv-axis").attr("transform","translate(0,"+n.range()[0]+")").call(c),d.scale(n).ticks(d.ticks()&&d.ticks().length?d.ticks():J/36).tickSize(-I,0),O.select(".nv-y.nv-axis").call(d),q&&(g.getData(b.x()).scale(m).width(I).color(x.map(function(a,b){return a.color||l(a,b)}).filter(function(a,b){return!x[b].disabled})),N.select(".nv-distWrap").append("g").attr("class","nv-distributionX"),O.select(".nv-distributionX").attr("transform","translate(0,"+n.range()[0]+")").datum(x.filter(function(a){return!a.disabled})).call(g)),r&&(h.getData(b.y()).scale(n).width(J).color(x.map(function(a,b){return a.color||l(a,b)}).filter(function(a,b){return!x[b].disabled})),N.select(".nv-distWrap").append("g").attr("class","nv-distributionY"),O.select(".nv-distributionY").attr("transform","translate(-"+h.size()+",0)").datum(x.filter(function(a){return!a.disabled})).call(h)),d3.fisheye&&(O.select(".nv-background").attr("width",I).attr("height",J),O.select(".nv-background").on("mousemove",R),O.select(".nv-background").on("click",function(){v=!v}),b.dispatch.on("elementClick.freezeFisheye",function(){v=!v})),f.dispatch.on("legendClick",function(e,f){e.disabled=!e.disabled,u=e.disabled?0:2.5,O.select(".nv-background").style("pointer-events",e.disabled?"none":"all"),O.select(".nv-point-paths").style("pointer-events",e.disabled?"all":"none"),e.disabled?(m.distortion(u).focus(0),n.distortion(u).focus(0),O.select(".nv-scatterWrap").call(b),O.select(".nv-x.nv-axis").call(c),O.select(".nv-y.nv-axis").call(d)):v=!1,H(a)}),e.dispatch.on("legendClick",function(b,c,d){b.disabled=!b.disabled,x.filter(function(a){return!a.disabled}).length||x.map(function(a){return a.disabled=!1,L.selectAll(".nv-series").classed("disabled",!1),a}),C.disabled=x.map(function(a){return!!a.disabled}),A.stateChange(C),H(a)}),b.dispatch.on("elementMouseover.tooltip",function(a){d3.select(".nv-chart-"+b.id()+" .nv-series-"+a.seriesIndex+" .nv-distx-"+a.pointIndex).attr("y1",a.pos[1]-J),d3.select(".nv-chart-"+b.id()+" .nv-series-"+a.seriesIndex+" .nv-disty-"+a.pointIndex).attr("x2",a.pos[0]+g.size()),a.pos=[a.pos[0]+i.left,a.pos[1]+i.top],A.tooltipShow(a)}),A.on("tooltipShow",function(a){w&&F(a,z.parentNode)}),A.on("changeState",function(b){typeof b.disabled!="undefined"&&(x.forEach(function(a,c){a.disabled=b.disabled[c]}),C.disabled=b.disabled),a.call(H)}),D=m.copy(),E=n.copy()}),H}var b=a.models.scatter(),c=a.models.axis(),d=a.models.axis(),e=a.models.legend(),f=a.models.legend(),g=a.models.distribution(),h=a.models.distribution(),i={top:30,right:20,bottom:50,left:75},j=null,k=null,l=a.utils.defaultColor(),m=d3.fisheye?d3.fisheye.scale(d3.scale.linear).distortion(0):b.xScale(),n=d3.fisheye?d3.fisheye.scale(d3.scale.linear).distortion(0):b.yScale(),o=0,p=0,q=!1,r=!1,s=!0,t=!!d3.fisheye,u=0,v=!1,w=!0,x=function(a,b,c){return"<strong>"+b+"</strong>"},y=function(a,b,c){return"<strong>"+c+"</strong>"},z=null,A=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),B="No Data Available.";b.xScale(m).yScale(n),c.orient("bottom").tickPadding(10),d.orient("left").tickPadding(10),g.axis("x"),h.axis("y");var C={},D,E,F=function(e,f){var g=e.pos[0]+(f.offsetLeft||0),h=e.pos[1]+(f.offsetTop||0),j=e.pos[0]+(f.offsetLeft||0),k=n.range()[0]+i.top+(f.offsetTop||0),l=m.range()[0]+i.left+(f.offsetLeft||0),o=e.pos[1]+(f.offsetTop||0),p=c.tickFormat()(b.x()(e.point,e.pointIndex)),q=d.tickFormat()(b.y()(e.point,e.pointIndex));x!=null&&a.tooltip.show([j,k],x(e.series.key,p,q,e,H),"n",1,f,"x-nvtooltip"),y!=null&&a.tooltip.show([l,o],y(e.series.key,p,q,e,H),"e",1,f,"y-nvtooltip"),z!=null&&a.tooltip.show([g,h],z(e.series.key,p,q,e,H),e.value<0?"n":"s",null,f)},G=[{key:"Magnify",disabled:!0}];return b.dispatch.on("elementMouseout.tooltip",function(a){A.tooltipHide(a),d3.select(".nv-chart-"+b.id()+" .nv-series-"+a.seriesIndex+" .nv-distx-"+a.pointIndex).attr("y1",0),d3.select(".nv-chart-"+b.id()+" .nv-series-"+a.seriesIndex+" .nv-disty-"+a.pointIndex).attr("x2",h.size())}),A.on("tooltipHide",function(){w&&a.tooltip.cleanup()}),H.dispatch=A,H.scatter=b,H.legend=e,H.controls=f,H.xAxis=c,H.yAxis=d,H.distX=g,H.distY=h,d3.rebind(H,b,"id","interactive","pointActive","x","y","shape","size","xScale","yScale","zScale","xDomain","yDomain","sizeDomain","sizeRange","forceX","forceY","forceSize","clipVoronoi","clipRadius","useVoronoi"),H.margin=function(a){return arguments.length?(i.top=typeof a.top!="undefined"?a.top:i.top,i.right=typeof a.right!="undefined"?a.right:i.right,i.bottom=typeof a.bottom!="undefined"?a.bottom:i.bottom,i.left=typeof a.left!="undefined"?a.left:i.left,H):i},H.width=function(a){return arguments.length?(j=a,H):j},H.height=function(a){return arguments.length?(k=a,H):k},H.color=function(b){return arguments.length?(l=a.utils.getColor(b),e.color(l),g.color(l),h.color(l),H):l},H.showDistX=function(a){return arguments.length?(q=a,H):q},H.showDistY=function(a){return arguments.length?(r=a,H):r},H.showControls=function(a){return arguments.length?(t=a,H):t},H.showLegend=function(a){return arguments.length?(s=a,H):s},H.fisheye=function(a){return arguments.length?(u=a,H):u},H.xPadding=function(a){return arguments.length?(o=a,H):o},H.yPadding=function(a){return arguments.length?(p=a,H):p},H.tooltips=function(a){return arguments.length?(w=a,H):w},H.tooltipContent=function(a){return arguments.length?(z=a,H):z},H.tooltipXContent=function(a){return arguments.length?(x=a,H):x},H.tooltipYContent=function(a){return arguments.length?(y=a,H):y},H.state=function(a){return arguments.length?(C=a,H):C},H.noData=function(a){return arguments.length?(B=a,H):B},H},a.models.scatterPlusLineChart=function(){function F(a){return a.each(function(v){function P(){if(t)return M.select(".nv-point-paths").style("pointer-events","all"),!1;M.select(".nv-point-paths").style("pointer-events","none");var a=d3.mouse(this);m.distortion(s).focus(a[0]),n.distortion(s).focus(a[1]),M.select(".nv-scatterWrap").datum(v.filter(function(a){return!a.disabled})).call(b),M.select(".nv-x.nv-axis").call(c),M.select(".nv-y.nv-axis").call(d),M.select(".nv-distributionX").datum(v.filter(function(a){return!a.disabled})).call(g),M.select(".nv-distributionY").datum(v.filter(function(a){return!a.disabled})).call(h)}var w=d3.select(this),x=this,G=(j||parseInt(w.style("width"))||960)-i.left-i.right,H=(k||parseInt(w.style("height"))||400)-i.top-i.bottom;F.update=function(){F(a)},F.container=this;if(!v||!v.length||!v.filter(function(a){return a.values.length}).length){var I=w.selectAll(".nv-noData").data([z]);return I.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),I.attr("x",i.left+G/2).attr("y",i.top+H/2).text(function(a){return a}),F}w.selectAll(".nv-noData").remove(),m=b.xScale(),n=b.yScale(),B=B||m,C=C||n;var J=w.selectAll("g.nv-wrap.nv-scatterChart").data([v]),K=J.enter().append("g").attr("class","nvd3 nv-wrap nv-scatterChart nv-chart-"+b.id()),L=K.append("g"),M=J.select("g");L.append("rect").attr("class","nvd3 nv-background"),L.append("g").attr("class","nv-x nv-axis"),L.append("g").attr("class","nv-y nv-axis"),L.append("g").attr("class","nv-scatterWrap"),L.append("g").attr("class","nv-regressionLinesWrap"),L.append("g").attr("class","nv-distWrap"),L.append("g").attr("class","nv-legendWrap"),L.append("g").attr("class","nv-controlsWrap"),J.attr("transform","translate("+i.left+","+i.top+")"),q&&(e.width(G/2),J.select(".nv-legendWrap").datum(v).call(e),i.top!=e.height()&&(i.top=e.height(),H=(k||parseInt(w.style("height"))||400)-i.top-i.bottom),J.select(".nv-legendWrap").attr("transform","translate("+G/2+","+ -i.top+")")),r&&(f.width(180).color(["#444"]),M.select(".nv-controlsWrap").datum(E).attr("transform","translate(0,"+ -i.top+")").call(f)),b.width(G).height(H).color(v.map(function(a,b){return a.color||l(a,b)}).filter(function(a,b){return!v[b].disabled})),J.select(".nv-scatterWrap").datum(v.filter(function(a){return!a.disabled})).call(b),J.select(".nv-regressionLinesWrap").attr("clip-path","url(#nv-edge-clip-"+b.id()+")");var N=J.select(".nv-regressionLinesWrap").selectAll(".nv-regLines").data(function(a){return a}),O=N.enter().append("g").attr("class","nv-regLines").append("line").attr("class","nv-regLine").style("stroke-opacity",0);N.selectAll(".nv-regLines line").attr("x1",m.range()[0]).attr("x2",m.range()[1]).attr("y1",function(a,b){return n(m.domain()[0]*a.slope+a.intercept)}).attr("y2",function(a,b){return n(m.domain()[1]*a.slope+a.intercept)}).style("stroke",function(a,b,c){return l(a,c)}).style("stroke-opacity",function(a,b){return a.disabled||typeof a.slope=="undefined"||typeof a.intercept=="undefined"?0:1}),c.scale(m).ticks(c.ticks()?c.ticks():G/100).tickSize(-H,0),M.select(".nv-x.nv-axis").attr("transform","translate(0,"+n.range()[0]+")").call(c),d.scale(n).ticks(d.ticks()?d.ticks():H/36).tickSize(-G,0),M.select(".nv-y.nv-axis").call(d),o&&(g.getData(b.x()).scale(m).width(G).color(v.map(function(a,b){return a.color||l(a,b)}).filter(function(a,b){return!v[b].disabled})),L.select(".nv-distWrap").append("g").attr("class","nv-distributionX"),M.select(".nv-distributionX").attr("transform","translate(0,"+n.range()[0]+")").datum(v.filter(function(a){return!a.disabled})).call(g)),p&&(h.getData(b.y()).scale(n).width(H).color(v.map(function(a,b){return a.color||l(a,b)}).filter(function(a,b){return!v[b].disabled})),L.select(".nv-distWrap").append("g").attr("class","nv-distributionY"),M.select(".nv-distributionY").attr("transform","translate(-"+h.size()+",0)").datum(v.filter(function(a){return!a.disabled})).call(h)),d3.fisheye&&(M.select(".nv-background").attr("width",G).attr("height",H),M.select(".nv-background").on("mousemove",P),M.select(".nv-background").on("click",function(){t=!t}),b.dispatch.on("elementClick.freezeFisheye",function(){t=!t})),f.dispatch.on("legendClick",function(e,f){e.disabled=!e.disabled,s=e.disabled?0:2.5,M.select(".nv-background").style("pointer-events",e.disabled?"none":"all"),M.select(".nv-point-paths").style("pointer-events",e.disabled?"all":"none"),e.disabled?(m.distortion(s).focus(0),n.distortion(s).focus(0),M.select(".nv-scatterWrap").call(b),M.select(".nv-x.nv-axis").call(c),M.select(".nv-y.nv-axis").call(d)):t=!1,F(a)}),e.dispatch.on("legendClick",function(b,c,d){b.disabled=!b.disabled,v.filter(function(a){return!a.disabled}).length||v.map(function(a){return a.disabled=!1,J.selectAll(".nv-series").classed("disabled",!1),a}),A.disabled=v.map(function(a){return!!a.disabled}),y.stateChange(A),F(a)}),b.dispatch.on("elementMouseover.tooltip",function(a){d3.select(".nv-chart-"+b.id()+" .nv-series-"+a.seriesIndex+" .nv-distx-"+a.pointIndex).attr("y1",a.pos[1]-H),d3.select(".nv-chart-"+b.id()+" .nv-series-"+a.seriesIndex+" .nv-disty-"+a.pointIndex).attr("x2",a.pos[0]+g.size()),a.pos=[a.pos[0]+i.left,a.pos[1]+i.top],y.tooltipShow(a)}),y.on("tooltipShow",function(a){u&&D(a,x.parentNode)}),y.on("changeState",function(b){typeof b.disabled!="undefined"&&(v.forEach(function(a,c){a.disabled=b.disabled[c]}),A.disabled=b.disabled),a.call(F)}),B=m.copy(),C=n.copy()}),F}var b=a.models.scatter(),c=a.models.axis(),d=a.models.axis(),e=a.models.legend(),f=a.models.legend(),g=a.models.distribution(),h=a.models.distribution(),i={top:30,right:20,bottom:50,left:75},j=null,k=null,l=a.utils.defaultColor(),m=d3.fisheye?d3.fisheye.scale(d3.scale.linear).distortion(0):b.xScale(),n=d3.fisheye?d3.fisheye.scale(d3.scale.linear).distortion(0):b.yScale(),o=!1,p=!1,q=!0,r=!!d3.fisheye,s=0,t=!1,u=!0,v=function(a,b,c){return"<strong>"+b+"</strong>"},w=function(a,b,c){return"<strong>"+c+"</strong>"},x=function(a,b,c,d){return"<h3>"+a+"</h3>"+"<p>"+d+"</p>"},y=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),z="No Data Available.";b.xScale(m).yScale(n),c.orient("bottom").tickPadding(10),d.orient("left").tickPadding(10),g.axis("x"),h.axis("y"
|
5
|
+
);var A={},B,C,D=function(e,f){var g=e.pos[0]+(f.offsetLeft||0),h=e.pos[1]+(f.offsetTop||0),j=e.pos[0]+(f.offsetLeft||0),k=n.range()[0]+i.top+(f.offsetTop||0),l=m.range()[0]+i.left+(f.offsetLeft||0),o=e.pos[1]+(f.offsetTop||0),p=c.tickFormat()(b.x()(e.point,e.pointIndex)),q=d.tickFormat()(b.y()(e.point,e.pointIndex));v!=null&&a.tooltip.show([j,k],v(e.series.key,p,q,e,F),"n",1,f,"x-nvtooltip"),w!=null&&a.tooltip.show([l,o],w(e.series.key,p,q,e,F),"e",1,f,"y-nvtooltip"),x!=null&&a.tooltip.show([g,h],x(e.series.key,p,q,e.point.tooltip,e,F),e.value<0?"n":"s",null,f)},E=[{key:"Magnify",disabled:!0}];return b.dispatch.on("elementMouseout.tooltip",function(a){y.tooltipHide(a),d3.select(".nv-chart-"+b.id()+" .nv-series-"+a.seriesIndex+" .nv-distx-"+a.pointIndex).attr("y1",0),d3.select(".nv-chart-"+b.id()+" .nv-series-"+a.seriesIndex+" .nv-disty-"+a.pointIndex).attr("x2",h.size())}),y.on("tooltipHide",function(){u&&a.tooltip.cleanup()}),F.dispatch=y,F.scatter=b,F.legend=e,F.controls=f,F.xAxis=c,F.yAxis=d,F.distX=g,F.distY=h,d3.rebind(F,b,"id","interactive","pointActive","x","y","shape","size","xScale","yScale","zScale","xDomain","yDomain","sizeDomain","sizeRange","forceX","forceY","forceSize","clipVoronoi","clipRadius","useVoronoi"),F.margin=function(a){return arguments.length?(i.top=typeof a.top!="undefined"?a.top:i.top,i.right=typeof a.right!="undefined"?a.right:i.right,i.bottom=typeof a.bottom!="undefined"?a.bottom:i.bottom,i.left=typeof a.left!="undefined"?a.left:i.left,F):i},F.width=function(a){return arguments.length?(j=a,F):j},F.height=function(a){return arguments.length?(k=a,F):k},F.color=function(b){return arguments.length?(l=a.utils.getColor(b),e.color(l),g.color(l),h.color(l),F):l},F.showDistX=function(a){return arguments.length?(o=a,F):o},F.showDistY=function(a){return arguments.length?(p=a,F):p},F.showControls=function(a){return arguments.length?(r=a,F):r},F.showLegend=function(a){return arguments.length?(q=a,F):q},F.fisheye=function(a){return arguments.length?(s=a,F):s},F.tooltips=function(a){return arguments.length?(u=a,F):u},F.tooltipContent=function(a){return arguments.length?(x=a,F):x},F.tooltipXContent=function(a){return arguments.length?(v=a,F):v},F.tooltipYContent=function(a){return arguments.length?(w=a,F):w},F.state=function(a){return arguments.length?(A=a,F):A},F.noData=function(a){return arguments.length?(z=a,F):z},F},a.models.sparkline=function(){function m(a){return a.each(function(a){var e=c-b.left-b.right,m=d-b.top-b.bottom,n=d3.select(this);f.domain(k||d3.extent(a,h)).range([0,e]),g.domain(l||d3.extent(a,i)).range([m,0]);var o=n.selectAll("g.nv-wrap.nv-sparkline").data([a]),p=o.enter().append("g").attr("class","nvd3 nv-wrap nv-sparkline"),q=p.append("g"),r=o.select("g");o.attr("transform","translate("+b.left+","+b.top+")");var s=o.selectAll("path").data(function(a){return[a]});s.enter().append("path"),s.exit().remove(),s.style("stroke",function(a,b){return a.color||j(a,b)}).attr("d",d3.svg.line().x(function(a,b){return f(h(a,b))}).y(function(a,b){return g(i(a,b))}));var t=o.selectAll("circle.nv-point").data(function(a){function c(b){if(b!=-1){var c=a[b];return c.pointIndex=b,c}return null}var b=a.map(function(a,b){return i(a,b)}),d=c(b.lastIndexOf(g.domain()[1])),e=c(b.indexOf(g.domain()[0])),f=c(b.length-1);return[e,d,f].filter(function(a){return a!=null})});t.enter().append("circle"),t.exit().remove(),t.attr("cx",function(a,b){return f(h(a,a.pointIndex))}).attr("cy",function(a,b){return g(i(a,a.pointIndex))}).attr("r",2).attr("class",function(a,b){return h(a,a.pointIndex)==f.domain()[1]?"nv-point nv-currentValue":i(a,a.pointIndex)==g.domain()[0]?"nv-point nv-minValue":"nv-point nv-maxValue"})}),m}var b={top:2,right:0,bottom:2,left:0},c=400,d=32,e=!0,f=d3.scale.linear(),g=d3.scale.linear(),h=function(a){return a.x},i=function(a){return a.y},j=a.utils.getColor(["#000"]),k,l;return m.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,m):b},m.width=function(a){return arguments.length?(c=a,m):c},m.height=function(a){return arguments.length?(d=a,m):d},m.x=function(a){return arguments.length?(h=d3.functor(a),m):h},m.y=function(a){return arguments.length?(i=d3.functor(a),m):i},m.xScale=function(a){return arguments.length?(f=a,m):f},m.yScale=function(a){return arguments.length?(g=a,m):g},m.xDomain=function(a){return arguments.length?(k=a,m):k},m.yDomain=function(a){return arguments.length?(l=a,m):l},m.animate=function(a){return arguments.length?(e=a,m):e},m.color=function(b){return arguments.length?(j=a.utils.getColor(b),m):j},m},a.models.sparklinePlus=function(){function p(a){return a.each(function(l){function E(){if(i)return;var a=A.selectAll(".nv-hoverValue").data(h),d=a.enter().append("g").attr("class","nv-hoverValue").style("stroke-opacity",0).style("fill-opacity",0);a.exit().transition().duration(250).style("stroke-opacity",0).style("fill-opacity",0).remove(),a.attr("transform",function(a){return"translate("+f(b.x()(l[a],a))+",0)"}).transition().duration(250).style("stroke-opacity",1).style("fill-opacity",1);if(!h.length)return;d.append("line").attr("x1",0).attr("y1",-c.top).attr("x2",0).attr("y2",s),d.append("text").attr("class","nv-xValue").attr("x",-6).attr("y",-c.top).attr("text-anchor","end").attr("dy",".9em"),A.select(".nv-hoverValue .nv-xValue").text(j(b.x()(l[h[0]],h[0]))),d.append("text").attr("class","nv-yValue").attr("x",6).attr("y",-c.top).attr("text-anchor","start").attr("dy",".9em"),A.select(".nv-hoverValue .nv-yValue").text(k(b.y()(l[h[0]],h[0])))}function F(){function d(a,c){var d=Math.abs(b.x()(a[0],0)-c),e=0;for(var f=0;f<a.length;f++)Math.abs(b.x()(a[f],f)-c)<d&&(d=Math.abs(b.x()(a[f],f)-c),e=f);return e}if(i)return;var a=d3.mouse(this)[0]-c.left;h=[d(l,Math.round(f.invert(a)))],E()}var q=d3.select(this),r=(d||parseInt(q.style("width"))||960)-c.left-c.right,s=(e||parseInt(q.style("height"))||400)-c.top-c.bottom,t=b.y()(l[l.length-1],l.length-1);p.update=function(){p(a)},p.container=this;if(!l||!l.length){var u=q.selectAll(".nv-noData").data([o]);return u.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),u.attr("x",c.left+r/2).attr("y",c.top+s/2).text(function(a){return a}),p}q.selectAll(".nv-noData").remove(),f=b.xScale(),g=b.yScale();var v=q.selectAll("g.nv-wrap.nv-sparklineplus").data([l]),w=v.enter().append("g").attr("class","nvd3 nv-wrap nv-sparklineplus"),z=w.append("g"),A=v.select("g");z.append("g").attr("class","nv-sparklineWrap"),z.append("g").attr("class","nv-valueWrap"),z.append("g").attr("class","nv-hoverArea"),v.attr("transform","translate("+c.left+","+c.top+")");var B=A.select(".nv-sparklineWrap");b.width(r).height(s),B.call(b);var C=A.select(".nv-valueWrap"),D=C.selectAll(".nv-currentValue").data([t]);D.enter().append("text").attr("class","nv-currentValue").attr("dx",n?-8:8).attr("dy",".9em").style("text-anchor",n?"end":"start"),D.attr("x",r+(n?c.right:0)).attr("y",m?function(a){return g(a)}:0).style("fill",b.color()(l[l.length-1],l.length-1)).text(k(t)),z.select(".nv-hoverArea").append("rect").on("mousemove",F).on("click",function(){i=!i}).on("mouseout",function(){h=[],E()}),A.select(".nv-hoverArea rect").attr("transform",function(a){return"translate("+ -c.left+","+ -c.top+")"}).attr("width",r+c.left+c.right).attr("height",s+c.top)}),p}var b=a.models.sparkline(),c={top:15,right:100,bottom:10,left:50},d=null,e=null,f,g,h=[],i=!1,j=d3.format(",r"),k=d3.format(",.2f"),l=!0,m=!0,n=!1,o="No Data Available.";return p.sparkline=b,d3.rebind(p,b,"x","y","xScale","yScale","color"),p.margin=function(a){return arguments.length?(c.top=typeof a.top!="undefined"?a.top:c.top,c.right=typeof a.right!="undefined"?a.right:c.right,c.bottom=typeof a.bottom!="undefined"?a.bottom:c.bottom,c.left=typeof a.left!="undefined"?a.left:c.left,p):c},p.width=function(a){return arguments.length?(d=a,p):d},p.height=function(a){return arguments.length?(e=a,p):e},p.xTickFormat=function(a){return arguments.length?(j=a,p):j},p.yTickFormat=function(a){return arguments.length?(k=a,p):k},p.showValue=function(a){return arguments.length?(l=a,p):l},p.alignValue=function(a){return arguments.length?(m=a,p):m},p.rightAlignValue=function(a){return arguments.length?(n=a,p):n},p.noData=function(a){return arguments.length?(o=a,p):o},p},a.models.stackedArea=function(){function r(a){return a.each(function(a){var i=c-b.left-b.right,r=d-b.top-b.bottom,s=d3.select(this);n=p.xScale(),o=p.yScale(),a=a.map(function(a,b){return a.values=a.values.map(function(b,c){return b.index=c,b.stackedY=a.disabled?0:h(b,c),b}),a}),a=d3.layout.stack().order(k).offset(j).values(function(a){return a.values}).x(g).y(function(a){return a.stackedY}).out(function(a,b,c){a.display={y:c,y0:b}})(a);var t=s.selectAll("g.nv-wrap.nv-stackedarea").data([a]),u=t.enter().append("g").attr("class","nvd3 nv-wrap nv-stackedarea"),v=u.append("defs"),w=u.append("g"),z=t.select("g");w.append("g").attr("class","nv-areaWrap"),w.append("g").attr("class","nv-scatterWrap"),t.attr("transform","translate("+b.left+","+b.top+")"),p.width(i).height(r).x(g).y(function(a){return a.display.y+a.display.y0}).forceY([0]).color(a.map(function(a,b){return a.color||e(a,b)}).filter(function(b,c){return!a[c].disabled}));var A=z.select(".nv-scatterWrap").datum(a.filter(function(a){return!a.disabled}));A.call(p),v.append("clipPath").attr("id","nv-edge-clip-"+f).append("rect"),t.select("#nv-edge-clip-"+f+" rect").attr("width",i).attr("height",r),z.attr("clip-path",m?"url(#nv-edge-clip-"+f+")":"");var B=d3.svg.area().x(function(a,b){return n(g(a,b))}).y0(function(a){return o(a.display.y0)}).y1(function(a){return o(a.display.y+a.display.y0)}).interpolate(l),C=d3.svg.area().x(function(a,b){return n(g(a,b))}).y0(function(a){return o(a.display.y0)}).y1(function(a){return o(a.display.y0)}),D=z.select(".nv-areaWrap").selectAll("path.nv-area").data(function(a){return a});D.enter().append("path").attr("class",function(a,b){return"nv-area nv-area-"+b}).on("mouseover",function(a,b){d3.select(this).classed("hover",!0),q.areaMouseover({point:a,series:a.key,pos:[d3.event.pageX,d3.event.pageY],seriesIndex:b})}).on("mouseout",function(a,b){d3.select(this).classed("hover",!1),q.areaMouseout({point:a,series:a.key,pos:[d3.event.pageX,d3.event.pageY],seriesIndex:b})}).on("click",function(a,b){d3.select(this).classed("hover",!1),q.areaClick({point:a,series:a.key,pos:[d3.event.pageX,d3.event.pageY],seriesIndex:b})}),D.exit().attr("d",function(a,b){return C(a.values,b)}).remove(),D.style("fill",function(a,b){return a.color||e(a,b)}).style("stroke",function(a,b){return a.color||e(a,b)}),D.attr("d",function(a,b){return B(a.values,b)}),p.dispatch.on("elementMouseover.area",function(a){z.select(".nv-chart-"+f+" .nv-area-"+a.seriesIndex).classed("hover",!0)}),p.dispatch.on("elementMouseout.area",function(a){z.select(".nv-chart-"+f+" .nv-area-"+a.seriesIndex).classed("hover",!1)})}),r}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=a.utils.defaultColor(),f=Math.floor(Math.random()*1e5),g=function(a){return a.x},h=function(a){return a.y},i="stack",j="zero",k="default",l="linear",m=!1,n,o,p=a.models.scatter(),q=d3.dispatch("tooltipShow","tooltipHide","areaClick","areaMouseover","areaMouseout");return p.size(2.2).sizeDomain([2.2]),p.dispatch.on("elementClick.area",function(a){q.areaClick(a)}),p.dispatch.on("elementMouseover.tooltip",function(a){a.pos=[a.pos[0]+b.left,a.pos[1]+b.top],q.tooltipShow(a)}),p.dispatch.on("elementMouseout.tooltip",function(a){q.tooltipHide(a)}),r.dispatch=q,r.scatter=p,d3.rebind(r,p,"interactive","size","xScale","yScale","zScale","xDomain","yDomain","sizeDomain","forceX","forceY","forceSize","clipVoronoi","clipRadius"),r.x=function(a){return arguments.length?(g=d3.functor(a),r):g},r.y=function(a){return arguments.length?(h=d3.functor(a),r):h},r.margin=function(a){return arguments.length?(b.top=typeof a.top!="undefined"?a.top:b.top,b.right=typeof a.right!="undefined"?a.right:b.right,b.bottom=typeof a.bottom!="undefined"?a.bottom:b.bottom,b.left=typeof a.left!="undefined"?a.left:b.left,r):b},r.width=function(a){return arguments.length?(c=a,r):c},r.height=function(a){return arguments.length?(d=a,r):d},r.clipEdge=function(a){return arguments.length?(m=a,r):m},r.color=function(b){return arguments.length?(e=a.utils.getColor(b),r):e},r.offset=function(a){return arguments.length?(j=a,r):j},r.order=function(a){return arguments.length?(k=a,r):k},r.style=function(a){if(!arguments.length)return i;i=a;switch(i){case"stack":r.offset("zero"),r.order("default");break;case"stream":r.offset("wiggle"),r.order("inside-out");break;case"stream-center":r.offset("silhouette"),r.order("inside-out");break;case"expand":r.offset("expand"),r.order("default")}return r},r.interpolate=function(a){return arguments.length?(l=a,l):l},r},a.models.stackedAreaChart=function(){function w(a){return a.each(function(j){var n=d3.select(this),z=this,A=(h||parseInt(n.style("width"))||960)-g.left-g.right,B=(i||parseInt(n.style("height"))||400)-g.top-g.bottom;w.update=function(){w(a)},w.container=this;if(!j||!j.length||!j.filter(function(a){return a.values.length}).length){var C=n.selectAll(".nv-noData").data([s]);return C.enter().append("text").attr("class","nvd3 nv-noData").attr("dy","-.7em").style("text-anchor","middle"),C.attr("x",g.left+A/2).attr("y",g.top+B/2).text(function(a){return a}),w}n.selectAll(".nv-noData").remove(),o=b.xScale(),p=b.yScale();var D=n.selectAll("g.nv-wrap.nv-stackedAreaChart").data([j]),E=D.enter().append("g").attr("class","nvd3 nv-wrap nv-stackedAreaChart").append("g"),F=D.select("g");E.append("g").attr("class","nv-x nv-axis"),E.append("g").attr("class","nv-y nv-axis"),E.append("g").attr("class","nv-stackedWrap"),E.append("g").attr("class","nv-legendWrap"),E.append("g").attr("class","nv-controlsWrap"),l&&(e.width(A-u),F.select(".nv-legendWrap").datum(j).call(e),g.top!=e.height()&&(g.top=e.height(),B=(i||parseInt(n.style("height"))||400)-g.top-g.bottom),F.select(".nv-legendWrap").attr("transform","translate("+u+","+ -g.top+")"));if(k){var G=[{key:"Stacked",disabled:b.offset()!="zero"},{key:"Stream",disabled:b.offset()!="wiggle"},{key:"Expanded",disabled:b.offset()!="expand"}];f.width(u).color(["#444","#444","#444"]),F.select(".nv-controlsWrap").datum(G).call(f),g.top!=Math.max(f.height(),e.height())&&(g.top=Math.max(f.height(),e.height()),B=(i||parseInt(n.style("height"))||400)-g.top-g.bottom),F.select(".nv-controlsWrap").attr("transform","translate(0,"+ -g.top+")")}D.attr("transform","translate("+g.left+","+g.top+")"),b.width(A).height(B);var H=F.select(".nv-stackedWrap").datum(j);H.call(b),c.scale(o).ticks(A/100).tickSize(-B,0),F.select(".nv-x.nv-axis").attr("transform","translate(0,"+B+")"),F.select(".nv-x.nv-axis").transition().duration(0).call(c),d.scale(p).ticks(b.offset()=="wiggle"?0:B/36).tickSize(-A,0).setTickFormat(b.offset()=="expand"?d3.format("%"):q),F.select(".nv-y.nv-axis").transition().duration(0).call(d),b.dispatch.on("areaClick.toggle",function(b){j.filter(function(a){return!a.disabled}).length===1?j=j.map(function(a){return a.disabled=!1,a}):j=j.map(function(a,c){return a.disabled=c!=b.seriesIndex,a}),w(a)}),e.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}),r.disabled=j.map(function(a){return!!a.disabled}),t.stateChange(r),w(a)}),f.dispatch.on("legendClick",function(c,d){if(!c.disabled)return;G=G.map(function(a){return a.disabled=!0,a}),c.disabled=!1;switch(c.key){case"Stacked":b.style("stack");break;case"Stream":b.style("stream");break;case"Expanded":b.style("expand")}r.style=b.style(),t.stateChange(r),w(a)}),t.on("tooltipShow",function(a){m&&v(a,z.parentNode)}),t.on("changeState",function(c){typeof c.disabled!="undefined"&&(j.forEach(function(a,b){a.disabled=c.disabled[b]}),r.disabled=c.disabled),typeof c.style!="undefined"&&b.style(c.style),a.call(w)})}),w}var b=a.models.stackedArea(),c=a.models.axis(),d=a.models.axis(),e=a.models.legend(),f=a.models.legend(),g={top:30,right:25,bottom:50,left:60},h=null,i=null,j=a.utils.defaultColor(),k=!0,l=!0,m=!0,n=function(a,b,c,d,e){return"<h3>"+a+"</h3>"+"<p>"+c+" on "+b+"</p>"},o,p,q=d3.format(",.2f"),r={style:b.style()},s="No Data Available.",t=d3.dispatch("tooltipShow","tooltipHide","stateChange","changeState"),u=250;c.orient("bottom").tickPadding(7),d.orient("left"),b.scatter.pointActive(function(a){return!!Math.round(b.y()(a)*100)});var v=function(e,f){var g=e.pos[0]+(f.offsetLeft||0),h=e.pos[1]+(f.offsetTop||0),i=c.tickFormat()(b.x()(e.point,e.pointIndex)),j=d.tickFormat()(b.y()(e.point,e.pointIndex)),k=n(e.series.key,i,j,e,w);a.tooltip.show([g,h],k,e.value<0?"n":"s",null,f)};return b.dispatch.on("tooltipShow",function(a){a.pos=[a.pos[0]+g.left,a.pos[1]+g.top],t.tooltipShow(a)}),b.dispatch.on("tooltipHide",function(a){t.tooltipHide(a)}),t.on("tooltipHide",function(){m&&a.tooltip.cleanup()}),w.dispatch=t,w.stacked=b,w.legend=e,w.controls=f,w.xAxis=c,w.yAxis=d,d3.rebind(w,b,"x","y","size","xScale","yScale","xDomain","yDomain","sizeDomain","interactive","offset","order","style","clipEdge","forceX","forceY","forceSize","interpolate"),w.margin=function(a){return arguments.length?(g.top=typeof a.top!="undefined"?a.top:g.top,g.right=typeof a.right!="undefined"?a.right:g.right,g.bottom=typeof a.bottom!="undefined"?a.bottom:g.bottom,g.left=typeof a.left!="undefined"?a.left:g.left,w):g},w.width=function(a){return arguments.length?(h=a,w):getWidth},w.height=function(a){return arguments.length?(i=a,w):getHeight},w.color=function(c){return arguments.length?(j=a.utils.getColor(c),e.color(j),b.color(j),w):j},w.showControls=function(a){return arguments.length?(k=a,w):k},w.showLegend=function(a){return arguments.length?(l=a,w):l},w.tooltip=function(a){return arguments.length?(n=a,w):n},w.tooltips=function(a){return arguments.length?(m=a,w):m},w.tooltipContent=function(a){return arguments.length?(n=a,w):n},w.state=function(a){return arguments.length?(r=a,w):r},w.noData=function(a){return arguments.length?(s=a,w):s},d.setTickFormat=d.tickFormat,d.tickFormat=function(a){return arguments.length?(q=a,d):q},w}})();
|
data/lib/redmon/redis.rb
CHANGED
data/lib/redmon/version.rb
CHANGED
data/lib/redmon/views/app.haml
CHANGED
@@ -6,12 +6,14 @@
|
|
6
6
|
%script(type="text/javascript" src="vendor/jquery-1.7.1.min.js")
|
7
7
|
%script(type="text/javascript" src="vendor/jquery-effects-core.min.js")
|
8
8
|
%script(type="text/javascript" src="vendor/jquery.editinplace.js")
|
9
|
-
%script(type="text/javascript" src="vendor/jquery.flot.js")
|
10
9
|
%script(type="text/javascript" src="vendor/bootstrap-modal.js")
|
10
|
+
%script(type="text/javascript" src="vendor/d3.v3.min.js")
|
11
|
+
%script(type="text/javascript" src="vendor/nv.d3.min.js")
|
11
12
|
%script(type="text/javascript" src="vendor/terminal.js")
|
12
13
|
%script(type="text/javascript" src="redmon.js")
|
13
14
|
|
14
15
|
%link(type="text/css" rel="stylesheet" href="vendor/bootstrap.min.css")
|
16
|
+
%link(type="text/css" rel="stylesheet" href="vendor/nv.d3.css")
|
15
17
|
%link(type="text/css" rel="stylesheet" href="redmon.css")
|
16
18
|
|
17
19
|
%body
|
@@ -44,13 +46,17 @@
|
|
44
46
|
.widget
|
45
47
|
.headbar
|
46
48
|
%h2 Memory Usage
|
47
|
-
#memory-container.chart
|
49
|
+
#memory-container.chart-container
|
50
|
+
#memory-chart.chart
|
51
|
+
%svg
|
48
52
|
.row
|
49
53
|
.span15
|
50
54
|
.widget
|
51
55
|
.headbar
|
52
56
|
%h2 Keyspace
|
53
|
-
#keyspace-container.chart
|
57
|
+
#keyspace-container.chart-container
|
58
|
+
#keyspace-chart.chart
|
59
|
+
%svg
|
54
60
|
.row
|
55
61
|
.span15
|
56
62
|
.widget
|
data/redmon.gemspec
CHANGED
data/spec/app_spec.rb
CHANGED
@@ -36,7 +36,13 @@ describe "app" do
|
|
36
36
|
|
37
37
|
it "should execute the passed command" do
|
38
38
|
stub_redis_cmd :keys, '*'
|
39
|
-
get
|
39
|
+
get "/cli?command=#{command}"
|
40
|
+
last_response.should be_ok
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should execute a passed command with quoted values" do
|
44
|
+
stub_redis_cmd :set, 'key', 'quoted value'
|
45
|
+
get URI.encode('/cli?command=set key "quoted value"')
|
40
46
|
last_response.should be_ok
|
41
47
|
end
|
42
48
|
|
data/spec/config_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe "Redmon" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "Config" do
|
15
|
-
subject {Redmon::Config.new}
|
15
|
+
subject { Redmon::Config.new }
|
16
16
|
describe "#initialize" do
|
17
17
|
it "should apply the defaults" do
|
18
18
|
Redmon::Config::DEFAULTS.each do |k,v|
|
@@ -26,9 +26,9 @@ describe "Config" do
|
|
26
26
|
subject.app.should be_true
|
27
27
|
subject.worker.should be_true
|
28
28
|
|
29
|
-
subject.apply app
|
29
|
+
subject.apply :app => false, :worker => false
|
30
30
|
subject.app.should be_false
|
31
31
|
subject.worker.should be_false
|
32
32
|
end
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redmon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bson_ext
|
@@ -251,22 +251,6 @@ dependencies:
|
|
251
251
|
- - ~>
|
252
252
|
- !ruby/object:Gem::Version
|
253
253
|
version: 2.8.0
|
254
|
-
- !ruby/object:Gem::Dependency
|
255
|
-
name: shoulda
|
256
|
-
requirement: !ruby/object:Gem::Requirement
|
257
|
-
none: false
|
258
|
-
requirements:
|
259
|
-
- - ! '>='
|
260
|
-
- !ruby/object:Gem::Version
|
261
|
-
version: '0'
|
262
|
-
type: :development
|
263
|
-
prerelease: false
|
264
|
-
version_requirements: !ruby/object:Gem::Requirement
|
265
|
-
none: false
|
266
|
-
requirements:
|
267
|
-
- - ! '>='
|
268
|
-
- !ruby/object:Gem::Version
|
269
|
-
version: '0'
|
270
254
|
description: Redis Admin interface and monitor.
|
271
255
|
email:
|
272
256
|
- sean.mcdaniel@me.com
|
@@ -290,10 +274,12 @@ files:
|
|
290
274
|
- lib/redmon/public/redmon.js
|
291
275
|
- lib/redmon/public/vendor/bootstrap-modal.js
|
292
276
|
- lib/redmon/public/vendor/bootstrap.min.css
|
277
|
+
- lib/redmon/public/vendor/d3.v3.min.js
|
293
278
|
- lib/redmon/public/vendor/jquery-1.7.1.min.js
|
294
279
|
- lib/redmon/public/vendor/jquery-effects-core.min.js
|
295
280
|
- lib/redmon/public/vendor/jquery.editinplace.js
|
296
|
-
- lib/redmon/public/vendor/
|
281
|
+
- lib/redmon/public/vendor/nv.d3.css
|
282
|
+
- lib/redmon/public/vendor/nv.d3.min.js
|
297
283
|
- lib/redmon/public/vendor/terminal.js
|
298
284
|
- lib/redmon/redis.rb
|
299
285
|
- lib/redmon/version.rb
|
@@ -321,7 +307,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
321
307
|
version: '0'
|
322
308
|
segments:
|
323
309
|
- 0
|
324
|
-
hash:
|
310
|
+
hash: 1243816364635606113
|
325
311
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
326
312
|
none: false
|
327
313
|
requirements:
|
@@ -330,10 +316,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
330
316
|
version: '0'
|
331
317
|
segments:
|
332
318
|
- 0
|
333
|
-
hash:
|
319
|
+
hash: 1243816364635606113
|
334
320
|
requirements: []
|
335
321
|
rubyforge_project: redmon
|
336
|
-
rubygems_version: 1.8.
|
322
|
+
rubygems_version: 1.8.23
|
337
323
|
signing_key:
|
338
324
|
specification_version: 3
|
339
325
|
summary: Redis monitor
|
@@ -1,2651 +0,0 @@
|
|
1
|
-
/*! Javascript plotting library for jQuery, v. 0.7.
|
2
|
-
*
|
3
|
-
* Released under the MIT license by IOLA, December 2007.
|
4
|
-
*
|
5
|
-
*/
|
6
|
-
|
7
|
-
// first an inline dependency, jquery.colorhelpers.js, we inline it here
|
8
|
-
// for convenience
|
9
|
-
|
10
|
-
/* Plugin for jQuery for working with colors.
|
11
|
-
*
|
12
|
-
* Version 1.1.
|
13
|
-
*
|
14
|
-
* Inspiration from jQuery color animation plugin by John Resig.
|
15
|
-
*
|
16
|
-
* Released under the MIT license by Ole Laursen, October 2009.
|
17
|
-
*
|
18
|
-
* Examples:
|
19
|
-
*
|
20
|
-
* $.color.parse("#fff").scale('rgb', 0.25).add('a', -0.5).toString()
|
21
|
-
* var c = $.color.extract($("#mydiv"), 'background-color');
|
22
|
-
* console.log(c.r, c.g, c.b, c.a);
|
23
|
-
* $.color.make(100, 50, 25, 0.4).toString() // returns "rgba(100,50,25,0.4)"
|
24
|
-
*
|
25
|
-
* Note that .scale() and .add() return the same modified object
|
26
|
-
* instead of making a new one.
|
27
|
-
*
|
28
|
-
* V. 1.1: Fix error handling so e.g. parsing an empty string does
|
29
|
-
* produce a color rather than just crashing.
|
30
|
-
*/
|
31
|
-
(function(B){B.color={};B.color.make=function(F,E,C,D){var G={};G.r=F||0;G.g=E||0;G.b=C||0;G.a=D!=null?D:1;G.add=function(J,I){for(var H=0;H<J.length;++H){G[J.charAt(H)]+=I}return G.normalize()};G.scale=function(J,I){for(var H=0;H<J.length;++H){G[J.charAt(H)]*=I}return G.normalize()};G.toString=function(){if(G.a>=1){return"rgb("+[G.r,G.g,G.b].join(",")+")"}else{return"rgba("+[G.r,G.g,G.b,G.a].join(",")+")"}};G.normalize=function(){function H(J,K,I){return K<J?J:(K>I?I:K)}G.r=H(0,parseInt(G.r),255);G.g=H(0,parseInt(G.g),255);G.b=H(0,parseInt(G.b),255);G.a=H(0,G.a,1);return G};G.clone=function(){return B.color.make(G.r,G.b,G.g,G.a)};return G.normalize()};B.color.extract=function(D,C){var E;do{E=D.css(C).toLowerCase();if(E!=""&&E!="transparent"){break}D=D.parent()}while(!B.nodeName(D.get(0),"body"));if(E=="rgba(0, 0, 0, 0)"){E="transparent"}return B.color.parse(E)};B.color.parse=function(F){var E,C=B.color.make;if(E=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(F)){return C(parseInt(E[1],10),parseInt(E[2],10),parseInt(E[3],10))}if(E=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(F)){return C(parseInt(E[1],10),parseInt(E[2],10),parseInt(E[3],10),parseFloat(E[4]))}if(E=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(F)){return C(parseFloat(E[1])*2.55,parseFloat(E[2])*2.55,parseFloat(E[3])*2.55)}if(E=/rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(F)){return C(parseFloat(E[1])*2.55,parseFloat(E[2])*2.55,parseFloat(E[3])*2.55,parseFloat(E[4]))}if(E=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(F)){return C(parseInt(E[1],16),parseInt(E[2],16),parseInt(E[3],16))}if(E=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(F)){return C(parseInt(E[1]+E[1],16),parseInt(E[2]+E[2],16),parseInt(E[3]+E[3],16))}var D=B.trim(F).toLowerCase();if(D=="transparent"){return C(255,255,255,0)}else{E=A[D]||[0,0,0];return C(E[0],E[1],E[2])}};var A={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery);
|
32
|
-
|
33
|
-
// the actual Flot code
|
34
|
-
(function($) {
|
35
|
-
function Plot(placeholder, data_, options_, plugins) {
|
36
|
-
// data is on the form:
|
37
|
-
// [ series1, series2 ... ]
|
38
|
-
// where series is either just the data as [ [x1, y1], [x2, y2], ... ]
|
39
|
-
// or { data: [ [x1, y1], [x2, y2], ... ], label: "some label", ... }
|
40
|
-
|
41
|
-
var series = [],
|
42
|
-
options = {
|
43
|
-
// the color theme used for graphs
|
44
|
-
colors: ["#edc240", "#afd8f8", "#cb4b4b", "#4da74d", "#9440ed"],
|
45
|
-
legend: {
|
46
|
-
show: true,
|
47
|
-
noColumns: 1, // number of colums in legend table
|
48
|
-
labelFormatter: null, // fn: string -> string
|
49
|
-
labelBoxBorderColor: "#ccc", // border color for the little label boxes
|
50
|
-
container: null, // container (as jQuery object) to put legend in, null means default on top of graph
|
51
|
-
position: "ne", // position of default legend container within plot
|
52
|
-
margin: 5, // distance from grid edge to default legend container within plot
|
53
|
-
backgroundColor: null, // null means auto-detect
|
54
|
-
backgroundOpacity: 0.85 // set to 0 to avoid background
|
55
|
-
},
|
56
|
-
xaxis: {
|
57
|
-
show: null, // null = auto-detect, true = always, false = never
|
58
|
-
position: "bottom", // or "top"
|
59
|
-
mode: null, // null or "time"
|
60
|
-
font: null, // null (derived from CSS in placeholder) or object like { size: 11, style: "italic", weight: "bold", family: "sans-serif", variant: "small-caps" }
|
61
|
-
color: null, // base color, labels, ticks
|
62
|
-
tickColor: null, // possibly different color of ticks, e.g. "rgba(0,0,0,0.15)"
|
63
|
-
transform: null, // null or f: number -> number to transform axis
|
64
|
-
inverseTransform: null, // if transform is set, this should be the inverse function
|
65
|
-
min: null, // min. value to show, null means set automatically
|
66
|
-
max: null, // max. value to show, null means set automatically
|
67
|
-
autoscaleMargin: null, // margin in % to add if auto-setting min/max
|
68
|
-
ticks: null, // either [1, 3] or [[1, "a"], 3] or (fn: axis info -> ticks) or app. number of ticks for auto-ticks
|
69
|
-
tickFormatter: null, // fn: number -> string
|
70
|
-
labelWidth: null, // size of tick labels in pixels
|
71
|
-
labelHeight: null,
|
72
|
-
reserveSpace: null, // whether to reserve space even if axis isn't shown
|
73
|
-
tickLength: null, // size in pixels of ticks, or "full" for whole line
|
74
|
-
alignTicksWithAxis: null, // axis number or null for no sync
|
75
|
-
|
76
|
-
// mode specific options
|
77
|
-
tickDecimals: null, // no. of decimals, null means auto
|
78
|
-
tickSize: null, // number or [number, "unit"]
|
79
|
-
minTickSize: null, // number or [number, "unit"]
|
80
|
-
monthNames: null, // list of names of months
|
81
|
-
timeformat: null, // format string to use
|
82
|
-
twelveHourClock: false // 12 or 24 time in time mode
|
83
|
-
},
|
84
|
-
yaxis: {
|
85
|
-
autoscaleMargin: 0.02,
|
86
|
-
position: "left" // or "right"
|
87
|
-
},
|
88
|
-
xaxes: [],
|
89
|
-
yaxes: [],
|
90
|
-
series: {
|
91
|
-
points: {
|
92
|
-
show: false,
|
93
|
-
radius: 3,
|
94
|
-
lineWidth: 2, // in pixels
|
95
|
-
fill: true,
|
96
|
-
fillColor: "#ffffff",
|
97
|
-
symbol: "circle" // or callback
|
98
|
-
},
|
99
|
-
lines: {
|
100
|
-
// we don't put in show: false so we can see
|
101
|
-
// whether lines were actively disabled
|
102
|
-
lineWidth: 2, // in pixels
|
103
|
-
fill: false,
|
104
|
-
fillColor: null,
|
105
|
-
steps: false
|
106
|
-
},
|
107
|
-
bars: {
|
108
|
-
show: false,
|
109
|
-
lineWidth: 2, // in pixels
|
110
|
-
barWidth: 1, // in units of the x axis
|
111
|
-
fill: true,
|
112
|
-
fillColor: null,
|
113
|
-
align: "left", // or "center"
|
114
|
-
horizontal: false
|
115
|
-
},
|
116
|
-
shadowSize: 3
|
117
|
-
},
|
118
|
-
grid: {
|
119
|
-
show: true,
|
120
|
-
aboveData: false,
|
121
|
-
color: "#545454", // primary color used for outline and labels
|
122
|
-
backgroundColor: null, // null for transparent, else color
|
123
|
-
borderColor: null, // set if different from the grid color
|
124
|
-
tickColor: null, // color for the ticks, e.g. "rgba(0,0,0,0.15)"
|
125
|
-
labelMargin: 5, // in pixels
|
126
|
-
axisMargin: 8, // in pixels
|
127
|
-
borderWidth: 2, // in pixels
|
128
|
-
minBorderMargin: null, // in pixels, null means taken from points radius
|
129
|
-
markings: null, // array of ranges or fn: axes -> array of ranges
|
130
|
-
markingsColor: "#f4f4f4",
|
131
|
-
markingsLineWidth: 2,
|
132
|
-
// interactive stuff
|
133
|
-
clickable: false,
|
134
|
-
hoverable: false,
|
135
|
-
autoHighlight: true, // highlight in case mouse is near
|
136
|
-
mouseActiveRadius: 10 // how far the mouse can be away to activate an item
|
137
|
-
},
|
138
|
-
interaction: {
|
139
|
-
redrawOverlayInterval: 1000/60 // time between updates, -1 means in same flow
|
140
|
-
},
|
141
|
-
hooks: {}
|
142
|
-
},
|
143
|
-
canvas = null, // the canvas for the plot itself
|
144
|
-
overlay = null, // canvas for interactive stuff on top of plot
|
145
|
-
eventHolder = null, // jQuery object that events should be bound to
|
146
|
-
ctx = null, octx = null,
|
147
|
-
xaxes = [], yaxes = [],
|
148
|
-
plotOffset = { left: 0, right: 0, top: 0, bottom: 0},
|
149
|
-
canvasWidth = 0, canvasHeight = 0,
|
150
|
-
plotWidth = 0, plotHeight = 0,
|
151
|
-
hooks = {
|
152
|
-
processOptions: [],
|
153
|
-
processRawData: [],
|
154
|
-
processDatapoints: [],
|
155
|
-
drawSeries: [],
|
156
|
-
draw: [],
|
157
|
-
bindEvents: [],
|
158
|
-
drawOverlay: [],
|
159
|
-
shutdown: []
|
160
|
-
},
|
161
|
-
plot = this;
|
162
|
-
|
163
|
-
// public functions
|
164
|
-
plot.setData = setData;
|
165
|
-
plot.setupGrid = setupGrid;
|
166
|
-
plot.draw = draw;
|
167
|
-
plot.getPlaceholder = function() { return placeholder; };
|
168
|
-
plot.getCanvas = function() { return canvas; };
|
169
|
-
plot.getPlotOffset = function() { return plotOffset; };
|
170
|
-
plot.width = function () { return plotWidth; };
|
171
|
-
plot.height = function () { return plotHeight; };
|
172
|
-
plot.offset = function () {
|
173
|
-
var o = eventHolder.offset();
|
174
|
-
o.left += plotOffset.left;
|
175
|
-
o.top += plotOffset.top;
|
176
|
-
return o;
|
177
|
-
};
|
178
|
-
plot.getData = function () { return series; };
|
179
|
-
plot.getAxes = function () {
|
180
|
-
var res = {}, i;
|
181
|
-
$.each(xaxes.concat(yaxes), function (_, axis) {
|
182
|
-
if (axis)
|
183
|
-
res[axis.direction + (axis.n != 1 ? axis.n : "") + "axis"] = axis;
|
184
|
-
});
|
185
|
-
return res;
|
186
|
-
};
|
187
|
-
plot.getXAxes = function () { return xaxes; };
|
188
|
-
plot.getYAxes = function () { return yaxes; };
|
189
|
-
plot.c2p = canvasToAxisCoords;
|
190
|
-
plot.p2c = axisToCanvasCoords;
|
191
|
-
plot.getOptions = function () { return options; };
|
192
|
-
plot.highlight = highlight;
|
193
|
-
plot.unhighlight = unhighlight;
|
194
|
-
plot.triggerRedrawOverlay = triggerRedrawOverlay;
|
195
|
-
plot.pointOffset = function(point) {
|
196
|
-
return {
|
197
|
-
left: parseInt(xaxes[axisNumber(point, "x") - 1].p2c(+point.x) + plotOffset.left),
|
198
|
-
top: parseInt(yaxes[axisNumber(point, "y") - 1].p2c(+point.y) + plotOffset.top)
|
199
|
-
};
|
200
|
-
};
|
201
|
-
plot.shutdown = shutdown;
|
202
|
-
plot.resize = function () {
|
203
|
-
getCanvasDimensions();
|
204
|
-
resizeCanvas(canvas);
|
205
|
-
resizeCanvas(overlay);
|
206
|
-
};
|
207
|
-
|
208
|
-
// public attributes
|
209
|
-
plot.hooks = hooks;
|
210
|
-
|
211
|
-
// initialize
|
212
|
-
initPlugins(plot);
|
213
|
-
parseOptions(options_);
|
214
|
-
setupCanvases();
|
215
|
-
setData(data_);
|
216
|
-
setupGrid();
|
217
|
-
draw();
|
218
|
-
bindEvents();
|
219
|
-
|
220
|
-
|
221
|
-
function executeHooks(hook, args) {
|
222
|
-
args = [plot].concat(args);
|
223
|
-
for (var i = 0; i < hook.length; ++i)
|
224
|
-
hook[i].apply(this, args);
|
225
|
-
}
|
226
|
-
|
227
|
-
function initPlugins() {
|
228
|
-
for (var i = 0; i < plugins.length; ++i) {
|
229
|
-
var p = plugins[i];
|
230
|
-
p.init(plot);
|
231
|
-
if (p.options)
|
232
|
-
$.extend(true, options, p.options);
|
233
|
-
}
|
234
|
-
}
|
235
|
-
|
236
|
-
function parseOptions(opts) {
|
237
|
-
var i;
|
238
|
-
|
239
|
-
$.extend(true, options, opts);
|
240
|
-
|
241
|
-
if (options.xaxis.color == null)
|
242
|
-
options.xaxis.color = options.grid.color;
|
243
|
-
if (options.yaxis.color == null)
|
244
|
-
options.yaxis.color = options.grid.color;
|
245
|
-
|
246
|
-
if (options.xaxis.tickColor == null) // backwards-compatibility
|
247
|
-
options.xaxis.tickColor = options.grid.tickColor;
|
248
|
-
if (options.yaxis.tickColor == null) // backwards-compatibility
|
249
|
-
options.yaxis.tickColor = options.grid.tickColor;
|
250
|
-
|
251
|
-
if (options.grid.borderColor == null)
|
252
|
-
options.grid.borderColor = options.grid.color;
|
253
|
-
if (options.grid.tickColor == null)
|
254
|
-
options.grid.tickColor = $.color.parse(options.grid.color).scale('a', 0.22).toString();
|
255
|
-
|
256
|
-
// fill in defaults in axes, copy at least always the
|
257
|
-
// first as the rest of the code assumes it'll be there
|
258
|
-
for (i = 0; i < Math.max(1, options.xaxes.length); ++i)
|
259
|
-
options.xaxes[i] = $.extend(true, {}, options.xaxis, options.xaxes[i]);
|
260
|
-
for (i = 0; i < Math.max(1, options.yaxes.length); ++i)
|
261
|
-
options.yaxes[i] = $.extend(true, {}, options.yaxis, options.yaxes[i]);
|
262
|
-
|
263
|
-
// backwards compatibility, to be removed in future
|
264
|
-
if (options.xaxis.noTicks && options.xaxis.ticks == null)
|
265
|
-
options.xaxis.ticks = options.xaxis.noTicks;
|
266
|
-
if (options.yaxis.noTicks && options.yaxis.ticks == null)
|
267
|
-
options.yaxis.ticks = options.yaxis.noTicks;
|
268
|
-
if (options.x2axis) {
|
269
|
-
options.xaxes[1] = $.extend(true, {}, options.xaxis, options.x2axis);
|
270
|
-
options.xaxes[1].position = "top";
|
271
|
-
}
|
272
|
-
if (options.y2axis) {
|
273
|
-
options.yaxes[1] = $.extend(true, {}, options.yaxis, options.y2axis);
|
274
|
-
options.yaxes[1].position = "right";
|
275
|
-
}
|
276
|
-
if (options.grid.coloredAreas)
|
277
|
-
options.grid.markings = options.grid.coloredAreas;
|
278
|
-
if (options.grid.coloredAreasColor)
|
279
|
-
options.grid.markingsColor = options.grid.coloredAreasColor;
|
280
|
-
if (options.lines)
|
281
|
-
$.extend(true, options.series.lines, options.lines);
|
282
|
-
if (options.points)
|
283
|
-
$.extend(true, options.series.points, options.points);
|
284
|
-
if (options.bars)
|
285
|
-
$.extend(true, options.series.bars, options.bars);
|
286
|
-
if (options.shadowSize != null)
|
287
|
-
options.series.shadowSize = options.shadowSize;
|
288
|
-
|
289
|
-
// save options on axes for future reference
|
290
|
-
for (i = 0; i < options.xaxes.length; ++i)
|
291
|
-
getOrCreateAxis(xaxes, i + 1).options = options.xaxes[i];
|
292
|
-
for (i = 0; i < options.yaxes.length; ++i)
|
293
|
-
getOrCreateAxis(yaxes, i + 1).options = options.yaxes[i];
|
294
|
-
|
295
|
-
// add hooks from options
|
296
|
-
for (var n in hooks)
|
297
|
-
if (options.hooks[n] && options.hooks[n].length)
|
298
|
-
hooks[n] = hooks[n].concat(options.hooks[n]);
|
299
|
-
|
300
|
-
executeHooks(hooks.processOptions, [options]);
|
301
|
-
}
|
302
|
-
|
303
|
-
function setData(d) {
|
304
|
-
series = parseData(d);
|
305
|
-
fillInSeriesOptions();
|
306
|
-
processData();
|
307
|
-
}
|
308
|
-
|
309
|
-
function parseData(d) {
|
310
|
-
var res = [];
|
311
|
-
for (var i = 0; i < d.length; ++i) {
|
312
|
-
var s = $.extend(true, {}, options.series);
|
313
|
-
|
314
|
-
if (d[i].data != null) {
|
315
|
-
s.data = d[i].data; // move the data instead of deep-copy
|
316
|
-
delete d[i].data;
|
317
|
-
|
318
|
-
$.extend(true, s, d[i]);
|
319
|
-
|
320
|
-
d[i].data = s.data;
|
321
|
-
}
|
322
|
-
else
|
323
|
-
s.data = d[i];
|
324
|
-
res.push(s);
|
325
|
-
}
|
326
|
-
|
327
|
-
return res;
|
328
|
-
}
|
329
|
-
|
330
|
-
function axisNumber(obj, coord) {
|
331
|
-
var a = obj[coord + "axis"];
|
332
|
-
if (typeof a == "object") // if we got a real axis, extract number
|
333
|
-
a = a.n;
|
334
|
-
if (typeof a != "number")
|
335
|
-
a = 1; // default to first axis
|
336
|
-
return a;
|
337
|
-
}
|
338
|
-
|
339
|
-
function allAxes() {
|
340
|
-
// return flat array without annoying null entries
|
341
|
-
return $.grep(xaxes.concat(yaxes), function (a) { return a; });
|
342
|
-
}
|
343
|
-
|
344
|
-
function canvasToAxisCoords(pos) {
|
345
|
-
// return an object with x/y corresponding to all used axes
|
346
|
-
var res = {}, i, axis;
|
347
|
-
for (i = 0; i < xaxes.length; ++i) {
|
348
|
-
axis = xaxes[i];
|
349
|
-
if (axis && axis.used)
|
350
|
-
res["x" + axis.n] = axis.c2p(pos.left);
|
351
|
-
}
|
352
|
-
|
353
|
-
for (i = 0; i < yaxes.length; ++i) {
|
354
|
-
axis = yaxes[i];
|
355
|
-
if (axis && axis.used)
|
356
|
-
res["y" + axis.n] = axis.c2p(pos.top);
|
357
|
-
}
|
358
|
-
|
359
|
-
if (res.x1 !== undefined)
|
360
|
-
res.x = res.x1;
|
361
|
-
if (res.y1 !== undefined)
|
362
|
-
res.y = res.y1;
|
363
|
-
|
364
|
-
return res;
|
365
|
-
}
|
366
|
-
|
367
|
-
function axisToCanvasCoords(pos) {
|
368
|
-
// get canvas coords from the first pair of x/y found in pos
|
369
|
-
var res = {}, i, axis, key;
|
370
|
-
|
371
|
-
for (i = 0; i < xaxes.length; ++i) {
|
372
|
-
axis = xaxes[i];
|
373
|
-
if (axis && axis.used) {
|
374
|
-
key = "x" + axis.n;
|
375
|
-
if (pos[key] == null && axis.n == 1)
|
376
|
-
key = "x";
|
377
|
-
|
378
|
-
if (pos[key] != null) {
|
379
|
-
res.left = axis.p2c(pos[key]);
|
380
|
-
break;
|
381
|
-
}
|
382
|
-
}
|
383
|
-
}
|
384
|
-
|
385
|
-
for (i = 0; i < yaxes.length; ++i) {
|
386
|
-
axis = yaxes[i];
|
387
|
-
if (axis && axis.used) {
|
388
|
-
key = "y" + axis.n;
|
389
|
-
if (pos[key] == null && axis.n == 1)
|
390
|
-
key = "y";
|
391
|
-
|
392
|
-
if (pos[key] != null) {
|
393
|
-
res.top = axis.p2c(pos[key]);
|
394
|
-
break;
|
395
|
-
}
|
396
|
-
}
|
397
|
-
}
|
398
|
-
|
399
|
-
return res;
|
400
|
-
}
|
401
|
-
|
402
|
-
function getOrCreateAxis(axes, number) {
|
403
|
-
if (!axes[number - 1])
|
404
|
-
axes[number - 1] = {
|
405
|
-
n: number, // save the number for future reference
|
406
|
-
direction: axes == xaxes ? "x" : "y",
|
407
|
-
options: $.extend(true, {}, axes == xaxes ? options.xaxis : options.yaxis)
|
408
|
-
};
|
409
|
-
|
410
|
-
return axes[number - 1];
|
411
|
-
}
|
412
|
-
|
413
|
-
function fillInSeriesOptions() {
|
414
|
-
var i;
|
415
|
-
|
416
|
-
// collect what we already got of colors
|
417
|
-
var neededColors = series.length,
|
418
|
-
usedColors = [],
|
419
|
-
assignedColors = [];
|
420
|
-
for (i = 0; i < series.length; ++i) {
|
421
|
-
var sc = series[i].color;
|
422
|
-
if (sc != null) {
|
423
|
-
--neededColors;
|
424
|
-
if (typeof sc == "number")
|
425
|
-
assignedColors.push(sc);
|
426
|
-
else
|
427
|
-
usedColors.push($.color.parse(series[i].color));
|
428
|
-
}
|
429
|
-
}
|
430
|
-
|
431
|
-
// we might need to generate more colors if higher indices
|
432
|
-
// are assigned
|
433
|
-
for (i = 0; i < assignedColors.length; ++i) {
|
434
|
-
neededColors = Math.max(neededColors, assignedColors[i] + 1);
|
435
|
-
}
|
436
|
-
|
437
|
-
// produce colors as needed
|
438
|
-
var colors = [], variation = 0;
|
439
|
-
i = 0;
|
440
|
-
while (colors.length < neededColors) {
|
441
|
-
var c;
|
442
|
-
if (options.colors.length == i) // check degenerate case
|
443
|
-
c = $.color.make(100, 100, 100);
|
444
|
-
else
|
445
|
-
c = $.color.parse(options.colors[i]);
|
446
|
-
|
447
|
-
// vary color if needed
|
448
|
-
var sign = variation % 2 == 1 ? -1 : 1;
|
449
|
-
c.scale('rgb', 1 + sign * Math.ceil(variation / 2) * 0.2);
|
450
|
-
|
451
|
-
// FIXME: if we're getting to close to something else,
|
452
|
-
// we should probably skip this one
|
453
|
-
colors.push(c);
|
454
|
-
|
455
|
-
++i;
|
456
|
-
if (i >= options.colors.length) {
|
457
|
-
i = 0;
|
458
|
-
++variation;
|
459
|
-
}
|
460
|
-
}
|
461
|
-
|
462
|
-
// fill in the options
|
463
|
-
var colori = 0, s;
|
464
|
-
for (i = 0; i < series.length; ++i) {
|
465
|
-
s = series[i];
|
466
|
-
|
467
|
-
// assign colors
|
468
|
-
if (s.color == null) {
|
469
|
-
s.color = colors[colori].toString();
|
470
|
-
++colori;
|
471
|
-
}
|
472
|
-
else if (typeof s.color == "number")
|
473
|
-
s.color = colors[s.color].toString();
|
474
|
-
|
475
|
-
// turn on lines automatically in case nothing is set
|
476
|
-
if (s.lines.show == null) {
|
477
|
-
var v, show = true;
|
478
|
-
for (v in s)
|
479
|
-
if (s[v] && s[v].show) {
|
480
|
-
show = false;
|
481
|
-
break;
|
482
|
-
}
|
483
|
-
if (show)
|
484
|
-
s.lines.show = true;
|
485
|
-
}
|
486
|
-
|
487
|
-
// setup axes
|
488
|
-
s.xaxis = getOrCreateAxis(xaxes, axisNumber(s, "x"));
|
489
|
-
s.yaxis = getOrCreateAxis(yaxes, axisNumber(s, "y"));
|
490
|
-
}
|
491
|
-
}
|
492
|
-
|
493
|
-
function processData() {
|
494
|
-
var topSentry = Number.POSITIVE_INFINITY,
|
495
|
-
bottomSentry = Number.NEGATIVE_INFINITY,
|
496
|
-
fakeInfinity = Number.MAX_VALUE,
|
497
|
-
i, j, k, m, length,
|
498
|
-
s, points, ps, x, y, axis, val, f, p;
|
499
|
-
|
500
|
-
function updateAxis(axis, min, max) {
|
501
|
-
if (min < axis.datamin && min != -fakeInfinity)
|
502
|
-
axis.datamin = min;
|
503
|
-
if (max > axis.datamax && max != fakeInfinity)
|
504
|
-
axis.datamax = max;
|
505
|
-
}
|
506
|
-
|
507
|
-
$.each(allAxes(), function (_, axis) {
|
508
|
-
// init axis
|
509
|
-
axis.datamin = topSentry;
|
510
|
-
axis.datamax = bottomSentry;
|
511
|
-
axis.used = false;
|
512
|
-
});
|
513
|
-
|
514
|
-
for (i = 0; i < series.length; ++i) {
|
515
|
-
s = series[i];
|
516
|
-
s.datapoints = { points: [] };
|
517
|
-
|
518
|
-
executeHooks(hooks.processRawData, [ s, s.data, s.datapoints ]);
|
519
|
-
}
|
520
|
-
|
521
|
-
// first pass: clean and copy data
|
522
|
-
for (i = 0; i < series.length; ++i) {
|
523
|
-
s = series[i];
|
524
|
-
|
525
|
-
var data = s.data, format = s.datapoints.format;
|
526
|
-
|
527
|
-
if (!format) {
|
528
|
-
format = [];
|
529
|
-
// find out how to copy
|
530
|
-
format.push({ x: true, number: true, required: true });
|
531
|
-
format.push({ y: true, number: true, required: true });
|
532
|
-
|
533
|
-
if (s.bars.show || (s.lines.show && s.lines.fill)) {
|
534
|
-
format.push({ y: true, number: true, required: false, defaultValue: 0 });
|
535
|
-
if (s.bars.horizontal) {
|
536
|
-
delete format[format.length - 1].y;
|
537
|
-
format[format.length - 1].x = true;
|
538
|
-
}
|
539
|
-
}
|
540
|
-
|
541
|
-
s.datapoints.format = format;
|
542
|
-
}
|
543
|
-
|
544
|
-
if (s.datapoints.pointsize != null)
|
545
|
-
continue; // already filled in
|
546
|
-
|
547
|
-
s.datapoints.pointsize = format.length;
|
548
|
-
|
549
|
-
ps = s.datapoints.pointsize;
|
550
|
-
points = s.datapoints.points;
|
551
|
-
|
552
|
-
insertSteps = s.lines.show && s.lines.steps;
|
553
|
-
s.xaxis.used = s.yaxis.used = true;
|
554
|
-
|
555
|
-
for (j = k = 0; j < data.length; ++j, k += ps) {
|
556
|
-
p = data[j];
|
557
|
-
|
558
|
-
var nullify = p == null;
|
559
|
-
if (!nullify) {
|
560
|
-
for (m = 0; m < ps; ++m) {
|
561
|
-
val = p[m];
|
562
|
-
f = format[m];
|
563
|
-
|
564
|
-
if (f) {
|
565
|
-
if (f.number && val != null) {
|
566
|
-
val = +val; // convert to number
|
567
|
-
if (isNaN(val))
|
568
|
-
val = null;
|
569
|
-
else if (val == Infinity)
|
570
|
-
val = fakeInfinity;
|
571
|
-
else if (val == -Infinity)
|
572
|
-
val = -fakeInfinity;
|
573
|
-
}
|
574
|
-
|
575
|
-
if (val == null) {
|
576
|
-
if (f.required)
|
577
|
-
nullify = true;
|
578
|
-
|
579
|
-
if (f.defaultValue != null)
|
580
|
-
val = f.defaultValue;
|
581
|
-
}
|
582
|
-
}
|
583
|
-
|
584
|
-
points[k + m] = val;
|
585
|
-
}
|
586
|
-
}
|
587
|
-
|
588
|
-
if (nullify) {
|
589
|
-
for (m = 0; m < ps; ++m) {
|
590
|
-
val = points[k + m];
|
591
|
-
if (val != null) {
|
592
|
-
f = format[m];
|
593
|
-
// extract min/max info
|
594
|
-
if (f.x)
|
595
|
-
updateAxis(s.xaxis, val, val);
|
596
|
-
if (f.y)
|
597
|
-
updateAxis(s.yaxis, val, val);
|
598
|
-
}
|
599
|
-
points[k + m] = null;
|
600
|
-
}
|
601
|
-
}
|
602
|
-
else {
|
603
|
-
// a little bit of line specific stuff that
|
604
|
-
// perhaps shouldn't be here, but lacking
|
605
|
-
// better means...
|
606
|
-
if (insertSteps && k > 0
|
607
|
-
&& points[k - ps] != null
|
608
|
-
&& points[k - ps] != points[k]
|
609
|
-
&& points[k - ps + 1] != points[k + 1]) {
|
610
|
-
// copy the point to make room for a middle point
|
611
|
-
for (m = 0; m < ps; ++m)
|
612
|
-
points[k + ps + m] = points[k + m];
|
613
|
-
|
614
|
-
// middle point has same y
|
615
|
-
points[k + 1] = points[k - ps + 1];
|
616
|
-
|
617
|
-
// we've added a point, better reflect that
|
618
|
-
k += ps;
|
619
|
-
}
|
620
|
-
}
|
621
|
-
}
|
622
|
-
}
|
623
|
-
|
624
|
-
// give the hooks a chance to run
|
625
|
-
for (i = 0; i < series.length; ++i) {
|
626
|
-
s = series[i];
|
627
|
-
|
628
|
-
executeHooks(hooks.processDatapoints, [ s, s.datapoints]);
|
629
|
-
}
|
630
|
-
|
631
|
-
// second pass: find datamax/datamin for auto-scaling
|
632
|
-
for (i = 0; i < series.length; ++i) {
|
633
|
-
s = series[i];
|
634
|
-
points = s.datapoints.points,
|
635
|
-
ps = s.datapoints.pointsize;
|
636
|
-
format = s.datapoints.format;
|
637
|
-
|
638
|
-
var xmin = topSentry, ymin = topSentry,
|
639
|
-
xmax = bottomSentry, ymax = bottomSentry;
|
640
|
-
|
641
|
-
for (j = 0; j < points.length; j += ps) {
|
642
|
-
if (points[j] == null)
|
643
|
-
continue;
|
644
|
-
|
645
|
-
for (m = 0; m < ps; ++m) {
|
646
|
-
val = points[j + m];
|
647
|
-
f = format[m];
|
648
|
-
if (!f || val == fakeInfinity || val == -fakeInfinity)
|
649
|
-
continue;
|
650
|
-
|
651
|
-
if (f.x) {
|
652
|
-
if (val < xmin)
|
653
|
-
xmin = val;
|
654
|
-
if (val > xmax)
|
655
|
-
xmax = val;
|
656
|
-
}
|
657
|
-
if (f.y) {
|
658
|
-
if (val < ymin)
|
659
|
-
ymin = val;
|
660
|
-
if (val > ymax)
|
661
|
-
ymax = val;
|
662
|
-
}
|
663
|
-
}
|
664
|
-
}
|
665
|
-
|
666
|
-
if (s.bars.show) {
|
667
|
-
// make sure we got room for the bar on the dancing floor
|
668
|
-
var delta = s.bars.align == "left" ? 0 : -s.bars.barWidth/2;
|
669
|
-
if (s.bars.horizontal) {
|
670
|
-
ymin += delta;
|
671
|
-
ymax += delta + s.bars.barWidth;
|
672
|
-
}
|
673
|
-
else {
|
674
|
-
xmin += delta;
|
675
|
-
xmax += delta + s.bars.barWidth;
|
676
|
-
}
|
677
|
-
}
|
678
|
-
|
679
|
-
updateAxis(s.xaxis, xmin, xmax);
|
680
|
-
updateAxis(s.yaxis, ymin, ymax);
|
681
|
-
}
|
682
|
-
|
683
|
-
$.each(allAxes(), function (_, axis) {
|
684
|
-
if (axis.datamin == topSentry)
|
685
|
-
axis.datamin = null;
|
686
|
-
if (axis.datamax == bottomSentry)
|
687
|
-
axis.datamax = null;
|
688
|
-
});
|
689
|
-
}
|
690
|
-
|
691
|
-
function makeCanvas(skipPositioning, cls) {
|
692
|
-
var c = document.createElement('canvas');
|
693
|
-
c.className = cls;
|
694
|
-
c.width = canvasWidth;
|
695
|
-
c.height = canvasHeight;
|
696
|
-
|
697
|
-
if (!skipPositioning)
|
698
|
-
$(c).css({ position: 'absolute', left: 0, top: 0 });
|
699
|
-
|
700
|
-
$(c).appendTo(placeholder);
|
701
|
-
|
702
|
-
if (!c.getContext) // excanvas hack
|
703
|
-
c = window.G_vmlCanvasManager.initElement(c);
|
704
|
-
|
705
|
-
// used for resetting in case we get replotted
|
706
|
-
c.getContext("2d").save();
|
707
|
-
|
708
|
-
return c;
|
709
|
-
}
|
710
|
-
|
711
|
-
function getCanvasDimensions() {
|
712
|
-
canvasWidth = placeholder.width();
|
713
|
-
canvasHeight = placeholder.height();
|
714
|
-
|
715
|
-
if (canvasWidth <= 0 || canvasHeight <= 0)
|
716
|
-
throw "Invalid dimensions for plot, width = " + canvasWidth + ", height = " + canvasHeight;
|
717
|
-
}
|
718
|
-
|
719
|
-
function resizeCanvas(c) {
|
720
|
-
// resizing should reset the state (excanvas seems to be
|
721
|
-
// buggy though)
|
722
|
-
if (c.width != canvasWidth)
|
723
|
-
c.width = canvasWidth;
|
724
|
-
|
725
|
-
if (c.height != canvasHeight)
|
726
|
-
c.height = canvasHeight;
|
727
|
-
|
728
|
-
// so try to get back to the initial state (even if it's
|
729
|
-
// gone now, this should be safe according to the spec)
|
730
|
-
var cctx = c.getContext("2d");
|
731
|
-
cctx.restore();
|
732
|
-
|
733
|
-
// and save again
|
734
|
-
cctx.save();
|
735
|
-
}
|
736
|
-
|
737
|
-
function setupCanvases() {
|
738
|
-
var reused,
|
739
|
-
existingCanvas = placeholder.children("canvas.flot-base"),
|
740
|
-
existingOverlay = placeholder.children("canvas.flot-overlay");
|
741
|
-
|
742
|
-
if (existingCanvas.length == 0 || existingOverlay == 0) {
|
743
|
-
// init everything
|
744
|
-
|
745
|
-
placeholder.html(""); // make sure placeholder is clear
|
746
|
-
|
747
|
-
placeholder.css({ padding: 0 }); // padding messes up the positioning
|
748
|
-
|
749
|
-
if (placeholder.css("position") == 'static')
|
750
|
-
placeholder.css("position", "relative"); // for positioning labels and overlay
|
751
|
-
|
752
|
-
getCanvasDimensions();
|
753
|
-
|
754
|
-
canvas = makeCanvas(true, "flot-base");
|
755
|
-
overlay = makeCanvas(false, "flot-overlay"); // overlay canvas for interactive features
|
756
|
-
|
757
|
-
reused = false;
|
758
|
-
}
|
759
|
-
else {
|
760
|
-
// reuse existing elements
|
761
|
-
|
762
|
-
canvas = existingCanvas.get(0);
|
763
|
-
overlay = existingOverlay.get(0);
|
764
|
-
|
765
|
-
reused = true;
|
766
|
-
}
|
767
|
-
|
768
|
-
ctx = canvas.getContext("2d");
|
769
|
-
octx = overlay.getContext("2d");
|
770
|
-
|
771
|
-
// define which element we're listening for events on
|
772
|
-
eventHolder = $(overlay);
|
773
|
-
|
774
|
-
if (reused) {
|
775
|
-
// run shutdown in the old plot object
|
776
|
-
placeholder.data("plot").shutdown();
|
777
|
-
|
778
|
-
// reset reused canvases
|
779
|
-
plot.resize();
|
780
|
-
|
781
|
-
// make sure overlay pixels are cleared (canvas is cleared when we redraw)
|
782
|
-
octx.clearRect(0, 0, canvasWidth, canvasHeight);
|
783
|
-
|
784
|
-
// then whack any remaining obvious garbage left
|
785
|
-
eventHolder.unbind();
|
786
|
-
placeholder.children().not([canvas, overlay]).remove();
|
787
|
-
}
|
788
|
-
|
789
|
-
// save in case we get replotted
|
790
|
-
placeholder.data("plot", plot);
|
791
|
-
}
|
792
|
-
|
793
|
-
function bindEvents() {
|
794
|
-
// bind events
|
795
|
-
if (options.grid.hoverable) {
|
796
|
-
eventHolder.mousemove(onMouseMove);
|
797
|
-
eventHolder.mouseleave(onMouseLeave);
|
798
|
-
}
|
799
|
-
|
800
|
-
if (options.grid.clickable)
|
801
|
-
eventHolder.click(onClick);
|
802
|
-
|
803
|
-
executeHooks(hooks.bindEvents, [eventHolder]);
|
804
|
-
}
|
805
|
-
|
806
|
-
function shutdown() {
|
807
|
-
if (redrawTimeout)
|
808
|
-
clearTimeout(redrawTimeout);
|
809
|
-
|
810
|
-
eventHolder.unbind("mousemove", onMouseMove);
|
811
|
-
eventHolder.unbind("mouseleave", onMouseLeave);
|
812
|
-
eventHolder.unbind("click", onClick);
|
813
|
-
|
814
|
-
executeHooks(hooks.shutdown, [eventHolder]);
|
815
|
-
}
|
816
|
-
|
817
|
-
function setTransformationHelpers(axis) {
|
818
|
-
// set helper functions on the axis, assumes plot area
|
819
|
-
// has been computed already
|
820
|
-
|
821
|
-
function identity(x) { return x; }
|
822
|
-
|
823
|
-
var s, m, t = axis.options.transform || identity,
|
824
|
-
it = axis.options.inverseTransform;
|
825
|
-
|
826
|
-
// precompute how much the axis is scaling a point
|
827
|
-
// in canvas space
|
828
|
-
if (axis.direction == "x") {
|
829
|
-
s = axis.scale = plotWidth / Math.abs(t(axis.max) - t(axis.min));
|
830
|
-
m = Math.min(t(axis.max), t(axis.min));
|
831
|
-
}
|
832
|
-
else {
|
833
|
-
s = axis.scale = plotHeight / Math.abs(t(axis.max) - t(axis.min));
|
834
|
-
s = -s;
|
835
|
-
m = Math.max(t(axis.max), t(axis.min));
|
836
|
-
}
|
837
|
-
|
838
|
-
// data point to canvas coordinate
|
839
|
-
if (t == identity) // slight optimization
|
840
|
-
axis.p2c = function (p) { return (p - m) * s; };
|
841
|
-
else
|
842
|
-
axis.p2c = function (p) { return (t(p) - m) * s; };
|
843
|
-
// canvas coordinate to data point
|
844
|
-
if (!it)
|
845
|
-
axis.c2p = function (c) { return m + c / s; };
|
846
|
-
else
|
847
|
-
axis.c2p = function (c) { return it(m + c / s); };
|
848
|
-
}
|
849
|
-
|
850
|
-
function measureTickLabels(axis) {
|
851
|
-
var opts = axis.options, ticks = axis.ticks || [],
|
852
|
-
axisw = opts.labelWidth || 0, axish = opts.labelHeight || 0,
|
853
|
-
f = axis.font;
|
854
|
-
|
855
|
-
ctx.save();
|
856
|
-
ctx.font = f.style + " " + f.variant + " " + f.weight + " " + f.size + "px '" + f.family + "'";
|
857
|
-
|
858
|
-
for (var i = 0; i < ticks.length; ++i) {
|
859
|
-
var t = ticks[i];
|
860
|
-
|
861
|
-
t.lines = [];
|
862
|
-
t.width = t.height = 0;
|
863
|
-
|
864
|
-
if (!t.label)
|
865
|
-
continue;
|
866
|
-
|
867
|
-
// accept various kinds of newlines, including HTML ones
|
868
|
-
// (you can actually split directly on regexps in Javascript,
|
869
|
-
// but IE is unfortunately broken)
|
870
|
-
var lines = t.label.replace(/<br ?\/?>|\r\n|\r/g, "\n").split("\n");
|
871
|
-
for (var j = 0; j < lines.length; ++j) {
|
872
|
-
var line = { text: lines[j] },
|
873
|
-
m = ctx.measureText(line.text);
|
874
|
-
|
875
|
-
line.width = m.width;
|
876
|
-
// m.height might not be defined, not in the
|
877
|
-
// standard yet
|
878
|
-
line.height = m.height != null ? m.height : f.size;
|
879
|
-
|
880
|
-
// add a bit of margin since font rendering is
|
881
|
-
// not pixel perfect and cut off letters look
|
882
|
-
// bad, this also doubles as spacing between
|
883
|
-
// lines
|
884
|
-
line.height += Math.round(f.size * 0.15);
|
885
|
-
|
886
|
-
t.width = Math.max(line.width, t.width);
|
887
|
-
t.height += line.height;
|
888
|
-
|
889
|
-
t.lines.push(line);
|
890
|
-
}
|
891
|
-
|
892
|
-
if (opts.labelWidth == null)
|
893
|
-
axisw = Math.max(axisw, t.width);
|
894
|
-
if (opts.labelHeight == null)
|
895
|
-
axish = Math.max(axish, t.height);
|
896
|
-
}
|
897
|
-
ctx.restore();
|
898
|
-
|
899
|
-
axis.labelWidth = Math.ceil(axisw);
|
900
|
-
axis.labelHeight = Math.ceil(axish);
|
901
|
-
}
|
902
|
-
|
903
|
-
function allocateAxisBoxFirstPhase(axis) {
|
904
|
-
// find the bounding box of the axis by looking at label
|
905
|
-
// widths/heights and ticks, make room by diminishing the
|
906
|
-
// plotOffset; this first phase only looks at one
|
907
|
-
// dimension per axis, the other dimension depends on the
|
908
|
-
// other axes so will have to wait
|
909
|
-
|
910
|
-
var lw = axis.labelWidth,
|
911
|
-
lh = axis.labelHeight,
|
912
|
-
pos = axis.options.position,
|
913
|
-
tickLength = axis.options.tickLength,
|
914
|
-
axisMargin = options.grid.axisMargin,
|
915
|
-
padding = options.grid.labelMargin,
|
916
|
-
all = axis.direction == "x" ? xaxes : yaxes,
|
917
|
-
index;
|
918
|
-
|
919
|
-
// determine axis margin
|
920
|
-
var samePosition = $.grep(all, function (a) {
|
921
|
-
return a && a.options.position == pos && a.reserveSpace;
|
922
|
-
});
|
923
|
-
if ($.inArray(axis, samePosition) == samePosition.length - 1)
|
924
|
-
axisMargin = 0; // outermost
|
925
|
-
|
926
|
-
// determine tick length - if we're innermost, we can use "full"
|
927
|
-
if (tickLength == null) {
|
928
|
-
var sameDirection = $.grep(all, function (a) {
|
929
|
-
return a && a.reserveSpace;
|
930
|
-
});
|
931
|
-
|
932
|
-
var innermost = $.inArray(axis, sameDirection) == 0;
|
933
|
-
if (innermost)
|
934
|
-
tickLength = "full";
|
935
|
-
else
|
936
|
-
tickLength = 5;
|
937
|
-
}
|
938
|
-
|
939
|
-
if (!isNaN(+tickLength))
|
940
|
-
padding += +tickLength;
|
941
|
-
|
942
|
-
// compute box
|
943
|
-
if (axis.direction == "x") {
|
944
|
-
lh += padding;
|
945
|
-
|
946
|
-
if (pos == "bottom") {
|
947
|
-
plotOffset.bottom += lh + axisMargin;
|
948
|
-
axis.box = { top: canvasHeight - plotOffset.bottom, height: lh };
|
949
|
-
}
|
950
|
-
else {
|
951
|
-
axis.box = { top: plotOffset.top + axisMargin, height: lh };
|
952
|
-
plotOffset.top += lh + axisMargin;
|
953
|
-
}
|
954
|
-
}
|
955
|
-
else {
|
956
|
-
lw += padding;
|
957
|
-
|
958
|
-
if (pos == "left") {
|
959
|
-
axis.box = { left: plotOffset.left + axisMargin, width: lw };
|
960
|
-
plotOffset.left += lw + axisMargin;
|
961
|
-
}
|
962
|
-
else {
|
963
|
-
plotOffset.right += lw + axisMargin;
|
964
|
-
axis.box = { left: canvasWidth - plotOffset.right, width: lw };
|
965
|
-
}
|
966
|
-
}
|
967
|
-
|
968
|
-
// save for future reference
|
969
|
-
axis.position = pos;
|
970
|
-
axis.tickLength = tickLength;
|
971
|
-
axis.box.padding = padding;
|
972
|
-
axis.innermost = innermost;
|
973
|
-
}
|
974
|
-
|
975
|
-
function allocateAxisBoxSecondPhase(axis) {
|
976
|
-
// now that all axis boxes have been placed in one
|
977
|
-
// dimension, we can set the remaining dimension coordinates
|
978
|
-
if (axis.direction == "x") {
|
979
|
-
axis.box.left = plotOffset.left - axis.labelWidth / 2;
|
980
|
-
axis.box.width = canvasWidth - plotOffset.left - plotOffset.right + axis.labelWidth;
|
981
|
-
}
|
982
|
-
else {
|
983
|
-
axis.box.top = plotOffset.top - axis.labelHeight / 2;
|
984
|
-
axis.box.height = canvasHeight - plotOffset.bottom - plotOffset.top + axis.labelHeight;
|
985
|
-
}
|
986
|
-
}
|
987
|
-
|
988
|
-
function adjustLayoutForThingsStickingOut() {
|
989
|
-
// possibly adjust plot offset to ensure everything stays
|
990
|
-
// inside the canvas and isn't clipped off
|
991
|
-
|
992
|
-
var minMargin = options.grid.minBorderMargin,
|
993
|
-
margins = { x: 0, y: 0 }, i, axis;
|
994
|
-
|
995
|
-
// check stuff from the plot (FIXME: this should just read
|
996
|
-
// a value from the series, otherwise it's impossible to
|
997
|
-
// customize)
|
998
|
-
if (minMargin == null) {
|
999
|
-
minMargin = 0;
|
1000
|
-
for (i = 0; i < series.length; ++i)
|
1001
|
-
minMargin = Math.max(minMargin, 2 * (series[i].points.radius + series[i].points.lineWidth/2));
|
1002
|
-
}
|
1003
|
-
|
1004
|
-
margins.x = margins.y = Math.ceil(minMargin);
|
1005
|
-
|
1006
|
-
// check axis labels, note we don't check the actual
|
1007
|
-
// labels but instead use the overall width/height to not
|
1008
|
-
// jump as much around with replots
|
1009
|
-
$.each(allAxes(), function (_, axis) {
|
1010
|
-
var dir = axis.direction;
|
1011
|
-
if (axis.reserveSpace)
|
1012
|
-
margins[dir] = Math.ceil(Math.max(margins[dir], (dir == "x" ? axis.labelWidth : axis.labelHeight) / 2));
|
1013
|
-
});
|
1014
|
-
|
1015
|
-
plotOffset.left = Math.max(margins.x, plotOffset.left);
|
1016
|
-
plotOffset.right = Math.max(margins.x, plotOffset.right);
|
1017
|
-
plotOffset.top = Math.max(margins.y, plotOffset.top);
|
1018
|
-
plotOffset.bottom = Math.max(margins.y, plotOffset.bottom);
|
1019
|
-
}
|
1020
|
-
|
1021
|
-
function setupGrid() {
|
1022
|
-
var i, axes = allAxes(), showGrid = options.grid.show;
|
1023
|
-
|
1024
|
-
// init plot offset
|
1025
|
-
for (var a in plotOffset)
|
1026
|
-
plotOffset[a] = showGrid ? options.grid.borderWidth : 0;
|
1027
|
-
|
1028
|
-
// init axes
|
1029
|
-
$.each(axes, function (_, axis) {
|
1030
|
-
axis.show = axis.options.show;
|
1031
|
-
if (axis.show == null)
|
1032
|
-
axis.show = axis.used; // by default an axis is visible if it's got data
|
1033
|
-
|
1034
|
-
axis.reserveSpace = axis.show || axis.options.reserveSpace;
|
1035
|
-
|
1036
|
-
setRange(axis);
|
1037
|
-
});
|
1038
|
-
|
1039
|
-
if (showGrid) {
|
1040
|
-
// determine from the placeholder the font size ~ height of font ~ 1 em
|
1041
|
-
var fontDefaults = {
|
1042
|
-
style: placeholder.css("font-style"),
|
1043
|
-
size: Math.round(0.8 * (+placeholder.css("font-size").replace("px", "") || 13)),
|
1044
|
-
variant: placeholder.css("font-variant"),
|
1045
|
-
weight: placeholder.css("font-weight"),
|
1046
|
-
family: placeholder.css("font-family")
|
1047
|
-
};
|
1048
|
-
|
1049
|
-
var allocatedAxes = $.grep(axes, function (axis) { return axis.reserveSpace; });
|
1050
|
-
|
1051
|
-
$.each(allocatedAxes, function (_, axis) {
|
1052
|
-
// make the ticks
|
1053
|
-
setupTickGeneration(axis);
|
1054
|
-
setTicks(axis);
|
1055
|
-
snapRangeToTicks(axis, axis.ticks);
|
1056
|
-
|
1057
|
-
// find labelWidth/Height for axis
|
1058
|
-
axis.font = $.extend({}, fontDefaults, axis.options.font);
|
1059
|
-
measureTickLabels(axis);
|
1060
|
-
});
|
1061
|
-
|
1062
|
-
// with all dimensions calculated, we can compute the
|
1063
|
-
// axis bounding boxes, start from the outside
|
1064
|
-
// (reverse order)
|
1065
|
-
for (i = allocatedAxes.length - 1; i >= 0; --i)
|
1066
|
-
allocateAxisBoxFirstPhase(allocatedAxes[i]);
|
1067
|
-
|
1068
|
-
// make sure we've got enough space for things that
|
1069
|
-
// might stick out
|
1070
|
-
adjustLayoutForThingsStickingOut();
|
1071
|
-
|
1072
|
-
$.each(allocatedAxes, function (_, axis) {
|
1073
|
-
allocateAxisBoxSecondPhase(axis);
|
1074
|
-
});
|
1075
|
-
}
|
1076
|
-
|
1077
|
-
plotWidth = canvasWidth - plotOffset.left - plotOffset.right;
|
1078
|
-
plotHeight = canvasHeight - plotOffset.bottom - plotOffset.top;
|
1079
|
-
|
1080
|
-
// now we got the proper plot dimensions, we can compute the scaling
|
1081
|
-
$.each(axes, function (_, axis) {
|
1082
|
-
setTransformationHelpers(axis);
|
1083
|
-
});
|
1084
|
-
|
1085
|
-
insertLegend();
|
1086
|
-
}
|
1087
|
-
|
1088
|
-
function setRange(axis) {
|
1089
|
-
var opts = axis.options,
|
1090
|
-
min = +(opts.min != null ? opts.min : axis.datamin),
|
1091
|
-
max = +(opts.max != null ? opts.max : axis.datamax),
|
1092
|
-
delta = max - min;
|
1093
|
-
|
1094
|
-
if (delta == 0.0) {
|
1095
|
-
// degenerate case
|
1096
|
-
var widen = max == 0 ? 1 : 0.01;
|
1097
|
-
|
1098
|
-
if (opts.min == null)
|
1099
|
-
min -= widen;
|
1100
|
-
// always widen max if we couldn't widen min to ensure we
|
1101
|
-
// don't fall into min == max which doesn't work
|
1102
|
-
if (opts.max == null || opts.min != null)
|
1103
|
-
max += widen;
|
1104
|
-
}
|
1105
|
-
else {
|
1106
|
-
// consider autoscaling
|
1107
|
-
var margin = opts.autoscaleMargin;
|
1108
|
-
if (margin != null) {
|
1109
|
-
if (opts.min == null) {
|
1110
|
-
min -= delta * margin;
|
1111
|
-
// make sure we don't go below zero if all values
|
1112
|
-
// are positive
|
1113
|
-
if (min < 0 && axis.datamin != null && axis.datamin >= 0)
|
1114
|
-
min = 0;
|
1115
|
-
}
|
1116
|
-
if (opts.max == null) {
|
1117
|
-
max += delta * margin;
|
1118
|
-
if (max > 0 && axis.datamax != null && axis.datamax <= 0)
|
1119
|
-
max = 0;
|
1120
|
-
}
|
1121
|
-
}
|
1122
|
-
}
|
1123
|
-
axis.min = min;
|
1124
|
-
axis.max = max;
|
1125
|
-
}
|
1126
|
-
|
1127
|
-
function setupTickGeneration(axis) {
|
1128
|
-
var opts = axis.options;
|
1129
|
-
|
1130
|
-
// estimate number of ticks
|
1131
|
-
var noTicks;
|
1132
|
-
if (typeof opts.ticks == "number" && opts.ticks > 0)
|
1133
|
-
noTicks = opts.ticks;
|
1134
|
-
else
|
1135
|
-
// heuristic based on the model a*sqrt(x) fitted to
|
1136
|
-
// some data points that seemed reasonable
|
1137
|
-
noTicks = 0.3 * Math.sqrt(axis.direction == "x" ? canvasWidth : canvasHeight);
|
1138
|
-
|
1139
|
-
var delta = (axis.max - axis.min) / noTicks,
|
1140
|
-
size, generator, unit, formatter, i, magn, norm;
|
1141
|
-
|
1142
|
-
if (opts.mode == "time") {
|
1143
|
-
// pretty handling of time
|
1144
|
-
|
1145
|
-
// map of app. size of time units in milliseconds
|
1146
|
-
var timeUnitSize = {
|
1147
|
-
"second": 1000,
|
1148
|
-
"minute": 60 * 1000,
|
1149
|
-
"hour": 60 * 60 * 1000,
|
1150
|
-
"day": 24 * 60 * 60 * 1000,
|
1151
|
-
"month": 30 * 24 * 60 * 60 * 1000,
|
1152
|
-
"year": 365.2425 * 24 * 60 * 60 * 1000
|
1153
|
-
};
|
1154
|
-
|
1155
|
-
|
1156
|
-
// the allowed tick sizes, after 1 year we use
|
1157
|
-
// an integer algorithm
|
1158
|
-
var spec = [
|
1159
|
-
[1, "second"], [2, "second"], [5, "second"], [10, "second"],
|
1160
|
-
[30, "second"],
|
1161
|
-
[1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"],
|
1162
|
-
[30, "minute"],
|
1163
|
-
[1, "hour"], [2, "hour"], [4, "hour"],
|
1164
|
-
[8, "hour"], [12, "hour"],
|
1165
|
-
[1, "day"], [2, "day"], [3, "day"],
|
1166
|
-
[0.25, "month"], [0.5, "month"], [1, "month"],
|
1167
|
-
[2, "month"], [3, "month"], [6, "month"],
|
1168
|
-
[1, "year"]
|
1169
|
-
];
|
1170
|
-
|
1171
|
-
var minSize = 0;
|
1172
|
-
if (opts.minTickSize != null) {
|
1173
|
-
if (typeof opts.tickSize == "number")
|
1174
|
-
minSize = opts.tickSize;
|
1175
|
-
else
|
1176
|
-
minSize = opts.minTickSize[0] * timeUnitSize[opts.minTickSize[1]];
|
1177
|
-
}
|
1178
|
-
|
1179
|
-
for (var i = 0; i < spec.length - 1; ++i)
|
1180
|
-
if (delta < (spec[i][0] * timeUnitSize[spec[i][1]]
|
1181
|
-
+ spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2
|
1182
|
-
&& spec[i][0] * timeUnitSize[spec[i][1]] >= minSize)
|
1183
|
-
break;
|
1184
|
-
size = spec[i][0];
|
1185
|
-
unit = spec[i][1];
|
1186
|
-
|
1187
|
-
// special-case the possibility of several years
|
1188
|
-
if (unit == "year") {
|
1189
|
-
magn = Math.pow(10, Math.floor(Math.log(delta / timeUnitSize.year) / Math.LN10));
|
1190
|
-
norm = (delta / timeUnitSize.year) / magn;
|
1191
|
-
if (norm < 1.5)
|
1192
|
-
size = 1;
|
1193
|
-
else if (norm < 3)
|
1194
|
-
size = 2;
|
1195
|
-
else if (norm < 7.5)
|
1196
|
-
size = 5;
|
1197
|
-
else
|
1198
|
-
size = 10;
|
1199
|
-
|
1200
|
-
size *= magn;
|
1201
|
-
}
|
1202
|
-
|
1203
|
-
axis.tickSize = opts.tickSize || [size, unit];
|
1204
|
-
|
1205
|
-
generator = function(axis) {
|
1206
|
-
var ticks = [],
|
1207
|
-
tickSize = axis.tickSize[0], unit = axis.tickSize[1],
|
1208
|
-
d = new Date(axis.min);
|
1209
|
-
|
1210
|
-
var step = tickSize * timeUnitSize[unit];
|
1211
|
-
|
1212
|
-
if (unit == "second")
|
1213
|
-
d.setUTCSeconds(floorInBase(d.getUTCSeconds(), tickSize));
|
1214
|
-
if (unit == "minute")
|
1215
|
-
d.setUTCMinutes(floorInBase(d.getUTCMinutes(), tickSize));
|
1216
|
-
if (unit == "hour")
|
1217
|
-
d.setUTCHours(floorInBase(d.getUTCHours(), tickSize));
|
1218
|
-
if (unit == "month")
|
1219
|
-
d.setUTCMonth(floorInBase(d.getUTCMonth(), tickSize));
|
1220
|
-
if (unit == "year")
|
1221
|
-
d.setUTCFullYear(floorInBase(d.getUTCFullYear(), tickSize));
|
1222
|
-
|
1223
|
-
// reset smaller components
|
1224
|
-
d.setUTCMilliseconds(0);
|
1225
|
-
if (step >= timeUnitSize.minute)
|
1226
|
-
d.setUTCSeconds(0);
|
1227
|
-
if (step >= timeUnitSize.hour)
|
1228
|
-
d.setUTCMinutes(0);
|
1229
|
-
if (step >= timeUnitSize.day)
|
1230
|
-
d.setUTCHours(0);
|
1231
|
-
if (step >= timeUnitSize.day * 4)
|
1232
|
-
d.setUTCDate(1);
|
1233
|
-
if (step >= timeUnitSize.year)
|
1234
|
-
d.setUTCMonth(0);
|
1235
|
-
|
1236
|
-
|
1237
|
-
var carry = 0, v = Number.NaN, prev;
|
1238
|
-
do {
|
1239
|
-
prev = v;
|
1240
|
-
v = d.getTime();
|
1241
|
-
ticks.push(v);
|
1242
|
-
if (unit == "month") {
|
1243
|
-
if (tickSize < 1) {
|
1244
|
-
// a bit complicated - we'll divide the month
|
1245
|
-
// up but we need to take care of fractions
|
1246
|
-
// so we don't end up in the middle of a day
|
1247
|
-
d.setUTCDate(1);
|
1248
|
-
var start = d.getTime();
|
1249
|
-
d.setUTCMonth(d.getUTCMonth() + 1);
|
1250
|
-
var end = d.getTime();
|
1251
|
-
d.setTime(v + carry * timeUnitSize.hour + (end - start) * tickSize);
|
1252
|
-
carry = d.getUTCHours();
|
1253
|
-
d.setUTCHours(0);
|
1254
|
-
}
|
1255
|
-
else
|
1256
|
-
d.setUTCMonth(d.getUTCMonth() + tickSize);
|
1257
|
-
}
|
1258
|
-
else if (unit == "year") {
|
1259
|
-
d.setUTCFullYear(d.getUTCFullYear() + tickSize);
|
1260
|
-
}
|
1261
|
-
else
|
1262
|
-
d.setTime(v + step);
|
1263
|
-
} while (v < axis.max && v != prev);
|
1264
|
-
|
1265
|
-
return ticks;
|
1266
|
-
};
|
1267
|
-
|
1268
|
-
formatter = function (v, axis) {
|
1269
|
-
var d = new Date(v);
|
1270
|
-
|
1271
|
-
// first check global format
|
1272
|
-
if (opts.timeformat != null)
|
1273
|
-
return $.plot.formatDate(d, opts.timeformat, opts.monthNames);
|
1274
|
-
|
1275
|
-
var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]];
|
1276
|
-
var span = axis.max - axis.min;
|
1277
|
-
var suffix = (opts.twelveHourClock) ? " %p" : "";
|
1278
|
-
|
1279
|
-
if (t < timeUnitSize.minute)
|
1280
|
-
fmt = "%h:%M:%S" + suffix;
|
1281
|
-
else if (t < timeUnitSize.day) {
|
1282
|
-
if (span < 2 * timeUnitSize.day)
|
1283
|
-
fmt = "%h:%M" + suffix;
|
1284
|
-
else
|
1285
|
-
fmt = "%b %d %h:%M" + suffix;
|
1286
|
-
}
|
1287
|
-
else if (t < timeUnitSize.month)
|
1288
|
-
fmt = "%b %d";
|
1289
|
-
else if (t < timeUnitSize.year) {
|
1290
|
-
if (span < timeUnitSize.year)
|
1291
|
-
fmt = "%b";
|
1292
|
-
else
|
1293
|
-
fmt = "%b %y";
|
1294
|
-
}
|
1295
|
-
else
|
1296
|
-
fmt = "%y";
|
1297
|
-
|
1298
|
-
return $.plot.formatDate(d, fmt, opts.monthNames);
|
1299
|
-
};
|
1300
|
-
}
|
1301
|
-
else {
|
1302
|
-
// pretty rounding of base-10 numbers
|
1303
|
-
var maxDec = opts.tickDecimals;
|
1304
|
-
var dec = -Math.floor(Math.log(delta) / Math.LN10);
|
1305
|
-
if (maxDec != null && dec > maxDec)
|
1306
|
-
dec = maxDec;
|
1307
|
-
|
1308
|
-
magn = Math.pow(10, -dec);
|
1309
|
-
norm = delta / magn; // norm is between 1.0 and 10.0
|
1310
|
-
|
1311
|
-
if (norm < 1.5)
|
1312
|
-
size = 1;
|
1313
|
-
else if (norm < 3) {
|
1314
|
-
size = 2;
|
1315
|
-
// special case for 2.5, requires an extra decimal
|
1316
|
-
if (norm > 2.25 && (maxDec == null || dec + 1 <= maxDec)) {
|
1317
|
-
size = 2.5;
|
1318
|
-
++dec;
|
1319
|
-
}
|
1320
|
-
}
|
1321
|
-
else if (norm < 7.5)
|
1322
|
-
size = 5;
|
1323
|
-
else
|
1324
|
-
size = 10;
|
1325
|
-
|
1326
|
-
size *= magn;
|
1327
|
-
|
1328
|
-
if (opts.minTickSize != null && size < opts.minTickSize)
|
1329
|
-
size = opts.minTickSize;
|
1330
|
-
|
1331
|
-
axis.tickDecimals = Math.max(0, maxDec != null ? maxDec : dec);
|
1332
|
-
axis.tickSize = opts.tickSize || size;
|
1333
|
-
|
1334
|
-
generator = function (axis) {
|
1335
|
-
var ticks = [];
|
1336
|
-
|
1337
|
-
// spew out all possible ticks
|
1338
|
-
var start = floorInBase(axis.min, axis.tickSize),
|
1339
|
-
i = 0, v = Number.NaN, prev;
|
1340
|
-
do {
|
1341
|
-
prev = v;
|
1342
|
-
v = start + i * axis.tickSize;
|
1343
|
-
ticks.push(v);
|
1344
|
-
++i;
|
1345
|
-
} while (v < axis.max && v != prev);
|
1346
|
-
return ticks;
|
1347
|
-
};
|
1348
|
-
|
1349
|
-
formatter = function (v, axis) {
|
1350
|
-
return v.toFixed(axis.tickDecimals);
|
1351
|
-
};
|
1352
|
-
}
|
1353
|
-
|
1354
|
-
if (opts.alignTicksWithAxis != null) {
|
1355
|
-
var otherAxis = (axis.direction == "x" ? xaxes : yaxes)[opts.alignTicksWithAxis - 1];
|
1356
|
-
if (otherAxis && otherAxis.used && otherAxis != axis) {
|
1357
|
-
// consider snapping min/max to outermost nice ticks
|
1358
|
-
var niceTicks = generator(axis);
|
1359
|
-
if (niceTicks.length > 0) {
|
1360
|
-
if (opts.min == null)
|
1361
|
-
axis.min = Math.min(axis.min, niceTicks[0]);
|
1362
|
-
if (opts.max == null && niceTicks.length > 1)
|
1363
|
-
axis.max = Math.max(axis.max, niceTicks[niceTicks.length - 1]);
|
1364
|
-
}
|
1365
|
-
|
1366
|
-
generator = function (axis) {
|
1367
|
-
// copy ticks, scaled to this axis
|
1368
|
-
var ticks = [], v, i;
|
1369
|
-
for (i = 0; i < otherAxis.ticks.length; ++i) {
|
1370
|
-
v = (otherAxis.ticks[i].v - otherAxis.min) / (otherAxis.max - otherAxis.min);
|
1371
|
-
v = axis.min + v * (axis.max - axis.min);
|
1372
|
-
ticks.push(v);
|
1373
|
-
}
|
1374
|
-
return ticks;
|
1375
|
-
};
|
1376
|
-
|
1377
|
-
// we might need an extra decimal since forced
|
1378
|
-
// ticks don't necessarily fit naturally
|
1379
|
-
if (!axis.mode && opts.tickDecimals == null) {
|
1380
|
-
var extraDec = Math.max(0, -Math.floor(Math.log(delta) / Math.LN10) + 1),
|
1381
|
-
ts = generator(axis);
|
1382
|
-
|
1383
|
-
// only proceed if the tick interval rounded
|
1384
|
-
// with an extra decimal doesn't give us a
|
1385
|
-
// zero at end
|
1386
|
-
if (!(ts.length > 1 && /\..*0$/.test((ts[1] - ts[0]).toFixed(extraDec))))
|
1387
|
-
axis.tickDecimals = extraDec;
|
1388
|
-
}
|
1389
|
-
}
|
1390
|
-
}
|
1391
|
-
|
1392
|
-
axis.tickGenerator = generator;
|
1393
|
-
if ($.isFunction(opts.tickFormatter))
|
1394
|
-
axis.tickFormatter = function (v, axis) { return "" + opts.tickFormatter(v, axis); };
|
1395
|
-
else
|
1396
|
-
axis.tickFormatter = formatter;
|
1397
|
-
}
|
1398
|
-
|
1399
|
-
function setTicks(axis) {
|
1400
|
-
var oticks = axis.options.ticks, ticks = [];
|
1401
|
-
if (oticks == null || (typeof oticks == "number" && oticks > 0))
|
1402
|
-
ticks = axis.tickGenerator(axis);
|
1403
|
-
else if (oticks) {
|
1404
|
-
if ($.isFunction(oticks))
|
1405
|
-
// generate the ticks
|
1406
|
-
ticks = oticks(axis);
|
1407
|
-
else
|
1408
|
-
ticks = oticks;
|
1409
|
-
}
|
1410
|
-
|
1411
|
-
// clean up/labelify the supplied ticks, copy them over
|
1412
|
-
var i, v;
|
1413
|
-
axis.ticks = [];
|
1414
|
-
for (i = 0; i < ticks.length; ++i) {
|
1415
|
-
var label = null;
|
1416
|
-
var t = ticks[i];
|
1417
|
-
if (typeof t == "object") {
|
1418
|
-
v = +t[0];
|
1419
|
-
if (t.length > 1)
|
1420
|
-
label = t[1];
|
1421
|
-
}
|
1422
|
-
else
|
1423
|
-
v = +t;
|
1424
|
-
if (label == null)
|
1425
|
-
label = axis.tickFormatter(v, axis);
|
1426
|
-
if (!isNaN(v))
|
1427
|
-
axis.ticks.push({ v: v, label: label });
|
1428
|
-
}
|
1429
|
-
}
|
1430
|
-
|
1431
|
-
function snapRangeToTicks(axis, ticks) {
|
1432
|
-
if (axis.options.autoscaleMargin && ticks.length > 0) {
|
1433
|
-
// snap to ticks
|
1434
|
-
if (axis.options.min == null)
|
1435
|
-
axis.min = Math.min(axis.min, ticks[0].v);
|
1436
|
-
if (axis.options.max == null && ticks.length > 1)
|
1437
|
-
axis.max = Math.max(axis.max, ticks[ticks.length - 1].v);
|
1438
|
-
}
|
1439
|
-
}
|
1440
|
-
|
1441
|
-
function draw() {
|
1442
|
-
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
1443
|
-
|
1444
|
-
var grid = options.grid;
|
1445
|
-
|
1446
|
-
// draw background, if any
|
1447
|
-
if (grid.show && grid.backgroundColor)
|
1448
|
-
drawBackground();
|
1449
|
-
|
1450
|
-
if (grid.show && !grid.aboveData) {
|
1451
|
-
drawGrid();
|
1452
|
-
drawAxisLabels();
|
1453
|
-
}
|
1454
|
-
|
1455
|
-
for (var i = 0; i < series.length; ++i) {
|
1456
|
-
executeHooks(hooks.drawSeries, [ctx, series[i]]);
|
1457
|
-
drawSeries(series[i]);
|
1458
|
-
}
|
1459
|
-
|
1460
|
-
executeHooks(hooks.draw, [ctx]);
|
1461
|
-
|
1462
|
-
if (grid.show && grid.aboveData) {
|
1463
|
-
drawGrid();
|
1464
|
-
drawAxisLabels();
|
1465
|
-
}
|
1466
|
-
}
|
1467
|
-
|
1468
|
-
function extractRange(ranges, coord) {
|
1469
|
-
var axis, from, to, key, axes = allAxes();
|
1470
|
-
|
1471
|
-
for (i = 0; i < axes.length; ++i) {
|
1472
|
-
axis = axes[i];
|
1473
|
-
if (axis.direction == coord) {
|
1474
|
-
key = coord + axis.n + "axis";
|
1475
|
-
if (!ranges[key] && axis.n == 1)
|
1476
|
-
key = coord + "axis"; // support x1axis as xaxis
|
1477
|
-
if (ranges[key]) {
|
1478
|
-
from = ranges[key].from;
|
1479
|
-
to = ranges[key].to;
|
1480
|
-
break;
|
1481
|
-
}
|
1482
|
-
}
|
1483
|
-
}
|
1484
|
-
|
1485
|
-
// backwards-compat stuff - to be removed in future
|
1486
|
-
if (!ranges[key]) {
|
1487
|
-
axis = coord == "x" ? xaxes[0] : yaxes[0];
|
1488
|
-
from = ranges[coord + "1"];
|
1489
|
-
to = ranges[coord + "2"];
|
1490
|
-
}
|
1491
|
-
|
1492
|
-
// auto-reverse as an added bonus
|
1493
|
-
if (from != null && to != null && from > to) {
|
1494
|
-
var tmp = from;
|
1495
|
-
from = to;
|
1496
|
-
to = tmp;
|
1497
|
-
}
|
1498
|
-
|
1499
|
-
return { from: from, to: to, axis: axis };
|
1500
|
-
}
|
1501
|
-
|
1502
|
-
function drawBackground() {
|
1503
|
-
ctx.save();
|
1504
|
-
ctx.translate(plotOffset.left, plotOffset.top);
|
1505
|
-
|
1506
|
-
ctx.fillStyle = getColorOrGradient(options.grid.backgroundColor, plotHeight, 0, "rgba(255, 255, 255, 0)");
|
1507
|
-
ctx.fillRect(0, 0, plotWidth, plotHeight);
|
1508
|
-
ctx.restore();
|
1509
|
-
}
|
1510
|
-
|
1511
|
-
function drawGrid() {
|
1512
|
-
var i;
|
1513
|
-
|
1514
|
-
ctx.save();
|
1515
|
-
ctx.translate(plotOffset.left, plotOffset.top);
|
1516
|
-
|
1517
|
-
// draw markings
|
1518
|
-
var markings = options.grid.markings;
|
1519
|
-
if (markings) {
|
1520
|
-
if ($.isFunction(markings)) {
|
1521
|
-
var axes = plot.getAxes();
|
1522
|
-
// xmin etc. is backwards compatibility, to be
|
1523
|
-
// removed in the future
|
1524
|
-
axes.xmin = axes.xaxis.min;
|
1525
|
-
axes.xmax = axes.xaxis.max;
|
1526
|
-
axes.ymin = axes.yaxis.min;
|
1527
|
-
axes.ymax = axes.yaxis.max;
|
1528
|
-
|
1529
|
-
markings = markings(axes);
|
1530
|
-
}
|
1531
|
-
|
1532
|
-
for (i = 0; i < markings.length; ++i) {
|
1533
|
-
var m = markings[i],
|
1534
|
-
xrange = extractRange(m, "x"),
|
1535
|
-
yrange = extractRange(m, "y");
|
1536
|
-
|
1537
|
-
// fill in missing
|
1538
|
-
if (xrange.from == null)
|
1539
|
-
xrange.from = xrange.axis.min;
|
1540
|
-
if (xrange.to == null)
|
1541
|
-
xrange.to = xrange.axis.max;
|
1542
|
-
if (yrange.from == null)
|
1543
|
-
yrange.from = yrange.axis.min;
|
1544
|
-
if (yrange.to == null)
|
1545
|
-
yrange.to = yrange.axis.max;
|
1546
|
-
|
1547
|
-
// clip
|
1548
|
-
if (xrange.to < xrange.axis.min || xrange.from > xrange.axis.max ||
|
1549
|
-
yrange.to < yrange.axis.min || yrange.from > yrange.axis.max)
|
1550
|
-
continue;
|
1551
|
-
|
1552
|
-
xrange.from = Math.max(xrange.from, xrange.axis.min);
|
1553
|
-
xrange.to = Math.min(xrange.to, xrange.axis.max);
|
1554
|
-
yrange.from = Math.max(yrange.from, yrange.axis.min);
|
1555
|
-
yrange.to = Math.min(yrange.to, yrange.axis.max);
|
1556
|
-
|
1557
|
-
if (xrange.from == xrange.to && yrange.from == yrange.to)
|
1558
|
-
continue;
|
1559
|
-
|
1560
|
-
// then draw
|
1561
|
-
xrange.from = xrange.axis.p2c(xrange.from);
|
1562
|
-
xrange.to = xrange.axis.p2c(xrange.to);
|
1563
|
-
yrange.from = yrange.axis.p2c(yrange.from);
|
1564
|
-
yrange.to = yrange.axis.p2c(yrange.to);
|
1565
|
-
|
1566
|
-
if (xrange.from == xrange.to || yrange.from == yrange.to) {
|
1567
|
-
// draw line
|
1568
|
-
ctx.beginPath();
|
1569
|
-
ctx.strokeStyle = m.color || options.grid.markingsColor;
|
1570
|
-
ctx.lineWidth = m.lineWidth || options.grid.markingsLineWidth;
|
1571
|
-
ctx.moveTo(xrange.from, yrange.from);
|
1572
|
-
ctx.lineTo(xrange.to, yrange.to);
|
1573
|
-
ctx.stroke();
|
1574
|
-
}
|
1575
|
-
else {
|
1576
|
-
// fill area
|
1577
|
-
ctx.fillStyle = m.color || options.grid.markingsColor;
|
1578
|
-
ctx.fillRect(xrange.from, yrange.to,
|
1579
|
-
xrange.to - xrange.from,
|
1580
|
-
yrange.from - yrange.to);
|
1581
|
-
}
|
1582
|
-
}
|
1583
|
-
}
|
1584
|
-
|
1585
|
-
// draw the ticks
|
1586
|
-
var axes = allAxes(), bw = options.grid.borderWidth;
|
1587
|
-
|
1588
|
-
for (var j = 0; j < axes.length; ++j) {
|
1589
|
-
var axis = axes[j], box = axis.box,
|
1590
|
-
t = axis.tickLength, x, y, xoff, yoff;
|
1591
|
-
if (!axis.show || axis.ticks.length == 0)
|
1592
|
-
continue;
|
1593
|
-
|
1594
|
-
ctx.strokeStyle = axis.options.tickColor || $.color.parse(axis.options.color).scale('a', 0.22).toString();
|
1595
|
-
ctx.lineWidth = 1;
|
1596
|
-
|
1597
|
-
// find the edges
|
1598
|
-
if (axis.direction == "x") {
|
1599
|
-
x = 0;
|
1600
|
-
if (t == "full")
|
1601
|
-
y = (axis.position == "top" ? 0 : plotHeight);
|
1602
|
-
else
|
1603
|
-
y = box.top - plotOffset.top + (axis.position == "top" ? box.height : 0);
|
1604
|
-
}
|
1605
|
-
else {
|
1606
|
-
y = 0;
|
1607
|
-
if (t == "full")
|
1608
|
-
x = (axis.position == "left" ? 0 : plotWidth);
|
1609
|
-
else
|
1610
|
-
x = box.left - plotOffset.left + (axis.position == "left" ? box.width : 0);
|
1611
|
-
}
|
1612
|
-
|
1613
|
-
// draw tick bar
|
1614
|
-
if (!axis.innermost) {
|
1615
|
-
ctx.beginPath();
|
1616
|
-
xoff = yoff = 0;
|
1617
|
-
if (axis.direction == "x")
|
1618
|
-
xoff = plotWidth;
|
1619
|
-
else
|
1620
|
-
yoff = plotHeight;
|
1621
|
-
|
1622
|
-
if (ctx.lineWidth == 1) {
|
1623
|
-
x = Math.floor(x) + 0.5;
|
1624
|
-
y = Math.floor(y) + 0.5;
|
1625
|
-
}
|
1626
|
-
|
1627
|
-
ctx.moveTo(x, y);
|
1628
|
-
ctx.lineTo(x + xoff, y + yoff);
|
1629
|
-
ctx.stroke();
|
1630
|
-
}
|
1631
|
-
|
1632
|
-
// draw ticks
|
1633
|
-
ctx.beginPath();
|
1634
|
-
for (i = 0; i < axis.ticks.length; ++i) {
|
1635
|
-
var v = axis.ticks[i].v;
|
1636
|
-
|
1637
|
-
xoff = yoff = 0;
|
1638
|
-
|
1639
|
-
if (v < axis.min || v > axis.max
|
1640
|
-
// skip those lying on the axes if we got a border
|
1641
|
-
|| (t == "full" && bw > 0
|
1642
|
-
&& (v == axis.min || v == axis.max)))
|
1643
|
-
continue;
|
1644
|
-
|
1645
|
-
if (axis.direction == "x") {
|
1646
|
-
x = axis.p2c(v);
|
1647
|
-
yoff = t == "full" ? -plotHeight : t;
|
1648
|
-
|
1649
|
-
if (axis.position == "top")
|
1650
|
-
yoff = -yoff;
|
1651
|
-
}
|
1652
|
-
else {
|
1653
|
-
y = axis.p2c(v);
|
1654
|
-
xoff = t == "full" ? -plotWidth : t;
|
1655
|
-
|
1656
|
-
if (axis.position == "left")
|
1657
|
-
xoff = -xoff;
|
1658
|
-
}
|
1659
|
-
|
1660
|
-
if (ctx.lineWidth == 1) {
|
1661
|
-
if (axis.direction == "x")
|
1662
|
-
x = Math.floor(x) + 0.5;
|
1663
|
-
else
|
1664
|
-
y = Math.floor(y) + 0.5;
|
1665
|
-
}
|
1666
|
-
|
1667
|
-
ctx.moveTo(x, y);
|
1668
|
-
ctx.lineTo(x + xoff, y + yoff);
|
1669
|
-
}
|
1670
|
-
|
1671
|
-
ctx.stroke();
|
1672
|
-
}
|
1673
|
-
|
1674
|
-
|
1675
|
-
// draw border
|
1676
|
-
if (bw) {
|
1677
|
-
ctx.lineWidth = bw;
|
1678
|
-
ctx.strokeStyle = options.grid.borderColor;
|
1679
|
-
ctx.strokeRect(-bw/2, -bw/2, plotWidth + bw, plotHeight + bw);
|
1680
|
-
}
|
1681
|
-
|
1682
|
-
ctx.restore();
|
1683
|
-
}
|
1684
|
-
|
1685
|
-
function drawAxisLabels() {
|
1686
|
-
ctx.save();
|
1687
|
-
|
1688
|
-
$.each(allAxes(), function (_, axis) {
|
1689
|
-
if (!axis.show || axis.ticks.length == 0)
|
1690
|
-
return;
|
1691
|
-
|
1692
|
-
var box = axis.box, f = axis.font;
|
1693
|
-
// placeholder.append('<div style="position:absolute;opacity:0.10;background-color:red;left:' + box.left + 'px;top:' + box.top + 'px;width:' + box.width + 'px;height:' + box.height + 'px"></div>') // debug
|
1694
|
-
|
1695
|
-
ctx.fillStyle = axis.options.color;
|
1696
|
-
// Important: Don't use quotes around axis.font.family! Just around single
|
1697
|
-
// font names like 'Times New Roman' that have a space or special character in it.
|
1698
|
-
ctx.font = f.style + " " + f.variant + " " + f.weight + " " + f.size + "px " + f.family;
|
1699
|
-
ctx.textAlign = "start";
|
1700
|
-
// middle align the labels - top would be more
|
1701
|
-
// natural, but browsers can differ a pixel or two in
|
1702
|
-
// where they consider the top to be, so instead we
|
1703
|
-
// middle align to minimize variation between browsers
|
1704
|
-
// and compensate when calculating the coordinates
|
1705
|
-
ctx.textBaseline = "middle";
|
1706
|
-
|
1707
|
-
for (var i = 0; i < axis.ticks.length; ++i) {
|
1708
|
-
var tick = axis.ticks[i];
|
1709
|
-
if (!tick.label || tick.v < axis.min || tick.v > axis.max)
|
1710
|
-
continue;
|
1711
|
-
|
1712
|
-
var x, y, offset = 0, line;
|
1713
|
-
for (var k = 0; k < tick.lines.length; ++k) {
|
1714
|
-
line = tick.lines[k];
|
1715
|
-
|
1716
|
-
if (axis.direction == "x") {
|
1717
|
-
x = plotOffset.left + axis.p2c(tick.v) - line.width/2;
|
1718
|
-
if (axis.position == "bottom")
|
1719
|
-
y = box.top + box.padding;
|
1720
|
-
else
|
1721
|
-
y = box.top + box.height - box.padding - tick.height;
|
1722
|
-
}
|
1723
|
-
else {
|
1724
|
-
y = plotOffset.top + axis.p2c(tick.v) - tick.height/2;
|
1725
|
-
if (axis.position == "left")
|
1726
|
-
x = box.left + box.width - box.padding - line.width;
|
1727
|
-
else
|
1728
|
-
x = box.left + box.padding;
|
1729
|
-
}
|
1730
|
-
|
1731
|
-
// account for middle aligning and line number
|
1732
|
-
y += line.height/2 + offset;
|
1733
|
-
offset += line.height;
|
1734
|
-
|
1735
|
-
if ($.browser.opera) {
|
1736
|
-
// FIXME: UGLY BROWSER DETECTION
|
1737
|
-
// round the coordinates since Opera
|
1738
|
-
// otherwise switches to more ugly
|
1739
|
-
// rendering (probably non-hinted) and
|
1740
|
-
// offset the y coordinates since it seems
|
1741
|
-
// to be off pretty consistently compared
|
1742
|
-
// to the other browsers
|
1743
|
-
x = Math.floor(x);
|
1744
|
-
y = Math.ceil(y - 2);
|
1745
|
-
}
|
1746
|
-
ctx.fillText(line.text, x, y);
|
1747
|
-
}
|
1748
|
-
}
|
1749
|
-
});
|
1750
|
-
|
1751
|
-
ctx.restore();
|
1752
|
-
}
|
1753
|
-
|
1754
|
-
function drawSeries(series) {
|
1755
|
-
if (series.lines.show)
|
1756
|
-
drawSeriesLines(series);
|
1757
|
-
if (series.bars.show)
|
1758
|
-
drawSeriesBars(series);
|
1759
|
-
if (series.points.show)
|
1760
|
-
drawSeriesPoints(series);
|
1761
|
-
}
|
1762
|
-
|
1763
|
-
function drawSeriesLines(series) {
|
1764
|
-
function plotLine(datapoints, xoffset, yoffset, axisx, axisy) {
|
1765
|
-
var points = datapoints.points,
|
1766
|
-
ps = datapoints.pointsize,
|
1767
|
-
prevx = null, prevy = null;
|
1768
|
-
|
1769
|
-
ctx.beginPath();
|
1770
|
-
for (var i = ps; i < points.length; i += ps) {
|
1771
|
-
var x1 = points[i - ps], y1 = points[i - ps + 1],
|
1772
|
-
x2 = points[i], y2 = points[i + 1];
|
1773
|
-
|
1774
|
-
if (x1 == null || x2 == null)
|
1775
|
-
continue;
|
1776
|
-
|
1777
|
-
// clip with ymin
|
1778
|
-
if (y1 <= y2 && y1 < axisy.min) {
|
1779
|
-
if (y2 < axisy.min)
|
1780
|
-
continue; // line segment is outside
|
1781
|
-
// compute new intersection point
|
1782
|
-
x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
|
1783
|
-
y1 = axisy.min;
|
1784
|
-
}
|
1785
|
-
else if (y2 <= y1 && y2 < axisy.min) {
|
1786
|
-
if (y1 < axisy.min)
|
1787
|
-
continue;
|
1788
|
-
x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
|
1789
|
-
y2 = axisy.min;
|
1790
|
-
}
|
1791
|
-
|
1792
|
-
// clip with ymax
|
1793
|
-
if (y1 >= y2 && y1 > axisy.max) {
|
1794
|
-
if (y2 > axisy.max)
|
1795
|
-
continue;
|
1796
|
-
x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
|
1797
|
-
y1 = axisy.max;
|
1798
|
-
}
|
1799
|
-
else if (y2 >= y1 && y2 > axisy.max) {
|
1800
|
-
if (y1 > axisy.max)
|
1801
|
-
continue;
|
1802
|
-
x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
|
1803
|
-
y2 = axisy.max;
|
1804
|
-
}
|
1805
|
-
|
1806
|
-
// clip with xmin
|
1807
|
-
if (x1 <= x2 && x1 < axisx.min) {
|
1808
|
-
if (x2 < axisx.min)
|
1809
|
-
continue;
|
1810
|
-
y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
|
1811
|
-
x1 = axisx.min;
|
1812
|
-
}
|
1813
|
-
else if (x2 <= x1 && x2 < axisx.min) {
|
1814
|
-
if (x1 < axisx.min)
|
1815
|
-
continue;
|
1816
|
-
y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
|
1817
|
-
x2 = axisx.min;
|
1818
|
-
}
|
1819
|
-
|
1820
|
-
// clip with xmax
|
1821
|
-
if (x1 >= x2 && x1 > axisx.max) {
|
1822
|
-
if (x2 > axisx.max)
|
1823
|
-
continue;
|
1824
|
-
y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
|
1825
|
-
x1 = axisx.max;
|
1826
|
-
}
|
1827
|
-
else if (x2 >= x1 && x2 > axisx.max) {
|
1828
|
-
if (x1 > axisx.max)
|
1829
|
-
continue;
|
1830
|
-
y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
|
1831
|
-
x2 = axisx.max;
|
1832
|
-
}
|
1833
|
-
|
1834
|
-
if (x1 != prevx || y1 != prevy)
|
1835
|
-
ctx.moveTo(axisx.p2c(x1) + xoffset, axisy.p2c(y1) + yoffset);
|
1836
|
-
|
1837
|
-
prevx = x2;
|
1838
|
-
prevy = y2;
|
1839
|
-
ctx.lineTo(axisx.p2c(x2) + xoffset, axisy.p2c(y2) + yoffset);
|
1840
|
-
}
|
1841
|
-
ctx.stroke();
|
1842
|
-
}
|
1843
|
-
|
1844
|
-
function plotLineArea(datapoints, axisx, axisy) {
|
1845
|
-
var points = datapoints.points,
|
1846
|
-
ps = datapoints.pointsize,
|
1847
|
-
bottom = Math.min(Math.max(0, axisy.min), axisy.max),
|
1848
|
-
i = 0, top, areaOpen = false,
|
1849
|
-
ypos = 1, segmentStart = 0, segmentEnd = 0;
|
1850
|
-
|
1851
|
-
// we process each segment in two turns, first forward
|
1852
|
-
// direction to sketch out top, then once we hit the
|
1853
|
-
// end we go backwards to sketch the bottom
|
1854
|
-
while (true) {
|
1855
|
-
if (ps > 0 && i > points.length + ps)
|
1856
|
-
break;
|
1857
|
-
|
1858
|
-
i += ps; // ps is negative if going backwards
|
1859
|
-
|
1860
|
-
var x1 = points[i - ps],
|
1861
|
-
y1 = points[i - ps + ypos],
|
1862
|
-
x2 = points[i], y2 = points[i + ypos];
|
1863
|
-
|
1864
|
-
if (areaOpen) {
|
1865
|
-
if (ps > 0 && x1 != null && x2 == null) {
|
1866
|
-
// at turning point
|
1867
|
-
segmentEnd = i;
|
1868
|
-
ps = -ps;
|
1869
|
-
ypos = 2;
|
1870
|
-
continue;
|
1871
|
-
}
|
1872
|
-
|
1873
|
-
if (ps < 0 && i == segmentStart + ps) {
|
1874
|
-
// done with the reverse sweep
|
1875
|
-
ctx.fill();
|
1876
|
-
areaOpen = false;
|
1877
|
-
ps = -ps;
|
1878
|
-
ypos = 1;
|
1879
|
-
i = segmentStart = segmentEnd + ps;
|
1880
|
-
continue;
|
1881
|
-
}
|
1882
|
-
}
|
1883
|
-
|
1884
|
-
if (x1 == null || x2 == null)
|
1885
|
-
continue;
|
1886
|
-
|
1887
|
-
// clip x values
|
1888
|
-
|
1889
|
-
// clip with xmin
|
1890
|
-
if (x1 <= x2 && x1 < axisx.min) {
|
1891
|
-
if (x2 < axisx.min)
|
1892
|
-
continue;
|
1893
|
-
y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
|
1894
|
-
x1 = axisx.min;
|
1895
|
-
}
|
1896
|
-
else if (x2 <= x1 && x2 < axisx.min) {
|
1897
|
-
if (x1 < axisx.min)
|
1898
|
-
continue;
|
1899
|
-
y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
|
1900
|
-
x2 = axisx.min;
|
1901
|
-
}
|
1902
|
-
|
1903
|
-
// clip with xmax
|
1904
|
-
if (x1 >= x2 && x1 > axisx.max) {
|
1905
|
-
if (x2 > axisx.max)
|
1906
|
-
continue;
|
1907
|
-
y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
|
1908
|
-
x1 = axisx.max;
|
1909
|
-
}
|
1910
|
-
else if (x2 >= x1 && x2 > axisx.max) {
|
1911
|
-
if (x1 > axisx.max)
|
1912
|
-
continue;
|
1913
|
-
y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
|
1914
|
-
x2 = axisx.max;
|
1915
|
-
}
|
1916
|
-
|
1917
|
-
if (!areaOpen) {
|
1918
|
-
// open area
|
1919
|
-
ctx.beginPath();
|
1920
|
-
ctx.moveTo(axisx.p2c(x1), axisy.p2c(bottom));
|
1921
|
-
areaOpen = true;
|
1922
|
-
}
|
1923
|
-
|
1924
|
-
// now first check the case where both is outside
|
1925
|
-
if (y1 >= axisy.max && y2 >= axisy.max) {
|
1926
|
-
ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.max));
|
1927
|
-
ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.max));
|
1928
|
-
continue;
|
1929
|
-
}
|
1930
|
-
else if (y1 <= axisy.min && y2 <= axisy.min) {
|
1931
|
-
ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.min));
|
1932
|
-
ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.min));
|
1933
|
-
continue;
|
1934
|
-
}
|
1935
|
-
|
1936
|
-
// else it's a bit more complicated, there might
|
1937
|
-
// be a flat maxed out rectangle first, then a
|
1938
|
-
// triangular cutout or reverse; to find these
|
1939
|
-
// keep track of the current x values
|
1940
|
-
var x1old = x1, x2old = x2;
|
1941
|
-
|
1942
|
-
// clip the y values, without shortcutting, we
|
1943
|
-
// go through all cases in turn
|
1944
|
-
|
1945
|
-
// clip with ymin
|
1946
|
-
if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) {
|
1947
|
-
x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
|
1948
|
-
y1 = axisy.min;
|
1949
|
-
}
|
1950
|
-
else if (y2 <= y1 && y2 < axisy.min && y1 >= axisy.min) {
|
1951
|
-
x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
|
1952
|
-
y2 = axisy.min;
|
1953
|
-
}
|
1954
|
-
|
1955
|
-
// clip with ymax
|
1956
|
-
if (y1 >= y2 && y1 > axisy.max && y2 <= axisy.max) {
|
1957
|
-
x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
|
1958
|
-
y1 = axisy.max;
|
1959
|
-
}
|
1960
|
-
else if (y2 >= y1 && y2 > axisy.max && y1 <= axisy.max) {
|
1961
|
-
x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
|
1962
|
-
y2 = axisy.max;
|
1963
|
-
}
|
1964
|
-
|
1965
|
-
// if the x value was changed we got a rectangle
|
1966
|
-
// to fill
|
1967
|
-
if (x1 != x1old) {
|
1968
|
-
ctx.lineTo(axisx.p2c(x1old), axisy.p2c(y1));
|
1969
|
-
// it goes to (x1, y1), but we fill that below
|
1970
|
-
}
|
1971
|
-
|
1972
|
-
// fill triangular section, this sometimes result
|
1973
|
-
// in redundant points if (x1, y1) hasn't changed
|
1974
|
-
// from previous line to, but we just ignore that
|
1975
|
-
ctx.lineTo(axisx.p2c(x1), axisy.p2c(y1));
|
1976
|
-
ctx.lineTo(axisx.p2c(x2), axisy.p2c(y2));
|
1977
|
-
|
1978
|
-
// fill the other rectangle if it's there
|
1979
|
-
if (x2 != x2old) {
|
1980
|
-
ctx.lineTo(axisx.p2c(x2), axisy.p2c(y2));
|
1981
|
-
ctx.lineTo(axisx.p2c(x2old), axisy.p2c(y2));
|
1982
|
-
}
|
1983
|
-
}
|
1984
|
-
}
|
1985
|
-
|
1986
|
-
ctx.save();
|
1987
|
-
ctx.translate(plotOffset.left, plotOffset.top);
|
1988
|
-
ctx.lineJoin = "round";
|
1989
|
-
|
1990
|
-
var lw = series.lines.lineWidth,
|
1991
|
-
sw = series.shadowSize;
|
1992
|
-
// FIXME: consider another form of shadow when filling is turned on
|
1993
|
-
if (lw > 0 && sw > 0) {
|
1994
|
-
// draw shadow as a thick and thin line with transparency
|
1995
|
-
ctx.lineWidth = sw;
|
1996
|
-
ctx.strokeStyle = "rgba(0,0,0,0.1)";
|
1997
|
-
// position shadow at angle from the mid of line
|
1998
|
-
var angle = Math.PI/18;
|
1999
|
-
plotLine(series.datapoints, Math.sin(angle) * (lw/2 + sw/2), Math.cos(angle) * (lw/2 + sw/2), series.xaxis, series.yaxis);
|
2000
|
-
ctx.lineWidth = sw/2;
|
2001
|
-
plotLine(series.datapoints, Math.sin(angle) * (lw/2 + sw/4), Math.cos(angle) * (lw/2 + sw/4), series.xaxis, series.yaxis);
|
2002
|
-
}
|
2003
|
-
|
2004
|
-
ctx.lineWidth = lw;
|
2005
|
-
ctx.strokeStyle = series.color;
|
2006
|
-
var fillStyle = getFillStyle(series.lines, series.color, 0, plotHeight);
|
2007
|
-
if (fillStyle) {
|
2008
|
-
ctx.fillStyle = fillStyle;
|
2009
|
-
plotLineArea(series.datapoints, series.xaxis, series.yaxis);
|
2010
|
-
}
|
2011
|
-
|
2012
|
-
if (lw > 0)
|
2013
|
-
plotLine(series.datapoints, 0, 0, series.xaxis, series.yaxis);
|
2014
|
-
ctx.restore();
|
2015
|
-
}
|
2016
|
-
|
2017
|
-
function drawSeriesPoints(series) {
|
2018
|
-
function plotPoints(datapoints, radius, fillStyle, offset, shadow, axisx, axisy, symbol) {
|
2019
|
-
var points = datapoints.points, ps = datapoints.pointsize;
|
2020
|
-
|
2021
|
-
for (var i = 0; i < points.length; i += ps) {
|
2022
|
-
var x = points[i], y = points[i + 1];
|
2023
|
-
if (x == null || x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max)
|
2024
|
-
continue;
|
2025
|
-
|
2026
|
-
ctx.beginPath();
|
2027
|
-
x = axisx.p2c(x);
|
2028
|
-
y = axisy.p2c(y) + offset;
|
2029
|
-
if (symbol == "circle")
|
2030
|
-
ctx.arc(x, y, radius, 0, shadow ? Math.PI : Math.PI * 2, false);
|
2031
|
-
else
|
2032
|
-
symbol(ctx, x, y, radius, shadow);
|
2033
|
-
ctx.closePath();
|
2034
|
-
|
2035
|
-
if (fillStyle) {
|
2036
|
-
ctx.fillStyle = fillStyle;
|
2037
|
-
ctx.fill();
|
2038
|
-
}
|
2039
|
-
ctx.stroke();
|
2040
|
-
}
|
2041
|
-
}
|
2042
|
-
|
2043
|
-
ctx.save();
|
2044
|
-
ctx.translate(plotOffset.left, plotOffset.top);
|
2045
|
-
|
2046
|
-
var lw = series.points.lineWidth,
|
2047
|
-
sw = series.shadowSize,
|
2048
|
-
radius = series.points.radius,
|
2049
|
-
symbol = series.points.symbol;
|
2050
|
-
if (lw > 0 && sw > 0) {
|
2051
|
-
// draw shadow in two steps
|
2052
|
-
var w = sw / 2;
|
2053
|
-
ctx.lineWidth = w;
|
2054
|
-
ctx.strokeStyle = "rgba(0,0,0,0.1)";
|
2055
|
-
plotPoints(series.datapoints, radius, null, w + w/2, true,
|
2056
|
-
series.xaxis, series.yaxis, symbol);
|
2057
|
-
|
2058
|
-
ctx.strokeStyle = "rgba(0,0,0,0.2)";
|
2059
|
-
plotPoints(series.datapoints, radius, null, w/2, true,
|
2060
|
-
series.xaxis, series.yaxis, symbol);
|
2061
|
-
}
|
2062
|
-
|
2063
|
-
ctx.lineWidth = lw;
|
2064
|
-
ctx.strokeStyle = series.color;
|
2065
|
-
plotPoints(series.datapoints, radius,
|
2066
|
-
getFillStyle(series.points, series.color), 0, false,
|
2067
|
-
series.xaxis, series.yaxis, symbol);
|
2068
|
-
ctx.restore();
|
2069
|
-
}
|
2070
|
-
|
2071
|
-
function drawBar(x, y, b, barLeft, barRight, offset, fillStyleCallback, axisx, axisy, c, horizontal, lineWidth) {
|
2072
|
-
var left, right, bottom, top,
|
2073
|
-
drawLeft, drawRight, drawTop, drawBottom,
|
2074
|
-
tmp;
|
2075
|
-
|
2076
|
-
// in horizontal mode, we start the bar from the left
|
2077
|
-
// instead of from the bottom so it appears to be
|
2078
|
-
// horizontal rather than vertical
|
2079
|
-
if (horizontal) {
|
2080
|
-
drawBottom = drawRight = drawTop = true;
|
2081
|
-
drawLeft = false;
|
2082
|
-
left = b;
|
2083
|
-
right = x;
|
2084
|
-
top = y + barLeft;
|
2085
|
-
bottom = y + barRight;
|
2086
|
-
|
2087
|
-
// account for negative bars
|
2088
|
-
if (right < left) {
|
2089
|
-
tmp = right;
|
2090
|
-
right = left;
|
2091
|
-
left = tmp;
|
2092
|
-
drawLeft = true;
|
2093
|
-
drawRight = false;
|
2094
|
-
}
|
2095
|
-
}
|
2096
|
-
else {
|
2097
|
-
drawLeft = drawRight = drawTop = true;
|
2098
|
-
drawBottom = false;
|
2099
|
-
left = x + barLeft;
|
2100
|
-
right = x + barRight;
|
2101
|
-
bottom = b;
|
2102
|
-
top = y;
|
2103
|
-
|
2104
|
-
// account for negative bars
|
2105
|
-
if (top < bottom) {
|
2106
|
-
tmp = top;
|
2107
|
-
top = bottom;
|
2108
|
-
bottom = tmp;
|
2109
|
-
drawBottom = true;
|
2110
|
-
drawTop = false;
|
2111
|
-
}
|
2112
|
-
}
|
2113
|
-
|
2114
|
-
// clip
|
2115
|
-
if (right < axisx.min || left > axisx.max ||
|
2116
|
-
top < axisy.min || bottom > axisy.max)
|
2117
|
-
return;
|
2118
|
-
|
2119
|
-
if (left < axisx.min) {
|
2120
|
-
left = axisx.min;
|
2121
|
-
drawLeft = false;
|
2122
|
-
}
|
2123
|
-
|
2124
|
-
if (right > axisx.max) {
|
2125
|
-
right = axisx.max;
|
2126
|
-
drawRight = false;
|
2127
|
-
}
|
2128
|
-
|
2129
|
-
if (bottom < axisy.min) {
|
2130
|
-
bottom = axisy.min;
|
2131
|
-
drawBottom = false;
|
2132
|
-
}
|
2133
|
-
|
2134
|
-
if (top > axisy.max) {
|
2135
|
-
top = axisy.max;
|
2136
|
-
drawTop = false;
|
2137
|
-
}
|
2138
|
-
|
2139
|
-
left = axisx.p2c(left);
|
2140
|
-
bottom = axisy.p2c(bottom);
|
2141
|
-
right = axisx.p2c(right);
|
2142
|
-
top = axisy.p2c(top);
|
2143
|
-
|
2144
|
-
// fill the bar
|
2145
|
-
if (fillStyleCallback) {
|
2146
|
-
c.beginPath();
|
2147
|
-
c.moveTo(left, bottom);
|
2148
|
-
c.lineTo(left, top);
|
2149
|
-
c.lineTo(right, top);
|
2150
|
-
c.lineTo(right, bottom);
|
2151
|
-
c.fillStyle = fillStyleCallback(bottom, top);
|
2152
|
-
c.fill();
|
2153
|
-
}
|
2154
|
-
|
2155
|
-
// draw outline
|
2156
|
-
if (lineWidth > 0 && (drawLeft || drawRight || drawTop || drawBottom)) {
|
2157
|
-
c.beginPath();
|
2158
|
-
|
2159
|
-
// FIXME: inline moveTo is buggy with excanvas
|
2160
|
-
c.moveTo(left, bottom + offset);
|
2161
|
-
if (drawLeft)
|
2162
|
-
c.lineTo(left, top + offset);
|
2163
|
-
else
|
2164
|
-
c.moveTo(left, top + offset);
|
2165
|
-
if (drawTop)
|
2166
|
-
c.lineTo(right, top + offset);
|
2167
|
-
else
|
2168
|
-
c.moveTo(right, top + offset);
|
2169
|
-
if (drawRight)
|
2170
|
-
c.lineTo(right, bottom + offset);
|
2171
|
-
else
|
2172
|
-
c.moveTo(right, bottom + offset);
|
2173
|
-
if (drawBottom)
|
2174
|
-
c.lineTo(left, bottom + offset);
|
2175
|
-
else
|
2176
|
-
c.moveTo(left, bottom + offset);
|
2177
|
-
c.stroke();
|
2178
|
-
}
|
2179
|
-
}
|
2180
|
-
|
2181
|
-
function drawSeriesBars(series) {
|
2182
|
-
function plotBars(datapoints, barLeft, barRight, offset, fillStyleCallback, axisx, axisy) {
|
2183
|
-
var points = datapoints.points, ps = datapoints.pointsize;
|
2184
|
-
|
2185
|
-
for (var i = 0; i < points.length; i += ps) {
|
2186
|
-
if (points[i] == null)
|
2187
|
-
continue;
|
2188
|
-
drawBar(points[i], points[i + 1], points[i + 2], barLeft, barRight, offset, fillStyleCallback, axisx, axisy, ctx, series.bars.horizontal, series.bars.lineWidth);
|
2189
|
-
}
|
2190
|
-
}
|
2191
|
-
|
2192
|
-
ctx.save();
|
2193
|
-
ctx.translate(plotOffset.left, plotOffset.top);
|
2194
|
-
|
2195
|
-
// FIXME: figure out a way to add shadows (for instance along the right edge)
|
2196
|
-
ctx.lineWidth = series.bars.lineWidth;
|
2197
|
-
ctx.strokeStyle = series.color;
|
2198
|
-
var barLeft = series.bars.align == "left" ? 0 : -series.bars.barWidth/2;
|
2199
|
-
var fillStyleCallback = series.bars.fill ? function (bottom, top) { return getFillStyle(series.bars, series.color, bottom, top); } : null;
|
2200
|
-
plotBars(series.datapoints, barLeft, barLeft + series.bars.barWidth, 0, fillStyleCallback, series.xaxis, series.yaxis);
|
2201
|
-
ctx.restore();
|
2202
|
-
}
|
2203
|
-
|
2204
|
-
function getFillStyle(filloptions, seriesColor, bottom, top) {
|
2205
|
-
var fill = filloptions.fill;
|
2206
|
-
if (!fill)
|
2207
|
-
return null;
|
2208
|
-
|
2209
|
-
if (filloptions.fillColor)
|
2210
|
-
return getColorOrGradient(filloptions.fillColor, bottom, top, seriesColor);
|
2211
|
-
|
2212
|
-
var c = $.color.parse(seriesColor);
|
2213
|
-
c.a = typeof fill == "number" ? fill : 0.4;
|
2214
|
-
c.normalize();
|
2215
|
-
return c.toString();
|
2216
|
-
}
|
2217
|
-
|
2218
|
-
function insertLegend() {
|
2219
|
-
placeholder.find(".legend").remove();
|
2220
|
-
|
2221
|
-
if (!options.legend.show)
|
2222
|
-
return;
|
2223
|
-
|
2224
|
-
var fragments = [], rowStarted = false,
|
2225
|
-
lf = options.legend.labelFormatter, s, label;
|
2226
|
-
for (var i = 0; i < series.length; ++i) {
|
2227
|
-
s = series[i];
|
2228
|
-
label = s.label;
|
2229
|
-
if (!label)
|
2230
|
-
continue;
|
2231
|
-
|
2232
|
-
if (i % options.legend.noColumns == 0) {
|
2233
|
-
if (rowStarted)
|
2234
|
-
fragments.push('</tr>');
|
2235
|
-
fragments.push('<tr>');
|
2236
|
-
rowStarted = true;
|
2237
|
-
}
|
2238
|
-
|
2239
|
-
if (lf)
|
2240
|
-
label = lf(label, s);
|
2241
|
-
|
2242
|
-
fragments.push(
|
2243
|
-
'<td class="legendColorBox"><div style="border:1px solid ' + options.legend.labelBoxBorderColor + ';padding:1px"><div style="width:4px;height:0;border:5px solid ' + s.color + ';overflow:hidden"></div></div></td>' +
|
2244
|
-
'<td class="legendLabel">' + label + '</td>');
|
2245
|
-
}
|
2246
|
-
if (rowStarted)
|
2247
|
-
fragments.push('</tr>');
|
2248
|
-
|
2249
|
-
if (fragments.length == 0)
|
2250
|
-
return;
|
2251
|
-
|
2252
|
-
var table = '<table style="font-size:smaller;color:' + options.grid.color + '">' + fragments.join("") + '</table>';
|
2253
|
-
if (options.legend.container != null)
|
2254
|
-
$(options.legend.container).html(table);
|
2255
|
-
else {
|
2256
|
-
var pos = "",
|
2257
|
-
p = options.legend.position,
|
2258
|
-
m = options.legend.margin;
|
2259
|
-
if (m[0] == null)
|
2260
|
-
m = [m, m];
|
2261
|
-
if (p.charAt(0) == "n")
|
2262
|
-
pos += 'top:' + (m[1] + plotOffset.top) + 'px;';
|
2263
|
-
else if (p.charAt(0) == "s")
|
2264
|
-
pos += 'bottom:' + (m[1] + plotOffset.bottom) + 'px;';
|
2265
|
-
if (p.charAt(1) == "e")
|
2266
|
-
pos += 'right:' + (m[0] + plotOffset.right) + 'px;';
|
2267
|
-
else if (p.charAt(1) == "w")
|
2268
|
-
pos += 'left:' + (m[0] + plotOffset.left) + 'px;';
|
2269
|
-
var legend = $('<div class="legend">' + table.replace('style="', 'style="position:absolute;' + pos +';') + '</div>').appendTo(placeholder);
|
2270
|
-
if (options.legend.backgroundOpacity != 0.0) {
|
2271
|
-
// put in the transparent background
|
2272
|
-
// separately to avoid blended labels and
|
2273
|
-
// label boxes
|
2274
|
-
var c = options.legend.backgroundColor;
|
2275
|
-
if (c == null) {
|
2276
|
-
c = options.grid.backgroundColor;
|
2277
|
-
if (c && typeof c == "string")
|
2278
|
-
c = $.color.parse(c);
|
2279
|
-
else
|
2280
|
-
c = $.color.extract(legend, 'background-color');
|
2281
|
-
c.a = 1;
|
2282
|
-
c = c.toString();
|
2283
|
-
}
|
2284
|
-
var div = legend.children();
|
2285
|
-
$('<div style="position:absolute;width:' + div.width() + 'px;height:' + div.height() + 'px;' + pos +'background-color:' + c + ';"> </div>').prependTo(legend).css('opacity', options.legend.backgroundOpacity);
|
2286
|
-
}
|
2287
|
-
}
|
2288
|
-
}
|
2289
|
-
|
2290
|
-
|
2291
|
-
// interactive features
|
2292
|
-
|
2293
|
-
var highlights = [],
|
2294
|
-
redrawTimeout = null;
|
2295
|
-
|
2296
|
-
// returns the data item the mouse is over, or null if none is found
|
2297
|
-
function findNearbyItem(mouseX, mouseY, seriesFilter) {
|
2298
|
-
var maxDistance = options.grid.mouseActiveRadius,
|
2299
|
-
smallestDistance = maxDistance * maxDistance + 1,
|
2300
|
-
item = null, foundPoint = false, i, j;
|
2301
|
-
|
2302
|
-
for (i = series.length - 1; i >= 0; --i) {
|
2303
|
-
if (!seriesFilter(series[i]))
|
2304
|
-
continue;
|
2305
|
-
|
2306
|
-
var s = series[i],
|
2307
|
-
axisx = s.xaxis,
|
2308
|
-
axisy = s.yaxis,
|
2309
|
-
points = s.datapoints.points,
|
2310
|
-
ps = s.datapoints.pointsize,
|
2311
|
-
mx = axisx.c2p(mouseX), // precompute some stuff to make the loop faster
|
2312
|
-
my = axisy.c2p(mouseY),
|
2313
|
-
maxx = maxDistance / axisx.scale,
|
2314
|
-
maxy = maxDistance / axisy.scale;
|
2315
|
-
|
2316
|
-
// with inverse transforms, we can't use the maxx/maxy
|
2317
|
-
// optimization, sadly
|
2318
|
-
if (axisx.options.inverseTransform)
|
2319
|
-
maxx = Number.MAX_VALUE;
|
2320
|
-
if (axisy.options.inverseTransform)
|
2321
|
-
maxy = Number.MAX_VALUE;
|
2322
|
-
|
2323
|
-
if (s.lines.show || s.points.show) {
|
2324
|
-
for (j = 0; j < points.length; j += ps) {
|
2325
|
-
var x = points[j], y = points[j + 1];
|
2326
|
-
if (x == null)
|
2327
|
-
continue;
|
2328
|
-
|
2329
|
-
// For points and lines, the cursor must be within a
|
2330
|
-
// certain distance to the data point
|
2331
|
-
if (x - mx > maxx || x - mx < -maxx ||
|
2332
|
-
y - my > maxy || y - my < -maxy)
|
2333
|
-
continue;
|
2334
|
-
|
2335
|
-
// We have to calculate distances in pixels, not in
|
2336
|
-
// data units, because the scales of the axes may be different
|
2337
|
-
var dx = Math.abs(axisx.p2c(x) - mouseX),
|
2338
|
-
dy = Math.abs(axisy.p2c(y) - mouseY),
|
2339
|
-
dist = dx * dx + dy * dy; // we save the sqrt
|
2340
|
-
|
2341
|
-
// use <= to ensure last point takes precedence
|
2342
|
-
// (last generally means on top of)
|
2343
|
-
if (dist < smallestDistance) {
|
2344
|
-
smallestDistance = dist;
|
2345
|
-
item = [i, j / ps];
|
2346
|
-
}
|
2347
|
-
}
|
2348
|
-
}
|
2349
|
-
|
2350
|
-
if (s.bars.show && !item) { // no other point can be nearby
|
2351
|
-
var barLeft = s.bars.align == "left" ? 0 : -s.bars.barWidth/2,
|
2352
|
-
barRight = barLeft + s.bars.barWidth;
|
2353
|
-
|
2354
|
-
for (j = 0; j < points.length; j += ps) {
|
2355
|
-
var x = points[j], y = points[j + 1], b = points[j + 2];
|
2356
|
-
if (x == null)
|
2357
|
-
continue;
|
2358
|
-
|
2359
|
-
// for a bar graph, the cursor must be inside the bar
|
2360
|
-
if (series[i].bars.horizontal ?
|
2361
|
-
(mx <= Math.max(b, x) && mx >= Math.min(b, x) &&
|
2362
|
-
my >= y + barLeft && my <= y + barRight) :
|
2363
|
-
(mx >= x + barLeft && mx <= x + barRight &&
|
2364
|
-
my >= Math.min(b, y) && my <= Math.max(b, y)))
|
2365
|
-
item = [i, j / ps];
|
2366
|
-
}
|
2367
|
-
}
|
2368
|
-
}
|
2369
|
-
|
2370
|
-
if (item) {
|
2371
|
-
i = item[0];
|
2372
|
-
j = item[1];
|
2373
|
-
ps = series[i].datapoints.pointsize;
|
2374
|
-
|
2375
|
-
return { datapoint: series[i].datapoints.points.slice(j * ps, (j + 1) * ps),
|
2376
|
-
dataIndex: j,
|
2377
|
-
series: series[i],
|
2378
|
-
seriesIndex: i };
|
2379
|
-
}
|
2380
|
-
|
2381
|
-
return null;
|
2382
|
-
}
|
2383
|
-
|
2384
|
-
function onMouseMove(e) {
|
2385
|
-
if (options.grid.hoverable)
|
2386
|
-
triggerClickHoverEvent("plothover", e,
|
2387
|
-
function (s) { return s["hoverable"] != false; });
|
2388
|
-
}
|
2389
|
-
|
2390
|
-
function onMouseLeave(e) {
|
2391
|
-
if (options.grid.hoverable)
|
2392
|
-
triggerClickHoverEvent("plothover", e,
|
2393
|
-
function (s) { return false; });
|
2394
|
-
}
|
2395
|
-
|
2396
|
-
function onClick(e) {
|
2397
|
-
triggerClickHoverEvent("plotclick", e,
|
2398
|
-
function (s) { return s["clickable"] != false; });
|
2399
|
-
}
|
2400
|
-
|
2401
|
-
// trigger click or hover event (they send the same parameters
|
2402
|
-
// so we share their code)
|
2403
|
-
function triggerClickHoverEvent(eventname, event, seriesFilter) {
|
2404
|
-
var offset = eventHolder.offset(),
|
2405
|
-
canvasX = event.pageX - offset.left - plotOffset.left,
|
2406
|
-
canvasY = event.pageY - offset.top - plotOffset.top,
|
2407
|
-
pos = canvasToAxisCoords({ left: canvasX, top: canvasY });
|
2408
|
-
|
2409
|
-
pos.pageX = event.pageX;
|
2410
|
-
pos.pageY = event.pageY;
|
2411
|
-
|
2412
|
-
var item = findNearbyItem(canvasX, canvasY, seriesFilter);
|
2413
|
-
|
2414
|
-
if (item) {
|
2415
|
-
// fill in mouse pos for any listeners out there
|
2416
|
-
item.pageX = parseInt(item.series.xaxis.p2c(item.datapoint[0]) + offset.left + plotOffset.left);
|
2417
|
-
item.pageY = parseInt(item.series.yaxis.p2c(item.datapoint[1]) + offset.top + plotOffset.top);
|
2418
|
-
}
|
2419
|
-
|
2420
|
-
if (options.grid.autoHighlight) {
|
2421
|
-
// clear auto-highlights
|
2422
|
-
for (var i = 0; i < highlights.length; ++i) {
|
2423
|
-
var h = highlights[i];
|
2424
|
-
if (h.auto == eventname &&
|
2425
|
-
!(item && h.series == item.series &&
|
2426
|
-
h.point[0] == item.datapoint[0] &&
|
2427
|
-
h.point[1] == item.datapoint[1]))
|
2428
|
-
unhighlight(h.series, h.point);
|
2429
|
-
}
|
2430
|
-
|
2431
|
-
if (item)
|
2432
|
-
highlight(item.series, item.datapoint, eventname);
|
2433
|
-
}
|
2434
|
-
|
2435
|
-
placeholder.trigger(eventname, [ pos, item ]);
|
2436
|
-
}
|
2437
|
-
|
2438
|
-
function triggerRedrawOverlay() {
|
2439
|
-
var t = options.interaction.redrawOverlayInterval;
|
2440
|
-
if (t == -1) { // skip event queue
|
2441
|
-
drawOverlay();
|
2442
|
-
return;
|
2443
|
-
}
|
2444
|
-
|
2445
|
-
if (!redrawTimeout)
|
2446
|
-
redrawTimeout = setTimeout(drawOverlay, t);
|
2447
|
-
}
|
2448
|
-
|
2449
|
-
function drawOverlay() {
|
2450
|
-
redrawTimeout = null;
|
2451
|
-
|
2452
|
-
// draw highlights
|
2453
|
-
octx.save();
|
2454
|
-
octx.clearRect(0, 0, canvasWidth, canvasHeight);
|
2455
|
-
octx.translate(plotOffset.left, plotOffset.top);
|
2456
|
-
|
2457
|
-
var i, hi;
|
2458
|
-
for (i = 0; i < highlights.length; ++i) {
|
2459
|
-
hi = highlights[i];
|
2460
|
-
|
2461
|
-
if (hi.series.bars.show)
|
2462
|
-
drawBarHighlight(hi.series, hi.point);
|
2463
|
-
else
|
2464
|
-
drawPointHighlight(hi.series, hi.point);
|
2465
|
-
}
|
2466
|
-
octx.restore();
|
2467
|
-
|
2468
|
-
executeHooks(hooks.drawOverlay, [octx]);
|
2469
|
-
}
|
2470
|
-
|
2471
|
-
function highlight(s, point, auto) {
|
2472
|
-
if (typeof s == "number")
|
2473
|
-
s = series[s];
|
2474
|
-
|
2475
|
-
if (typeof point == "number") {
|
2476
|
-
var ps = s.datapoints.pointsize;
|
2477
|
-
point = s.datapoints.points.slice(ps * point, ps * (point + 1));
|
2478
|
-
}
|
2479
|
-
|
2480
|
-
var i = indexOfHighlight(s, point);
|
2481
|
-
if (i == -1) {
|
2482
|
-
highlights.push({ series: s, point: point, auto: auto });
|
2483
|
-
|
2484
|
-
triggerRedrawOverlay();
|
2485
|
-
}
|
2486
|
-
else if (!auto)
|
2487
|
-
highlights[i].auto = false;
|
2488
|
-
}
|
2489
|
-
|
2490
|
-
function unhighlight(s, point) {
|
2491
|
-
if (s == null && point == null) {
|
2492
|
-
highlights = [];
|
2493
|
-
triggerRedrawOverlay();
|
2494
|
-
}
|
2495
|
-
|
2496
|
-
if (typeof s == "number")
|
2497
|
-
s = series[s];
|
2498
|
-
|
2499
|
-
if (typeof point == "number")
|
2500
|
-
point = s.data[point];
|
2501
|
-
|
2502
|
-
var i = indexOfHighlight(s, point);
|
2503
|
-
if (i != -1) {
|
2504
|
-
highlights.splice(i, 1);
|
2505
|
-
|
2506
|
-
triggerRedrawOverlay();
|
2507
|
-
}
|
2508
|
-
}
|
2509
|
-
|
2510
|
-
function indexOfHighlight(s, p) {
|
2511
|
-
for (var i = 0; i < highlights.length; ++i) {
|
2512
|
-
var h = highlights[i];
|
2513
|
-
if (h.series == s && h.point[0] == p[0]
|
2514
|
-
&& h.point[1] == p[1])
|
2515
|
-
return i;
|
2516
|
-
}
|
2517
|
-
return -1;
|
2518
|
-
}
|
2519
|
-
|
2520
|
-
function drawPointHighlight(series, point) {
|
2521
|
-
var x = point[0], y = point[1],
|
2522
|
-
axisx = series.xaxis, axisy = series.yaxis;
|
2523
|
-
|
2524
|
-
if (x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max)
|
2525
|
-
return;
|
2526
|
-
|
2527
|
-
var pointRadius = series.points.radius + series.points.lineWidth / 2;
|
2528
|
-
octx.lineWidth = pointRadius;
|
2529
|
-
octx.strokeStyle = $.color.parse(series.color).scale('a', 0.5).toString();
|
2530
|
-
var radius = 1.5 * pointRadius,
|
2531
|
-
x = axisx.p2c(x),
|
2532
|
-
y = axisy.p2c(y);
|
2533
|
-
|
2534
|
-
octx.beginPath();
|
2535
|
-
if (series.points.symbol == "circle")
|
2536
|
-
octx.arc(x, y, radius, 0, 2 * Math.PI, false);
|
2537
|
-
else
|
2538
|
-
series.points.symbol(octx, x, y, radius, false);
|
2539
|
-
octx.closePath();
|
2540
|
-
octx.stroke();
|
2541
|
-
}
|
2542
|
-
|
2543
|
-
function drawBarHighlight(series, point) {
|
2544
|
-
octx.lineWidth = series.bars.lineWidth;
|
2545
|
-
octx.strokeStyle = $.color.parse(series.color).scale('a', 0.5).toString();
|
2546
|
-
var fillStyle = $.color.parse(series.color).scale('a', 0.5).toString();
|
2547
|
-
var barLeft = series.bars.align == "left" ? 0 : -series.bars.barWidth/2;
|
2548
|
-
drawBar(point[0], point[1], point[2] || 0, barLeft, barLeft + series.bars.barWidth,
|
2549
|
-
0, function () { return fillStyle; }, series.xaxis, series.yaxis, octx, series.bars.horizontal, series.bars.lineWidth);
|
2550
|
-
}
|
2551
|
-
|
2552
|
-
function getColorOrGradient(spec, bottom, top, defaultColor) {
|
2553
|
-
if (typeof spec == "string")
|
2554
|
-
return spec;
|
2555
|
-
else {
|
2556
|
-
// assume this is a gradient spec; IE currently only
|
2557
|
-
// supports a simple vertical gradient properly, so that's
|
2558
|
-
// what we support too
|
2559
|
-
var gradient = ctx.createLinearGradient(0, top, 0, bottom);
|
2560
|
-
|
2561
|
-
for (var i = 0, l = spec.colors.length; i < l; ++i) {
|
2562
|
-
var c = spec.colors[i];
|
2563
|
-
if (typeof c != "string") {
|
2564
|
-
var co = $.color.parse(defaultColor);
|
2565
|
-
if (c.brightness != null)
|
2566
|
-
co = co.scale('rgb', c.brightness);
|
2567
|
-
if (c.opacity != null)
|
2568
|
-
co.a *= c.opacity;
|
2569
|
-
c = co.toString();
|
2570
|
-
}
|
2571
|
-
gradient.addColorStop(i / (l - 1), c);
|
2572
|
-
}
|
2573
|
-
|
2574
|
-
return gradient;
|
2575
|
-
}
|
2576
|
-
}
|
2577
|
-
}
|
2578
|
-
|
2579
|
-
$.plot = function(placeholder, data, options) {
|
2580
|
-
//var t0 = new Date();
|
2581
|
-
var plot = new Plot($(placeholder), data, options, $.plot.plugins);
|
2582
|
-
//(window.console ? console.log : alert)("time used (msecs): " + ((new Date()).getTime() - t0.getTime()));
|
2583
|
-
return plot;
|
2584
|
-
};
|
2585
|
-
|
2586
|
-
$.plot.version = "0.7";
|
2587
|
-
|
2588
|
-
$.plot.plugins = [];
|
2589
|
-
|
2590
|
-
// returns a string with the date d formatted according to fmt
|
2591
|
-
$.plot.formatDate = function(d, fmt, monthNames) {
|
2592
|
-
var leftPad = function(n) {
|
2593
|
-
n = "" + n;
|
2594
|
-
return n.length == 1 ? "0" + n : n;
|
2595
|
-
};
|
2596
|
-
|
2597
|
-
var r = [];
|
2598
|
-
var escape = false, padNext = false;
|
2599
|
-
var hours = d.getUTCHours();
|
2600
|
-
var isAM = hours < 12;
|
2601
|
-
if (monthNames == null)
|
2602
|
-
monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
2603
|
-
|
2604
|
-
if (fmt.search(/%p|%P/) != -1) {
|
2605
|
-
if (hours > 12) {
|
2606
|
-
hours = hours - 12;
|
2607
|
-
} else if (hours == 0) {
|
2608
|
-
hours = 12;
|
2609
|
-
}
|
2610
|
-
}
|
2611
|
-
for (var i = 0; i < fmt.length; ++i) {
|
2612
|
-
var c = fmt.charAt(i);
|
2613
|
-
|
2614
|
-
if (escape) {
|
2615
|
-
switch (c) {
|
2616
|
-
case 'h': c = "" + hours; break;
|
2617
|
-
case 'H': c = leftPad(hours); break;
|
2618
|
-
case 'M': c = leftPad(d.getUTCMinutes()); break;
|
2619
|
-
case 'S': c = leftPad(d.getUTCSeconds()); break;
|
2620
|
-
case 'd': c = "" + d.getUTCDate(); break;
|
2621
|
-
case 'm': c = "" + (d.getUTCMonth() + 1); break;
|
2622
|
-
case 'y': c = "" + d.getUTCFullYear(); break;
|
2623
|
-
case 'b': c = "" + monthNames[d.getUTCMonth()]; break;
|
2624
|
-
case 'p': c = (isAM) ? ("" + "am") : ("" + "pm"); break;
|
2625
|
-
case 'P': c = (isAM) ? ("" + "AM") : ("" + "PM"); break;
|
2626
|
-
case '0': c = ""; padNext = true; break;
|
2627
|
-
}
|
2628
|
-
if (c && padNext) {
|
2629
|
-
c = leftPad(c);
|
2630
|
-
padNext = false;
|
2631
|
-
}
|
2632
|
-
r.push(c);
|
2633
|
-
if (!padNext)
|
2634
|
-
escape = false;
|
2635
|
-
}
|
2636
|
-
else {
|
2637
|
-
if (c == "%")
|
2638
|
-
escape = true;
|
2639
|
-
else
|
2640
|
-
r.push(c);
|
2641
|
-
}
|
2642
|
-
}
|
2643
|
-
return r.join("");
|
2644
|
-
};
|
2645
|
-
|
2646
|
-
// round to nearby lower multiple of base
|
2647
|
-
function floorInBase(n, base) {
|
2648
|
-
return base * Math.floor(n / base);
|
2649
|
-
}
|
2650
|
-
|
2651
|
-
})(jQuery);
|