UNPKG

monte-ext-d3-tip

Version:
3 lines (2 loc) 3.65 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.monteExtD3Tip=t.monteExtD3Tip||{})}(this,function(t){"use strict";function e(t,e){return monte.Extension.featureEventName(t,e)}var n=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),i=function t(e,n,o){null===e&&(e=Function.prototype);var i=Object.getOwnPropertyDescriptor(e,n);if(void 0===i){var r=Object.getPrototypeOf(e);return null===r?void 0:t(r,n,o)}if("value"in i)return i.value;var s=i.get;if(void 0!==s)return s.call(o)},r=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},s=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},u=monte.tools,f=u.isFunc,c=u.isNumeric,h=u.isObject,p=u.isArray,a={eventPrefix:"d3tip",css:"d3-tip",direction:"n",offset:{},html:function(t,e){return t.value||t||e},featurePrefix:"",featureShowBindings:["mouseover","touchstart"],featureHideBindings:["mouseout"],showBindings:[],hideBindings:[]},l=function(t){function u(){return n(this,u),s(this,(u.__proto__||Object.getPrototypeOf(u)).apply(this,arguments))}return r(u,t),o(u,[{key:"_initOptions",value:function(){for(var t,e=arguments.length,n=Array(e),o=0;o<e;o++)n[o]=arguments[o];if((t=i(u.prototype.__proto__||Object.getPrototypeOf(u.prototype),"_initOptions",this)).call.apply(t,[this].concat(n,[a])),!this.opts.featurePrefix)throw monte.MonteOptionError.RequiredOption("featurePrefix",'If you wish to listen directly to chart events use: "chart"')}},{key:"_render",value:function(){var t=this.tryInvoke(this.option("css")),e=this.tryInvoke(this.option("direction")),n=this.option("html"),o=this.tryInvoke(this.option("offset")),i=d3.tip().attr("class",t).direction(e).html(n);if(!f(n))throw new monte.MonteOptionError('Check the "html" option value. A function is expected. Received: '+n);if(h(o))i.offset([+o.y||+o.top||0,+o.x||+o.left||0]);else{if(!c(o))throw new monte.MonteOptionError('Check the "offset" option value. A function, object, or number is expected. Received: '+o);i.offset([+o,0])}this.chart.bound.call(i),this.tip=i,this._bindTipEvents()}},{key:"_bindTipEvents",value:function(){var t=this,n=this.tip,o=this.tryInvoke(this.option("featureShowBindings")),i=this.tryInvoke(this.option("featureHideBindings")),r=this.tryInvoke(this.option("showBindings")),s=this.tryInvoke(this.option("hideBindings")),u=this.tryInvoke(this.option("featurePrefix"));p(u)||(u=[u]),u.forEach(function(r){o.forEach(function(o){return t.chart.on(e(r,o),n.show)}),i.forEach(function(o){return t.chart.on(e(r,o),n.hide)})}),r.forEach(function(e){return t.chart.on(e,n.show)}),s.forEach(function(e){return t.chart.on(e,n.hide)})}},{key:"_update",value:function(){}},{key:"_destroy",value:function(){this.tip.destroy()}},{key:"showTip",value:function(t,e){this.tip.show(t,e)}},{key:"hideTip",value:function(){this.tip.hide()}}]),u}(monte.Extension);t.ExtD3Tip=l,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=monte-ext-d3-tip.min.js.map