mongodb_logger 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.rvmrc +1 -1
  2. data/.travis.yml +13 -7
  3. data/Gemfile +1 -7
  4. data/README.md +128 -117
  5. data/Rakefile +11 -40
  6. data/SUPPORTED_RAILS_VERSIONS +3 -1
  7. data/app/assets/javascripts/analytics.js.coffee +66 -0
  8. data/app/assets/javascripts/logs.js.coffee +107 -164
  9. data/app/assets/javascripts/mongodb_logger.js +11 -2
  10. data/app/assets/javascripts/vendors/jquery-1.8.3.min.js +2 -0
  11. data/app/assets/javascripts/vendors/jquery-ui-1.9.2.min.js +6 -0
  12. data/app/assets/javascripts/vendors/jquery.pjax.min.js +13 -6
  13. data/app/assets/javascripts/vendors/rickshaw/d3.layout.min.js +1 -0
  14. data/app/assets/javascripts/vendors/rickshaw/d3.min.js +2 -0
  15. data/app/assets/javascripts/vendors/rickshaw/rickshaw.js +2637 -0
  16. data/app/assets/stylesheets/humanity/{jquery-ui-1.8.16.custom.css → jquery-ui-1.9.2.custom.css} +0 -0
  17. data/app/assets/stylesheets/layout.css +1 -1
  18. data/app/assets/stylesheets/library.css.erb +2 -2
  19. data/app/assets/stylesheets/mongodb_logger.css +2 -1
  20. data/app/assets/stylesheets/rickshaw/rickshaw.css +307 -0
  21. data/bin/mongodb_logger_web +1 -2
  22. data/config.ru +8 -1
  23. data/examples/server_config.yml +1 -2
  24. data/features/mongodb_logger_web.feature +1 -1
  25. data/features/step_definitions/mongodb_logger_web_steps.rb +18 -12
  26. data/lib/mongodb_logger.rb +6 -2
  27. data/lib/mongodb_logger/adapters.rb +3 -0
  28. data/lib/mongodb_logger/adapters/base.rb +45 -0
  29. data/lib/mongodb_logger/adapters/mongo.rb +91 -0
  30. data/lib/mongodb_logger/adapters/moped.rb +95 -0
  31. data/lib/mongodb_logger/logger.rb +39 -71
  32. data/lib/mongodb_logger/replica_set_helper.rb +11 -2
  33. data/lib/mongodb_logger/server.rb +15 -36
  34. data/lib/mongodb_logger/server/model/analytic.rb +54 -37
  35. data/lib/mongodb_logger/server/view_helpers.rb +5 -1
  36. data/lib/mongodb_logger/server/views/analytics.erb +8 -7
  37. data/lib/mongodb_logger/server/views/layout.erb +4 -11
  38. data/lib/mongodb_logger/server/views/overview.erb +6 -6
  39. data/lib/mongodb_logger/server/views/shared/_collection_stats.erb +4 -4
  40. data/lib/mongodb_logger/server/views/shared/_dynamic_filter.erb +1 -1
  41. data/lib/mongodb_logger/server/views/shared/_log_info.erb +1 -1
  42. data/lib/mongodb_logger/server/views/shared/_tabs.erb +2 -2
  43. data/lib/mongodb_logger/server/views/shared/_tail_panel.erb +4 -4
  44. data/lib/mongodb_logger/server/views/shared/_top_panel.erb +1 -1
  45. data/lib/mongodb_logger/server/views/show_log.erb +11 -1
  46. data/lib/mongodb_logger/server_config.rb +17 -66
  47. data/lib/mongodb_logger/version.rb +1 -1
  48. data/mongodb_logger.gemspec +19 -20
  49. data/spec/javascripts/MongodbLoggerMainSpec.js +2 -2
  50. data/spec/javascripts/support/jasmine.yml +5 -5
  51. data/test/Gemfile_tests +2 -1
  52. data/test/config/samples/database.yml +3 -1
  53. data/test/config/samples/database_no_file_logging.yml +3 -1
  54. data/test/shoulda_macros/log_macros.rb +1 -1
  55. data/test/test.sh +5 -5
  56. data/test/test_helper.rb +26 -18
  57. data/test/unit/mongodb_logger_test.rb +21 -20
  58. metadata +70 -88
  59. data/app/assets/javascripts/vendors/jquery-1.7.1.min.js +0 -4
  60. data/app/assets/javascripts/vendors/jquery-ui-1.8.16.min.js +0 -791
  61. data/mongodb_logger.java.gemspec +0 -43
