higlass-labeled-annotation
Version:
Labeled Annotation Track for HiGlass
1 lines • 13.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["higlass-labeled-annotation"]=e():t["higlass-labeled-annotation"]=e()}(window,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e),window.higlassTracks=window.higlassTracks||{},window.higlassTracksByType=window.higlassTracksByType||{};var i=t=>{window.higlassTracks[t.name]=t,window.higlassTracksByType[t.config.type]=t},r=function(t,e,n){t.prototype=e.prototype=n,n.constructor=t};function a(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function o(){}var s="\\s*([+-]?\\d+)\\s*",l="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",h="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",c=/^#([0-9a-f]{3})$/,u=/^#([0-9a-f]{6})$/,p=new RegExp("^rgb\\("+[s,s,s]+"\\)$"),g=new RegExp("^rgb\\("+[h,h,h]+"\\)$"),d=new RegExp("^rgba\\("+[s,s,s,l]+"\\)$"),f=new RegExp("^rgba\\("+[h,h,h,l]+"\\)$"),y=new RegExp("^hsl\\("+[l,h,h]+"\\)$"),b=new RegExp("^hsla\\("+[l,h,h,l]+"\\)$"),w={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function m(t){var e;return t=(t+"").trim().toLowerCase(),(e=c.exec(t))?new x((e=parseInt(e[1],16))>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):(e=u.exec(t))?v(parseInt(e[1],16)):(e=p.exec(t))?new x(e[1],e[2],e[3],1):(e=g.exec(t))?new x(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=d.exec(t))?k(e[1],e[2],e[3],e[4]):(e=f.exec(t))?k(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=y.exec(t))?N(e[1],e[2]/100,e[3]/100,1):(e=b.exec(t))?N(e[1],e[2]/100,e[3]/100,e[4]):w.hasOwnProperty(t)?v(w[t]):"transparent"===t?new x(NaN,NaN,NaN,0):null}function v(t){return new x(t>>16&255,t>>8&255,255&t,1)}function k(t,e,n,i){return i<=0&&(t=e=n=NaN),new x(t,e,n,i)}function M(t){return t instanceof o||(t=m(t)),t?new x((t=t.rgb()).r,t.g,t.b,t.opacity):new x}function x(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function N(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new O(t,e,n,i)}function O(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function _(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}r(o,m,{displayable:function(){return this.rgb().displayable()},toString:function(){return this.rgb()+""}}),r(x,function(t,e,n,i){return 1===arguments.length?M(t):new x(t,e,n,null==i?1:i)},a(o,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new x(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new x(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return 0<=this.r&&this.r<=255&&0<=this.g&&this.g<=255&&0<=this.b&&this.b<=255&&0<=this.opacity&&this.opacity<=1},toString:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}})),r(O,function(t,e,n,i){return 1===arguments.length?function(t){if(t instanceof O)return new O(t.h,t.s,t.l,t.opacity);if(t instanceof o||(t=m(t)),!t)return new O;if(t instanceof O)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),a=Math.max(e,n,i),s=NaN,l=a-r,h=(a+r)/2;return l?(s=e===a?(n-i)/l+6*(n<i):n===a?(i-e)/l+2:(e-n)/l+4,l/=h<.5?a+r:2-a-r,s*=60):l=h>0&&h<1?0:s,new O(s,l,h,t.opacity)}(t):new O(t,e,n,null==i?1:i)},a(o,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new O(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new O(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*e,r=2*n-i;return new x(_(t>=240?t-240:t+120,r,i),_(t,r,i),_(t<120?t+240:t-120,r,i),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1}}));var R=Math.PI/180,j=180/Math.PI,P=.96422,T=1,E=.82521,S=4/29,q=6/29,L=3*q*q,C=q*q*q;function $(t){if(t instanceof F)return new F(t.l,t.a,t.b,t.opacity);if(t instanceof W){if(isNaN(t.h))return new F(t.l,0,0,t.opacity);var e=t.h*R;return new F(t.l,Math.cos(e)*t.c,Math.sin(e)*t.c,t.opacity)}t instanceof x||(t=M(t));var n,i,r=z(t.r),a=z(t.g),o=z(t.b),s=I((.2225045*r+.7168786*a+.0606169*o)/T);return r===a&&a===o?n=i=s:(n=I((.4360747*r+.3850649*a+.1430804*o)/P),i=I((.0139322*r+.0971045*a+.7141733*o)/E)),new F(116*s-16,500*(n-s),200*(s-i),t.opacity)}function F(t,e,n,i){this.l=+t,this.a=+e,this.b=+n,this.opacity=+i}function I(t){return t>C?Math.pow(t,1/3):t/L+S}function A(t){return t>q?t*t*t:L*(t-S)}function B(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function z(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function G(t){if(t instanceof W)return new W(t.h,t.c,t.l,t.opacity);if(t instanceof F||(t=$(t)),0===t.a&&0===t.b)return new W(NaN,0,t.l,t.opacity);var e=Math.atan2(t.b,t.a)*j;return new W(e<0?e+360:e,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}function W(t,e,n,i){this.h=+t,this.c=+e,this.l=+n,this.opacity=+i}r(F,function(t,e,n,i){return 1===arguments.length?$(t):new F(t,e,n,null==i?1:i)},a(o,{brighter:function(t){return new F(this.l+18*(null==t?1:t),this.a,this.b,this.opacity)},darker:function(t){return new F(this.l-18*(null==t?1:t),this.a,this.b,this.opacity)},rgb:function(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,n=isNaN(this.b)?t:t-this.b/200;return new x(B(3.1338561*(e=P*A(e))-1.6168667*(t=T*A(t))-.4906146*(n=E*A(n))),B(-.9787684*e+1.9161415*t+.033454*n),B(.0719453*e-.2289914*t+1.4052427*n),this.opacity)}})),r(W,function(t,e,n,i){return 1===arguments.length?G(t):new W(t,e,n,null==i?1:i)},a(o,{brighter:function(t){return new W(this.h,this.c,this.l+18*(null==t?1:t),this.opacity)},darker:function(t){return new W(this.h,this.c,this.l-18*(null==t?1:t),this.opacity)},rgb:function(){return $(this).rgb()}}));var D=-.14861,H=1.78277,U=-.29227,X=-.90649,J=1.97294,K=J*X,Q=J*H,V=H*U-X*D;function Y(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}r(Y,function(t,e,n,i){return 1===arguments.length?function(t){if(t instanceof Y)return new Y(t.h,t.s,t.l,t.opacity);t instanceof x||(t=M(t));var e=t.r/255,n=t.g/255,i=t.b/255,r=(V*i+K*e-Q*n)/(V+K-Q),a=i-r,o=(J*(n-r)-U*a)/X,s=Math.sqrt(o*o+a*a)/(J*r*(1-r)),l=s?Math.atan2(o,a)*j-120:NaN;return new Y(l<0?l+360:l,s,r,t.opacity)}(t):new Y(t,e,n,null==i?1:i)},a(o,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new Y(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Y(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=isNaN(this.h)?0:(this.h+120)*R,e=+this.l,n=isNaN(this.s)?0:this.s*e*(1-e),i=Math.cos(t),r=Math.sin(t);return new x(255*(e+n*(D*i+H*r)),255*(e+n*(U*i+X*r)),255*(e+n*(J*i)),this.opacity)}}));var Z=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),tt=function t(e,n,i){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,n);if(void 0===r){var a=Object.getPrototypeOf(e);return null===a?void 0:t(a,n,i)}if("value"in r)return r.value;var o=r.get;return void 0!==o?o.call(i):void 0};var et=function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');var r=t.libraries.PIXI,a=function(e){function n(t,e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n);var i=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}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e.options));return i.drawnRects=new Set,i.g1=new r.Graphics,i.g2=new r.Graphics,i.g3=new r.Graphics,i.pMain.addChild(i.g1),i.pMain.addChild(i.g2),i.pMain.addChild(i.g3),i.drawnLabels=[],i}return 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)}(n,t.tracks.PixiTrack),Z(n,[{key:"draw",value:function(){var t=this;this.drawnRects.clear();var e=this.options.minRectWidth?this.options.minRectWidth:10,i=this.options.minRectWidth?this.options.minRectHeight:10;tt(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"draw",this).call(this),this.g1.clear(),this.g2.clear(),this.g3.clear(),this.label&&this.g3.removeChild(this.label),this.options.regions.forEach(function(n,a){var o=m(n[4]),s=m(n[5]);s||(s=o);var l=r.utils.rgb2hex([o.r/255,o.g/255,o.b/255]),h=r.utils.rgb2hex([s.r/255,s.g/255,s.b/255]);t.g1.lineStyle(6,16777215,1),t.g1.beginFill(l,o.opacity),t.g2.lineStyle(2,h,s.opacity),t.g2.beginFill(l,o.opacity),t.g3.lineStyle(2,h,1),t.g3.beginFill(h,1);var c=t._xScale(+n[0]),u=t._xScale(+n[1]),p=t._yScale(+n[2]),g=t._yScale(+n[3]),d=u-c,f=g-p,y=void 0!==n[6]?n[6]:e,b=void 0!==n[7]?n[7]:i;if(d<y&&(c=(c+u)/2-y/2,d=y),f<b&&(p=(p+g)/2-b/2,f=b),n[8]&&t.g1.drawRect(c-8,p-8,16,16),t.g1.drawRect(c,p,d,f),t.g2.drawRect(c,p,d,f),t.g3.drawRect(c-8,p-8,16,16),n[8]){var w=16;t.drawnLabels[a]||(t.drawnLabels[a]=new r.Text(n[8],{fontFamily:"Arial",fontSize:16,fill:16777215,align:"center"}),t.g3.addChild(t.drawnLabels[a]));var v=t.drawnLabels[a].getBounds().width;v>w&&(w=v+4),console.log("??",w),t.g1.drawRect(c-8,p-8,w,16),t.g3.drawRect(c-8,p-8,w,16),t.drawnLabels[a].x=c-6,t.drawnLabels[a].y=p-9}})}},{key:"setPosition",value:function(t){tt(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"setPosition",this).call(this,t),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0]}},{key:"zoomed",value:function(t,e){this.xScale(t),this.yScale(e),this.draw()}}]),n}();return new(Function.prototype.bind.apply(a,[null].concat(n)))};i({name:"LabeledAnnotationTrack",track:et,config:et.config={type:"labeled-annotations",datatype:["labeled-annotations"],local:!0,orientation:"2d",name:"Labeled Annotations",thumbnail:null,hidden:!0,availableOptions:["regions"],defaultOptions:{regions:[]}}})}])});