-
Notifications
You must be signed in to change notification settings - Fork 11
/
d3.chart.base.min.js
5 lines (5 loc) · 3.76 KB
/
d3.chart.base.min.js
1
2
3
4
5
/*! d3.chart.base - v0.4.0
* License: MIT Expat
* Date: 2013-10-15
*/
(function(t){function e(t){var e,i=this.base[0][0];return window.getComputedStyle?e=window.getComputedStyle(i):i.currentStyle&&(e=i.currentStyle),t?e[t]:e}function i(t,i,s){var r=n(e.call(this,i));null===r||0===r||""===r?(this[t]=s,this.base.style(i,s)):this[t]=n(e.call(this,i))}function s(t,e,i){var s,r,h,n,a;return function(){h=this,r=arguments,n=new Date;var o=function(){var l=new Date-n;e>l?s=setTimeout(o,e-l):(s=null,i||(a=t.apply(h,r)))},l=i&&!s;return s||(s=setTimeout(o,e)),l&&(a=t.apply(h,r)),a}}function r(){var t=this._currentMode;if(this._currentMode=null,"modes"in this){var e=!1;for(var i in this._modes)if(e=this._modes[i].call(this)){this._currentMode=i;break}}return t!==this._currentMode}function h(){var t=this;for(var e in t._layersArguments){var i=t._layersArguments[e];if(-1===i.options.modes.indexOf(t.mode())){if(i.showing===!0){var s=t.unlayer(e);s.style("display","none"),t._layersArguments[e].showing=!1,t._layersArguments[e].layer=s}}else t._layersArguments[e].showing===!1&&(null!==t._layersArguments[e].layer?(o.call(t,e,t._layersArguments[e].layer),t._layersArguments[e].layer.style("display","inline")):o.call(t,t._layersArguments[e].name,t._layersArguments[e].selection,t._layersArguments[e].options),t._layersArguments[e].showing=!0)}}var n=function(){var t=/px$/;return function(e){return t.test(e)?+e.replace(t,""):e}}(),a=t.chart("BaseChart",{initialize:function(){var t=this;this._layersArguments={},this._modes=this.modes||{},delete this.modes,this._modeLayers={},r.call(this),t._width=n(e.call(t,"width"))||200,t._height=n(e.call(t,"height"))||200,i.call(this,"_width","width",200),i.call(this,"_height","height",200),window.addEventListener("resize",s(function(){t.trigger("resize"),isNaN(t._width)||t.width(n(e.call(t,"width"))||200,{noDraw:!0}),isNaN(t._height)||t.height(n(e.call(t,"height"))||200,{noDraw:!0});var i=r.call(t);i&&t.trigger("change:mode",this._currentMode),t.data&&t.draw(t.data)},150)),window.addEventListener("orientationchange",function(){t.trigger("change:mode",this._currentMode),t.data&&t.draw(t.data)},!1),t.on("change:mode",function(){h.call(t)})},mode:function(){return this._currentMode},recomputeMode:function(){var t=r.call(this);return t&&this.trigger("change:mode",this._currentMode),t},width:function(t,i){if(i=i||{},0===arguments.length)return this._width&&!isNaN(+this._width)?this._width:n(e.call(this,"width"));var s=this._width;return this._width=t,this._width!==s&&(this.base.style("width",isNaN(this._width)?this._width:this._width+"px"),i.silent||this.trigger("change:width",this._width,s),this.data&&!i.noDraw&&this.draw(this.data)),this},height:function(t,i){if(i=i||{},0===arguments.length)return this._height&&!isNaN(+this._height)?this._height:n(e.call(this,"height"));var s=this._height;return this._height=t,this._height!==s&&(this.base.style("height",isNaN(this._height)?this._height:this._height+"px"),i.silent||this.trigger("change:height",this._height,s),this.data&&!i.noDraw&&this.draw(this.data)),this}}),o=a.prototype.layer;a.prototype.layer=function(t,e,i){var s=this;if(1===arguments.length)return o.call(this,t);s._layersArguments[t]={name:t,selection:e,options:i,showing:!1,layer:null};var r;if((i.modes===void 0||"modes"in i&&i.modes.indexOf(s.mode())>-1)&&(r=o.call(this,t,e,i),s._layersArguments[t].showing=!0,s._layersArguments[t].layer=r),"modes"in i)r&&(r._modes=i.modes),i.modes.forEach(function(e){if(!(e in s._modes))throw Error("Mode "+e+" is not defined");s._modeLayers[e]=s._modeLayers[e]||[],s._modeLayers[e].push(t)});else if(s._modes){var h=Object.keys(s._modes);r&&(r._modes=h),h.forEach(function(e){s._modeLayers[e]=s._modeLayers[e]||[],s._modeLayers[e].push(t)}),s._layersArguments[t].showing=!0,s._layersArguments[t].layer=r}return r}})(window.d3);