@@ -1,6 +1,13 @@
1
- (function(b){b.fn.pjax=function(a,c){c?c.container=a:c=b.isPlainObject(a)?a:{container:a};if(c.container&&"string"!==typeof c.container)throw"pjax container must be a string selector!";return this.live("click",function(a){if(1<a.which||a.metaKey)return!0;var d={url:this.href,container:b(this).attr("data-pjax"),clickedElement:b(this),fragment:null};b.pjax(b.extend({},d,c));a.preventDefault()})};var d=b.pjax=function(a){var c=b(a.container),h=a.success||b.noop;delete a.success;if("string"!==typeof a.container)throw"pjax container must be a string selector!";
2
- a=b.extend(!0,{},d.defaults,a);if(b.isFunction(a.url))a.url=a.url();a.context=c;a.success=function(c){if(a.fragment){var e=b(c).find(a.fragment);if(e.length)c=e.children();else return window.location=a.url}else if(!b.trim(c)||/<html/i.test(c))return window.location=a.url;this.html(c);var g=document.title,f=b.trim(this.find("title").remove().text());if(f)document.title=f;!f&&a.fragment&&(e.attr("title")||e.data("title"));e={pjax:a.container,fragment:a.fragment,timeout:a.timeout};f=b.param(a.data);
3
- if("_pjax=true"!=f)e.url=a.url+(/\?/.test(a.url)?"&":"?")+f;if(a.replace)window.history.replaceState(e,document.title,a.url);else if(a.push){if(!d.active)window.history.replaceState(b.extend({},e,{url:null}),g),d.active=!0;window.history.pushState(e,document.title,a.url)}(a.replace||a.push)&&window._gaq&&_gaq.push(["_trackPageview"]);g=window.location.hash.toString();if(""!==g)window.location.href=g;h.apply(this,arguments)};if((c=d.xhr)&&4>c.readyState)c.onreadystatechange=b.noop,c.abort();d.options=
4
- a;d.xhr=b.ajax(a);b(document).trigger("pjax",[d.xhr,a]);return d.xhr};d.defaults={timeout:650,push:!0,replace:!1,data:{_pjax:!0},type:"GET",dataType:"html",beforeSend:function(a){this.trigger("pjax:start",[a,d.options]);this.trigger("start.pjax",[a,d.options]);a.setRequestHeader("X-PJAX","true")},error:function(a,b){if("abort"!==b)window.location=d.options.url},complete:function(a){this.trigger("pjax:end",[a,d.options]);this.trigger("end.pjax",[a,d.options])}};var h="state"in window.history,i=location.href;
5
- b(window).bind("popstate",function(a){var c=!h&&location.href==i;h=!0;if(!c&&(a=a.state)&&a.pjax)c=a.pjax,b(c+"").length?b.pjax({url:a.url||location.href,fragment:a.fragment,container:c,push:!1,timeout:a.timeout}):window.location=location.href});0>b.inArray("state",b.event.props)&&b.event.props.push("state");b.support.pjax=window.history&&window.history.pushState&&window.history.replaceState&&!navigator.userAgent.match(/(iPod|iPhone|iPad|WebApps\/.+CFNetwork)/);if(!b.support.pjax)b.pjax=function(a){window.location=
6
- b.isFunction(a.url)?a.url():a.url},b.fn.pjax=function(){return this}})(jQuery);
1
+ (function(b){function y(a,c,f){var d=this;return this.on("click.pjax",a,function(a){var e=b.extend({},j(c,f));e.container||(e.container=b(this).attr("data-pjax")||d);n(a,e)})}function n(a,c,f){f=j(c,f);c=a.currentTarget;if("A"!==c.tagName.toUpperCase())throw"$.fn.pjax or $.pjax.click requires an anchor element";if(!(1<a.which||a.metaKey||a.ctrlKey||a.shiftKey||a.altKey))if(!(location.protocol!==c.protocol||location.host!==c.host)&&!(c.hash&&c.href.replace(c.hash,"")===location.href.replace(location.hash,
2
+ ""))&&c.href!==location.href+"#")c={url:c.href,container:b(c).attr("data-pjax"),target:c,fragment:null},e(b.extend({},c,f)),a.preventDefault()}function z(a,c,f){f=j(c,f);c=a.currentTarget;if("FORM"!==c.tagName.toUpperCase())throw"$.pjax.submit requires a form element";c={type:c.method,url:c.action,data:b(c).serializeArray(),container:b(c).attr("data-pjax"),target:c,fragment:null,timeout:0};e(b.extend({},c,f));a.preventDefault()}function e(a){function c(a,c){var d=b.Event(a,{relatedTarget:f});i.trigger(d,
3
+ c);return!d.isDefaultPrevented()}a=b.extend(!0,{},b.ajaxSettings,e.defaults,a);b.isFunction(a.url)&&(a.url=a.url());var f=a.target,d=q(a.url).hash,i=a.context=s(a.container);a.data||(a.data={});a.data._pjax=i.selector;var k;a.beforeSend=function(b,d){"GET"!==d.type&&(d.timeout=0);0<d.timeout&&(k=setTimeout(function(){c("pjax:timeout",[b,a])&&b.abort("timeout")},d.timeout),d.timeout=0);b.setRequestHeader("X-PJAX","true");b.setRequestHeader("X-PJAX-Container",i.selector);if(!c("pjax:beforeSend",[b,
4
+ d]))return!1;a.requestUrl=q(d.url).href};a.complete=function(b,d){k&&clearTimeout(k);c("pjax:complete",[b,d,a]);c("pjax:end",[b,a])};a.error=function(b,d,e){var f=t("",b,a),b=c("pjax:error",[b,d,e,a]);"GET"==a.type&&("abort"!==d&&b)&&r(f.url)};a.success=function(f,g,k){var h=t(f,k,a);if(h.contents){e.state={id:a.id||(new Date).getTime(),url:h.url,title:h.title,container:i.selector,fragment:a.fragment,timeout:a.timeout};(a.push||a.replace)&&window.history.replaceState(e.state,h.title,h.url);h.title&&
5
+ (document.title=h.title);i.html(h.contents);"number"===typeof a.scrollTo&&b(window).scrollTop(a.scrollTo);(a.replace||a.push)&&window._gaq&&_gaq.push(["_trackPageview"]);if(""!==d){var j=q(h.url);j.hash=d;e.state.url=j.href;window.history.replaceState(e.state,h.title,j.href);h=b(j.hash);h.length&&b(window).scrollTop(h.offset().top)}c("pjax:success",[f,g,k,a])}else r(h.url)};e.state||(e.state={id:(new Date).getTime(),url:window.location.href,title:document.title,container:i.selector,fragment:a.fragment,
6
+ timeout:a.timeout},window.history.replaceState(e.state,document.title));var g=e.xhr;g&&4>g.readyState&&(g.onreadystatechange=b.noop,g.abort());e.options=a;g=e.xhr=b.ajax(a);if(0<g.readyState){if(a.push&&!a.replace){var j=e.state.id,n=i.clone().contents();l[j]=n;for(m.push(j);p.length;)delete l[p.shift()];for(;m.length>e.defaults.maxCacheLength;)delete l[m.shift()];window.history.pushState(null,"",u(a.requestUrl))}c("pjax:start",[g,a]);c("pjax:send",[g,a])}return e.xhr}function A(a,c){return e(b.extend({url:window.location.href,
7
+ push:!1,replace:!0,scrollTo:!1},j(a,c)))}function r(a){window.history.replaceState(null,"","#");window.location.replace(a)}function v(a){if((a=a.state)&&a.container){var c=b(a.container);if(c.length){var f=l[a.id];if(e.state){var d=e.state.id<a.id?"forward":"back",i=d,k=e.state.id,g=c.clone().contents();l[k]=g;"forward"===i?(i=m,g=p):(i=p,g=m);i.push(k);(k=g.pop())&&delete l[k]}d=b.Event("pjax:popstate",{state:a,direction:d});c.trigger(d);d={id:a.id,url:a.url,container:c,push:!1,fragment:a.fragment,
8
+ timeout:a.timeout,scrollTo:!1};f?(c.trigger("pjax:start",[null,d]),a.title&&(document.title=a.title),c.html(f),e.state=a,c.trigger("pjax:end",[null,d])):e(d);c[0].offsetHeight}else r(location.href)}}function B(a){var c=b.isFunction(a.url)?a.url():a.url,f=a.type?a.type.toUpperCase():"GET",d=b("<form>",{method:"GET"===f?"GET":"POST",action:c,style:"display:none"});"GET"!==f&&"POST"!==f&&d.append(b("<input>",{type:"hidden",name:"_method",value:f.toLowerCase()}));a=a.data;if("string"===typeof a)b.each(a.split("&"),
9
+ function(a,c){var f=c.split("=");d.append(b("<input>",{type:"hidden",name:f[0],value:f[1]}))});else if("object"===typeof a)for(key in a)d.append(b("<input>",{type:"hidden",name:key,value:a[key]}));b(document.body).append(d);d.submit()}function u(a){return a.replace(/\?_pjax=[^&]+&?/,"?").replace(/_pjax=[^&]+&?/,"").replace(/[\?&]$/,"")}function q(a){var b=document.createElement("a");b.href=a;return b}function j(a,c){a&&c?c.container=a:c=b.isPlainObject(a)?a:{container:a};c.container&&(c.container=
10
+ s(c.container));return c}function s(a){a=b(a);if(a.length){if(""!==a.selector&&a.context===document)return a;if(a.attr("id"))return b("#"+a.attr("id"));throw"cant get selector for pjax container!";}throw"no pjax container for "+a.selector;}function t(a,c,f){var d={};d.url=u(c.getResponseHeader("X-PJAX-URL")||f.requestUrl);if(/<html/i.test(a))var c=b(a.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0]),e=b(a.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]);else c=e=b(a);if(0===e.length)return d;d.title=c.filter("title").add(c.find("title")).last().text();
11
+ f.fragment?(a="body"===f.fragment?e:e.filter(f.fragment).add(e.find(f.fragment)).first(),a.length&&(d.contents=a.contents(),d.title||(d.title=a.attr("title")||a.data("title")))):/<html/i.test(a)||(d.contents=e);d.contents&&(d.contents=d.contents.not("title"),d.contents.find("title").remove());d.title&&(d.title=b.trim(d.title));return d}function w(){b.fn.pjax=y;b.pjax=e;b.pjax.enable=b.noop;b.pjax.disable=x;b.pjax.click=n;b.pjax.submit=z;b.pjax.reload=A;b.pjax.defaults={timeout:650,push:!0,replace:!1,
12
+ type:"GET",dataType:"html",scrollTo:0,maxCacheLength:20};b(window).bind("popstate.pjax",v)}function x(){b.fn.pjax=function(){return this};b.pjax=B;b.pjax.enable=w;b.pjax.disable=b.noop;b.pjax.click=b.noop;b.pjax.submit=b.noop;b.pjax.reload=function(){window.location.reload()};b(window).unbind("popstate.pjax",v)}var l={},p=[],m=[];0>b.inArray("state",b.event.props)&&b.event.props.push("state");b.support.pjax=window.history&&window.history.pushState&&window.history.replaceState&&!navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]|WebApps\/.+CFNetwork)/);
13
+ b.support.pjax?w():x()})(jQuery);
@@ -0,0 +1 @@
1
+ (function(){function a(a){var b=a.source,d=a.target,e=c(b,d),f=[b];while(b!==e)b=b.parent,f.push(b);var g=f.length;while(d!==e)f.splice(g,0,d),d=d.parent;return f}function b(a){var b=[],c=a.parent;while(c!=null)b.push(a),a=c,c=c.parent;return b.push(a),b}function c(a,c){if(a===c)return a;var d=b(a),e=b(c),f=d.pop(),g=e.pop(),h=null;while(f===g)h=f,f=d.pop(),g=e.pop();return h}function g(a){a.fixed|=2}function h(a){a!==f&&(a.fixed&=1)}function i(){j(),f.fixed&=1,e=f=null}function j(){f.px+=d3.event.dx,f.py+=d3.event.dy,e.resume()}function k(a,b,c){var d=0,e=0;a.charge=0;if(!a.leaf){var f=a.nodes,g=f.length,h=-1,i;while(++h<g){i=f[h];if(i==null)continue;k(i,b,c),a.charge+=i.charge,d+=i.charge*i.cx,e+=i.charge*i.cy}}if(a.point){a.leaf||(a.point.x+=Math.random()-.5,a.point.y+=Math.random()-.5);var j=b*c[a.point.index];a.charge+=a.pointCharge=j,d+=j*a.point.x,e+=j*a.point.y}a.cx=d/a.charge,a.cy=e/a.charge}function l(a){return 20}function m(a){return 1}function o(a){return a.x}function p(a){return a.y}function q(a,b,c){a.y0=b,a.y=c}function t(a){var b=1,c=0,d=a[0][1],e,f=a.length;for(;b<f;++b)(e=a[b][1])>d&&(c=b,d=e);return c}function u(a){return a.reduce(v,0)}function v(a,b){return a+b[1]}function w(a,b){return x(a,Math.ceil(Math.log(b.length)/Math.LN2+1))}function x(a,b){var c=-1,d=+a[0],e=(a[1]-d)/b,f=[];while(++c<=b)f[c]=e*c+d;return f}function y(a){return[d3.min(a),d3.max(a)]}function z(a,b){return a.sort=d3.rebind(a,b.sort),a.children=d3.rebind(a,b.children),a.links=D,a.value=d3.rebind(a,b.value),a.nodes=function(b){return E=!0,(a.nodes=a)(b)},a}function A(a){return a.children}function B(a){return a.value}function C(a,b){return b.value-a.value}function D(a){return d3.merge(a.map(function(a){return(a.children||[]).map(function(b){return{source:a,target:b}})}))}function F(a,b){return a.value-b.value}function G(a,b){var c=a._pack_next;a._pack_next=b,b._pack_prev=a,b._pack_next=c,c._pack_prev=b}function H(a,b){a._pack_next=b,b._pack_prev=a}function I(a,b){var c=b.x-a.x,d=b.y-a.y,e=a.r+b.r;return e*e-c*c-d*d>.001}function J(a){function l(a){b=Math.min(a.x-a.r,b),c=Math.max(a.x+a.r,c),d=Math.min(a.y-a.r,d),e=Math.max(a.y+a.r,e)}var b=Infinity,c=-Infinity,d=Infinity,e=-Infinity,f=a.length,g,h,i,j,k;a.forEach(K),g=a[0],g.x=-g.r,g.y=0,l(g);if(f>1){h=a[1],h.x=h.r,h.y=0,l(h);if(f>2){i=a[2],O(g,h,i),l(i),G(g,i),g._pack_prev=i,G(i,h),h=g._pack_next;for(var m=3;m<f;m++){O(g,h,i=a[m]);var n=0,o=1,p=1;for(j=h._pack_next;j!==h;j=j._pack_next,o++)if(I(j,i)){n=1;break}if(n==1)for(k=g._pack_prev;k!==j._pack_prev;k=k._pack_prev,p++)if(I(k,i)){p<o&&(n=-1,j=k);break}n==0?(G(g,i),h=i,l(i)):n>0?(H(g,j),h=j,m--):(H(j,h),g=j,m--)}}}var q=(b+c)/2,r=(d+e)/2,s=0;for(var m=0;m<f;m++){var t=a[m];t.x-=q,t.y-=r,s=Math.max(s,t.r+Math.sqrt(t.x*t.x+t.y*t.y))}return a.forEach(L),s}function K(a){a._pack_next=a._pack_prev=a}function L(a){delete a._pack_next,delete a._pack_prev}function M(a){var b=a.children;b&&b.length?(b.forEach(M),a.r=J(b)):a.r=Math.sqrt(a.value)}function N(a,b,c,d){var e=a.children;a.x=b+=d*a.x,a.y=c+=d*a.y,a.r*=d;if(e){var f=-1,g=e.length;while(++f<g)N(e[f],b,c,d)}}function O(a,b,c){var d=a.r+c.r,e=b.x-a.x,f=b.y-a.y;if(d&&(e||f)){var g=b.r+c.r,h=Math.sqrt(e*e+f*f),i=Math.max(-1,Math.min(1,(d*d+h*h-g*g)/(2*d*h))),j=Math.acos(i),k=i*(d/=h),l=Math.sin(j)*d;c.x=a.x+k*e+l*f,c.y=a.y+k*f-l*e}else c.x=a.x+d,c.y=a.y}function P(a){return 1+d3.max(a,function(a){return a.y})}function Q(a){return a.reduce(function(a,b){return a+b.x},0)/a.length}function R(a){var b=a.children;return b&&b.length?R(b[0]):a}function S(a){var b=a.children,c;return b&&(c=b.length)?S(b[c-1]):a}function T(a,b){return a.parent==b.parent?1:2}function U(a){var b=a.children;return b&&b.length?b[0]:a._tree.thread}function V(a){var b=a.children,c;return b&&(c=b.length)?b[c-1]:a._tree.thread}function W(a,b){var c=a.children;if(c&&(e=c.length)){var d,e,f=-1;while(++f<e)b(d=W(c[f],b),a)>0&&(a=d)}return a}function X(a,b){return a.x-b.x}function Y(a,b){return b.x-a.x}function Z(a,b){return a.depth-b.depth}function $(a,b){function c(a,d){var e=a.children;if(e&&(i=e.length)){var f,g=null,h=-1,i;while(++h<i)f=e[h],c(f,g),g=f}b(a,d)}c(a,null)}function _(a){var b=0,c=0,d=a.children,e=d.length,f;while(--e>=0)f=d[e]._tree,f.prelim+=b,f.mod+=b,b+=f.shift+(c+=f.change)}function ba(a,b,c){a=a._tree,b=b._tree;var d=c/(b.number-a.number);a.change+=d,b.change-=d,b.shift+=c,b.prelim+=c,b.mod+=c}function bb(a,b,c){return a._tree.ancestor.parent==b.parent?a._tree.ancestor:c}function bc(a){return{x:a.x,y:a.y,dx:a.dx,dy:a.dy}}function bd(a,b){var c=a.x+b[3],d=a.y+b[0],e=a.dx-b[1]-b[3],f=a.dy-b[0]-b[2];return e<0&&(c+=e/2,e=0),f<0&&(d+=f/2,f=0),{x:c,y:d,dx:e,dy:f}}d3.layout={},d3.layout.bundle=function(){return function(b){var c=[],d=-1,e=b.length;while(++d<e)c.push(a(b[d]));return c}},d3.layout.chord=function(){function j(){var a={},j=[],l=d3.range(e),m=[],n,o,p,q,r;b=[],c=[],n=0,q=-1;while(++q<e){o=0,r=-1;while(++r<e)o+=d[q][r];j.push(o),m.push(d3.range(e)),n+=o}g&&l.sort(function(a,b){return g(j[a],j[b])}),h&&m.forEach(function(a,b){a.sort(function(a,c){return h(d[b][a],d[b][c])})}),n=(2*Math.PI-f*e)/n,o=0,q=-1;while(++q<e){p=o,r=-1;while(++r<e){var s=l[q],t=m[s][r],u=d[s][t],v=o,w=o+=u*n;a[s+"-"+t]={index:s,subindex:t,startAngle:v,endAngle:w,value:u}}c.push({index:s,startAngle:p,endAngle:o,value:(o-p)/n}),o+=f}q=-1;while(++q<e){r=q-1;while(++r<e){var x=a[q+"-"+r],y=a[r+"-"+q];(x.value||y.value)&&b.push(x.value<y.value?{source:y,target:x}:{source:x,target:y})}}i&&k()}function k(){b.sort(function(a,b){return i((a.source.value+a.target.value)/2,(b.source.value+b.target.value)/2)})}var a={},b,c,d,e,f=0,g,h,i;return a.matrix=function(f){return arguments.length?(e=(d=f)&&d.length,b=c=null,a):d},a.padding=function(d){return arguments.length?(f=d,b=c=null,a):f},a.sortGroups=function(d){return arguments.length?(g=d,b=c=null,a):g},a.sortSubgroups=function(c){return arguments.length?(h=c,b=null,a):h},a.sortChords=function(c){return arguments.length?(i=c,b&&k(),a):i},a.chords=function(){return b||j(),b},a.groups=function(){return c||j(),c},a},d3.layout.force=function(){function A(a){return function(b,c,d,e,f){if(b.point!==a){var g=b.cx-a.x,h=b.cy-a.y,i=1/Math.sqrt(g*g+h*h);if((e-c)*i<t){var j=b.charge*i*i;return a.px-=g*j,a.py-=h*j,!0}if(b.point&&isFinite(i)){var j=b.pointCharge*i*i;a.px-=g*j,a.py-=h*j}}return!b.charge}}function B(){var a=v.length,d=w.length,e,f,g,h,i,j,l,m,p;for(f=0;f<d;++f){g=w[f],h=g.source,i=g.target,m=i.x-h.x,p=i.y-h.y;if(j=m*m+p*p)j=n*y[f]*((j=Math.sqrt(j))-x[f])/j,m*=j,p*=j,i.x-=m*(l=h.weight/(i.weight+h.weight)),i.y-=p*l,h.x+=m*(l=1-l),h.y+=p*l}if(l=n*s){m=c[0]/2,p=c[1]/2,f=-1;if(l)while(++f<a)g=v[f],g.x+=(m-g.x)*l,g.y+=(p-g.y)*l}if(r){k(e=d3.geom.quadtree(v),n,z),f=-1;while(++f<a)(g=v[f]).fixed||e.visit(A(g))}f=-1;while(++f<a)g=v[f],g.fixed?(g.x=g.px,g.y=g.py):(g.x-=(g.px-(g.px=g.x))*o,g.y-=(g.py-(g.py=g.y))*o);return b.tick({type:"tick",alpha:n}),(n*=.99)<.005}function C(b){g(f=b),e=a}var a={},b=d3.dispatch("tick"),c=[1,1],d,n,o=.9,p=l,q=m,r=-30,s=.1,t=.8,u,v=[],w=[],x,y,z;return a.on=function(c,d){return b.on(c,d),a},a.nodes=function(b){return arguments.length?(v=b,a):v},a.links=function(b){return arguments.length?(w=b,a):w},a.size=function(b){return arguments.length?(c=b,a):c},a.linkDistance=function(b){return arguments.length?(p=d3.functor(b),a):p},a.distance=a.linkDistance,a.linkStrength=function(b){return arguments.length?(q=d3.functor(b),a):q},a.friction=function(b){return arguments.length?(o=b,a):o},a.charge=function(b){return arguments.length?(r=typeof b=="function"?b:+b,a):r},a.gravity=function(b){return arguments.length?(s=b,a):s},a.theta=function(b){return arguments.length?(t=b,a):t},a.start=function(){function k(a,c){var d=l(b),e=-1,f=d.length,g;while(++e<f)if(!isNaN(g=d[e][a]))return g;return Math.random()*c}function l(){if(!i){i=[];for(d=0;d<e;++d)i[d]=[];for(d=0;d<f;++d){var a=w[d];i[a.source.index].push(a.target),i[a.target.index].push(a.source)}}return i[b]}var b,d,e=v.length,f=w.length,g=c[0],h=c[1],i,j;for(b=0;b<e;++b)(j=v[b]).index=b,j.weight=0;x=[],y=[];for(b=0;b<f;++b)j=w[b],typeof j.source=="number"&&(j.source=v[j.source]),typeof j.target=="number"&&(j.target=v[j.target]),x[b]=p.call(this,j,b),y[b]=q.call(this,j,b),++j.source.weight,++j.target.weight;for(b=0;b<e;++b)j=v[b],isNaN(j.x)&&(j.x=k("x",g)),isNaN(j.y)&&(j.y=k("y",h)),isNaN(j.px)&&(j.px=j.x),isNaN(j.py)&&(j.py=j.y);z=[];if(typeof r=="function")for(b=0;b<e;++b)z[b]=+r.call(this,v[b],b);else for(b=0;b<e;++b)z[b]=r;return a.resume()},a.resume=function(){return n=.1,d3.timer(B),a},a.stop=function(){return n=0,a},a.drag=function(){d||(d=d3.behavior.drag().on("dragstart",C).on("drag",j).on("dragend",i)),this.on("mouseover.force",g).on("mouseout.force",h).call(d)},a};var e,f;d3.layout.partition=function(){function c(a,b,d,e){var f=a.children;a.x=b,a.y=a.depth*e,a.dx=d,a.dy=e;if(f&&(h=f.length)){var g=-1,h,i,j;d=a.value?d/a.value:0;while(++g<h)c(i=f[g],b,j=i.value*d,e),b+=j}}function d(a){var b=a.children,c=0;if(b&&(f=b.length)){var e=-1,f;while(++e<f)c=Math.max(c,d(b[e]))}return 1+c}function e(e,f){var g=a.call(this,e,f);return c(g[0],0,b[0],b[1]/d(g[0])),g}var a=d3.layout.hierarchy(),b=[1,1];return e.size=function(a){return arguments.length?(b=a,e):b},z(e,a)},d3.layout.pie=function(){function f(g,h){var i=g.map(function(b,c){return+a.call(f,b,c)}),j=+(typeof c=="function"?c.apply(this,arguments):c),k=((typeof e=="function"?e.apply(this,arguments):e)-c)/d3.sum(i),l=d3.range(g.length);b!=null&&l.sort(b===n?function(a,b){return i[b]-i[a]}:function(a,c){return b(g[a],g[c])});var m=l.map(function(a){return{data:g[a],value:d=i[a],startAngle:j,endAngle:j+=d*k}});return g.map(function(a,b){return m[l[b]]})}var a=Number,b=n,c=0,e=2*Math.PI;return f.value=function(b){return arguments.length?(a=b,f):a},f.sort=function(a){return arguments.length?(b=a,f):b},f.startAngle=function(a){return arguments.length?(c=a,f):c},f.endAngle=function(a){return arguments.length?(e=a,f):e},f};var n={};d3.layout.stack=function(){function g(h,i){var j=h.map(function(b,c){return a.call(g,b,c)}),k=j.map(function(a,b){return a.map(function(a,b){return[e.call(g,a,b),f.call(g,a,b)]})}),l=b.call(g,k,i);j=d3.permute(j,l),k=d3.permute(k,l);var m=c.call(g,k,i),n=j.length,o=j[0].length,p,q,r;for(q=0;q<o;++q){d.call(g,j[0][q],r=m[q],k[0][q][1]);for(p=1;p<n;++p)d.call(g,j[p][q],r+=k[p-1][q][1],k[p][q][1])}return h}var a=Object,b=r["default"],c=s.zero,d=q,e=o,f=p;return g.values=function(b){return arguments.length?(a=b,g):a},g.order=function(a){return arguments.length?(b=typeof a=="function"?a:r[a],g):b},g.offset=function(a){return arguments.length?(c=typeof a=="function"?a:s[a],g):c},g.x=function(a){return arguments.length?(e=a,g):e},g.y=function(a){return arguments.length?(f=a,g):f},g.out=function(a){return arguments.length?(d=a,g):d},g};var r={"inside-out":function(a){var b=a.length,c,d,e=a.map(t),f=a.map(u),g=d3.range(b).sort(function(a,b){return e[a]-e[b]}),h=0,i=0,j=[],k=[];for(c=0;c<b;++c)d=g[c],h<i?(h+=f[d],j.push(d)):(i+=f[d],k.push(d));return k.reverse().concat(j)},reverse:function(a){return d3.range(a.length).reverse()},"default":function(a){return d3.range(a.length)}},s={silhouette:function(a){var b=a.length,c=a[0].length,d=[],e=0,f,g,h,i=[];for(g=0;g<c;++g){for(f=0,h=0;f<b;f++)h+=a[f][g][1];h>e&&(e=h),d.push(h)}for(g=0;g<c;++g)i[g]=(e-d[g])/2;return i},wiggle:function(a){var b=a.length,c=a[0],d=c.length,e=0,f,g,h,i,j,k,l,m,n,o=[];o[0]=m=n=0;for(g=1;g<d;++g){for(f=0,i=0;f<b;++f)i+=a[f][g][1];for(f=0,j=0,l=c[g][0]-c[g-1][0];f<b;++f){for(h=0,k=(a[f][g][1]-a[f][g-1][1])/(2*l);h<f;++h)k+=(a[h][g][1]-a[h][g-1][1])/l;j+=k*a[f][g][1]}o[g]=m-=i?j/i*l:0,m<n&&(n=m)}for(g=0;g<d;++g)o[g]-=n;return o},expand:function(a){var b=a.length,c=a[0].length,d=1/b,e,f,g,h=[];for(f=0;f<c;++f){for(e=0,g=0;e<b;e++)g+=a[e][f][1];if(g)for(e=0;e<b;e++)a[e][f][1]/=g;else for(e=0;e<b;e++)a[e][f][1]=d}for(f=0;f<c;++f)h[f]=0;return h},zero:function(a){var b=-1,c=a[0].length,d=[];while(++b<c)d[b]=0;return d}};d3.layout.histogram=function(){function e(e,f){var g=[],h=e.map(b,this),i=c.call(this,h,f),j=d.call(this,i,h,f),k,f=-1,l=h.length,m=j.length-1,n=a?1:1/l,o;while(++f<m)k=g[f]=[],k.dx=j[f+1]-(k.x=j[f]),k.y=0;f=-1;while(++f<l)o=h[f],o>=i[0]&&o<=i[1]&&(k=g[d3.bisect(j,o,1,m)-1],k.y+=n,k.push(e[f]));return g}var a=!0,b=Number,c=y,d=w;return e.value=function(a){return arguments.length?(b=a,e):b},e.range=function(a){return arguments.length?(c=d3.functor(a),e):c},e.bins=function(a){return arguments.length?(d=typeof a=="number"?function(b){return x(b,a)}:d3.functor(a),e):d},e.frequency=function(b){return arguments.length?(a=!!b,e):a},e},d3.layout.hierarchy=function(){function e(f,h,i){var j=b.call(g,f,h),k=E?f:{data:f};k.depth=h,i.push(k);if(j&&(m=j.length)){var l=-1,m,n=k.children=[],o=0,p=h+1;while(++l<m)d=e(j[l],p,i),d.parent=k,n.push(d),o+=d.value;a&&n.sort(a),c&&(k.value=o)}else c&&(k.value=+c.call(g,f,h)||0);return k}function f(a,b){var d=a.children,e=0;if(d&&(i=d.length)){var h=-1,i,j=b+1;while(++h<i)e+=f(d[h],j)}else c&&(e=+c.call(g,E?a:a.data,b)||0);return c&&(a.value=e),e}function g(a){var b=[];return e(a,0,b),b}var a=C,b=A,c=B;return g.sort=function(b){return arguments.length?(a=b,g):a},g.children=function(a){return arguments.length?(b=a,g):b},g.value=function(a){return arguments.length?(c=a,g):c},g.revalue=function(a){return f(a,0),a},g};var E=!1;d3.layout.pack=function(){function c(c,d){var e=a.call(this,c,d),f=e[0];f.x=0,f.y=0,M(f);var g=b[0],h=b[1],i=1/Math.max(2*f.r/g,2*f.r/h);return N(f,g/2,h/2,i),e}var a=d3.layout.hierarchy().sort(F),b=[1,1];return c.size=function(a){return arguments.length?(b=a,c):b},z(c,a)},d3.layout.cluster=function(){function d(d,e){var f=a.call(this,d,e),g=f[0],h,i=0,j,k;$(g,function(a){var c=a.children;c&&c.length?(a.x=Q(c),a.y=P(c)):(a.x=h?i+=b(a,h):0,a.y=0,h=a)});var l=R(g),m=S(g),n=l.x-b(l,m)/2,o=m.x+b(m,l)/2;return $(g,function(a){a.x=(a.x-n)/(o-n)*c[0],a.y=(1-a.y/g.y)*c[1]}),f}var a=d3.layout.hierarchy().sort(null).value(null),b=T,c=[1,1];return d.separation=function(a){return arguments.length?(b=a,d):b},d.size=function(a){return arguments.length?(c=a,d):c},z(d,a)},d3.layout.tree=function(){function d(d,e){function h(a,c){var d=a.children,e=a._tree;if(d&&(f=d.length)){var f,g=d[0],i,k=g,l,m=-1;while(++m<f)l=d[m],h(l,i),k=j(l,i,k),i=l;_(a);var n=.5*(g._tree.prelim+l._tree.prelim);c?(e.prelim=c._tree.prelim+b(a,c),e.mod=e.prelim-n):e.prelim=n}else c&&(e.prelim=c._tree.prelim+b(a,c))}function i(a,b){a.x=a._tree.prelim+b;var c=a.children;if(c&&(e=c.length)){var d=-1,e;b+=a._tree.mod;while(++d<e)i(c[d],b)}}function j(a,c,d){if(c){var e=a,f=a,g=c,h=a.parent.children[0],i=e._tree.mod,j=f._tree.mod,k=g._tree.mod,l=h._tree.mod,m;while(g=V(g),e=U(e),g&&e)h=U(h),f=V(f),f._tree.ancestor=a,m=g._tree.prelim+k-e._tree.prelim-i+b(g,e),m>0&&(ba(bb(g,a,d),a,m),i+=m,j+=m),k+=g._tree.mod,i+=e._tree.mod,l+=h._tree.mod,j+=f._tree.mod;g&&!V(f)&&(f._tree.thread=g,f._tree.mod+=k-j),e&&!U(h)&&(h._tree.thread=e,h._tree.mod+=i-l,d=a)}return d}var f=a.call(this,d,e),g=f[0];$(g,function(a,b){a._tree={ancestor:a,prelim:0,mod:0,change:0,shift:0,number:b?b._tree.number+1:0}}),h(g),i(g,-g._tree.prelim);var k=W(g,Y),l=W(g,X),m=W(g,Z),n=k.x-b(k,l)/2,o=l.x+b(l,k)/2,p=m.depth||1;return $(g,function(a){a.x=(a.x-n)/(o-n)*c[0],a.y=a.depth/p*c[1],delete a._tree}),f}var a=d3.layout.hierarchy().sort(null).value(null),b=T,c=[1,1];return d.separation=function(a){return arguments.length?(b=a,d):b},d.size=function(a){return arguments.length?(c=a,d):c},z(d,a)},d3.layout.treemap=function(){function i(a,b){var c=-1,d=a.length,e,f;while(++c<d)f=(e=a[c]).value*(b<0?0:b),e.area=isNaN(f)||f<=0?0:f}function j(a){var b=a.children;if(b&&b.length){var c=e(a),d=[],f=b.slice(),g,h=Infinity,k,n=Math.min(c.dx,c.dy),o;i(f,c.dx*c.dy/a.value),d.area=0;while((o=f.length)>0)d.push(g=f[o-1]),d.area+=g.area,(k=l(d,n))<=h?(f.pop(),h=k):(d.area-=d.pop().area,m(d,n,c,!1),n=Math.min(c.dx,c.dy),d.length=d.area=0,h=Infinity);d.length&&(m(d,n,c,!0),d.length=d.area=0),b.forEach(j)}}function k(a){var b=a.children;if(b&&b.length){var c=e(a),d=b.slice(),f,g=[];i(d,c.dx*c.dy/a.value),g.area=0;while(f=d.pop())g.push(f),g.area+=f.area,f.z!=null&&(m(g,f.z?c.dx:c.dy,c,!d.length),g.length=g.area=0);b.forEach(k)}}function l(a,b){var c=a.area,d,e=0,f=Infinity,g=-1,i=a.length;while(++g<i){if(!(d=a[g].area))continue;d<f&&(f=d),d>e&&(e=d)}return c*=c,b*=b,c?Math.max(b*e*h/c,c/(b*f*h)):Infinity}function m(a,c,d,e){var f=-1,g=a.length,h=d.x,i=d.y,j=c?b(a.area/c):0,k;if(c==d.dx){if(e||j>d.dy)j=j?d.dy:0;while(++f<g)k=a[f],k.x=h,k.y=i,k.dy=j,h+=k.dx=j?b(k.area/j):0;k.z=!0,k.dx+=d.x+d.dx-h,d.y+=j,d.dy-=j}else{if(e||j>d.dx)j=j?d.dx:0;while(++f<g)k=a[f],k.x=h,k.y=i,k.dx=j,i+=k.dy=j?b(k.area/j):0;k.z=!1,k.dy+=d.y+d.dy-i,d.x+=j,d.dx-=j}}function n(b){var d=g||a(b),e=d[0];return e.x=0,e.y=0,e.dx=c[0],e.dy=c[1],g&&a.revalue(e),i([e],e.dx*e.dy/e.value),(g?k:j)(e),f&&(g=d),d}var a=d3.layout.hierarchy(),b=Math.round,c=[1,1],d=null,e=bc,f=!1,g,h=.5*(1+Math.sqrt(5));return n.size=function(a){return arguments.length?(c=a,n):c},n.padding=function(a){function b(b){var c=a.call(n,b,b.depth);return c==null?bc(b):bd(b,typeof c=="number"?[c,c,c,c]:c)}function c(b){return bd(b,a)}if(!arguments.length)return d;var f;return e=(d=a)==null?bc:(f=typeof a)==="function"?b:f==="number"?(a=[a,a,a,a],c):c,n},n.round=function(a){return arguments.length?(b=a?Math.round:Number,n):b!=Number},n.sticky=function(a){return arguments.length?(f=a,g=null,n):f},n.ratio=function(a){return arguments.length?(h=a,n):h},z(n,a)}})();
@@ -0,0 +1,2 @@
1
+ (function(){function e(a){var b=-1,c=a.length,d=[];while(++b<c)d.push(a[b]);return d}function f(a){return Array.prototype.slice.call(a)}function i(){return this}function j(a){return a!=null&&!isNaN(a)}function k(a){return a.length}function l(a){return a==null}function m(a){return a.replace(/(^\s+)|(\s+$)/g,"").replace(/\s+/g," ")}function o(){}function p(){function c(){var b=a,c=-1,d=b.length,e;while(++c<d)(e=b[c])._on&&e.apply(this,arguments)}var a=[],b={};return c.on=function(d,e){var f,g;if(f=b[d])f._on=!1,a=a.slice(0,g=a.indexOf(f)).concat(a.slice(g+1)),delete b[d];return e&&(e._on=!0,a.push(e),b[d]=e),c},c}function s(a,b){return b-(a?1+Math.floor(Math.log(a+Math.pow(10,1+Math.floor(Math.log(a)/Math.LN10)-b))/Math.LN10):1)}function t(a){return a+""}function u(a){var b=a.lastIndexOf("."),c=b>=0?a.substring(b):(b=a.length,""),d=[];while(b>0)d.push(a.substring(b-=3,b+3));return d.reverse().join(",")+c}function w(a,b){return{scale:Math.pow(10,(8-b)*3),symbol:a}}function B(a){return function(b){return b<=0?0:b>=1?1:a(b)}}function C(a){return function(b){return 1-a(1-b)}}function D(a){return function(b){return.5*(b<.5?a(2*b):2-a(2-2*b))}}function E(a){return a}function F(a){return function(b){return Math.pow(b,a)}}function G(a){return 1-Math.cos(a*Math.PI/2)}function H(a){return Math.pow(2,10*(a-1))}function I(a){return 1-Math.sqrt(1-a*a)}function J(a,b){var c;return arguments.length<2&&(b=.45),arguments.length<1?(a=1,c=b/4):c=b/(2*Math.PI)*Math.asin(1/a),function(d){return 1+a*Math.pow(2,10*-d)*Math.sin((d-c)*2*Math.PI/b)}}function K(a){return a||(a=1.70158),function(b){return b*b*((a+1)*b-a)}}function L(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+.9375:7.5625*(a-=2.625/2.75)*a+.984375}function M(){d3.event.stopPropagation(),d3.event.preventDefault()}function O(a){return a=="transform"?d3.interpolateTransform:d3.interpolate}function P(a,b){return b=b-(a=+a)?1/(b-a):0,function(c){return(c-a)*b}}function Q(a,b){return b=b-(a=+a)?1/(b-a):0,function(c){return Math.max(0,Math.min(1,(c-a)*b))}}function R(a,b,c){return new S(a,b,c)}function S(a,b,c){this.r=a,this.g=b,this.b=c}function T(a){return a<16?"0"+Math.max(0,a).toString(16):Math.min(255,a).toString(16)}function U(a,b,c){var d=0,e=0,f=0,g,h,i;g=/([a-z]+)\((.*)\)/i.exec(a);if(g){h=g[2].split(",");switch(g[1]){case"hsl":return c(parseFloat(h[0]),parseFloat(h[1])/100,parseFloat(h[2])/100);case"rgb":return b(W(h[0]),W(h[1]),W(h[2]))}}return(i=X[a])?b(i.r,i.g,i.b):(a!=null&&a.charAt(0)==="#"&&(a.length===4?(d=a.charAt(1),d+=d,e=a.charAt(2),e+=e,f=a.charAt(3),f+=f):a.length===7&&(d=a.substring(1,3),e=a.substring(3,5),f=a.substring(5,7)),d=parseInt(d,16),e=parseInt(e,16),f=parseInt(f,16)),b(d,e,f))}function V(a,b,c){var d=Math.min(a/=255,b/=255,c/=255),e=Math.max(a,b,c),f=e-d,g,h,i=(e+d)/2;return f?(h=i<.5?f/(e+d):f/(2-e-d),a==e?g=(b-c)/f+(b<c?6:0):b==e?g=(c-a)/f+2:g=(a-b)/f+4,g*=60):h=g=0,Z(g,h,i)}function W(a){var b=parseFloat(a);return a.charAt(a.length-1)==="%"?Math.round(b*2.55):b}function Z(a,b,c){return new $(a,b,c)}function $(a,b,c){this.h=a,this.s=b,this.l=c}function _(a,b,c){function f(a){return a>360?a-=360:a<0&&(a+=360),a<60?d+(e-d)*a/60:a<180?e:a<240?d+(e-d)*(240-a)/60:d}function g(a){return Math.round(f(a)*255)}var d,e;return a%=360,a<0&&(a+=360),b=b<0?0:b>1?1:b,c=c<0?0:c>1?1:c,e=c<=.5?c*(1+b):c+b-c*b,d=2*c-e,R(g(a+120),g(a),g(a-120))}function ba(a){return h(a,bd),a}function be(a){return function(){return bb(a,this)}}function bf(a){return function(){return bc(a,this)}}function bh(a,b){function f(){if(b=this.classList)return b.add(a);var b=this.className,d=b.baseVal!=null,e=d?b.baseVal:b;c.lastIndex=0,c.test(e)||(e=m(e+" "+a),d?b.baseVal=e:this.className=e)}function g(){if(b=this.classList)return b.remove(a);var b=this.className,d=b.baseVal!=null,e=d?b.baseVal:b;e=m(e.replace(c," ")),d?b.baseVal=e:this.className=e}function h(){(b.apply(this,arguments)?f:g).call(this)}var c=new RegExp("(^|\\s+)"+d3.requote(a)+"(\\s+|$)","g");if(arguments.length<2){var d=this.node();if(e=d.classList)return e.contains(a);var e=d.className;return c.lastIndex=0,c.test(e.baseVal!=null?e.baseVal:e)}return this.each(typeof b=="function"?h:b?f:g)}function bi(a){return{__data__:a}}function bj(a){return arguments.length||(a=d3.ascending),function(b,c){return a(b&&b.__data__,c&&c.__data__)}}function bl(a){return h(a,bm),a}function bn(a,b,c){h(a,br);var d={},e=d3.dispatch("start","end"),f=bu;return a.id=b,a.time=c,a.tween=function(b,c){return arguments.length<2?d[b]:(c==null?delete d[b]:d[b]=c,a)},a.ease=function(b){return arguments.length?(f=typeof b=="function"?b:d3.ease.apply(d3,arguments),a):f},a.each=function(b,c){return arguments.length<2?bv.call(a,b):(e.on(b,c),a)},d3.timer(function(g){return a.each(function(h,i,j){function p(a){if(o.active>b)return r();o.active=b;for(var f in d)(f=d[f].call(l,h,i))&&k.push(f);return e.start.call(l,h,i),q(a)||d3.timer(q,0,c),1}function q(a){if(o.active!==b)return r();var c=(a-m)/n,d=f(c),g=k.length;while(g>0)k[--g].call(l,d);if(c>=1)return r(),bt=b,e.end.call(l,h,i),bt=0,1}function r(){return--o.count||delete l.__transition__,1}var k=[],l=this,m=a[j][i].delay,n=a[j][i].duration,o=l.__transition__||(l.__transition__={active:0,count:0});++o.count,m<=g?p(g):d3.timer(p,m,c)}),1},0,c),a}function bp(a,b,c){return c!=""&&bo}function bq(a,b){function d(a,d,e){var f=b.call(this,a,d);return f==null?e!=""&&bo:e!=f&&c(e,f)}function e(a,d,e){return e!=b&&c(e,b)}var c=O(a);return typeof b=="function"?d:b==null?bp:(b+="",e)}function bv(a){for(var b=0,c=this.length;b<c;b++)for(var d=this[b],e=0,f=d.length;e<f;e++){var g=d[e];g&&a.call(g=g.node,g.__data__,e,b)}return this}function bz(){var a,b=Date.now(),c=bw;while(c)a=b-c.then,a>=c.delay&&(c.flush=c.callback(a)),c=c.next;var d=bA()-b;d>24?(isFinite(d)&&(clearTimeout(by),by=setTimeout(bz,d)),bx=0):(bx=1,bB(bz))}function bA(){var a=null,b=bw,c=Infinity;while(b)b.flush?b=a?a.next=b.next:bw=b.next:(c=Math.min(c,b.then+b.delay),b=(a=b).next);return c}function bC(a){var b=[a.a,a.b],c=[a.c,a.d],d=bE(b),e=bD(b,c),f=bE(bF(c,b,-e));this.translate=[a.e,a.f],this.rotate=Math.atan2(a.b,a.a)*bH,this.scale=[d,f||0],this.skew=f?e/f*bH:0}function bD(a,b){return a[0]*b[0]+a[1]*b[1]}function bE(a){var b=Math.sqrt(bD(a,a));return a[0]/=b,a[1]/=b,b}function bF(a,b,c){return a[0]+=c*b[0],a[1]+=c*b[1],a}function bI(){}function bJ(a){var b=a[0],c=a[a.length-1];return b<c?[b,c]:[c,b]}function bK(a,b){var c=0,d=a.length-1,e=a[c],f=a[d],g;f<e&&(g=c,c=d,d=g,g=e,e=f,f=g);if(g=f-e)b=b(g),a[c]=b.floor(e),a[d]=b.ceil(f);return a}function bL(){return Math}function bM(a,b,c,d){function g(){var g=a.length==2?bS:bT,i=d?Q:P;return e=g(a,b,i,c),f=g(b,a,i,d3.interpolate),h}function h(a){return e(a)}var e,f;return h.invert=function(a){return f(a)},h.domain=function(b){return arguments.length?(a=b.map(Number),g()):a},h.range=function(a){return arguments.length?(b=a,g()):b},h.rangeRound=function(a){return h.range(a).interpolate(d3.interpolateRound)},h.clamp=function(a){return arguments.length?(d=a,g()):d},h.interpolate=function(a){return arguments.length?(c=a,g()):c},h.ticks=function(b){return bQ(a,b)},h.tickFormat=function(b){return bR(a,b)},h.nice=function(){return bK(a,bO),g()},h.copy=function(){return bM(a,b,c,d)},g()}function bN(a,b){return a.range=d3.rebind(a,b.range),a.rangeRound=d3.rebind(a,b.rangeRound),a.interpolate=d3.rebind(a,b.interpolate),a.clamp=d3.rebind(a,b.clamp),a}function bO(a){return a=Math.pow(10,Math.round(Math.log(a)/Math.LN10)-1),{floor:function(b){return Math.floor(b/a)*a},ceil:function(b){return Math.ceil(b/a)*a}}}function bP(a,b){var c=bJ(a),d=c[1]-c[0],e=Math.pow(10,Math.floor(Math.log(d/b)/Math.LN10)),f=b/d*e;return f<=.15?e*=10:f<=.35?e*=5:f<=.75&&(e*=2),c[0]=Math.ceil(c[0]/e)*e,c[1]=Math.floor(c[1]/e)*e+e*.5,c[2]=e,c}function bQ(a,b){return d3.range.apply(d3,bP(a,b))}function bR(a,b){return d3.format(",."+Math.max(0,-Math.floor(Math.log(bP(a,b)[2])/Math.LN10+.01))+"f")}function bS(a,b,c,d){var e=c(a[0],a[1]),f=d(b[0],b[1]);return function(a){return f(e(a))}}function bT(a,b,c,d){var e=[],f=[],g=0,h=a.length;while(++g<h)e.push(c(a[g-1],a[g])),f.push(d(b[g-1],b[g]));return function(b){var c=d3.bisect(a,b,1,a.length-1)-1;return f[c](e[c](b))}}function bU(a,b){function d(c){return a(b(c))}var c=b.pow;return d.invert=function(b){return c(a.invert(b))},d.domain=function(e){return arguments.length?(b=e[0]<0?bX:bW,c=b.pow,a.domain(e.map(b)),d):a.domain().map(c)},d.nice=function(){return a.domain(bK(a.domain(),bL)),d},d.ticks=function(){var d=bJ(a.domain()),e=[];if(d.every(isFinite)){var f=Math.floor(d[0]),g=Math.ceil(d[1]),h=Math.round(c(d[0])),i=Math.round(c(d[1]));if(b===bX){e.push(c(f));for(;f++<g;)for(var j=9;j>0;j--)e.push(c(f)*j)}else{for(;f<g;f++)for(var j=1;j<10;j++)e.push(c(f)*j);e.push(c(f))}for(f=0;e[f]<h;f++);for(g=e.length;e[g-1]>i;g--);e=e.slice(f,g)}return e},d.tickFormat=function(a,e){arguments.length<2&&(e=bV);if(arguments.length<1)return e;var f=a/d.ticks().length,g=b===bX?(h=-1e-15,Math.floor):(h=1e-15,Math.ceil),h;return function(a){return a/c(g(b(a)+h))<f?e(a):""}},d.copy=function(){return bU(a.copy(),b)},bN(d,a)}function bW(a){return Math.log(a)/Math.LN10}function bX(a){return-Math.log(-a)/Math.LN10}function bY(a,b){function e(b){return a(c(b))}var c=bZ(b),d=bZ(1/b);return e.invert=function(b){return d(a.invert(b))},e.domain=function(b){return arguments.length?(a.domain(b.map(c)),e):a.domain().map(d)},e.ticks=function(a){return bQ(e.domain(),a)},e.tickFormat=function(a){return bR(e.domain(),a)},e.nice=function(){return e.domain(bK(e.domain(),bO))},e.exponent=function(a){if(!arguments.length)return b;var f=e.domain();return c=bZ(b=a),d=bZ(1/b),e.domain(f)},e.copy=function(){return bY(a.copy(),b)},bN(e,a)}function bZ(a){return function(b){return b<0?-Math.pow(-b,a):Math.pow(b,a)}}function b$(a,b){function f(b){return d[((c[b]||(c[b]=a.push(b)))-1)%d.length]}function g(b,c){return d3.range(a.length).map(function(a){return b+c*a})}var c,d,e;return f.domain=function(d){if(!arguments.length)return a;a=[],c={};var e=-1,g=d.length,h;while(++e<g)c[h=d[e]]||(c[h]=a.push(h));return f[b.t](b.x,b.p)},f.range=function(a){return arguments.length?(d=a,e=0,b={t:"range",x:a},f):d},f.rangePoints=function(c,h){arguments.length<2&&(h=0);var i=c[0],j=c[1],k=(j-i)/(a.length-1+h);return d=g(a.length<2?(i+j)/2:i+k*h/2,k),e=0,b={t:"rangePoints",x:c,p:h},f},f.rangeBands=function(c,h){arguments.length<2&&(h=0);var i=c[0],j=c[1],k=(j-i)/(a.length+h);return d=g(i+k*h,k),e=k*(1-h),b={t:"rangeBands",x:c,p:h},f},f.rangeRoundBands=function(c,h){arguments.length<2&&(h=0);var i=c[0],j=c[1],k=Math.floor((j-i)/(a.length+h));return d=g(i+Math.round((j-i-(a.length-h)*k)/2),k),e=Math.round(k*(1-h)),b={t:"rangeRoundBands",x:c,p:h},f},f.rangeBand=function(){return e},f.copy=function(){return b$(a,b)},f.domain(a)}function cd(a,b){function d(){var d=0,f=a.length,g=b.length;c=[];while(++d<g)c[d-1]=d3.quantile(a,d/g);return e}function e(a){return isNaN(a=+a)?NaN:b[d3.bisect(c,a)]}var c;return e.domain=function(b){return arguments.length?(a=b.filter(function(a){return!isNaN(a)}).sort(d3.ascending),d()):a},e.range=function(a){return arguments.length?(b=a,d()):b},e.quantiles=function(){return c},e.copy=function(){return cd(a,b)},d()}function ce(a,b,c){function f(b){return c[Math.max(0,Math.min(e,Math.floor(d*(b-a))))]}function g(){return d=c.length/(b-a),e=c.length-1,f}var d,e;return f.domain=function(c){return arguments.length?(a=+c[0],b=+c[c.length-1],g()):[a,b]},f.range=function(a){return arguments.length?(c=a,g()):c},f.copy=function(){return ce(a,b,c)},g()}function ch(a){return a.innerRadius}function ci(a){return a.outerRadius}function cj(a){return a.startAngle}function ck(a){return a.endAngle}function cl(a){function g(d){return d.length<1?null:"M"+e(a(cm(this,d,b,c)),f)}var b=cn,c=co,d="linear",e=cp[d],f=.7;return g.x=function(a){return arguments.length?(b=a,g):b},g.y=function(a){return arguments.length?(c=a,g):c},g.interpolate=function(a){return arguments.length?(e=cp[d=a],g):d},g.tension=function(a){return arguments.length?(f=a,g):f},g}function cm(a,b,c,d){var e=[],f=-1,g=b.length,h=typeof c=="function",i=typeof d=="function",j;if(h&&i)while(++f<g)e.push([c.call(a,j=b[f],f),d.call(a,j,f)]);else if(h)while(++f<g)e.push([c.call(a,b[f],f),d]);else if(i)while(++f<g)e.push([c,d.call(a,b[f],f)]);else while(++f<g)e.push([c,d]);return e}function cn(a){return a[0]}function co(a){return a[1]}function cq(a){var b=0,c=a.length,d=a[0],e=[d[0],",",d[1]];while(++b<c)e.push("L",(d=a[b])[0],",",d[1]);return e.join("")}function cr(a){var b=0,c=a.length,d=a[0],e=[d[0],",",d[1]];while(++b<c)e.push("V",(d=a[b])[1],"H",d[0]);return e.join("")}function cs(a){var b=0,c=a.length,d=a[0],e=[d[0],",",d[1]];while(++b<c)e.push("H",(d=a[b])[0],"V",d[1]);return e.join("")}function ct(a,b){return a.length<4?cq(a):a[1]+cw(a.slice(1,a.length-1),cx(a,b))}function cu(a,b){return a.length<3?cq(a):a[0]+cw((a.push(a[0]),a),cx([a[a.length-2]].concat(a,[a[1]]),b))}function cv(a,b,c){return a.length<3?cq(a):a[0]+cw(a,cx(a,b))}function cw(a,b){if(b.length<1||a.length!=b.length&&a.length!=b.length+2)return cq(a);var c=a.length!=b.length,d="",e=a[0],f=a[1],g=b[0],h=g,i=1;c&&(d+="Q"+(f[0]-g[0]*2/3)+","+(f[1]-g[1]*2/3)+","+f[0]+","+f[1],e=a[1],i=2);if(b.length>1){h=b[1],f=a[i],i++,d+="C"+(e[0]+g[0])+","+(e[1]+g[1])+","+(f[0]-h[0])+","+(f[1]-h[1])+","+f[0]+","+f[1];for(var j=2;j<b.length;j++,i++)f=a[i],h=b[j],d+="S"+(f[0]-h[0])+","+(f[1]-h[1])+","+f[0]+","+f[1]}if(c){var k=a[i];d+="Q"+(f[0]+h[0]*2/3)+","+(f[1]+h[1]*2/3)+","+k[0]+","+k[1]}return d}function cx(a,b){var c=[],d=(1-b)/2,e,f=a[0],g=a[1],h=1,i=a.length;while(++h<i)e=f,f=g,g=a[h],c.push([d*(g[0]-e[0]),d*(g[1]-e[1])]);return c}function cy(a){if(a.length<3)return cq(a);var b=1,c=a.length,d=a[0],e=d[0],f=d[1],g=[e,e,e,(d=a[1])[0]],h=[f,f,f,d[1]],i=[e,",",f];cG(i,g,h);while(++b<c)d=a[b],g.shift(),g.push(d[0]),h.shift(),h.push(d[1]),cG(i,g,h);b=-1;while(++b<2)g.shift(),g.push(d[0]),h.shift(),h.push(d[1]),cG(i,g,h);return i.join("")}function cz(a){if(a.length<4)return cq(a);var b=[],c=-1,d=a.length,e,f=[0],g=[0];while(++c<3)e=a[c],f.push(e[0]),g.push(e[1]);b.push(cC(cF,f)+","+cC(cF,g)),--c;while(++c<d)e=a[c],f.shift(),f.push(e[0]),g.shift(),g.push(e[1]),cG(b,f,g);return b.join("")}function cA(a){var b,c=-1,d=a.length,e=d+4,f,g=[],h=[];while(++c<4)f=a[c%d],g.push(f[0]),h.push(f[1]);b=[cC(cF,g),",",cC(cF,h)],--c;while(++c<e)f=a[c%d],g.shift(),g.push(f[0]),h.shift(),h.push(f[1]),cG(b,g,h);return b.join("")}function cB(a,b){var c=a.length-1,d=a[0][0],e=a[0][1],f=a[c][0]-d,g=a[c][1]-e,h=-1,i,j;while(++h<=c)i=a[h],j=h/c,i[0]=b*i[0]+(1-b)*(d+j*f),i[1]=b*i[1]+(1-b)*(e+j*g);return cy(a)}function cC(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]}function cG(a,b,c){a.push("C",cC(cD,b),",",cC(cD,c),",",cC(cE,b),",",cC(cE,c),",",cC(cF,b),",",cC(cF,c))}function cH(a,b){return(b[1]-a[1])/(b[0]-a[0])}function cI(a){var b=0,c=a.length-1,d=[],e=a[0],f=a[1],g=d[0]=cH(e,f);while(++b<c)d[b]=g+(g=cH(e=f,f=a[b+1]));return d[b]=g,d}function cJ(a){var b=[],c,d,e,f,g=cI(a),h=-1,i=a.length-1;while(++h<i)c=cH(a[h],a[h+1]),Math.abs(c)<1e-6?g[h]=g[h+1]=0:(d=g[h]/c,e=g[h+1]/c,f=d*d+e*e,f>9&&(f=c*3/Math.sqrt(f),g[h]=f*d,g[h+1]=f*e));h=-1;while(++h<=i)f=(a[Math.min(i,h+1)][0]-a[Math.max(0,h-1)][0])/(6*(1+g[h]*g[h])),b.push([f||0,g[h]*f||0]);return b}function cK(a){return a.length<3?cq(a):a[0]+cw(a,cJ(a))}function cL(a){var b,c=-1,d=a.length,e,f;while(++c<d)b=a[c],e=b[0],f=b[1]+cf,b[0]=e*Math.cos(f),b[1]=e*Math.sin(f);return a}function cM(a){function j(f){if(f.length<1)return null;var j=cm(this,f,b,d),k=cm(this,f,b===c?cN(j):c,d===e?cO(j):e);return"M"+g(a(k),i)+"L"+h(a(j.reverse()),i)+"Z"}var b=cn,c=cn,d=0,e=co,f,g,h,i=.7;return j.x=function(a){return arguments.length?(b=c=a,j):c},j.x0=function(a){return arguments.length?(b=a,j):b},j.x1=function(a){return arguments.length?(c=a,j):c},j.y=function(a){return arguments.length?(d=e=a,j):e},j.y0=function(a){return arguments.length?(d=a,j):d},j.y1=function(a){return arguments.length?(e=a,j):e},j.interpolate=function(a){return arguments.length?(g=cp[f=a],h=g.reverse||g,j):f},j.tension=function(a){return arguments.length?(i=a,j):i},j.interpolate("linear")}function cN(a){return function(b,c){return a[c][0]}}function cO(a){return function(b,c){return a[c][1]}}function cP(a){return a.source}function cQ(a){return a.target}function cR(a){return a.radius}function cS(a){return a.startAngle}function cT(a){return a.endAngle}function cU(a){return[a.x,a.y]}function cV(a){return function(){var b=a.apply(this,arguments),c=b[0],d=b[1]+cf;return[c*Math.cos(d),c*Math.sin(d)]}}function cX(a,b){var c=(a.ownerSVGElement||a).createSVGPoint();if(cW<0&&(window.scrollX||window.scrollY)){var d=d3.select(document.body).append("svg:svg").style("position","absolute").style("top",0).style("left",0),e=d[0][0].getScreenCTM();cW=!e.f&&!e.e,d.remove()}return cW?(c.x=b.pageX,c.y=b.pageY):(c.x=b.clientX,c.y=b.clientY),c=c.matrixTransform(a.getScreenCTM().inverse()),[c.x,c.y]}function cY(){return 64}function cZ(){return"circle"}function db(a,b){a.attr("transform",function(a){return"translate("+b(a)+",0)"})}function dc(a,b){a.attr("transform",function(a){return"translate(0,"+b(a)+")"})}function dd(a,b,c){e=[];if(c&&b.length>1){var d=bJ(a.domain()),e,f=-1,g=b.length,h=(b[1]-b[0])/++c,i,j;while(++f<g)for(i=c;--i>0;)(j=+b[f]-i*h)>=d[0]&&e.push(j);for(--f,i=0;++i<c&&(j=+b[f]+i*h)<d[1];)e.push(j)}return e}function dp(a,b){a.select(".extent").attr("x",b[0][0]),a.selectAll(".n,.s,.w,.nw,.sw").attr("x",b[0][0]-2),a.selectAll(".e,.ne,.se").attr("x",b[1][0]-3),a.selectAll(".extent,.n,.s").attr("width",b[1][0]-b[0][0])}function dq(a,b){a.select(".extent").attr("y",b[0][1]),a.selectAll(".n,.e,.w,.nw,.ne").attr("y",b[0][1]-3),a.selectAll(".s,.se,.sw").attr("y",b[1][1]-4),a.selectAll(".extent,.e,.w").attr("height",b[1][1]-b[0][1])}function dr(){d3.event.keyCode==32&&dg&&!dk&&(dm=null,dn[0]-=dj[1][0],dn[1]-=dj[1][1],dk=2,M())}function ds(){d3.event.keyCode==32&&dk==2&&(dn[0]+=dj[1][0],dn[1]+=dj[1][1],dk=0,M())}function dt(){if(dn){var a=d3.svg.mouse(dg),b=d3.select(dg);dk||(d3.event.altKey?(dm||(dm=[(dj[0][0]+dj[1][0])/2,(dj[0][1]+dj[1][1])/2]),dn[0]=dj[+(a[0]<dm[0])][0],dn[1]=dj[+(a[1]<dm[1])][1]):dm=null),dh&&(du(a,dh,0),dp(b,dj)),di&&(du(a,di,1),dq(b,dj)),df("brush")}}function du(a,b,c){var d=bJ(b.range()),e=dn[c],f=dj[1][c]-dj[0][c],g,h;dk&&(d[0]-=e,d[1]-=f+e),g=Math.max(d[0],Math.min(d[1],a[c])),dk?h=(g+=e)+f:(dm&&(e=Math.max(d[0],Math.min(d[1],2*dm[c]-g))),e<g?(h=g,g=e):h=e),dj[0][c]=g,dj[1][c]=h}function dv(){dn&&(dt(),d3.select(dg).selectAll(".resize").style("pointer-events",de.empty()?"none":"all"),df("brushend"),de=df=dg=dh=di=dj=dk=dl=dm=dn=null,M())}function dE(a){var b=d3.event,c=dz.parentNode,d=0,e=0;c&&(c=dF(c),d=c[0]-dB[0],e=c[1]-dB[1],dB=c,dC|=d|e);try{d3.event={dx:d,dy:e},dx[a].apply(dz,dA)}finally{d3.event=b}b.preventDefault()}function dF(a,b){var c=d3.event.changedTouches;return c?d3.svg.touches(a,c)[0]:d3.svg.mouse(a)}function dG(){if(!dz)return;var a=dz.parentNode;if(!a)return dH();dE("drag"),M()}function dH(){if(!dz)return;dE("dragend"),dz=null,dC&&dy===d3.event.target&&(dD=!0,M())}function dI(){dD&&dy===d3.event.target&&(M(),dD=!1,dy=null)}function dW(a){return[a[0]-dO[0],a[1]-dO[1],dO[2]]}function dX(){dJ||(dJ=d3.select("body").append("div").style("visibility","hidden").style("top",0).style("height",0).style("width",0).style("overflow-y","scroll").append("div").style("height","2000px").node().parentNode);var a=d3.event,b;try{dJ.scrollTop=1e3,dJ.dispatchEvent(a),b=1e3-dJ.scrollTop}catch(c){b=a.wheelDelta||-a.detail*5}return b*.005}function dY(){var a=d3.svg.touches(dS),b=-1,c=a.length,d;while(++b<c)dM[(d=a[b]).identifier]=dW(d);return a}function dZ(){var a=d3.svg.touches(dS);switch(a.length){case 1:var b=a[0];eb(dO[2],b,dM[b.identifier]);break;case 2:var c=a[0],d=a[1],e=[(c[0]+d[0])/2,(c[1]+d[1])/2],f=dM[c.identifier],g=dM[d.identifier],h=[(f[0]+g[0])/2,(f[1]+g[1])/2,f[2]];eb(Math.log(d3.event.scale)/Math.LN2+f[2],e,h)}}function d$(){dL=null,dK&&(dU=!0,eb(dO[2],d3.svg.mouse(dS),dK))}function d_(){dK&&(dU&&dR===d3.event.target&&(dV=!0),d$(),dK=null)}function ea(){dV&&dR===d3.event.target&&(d3.event.stopPropagation(),d3.event.preventDefault(),dV=!1,dR=null)}function eb(a,b,c){function l(a,b,c){a.domain(a.range().map(function(f){return a.invert((f-c)*d/e+b)}))}a=ed(a,2);var d=Math.pow(2,dO[2]),e=Math.pow(2,a),f=Math.pow(2,(dO[2]=a)-c[2]),g=dO[0],h=dO[1],i=dO[0]=ed(b[0]-c[0]*f,0,e),j=dO[1]=ed(b[1]-c[1]*f,1,e),k=d3.event;d3.event={scale:e,translate:[i,j],transform:function(a,b){a&&l(a,g,i),b&&l(b,h,j)}};try{dQ.apply(dS,dT)}finally{d3.event=k}k.preventDefault()}function ed(a,b,c){var d=dP[b],e=d[0],f=d[1];return arguments.length===3?Math.max(f*(f===Infinity?-Infinity:1/c-1),Math.min(e===-Infinity?Infinity:e,a/c))*c:Math.max(e,Math.min(f,a))}Date.now||(Date.now=function(){return+(new Date)});try{document.createElement("div").style.setProperty("opacity",0,"")}catch(a){var b=CSSStyleDeclaration.prototype,c=b.setProperty;b.setProperty=function(a,b,d){c.call(this,a,b+"",d)}}d3={version:"2.5.0"};var d=f;try{d(document.documentElement.childNodes)[0].nodeType}catch(g){d=e}var h=[].__proto__?function(a,b){a.__proto__=b}:function(a,b){for(var c in b)a[c]=b[c]};d3.functor=function(a){return typeof a=="function"?a:function(){return a}},d3.rebind=function(a,b){return function(){var c=b.apply(a,arguments);return arguments.length?a:c}},d3.ascending=function(a,b){return a<b?-1:a>b?1:a>=b?0:NaN},d3.descending=function(a,b){return b<a?-1:b>a?1:b>=a?0:NaN},d3.mean=function(a,b){var c=a.length,d,e=0,f=-1,g=0;if(arguments.length===1)while(++f<c)j(d=a[f])&&(e+=(d-e)/++g);else while(++f<c)j(d=b.call(a,a[f],f))&&(e+=(d-e)/++g);return g?e:undefined},d3.median=function(a,b){return arguments.length>1&&(a=a.map(b)),a=a.filter(j),a.length?d3.quantile(a.sort(d3.ascending),.5):undefined},d3.min=function(a,b){var c=-1,d=a.length,e,f;if(arguments.length===1){while(++c<d&&((e=a[c])==null||e!=e))e=undefined;while(++c<d)(f=a[c])!=null&&e>f&&(e=f)}else{while(++c<d&&((e=b.call(a,a[c],c))==null||e!=e))e=undefined;while(++c<d)(f=b.call(a,a[c],c))!=null&&e>f&&(e=f)}return e},d3.max=function(a,b){var c=-1,d=a.length,e,f;if(arguments.length===1){while(++c<d&&((e=a[c])==null||e!=e))e=undefined;while(++c<d)(f=a[c])!=null&&f>e&&(e=f)}else{while(++c<d&&((e=b.call(a,a[c],c))==null||e!=e))e=undefined;while(++c<d)(f=b.call(a,a[c],c))!=null&&f>e&&(e=f)}return e},d3.extent=function(a,b){var c=-1,d=a.length,e,f,g;if(arguments.length===1){while(++c<d&&((e=g=a[c])==null||e!=e))e=g=undefined;while(++c<d)(f=a[c])!=null&&(e>f&&(e=f),g<f&&(g=f))}else{while(++c<d&&((e=g=b.call(a,a[c],c))==null||e!=e))e=undefined;while(++c<d)(f=b.call(a,a[c],c))!=null&&(e>f&&(e=f),g<f&&(g=f))}return[e,g]},d3.random={normal:function(a,b){return arguments.length<2&&(b=1),arguments.length<1&&(a=0),function(){var c,d,e;do c=Math.random()*2-1,d=Math.random()*2-1,e=c*c+d*d;while(!e||e>1);return a+b*c*Math.sqrt(-2*Math.log(e)/e)}}},d3.sum=function(a,b){var c=0,d=a.length,e,f=-1;if(arguments.length===1)while(++f<d)isNaN(e=+a[f])||(c+=e);else while(++f<d)isNaN(e=+b.call(a,a[f],f))||(c+=e);return c},d3.quantile=function(a,b){var c=(a.length-1)*b+1,d=Math.floor(c),e=a[d-1],f=c-d;return f?e+f*(a[d]-e):e},d3.zip=function(){if(!(e=arguments.length))return[];for(var a=-1,b=d3.min(arguments,k),c=new Array(b);++a<b;)for(var d=-1,e,f=c[a]=new Array(e);++d<e;)f[d]=arguments[d][a];return c},d3.bisectLeft=function(a,b,c,d){arguments.length<3&&(c=0),arguments.length<4&&(d=a.length);while(c<d){var e=c+d>>1;a[e]<b?c=e+1:d=e}return c},d3.bisect=d3.bisectRight=function(a,b,c,d){arguments.length<3&&(c=0),arguments.length<4&&(d=a.length);while(c<d){var e=c+d>>1;b<a[e]?d=e:c=e+1}return c},d3.first=function(a,b){var c=0,d=a.length,e=a[0],f;arguments.length===1&&(b=d3.ascending);while(++c<d)b.call(a,e,f=a[c])>0&&(e=f);return e},d3.last=function(a,b){var c=0,d=a.length,e=a[0],f;arguments.length===1&&(b=d3.ascending);while(++c<d)b.call(a,e,f=a[c])<=0&&(e=f);return e},d3.nest=function(){function f(c,g){if(g>=b.length)return e?e.call(a,c):d?c.sort(d):c;var h=-1,i=c.length,j=b[g++],k,l,m={};while(++h<i)(k=j(l=c[h]))in m?m[k].push(l):m[k]=[l];for(k in m)m[k]=f(m[k],g);return m}function g(a,d){if(d>=b.length)return a;var e=[],f=c[d++],h;for(h in a)e.push({key:h,values:g(a[h],d)});return f&&e.sort(function(a,b){return f(a.key,b.key)}),e}var a={},b=[],c=[],d,e;return a.map=function(a){return f(a,0)},a.entries=function(a){return g(f(a,0),0)},a.key=function(c){return b.push(c),a},a.sortKeys=function(d){return c[b.length-1]=d,a},a.sortValues=function(b){return d=b,a},a.rollup=function(b){return e=b,a},a},d3.keys=function(a){var b=[];for(var c in a)b.push(c);return b},d3.values=function(a){var b=[];for(var c in a)b.push(a[c]);return b},d3.entries=function(a){var b=[];for(var c in a)b.push({key:c,value:a[c]});return b},d3.permute=function(a,b){var c=[],d=-1,e=b.length;while(++d<e)c[d]=a[b[d]];return c},d3.merge=function(a){return Array.prototype.concat.apply([],a)},d3.split=function(a,b){var c=[],d=[],e,f=-1,g=a.length;arguments.length<2&&(b=l);while(++f<g)b.call(d,e=a[f],f)?d=[]:(d.length||c.push(d),d.push(e));return c},d3.range=function(a,b,c){arguments.length<3&&(c=1,arguments.length<2&&(b=a,a=0));if((b-a)/c==Infinity)throw new Error("infinite range");var d=[],e=-1,f;if(c<0)while((f=a+c*++e)>b)d.push(f);else while((f=a+c*++e)<b)d.push(f);return d},d3.requote=function(a){return a.replace(n,"\\$&")};var n=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;d3.round=function(a,b){return b?Math.round(a*Math.pow(10,b))*Math.pow(10,-b):Math.round(a)},d3.xhr=function(a,b,c){var d=new XMLHttpRequest;arguments.length<3?c=b:b&&d.overrideMimeType&&d.overrideMimeType(b),d.open("GET",a,!0),d.onreadystatechange=function(){d.readyState===4&&c(d.status<300?d:null)},d.send(null)},d3.text=function(a,b,c){function d(a){c(a&&a.responseText)}arguments.length<3&&(c=b,b=null),d3.xhr(a,b,d)},d3.json=function(a,b){d3.text(a,"application/json",function(a){b(a?JSON.parse(a):null)})},d3.html=function(a,b){d3.text(a,"text/html",function(a){if(a!=null){var c=document.createRange();c.selectNode(document.body),a=c.createContextualFragment(a)}b(a)})},d3.xml=function(a,b,c){function d(a){c(a&&a.responseXML)}arguments.length<3&&(c=b,b=null),d3.xhr(a,b,d)},d3.ns={prefix:{svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},qualify:function(a){var b=a.indexOf(":");return b<0?a:{space:d3.ns.prefix[a.substring(0,b)],local:a.substring(b+1)}}},d3.dispatch=function(){var a=new o,b=-1,c=arguments.length;while(++b<c)a[arguments[b]]=p();return a},o.prototype.on=function(a,b){var c=a.indexOf("."),d="";c>0&&(d=a.substring(c+1),a=a.substring(0,c)),this[a].on(d,b)},d3.format=function(a){var b=q.exec(a),c=b[1]||" ",d=b[3]||"",e=b[5],f=+b[6],g=b[7],h=b[8],i=b[9],j=1,k="",l=!1;h&&(h=+h.substring(1)),e&&(c="0",g&&(f-=Math.floor((f-1)/4)));switch(i){case"n":g=!0,i="g";break;case"%":j=100,k="%",i="f";break;case"p":j=100,k="%",i="r";break;case"d":l=!0,h=0;break;case"s":j=-1,i="r"}return i=="r"&&!h&&(i="g"),i=r[i]||t,function(a){if(l&&a%1)return"";var b=a<0&&(a=-a)?"−":d;if(j<0){var m=d3.formatPrefix(a,h);a*=m.scale,k=m.symbol}else a*=j;a=i(a,h);if(e){var n=a.length+b.length;n<f&&(a=(new Array(f-n+1)).join(c)+a),g&&(a=u(a)),a=b+a}else{g&&(a=u(a)),a=b+a;var n=a.length;n<f&&(a=(new Array(f-n+1)).join(c)+a)}return a+k}};var q=/(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/,r={g:function(a,b){return a.toPrecision(b)},e:function(a,b){return a.toExponential(b)},f:function(a,b){return a.toFixed(b)},r:function(a,b){return d3.round(a,b=s(a,b)).toFixed(Math.max(0,Math.min(20,b)))}},v=["y","z","a","f","p","n","μ","m","","k","M","G","T","P","E","Z","Y"].map(w);d3.formatPrefix=function(a,b){var c=0;return a&&(a<0&&(a*=-1),b&&(a=d3.round(a,s(a,b))),c=1+Math.floor(1e-12+Math.log(a)/Math.LN10),c=Math.max(-24,Math.min(24,Math.floor((c<=0?c+1:c-1)/3)*3))),v[8+c/3]};var x=F(2),y=F(3),z={linear:function(){return E},poly:F,quad:function(){return x},cubic:function(){return y},sin:function(){return G},exp:function(){return H},circle:function(){return I},elastic:J,back:K,bounce:function(){return L}},A={"in":function(a){return a},out:C,"in-out":D,"out-in":function(a){return D(C(a))}};d3.ease=function(a){var b=a.indexOf("-"),c=b>=0?a.substring(0,b):a,d=b>=0?a.substring(b+1):"in";return B(A[d](z[c].apply(null,Array.prototype.slice.call(arguments,1))))},d3.event=null,d3.interpolate=function(a,b){var c=d3.interpolators.length,d;while(--c>=0&&!(d=d3.interpolators[c](a,b)));return d},d3.interpolateNumber=function(a,b){return b-=a,function(c){return a+b*c}},d3.interpolateRound=function(a,b){return b-=a,function(c){return Math.round(a+b*c)}},d3.interpolateString=function(a,b){var c,d,e,f=0,g=0,h=[],i=[],j,k;N.lastIndex=0;for(d=0;c=N.exec(b);++d)c.index&&h.push(b.substring(f,g=c.index)),i.push({i:h.length,x:c[0]}),h.push(null),f=N.lastIndex;f<b.length&&h.push(b.substring(f));for(d=0,j=i.length;(c=N.exec(a))&&d<j;++d){k=i[d];if(k.x==c[0]){if(k.i)if(h[k.i+1]==null){h[k.i-1]+=k.x,h.splice(k.i,1);for(e=d+1;e<j;++e)i[e].i--}else{h[k.i-1]+=k.x+h[k.i+1],h.splice(k.i,2);for(e=d+1;e<j;++e)i[e].i-=2}else if(h[k.i+1]==null)h[k.i]=k.x;else{h[k.i]=k.x+h[k.i+1],h.splice(k.i+1,1);for(e=d+1;e<j;++e)i[e].i--}i.splice(d,1),j--,d--}else k.x=d3.interpolateNumber(parseFloat(c[0]),parseFloat(k.x))}while(d<j)k=i.pop(),h[k.i+1]==null?h[k.i]=k.x:(h[k.i]=k.x+h[k.i+1],h.splice(k.i+1,1)),j--;return h.length===1?h[0]==null?i[0].x:function(){return b}:function(a){for(d=0;d<j;++d)h[(k=i[d]).i]=k.x(a);return h.join("")}},d3.interpolateTransform=function(a,b){return d3.interpolateString(d3.transform(a)+"",d3.transform(b)+"")},d3.interpolateRgb=function(a,b){a=d3.rgb(a),b=d3.rgb(b);var c=a.r,d=a.g,e=a.b,f=b.r-c,g=b.g-d,h=b.b-e;return function(a){return"#"+T(Math.round(c+f*a))+T(Math.round(d+g*a))+T(Math.round(e+h*a))}},d3.interpolateHsl=function(a,b){a=d3.hsl(a),b=d3.hsl(b);var c=a.h,d=a.s,e=a.l,f=b.h-c,g=b.s-d,h=b.l-e;return function(a){return _(c+f*a,d+g*a,e+h*a).toString()}},d3.interpolateArray=function(a,b){var c=[],d=[],e=a.length,f=b.length,g=Math.min(a.length,b.length),h;for(h=0;h<g;++h)c.push(d3.interpolate(a[h],b[h]));for(;h<e;++h)d[h]=a[h];for(;h<f;++h)d[h]=b[h];return function(a){for(h=0;h<g;++h)d[h]=c[h](a);return d}},d3.interpolateObject=function(a,b){var c={},d={},e;for(e in a)e in b?c[e]=O(e)(a[e],b[e]):d[e]=a[e];for(e in b)e in a||(d[e]=b[e]);return function(a){for(e in c)d[e]=c[e](a);return d}};var N=/[-+]?(?:\d*\.?\d+)(?:[eE][-+]?\d+)?/g;d3.interpolators=[d3.interpolateObject,function(a,b){return b instanceof Array&&d3.interpolateArray(a,b)},function(a,b){return typeof b=="string"&&d3.interpolateString(a+"",b)},function(a,b){return(typeof b=="string"?b in X||/^(#|rgb\(|hsl\()/.test(b):b instanceof S||b instanceof $)&&d3.interpolateRgb(a+"",b)},function(a,b){return typeof b=="number"&&d3.interpolateNumber(+a,b)}],d3.rgb=function(a,b,c){return arguments.length===1?a instanceof S?R(a.r,a.g,a.b):U(""+a,R,_):R(~~a,~~b,~~c)},S.prototype.brighter=function(a){a=Math.pow(.7,arguments.length?a:1);var b=this.r,c=this.g,d=this.b,e=30;return!b&&!c&&!d?R(e,e,e):(b&&b<e&&(b=e),c&&c<e&&(c=e),d&&d<e&&(d=e),R(Math.min(255,Math.floor(b/a)),Math.min(255,Math.floor(c/a)),Math.min(255,Math.floor(d/a))))},S.prototype.darker=function(a){return a=Math.pow(.7,arguments.length?a:1),R(Math.floor(a*this.r),Math.floor(a*this.g),Math.floor(a*this.b))},S.prototype.hsl=function(){return V(this.r,this.g,this.b)},S.prototype.toString=function(){return"#"+T(this.r)+T(this.g)+T(this.b)};var X={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080"
2
+ ,green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};for(var Y in X)X[Y]=U(X[Y],R,_);d3.hsl=function(a,b,c){return arguments.length===1?a instanceof $?Z(a.h,a.s,a.l):U(""+a,V,Z):Z(+a,+b,+c)},$.prototype.brighter=function(a){return a=Math.pow(.7,arguments.length?a:1),Z(this.h,this.s,this.l/a)},$.prototype.darker=function(a){return a=Math.pow(.7,arguments.length?a:1),Z(this.h,this.s,a*this.l)},$.prototype.rgb=function(){return _(this.h,this.s,this.l)},$.prototype.toString=function(){return this.rgb().toString()};var bb=function(a,b){return b.querySelector(a)},bc=function(a,b){return b.querySelectorAll(a)};typeof Sizzle=="function"&&(bb=function(a,b){return Sizzle(a,b)[0]},bc=function(a,b){return Sizzle.uniqueSort(Sizzle(a,b))});var bd=[];d3.selection=function(){return bk},d3.selection.prototype=bd,bd.select=function(a){var b=[],c,d,e,f;typeof a!="function"&&(a=be(a));for(var g=-1,h=this.length;++g<h;){b.push(c=[]),c.parentNode=(e=this[g]).parentNode;for(var i=-1,j=e.length;++i<j;)(f=e[i])?(c.push(d=a.call(f,f.__data__,i)),d&&"__data__"in f&&(d.__data__=f.__data__)):c.push(null)}return ba(b)},bd.selectAll=function(a){var b=[],c,e;typeof a!="function"&&(a=bf(a));for(var f=-1,g=this.length;++f<g;)for(var h=this[f],i=-1,j=h.length;++i<j;)if(e=h[i])b.push(c=d(a.call(e,e.__data__,i))),c.parentNode=e;return ba(b)},bd.attr=function(a,b){function d(){this.removeAttribute(a)}function e(){this.removeAttributeNS(a.space,a.local)}function f(){this.setAttribute(a,b)}function g(){this.setAttributeNS(a.space,a.local,b)}function h(){var c=b.apply(this,arguments);c==null?this.removeAttribute(a):this.setAttribute(a,c)}function i(){var c=b.apply(this,arguments);c==null?this.removeAttributeNS(a.space,a.local):this.setAttributeNS(a.space,a.local,c)}a=d3.ns.qualify(a);if(arguments.length<2){var c=this.node();return a.local?c.getAttributeNS(a.space,a.local):c.getAttribute(a)}return this.each(b==null?a.local?e:d:typeof b=="function"?a.local?i:h:a.local?g:f)},bd.classed=function(a,b){var c=a.split(bg),d=c.length,e=-1;if(arguments.length>1){while(++e<d)bh.call(this,c[e],b);return this}while(++e<d)if(!bh.call(this,c[e]))return!1;return!0};var bg=/\s+/g;bd.style=function(a,b,c){function d(){this.style.removeProperty(a)}function e(){this.style.setProperty(a,b,c)}function f(){var d=b.apply(this,arguments);d==null?this.style.removeProperty(a):this.style.setProperty(a,d,c)}return arguments.length<3&&(c=""),arguments.length<2?window.getComputedStyle(this.node(),null).getPropertyValue(a):this.each(b==null?d:typeof b=="function"?f:e)},bd.property=function(a,b){function c(){delete this[a]}function d(){this[a]=b}function e(){var c=b.apply(this,arguments);c==null?delete this[a]:this[a]=c}return arguments.length<2?this.node()[a]:this.each(b==null?c:typeof b=="function"?e:d)},bd.text=function(a){return arguments.length<1?this.node().textContent:this.each(typeof a=="function"?function(){this.textContent=a.apply(this,arguments)}:function(){this.textContent=a})},bd.html=function(a){return arguments.length<1?this.node().innerHTML:this.each(typeof a=="function"?function(){this.innerHTML=a.apply(this,arguments)}:function(){this.innerHTML=a})},bd.append=function(a){function b(){return this.appendChild(document.createElement(a))}function c(){return this.appendChild(document.createElementNS(a.space,a.local))}return a=d3.ns.qualify(a),this.select(a.local?c:b)},bd.insert=function(a,b){function c(){return this.insertBefore(document.createElement(a),bb(b,this))}function d(){return this.insertBefore(document.createElementNS(a.space,a.local),bb(b,this))}return a=d3.ns.qualify(a),this.select(a.local?d:c)},bd.remove=function(){return this.each(function(){var a=this.parentNode;a&&a.removeChild(this)})},bd.data=function(a,b){function f(a,f){var g,h=a.length,i=f.length,j=Math.min(h,i),k=Math.max(h,i),l=[],m=[],n=[],o,p;if(b){var q={},r=[],s,t=f.length;for(g=-1;++g<h;)s=b.call(o=a[g],o.__data__,g),s in q?n[t++]=o:q[s]=o,r.push(s);for(g=-1;++g<i;)o=q[s=b.call(f,p=f[g],g)],o?(o.__data__=p,l[g]=o,m[g]=n[g]=null):(m[g]=bi(p),l[g]=n[g]=null),delete q[s];for(g=-1;++g<h;)r[g]in q&&(n[g]=a[g])}else{for(g=-1;++g<j;)o=a[g],p=f[g],o?(o.__data__=p,l[g]=o,m[g]=n[g]=null):(m[g]=bi(p),l[g]=n[g]=null);for(;g<i;++g)m[g]=bi(f[g]),l[g]=n[g]=null;for(;g<k;++g)n[g]=a[g],m[g]=l[g]=null}m.update=l,m.parentNode=l.parentNode=n.parentNode=a.parentNode,c.push(m),d.push(l),e.push(n)}var c=[],d=[],e=[],g=-1,h=this.length,i;if(typeof a=="function")while(++g<h)f(i=this[g],a.call(i,i.parentNode.__data__,g));else while(++g<h)f(i=this[g],a);var j=ba(d);return j.enter=function(){return bl(c)},j.exit=function(){return ba(e)},j},bd.filter=function(a){var b=[],c,d,e;for(var f=0,g=this.length;f<g;f++){b.push(c=[]),c.parentNode=(d=this[f]).parentNode;for(var h=0,i=d.length;h<i;h++)(e=d[h])&&a.call(e,e.__data__,h)&&c.push(e)}return ba(b)},bd.map=function(a){return this.each(function(){this.__data__=a.apply(this,arguments)})},bd.sort=function(a){a=bj.apply(this,arguments);for(var b=0,c=this.length;b<c;b++)for(var d=this[b].sort(a),e=1,f=d.length,g=d[0];e<f;e++){var h=d[e];h&&(g&&g.parentNode.insertBefore(h,g.nextSibling),g=h)}return this},bd.on=function(a,b,c){arguments.length<3&&(c=!1);var d="__on"+a,e=a.indexOf(".");return e>0&&(a=a.substring(0,e)),arguments.length<2?(e=this.node()[d])&&e._:this.each(function(e,f){function h(a){var c=d3.event;d3.event=a;try{b.call(g,g.__data__,f)}finally{d3.event=c}}var g=this;g[d]&&g.removeEventListener(a,g[d],c),b&&g.addEventListener(a,g[d]=h,c),h._=b})},bd.each=function(a){for(var b=-1,c=this.length;++b<c;)for(var d=this[b],e=-1,f=d.length;++e<f;){var g=d[e];g&&a.call(g,g.__data__,e,b)}return this},bd.call=function(a){return a.apply(this,(arguments[0]=this,arguments)),this},bd.empty=function(){return!this.node()},bd.node=function(a){for(var b=0,c=this.length;b<c;b++)for(var d=this[b],e=0,f=d.length;e<f;e++){var g=d[e];if(g)return g}return null},bd.transition=function(){var a=[],b,c;for(var d=-1,e=this.length;++d<e;){a.push(b=[]);for(var f=this[d],g=-1,h=f.length;++g<h;)b.push((c=f[g])?{node:c,delay:0,duration:250}:null)}return bn(a,bt||++bs,Date.now())};var bk=ba([[document]]);bk[0].parentNode=document.documentElement,d3.select=function(a){return typeof a=="string"?bk.select(a):ba([[a]])},d3.selectAll=function(a){return typeof a=="string"?bk.selectAll(a):ba([d(a)])};var bm=[];bm.append=bd.append,bm.insert=bd.insert,bm.empty=bd.empty,bm.node=bd.node,bm.select=function(a){var b=[],c,d,e,f,g;for(var h=-1,i=this.length;++h<i;){e=(f=this[h]).update,b.push(c=[]),c.parentNode=f.parentNode;for(var j=-1,k=f.length;++j<k;)(g=f[j])?(c.push(e[j]=d=a.call(f.parentNode,g.__data__,j)),d.__data__=g.__data__):c.push(null)}return ba(b)};var bo={},br=[],bs=0,bt=0,bu=d3.ease("cubic-in-out");br.call=bd.call,d3.transition=function(){return bk.transition()},d3.transition.prototype=br,br.select=function(a){var b=[],c,d,e;typeof a!="function"&&(a=be(a));for(var f=-1,g=this.length;++f<g;){b.push(c=[]);for(var h=this[f],i=-1,j=h.length;++i<j;)(e=h[i])&&(d=a.call(e.node,e.node.__data__,i))?("__data__"in e.node&&(d.__data__=e.node.__data__),c.push({node:d,delay:e.delay,duration:e.duration})):c.push(null)}return bn(b,this.id,this.time).ease(this.ease())},br.selectAll=function(a){var b=[],c,d,e;typeof a!="function"&&(a=bf(a));for(var f=-1,g=this.length;++f<g;)for(var h=this[f],i=-1,j=h.length;++i<j;)if(e=h[i]){d=a.call(e.node,e.node.__data__,i),b.push(c=[]);for(var k=-1,l=d.length;++k<l;)c.push({node:d[k],delay:e.delay,duration:e.duration})}return bn(b,this.id,this.time).ease(this.ease())},br.attr=function(a,b){return this.attrTween(a,bq(a,b))},br.attrTween=function(a,b){function d(a,d){var e=b.call(this,a,d,this.getAttribute(c));return e===bo?(this.removeAttribute(c),null):e&&function(a){this.setAttribute(c,e(a))}}function e(a,d){var e=b.call(this,a,d,this.getAttributeNS(c.space,c.local));return e===bo?(this.removeAttributeNS(c.space,c.local),null):e&&function(a){this.setAttributeNS(c.space,c.local,e(a))}}var c=d3.ns.qualify(a);return this.tween("attr."+a,c.local?e:d)},br.style=function(a,b,c){return arguments.length<3&&(c=""),this.styleTween(a,bq(a,b),c)},br.styleTween=function(a,b,c){return arguments.length<3&&(c=""),this.tween("style."+a,function(d,e){var f=b.call(this,d,e,window.getComputedStyle(this,null).getPropertyValue(a));return f===bo?(this.style.removeProperty(a),null):f&&function(b){this.style.setProperty(a,f(b),c)}})},br.text=function(a){return this.tween("text",function(b,c){this.textContent=typeof a=="function"?a.call(this,b,c):a})},br.remove=function(){return this.each("end",function(){var a;!this.__transition__&&(a=this.parentNode)&&a.removeChild(this)})},br.delay=function(a){var b=this;return b.each(typeof a=="function"?function(c,d,e){b[e][d].delay=+a.apply(this,arguments)}:(a=+a,function(c,d,e){b[e][d].delay=a}))},br.duration=function(a){var b=this;return b.each(typeof a=="function"?function(c,d,e){b[e][d].duration=+a.apply(this,arguments)}:(a=+a,function(c,d,e){b[e][d].duration=a}))},br.transition=function(){return this.select(i)};var bw=null,bx,by;d3.timer=function(a,b,c){var d=!1,e,f=bw;if(arguments.length<3){if(arguments.length<2)b=0;else if(!isFinite(b))return;c=Date.now()}while(f){if(f.callback===a){f.then=c,f.delay=b,d=!0;break}e=f,f=f.next}d||(bw={callback:a,then:c,delay:b,next:bw}),bx||(by=clearTimeout(by),bx=1,bB(bz))},d3.timer.flush=function(){var a,b=Date.now(),c=bw;while(c)a=b-c.then,c.delay||(c.flush=c.callback(a)),c=c.next;bA()};var bB=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(a,17)};d3.transform=function(a){return bG.setAttribute("transform",a),new bC(bG.transform.baseVal.consolidate().matrix)},bC.prototype.toString=function(){return"translate("+this.translate+")rotate("+this.rotate+")skewX("+this.skew+")scale("+this.scale+")"};var bG=document.createElementNS(d3.ns.prefix.svg,"g"),bH=180/Math.PI;d3.scale={},d3.scale.linear=function(){return bM([0,1],[0,1],d3.interpolate,!1)},d3.scale.log=function(){return bU(d3.scale.linear(),bW)};var bV=d3.format("e");bW.pow=function(a){return Math.pow(10,a)},bX.pow=function(a){return-Math.pow(10,-a)},d3.scale.pow=function(){return bY(d3.scale.linear(),1)},d3.scale.sqrt=function(){return d3.scale.pow().exponent(.5)},d3.scale.ordinal=function(){return b$([],{t:"range",x:[]})},d3.scale.category10=function(){return d3.scale.ordinal().range(b_)},d3.scale.category20=function(){return d3.scale.ordinal().range(ca)},d3.scale.category20b=function(){return d3.scale.ordinal().range(cb)},d3.scale.category20c=function(){return d3.scale.ordinal().range(cc)};var b_=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],ca=["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"],cb=["#393b79","#5254a3","#6b6ecf","#9c9ede","#637939","#8ca252","#b5cf6b","#cedb9c","#8c6d31","#bd9e39","#e7ba52","#e7cb94","#843c39","#ad494a","#d6616b","#e7969c","#7b4173","#a55194","#ce6dbd","#de9ed6"],cc=["#3182bd","#6baed6","#9ecae1","#c6dbef","#e6550d","#fd8d3c","#fdae6b","#fdd0a2","#31a354","#74c476","#a1d99b","#c7e9c0","#756bb1","#9e9ac8","#bcbddc","#dadaeb","#636363","#969696","#bdbdbd","#d9d9d9"];d3.scale.quantile=function(){return cd([],[])},d3.scale.quantize=function(){return ce(0,1,[0,1])},d3.svg={},d3.svg.arc=function(){function e(){var e=a.apply(this,arguments),f=b.apply(this,arguments),g=c.apply(this,arguments)+cf,h=d.apply(this,arguments)+cf,i=(h<g&&(i=g,g=h,h=i),h-g),j=i<Math.PI?"0":"1",k=Math.cos(g),l=Math.sin(g),m=Math.cos(h),n=Math.sin(h);return i>=cg?e?"M0,"+f+"A"+f+","+f+" 0 1,1 0,"+ -f+"A"+f+","+f+" 0 1,1 0,"+f+"M0,"+e+"A"+e+","+e+" 0 1,0 0,"+ -e+"A"+e+","+e+" 0 1,0 0,"+e+"Z":"M0,"+f+"A"+f+","+f+" 0 1,1 0,"+ -f+"A"+f+","+f+" 0 1,1 0,"+f+"Z":e?"M"+f*k+","+f*l+"A"+f+","+f+" 0 "+j+",1 "+f*m+","+f*n+"L"+e*m+","+e*n+"A"+e+","+e+" 0 "+j+",0 "+e*k+","+e*l+"Z":"M"+f*k+","+f*l+"A"+f+","+f+" 0 "+j+",1 "+f*m+","+f*n+"L0,0"+"Z"}var a=ch,b=ci,c=cj,d=ck;return e.innerRadius=function(b){return arguments.length?(a=d3.functor(b),e):a},e.outerRadius=function(a){return arguments.length?(b=d3.functor(a),e):b},e.startAngle=function(a){return arguments.length?(c=d3.functor(a),e):c},e.endAngle=function(a){return arguments.length?(d=d3.functor(a),e):d},e.centroid=function(){var e=(a.apply(this,arguments)+b.apply(this,arguments))/2,f=(c.apply(this,arguments)+d.apply(this,arguments))/2+cf;return[Math.cos(f)*e,Math.sin(f)*e]},e};var cf=-Math.PI/2,cg=2*Math.PI-1e-6;d3.svg.line=function(){return cl(Object)};var cp={linear:cq,"step-before":cr,"step-after":cs,basis:cy,"basis-open":cz,"basis-closed":cA,bundle:cB,cardinal:cv,"cardinal-open":ct,"cardinal-closed":cu,monotone:cK},cD=[0,2/3,1/3,0],cE=[0,1/3,2/3,0],cF=[0,1/6,2/3,1/6];d3.svg.line.radial=function(){var a=cl(cL);return a.radius=a.x,delete a.x,a.angle=a.y,delete a.y,a},cr.reverse=cs,cs.reverse=cr,d3.svg.area=function(){return cM(Object)},d3.svg.area.radial=function(){var a=cM(cL);return a.radius=a.x,delete a.x,a.innerRadius=a.x0,delete a.x0,a.outerRadius=a.x1,delete a.x1,a.angle=a.y,delete a.y,a.startAngle=a.y0,delete a.y0,a.endAngle=a.y1,delete a.y1,a},d3.svg.chord=function(){function f(c,d){var e=g(this,a,c,d),f=g(this,b,c,d);return"M"+e.p0+i(e.r,e.p1)+(h(e,f)?j(e.r,e.p1,e.r,e.p0):j(e.r,e.p1,f.r,f.p0)+i(f.r,f.p1)+j(f.r,f.p1,e.r,e.p0))+"Z"}function g(a,b,f,g){var h=b.call(a,f,g),i=c.call(a,h,g),j=d.call(a,h,g)+cf,k=e.call(a,h,g)+cf;return{r:i,a0:j,a1:k,p0:[i*Math.cos(j),i*Math.sin(j)],p1:[i*Math.cos(k),i*Math.sin(k)]}}function h(a,b){return a.a0==b.a0&&a.a1==b.a1}function i(a,b){return"A"+a+","+a+" 0 0,1 "+b}function j(a,b,c,d){return"Q 0,0 "+d}var a=cP,b=cQ,c=cR,d=cj,e=ck;return f.radius=function(a){return arguments.length?(c=d3.functor(a),f):c},f.source=function(b){return arguments.length?(a=d3.functor(b),f):a},f.target=function(a){return arguments.length?(b=d3.functor(a),f):b},f.startAngle=function(a){return arguments.length?(d=d3.functor(a),f):d},f.endAngle=function(a){return arguments.length?(e=d3.functor(a),f):e},f},d3.svg.diagonal=function(){function d(d,e){var f=a.call(this,d,e),g=b.call(this,d,e),h=(f.y+g.y)/2,i=[f,{x:f.x,y:h},{x:g.x,y:h},g];return i=i.map(c),"M"+i[0]+"C"+i[1]+" "+i[2]+" "+i[3]}var a=cP,b=cQ,c=cU;return d.source=function(b){return arguments.length?(a=d3.functor(b),d):a},d.target=function(a){return arguments.length?(b=d3.functor(a),d):b},d.projection=function(a){return arguments.length?(c=a,d):c},d},d3.svg.diagonal.radial=function(){var a=d3.svg.diagonal(),b=cU,c=a.projection;return a.projection=function(a){return arguments.length?c(cV(b=a)):b},a},d3.svg.mouse=function(a){return cX(a,d3.event)};var cW=/WebKit/.test(navigator.userAgent)?-1:0;d3.svg.touches=function(a,b){return arguments.length<2&&(b=d3.event.touches),b?d(b).map(function(b){var c=cX(a,b);return c.identifier=b.identifier,c}):[]},d3.svg.symbol=function(){function c(c,d){return(c$[a.call(this,c,d)]||c$.circle)(b.call(this,c,d))}var a=cZ,b=cY;return c.type=function(b){return arguments.length?(a=d3.functor(b),c):a},c.size=function(a){return arguments.length?(b=d3.functor(a),c):b},c};var c$={circle:function(a){var b=Math.sqrt(a/Math.PI);return"M0,"+b+"A"+b+","+b+" 0 1,1 0,"+ -b+"A"+b+","+b+" 0 1,1 0,"+b+"Z"},cross:function(a){var b=Math.sqrt(a/5)/2;return"M"+ -3*b+","+ -b+"H"+ -b+"V"+ -3*b+"H"+b+"V"+ -b+"H"+3*b+"V"+b+"H"+b+"V"+3*b+"H"+ -b+"V"+b+"H"+ -3*b+"Z"},diamond:function(a){var b=Math.sqrt(a/(2*da)),c=b*da;return"M0,"+ -b+"L"+c+",0"+" 0,"+b+" "+ -c+",0"+"Z"},square:function(a){var b=Math.sqrt(a)/2;return"M"+ -b+","+ -b+"L"+b+","+ -b+" "+b+","+b+" "+ -b+","+b+"Z"},"triangle-down":function(a){var b=Math.sqrt(a/c_),c=b*c_/2;return"M0,"+c+"L"+b+","+ -c+" "+ -b+","+ -c+"Z"},"triangle-up":function(a){var b=Math.sqrt(a/c_),c=b*c_/2;return"M0,"+ -c+"L"+b+","+c+" "+ -b+","+c+"Z"}};d3.svg.symbolTypes=d3.keys(c$);var c_=Math.sqrt(3),da=Math.tan(30*Math.PI/180);d3.svg.axis=function(){function j(j){j.each(function(k,l,m){var n=d3.select(this),o=j.delay?function(a){var b=bt;try{return bt=j.id,a.transition().delay(j[m][l].delay).duration(j[m][l].duration).ease(j.ease())}finally{bt=b}}:Object,p=a.ticks.apply(a,g),q=h==null?a.tickFormat.apply(a,g):h,r=dd(a,p,i),s=n.selectAll(".minor").data(r,String),t=s.enter().insert("svg:line","g").attr("class","tick minor").style("opacity",1e-6),u=o(s.exit()).style("opacity",1e-6).remove(),v=o(s).style("opacity",1),w=n.selectAll("g").data(p,String),x=w.enter().insert("svg:g","path").style("opacity",1e-6),y=o(w.exit()).style("opacity",1e-6).remove(),z=o(w).style("opacity",1),A,B=bJ(a.range()),C=n.selectAll(".domain").data([0]),D=C.enter().append("svg:path").attr("class","domain"),E=o(C),F=this.__chart__||a;this.__chart__=a.copy(),x.append("svg:line").attr("class","tick"),x.append("svg:text"),z.select("text").text(q);switch(b){case"bottom":A=db,v.attr("x2",0).attr("y2",d),z.select("line").attr("x2",0).attr("y2",c),z.select("text").attr("x",0).attr("y",Math.max(c,0)+f).attr("dy",".71em").attr("text-anchor","middle"),E.attr("d","M"+B[0]+","+e+"V0H"+B[1]+"V"+e);break;case"top":A=db,v.attr("x2",0).attr("y2",-d),z.select("line").attr("x2",0).attr("y2",-c),z.select("text").attr("x",0).attr("y",-(Math.max(c,0)+f)).attr("dy","0em").attr("text-anchor","middle"),E.attr("d","M"+B[0]+","+ -e+"V0H"+B[1]+"V"+ -e);break;case"left":A=dc,v.attr("x2",-d).attr("y2",0),z.select("line").attr("x2",-c).attr("y2",0),z.select("text").attr("x",-(Math.max(c,0)+f)).attr("y",0).attr("dy",".32em").attr("text-anchor","end"),E.attr("d","M"+ -e+","+B[0]+"H0V"+B[1]+"H"+ -e);break;case"right":A=dc,v.attr("x2",d).attr("y2",0),z.select("line").attr("x2",c).attr("y2",0),z.select("text").attr("x",Math.max(c,0)+f).attr("y",0).attr("dy",".32em").attr("text-anchor","start"),E.attr("d","M"+e+","+B[0]+"H0V"+B[1]+"H"+e)}x.call(A,F),z.call(A,a),y.call(A,a),t.call(A,F),v.call(A,a),u.call(A,a)})}var a=d3.scale.linear(),b="bottom",c=6,d=6,e=6,f=3,g=[10],h,i=0;return j.scale=function(b){return arguments.length?(a=b,j):a},j.orient=function(a){return arguments.length?(b=a,j):b},j.ticks=function(){return arguments.length?(g=arguments,j):g},j.tickFormat=function(a){return arguments.length?(h=a,j):h},j.tickSize=function(a,b,f){if(!arguments.length)return c;var g=arguments.length-1;return c=+a,d=g>1?+b:c,e=g>0?+arguments[g]:c,j},j.tickPadding=function(a){return arguments.length?(f=+a,j):f},j.tickSubdivide=function(a){return arguments.length?(i=+a,j):i},j},d3.svg.brush=function(){function e(a){var g=b&&c?["n","e","s","w","nw","ne","se","sw"]:b?["e","w"]:c?["n","s"]:[];a.each(function(){var a=d3.select(this).on("mousedown.brush",f),h=a.selectAll(".background").data([,]),i=a.selectAll(".extent").data([,]),j=a.selectAll(".resize").data(g,String),k;h.enter().append("svg:rect").attr("class","background").style("visibility","hidden").style("pointer-events","all").style("cursor","crosshair"),i.enter().append("svg:rect").attr("class","extent").style("cursor","move"),j.enter().append("svg:rect").attr("class",function(a){return"resize "+a}).attr("width",6).attr("height",6).style("visibility","hidden").style("pointer-events",e.empty()?"none":"all").style("cursor",function(a){return dw[a]}),j.exit().remove(),b&&(k=bJ(b.range()),h.attr("x",k[0]).attr("width",k[1]-k[0]),dp(a,d)),c&&(k=bJ(c.range()),h.attr("y",k[0]).attr("height",k[1]-k[0]),dq(a,d))})}function f(){var a=d3.select(d3.event.target);de=e,dg=this,dj=d,dn=d3.svg.mouse(dg),(dk=a.classed("extent"))?(dn[0]=d[0][0]-dn[0],dn[1]=d[0][1]-dn[1]):a.classed("resize")?(dl=d3.event.target.__data__,dn[0]=d[+/w$/.test(dl)][0],dn[1]=d[+/^n/.test(dl)][1]):d3.event.altKey&&(dm=dn.slice()),dh=!/^(n|s)$/.test(dl)&&b,di=!/^(e|w)$/.test(dl)&&c,df=g(this,arguments),df("brushstart"),dt(),M()}function g(b,c){return function(d){var f=d3.event;try{d3.event={type:d,target:e},a[d].apply(b,c)}finally{d3.event=f}}}var a=d3.dispatch("brushstart","brush","brushend"),b,c,d=[[0,0],[0,0]];return e.x=function(a){return arguments.length?(b=a,e):b},e.y=function(a){return arguments.length?(c=a,e):c},e.extent=function(a){var f,g,h,i,j;return arguments.length?(b&&(f=a[0],g=a[1],c&&(f=f[0],g=g[0]),f=b(f),g=b(g),g<f&&(j=f,f=g,g=j),d[0][0]=f,d[1][0]=g),c&&(h=a[0],i=a[1],b&&(h=h[1],i=i[1]),h=c(h),i=c(i),i<h&&(j=h,h=i,i=j),d[0][1]=h,d[1][1]=i),e):(b&&(f=b.invert(d[0][0]),g=b.invert(d[1][0]),g<f&&(j=f,f=g,g=j)),c&&(h=c.invert(d[0][1]),i=c.invert(d[1][1]),i<h&&(j=h,h=i,i=j)),b&&c?[[f,h],[g,i]]:b?[f,g]:c&&[h,i])},e.clear=function(){return d[0][0]=d[0][1]=d[1][0]=d[1][1]=0,e},e.empty=function(){return b&&d[0][0]===d[1][0]||c&&d[0][1]===d[1][1]},e.on=function(b,c){return a.on(b,c),e},d3.select(window).on("mousemove.brush",dt).on("mouseup.brush",dv).on("keydown.brush",dr).on("keyup.brush",ds),e};var de,df,dg,dh,di,dj,dk,dl,dm,dn,dw={n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"};d3.behavior={},d3.behavior.drag=function(){function b(){this.on("mousedown.drag",d).on("touchstart.drag",d),d3.select(window).on("mousemove.drag",dG).on("touchmove.drag",dG).on("mouseup.drag",dH,!0).on("touchend.drag",dH,!0).on("click.drag",dI,!0)}function c(){dx=a,dy=d3.event.target,dB=dF((dz=this).parentNode),dC=0,dA=arguments}function d(){c.apply(this,arguments),dE("dragstart")}var a=d3.dispatch("drag","dragstart","dragend");return b.on=function(c,d){return a.on(c,d),b},b};var dx,dy,dz,dA,dB,dC,dD;d3.behavior.zoom=function(){function d(){this.on("mousedown.zoom",f).on("mousewheel.zoom",g).on("DOMMouseScroll.zoom",g).on("dblclick.zoom",h).on("touchstart.zoom",i),d3.select(window).on("mousemove.zoom",d$).on("mouseup.zoom",d_).on("touchmove.zoom",dZ).on("touchend.zoom",dY).on("click.zoom",ea,!0)}function e(){dO=a,dP=c,dQ=b.zoom,dR=d3.event.target,dS=this,dT=arguments}function f(){e.apply(this,arguments),dK=dW(d3.svg.mouse(dS)),dU=!1,d3.event.preventDefault(),window.focus()}function g(){e.apply(this,arguments),dL||(dL=dW(d3.svg.mouse(dS))),eb(dX()+a[2],d3.svg.mouse(dS),dL)}function h(){e.apply(this,arguments);var b=d3.svg.mouse(dS);eb(d3.event.shiftKey?Math.ceil(a[2]-1):Math.floor(a[2]+1),b,dW(b))}function i(){e.apply(this,arguments);var b=dY(),c,d=Date.now();b.length===1&&d-dN<300&&eb(1+Math.floor(a[2]),c=b[0],dM[c.identifier]),dN=d}var a=[0,0,0],b=d3.dispatch("zoom"),c=ec;return d.extent=function(a){return arguments.length?(c=a==null?ec:a,d):c},d.on=function(a,c){return b.on(a,c),d},d};var dJ,dK,dL,dM={},dN=0,dO,dP,dQ,dR,dS,dT,dU,dV,ec=[[-Infinity,Infinity],[-Infinity,Infinity],[-Infinity,Infinity]]})();
@@ -0,0 +1,2637 @@
1
+ var Rickshaw = {
2
+
3
+ namespace: function(namespace, obj) {
4
+
5
+ var parts = namespace.split('.');
6
+
7
+ var parent = Rickshaw;
8
+
9
+ for(var i = 1, length = parts.length; i < length; i++) {
10
+ currentPart = parts[i];
11
+ parent[currentPart] = parent[currentPart] || {};
12
+ parent = parent[currentPart];
13
+ }
14
+ return parent;
15
+ },
16
+
17
+ keys: function(obj) {
18
+ var keys = [];
19
+ for (var key in obj) keys.push(key);
20
+ return keys;
21
+ },
22
+
23
+ extend: function(destination, source) {
24
+
25
+ for (var property in source) {
26
+ destination[property] = source[property];
27
+ }
28
+ return destination;
29
+ }
30
+ };
31
+
32
+ if (typeof module !== 'undefined' && module.exports) {
33
+ var d3 = require('d3');
34
+ module.exports = Rickshaw;
35
+ }
36
+
37
+ /* Adapted from https://github.com/Jakobo/PTClass */
38
+
39
+ /*
40
+ Copyright (c) 2005-2010 Sam Stephenson
41
+
42
+ Permission is hereby granted, free of charge, to any person obtaining a copy
43
+ of this software and associated documentation files (the "Software"), to deal
44
+ in the Software without restriction, including without limitation the rights
45
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46
+ copies of the Software, and to permit persons to whom the Software is
47
+ furnished to do so, subject to the following conditions:
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
+ SOFTWARE.
56
+ */
57
+ /* Based on Alex Arnell's inheritance implementation. */
58
+ /** section: Language
59
+ * class Class
60
+ *
61
+ * Manages Prototype's class-based OOP system.
62
+ *
63
+ * Refer to Prototype's web site for a [tutorial on classes and
64
+ * inheritance](http://prototypejs.org/learn/class-inheritance).
65
+ **/
66
+ (function(globalContext) {
67
+ /* ------------------------------------ */
68
+ /* Import from object.js */
69
+ /* ------------------------------------ */
70
+ var _toString = Object.prototype.toString,
71
+ NULL_TYPE = 'Null',
72
+ UNDEFINED_TYPE = 'Undefined',
73
+ BOOLEAN_TYPE = 'Boolean',
74
+ NUMBER_TYPE = 'Number',
75
+ STRING_TYPE = 'String',
76
+ OBJECT_TYPE = 'Object',
77
+ FUNCTION_CLASS = '[object Function]';
78
+ function isFunction(object) {
79
+ return _toString.call(object) === FUNCTION_CLASS;
80
+ }
81
+ function extend(destination, source) {
82
+ for (var property in source) if (source.hasOwnProperty(property)) // modify protect primitive slaughter
83
+ destination[property] = source[property];
84
+ return destination;
85
+ }
86
+ function keys(object) {
87
+ if (Type(object) !== OBJECT_TYPE) { throw new TypeError(); }
88
+ var results = [];
89
+ for (var property in object) {
90
+ if (object.hasOwnProperty(property)) {
91
+ results.push(property);
92
+ }
93
+ }
94
+ return results;
95
+ }
96
+ function Type(o) {
97
+ switch(o) {
98
+ case null: return NULL_TYPE;
99
+ case (void 0): return UNDEFINED_TYPE;
100
+ }
101
+ var type = typeof o;
102
+ switch(type) {
103
+ case 'boolean': return BOOLEAN_TYPE;
104
+ case 'number': return NUMBER_TYPE;
105
+ case 'string': return STRING_TYPE;
106
+ }
107
+ return OBJECT_TYPE;
108
+ }
109
+ function isUndefined(object) {
110
+ return typeof object === "undefined";
111
+ }
112
+ /* ------------------------------------ */
113
+ /* Import from Function.js */
114
+ /* ------------------------------------ */
115
+ var slice = Array.prototype.slice;
116
+ function argumentNames(fn) {
117
+ var names = fn.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
118
+ .replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
119
+ .replace(/\s+/g, '').split(',');
120
+ return names.length == 1 && !names[0] ? [] : names;
121
+ }
122
+ function wrap(fn, wrapper) {
123
+ var __method = fn;
124
+ return function() {
125
+ var a = update([bind(__method, this)], arguments);
126
+ return wrapper.apply(this, a);
127
+ }
128
+ }
129
+ function update(array, args) {
130
+ var arrayLength = array.length, length = args.length;
131
+ while (length--) array[arrayLength + length] = args[length];
132
+ return array;
133
+ }
134
+ function merge(array, args) {
135
+ array = slice.call(array, 0);
136
+ return update(array, args);
137
+ }
138
+ function bind(fn, context) {
139
+ if (arguments.length < 2 && isUndefined(arguments[0])) return this;
140
+ var __method = fn, args = slice.call(arguments, 2);
141
+ return function() {
142
+ var a = merge(args, arguments);
143
+ return __method.apply(context, a);
144
+ }
145
+ }
146
+
147
+ /* ------------------------------------ */
148
+ /* Import from Prototype.js */
149
+ /* ------------------------------------ */
150
+ var emptyFunction = function(){};
151
+
152
+ var Class = (function() {
153
+
154
+ // Some versions of JScript fail to enumerate over properties, names of which
155
+ // correspond to non-enumerable properties in the prototype chain
156
+ var IS_DONTENUM_BUGGY = (function(){
157
+ for (var p in { toString: 1 }) {
158
+ // check actual property name, so that it works with augmented Object.prototype
159
+ if (p === 'toString') return false;
160
+ }
161
+ return true;
162
+ })();
163
+
164
+ function subclass() {};
165
+ function create() {
166
+ var parent = null, properties = [].slice.apply(arguments);
167
+ if (isFunction(properties[0]))
168
+ parent = properties.shift();
169
+
170
+ function klass() {
171
+ this.initialize.apply(this, arguments);
172
+ }
173
+
174
+ extend(klass, Class.Methods);
175
+ klass.superclass = parent;
176
+ klass.subclasses = [];
177
+
178
+ if (parent) {
179
+ subclass.prototype = parent.prototype;
180
+ klass.prototype = new subclass;
181
+ try { parent.subclasses.push(klass) } catch(e) {}
182
+ }
183
+
184
+ for (var i = 0, length = properties.length; i < length; i++)
185
+ klass.addMethods(properties[i]);
186
+
187
+ if (!klass.prototype.initialize)
188
+ klass.prototype.initialize = emptyFunction;
189
+
190
+ klass.prototype.constructor = klass;
191
+ return klass;
192
+ }
193
+
194
+ function addMethods(source) {
195
+ var ancestor = this.superclass && this.superclass.prototype,
196
+ properties = keys(source);
197
+
198
+ // IE6 doesn't enumerate `toString` and `valueOf` (among other built-in `Object.prototype`) properties,
199
+ // Force copy if they're not Object.prototype ones.
200
+ // Do not copy other Object.prototype.* for performance reasons
201
+ if (IS_DONTENUM_BUGGY) {
202
+ if (source.toString != Object.prototype.toString)
203
+ properties.push("toString");
204
+ if (source.valueOf != Object.prototype.valueOf)
205
+ properties.push("valueOf");
206
+ }
207
+
208
+ for (var i = 0, length = properties.length; i < length; i++) {
209
+ var property = properties[i], value = source[property];
210
+ if (ancestor && isFunction(value) &&
211
+ argumentNames(value)[0] == "$super") {
212
+ var method = value;
213
+ value = wrap((function(m) {
214
+ return function() { return ancestor[m].apply(this, arguments); };
215
+ })(property), method);
216
+
217
+ value.valueOf = bind(method.valueOf, method);
218
+ value.toString = bind(method.toString, method);
219
+ }
220
+ this.prototype[property] = value;
221
+ }
222
+
223
+ return this;
224
+ }
225
+
226
+ return {
227
+ create: create,
228
+ Methods: {
229
+ addMethods: addMethods
230
+ }
231
+ };
232
+ })();
233
+
234
+ if (globalContext.exports) {
235
+ globalContext.exports.Class = Class;
236
+ }
237
+ else {
238
+ globalContext.Class = Class;
239
+ }
240
+ })(Rickshaw);
241
+ Rickshaw.namespace('Rickshaw.Compat.ClassList');
242
+
243
+ Rickshaw.Compat.ClassList = function() {
244
+
245
+ /* adapted from http://purl.eligrey.com/github/classList.js/blob/master/classList.js */
246
+
247
+ if (typeof document !== "undefined" && !("classList" in document.createElement("a"))) {
248
+
249
+ (function (view) {
250
+
251
+ "use strict";
252
+
253
+ var
254
+ classListProp = "classList"
255
+ , protoProp = "prototype"
256
+ , elemCtrProto = (view.HTMLElement || view.Element)[protoProp]
257
+ , objCtr = Object
258
+ , strTrim = String[protoProp].trim || function () {
259
+ return this.replace(/^\s+|\s+$/g, "");
260
+ }
261
+ , arrIndexOf = Array[protoProp].indexOf || function (item) {
262
+ var
263
+ i = 0
264
+ , len = this.length
265
+ ;
266
+ for (; i < len; i++) {
267
+ if (i in this && this[i] === item) {
268
+ return i;
269
+ }
270
+ }
271
+ return -1;
272
+ }
273
+ // Vendors: please allow content code to instantiate DOMExceptions
274
+ , DOMEx = function (type, message) {
275
+ this.name = type;
276
+ this.code = DOMException[type];
277
+ this.message = message;
278
+ }
279
+ , checkTokenAndGetIndex = function (classList, token) {
280
+ if (token === "") {
281
+ throw new DOMEx(
282
+ "SYNTAX_ERR"
283
+ , "An invalid or illegal string was specified"
284
+ );
285
+ }
286
+ if (/\s/.test(token)) {
287
+ throw new DOMEx(
288
+ "INVALID_CHARACTER_ERR"
289
+ , "String contains an invalid character"
290
+ );
291
+ }
292
+ return arrIndexOf.call(classList, token);
293
+ }
294
+ , ClassList = function (elem) {
295
+ var
296
+ trimmedClasses = strTrim.call(elem.className)
297
+ , classes = trimmedClasses ? trimmedClasses.split(/\s+/) : []
298
+ , i = 0
299
+ , len = classes.length
300
+ ;
301
+ for (; i < len; i++) {
302
+ this.push(classes[i]);
303
+ }
304
+ this._updateClassName = function () {
305
+ elem.className = this.toString();
306
+ };
307
+ }
308
+ , classListProto = ClassList[protoProp] = []
309
+ , classListGetter = function () {
310
+ return new ClassList(this);
311
+ }
312
+ ;
313
+ // Most DOMException implementations don't allow calling DOMException's toString()
314
+ // on non-DOMExceptions. Error's toString() is sufficient here.
315
+ DOMEx[protoProp] = Error[protoProp];
316
+ classListProto.item = function (i) {
317
+ return this[i] || null;
318
+ };
319
+ classListProto.contains = function (token) {
320
+ token += "";
321
+ return checkTokenAndGetIndex(this, token) !== -1;
322
+ };
323
+ classListProto.add = function (token) {
324
+ token += "";
325
+ if (checkTokenAndGetIndex(this, token) === -1) {
326
+ this.push(token);
327
+ this._updateClassName();
328
+ }
329
+ };
330
+ classListProto.remove = function (token) {
331
+ token += "";
332
+ var index = checkTokenAndGetIndex(this, token);
333
+ if (index !== -1) {
334
+ this.splice(index, 1);
335
+ this._updateClassName();
336
+ }
337
+ };
338
+ classListProto.toggle = function (token) {
339
+ token += "";
340
+ if (checkTokenAndGetIndex(this, token) === -1) {
341
+ this.add(token);
342
+ } else {
343
+ this.remove(token);
344
+ }
345
+ };
346
+ classListProto.toString = function () {
347
+ return this.join(" ");
348
+ };
349
+
350
+ if (objCtr.defineProperty) {
351
+ var classListPropDesc = {
352
+ get: classListGetter
353
+ , enumerable: true
354
+ , configurable: true
355
+ };
356
+ try {
357
+ objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
358
+ } catch (ex) { // IE 8 doesn't support enumerable:true
359
+ if (ex.number === -0x7FF5EC54) {
360
+ classListPropDesc.enumerable = false;
361
+ objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
362
+ }
363
+ }
364
+ } else if (objCtr[protoProp].__defineGetter__) {
365
+ elemCtrProto.__defineGetter__(classListProp, classListGetter);
366
+ }
367
+
368
+ }(window));
369
+
370
+ }
371
+ };
372
+
373
+ if ( (typeof RICKSHAW_NO_COMPAT !== "undefined" && !RICKSHAW_NO_COMPAT) || typeof RICKSHAW_NO_COMPAT === "undefined") {
374
+ new Rickshaw.Compat.ClassList();
375
+ }
376
+ Rickshaw.namespace('Rickshaw.Graph');
377
+
378
+ Rickshaw.Graph = function(args) {
379
+
380
+ this.element = args.element;
381
+ this.series = args.series;
382
+
383
+ this.defaults = {
384
+ interpolation: 'cardinal',
385
+ offset: 'zero',
386
+ min: undefined,
387
+ max: undefined
388
+ };
389
+
390
+ Rickshaw.keys(this.defaults).forEach( function(k) {
391
+ this[k] = args[k] || this.defaults[k];
392
+ }, this );
393
+
394
+ this.window = {};
395
+
396
+ this.updateCallbacks = [];
397
+
398
+ var self = this;
399
+
400
+ this.initialize = function(args) {
401
+
402
+ this.validateSeries(args.series);
403
+
404
+ this.series.active = function() { return self.series.filter( function(s) { return !s.disabled } ) };
405
+
406
+ this.setSize({ width: args.width, height: args.height });
407
+
408
+ this.element.classList.add('rickshaw_graph');
409
+ this.vis = d3.select(this.element)
410
+ .append("svg:svg")
411
+ .attr('width', this.width)
412
+ .attr('height', this.height);
413
+
414
+ var renderers = [
415
+ Rickshaw.Graph.Renderer.Stack,
416
+ Rickshaw.Graph.Renderer.Line,
417
+ Rickshaw.Graph.Renderer.Bar,
418
+ Rickshaw.Graph.Renderer.Area,
419
+ Rickshaw.Graph.Renderer.ScatterPlot
420
+ ];
421
+
422
+ renderers.forEach( function(r) {
423
+ if (!r) return;
424
+ self.registerRenderer(new r( { graph: self } ));
425
+ } );
426
+
427
+ this.setRenderer(args.renderer || 'stack', args);
428
+ this.discoverRange();
429
+ };
430
+
431
+ this.validateSeries = function(series) {
432
+
433
+ if (!(series instanceof Array) && !(series instanceof Rickshaw.Series)) {
434
+ var seriesSignature = Object.prototype.toString.apply(series);
435
+ throw "series is not an array: " + seriesSignature;
436
+ }
437
+
438
+ var pointsCount;
439
+
440
+ series.forEach( function(s) {
441
+
442
+ if (!(s instanceof Object)) {
443
+ throw "series element is not an object: " + s;
444
+ }
445
+ if (!(s.data)) {
446
+ throw "series has no data: " + JSON.stringify(s);
447
+ }
448
+ if (!(s.data instanceof Array)) {
449
+ throw "series data is not an array: " + JSON.stringify(s.data);
450
+ }
451
+
452
+ pointsCount = pointsCount || s.data.length;
453
+
454
+ if (pointsCount && s.data.length != pointsCount) {
455
+ throw "series cannot have differing numbers of points: " +
456
+ pointsCount + " vs " + s.data.length + "; see Rickshaw.Series.zeroFill()";
457
+ }
458
+
459
+ var dataTypeX = typeof s.data[0].x;
460
+ var dataTypeY = typeof s.data[0].y;
461
+
462
+ if (dataTypeX != 'number' || dataTypeY != 'number') {
463
+ throw "x and y properties of points should be numbers instead of " +
464
+ dataTypeX + " and " + dataTypeY;
465
+ }
466
+ } );
467
+ };
468
+
469
+ this.dataDomain = function() {
470
+
471
+ // take from the first series
472
+ var data = this.series[0].data;
473
+
474
+ return [ data[0].x, data.slice(-1).shift().x ];
475
+
476
+ };
477
+
478
+ this.discoverRange = function() {
479
+
480
+ var domain = this.renderer.domain();
481
+
482
+ this.x = d3.scale.linear().domain(domain.x).range([0, this.width]);
483
+
484
+ this.y = d3.scale.linear().domain(domain.y).range([this.height, 0]);
485
+
486
+ this.y.magnitude = d3.scale.linear()
487
+ .domain([domain.y[0] - domain.y[0], domain.y[1] - domain.y[0]])
488
+ .range([0, this.height]);
489
+ };
490
+
491
+ this.render = function() {
492
+
493
+ var stackedData = this.stackData();
494
+ this.discoverRange();
495
+
496
+ this.renderer.render();
497
+
498
+ this.updateCallbacks.forEach( function(callback) {
499
+ callback();
500
+ } );
501
+ };
502
+
503
+ this.update = this.render;
504
+
505
+ this.stackData = function() {
506
+
507
+ var data = this.series.active()
508
+ .map( function(d) { return d.data } )
509
+ .map( function(d) { return d.filter( function(d) { return this._slice(d) }, this ) }, this);
510
+
511
+ this.stackData.hooks.data.forEach( function(entry) {
512
+ data = entry.f.apply(self, [data]);
513
+ } );
514
+
515
+ var layout = d3.layout.stack();
516
+ layout.offset( self.offset );
517
+
518
+ var stackedData = layout(data);
519
+
520
+ this.stackData.hooks.after.forEach( function(entry) {
521
+ stackedData = entry.f.apply(self, [data]);
522
+ } );
523
+
524
+ var i = 0;
525
+ this.series.forEach( function(series) {
526
+ if (series.disabled) return;
527
+ series.stack = stackedData[i++];
528
+ } );
529
+
530
+ this.stackedData = stackedData;
531
+ return stackedData;
532
+ };
533
+
534
+ this.stackData.hooks = { data: [], after: [] };
535
+
536
+ this._slice = function(d) {
537
+
538
+ if (this.window.xMin || this.window.xMax) {
539
+
540
+ var isInRange = true;
541
+
542
+ if (this.window.xMin && d.x < this.window.xMin) isInRange = false;
543
+ if (this.window.xMax && d.x > this.window.xMax) isInRange = false;
544
+
545
+ return isInRange;
546
+ }
547
+
548
+ return true;
549
+ };
550
+
551
+ this.onUpdate = function(callback) {
552
+ this.updateCallbacks.push(callback);
553
+ };
554
+
555
+ this.registerRenderer = function(renderer) {
556
+ this._renderers = this._renderers || {};
557
+ this._renderers[renderer.name] = renderer;
558
+ };
559
+
560
+ this.configure = function(args) {
561
+
562
+ if (args.width || args.height) {
563
+ this.setSize(args);
564
+ }
565
+
566
+ Rickshaw.keys(this.defaults).forEach( function(k) {
567
+ this[k] = k in args ? args[k]
568
+ : k in this ? this[k]
569
+ : this.defaults[k];
570
+ }, this );
571
+
572
+ this.setRenderer(args.renderer || this.renderer.name, args);
573
+ };
574
+
575
+ this.setRenderer = function(name, args) {
576
+
577
+ if (!this._renderers[name]) {
578
+ throw "couldn't find renderer " + name;
579
+ }
580
+ this.renderer = this._renderers[name];
581
+
582
+ if (typeof args == 'object') {
583
+ this.renderer.configure(args);
584
+ }
585
+ };
586
+
587
+ this.setSize = function(args) {
588
+
589
+ args = args || {};
590
+
591
+ if (typeof window !== undefined) {
592
+ var style = window.getComputedStyle(this.element, null);
593
+ var elementWidth = parseInt(style.getPropertyValue('width'));
594
+ var elementHeight = parseInt(style.getPropertyValue('height'));
595
+ }
596
+
597
+ this.width = args.width || elementWidth || 400;
598
+ this.height = args.height || elementHeight || 250;
599
+
600
+ this.vis && this.vis
601
+ .attr('width', this.width)
602
+ .attr('height', this.height);
603
+ }
604
+
605
+ this.initialize(args);
606
+ };
607
+ Rickshaw.namespace('Rickshaw.Fixtures.Color');
608
+
609
+ Rickshaw.Fixtures.Color = function() {
610
+
611
+ this.schemes = {};
612
+
613
+ this.schemes.spectrum14 = [
614
+ '#ecb796',
615
+ '#dc8f70',
616
+ '#b2a470',
617
+ '#92875a',
618
+ '#716c49',
619
+ '#d2ed82',
620
+ '#bbe468',
621
+ '#a1d05d',
622
+ '#e7cbe6',
623
+ '#d8aad6',
624
+ '#a888c2',
625
+ '#9dc2d3',
626
+ '#649eb9',
627
+ '#387aa3'
628
+ ].reverse();
629
+
630
+ this.schemes.spectrum2000 = [
631
+ '#57306f',
632
+ '#514c76',
633
+ '#646583',
634
+ '#738394',
635
+ '#6b9c7d',
636
+ '#84b665',
637
+ '#a7ca50',
638
+ '#bfe746',
639
+ '#e2f528',
640
+ '#fff726',
641
+ '#ecdd00',
642
+ '#d4b11d',
643
+ '#de8800',
644
+ '#de4800',
645
+ '#c91515',
646
+ '#9a0000',
647
+ '#7b0429',
648
+ '#580839',
649
+ '#31082b'
650
+ ];
651
+
652
+ this.schemes.spectrum2001 = [
653
+ '#2f243f',
654
+ '#3c2c55',
655
+ '#4a3768',
656
+ '#565270',
657
+ '#6b6b7c',
658
+ '#72957f',
659
+ '#86ad6e',
660
+ '#a1bc5e',
661
+ '#b8d954',
662
+ '#d3e04e',
663
+ '#ccad2a',
664
+ '#cc8412',
665
+ '#c1521d',
666
+ '#ad3821',
667
+ '#8a1010',
668
+ '#681717',
669
+ '#531e1e',
670
+ '#3d1818',
671
+ '#320a1b'
672
+ ];
673
+
674
+ this.schemes.classic9 = [
675
+ '#423d4f',
676
+ '#4a6860',
677
+ '#848f39',
678
+ '#a2b73c',
679
+ '#ddcb53',
680
+ '#c5a32f',
681
+ '#7d5836',
682
+ '#963b20',
683
+ '#7c2626',
684
+ '#491d37',
685
+ '#2f254a'
686
+ ].reverse();
687
+
688
+ this.schemes.httpStatus = {
689
+ 503: '#ea5029',
690
+ 502: '#d23f14',
691
+ 500: '#bf3613',
692
+ 410: '#efacea',
693
+ 409: '#e291dc',
694
+ 403: '#f457e8',
695
+ 408: '#e121d2',
696
+ 401: '#b92dae',
697
+ 405: '#f47ceb',
698
+ 404: '#a82a9f',
699
+ 400: '#b263c6',
700
+ 301: '#6fa024',
701
+ 302: '#87c32b',
702
+ 307: '#a0d84c',
703
+ 304: '#28b55c',
704
+ 200: '#1a4f74',
705
+ 206: '#27839f',
706
+ 201: '#52adc9',
707
+ 202: '#7c979f',
708
+ 203: '#a5b8bd',
709
+ 204: '#c1cdd1'
710
+ };
711
+
712
+ this.schemes.colorwheel = [
713
+ '#b5b6a9',
714
+ '#858772',
715
+ '#785f43',
716
+ '#96557e',
717
+ '#4682b4',
718
+ '#65b9ac',
719
+ '#73c03a',
720
+ '#cb513a'
721
+ ].reverse();
722
+
723
+ this.schemes.cool = [
724
+ '#5e9d2f',
725
+ '#73c03a',
726
+ '#4682b4',
727
+ '#7bc3b8',
728
+ '#a9884e',
729
+ '#c1b266',
730
+ '#a47493',
731
+ '#c09fb5'
732
+ ];
733
+
734
+ this.schemes.munin = [
735
+ '#00cc00',
736
+ '#0066b3',
737
+ '#ff8000',
738
+ '#ffcc00',
739
+ '#330099',
740
+ '#990099',
741
+ '#ccff00',
742
+ '#ff0000',
743
+ '#808080',
744
+ '#008f00',
745
+ '#00487d',
746
+ '#b35a00',
747
+ '#b38f00',
748
+ '#6b006b',
749
+ '#8fb300',
750
+ '#b30000',
751
+ '#bebebe',
752
+ '#80ff80',
753
+ '#80c9ff',
754
+ '#ffc080',
755
+ '#ffe680',
756
+ '#aa80ff',
757
+ '#ee00cc',
758
+ '#ff8080',
759
+ '#666600',
760
+ '#ffbfff',
761
+ '#00ffcc',
762
+ '#cc6699',
763
+ '#999900'
764
+ ];
765
+ };
766
+ Rickshaw.namespace('Rickshaw.Fixtures.RandomData');
767
+
768
+ Rickshaw.Fixtures.RandomData = function(timeInterval) {
769
+
770
+ var addData;
771
+ timeInterval = timeInterval || 1;
772
+
773
+ var lastRandomValue = 200;
774
+
775
+ var timeBase = Math.floor(new Date().getTime() / 1000);
776
+
777
+ this.addData = function(data) {
778
+
779
+ var randomValue = Math.random() * 100 + 15 + lastRandomValue;
780
+ var index = data[0].length;
781
+
782
+ var counter = 1;
783
+
784
+ data.forEach( function(series) {
785
+ var randomVariance = Math.random() * 20;
786
+ var v = randomValue / 25 + counter++
787
+ + (Math.cos((index * counter * 11) / 960) + 2) * 15
788
+ + (Math.cos(index / 7) + 2) * 7
789
+ + (Math.cos(index / 17) + 2) * 1;
790
+
791
+ series.push( { x: (index * timeInterval) + timeBase, y: v + randomVariance } );
792
+ } );
793
+
794
+ lastRandomValue = randomValue * .85;
795
+ }
796
+ };
797
+
798
+ Rickshaw.namespace('Rickshaw.Fixtures.Time');
799
+
800
+ Rickshaw.Fixtures.Time = function() {
801
+
802
+ var tzOffset = new Date().getTimezoneOffset() * 60;
803
+
804
+ var self = this;
805
+
806
+ this.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
807
+
808
+ this.units = [
809
+ {
810
+ name: 'decade',
811
+ seconds: 86400 * 365.25 * 10,
812
+ formatter: function(d) { return (parseInt(d.getUTCFullYear() / 10) * 10) }
813
+ }, {
814
+ name: 'year',
815
+ seconds: 86400 * 365.25,
816
+ formatter: function(d) { return d.getUTCFullYear() }
817
+ }, {
818
+ name: 'month',
819
+ seconds: 86400 * 30.5,
820
+ formatter: function(d) { return self.months[d.getUTCMonth()] }
821
+ }, {
822
+ name: 'week',
823
+ seconds: 86400 * 7,
824
+ formatter: function(d) { return self.formatDate(d) }
825
+ }, {
826
+ name: 'day',
827
+ seconds: 86400,
828
+ formatter: function(d) { return d.getUTCDate() }
829
+ }, {
830
+ name: '6 hour',
831
+ seconds: 3600 * 6,
832
+ formatter: function(d) { return self.formatTime(d) }
833
+ }, {
834
+ name: 'hour',
835
+ seconds: 3600,
836
+ formatter: function(d) { return self.formatTime(d) }
837
+ }, {
838
+ name: '15 minute',
839
+ seconds: 60 * 15,
840
+ formatter: function(d) { return self.formatTime(d) }
841
+ }, {
842
+ name: 'minute',
843
+ seconds: 60,
844
+ formatter: function(d) { return d.getUTCMinutes() }
845
+ }, {
846
+ name: '15 second',
847
+ seconds: 15,
848
+ formatter: function(d) { return d.getUTCSeconds() + 's' }
849
+ }, {
850
+ name: 'second',
851
+ seconds: 1,
852
+ formatter: function(d) { return d.getUTCSeconds() + 's' }
853
+ }
854
+ ];
855
+
856
+ this.unit = function(unitName) {
857
+ return this.units.filter( function(unit) { return unitName == unit.name } ).shift();
858
+ };
859
+
860
+ this.formatDate = function(d) {
861
+ return d.toUTCString().match(/, (\w+ \w+ \w+)/)[1];
862
+ };
863
+
864
+ this.formatTime = function(d) {
865
+ return d.toUTCString().match(/(\d+:\d+):/)[1];
866
+ };
867
+
868
+ this.ceil = function(time, unit) {
869
+
870
+ if (unit.name == 'month') {
871
+
872
+ var nearFuture = new Date((time + unit.seconds - 1) * 1000);
873
+
874
+ var rounded = new Date(0);
875
+ rounded.setUTCFullYear(nearFuture.getUTCFullYear());
876
+ rounded.setUTCMonth(nearFuture.getUTCMonth());
877
+ rounded.setUTCDate(1);
878
+ rounded.setUTCHours(0);
879
+ rounded.setUTCMinutes(0);
880
+ rounded.setUTCSeconds(0);
881
+ rounded.setUTCMilliseconds(0);
882
+
883
+ return rounded.getTime() / 1000;
884
+ }
885
+
886
+ if (unit.name == 'year') {
887
+
888
+ var nearFuture = new Date((time + unit.seconds - 1) * 1000);
889
+
890
+ var rounded = new Date(0);
891
+ rounded.setUTCFullYear(nearFuture.getUTCFullYear());
892
+ rounded.setUTCMonth(0);
893
+ rounded.setUTCDate(1);
894
+ rounded.setUTCHours(0);
895
+ rounded.setUTCMinutes(0);
896
+ rounded.setUTCSeconds(0);
897
+ rounded.setUTCMilliseconds(0);
898
+
899
+ return rounded.getTime() / 1000;
900
+ }
901
+
902
+ return Math.ceil(time / unit.seconds) * unit.seconds;
903
+ };
904
+ };
905
+ Rickshaw.namespace('Rickshaw.Fixtures.Number');
906
+
907
+ Rickshaw.Fixtures.Number.formatKMBT = function(y) {
908
+ if (y >= 1000000000000) { return y / 1000000000000 + "T" }
909
+ else if (y >= 1000000000) { return y / 1000000000 + "B" }
910
+ else if (y >= 1000000) { return y / 1000000 + "M" }
911
+ else if (y >= 1000) { return y / 1000 + "K" }
912
+ else if (y < 1 && y > 0) { return y.toFixed(2) }
913
+ else if (y == 0) { return '' }
914
+ else { return y }
915
+ };
916
+
917
+ Rickshaw.Fixtures.Number.formatBase1024KMGTP = function(y) {
918
+ if (y >= 1125899906842624) { return y / 1125899906842624 + "P" }
919
+ else if (y >= 1099511627776){ return y / 1099511627776 + "T" }
920
+ else if (y >= 1073741824) { return y / 1073741824 + "G" }
921
+ else if (y >= 1048576) { return y / 1048576 + "M" }
922
+ else if (y >= 1024) { return y / 1024 + "K" }
923
+ else if (y < 1 && y > 0) { return y.toFixed(2) }
924
+ else if (y == 0) { return '' }
925
+ else { return y }
926
+ };
927
+ Rickshaw.namespace("Rickshaw.Color.Palette");
928
+
929
+ Rickshaw.Color.Palette = function(args) {
930
+
931
+ var color = new Rickshaw.Fixtures.Color();
932
+
933
+ args = args || {};
934
+ this.schemes = {};
935
+
936
+ this.scheme = color.schemes[args.scheme] || args.scheme || color.schemes.colorwheel;
937
+ this.runningIndex = 0;
938
+ this.generatorIndex = 0;
939
+
940
+ if (args.interpolatedStopCount) {
941
+ var schemeCount = this.scheme.length - 1;
942
+ var i, j, scheme = [];
943
+ for (i = 0; i < schemeCount; i++) {
944
+ scheme.push(this.scheme[i]);
945
+ var generator = d3.interpolateHsl(this.scheme[i], this.scheme[i + 1]);
946
+ for (j = 1; j < args.interpolatedStopCount; j++) {
947
+ scheme.push(generator((1 / args.interpolatedStopCount) * j));
948
+ }
949
+ }
950
+ scheme.push(this.scheme[this.scheme.length - 1]);
951
+ this.scheme = scheme;
952
+ }
953
+ this.rotateCount = this.scheme.length;
954
+
955
+ this.color = function(key) {
956
+ return this.scheme[key] || this.scheme[this.runningIndex++] || this.interpolateColor() || '#808080';
957
+ };
958
+
959
+ this.interpolateColor = function() {
960
+ if (!Array.isArray(this.scheme)) return;
961
+ var color;
962
+ if (this.generatorIndex == this.rotateCount * 2 - 1) {
963
+ color = d3.interpolateHsl(this.scheme[this.generatorIndex], this.scheme[0])(0.5);
964
+ this.generatorIndex = 0;
965
+ this.rotateCount *= 2;
966
+ } else {
967
+ color = d3.interpolateHsl(this.scheme[this.generatorIndex], this.scheme[this.generatorIndex + 1])(0.5);
968
+ this.generatorIndex++;
969
+ }
970
+ this.scheme.push(color);
971
+ return color;
972
+ };
973
+
974
+ };
975
+ Rickshaw.namespace('Rickshaw.Graph.Ajax');
976
+
977
+ Rickshaw.Graph.Ajax = Rickshaw.Class.create( {
978
+
979
+ initialize: function(args) {
980
+
981
+ this.dataURL = args.dataURL;
982
+
983
+ this.onData = args.onData || function(d) { return d };
984
+ this.onComplete = args.onComplete || function() {};
985
+ this.onError = args.onError || function() {};
986
+
987
+ this.args = args; // pass through to Rickshaw.Graph
988
+
989
+ this.request();
990
+ },
991
+
992
+ request: function() {
993
+
994
+ $.ajax( {
995
+ url: this.dataURL,
996
+ dataType: 'json',
997
+ success: this.success.bind(this),
998
+ error: this.error.bind(this)
999
+ } );
1000
+ },
1001
+
1002
+ error: function() {
1003
+
1004
+ console.log("error loading dataURL: " + this.dataURL);
1005
+ this.onError(this);
1006
+ },
1007
+
1008
+ success: function(data, status) {
1009
+
1010
+ data = this.onData(data);
1011
+ this.args.series = this._splice({ data: data, series: this.args.series });
1012
+
1013
+ this.graph = new Rickshaw.Graph(this.args);
1014
+ this.graph.render();
1015
+
1016
+ this.onComplete(this);
1017
+ },
1018
+
1019
+ _splice: function(args) {
1020
+
1021
+ var data = args.data;
1022
+ var series = args.series;
1023
+
1024
+ if (!args.series) return data;
1025
+
1026
+ series.forEach( function(s) {
1027
+
1028
+ var seriesKey = s.key || s.name;
1029
+ if (!seriesKey) throw "series needs a key or a name";
1030
+
1031
+ data.forEach( function(d) {
1032
+
1033
+ var dataKey = d.key || d.name;
1034
+ if (!dataKey) throw "data needs a key or a name";
1035
+
1036
+ if (seriesKey == dataKey) {
1037
+ var properties = ['color', 'name', 'data'];
1038
+ properties.forEach( function(p) {
1039
+ s[p] = s[p] || d[p];
1040
+ } );
1041
+ }
1042
+ } );
1043
+ } );
1044
+
1045
+ return series;
1046
+ }
1047
+ } );
1048
+
1049
+ Rickshaw.namespace('Rickshaw.Graph.Annotate');
1050
+
1051
+ Rickshaw.Graph.Annotate = function(args) {
1052
+
1053
+ var graph = this.graph = args.graph;
1054
+ this.elements = { timeline: args.element };
1055
+
1056
+ var self = this;
1057
+
1058
+ this.data = {};
1059
+
1060
+ this.elements.timeline.classList.add('rickshaw_annotation_timeline');
1061
+
1062
+ this.add = function(time, content, end_time) {
1063
+ self.data[time] = self.data[time] || {'boxes': []};
1064
+ self.data[time].boxes.push({content: content, end: end_time});
1065
+ };
1066
+
1067
+ this.update = function() {
1068
+
1069
+ Rickshaw.keys(self.data).forEach( function(time) {
1070
+
1071
+ var annotation = self.data[time];
1072
+ var left = self.graph.x(time);
1073
+
1074
+ if (left < 0 || left > self.graph.x.range()[1]) {
1075
+ if (annotation.element) {
1076
+ annotation.line.classList.add('offscreen');
1077
+ annotation.element.style.display = 'none';
1078
+ }
1079
+
1080
+ annotation.boxes.forEach( function(box) {
1081
+ if ( box.rangeElement ) box.rangeElement.classList.add('offscreen');
1082
+ });
1083
+
1084
+ return;
1085
+ }
1086
+
1087
+ if (!annotation.element) {
1088
+ var element = annotation.element = document.createElement('div');
1089
+ element.classList.add('annotation');
1090
+ this.elements.timeline.appendChild(element);
1091
+ element.addEventListener('click', function(e) {
1092
+ element.classList.toggle('active');
1093
+ annotation.line.classList.toggle('active');
1094
+ annotation.boxes.forEach( function(box) {
1095
+ if ( box.rangeElement ) box.rangeElement.classList.toggle('active');
1096
+ });
1097
+ }, false);
1098
+
1099
+ }
1100
+
1101
+ annotation.element.style.left = left + 'px';
1102
+ annotation.element.style.display = 'block';
1103
+
1104
+ annotation.boxes.forEach( function(box) {
1105
+
1106
+
1107
+ var element = box.element;
1108
+
1109
+ if (!element) {
1110
+ element = box.element = document.createElement('div');
1111
+ element.classList.add('content');
1112
+ element.innerHTML = box.content;
1113
+ annotation.element.appendChild(element);
1114
+
1115
+ annotation.line = document.createElement('div');
1116
+ annotation.line.classList.add('annotation_line');
1117
+ self.graph.element.appendChild(annotation.line);
1118
+
1119
+ if ( box.end ) {
1120
+ box.rangeElement = document.createElement('div');
1121
+ box.rangeElement.classList.add('annotation_range');
1122
+ self.graph.element.appendChild(box.rangeElement);
1123
+ }
1124
+
1125
+ }
1126
+
1127
+ if ( box.end ) {
1128
+
1129
+ var annotationRangeStart = left;
1130
+ var annotationRangeEnd = Math.min( self.graph.x(box.end), self.graph.x.range()[1] );
1131
+
1132
+ // annotation makes more sense at end
1133
+ if ( annotationRangeStart > annotationRangeEnd ) {
1134
+ annotationRangeEnd = left;
1135
+ annotationRangeStart = Math.max( self.graph.x(box.end), self.graph.x.range()[0] );
1136
+ }
1137
+
1138
+ var annotationRangeWidth = annotationRangeEnd - annotationRangeStart;
1139
+
1140
+ box.rangeElement.style.left = annotationRangeStart + 'px';
1141
+ box.rangeElement.style.width = annotationRangeWidth + 'px'
1142
+
1143
+ box.rangeElement.classList.remove('offscreen');
1144
+ }
1145
+
1146
+ annotation.line.classList.remove('offscreen');
1147
+ annotation.line.style.left = left + 'px';
1148
+ } );
1149
+ }, this );
1150
+ };
1151
+
1152
+ this.graph.onUpdate( function() { self.update() } );
1153
+ };
1154
+ Rickshaw.namespace('Rickshaw.Graph.Axis.Time');
1155
+
1156
+ Rickshaw.Graph.Axis.Time = function(args) {
1157
+
1158
+ var self = this;
1159
+
1160
+ this.graph = args.graph;
1161
+ this.elements = [];
1162
+ this.ticksTreatment = args.ticksTreatment || 'plain';
1163
+ this.fixedTimeUnit = args.timeUnit;
1164
+
1165
+ var time = new Rickshaw.Fixtures.Time();
1166
+
1167
+ this.appropriateTimeUnit = function() {
1168
+
1169
+ var unit;
1170
+ var units = time.units;
1171
+
1172
+ var domain = this.graph.x.domain();
1173
+ var rangeSeconds = domain[1] - domain[0];
1174
+
1175
+ units.forEach( function(u) {
1176
+ if (Math.floor(rangeSeconds / u.seconds) >= 2) {
1177
+ unit = unit || u;
1178
+ }
1179
+ } );
1180
+
1181
+ return (unit || time.units[time.units.length - 1]);
1182
+ };
1183
+
1184
+ this.tickOffsets = function() {
1185
+
1186
+ var domain = this.graph.x.domain();
1187
+
1188
+ var unit = this.fixedTimeUnit || this.appropriateTimeUnit();
1189
+ var count = Math.ceil((domain[1] - domain[0]) / unit.seconds);
1190
+
1191
+ var runningTick = domain[0];
1192
+
1193
+ var offsets = [];
1194
+
1195
+ for (var i = 0; i < count; i++) {
1196
+
1197
+ tickValue = time.ceil(runningTick, unit);
1198
+ runningTick = tickValue + unit.seconds / 2;
1199
+
1200
+ offsets.push( { value: tickValue, unit: unit } );
1201
+ }
1202
+
1203
+ return offsets;
1204
+ };
1205
+
1206
+ this.render = function() {
1207
+
1208
+ this.elements.forEach( function(e) {
1209
+ e.parentNode.removeChild(e);
1210
+ } );
1211
+
1212
+ this.elements = [];
1213
+
1214
+ var offsets = this.tickOffsets();
1215
+
1216
+ offsets.forEach( function(o) {
1217
+
1218
+ if (self.graph.x(o.value) > self.graph.x.range()[1]) return;
1219
+
1220
+ var element = document.createElement('div');
1221
+ element.style.left = self.graph.x(o.value) + 'px';
1222
+ element.classList.add('x_tick');
1223
+ element.classList.add(self.ticksTreatment);
1224
+
1225
+ var title = document.createElement('div');
1226
+ title.classList.add('title');
1227
+ title.innerHTML = o.unit.formatter(new Date(o.value * 1000));
1228
+ element.appendChild(title);
1229
+
1230
+ self.graph.element.appendChild(element);
1231
+ self.elements.push(element);
1232
+
1233
+ } );
1234
+ };
1235
+
1236
+ this.graph.onUpdate( function() { self.render() } );
1237
+ };
1238
+
1239
+ Rickshaw.namespace('Rickshaw.Graph.Axis.Y');
1240
+
1241
+ Rickshaw.Graph.Axis.Y = function(args) {
1242
+
1243
+ var self = this;
1244
+ var berthRate = 0.10;
1245
+
1246
+ this.initialize = function(args) {
1247
+
1248
+ this.graph = args.graph;
1249
+ this.orientation = args.orientation || 'right';
1250
+
1251
+ var pixelsPerTick = args.pixelsPerTick || 75;
1252
+ this.ticks = args.ticks || Math.floor(this.graph.height / pixelsPerTick);
1253
+ this.tickSize = args.tickSize || 4;
1254
+ this.ticksTreatment = args.ticksTreatment || 'plain';
1255
+
1256
+ if (args.element) {
1257
+
1258
+ this.element = args.element;
1259
+ this.vis = d3.select(args.element)
1260
+ .append("svg:svg")
1261
+ .attr('class', 'rickshaw_graph y_axis');
1262
+
1263
+ this.element = this.vis[0][0];
1264
+ this.element.style.position = 'relative';
1265
+
1266
+ this.setSize({ width: args.width, height: args.height });
1267
+
1268
+ } else {
1269
+ this.vis = this.graph.vis;
1270
+ }
1271
+
1272
+ this.graph.onUpdate( function() { self.render() } );
1273
+ };
1274
+
1275
+ this.setSize = function(args) {
1276
+
1277
+ args = args || {};
1278
+
1279
+ if (!this.element) return;
1280
+
1281
+ if (typeof window !== 'undefined') {
1282
+
1283
+ var style = window.getComputedStyle(this.element.parentNode, null);
1284
+ var elementWidth = parseInt(style.getPropertyValue('width'));
1285
+
1286
+ if (!args.auto) {
1287
+ var elementHeight = parseInt(style.getPropertyValue('height'));
1288
+ }
1289
+ }
1290
+
1291
+ this.width = args.width || elementWidth || this.graph.width * berthRate;
1292
+ this.height = args.height || elementHeight || this.graph.height;
1293
+
1294
+ this.vis
1295
+ .attr('width', this.width)
1296
+ .attr('height', this.height * (1 + berthRate));
1297
+
1298
+ var berth = this.height * berthRate;
1299
+ this.element.style.top = -1 * berth + 'px';
1300
+ };
1301
+
1302
+ this.render = function() {
1303
+
1304
+ if (this.graph.height !== this._renderHeight) this.setSize({ auto: true });
1305
+
1306
+ var axis = d3.svg.axis().scale(this.graph.y).orient(this.orientation);
1307
+ axis.tickFormat( args.tickFormat || function(y) { return y } );
1308
+
1309
+ if (this.orientation == 'left') {
1310
+ var berth = this.height * berthRate;
1311
+ var transform = 'translate(' + this.width + ', ' + berth + ')';
1312
+ }
1313
+
1314
+ if (this.element) {
1315
+ this.vis.selectAll('*').remove();
1316
+ }
1317
+
1318
+ this.vis
1319
+ .append("svg:g")
1320
+ .attr("class", ["y_ticks", this.ticksTreatment].join(" "))
1321
+ .attr("transform", transform)
1322
+ .call(axis.ticks(this.ticks).tickSubdivide(0).tickSize(this.tickSize))
1323
+
1324
+ var gridSize = (this.orientation == 'right' ? 1 : -1) * this.graph.width;
1325
+
1326
+ this.graph.vis
1327
+ .append("svg:g")
1328
+ .attr("class", "y_grid")
1329
+ .call(axis.ticks(this.ticks).tickSubdivide(0).tickSize(gridSize));
1330
+
1331
+ this._renderHeight = this.graph.height;
1332
+ };
1333
+
1334
+ this.initialize(args);
1335
+ };
1336
+
1337
+ Rickshaw.namespace('Rickshaw.Graph.Behavior.Series.Highlight');
1338
+
1339
+ Rickshaw.Graph.Behavior.Series.Highlight = function(args) {
1340
+
1341
+ this.graph = args.graph;
1342
+ this.legend = args.legend;
1343
+
1344
+ var self = this;
1345
+
1346
+ var colorSafe = {};
1347
+
1348
+ this.addHighlightEvents = function (l) {
1349
+ l.element.addEventListener( 'mouseover', function(e) {
1350
+
1351
+ self.legend.lines.forEach( function(line) {
1352
+ if (l === line) return;
1353
+ colorSafe[line.series.name] = colorSafe[line.series.name] || line.series.color;
1354
+ line.series.color = d3.interpolateRgb(line.series.color, d3.rgb('#d8d8d8'))(0.8).toString();
1355
+ } );
1356
+
1357
+ self.graph.update();
1358
+
1359
+ }, false );
1360
+
1361
+ l.element.addEventListener( 'mouseout', function(e) {
1362
+
1363
+ self.legend.lines.forEach( function(line) {
1364
+ if (colorSafe[line.series.name]) {
1365
+ line.series.color = colorSafe[line.series.name];
1366
+ }
1367
+ } );
1368
+
1369
+ self.graph.update();
1370
+
1371
+ }, false );
1372
+ };
1373
+
1374
+ if (this.legend) {
1375
+ this.legend.lines.forEach( function(l) {
1376
+ self.addHighlightEvents(l);
1377
+ } );
1378
+ }
1379
+
1380
+ };
1381
+ Rickshaw.namespace('Rickshaw.Graph.Behavior.Series.Order');
1382
+
1383
+ Rickshaw.Graph.Behavior.Series.Order = function(args) {
1384
+
1385
+ this.graph = args.graph;
1386
+ this.legend = args.legend;
1387
+
1388
+ var self = this;
1389
+
1390
+ $(function() {
1391
+ $(self.legend.list).sortable( {
1392
+ containment: 'parent',
1393
+ tolerance: 'pointer',
1394
+ update: function( event, ui ) {
1395
+ var series = [];
1396
+ $(self.legend.list).find('li').each( function(index, item) {
1397
+ if (!item.series) return;
1398
+ series.push(item.series);
1399
+ } );
1400
+
1401
+ for (var i = self.graph.series.length - 1; i >= 0; i--) {
1402
+ self.graph.series[i] = series.shift();
1403
+ }
1404
+
1405
+ self.graph.update();
1406
+ }
1407
+ } );
1408
+ $(self.legend.list).disableSelection();
1409
+ });
1410
+
1411
+ //hack to make jquery-ui sortable behave
1412
+ this.graph.onUpdate( function() {
1413
+ var h = window.getComputedStyle(self.legend.element).height;
1414
+ self.legend.element.style.height = h;
1415
+ } );
1416
+ };
1417
+ Rickshaw.namespace('Rickshaw.Graph.Behavior.Series.Toggle');
1418
+
1419
+ Rickshaw.Graph.Behavior.Series.Toggle = function(args) {
1420
+
1421
+ this.graph = args.graph;
1422
+ this.legend = args.legend;
1423
+
1424
+ var self = this;
1425
+
1426
+ this.addAnchor = function(line) {
1427
+ var anchor = document.createElement('a');
1428
+ anchor.innerHTML = '&#10004;';
1429
+ anchor.classList.add('action');
1430
+ line.element.insertBefore(anchor, line.element.firstChild);
1431
+
1432
+ anchor.onclick = function(e) {
1433
+ if (line.series.disabled) {
1434
+ line.series.enable();
1435
+ line.element.classList.remove('disabled');
1436
+ } else {
1437
+ line.series.disable();
1438
+ line.element.classList.add('disabled');
1439
+ }
1440
+ }
1441
+
1442
+ var label = line.element.getElementsByTagName('span')[0];
1443
+ label.onclick = function(e){
1444
+
1445
+ var disableAllOtherLines = line.series.disabled;
1446
+ if ( ! disableAllOtherLines ) {
1447
+ for ( var i = 0; i < self.legend.lines.length; i++ ) {
1448
+ var l = self.legend.lines[i];
1449
+ if ( line.series === l.series ) {
1450
+ // noop
1451
+ } else if ( l.series.disabled ) {
1452
+ // noop
1453
+ } else {
1454
+ disableAllOtherLines = true;
1455
+ break;
1456
+ }
1457
+ }
1458
+ }
1459
+
1460
+ // show all or none
1461
+ if ( disableAllOtherLines ) {
1462
+
1463
+ // these must happen first or else we try ( and probably fail ) to make a no line graph
1464
+ line.series.enable();
1465
+ line.element.classList.remove('disabled');
1466
+
1467
+ self.legend.lines.forEach(function(l){
1468
+ if ( line.series === l.series ) {
1469
+ // noop
1470
+ } else {
1471
+ l.series.disable();
1472
+ l.element.classList.add('disabled');
1473
+ }
1474
+ });
1475
+
1476
+ } else {
1477
+
1478
+ self.legend.lines.forEach(function(l){
1479
+ l.series.enable();
1480
+ l.element.classList.remove('disabled');
1481
+ });
1482
+
1483
+ }
1484
+
1485
+ };
1486
+
1487
+ };
1488
+
1489
+ if (this.legend) {
1490
+
1491
+ $(this.legend.list).sortable( {
1492
+ start: function(event, ui) {
1493
+ ui.item.bind('no.onclick',
1494
+ function(event) {
1495
+ event.preventDefault();
1496
+ }
1497
+ );
1498
+ },
1499
+ stop: function(event, ui) {
1500
+ setTimeout(function(){
1501
+ ui.item.unbind('no.onclick');
1502
+ }, 250);
1503
+ }
1504
+ })
1505
+
1506
+ this.legend.lines.forEach( function(l) {
1507
+ self.addAnchor(l);
1508
+ } );
1509
+ }
1510
+
1511
+ this._addBehavior = function() {
1512
+
1513
+ this.graph.series.forEach( function(s) {
1514
+
1515
+ s.disable = function() {
1516
+
1517
+ if (self.graph.series.length <= 1) {
1518
+ throw('only one series left');
1519
+ }
1520
+
1521
+ s.disabled = true;
1522
+ self.graph.update();
1523
+ };
1524
+
1525
+ s.enable = function() {
1526
+ s.disabled = false;
1527
+ self.graph.update();
1528
+ };
1529
+ } );
1530
+ };
1531
+ this._addBehavior();
1532
+
1533
+ this.updateBehaviour = function () { this._addBehavior() };
1534
+
1535
+ };
1536
+ Rickshaw.namespace('Rickshaw.Graph.HoverDetail');
1537
+
1538
+ Rickshaw.Graph.HoverDetail = Rickshaw.Class.create({
1539
+
1540
+ initialize: function(args) {
1541
+
1542
+ var graph = this.graph = args.graph;
1543
+
1544
+ this.xFormatter = args.xFormatter || function(x) {
1545
+ return new Date( x * 1000 ).toUTCString();
1546
+ };
1547
+
1548
+ this.yFormatter = args.yFormatter || function(y) {
1549
+ return y.toFixed(2);
1550
+ };
1551
+
1552
+ var element = this.element = document.createElement('div');
1553
+ element.className = 'detail';
1554
+
1555
+ this.visible = true;
1556
+ graph.element.appendChild(element);
1557
+
1558
+ this.lastEvent = null;
1559
+ this._addListeners();
1560
+
1561
+ this.onShow = args.onShow;
1562
+ this.onHide = args.onHide;
1563
+ this.onRender = args.onRender;
1564
+
1565
+ this.formatter = args.formatter || this.formatter;
1566
+ },
1567
+
1568
+ formatter: function(series, x, y, formattedX, formattedY, d) {
1569
+ return series.name + ':&nbsp;' + formattedY;
1570
+ },
1571
+
1572
+ update: function(e) {
1573
+
1574
+ e = e || this.lastEvent;
1575
+ if (!e) return;
1576
+ this.lastEvent = e;
1577
+
1578
+ if (!e.target.nodeName.match(/^(path|svg|rect)$/)) return;
1579
+
1580
+ var graph = this.graph;
1581
+
1582
+ var eventX = e.offsetX || e.layerX;
1583
+ var eventY = e.offsetY || e.layerY;
1584
+
1585
+ var domainX = graph.x.invert(eventX);
1586
+ var stackedData = graph.stackedData;
1587
+
1588
+ var topSeriesData = stackedData.slice(-1).shift();
1589
+
1590
+ var domainIndexScale = d3.scale.linear()
1591
+ .domain([topSeriesData[0].x, topSeriesData.slice(-1).shift().x])
1592
+ .range([0, topSeriesData.length]);
1593
+
1594
+ var approximateIndex = Math.floor(domainIndexScale(domainX));
1595
+ var dataIndex = Math.min(approximateIndex || 0, stackedData[0].length - 1);
1596
+
1597
+ for (var i = approximateIndex; i < stackedData[0].length - 1;) {
1598
+
1599
+ if (!stackedData[0][i] || !stackedData[0][i + 1]) {
1600
+ break;
1601
+ }
1602
+
1603
+ if (stackedData[0][i].x <= domainX && stackedData[0][i + 1].x > domainX) {
1604
+ dataIndex = i;
1605
+ break;
1606
+ }
1607
+ if (stackedData[0][i + 1] <= domainX) { i++ } else { i-- }
1608
+ }
1609
+
1610
+ var domainX = stackedData[0][dataIndex].x;
1611
+ var formattedXValue = this.xFormatter(domainX);
1612
+ var graphX = graph.x(domainX);
1613
+ var order = 0;
1614
+
1615
+ var detail = graph.series.active()
1616
+ .map( function(s) { return { order: order++, series: s, name: s.name, value: s.stack[dataIndex] } } );
1617
+
1618
+ var activeItem;
1619
+
1620
+ var sortFn = function(a, b) {
1621
+ return (a.value.y0 + a.value.y) - (b.value.y0 + b.value.y);
1622
+ };
1623
+
1624
+ var domainMouseY = graph.y.magnitude.invert(graph.element.offsetHeight - eventY);
1625
+
1626
+ detail.sort(sortFn).forEach( function(d) {
1627
+
1628
+ d.formattedYValue = (this.yFormatter.constructor == Array) ?
1629
+ this.yFormatter[detail.indexOf(d)](d.value.y) :
1630
+ this.yFormatter(d.value.y);
1631
+
1632
+ d.graphX = graphX;
1633
+ d.graphY = graph.y(d.value.y0 + d.value.y);
1634
+
1635
+ if (domainMouseY > d.value.y0 && domainMouseY < d.value.y0 + d.value.y && !activeItem) {
1636
+ activeItem = d;
1637
+ d.active = true;
1638
+ }
1639
+
1640
+ }, this );
1641
+
1642
+ this.element.innerHTML = '';
1643
+ this.element.style.left = graph.x(domainX) + 'px';
1644
+
1645
+ if (this.visible) {
1646
+ this.render( {
1647
+ detail: detail,
1648
+ domainX: domainX,
1649
+ formattedXValue: formattedXValue,
1650
+ mouseX: eventX,
1651
+ mouseY: eventY
1652
+ } );
1653
+ }
1654
+ },
1655
+
1656
+ hide: function() {
1657
+ this.visible = false;
1658
+ this.element.classList.add('inactive');
1659
+
1660
+ if (typeof this.onHide == 'function') {
1661
+ this.onHide();
1662
+ }
1663
+ },
1664
+
1665
+ show: function() {
1666
+ this.visible = true;
1667
+ this.element.classList.remove('inactive');
1668
+
1669
+ if (typeof this.onShow == 'function') {
1670
+ this.onShow();
1671
+ }
1672
+ },
1673
+
1674
+ render: function(args) {
1675
+
1676
+ var detail = args.detail;
1677
+ var domainX = args.domainX;
1678
+
1679
+ var mouseX = args.mouseX;
1680
+ var mouseY = args.mouseY;
1681
+
1682
+ var formattedXValue = args.formattedXValue;
1683
+
1684
+ var xLabel = document.createElement('div');
1685
+ xLabel.className = 'x_label';
1686
+ xLabel.innerHTML = formattedXValue;
1687
+ this.element.appendChild(xLabel);
1688
+
1689
+ detail.forEach( function(d) {
1690
+
1691
+ var item = document.createElement('div');
1692
+ item.className = 'item';
1693
+ item.innerHTML = this.formatter(d.series, domainX, d.value.y, formattedXValue, d.formattedYValue, d);
1694
+ item.style.top = this.graph.y(d.value.y0 + d.value.y) + 'px';
1695
+
1696
+ this.element.appendChild(item);
1697
+
1698
+ var dot = document.createElement('div');
1699
+ dot.className = 'dot';
1700
+ dot.style.top = item.style.top;
1701
+ dot.style.borderColor = d.series.color;
1702
+
1703
+ this.element.appendChild(dot);
1704
+
1705
+ if (d.active) {
1706
+ item.className = 'item active';
1707
+ dot.className = 'dot active';
1708
+ }
1709
+
1710
+ }, this );
1711
+
1712
+ this.show();
1713
+
1714
+ if (typeof this.onRender == 'function') {
1715
+ this.onRender(args);
1716
+ }
1717
+ },
1718
+
1719
+ _addListeners: function() {
1720
+
1721
+ this.graph.element.addEventListener(
1722
+ 'mousemove',
1723
+ function(e) {
1724
+ this.visible = true;
1725
+ this.update(e)
1726
+ }.bind(this),
1727
+ false
1728
+ );
1729
+
1730
+ this.graph.onUpdate( function() { this.update() }.bind(this) );
1731
+
1732
+ this.graph.element.addEventListener(
1733
+ 'mouseout',
1734
+ function(e) {
1735
+ if (e.relatedTarget && !(e.relatedTarget.compareDocumentPosition(this.graph.element) & Node.DOCUMENT_POSITION_CONTAINS)) {
1736
+ this.hide();
1737
+ }
1738
+ }.bind(this),
1739
+ false
1740
+ );
1741
+ }
1742
+ });
1743
+
1744
+ Rickshaw.namespace('Rickshaw.Graph.JSONP');
1745
+
1746
+ Rickshaw.Graph.JSONP = Rickshaw.Class.create( Rickshaw.Graph.Ajax, {
1747
+
1748
+ request: function() {
1749
+
1750
+ $.ajax( {
1751
+ url: this.dataURL,
1752
+ dataType: 'jsonp',
1753
+ success: this.success.bind(this),
1754
+ error: this.error.bind(this)
1755
+ } );
1756
+ }
1757
+ } );
1758
+ Rickshaw.namespace('Rickshaw.Graph.Legend');
1759
+
1760
+ Rickshaw.Graph.Legend = function(args) {
1761
+
1762
+ var element = this.element = args.element;
1763
+ var graph = this.graph = args.graph;
1764
+
1765
+ var self = this;
1766
+
1767
+ element.classList.add('rickshaw_legend');
1768
+
1769
+ var list = this.list = document.createElement('ul');
1770
+ element.appendChild(list);
1771
+
1772
+ var series = graph.series
1773
+ .map( function(s) { return s } )
1774
+ .reverse();
1775
+
1776
+ this.lines = [];
1777
+
1778
+ this.addLine = function (series) {
1779
+ var line = document.createElement('li');
1780
+ line.className = 'line';
1781
+
1782
+ var swatch = document.createElement('div');
1783
+ swatch.className = 'swatch';
1784
+ swatch.style.backgroundColor = series.color;
1785
+
1786
+ line.appendChild(swatch);
1787
+
1788
+ var label = document.createElement('span');
1789
+ label.className = 'label';
1790
+ label.innerHTML = series.name;
1791
+
1792
+ line.appendChild(label);
1793
+ list.appendChild(line);
1794
+
1795
+ line.series = series;
1796
+
1797
+ if (series.noLegend) {
1798
+ line.style.display = 'none';
1799
+ }
1800
+
1801
+ var _line = { element: line, series: series };
1802
+ if (self.shelving) {
1803
+ self.shelving.addAnchor(_line);
1804
+ self.shelving.updateBehaviour();
1805
+ }
1806
+ if (self.highlighter) {
1807
+ self.highlighter.addHighlightEvents(_line);
1808
+ }
1809
+ self.lines.push(_line);
1810
+ };
1811
+
1812
+ series.forEach( function(s) {
1813
+ self.addLine(s);
1814
+ } );
1815
+
1816
+ graph.onUpdate( function() {} );
1817
+ };
1818
+ Rickshaw.namespace('Rickshaw.Graph.RangeSlider');
1819
+
1820
+ Rickshaw.Graph.RangeSlider = function(args) {
1821
+
1822
+ var element = this.element = args.element;
1823
+ var graph = this.graph = args.graph;
1824
+
1825
+ $( function() {
1826
+ $(element).slider( {
1827
+
1828
+ range: true,
1829
+ min: graph.dataDomain()[0],
1830
+ max: graph.dataDomain()[1],
1831
+ values: [
1832
+ graph.dataDomain()[0],
1833
+ graph.dataDomain()[1]
1834
+ ],
1835
+ slide: function( event, ui ) {
1836
+
1837
+ graph.window.xMin = ui.values[0];
1838
+ graph.window.xMax = ui.values[1];
1839
+ graph.update();
1840
+
1841
+ // if we're at an extreme, stick there
1842
+ if (graph.dataDomain()[0] == ui.values[0]) {
1843
+ graph.window.xMin = undefined;
1844
+ }
1845
+ if (graph.dataDomain()[1] == ui.values[1]) {
1846
+ graph.window.xMax = undefined;
1847
+ }
1848
+ }
1849
+ } );
1850
+ } );
1851
+
1852
+ element[0].style.width = graph.width + 'px';
1853
+
1854
+ graph.onUpdate( function() {
1855
+
1856
+ var values = $(element).slider('option', 'values');
1857
+
1858
+ $(element).slider('option', 'min', graph.dataDomain()[0]);
1859
+ $(element).slider('option', 'max', graph.dataDomain()[1]);
1860
+
1861
+ if (graph.window.xMin == undefined) {
1862
+ values[0] = graph.dataDomain()[0];
1863
+ }
1864
+ if (graph.window.xMax == undefined) {
1865
+ values[1] = graph.dataDomain()[1];
1866
+ }
1867
+
1868
+ $(element).slider('option', 'values', values);
1869
+
1870
+ } );
1871
+ };
1872
+
1873
+ Rickshaw.namespace("Rickshaw.Graph.Renderer");
1874
+
1875
+ Rickshaw.Graph.Renderer = Rickshaw.Class.create( {
1876
+
1877
+ initialize: function(args) {
1878
+ this.graph = args.graph;
1879
+ this.tension = args.tension || this.tension;
1880
+ this.graph.unstacker = this.graph.unstacker || new Rickshaw.Graph.Unstacker( { graph: this.graph } );
1881
+ this.configure(args);
1882
+ },
1883
+
1884
+ seriesPathFactory: function() {
1885
+ //implement in subclass
1886
+ },
1887
+
1888
+ seriesStrokeFactory: function() {
1889
+ // implement in subclass
1890
+ },
1891
+
1892
+ defaults: function() {
1893
+ return {
1894
+ tension: 0.8,
1895
+ strokeWidth: 2,
1896
+ unstack: true,
1897
+ padding: { top: 0.01, right: 0, bottom: 0.01, left: 0 },
1898
+ stroke: false,
1899
+ fill: false
1900
+ };
1901
+ },
1902
+
1903
+ domain: function() {
1904
+
1905
+ var values = [];
1906
+ var stackedData = this.graph.stackedData || this.graph.stackData();
1907
+
1908
+ var topSeriesData = this.unstack ? stackedData : [ stackedData.slice(-1).shift() ];
1909
+
1910
+ topSeriesData.forEach( function(series) {
1911
+ series.forEach( function(d) {
1912
+ values.push( d.y + d.y0 );
1913
+ } );
1914
+ } );
1915
+
1916
+ var xMin = stackedData[0][0].x;
1917
+ var xMax = stackedData[0][ stackedData[0].length - 1 ].x;
1918
+
1919
+ xMin -= (xMax - xMin) * this.padding.left;
1920
+ xMax += (xMax - xMin) * this.padding.right;
1921
+
1922
+ var yMin = this.graph.min === 'auto' ? d3.min( values ) : this.graph.min || 0;
1923
+ var yMax = this.graph.max || d3.max( values );
1924
+
1925
+ if (this.graph.min === 'auto' || yMin < 0) {
1926
+ yMin -= (yMax - yMin) * this.padding.bottom;
1927
+ }
1928
+
1929
+ if (this.graph.max === undefined) {
1930
+ yMax += (yMax - yMin) * this.padding.top;
1931
+ }
1932
+
1933
+ return { x: [xMin, xMax], y: [yMin, yMax] };
1934
+ },
1935
+
1936
+ render: function() {
1937
+
1938
+ var graph = this.graph;
1939
+
1940
+ graph.vis.selectAll('*').remove();
1941
+
1942
+ var nodes = graph.vis.selectAll("path")
1943
+ .data(this.graph.stackedData)
1944
+ .enter().append("svg:path")
1945
+ .attr("d", this.seriesPathFactory());
1946
+
1947
+ var i = 0;
1948
+ graph.series.forEach( function(series) {
1949
+ if (series.disabled) return;
1950
+ series.path = nodes[0][i++];
1951
+ this._styleSeries(series);
1952
+ }, this );
1953
+ },
1954
+
1955
+ _styleSeries: function(series) {
1956
+
1957
+ var fill = this.fill ? series.color : 'none';
1958
+ var stroke = this.stroke ? series.color : 'none';
1959
+
1960
+ series.path.setAttribute('fill', fill);
1961
+ series.path.setAttribute('stroke', stroke);
1962
+ series.path.setAttribute('stroke-width', this.strokeWidth);
1963
+ series.path.setAttribute('class', series.className);
1964
+ },
1965
+
1966
+ configure: function(args) {
1967
+
1968
+ args = args || {};
1969
+
1970
+ Rickshaw.keys(this.defaults()).forEach( function(key) {
1971
+
1972
+ if (!args.hasOwnProperty(key)) {
1973
+ this[key] = this[key] || this.graph[key] || this.defaults()[key];
1974
+ return;
1975
+ }
1976
+
1977
+ if (typeof this.defaults()[key] == 'object') {
1978
+
1979
+ Rickshaw.keys(this.defaults()[key]).forEach( function(k) {
1980
+
1981
+ this[key][k] =
1982
+ args[key][k] !== undefined ? args[key][k] :
1983
+ this[key][k] !== undefined ? this[key][k] :
1984
+ this.defaults()[key][k];
1985
+ }, this );
1986
+
1987
+ } else {
1988
+ this[key] =
1989
+ args[key] !== undefined ? args[key] :
1990
+ this[key] !== undefined ? this[key] :
1991
+ this.graph[key] !== undefined ? this.graph[key] :
1992
+ this.defaults()[key];
1993
+ }
1994
+
1995
+ }, this );
1996
+ },
1997
+
1998
+ setStrokeWidth: function(strokeWidth) {
1999
+ if (strokeWidth !== undefined) {
2000
+ this.strokeWidth = strokeWidth;
2001
+ }
2002
+ },
2003
+
2004
+ setTension: function(tension) {
2005
+ if (tension !== undefined) {
2006
+ this.tension = tension;
2007
+ }
2008
+ }
2009
+ } );
2010
+
2011
+ Rickshaw.namespace('Rickshaw.Graph.Renderer.Line');
2012
+
2013
+ Rickshaw.Graph.Renderer.Line = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
2014
+
2015
+ name: 'line',
2016
+
2017
+ defaults: function($super) {
2018
+
2019
+ return Rickshaw.extend( $super(), {
2020
+ unstack: true,
2021
+ fill: false,
2022
+ stroke: true
2023
+ } );
2024
+ },
2025
+
2026
+ seriesPathFactory: function() {
2027
+
2028
+ var graph = this.graph;
2029
+
2030
+ return d3.svg.line()
2031
+ .x( function(d) { return graph.x(d.x) } )
2032
+ .y( function(d) { return graph.y(d.y) } )
2033
+ .interpolate(this.graph.interpolation).tension(this.tension);
2034
+ }
2035
+ } );
2036
+
2037
+ Rickshaw.namespace('Rickshaw.Graph.Renderer.Stack');
2038
+
2039
+ Rickshaw.Graph.Renderer.Stack = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
2040
+
2041
+ name: 'stack',
2042
+
2043
+ defaults: function($super) {
2044
+
2045
+ return Rickshaw.extend( $super(), {
2046
+ fill: true,
2047
+ stroke: false,
2048
+ unstack: false
2049
+ } );
2050
+ },
2051
+
2052
+ seriesPathFactory: function() {
2053
+
2054
+ var graph = this.graph;
2055
+
2056
+ return d3.svg.area()
2057
+ .x( function(d) { return graph.x(d.x) } )
2058
+ .y0( function(d) { return graph.y(d.y0) } )
2059
+ .y1( function(d) { return graph.y(d.y + d.y0) } )
2060
+ .interpolate(this.graph.interpolation).tension(this.tension);
2061
+ }
2062
+ } );
2063
+
2064
+ Rickshaw.namespace('Rickshaw.Graph.Renderer.Bar');
2065
+
2066
+ Rickshaw.Graph.Renderer.Bar = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
2067
+
2068
+ name: 'bar',
2069
+
2070
+ defaults: function($super) {
2071
+
2072
+ var defaults = Rickshaw.extend( $super(), {
2073
+ gapSize: 0.05,
2074
+ unstack: false
2075
+ } );
2076
+
2077
+ delete defaults.tension;
2078
+ return defaults;
2079
+ },
2080
+
2081
+ initialize: function($super, args) {
2082
+ args = args || {};
2083
+ this.gapSize = args.gapSize || this.gapSize;
2084
+ $super(args);
2085
+ },
2086
+
2087
+ domain: function($super) {
2088
+
2089
+ var domain = $super();
2090
+
2091
+ var frequentInterval = this._frequentInterval();
2092
+ domain.x[1] += parseInt(frequentInterval.magnitude);
2093
+
2094
+ return domain;
2095
+ },
2096
+
2097
+ barWidth: function() {
2098
+
2099
+ var stackedData = this.graph.stackedData || this.graph.stackData();
2100
+ var data = stackedData.slice(-1).shift();
2101
+
2102
+ var frequentInterval = this._frequentInterval();
2103
+ var barWidth = this.graph.x(data[0].x + frequentInterval.magnitude * (1 - this.gapSize));
2104
+
2105
+ return barWidth;
2106
+ },
2107
+
2108
+ render: function() {
2109
+
2110
+ var graph = this.graph;
2111
+
2112
+ graph.vis.selectAll('*').remove();
2113
+
2114
+ var barWidth = this.barWidth();
2115
+ var barXOffset = 0;
2116
+
2117
+ var activeSeriesCount = graph.series.filter( function(s) { return !s.disabled; } ).length;
2118
+ var seriesBarWidth = this.unstack ? barWidth / activeSeriesCount : barWidth;
2119
+
2120
+ var transform = function(d) {
2121
+ // add a matrix transform for negative values
2122
+ var matrix = [ 1, 0, 0, (d.y < 0 ? -1 : 1), 0, (d.y < 0 ? graph.y.magnitude(Math.abs(d.y)) * 2 : 0) ];
2123
+ return "matrix(" + matrix.join(',') + ")";
2124
+ };
2125
+
2126
+ graph.series.forEach( function(series) {
2127
+
2128
+ if (series.disabled) return;
2129
+
2130
+ var nodes = graph.vis.selectAll("path")
2131
+ .data(series.stack)
2132
+ .enter().append("svg:rect")
2133
+ .attr("x", function(d) { return graph.x(d.x) + barXOffset })
2134
+ .attr("y", function(d) { return (graph.y(d.y0 + Math.abs(d.y))) * (d.y < 0 ? -1 : 1 ) })
2135
+ .attr("width", seriesBarWidth)
2136
+ .attr("height", function(d) { return graph.y.magnitude(Math.abs(d.y)) })
2137
+ .attr("transform", transform);
2138
+
2139
+ Array.prototype.forEach.call(nodes[0], function(n) {
2140
+ n.setAttribute('fill', series.color);
2141
+ } );
2142
+
2143
+ if (this.unstack) barXOffset += seriesBarWidth;
2144
+
2145
+ }, this );
2146
+ },
2147
+
2148
+ _frequentInterval: function() {
2149
+
2150
+ var stackedData = this.graph.stackedData || this.graph.stackData();
2151
+ var data = stackedData.slice(-1).shift();
2152
+
2153
+ var intervalCounts = {};
2154
+
2155
+ for (var i = 0; i < data.length - 1; i++) {
2156
+ var interval = data[i + 1].x - data[i].x;
2157
+ intervalCounts[interval] = intervalCounts[interval] || 0;
2158
+ intervalCounts[interval]++;
2159
+ }
2160
+
2161
+ var frequentInterval = { count: 0 };
2162
+
2163
+ Rickshaw.keys(intervalCounts).forEach( function(i) {
2164
+ if (frequentInterval.count < intervalCounts[i]) {
2165
+
2166
+ frequentInterval = {
2167
+ count: intervalCounts[i],
2168
+ magnitude: i
2169
+ };
2170
+ }
2171
+ } );
2172
+
2173
+ this._frequentInterval = function() { return frequentInterval };
2174
+
2175
+ return frequentInterval;
2176
+ }
2177
+ } );
2178
+
2179
+ Rickshaw.namespace('Rickshaw.Graph.Renderer.Area');
2180
+
2181
+ Rickshaw.Graph.Renderer.Area = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
2182
+
2183
+ name: 'area',
2184
+
2185
+ defaults: function($super) {
2186
+
2187
+ return Rickshaw.extend( $super(), {
2188
+ unstack: false,
2189
+ fill: false,
2190
+ stroke: false
2191
+ } );
2192
+ },
2193
+
2194
+ seriesPathFactory: function() {
2195
+
2196
+ var graph = this.graph;
2197
+
2198
+ return d3.svg.area()
2199
+ .x( function(d) { return graph.x(d.x) } )
2200
+ .y0( function(d) { return graph.y(d.y0) } )
2201
+ .y1( function(d) { return graph.y(d.y + d.y0) } )
2202
+ .interpolate(graph.interpolation).tension(this.tension);
2203
+ },
2204
+
2205
+ seriesStrokeFactory: function() {
2206
+
2207
+ var graph = this.graph;
2208
+
2209
+ return d3.svg.line()
2210
+ .x( function(d) { return graph.x(d.x) } )
2211
+ .y( function(d) { return graph.y(d.y + d.y0) } )
2212
+ .interpolate(graph.interpolation).tension(this.tension);
2213
+ },
2214
+
2215
+ render: function() {
2216
+
2217
+ var graph = this.graph;
2218
+
2219
+ graph.vis.selectAll('*').remove();
2220
+
2221
+ var nodes = graph.vis.selectAll("path")
2222
+ .data(this.graph.stackedData)
2223
+ .enter().insert("svg:g", 'g');
2224
+
2225
+ nodes.append("svg:path")
2226
+ .attr("d", this.seriesPathFactory())
2227
+ .attr("class", 'area');
2228
+
2229
+ if (this.stroke) {
2230
+ nodes.append("svg:path")
2231
+ .attr("d", this.seriesStrokeFactory())
2232
+ .attr("class", 'line');
2233
+ }
2234
+
2235
+ var i = 0;
2236
+ graph.series.forEach( function(series) {
2237
+ if (series.disabled) return;
2238
+ series.path = nodes[0][i++];
2239
+ this._styleSeries(series);
2240
+ }, this );
2241
+ },
2242
+
2243
+ _styleSeries: function(series) {
2244
+
2245
+ if (!series.path) return;
2246
+
2247
+ d3.select(series.path).select('.area')
2248
+ .attr('fill', series.color);
2249
+
2250
+ if (this.stroke) {
2251
+ d3.select(series.path).select('.line')
2252
+ .attr('fill', 'none')
2253
+ .attr('stroke', series.stroke || d3.interpolateRgb(series.color, 'black')(0.125))
2254
+ .attr('stroke-width', this.strokeWidth);
2255
+ }
2256
+
2257
+ if (series.className) {
2258
+ series.path.setAttribute('class', series.className);
2259
+ }
2260
+ }
2261
+ } );
2262
+
2263
+ Rickshaw.namespace('Rickshaw.Graph.Renderer.ScatterPlot');
2264
+
2265
+ Rickshaw.Graph.Renderer.ScatterPlot = Rickshaw.Class.create( Rickshaw.Graph.Renderer, {
2266
+
2267
+ name: 'scatterplot',
2268
+
2269
+ defaults: function($super) {
2270
+
2271
+ return Rickshaw.extend( $super(), {
2272
+ unstack: true,
2273
+ fill: true,
2274
+ stroke: false,
2275
+ padding:{ top: 0.01, right: 0.01, bottom: 0.01, left: 0.01 },
2276
+ dotSize: 4
2277
+ } );
2278
+ },
2279
+
2280
+ initialize: function($super, args) {
2281
+ $super(args);
2282
+ },
2283
+
2284
+ render: function() {
2285
+
2286
+ var graph = this.graph;
2287
+
2288
+ graph.vis.selectAll('*').remove();
2289
+
2290
+ graph.series.forEach( function(series) {
2291
+
2292
+ if (series.disabled) return;
2293
+
2294
+ var nodes = graph.vis.selectAll("path")
2295
+ .data(series.stack)
2296
+ .enter().append("svg:circle")
2297
+ .attr("cx", function(d) { return graph.x(d.x) })
2298
+ .attr("cy", function(d) { return graph.y(d.y) })
2299
+ .attr("r", function(d) { return ("r" in d) ? d.r : graph.renderer.dotSize});
2300
+
2301
+ Array.prototype.forEach.call(nodes[0], function(n) {
2302
+ n.setAttribute('fill', series.color);
2303
+ } );
2304
+
2305
+ }, this );
2306
+ }
2307
+ } );
2308
+ Rickshaw.namespace('Rickshaw.Graph.Smoother');
2309
+
2310
+ Rickshaw.Graph.Smoother = function(args) {
2311
+
2312
+ this.graph = args.graph;
2313
+ this.element = args.element;
2314
+
2315
+ var self = this;
2316
+
2317
+ this.aggregationScale = 1;
2318
+
2319
+ if (this.element) {
2320
+
2321
+ $( function() {
2322
+ $(self.element).slider( {
2323
+ min: 1,
2324
+ max: 100,
2325
+ slide: function( event, ui ) {
2326
+ self.setScale(ui.value);
2327
+ self.graph.update();
2328
+ }
2329
+ } );
2330
+ } );
2331
+ }
2332
+
2333
+ self.graph.stackData.hooks.data.push( {
2334
+ name: 'smoother',
2335
+ orderPosition: 50,
2336
+ f: function(data) {
2337
+
2338
+ var aggregatedData = [];
2339
+
2340
+ data.forEach( function(seriesData) {
2341
+
2342
+ var aggregatedSeriesData = [];
2343
+
2344
+ while (seriesData.length) {
2345
+
2346
+ var avgX = 0, avgY = 0;
2347
+ var slice = seriesData.splice(0, self.aggregationScale);
2348
+
2349
+ slice.forEach( function(d) {
2350
+ avgX += d.x / slice.length;
2351
+ avgY += d.y / slice.length;
2352
+ } );
2353
+
2354
+ aggregatedSeriesData.push( { x: avgX, y: avgY } );
2355
+ }
2356
+
2357
+ aggregatedData.push(aggregatedSeriesData);
2358
+ } );
2359
+
2360
+ return aggregatedData;
2361
+ }
2362
+ } );
2363
+
2364
+ this.setScale = function(scale) {
2365
+
2366
+ if (scale < 1) {
2367
+ throw "scale out of range: " + scale;
2368
+ }
2369
+
2370
+ this.aggregationScale = scale;
2371
+ this.graph.update();
2372
+ }
2373
+ };
2374
+
2375
+ Rickshaw.namespace('Rickshaw.Graph.Unstacker');
2376
+
2377
+ Rickshaw.Graph.Unstacker = function(args) {
2378
+
2379
+ this.graph = args.graph;
2380
+ var self = this;
2381
+
2382
+ this.graph.stackData.hooks.after.push( {
2383
+ name: 'unstacker',
2384
+ f: function(data) {
2385
+
2386
+ if (!self.graph.renderer.unstack) return data;
2387
+
2388
+ data.forEach( function(seriesData) {
2389
+ seriesData.forEach( function(d) {
2390
+ d.y0 = 0;
2391
+ } );
2392
+ } );
2393
+
2394
+ return data;
2395
+ }
2396
+ } );
2397
+ };
2398
+
2399
+ Rickshaw.namespace('Rickshaw.Series');
2400
+
2401
+ Rickshaw.Series = Rickshaw.Class.create( Array, {
2402
+
2403
+ initialize: function (data, palette, options) {
2404
+
2405
+ options = options || {}
2406
+
2407
+ this.palette = new Rickshaw.Color.Palette(palette);
2408
+
2409
+ this.timeBase = typeof(options.timeBase) === 'undefined' ?
2410
+ Math.floor(new Date().getTime() / 1000) :
2411
+ options.timeBase;
2412
+
2413
+ var timeInterval = typeof(options.timeInterval) == 'undefined' ?
2414
+ 1000 :
2415
+ options.timeInterval;
2416
+
2417
+ this.setTimeInterval(timeInterval);
2418
+
2419
+ if (data && (typeof(data) == "object") && (data instanceof Array)) {
2420
+ data.forEach( function(item) { this.addItem(item) }, this );
2421
+ }
2422
+ },
2423
+
2424
+ addItem: function(item) {
2425
+
2426
+ if (typeof(item.name) === 'undefined') {
2427
+ throw('addItem() needs a name');
2428
+ }
2429
+
2430
+ item.color = (item.color || this.palette.color(item.name));
2431
+ item.data = (item.data || []);
2432
+
2433
+ // backfill, if necessary
2434
+ if ((item.data.length == 0) && this.length && (this.getIndex() > 0)) {
2435
+ this[0].data.forEach( function(plot) {
2436
+ item.data.push({ x: plot.x, y: 0 });
2437
+ } );
2438
+ } else if (item.data.length == 0) {
2439
+ item.data.push({ x: this.timeBase - (this.timeInterval || 0), y: 0 });
2440
+ }
2441
+
2442
+ this.push(item);
2443
+
2444
+ if (this.legend) {
2445
+ this.legend.addLine(this.itemByName(item.name));
2446
+ }
2447
+ },
2448
+
2449
+ addData: function(data) {
2450
+
2451
+ var index = this.getIndex();
2452
+
2453
+ Rickshaw.keys(data).forEach( function(name) {
2454
+ if (! this.itemByName(name)) {
2455
+ this.addItem({ name: name });
2456
+ }
2457
+ }, this );
2458
+
2459
+ this.forEach( function(item) {
2460
+ item.data.push({
2461
+ x: (index * this.timeInterval || 1) + this.timeBase,
2462
+ y: (data[item.name] || 0)
2463
+ });
2464
+ }, this );
2465
+ },
2466
+
2467
+ getIndex: function () {
2468
+ return (this[0] && this[0].data && this[0].data.length) ? this[0].data.length : 0;
2469
+ },
2470
+
2471
+ itemByName: function(name) {
2472
+
2473
+ for (var i = 0; i < this.length; i++) {
2474
+ if (this[i].name == name)
2475
+ return this[i];
2476
+ }
2477
+ },
2478
+
2479
+ setTimeInterval: function(iv) {
2480
+ this.timeInterval = iv / 1000;
2481
+ },
2482
+
2483
+ setTimeBase: function (t) {
2484
+ this.timeBase = t;
2485
+ },
2486
+
2487
+ dump: function() {
2488
+
2489
+ var data = {
2490
+ timeBase: this.timeBase,
2491
+ timeInterval: this.timeInterval,
2492
+ items: []
2493
+ };
2494
+
2495
+ this.forEach( function(item) {
2496
+
2497
+ var newItem = {
2498
+ color: item.color,
2499
+ name: item.name,
2500
+ data: []
2501
+ };
2502
+
2503
+ item.data.forEach( function(plot) {
2504
+ newItem.data.push({ x: plot.x, y: plot.y });
2505
+ } );
2506
+
2507
+ data.items.push(newItem);
2508
+ } );
2509
+
2510
+ return data;
2511
+ },
2512
+
2513
+ load: function(data) {
2514
+
2515
+ if (data.timeInterval) {
2516
+ this.timeInterval = data.timeInterval;
2517
+ }
2518
+
2519
+ if (data.timeBase) {
2520
+ this.timeBase = data.timeBase;
2521
+ }
2522
+
2523
+ if (data.items) {
2524
+ data.items.forEach( function(item) {
2525
+ this.push(item);
2526
+ if (this.legend) {
2527
+ this.legend.addLine(this.itemByName(item.name));
2528
+ }
2529
+
2530
+ }, this );
2531
+ }
2532
+ }
2533
+ } );
2534
+
2535
+ Rickshaw.Series.zeroFill = function(series) {
2536
+
2537
+ var x;
2538
+ var i = 0;
2539
+
2540
+ var data = series.map( function(s) { return s.data } );
2541
+
2542
+ while ( i < Math.max.apply(null, data.map( function(d) { return d.length } )) ) {
2543
+
2544
+ x = Math.min.apply( null,
2545
+ data
2546
+ .filter(function(d) { return d[i] })
2547
+ .map(function(d) { return d[i].x })
2548
+ );
2549
+
2550
+ data.forEach( function(d) {
2551
+ if (!d[i] || d[i].x != x) {
2552
+ d.splice(i, 0, { x: x, y: 0 });
2553
+ }
2554
+ } );
2555
+
2556
+ i++;
2557
+ }
2558
+ };
2559
+ Rickshaw.namespace('Rickshaw.Series.FixedDuration');
2560
+
2561
+ Rickshaw.Series.FixedDuration = Rickshaw.Class.create(Rickshaw.Series, {
2562
+
2563
+ initialize: function (data, palette, options) {
2564
+
2565
+ var options = options || {}
2566
+
2567
+ if (typeof(options.timeInterval) === 'undefined') {
2568
+ throw new Error('FixedDuration series requires timeInterval');
2569
+ }
2570
+
2571
+ if (typeof(options.maxDataPoints) === 'undefined') {
2572
+ throw new Error('FixedDuration series requires maxDataPoints');
2573
+ }
2574
+
2575
+ this.palette = new Rickshaw.Color.Palette(palette);
2576
+ this.timeBase = typeof(options.timeBase) === 'undefined' ? Math.floor(new Date().getTime() / 1000) : options.timeBase;
2577
+ this.setTimeInterval(options.timeInterval);
2578
+
2579
+ if (this[0] && this[0].data && this[0].data.length) {
2580
+ this.currentSize = this[0].data.length;
2581
+ this.currentIndex = this[0].data.length;
2582
+ } else {
2583
+ this.currentSize = 0;
2584
+ this.currentIndex = 0;
2585
+ }
2586
+
2587
+ this.maxDataPoints = options.maxDataPoints;
2588
+
2589
+
2590
+ if (data && (typeof(data) == "object") && (data instanceof Array)) {
2591
+ data.forEach( function (item) { this.addItem(item) }, this );
2592
+ this.currentSize += 1;
2593
+ this.currentIndex += 1;
2594
+ }
2595
+
2596
+ // reset timeBase for zero-filled values if needed
2597
+ this.timeBase -= (this.maxDataPoints - this.currentSize) * this.timeInterval;
2598
+
2599
+ // zero-fill up to maxDataPoints size if we don't have that much data yet
2600
+ if ((typeof(this.maxDataPoints) !== 'undefined') && (this.currentSize < this.maxDataPoints)) {
2601
+ for (var i = this.maxDataPoints - this.currentSize - 1; i > 0; i--) {
2602
+ this.currentSize += 1;
2603
+ this.currentIndex += 1;
2604
+ this.forEach( function (item) {
2605
+ item.data.unshift({ x: ((i-1) * this.timeInterval || 1) + this.timeBase, y: 0, i: i });
2606
+ }, this );
2607
+ }
2608
+ }
2609
+ },
2610
+
2611
+ addData: function($super, data) {
2612
+
2613
+ $super(data)
2614
+
2615
+ this.currentSize += 1;
2616
+ this.currentIndex += 1;
2617
+
2618
+ if (this.maxDataPoints !== undefined) {
2619
+ while (this.currentSize > this.maxDataPoints) {
2620
+ this.dropData();
2621
+ }
2622
+ }
2623
+ },
2624
+
2625
+ dropData: function() {
2626
+
2627
+ this.forEach(function(item) {
2628
+ item.data.splice(0, 1);
2629
+ } );
2630
+
2631
+ this.currentSize -= 1;
2632
+ },
2633
+
2634
+ getIndex: function () {
2635
+ return this.currentIndex;
2636
+ }
2637
+ } );