nvd3/nv.d3.min.js

4 lines
36 KiB
JavaScript
Raw Normal View History

/*****
* A no frills tooltip implementation.
*****/(function(a){var b=window.nvtooltip={};b.show=function(b,c,d,e){var f=a('<div class="nvtooltip">');d=d||"s",e=e||20,f.html(c).css({left:-1e3,top:-1e3,opacity:0}).appendTo("body");var g=f.height()+parseInt(f.css("padding-top"))+parseInt(f.css("padding-bottom")),h=f.width()+parseInt(f.css("padding-left"))+parseInt(f.css("padding-right")),i=a(window).width(),j=a(window).height(),k=a("body").scrollTop(),l=a("body").scrollLeft(),m,n;switch(d){case"e":m=b[0]-h-e,n=b[1]-g/2,m<l&&(m=b[0]+e),n<k&&(n=k+5),n+g>k+j&&(n=k-g-5);break;case"w":m=b[0]+e,n=b[1]-g/2,m+h>i&&(m=b[0]-h-e),n<k&&(n=k+5),n+g>k+j&&(n=k-g-5);break;case"n":m=b[0]-h/2,n=b[1]+e,m<l&&(m=l+5),m+h>i&&(m=i-h-5),n+g>k+j&&(n=b[1]-g-e);break;case"s":m=b[0]-h/2,n=b[1]-g-e,m<l&&(m=l+5),m+h>i&&(m=i-h-5),k>n&&(n=b[1]+20)}f.css({left:m,top:n,opacity:1});return f},b.cleanup=function(){var b=a(".nvtooltip");b.css({"transition-delay":"0 !important","-moz-transition-delay":"0 !important","-webkit-transition-delay":"0 !important"}),b.css("opacity",0),setTimeout(function(){b.remove()},500)}})(jQuery),function(){function c(a,b,c){return function(d,e,f){var g=a(d),h=[];g<d&&b(g);if(f>1)while(g<e){var i=new Date(+g);c(i)%f||h.push(i),b(g)}else while(g<e)h.push(new Date(+g)),b(g);return h}}function b(a,b){var c=[31,28,31,30,31,30,31,31,30,31,30,31];if(a!=2)return c[a-1];if(b%4!=0)return c[1];if(b%100==0&&b%400!=0)return c[1];return c[1]+1}var a={version:"0.0.1",dev:!0};window.nv=a,a.models={},a.charts={},a.graphs=[],a.log={},a.dispatch=d3.dispatch("render_start","render_end"),window.log=function(a){typeof window.console=="object"&&typeof window.console.log=="function"&&console.log.apply(console,arguments);return a},a.dispatch.on("render_start",function(b){a.log.startTime=+(new Date)}),a.dispatch.on("render_end",function(b){a.log.endTime=+(new Date),a.log.totalTime=a.log.endTime-a.log.startTime,a.dev&&log("total",a.log.totalTime)}),a.render=function b(c){c=c||1,b.active=!0,a.dispatch.render_start(),setTimeout(function(){var d;for(var e=0;e<c&&(graph=b.queue[e]);e++)d=graph.generate(),typeof graph.callback=="function"&&graph.callback(d),a.graphs.push(d);b.queue.splice(0,e),b.queue.length?setTimeout(arguments.callee,0):(a.render.active=!1,a.dispatch.render_end())},0)},a.render.queue=[],a.addGraph=function(b){typeof arguments[0]=="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()}),a.models.legend=function(){function f(g){g.each(function(f){var g=d3.select(this).selectAll("g.legend").data([f]),h=g.enter().append("g").attr("class","legend").append("g"),i=g.select("g").attr("transform","translate("+a.left+","+a.top+")"),j=i.selectAll(".series").data(function(a){return a}),k=j.enter().append("g").attr("class","series").on("mouseover",function(a,b){e.legendMouseover(a,b)}).on("mouseout",function(a,b){e.legendMouseout(a,b)}).on("click",function(a,b){e.legendClick(a,b)});k.append("circle").style("fill",function(a,b){return a.color||d[b%20]}).style("stroke",function(a,b){return a.color||d[b%20]}).style("stroke-width",2).attr("r",5),k.append("text").text(function(a){return a.key}).attr("text-anchor","start").attr("dy",".32em").attr("dx","8"),j.classed("disabled",function(a){return a.disabled}),j.exit().remove();var l=5,m=5,n=0,o;j.attr("transform",function(c,d){var e=d3.select(this).select("text").node().getComputedTextLength()+28;o=m,b<a.left+a.right+o+e&&(m=o=5,l+=20),m+=e,m>n&&(n=m);return"translate("+o+","+l+")"}),i.attr("transform","translate("+(b-a.right-n)+","+a.top+")"),c=a.top+a.bottom+l+15});return f}var a={top:5,right:0,bottom:5,left:10},b=400,c=20,d=d3.scale.category10().range(),e=d3.dispatch("legendClick","legendMouseover","legendMouseout");f.dispatch=e,f.margin=function(b){if(!arguments.length)return a
("path").attr("class","area"),d3.transition(t.exit()).attr("d",function(a,b){return s(a.values,b)}).remove(),t.style("fill",function(a,b){return e[b%10]}).style("stroke",function(a,b){return e[b%10]}),d3.transition(t).attr("d",function(a,b){return r(a.values,b)})});return j}var b={top:0,right:0,bottom:0,left:0},c=960,d=500,e=d3.scale.category10().range(),f="stack",g="zero",h="default",i=a.models.line();j.margin=function(a){if(!arguments.length)return b;b=a;return j},j.width=function(a){if(!arguments.length)return c;c=a;return j},j.height=function(a){if(!arguments.length)return d;d=a;return j},j.color=function(a){if(!arguments.length)return e;e=a;return j},j.offset=function(a){if(!arguments.length)return g;g=a;return j},j.order=function(a){if(!arguments.length)return h;h=a;return j},j.style=function(a){if(!arguments.length)return f;f=a;switch(f){case"stack":g="zero",h="default";break;case"stream":g="wiggle",h="inside-out";break;case"expand":g="expand",h="default"}return j},j.dispatch=i.dispatch;return j},a.models.stackedAreaWithLegend=function(){function r(a){a.each(function(e){var f=e.filter(function(a){return!a.disabled}).reduce(function(a,b,c){b.values.forEach(function(b,d){c||(a[d]={x:b.x,y:0}),a[d].y+=k(b)});return a},[]);h.domain(d3.extent(d3.merge(f),j)).range([0,c-b.left-b.right]),i.domain(p.offset()=="zero"?[0,d3.max(d3.merge(f),k)]:[0,1]).range([d-b.top-b.bottom,0]),p.width(c-b.left-b.right).height(d-b.top-b.bottom);var s=d3.select(this).selectAll("g.wrap").data([e]),t=s.enter().append("g").attr("class","wrap d3stackedWithLegend").append("g");t.append("g").attr("class","x axis"),t.append("g").attr("class","y axis"),t.append("g").attr("class","stackedWrap"),t.append("g").attr("class","legendWrap"),t.append("g").attr("class","controlsWrap"),n.dispatch.on("legendClick",function(b,c){b.disabled=!b.disabled,b.disabled?b.values.map(function(a){a._y=a.y,a.y=0;return a}):b.values.map(function(a){a.y=a._y;return a}),e.filter(function(a){return!a.disabled}).length||e.map(function(a){a.disabled=!1,a.values.map(function(a){a.y=a._y;return a});return a}),a.transition().call(r)}),o.dispatch.on("legendClick",function(b,c){if(!!b.disabled){q=q.map(function(a){a.disabled=!0;return a}),b.disabled=!1;switch(b.key){case"Stacked":p.style("stack");break;case"Stream":p.style("stream");break;case"Expanded":p.style("expand")}a.transition().call(r)}}),p.dispatch.on("pointMouseover.tooltip",function(a){g.tooltipShow({point:a.point,series:a.series,pos:[a.pos[0]+b.left,a.pos[1]+b.top],seriesIndex:a.seriesIndex,pointIndex:a.pointIndex})}),p.dispatch.on("pointMouseout.tooltip",function(a){g.tooltipHide(a)}),b.top=n.height();var u=s.select("g").attr("transform","translate("+b.left+","+b.top+")");n.width(c/2-b.right),o.width(280).color(["#666","#666","#666"]),u.select(".legendWrap").datum(e).attr("transform","translate("+(c/2-b.left)+","+ -b.top+")").call(n),u.select(".controlsWrap").datum(q).attr("transform","translate(0,"+ -b.top+")").call(o);var v=u.select(".stackedWrap").datum(e);d3.transition(v).call(p),l.domain(h.domain()).range(h.range()).ticks(c/100).tickSize(-(d-b.top-b.bottom),0),u.select(".x.axis").attr("transform","translate(0,"+i.range()[0]+")"),d3.transition(u.select(".x.axis")).call(l),m.domain(i.domain()).range(i.range()).ticks(p.offset()=="wiggle"?0:d/36).tickSize(-(c-b.right-b.left),0).tickFormat(p.offset()=="zero"?d3.format(",.2f"):d3.format("%")),d3.transition(u.select(".y.axis")).call(m)});return r}var b={top:30,right:20,bottom:50,left:60},c=960,d=500,e=function(){return 2.5},f=d3.scale.category10().range(),g=d3.dispatch("tooltipShow","tooltipHide"),h=d3.scale.linear(),i=d3.scale.linear(),j=function(a){return a.x},k=function(a){return a.y},l=a.models.xaxis().scale(h),m=a.models.yaxis().scale(i),n=a.models.legend().height(30),o=a.models.legend().height(30),p=a.models.stackedArea(),q=[{key:"Stacked"},{key:"Stream",disabled:!0},{key:"Expanded",disabled:!0}];r.dispatch=g,r.x=function(a){if(!arguments.length)return j;j=a,p.x(a);return r},r.y=function(a){if(!arguments.length)return k;k=a,p.y(a);return r},r.margin=function(a){if(