/*! d3.chart - v0.1.0 * License: MIT Expat * Date: 2013-05-27 */ (function(t){"use strict";var n=t.d3,e={noBase:Error("d3.layer must be initialized with a base"),noDataBind:Error("d3.layer must specify a `dataBind` method."),noInsert:Error("d3.layer must specify an `insert` method.")},r=function(t){if(!t)throw e.noBase;this._base=t,this._handlers={}};r.prototype.dataBind=function(){throw e.noDataBind},r.prototype.insert=function(){throw e.noInsert},r.prototype.on=function(t,n,e){e=e||{},t in this._handlers||(this._handlers[t]=[]),this._handlers[t].push({callback:n,chart:e.chart||null})},r.prototype.off=function(t,n){var e,r=this._handlers[t];if(r){if(1===arguments.length)return r.length=0,undefined;for(e=r.length-1;e>-1;--e)r[e].callback===n&&r.splice(e,1)}},r.prototype.draw=function(t){var e,r,i,s,o,a,h,c;if(e=this.dataBind.call(this._base,t),!(e instanceof n.selection))throw Error("Invalid selection defined by `dataBind` method.");r=e.enter(),r._chart=this._base._chart,i=[{name:"update",selection:e},{name:"enter",selection:this.insert.bind(r)},{name:"merge",selection:e},{name:"exit",selection:e.exit.bind(e)}];for(var l=0,u=i.length;u>l;++l){if(a=i[l].name,s=i[l].selection,"function"==typeof s&&(s=s()),!(s instanceof n.selection))throw Error('Invalid selection defined for "'+a+"' lifecycle event.");if(o=this._handlers[a])for(h=0,c=o.length;c>h;++h)s._chart=o[h].chart||this._base._chart,s.call(o[h].callback);if(o=this._handlers[a+":transition"],o&&o.length)for(s=s.transition(),h=0,c=o.length;c>h;++h)s._chart=o[h].chart||this._base._chart,s.call(o[h].callback)}},n.selection.prototype.layer=function(t){var n,e=new r(this);if(e.dataBind=t.dataBind,e.insert=t.insert,"events"in t)for(n in t.events)e.on(n,t.events[n]);return this.on=function(){return e.on.apply(e,arguments)},this.off=function(){return e.off.apply(e,arguments)},this.draw=function(){return e.draw.apply(e,arguments)},this}})(this),function(t){"use strict";function n(t){var n,e,r,i;if(!t)return t;for(e=arguments.length,n=1;e>n;n++)if(r=arguments[n])for(i in r)t[i]=r[i];return t}var e=t.d3,r=function(t){this.constructor=t},i=function(t,n){var e;return r.prototype=t.prototype,e=new r(t),t.apply(e,n),e},s=function(t,n){var e=this.constructor.__super__;e&&s.call(e,t,n),Object.hasOwnProperty.call(this.constructor.prototype,"initialize")&&this.initialize.apply(t,n)},o=function(t){this.base=t,this._layers={},this._mixins=[],this._events={},s.call(this,this,Array.prototype.slice.call(arguments,1))};o.prototype.unlayer=function(t){var n=this.layer(t),e=this._layerList.indexOf(n);return delete this._layers[t],this._layerList.splice(e,1),this},o.prototype.layer=function(t,n,e){var r;return 1===arguments.length?this._layers[t]:(r=n.layer(e),this._layers[t]=r,n._chart=this,r)},o.prototype.initialize=function(){},o.prototype.transform=function(t){return t},o.prototype.mixin=function(t,n){var e=Array.prototype.slice.call(arguments,2);e.unshift(n);var r=o[t],s=i(r,e);return this._mixins.push(s),s},o.prototype.draw=function(t){var n,e;t=this.transform(t);for(n in this._layers)this._layers[n].draw(t);for(e in this._mixins)this._mixins[e].draw(t)},o.prototype.on=function(t,n,e){var r=this._events[t]||(this._events[t]=[]);return r.push({callback:n,context:e||this,_chart:this}),this},o.prototype.once=function(t,n,e){var r=this,i=function(){r.off(t,i),n.apply(this,arguments)};return this.on(t,i,e)},o.prototype.off=function(t,n,e){var r,i,s,o,a,h;if(0===arguments.length){for(t in this._events)this._events[t].length=0;return this}if(1===arguments.length)return s=this._events[t],s&&(s.length=0),this;for(r=t?[t]:Object.keys(this._events),a=0;r.length>a;a++)for(i=r[a],s=this._events[i],h=s.length;h--;)o=s[h],(n&&n===o.callback||e&&e===o.context)&&s.splice(h,1);return this},o.prototype.trigger=function(t){var n,e,r=Array.prototype.slice.call(arguments,1),i=this._events[t];for(n=0;i.length>n;n++)e=i[n],e.callback.apply(e.context,r);return this},o.extend=function(t,e,r){var i,s=this;i=e&&Object.hasOwnProperty.call(e,"constructor")?e.constructor:function(){return s.apply(this,arguments)},n(i,s,r);var a=function(){this.constructor=i};return a.prototype=s.prototype,i.prototype=new a,e&&n(i.prototype,e),i.__super__=s.prototype,o[t]=i,i},e.chart=function(t){return 0===arguments.length?o:1===arguments.length?o[t]:o.extend.apply(o,arguments)},e.selection.prototype.chart=function(t){if(0===arguments.length)return this._chart;var n=Array.prototype.slice.call(arguments,1);n.unshift(this);var e=o[t];return i(e,n)},e.selection.enter.prototype.chart=function(){return this._chart},e.transition.prototype.chart=e.selection.enter.prototype.chart}(this);