chrt-annotation
Version:
Annotation component for Chrt
3 lines (2 loc) • 3.98 kB
JavaScript
// chrt.io v0.0.22 Copyright 2022 chrt
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("chrt-object")):"function"==typeof define&&define.amd?define(["exports","chrt-object"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).chrt=t.chrt||{},t.chrt)}(this,(function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(e);function i(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return o(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return o(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function a(t){var e=this.attr("position")();return void 0===t?e:this.attr("position",Object.assign({},e,t))}function l(t){var e=this.attr("alignment")();return void 0===t?e:this.attr("alignment",Object.assign({},e,t))}var s=e.utils.isNull,c=e.utils.create;function u(t){var r=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{x:"x",y:"y"};n.default.call(this),this.type="annnotation",this.div=null,this.attr("text",null!=t?t:""),this.attr("color",null),this.attr("position",{}),this.attr("alignment",{horizontal:"middle",vertical:"middle"}),this.attr("offset",[0,0]),this._classNames=["chrt-annotation"],this.text=function(t){return r.attr("text",t)},this.draw=function(){var t,n;if("chrt"!==r.parentNode.type)return r;var a,l,u={x:r.parentNode.scales.x[o.x]||Object.values(r.parentNode.scales.x)[0],y:r.parentNode.scales.y[o.y]||Object.values(r.parentNode.scales.y)[0]};r.div||(r.div=c("div"),r.parentNode.root.appendChild(r.div),""===(null===(a=r.parentNode.root)||void 0===a||null===(l=a.style)||void 0===l?void 0:l.position)&&(r.parentNode.root.style.position="relative"),r.div.style.position="absolute",r.g=r.div);if(console.log("display",r.attr("display")()),e.cssDisplay.call(r,r.attr("display")()),r.div.setAttribute("id",r.id()),(t=r.div.classList).remove.apply(t,i(r.div.classList)),(n=r.div.classList).add.apply(n,i(r._classNames)),u&&u.x){var d=r.attr("position")(),f=s(d.x)?0:u.x(d.x),p=s(d.y)?0:u.y(d.y),y=r.attr("offset")();r.div.style.left="".concat(f+y[0],"px"),r.div.style.top="".concat(p+y[1],"px")}var h={x:0,y:0},v=r.attr("alignment")();switch(v.horizontal){case"left":h.x="0";break;case"right":h.x="-100%";break;default:h.x="-50%"}switch(v.vertical){case"bottom":h.y="0";break;case"top":h.y="-100%";break;default:h.y="-50%"}r.div.style.transform="translate(".concat(h.x,",").concat(h.y,")");var b,x=r.div.querySelector("span");x||((x=c("span")).style.color=null!==(b=r.color()())&&void 0!==b?b:"inherit",r.div.appendChild(x));return x.innerHTML=r.attr("text")(),r}}u.prototype=Object.create(n.default.prototype),u.prototype.constructor=u,u.parent=n.default.prototype,u.prototype=Object.assign(u.prototype,{color:function(t){return this.attr("color",t)},position:a,top:function(t){return a.call(this,{y:t})},left:function(t){return a.call(this,{x:t})},align:function(t){return void 0===t?l.call(this).horizontal:l.call(this,{horizontal:t})},valign:function(t){return void 0===t?l.call(this).vertical:l.call(this,{vertical:t})},offset:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];if(!e.length)return this.attr("offset")();var n=this.attr("offset")(),i=e[0],o=e[1];return this.attr("offset",[null!=i?i:n[0],null!=o?o:n[1]])}}),t.chrtAnnotation=function(t,e){return new u(t,e)},Object.defineProperty(t,"__esModule",{value:!0})}));