protvista-utils
Advanced tools
Comparing version 3.0.0 to 3.2.13
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ProtvistaUtils=e():t.ProtvistaUtils=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},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=10)}([function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function n(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}t.exports=function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}},function(t,e){function n(e){return t.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},n(e)}t.exports=n},function(t,e,n){var r=n(14),i=n(15),o=n(5),l=n(16);t.exports=function(t){return r(t)||i(t)||o(t)||l()}},function(t,e,n){var r=n(17);function i(e,n,o){return"undefined"!=typeof Reflect&&Reflect.get?t.exports=i=Reflect.get:t.exports=i=function(t,e,n){var i=r(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(n):o.value}},i(e,n,o||e)}t.exports=i},function(t,e,n){var r=n(6);t.exports=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}},function(t,e){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}},function(t,e,n){var r=n(11),i=n(12),o=n(5),l=n(13);t.exports=function(t,e){return r(t)||i(t,e)||o(t,e)||l()}},function(t,e,n){var r=n(18);t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}},function(t,e,n){var r=n(19),i=n(20);t.exports=function(t,e){return!e||"object"!==r(e)&&"function"!=typeof e?i(t):e}},function(t,e,n){t.exports=n(21)},function(t,e){t.exports=function(t){if(Array.isArray(t))return t}},function(t,e){t.exports=function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],r=!0,i=!1,o=void 0;try{for(var l,u=t[Symbol.iterator]();!(r=(l=u.next()).done)&&(n.push(l.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==u.return||u.return()}finally{if(i)throw o}}return n}}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},function(t,e,n){var r=n(6);t.exports=function(t){if(Array.isArray(t))return r(t)}},function(t,e){t.exports=function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}},function(t,e){t.exports=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(t,e,n){var r=n(2);t.exports=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}},function(t,e){function n(e,r){return t.exports=n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(e,r)}t.exports=n},function(t,e){function n(e){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?t.exports=n=function(t){return typeof t}:t.exports=n=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(e)}t.exports=n},function(t,e){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}},function(t,e,n){"use strict";n.r(e),n.d(e,"Region",(function(){return T})),n.d(e,"TrackHighlighter",(function(){return P})),n.d(e,"ColorScaleParser",(function(){return R})),n.d(e,"String2Object",(function(){return C})),n.d(e,"ScrollFilter",(function(){return I})),n.d(e,"withMargin",(function(){return F}));var r=n(7),i=n.n(r),o=n(0),l=n.n(o),u=n(1),a=n.n(u),c=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.min,r=void 0===n?-1/0:n,i=e.max,o=void 0===i?1/0:i;l()(this,t),this.segments=[],this.max=o,this.min=r,this.regionString=null}return a()(t,[{key:"encode",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.segments.map((function(n){var r=n.start,i=n.end;if(e)return"".concat(r,":").concat(i);var o=r===t.min?"":r,l=i===t.max?"":i;return"".concat(o,":").concat(l)})).join(",")}},{key:"decode",value:function(t){var e=this;void 0!==t&&(this.regionString=t),this.regionString?this.segments=this.regionString.split(",").map((function(t){var n=t.split(":"),r=i()(n,3),o=r[0],l=r[1];if(void 0!==r[2])throw new Error("there should be at most 1 ':' per region. Region: ".concat(t));var u=o?Number(o):e.min,a=l?Number(l):e.max;if(u>a){var c=[a,u];u=c[0],a=c[1]}if(u<e.min&&(u=e.min),a>e.max&&(a=e.max),Number.isNaN(u))throw new Error("The parsed value of ".concat(o," is NaN. Region: ").concat(t));if(Number.isNaN(a))throw new Error("The parsed value of ".concat(l," is NaN. Region: ").concat(t));return{start:u,end:a}})):this.segments=[]}}]),t}(),s=function(t,e){return t?e?"".concat(t,",").concat(e):t:e},h=function(){function t(e){var n=e.element,r=e.min,i=e.max;l()(this,t),this.element=n,this.region=new c({min:r,max:i}),this.fixedHighlight=null}return a()(t,[{key:"setAttributesInElement",value:function(){this.region.decode(this.element.getAttribute("highlight")),0===this.region.segments.length&&(this.element._highlightstart=Number(this.element.getAttribute("highlightstart")),this.element._highlightend=Number(this.element.getAttribute("highlightend")),null!==this.element._highlightstart&&null!==this.element._highlightend&&"number"==typeof this.element._highlightstart&&"number"==typeof this.element._highlightend&&(this.element._highlight="".concat(this.element._highlightstart,":").concat(this.element._highlightend),this.region.decode(s(this.fixedHighlight,this.element._highlight))))}},{key:"setFloatAttribute",value:function(t,e){var n=parseFloat(e);this.element["_".concat(t)]=Number.isNaN(n)?e:n}},{key:"changedCallBack",value:function(t,e){switch(t){case"highlightstart":case"highlightend":this.setFloatAttribute(t,e),this.element._highlight=Number.isNaN(this.element._highlightstart)||Number.isNaN(this.element._highlightend)||void 0===this.element._highlightstart||void 0===this.element._highlightend||null===this.element._highlightstart||null===this.element._highlightend?"":"".concat(Math.max(this.region.min,this.element._highlightstart),":").concat(Math.min(this.region.max,this.element._highlightend));break;default:this.element._highlight=e}this.region.decode(s(this.fixedHighlight,this.element._highlight)),this.element.refresh()}},{key:"setFixedHighlight",value:function(t){this.fixedHighlight=t,this.region.decode(s(t,this.element._highlight)),this.element.refresh()}},{key:"appendHighlightTo",value:function(t){this.highlighted=t.append("g").attr("class","highlighted")}},{key:"updateHighlight",value:function(){var t=this,e=this.highlighted.selectAll("rect").data(this.region.segments);e.enter().append("rect").style("opacity",.5).attr("fill","rgba(255, 235, 59, 0.8)").style("pointer-events","none").merge(e).attr("height",this.element._height).attr("x",(function(e){return t.element.getXFromSeqPosition(e.start)})).attr("width",(function(e){return t.element.getSingleBaseWidth()*(e.end-e.start+1)})),e.exit().remove()}},{key:"max",set:function(t){this.region.max=t}}]),t}();function f(t){var e=document.createElement("div");return e.style.borderColor="",e.style.borderColor=t,""!==e.style.borderColor}var g=function(t){return t},m=function(){function t(e){l()(this,t),this.element=e,this.timeStampWheelOutside=0,this.resetScrollableTimeout=null}return a()(t,[{key:"setElementScrollable",value:function(t){this.element.setAttribute("scrollable",t)}},{key:"startResetScrollableTimer",value:function(){var t=this;this.resetScrollableTimeout&&clearTimeout(this.resetScrollableTimeout),this.resetScrollableTimeout=setTimeout((function(){t.setElementScrollable(!0),t.resetScrollableTimeout=null}),400)}},{key:"blockScroll",value:function(t){this.timeStampWheelOutside=t,this.setElementScrollable(!1),this.startResetScrollableTimer()}},{key:"isWheelEventInsideElement",value:function(t,e){var n=this.element.getBoundingClientRect(),r=n.height,i=n.width,o=n.x,l=n.y;return t>o&&e<o+i&&e>l&&e<l+r}},{key:"wheel",value:function(t){var e=t.x,n=t.y,r=t.timeStamp;this.isWheelEventInsideElement(e,n)?r<this.timeStampWheelOutside+400?this.blockScroll(r):this.setElementScrollable(!0):this.blockScroll(r)}}]),t}(),p=n(3),d=n.n(p),y=n(4),b=n.n(y),v=n(8),x=n.n(v),S=n(9),w=n.n(S),_=n(2),j=n.n(_);function O(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return E(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return E(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,u=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return l=t.done,t},e:function(t){u=!0,o=t},f:function(){try{l||null==n.return||n.return()}finally{if(u)throw o}}}}function E(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function k(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=j()(t);if(e){var i=j()(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return w()(this,n)}}var A=["left","right","top","bottom"],N=A.map((function(t){return"margin".concat(t)})),T=c,P=h,R=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=[],n=[];if(null!==t&&"string"!=typeof t)throw new Error("The attribute text has to be of type string");if(t&&""!==t.trim()){var r=t.split(",").map((function(t){return t.split(":")}));if(r.length<2)throw new Error("There should be at least 2 points to create a scale");e=r.map((function(t){var e=t[0].trim().toUpperCase();if(!f(e))throw new Error("The color '".concat(e," is not valid'"));return e})),n=r.map((function(t,e){var n=parseFloat(t[1]);if(Number.isNaN(n))throw new Error("The second part of every point should be a number. Error in point ".concat(e,": ").concat(t));return n}))}return{range:e,domain:n}},C=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.keyFormatter,r=void 0===n?g:n,i=e.valueFormatter,o=void 0===i?g:i;if(null!==t&&"string"!=typeof t)throw new Error("The attribute text has to be of type string");if(t&&""!==t.trim()){var l=t.split(",").map((function(t){return t.split(":")})),u={};return l.forEach((function(t){if(2!==t.length)throw new Error("Bad block: ".concat(t.join(":"),"\n The blocks of the string should follow the format KEY:VALUE"));u[r(t[0])]=o(t[1])})),u}return{}},I=m,F=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{initialValue:{top:0,bottom:0,left:0,right:0}},r=function(t){x()(r,t);var e=k(r);function r(){var t;return l()(this,r),(t=e.call(this)).margin=n.initialValue,t}return a()(r,[{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&N.includes(t)&&(this[t]=n),b()(j()(r.prototype),"attributeChangedCallback",this).call(this,t,e,n)}}],[{key:"observedAttributes",get:function(){return[].concat(d()(b()(j()(r),"observedAttributes",this)),d()(N))}}]),r}(t),i=O(A);try{var o=function(){var t=e.value;Object.defineProperty(r.prototype,"margin".concat(t),{get:function(){return this.margin[t]||0},set:function(e){this.margin[t]=+e}})};for(i.s();!(e=i.n()).done;)o()}catch(t){i.e(t)}finally{i.f()}return r}}])})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ProtvistaUtils=e():t.ProtvistaUtils=e()}(window,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},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=10)}([function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function n(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}t.exports=function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}},function(t,e){function n(e){return t.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},n(e)}t.exports=n},function(t,e,n){var r=n(14),i=n(15),o=n(5),l=n(16);t.exports=function(t){return r(t)||i(t)||o(t)||l()}},function(t,e,n){var r=n(17);function i(e,n,o){return"undefined"!=typeof Reflect&&Reflect.get?t.exports=i=Reflect.get:t.exports=i=function(t,e,n){var i=r(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(n):o.value}},i(e,n,o||e)}t.exports=i},function(t,e,n){var r=n(6);t.exports=function(t,e){if(t){if("string"==typeof t)return r(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}},function(t,e){t.exports=function(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}},function(t,e,n){var r=n(11),i=n(12),o=n(5),l=n(13);t.exports=function(t,e){return r(t)||i(t,e)||o(t,e)||l()}},function(t,e,n){var r=n(18);t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}},function(t,e,n){var r=n(19),i=n(20);t.exports=function(t,e){return!e||"object"!==r(e)&&"function"!=typeof e?i(t):e}},function(t,e,n){t.exports=n(21)},function(t,e){t.exports=function(t){if(Array.isArray(t))return t}},function(t,e){t.exports=function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],r=!0,i=!1,o=void 0;try{for(var l,a=t[Symbol.iterator]();!(r=(l=a.next()).done)&&(n.push(l.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==a.return||a.return()}finally{if(i)throw o}}return n}}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},function(t,e,n){var r=n(6);t.exports=function(t){if(Array.isArray(t))return r(t)}},function(t,e){t.exports=function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}},function(t,e){t.exports=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(t,e,n){var r=n(2);t.exports=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}},function(t,e){function n(e,r){return t.exports=n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(e,r)}t.exports=n},function(t,e){function n(e){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?t.exports=n=function(t){return typeof t}:t.exports=n=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(e)}t.exports=n},function(t,e){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}},function(t,e,n){"use strict";n.r(e),n.d(e,"Region",(function(){return N})),n.d(e,"TrackHighlighter",(function(){return P})),n.d(e,"ColorScaleParser",(function(){return R})),n.d(e,"String2Object",(function(){return C})),n.d(e,"ScrollFilter",(function(){return F})),n.d(e,"withMargin",(function(){return I}));var r=n(7),i=n.n(r),o=n(0),l=n.n(o),a=n(1),u=n.n(a),c=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.min,r=void 0===n?-1/0:n,i=e.max,o=void 0===i?1/0:i;l()(this,t),this.segments=[],this.max=o,this.min=r,this.regionString=null}return u()(t,[{key:"encode",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.segments.map((function(n){var r=n.start,i=n.end,o=n.color;if(e)return"".concat(r,":").concat(i).concat(o?":".concat(o):"");var l=r===t.min?"":r,a=i===t.max?"":i;return"".concat(l,":").concat(a).concat(o?":".concat(o):"")})).join(",")}},{key:"decode",value:function(t){var e=this;void 0!==t&&(this.regionString=t),this.regionString?this.segments=this.regionString.split(",").map((function(t){var n=t.split(":"),r=i()(n,4),o=r[0],l=r[1],a=r[2];if(void 0!==r[3])throw new Error("there should be at most 2 ':' per region. Region: ".concat(t));var u=o?Number(o):e.min,c=l?Number(l):e.max,s=""!==a?a:void 0;if(u>c){var h=[c,u];u=h[0],c=h[1]}if(u<e.min&&(u=e.min),c>e.max&&(c=e.max),Number.isNaN(u))throw new Error("The parsed value of ".concat(o," is NaN. Region: ").concat(t));if(Number.isNaN(c))throw new Error("The parsed value of ".concat(l," is NaN. Region: ").concat(t));if(s&&!s.match(/^#[0-9a-f]{6,8}$/i))throw new Error("The parsed value of ".concat(a," is not a color in hex format. Region: ").concat(t));return{start:u,end:c,color:s}})):this.segments=[]}}]),t}(),s=function(t,e){return t?e?"".concat(t,",").concat(e):t:e},h=function(){function t(e){var n=e.element,r=e.min,i=e.max;l()(this,t),this.element=n,this.element._highlightcolor="#FFEB3B66",this.region=new c({min:r,max:i}),this.fixedHighlight=null}return u()(t,[{key:"setAttributesInElement",value:function(){this.region.decode(this.element.getAttribute("highlight")),0===this.region.segments.length&&(this.element._highlightstart=Number(this.element.getAttribute("highlightstart")),this.element._highlightend=Number(this.element.getAttribute("highlightend")),this.element._highlightcolor=this.element.getAttribute("highlightcolor")||"#FFEB3B66",null!==this.element._highlightstart&&null!==this.element._highlightend&&"number"==typeof this.element._highlightstart&&"number"==typeof this.element._highlightend&&(this.element._highlight="".concat(this.element._highlightstart,":").concat(this.element._highlightend),this.region.decode(s(this.fixedHighlight,this.element._highlight))))}},{key:"setFloatAttribute",value:function(t,e){var n=parseFloat(e);this.element["_".concat(t)]=Number.isNaN(n)?e:n}},{key:"changedCallBack",value:function(t,e){switch(t){case"highlightstart":case"highlightend":this.setFloatAttribute(t,e),this.element._highlight=Number.isNaN(this.element._highlightstart)||Number.isNaN(this.element._highlightend)||void 0===this.element._highlightstart||void 0===this.element._highlightend||null===this.element._highlightstart||null===this.element._highlightend?"":"".concat(Math.max(this.region.min,this.element._highlightstart),":").concat(Math.min(this.region.max,this.element._highlightend));break;default:this.element._highlight=e}this.region.decode(s(this.fixedHighlight,this.element._highlight)),this.element.refresh()}},{key:"setFixedHighlight",value:function(t){this.fixedHighlight=t,this.region.decode(s(t,this.element._highlight)),this.element.refresh()}},{key:"appendHighlightTo",value:function(t){this.highlighted=t.append("g").attr("class","highlighted")}},{key:"updateHighlight",value:function(){var t=this,e=this.highlighted.selectAll("rect").data(this.region.segments);e.enter().append("rect").style("pointer-events","none").merge(e).attr("fill",(function(e){return e.color?e.color:t.element._highlightcolor})).attr("height",this.element._height).attr("x",(function(e){return t.element.getXFromSeqPosition(e.start)})).attr("width",(function(e){return t.element.getSingleBaseWidth()*(e.end-e.start+1)})),e.exit().remove()}},{key:"max",set:function(t){this.region.max=t}}]),t}();function f(t){var e=document.createElement("div");return e.style.borderColor="",e.style.borderColor=t,""!==e.style.borderColor}var g=function(t){return t},m=function(){function t(e){l()(this,t),this.element=e,this.timeStampWheelOutside=0,this.resetScrollableTimeout=null}return u()(t,[{key:"setElementScrollable",value:function(t){this.element.setAttribute("scrollable",t)}},{key:"startResetScrollableTimer",value:function(){var t=this;this.resetScrollableTimeout&&clearTimeout(this.resetScrollableTimeout),this.resetScrollableTimeout=setTimeout((function(){t.setElementScrollable(!0),t.resetScrollableTimeout=null}),400)}},{key:"blockScroll",value:function(t){this.timeStampWheelOutside=t,this.setElementScrollable(!1),this.startResetScrollableTimer()}},{key:"isWheelEventInsideElement",value:function(t,e){var n=this.element.getBoundingClientRect(),r=n.height,i=n.width,o=n.x,l=n.y;return t>o&&e<o+i&&e>l&&e<l+r}},{key:"wheel",value:function(t){var e=t.x,n=t.y,r=t.timeStamp;this.isWheelEventInsideElement(e,n)?r<this.timeStampWheelOutside+400?this.blockScroll(r):this.setElementScrollable(!0):this.blockScroll(r)}}]),t}(),p=n(3),d=n.n(p),b=n(4),y=n.n(b),v=n(8),x=n.n(v),S=n(9),w=n.n(S),_=n(2),j=n.n(_);function E(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return O(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return O(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,a=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return l=t.done,t},e:function(t){a=!0,o=t},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw o}}}}function O(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function k(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=j()(t);if(e){var i=j()(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return w()(this,n)}}var A=["left","right","top","bottom"],T=A.map((function(t){return"margin".concat(t)})),N=c,P=h,R=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=[],n=[];if(null!==t&&"string"!=typeof t)throw new Error("The attribute text has to be of type string");if(t&&""!==t.trim()){var r=t.split(",").map((function(t){return t.split(":")}));if(r.length<2)throw new Error("There should be at least 2 points to create a scale");e=r.map((function(t){var e=t[0].trim().toUpperCase();if(!f(e))throw new Error("The color '".concat(e," is not valid'"));return e})),n=r.map((function(t,e){var n=parseFloat(t[1]);if(Number.isNaN(n))throw new Error("The second part of every point should be a number. Error in point ".concat(e,": ").concat(t));return n}))}return{range:e,domain:n}},C=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.keyFormatter,r=void 0===n?g:n,i=e.valueFormatter,o=void 0===i?g:i;if(null!==t&&"string"!=typeof t)throw new Error("The attribute text has to be of type string");if(t&&""!==t.trim()){var l=t.split(",").map((function(t){return t.split(":")})),a={};return l.forEach((function(t){if(2!==t.length)throw new Error("Bad block: ".concat(t.join(":"),"\n The blocks of the string should follow the format KEY:VALUE"));a[r(t[0])]=o(t[1])})),a}return{}},F=m,I=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{initialValue:{top:0,bottom:0,left:0,right:0}},r=function(t){x()(r,t);var e=k(r);function r(){var t;return l()(this,r),(t=e.call(this)).margin=n.initialValue,t}return u()(r,[{key:"attributeChangedCallback",value:function(t,e,n){e!==n&&T.includes(t)&&(this[t]=n),y()(j()(r.prototype),"attributeChangedCallback",this).call(this,t,e,n)}}],[{key:"observedAttributes",get:function(){return[].concat(d()(y()(j()(r),"observedAttributes",this)),d()(T))}}]),r}(t),i=E(A);try{var o=function(){var t=e.value;Object.defineProperty(r.prototype,"margin".concat(t),{get:function(){return this.margin[t]||0},set:function(e){this.margin[t]=+e}})};for(i.s();!(e=i.n()).done;)o()}catch(t){i.e(t)}finally{i.f()}return r}}])})); | ||
//# sourceMappingURL=protvista-utils.js.map |
{ | ||
"name": "protvista-utils", | ||
"version": "3.0.0", | ||
"version": "3.2.13", | ||
"description": "Collection of utilities for ProtVista components", | ||
@@ -29,3 +29,3 @@ "files": [ | ||
"license": "ISC", | ||
"gitHead": "750856a787e184ab73d6677d5cef2d64fbf918e1" | ||
"gitHead": "563f7872ea6e92d7dc343cadcc7c4ed887c39d80" | ||
} |
@@ -11,7 +11,7 @@ export default class Region { | ||
return this.segments | ||
.map(({ start, end }) => { | ||
if (full) return `${start}:${end}`; | ||
.map(({ start, end, color }) => { | ||
if (full) return `${start}:${end}${color ? `:${color}` : ""}`; | ||
const s = start === this.min ? "" : start; | ||
const e = end === this.max ? "" : end; | ||
return `${s}:${e}`; | ||
return `${s}:${e}${color ? `:${color}` : ""}`; | ||
}) | ||
@@ -27,10 +27,11 @@ .join(","); | ||
} | ||
this.segments = this.regionString.split(",").map(region => { | ||
const [_start, _end, _] = region.split(":"); | ||
this.segments = this.regionString.split(",").map((region) => { | ||
const [_start, _end, _color, _] = region.split(":"); | ||
if (typeof _ !== "undefined") | ||
throw new Error( | ||
`there should be at most 1 ':' per region. Region: ${region}` | ||
`there should be at most 2 ':' per region. Region: ${region}` | ||
); | ||
let start = _start ? Number(_start) : this.min; | ||
let end = _end ? Number(_end) : this.max; | ||
const color = _color !== "" ? _color : undefined; | ||
if (start > end) [start, end] = [end, start]; | ||
@@ -47,5 +48,11 @@ if (start < this.min) start = this.min; | ||
); | ||
if (color && !color.match(/^#[0-9a-f]{6,8}$/i)) | ||
throw new Error( | ||
`The parsed value of ${_color} is not a color in hex format. Region: ${region}` | ||
); | ||
return { | ||
start, | ||
end | ||
end, | ||
color, | ||
}; | ||
@@ -52,0 +59,0 @@ }); |
@@ -19,2 +19,10 @@ /* eslint-disable no-empty */ | ||
}); | ||
test("encode whole region with default color", () => { | ||
const region = new Region(); | ||
region.decode("::"); | ||
expect(region.segments).toMatchSnapshot(); | ||
expect(region.encode(true)).toEqual("-Infinity:Infinity"); | ||
expect(region.encode(false)).toEqual(":"); | ||
}); | ||
test("encode simple region", () => { | ||
@@ -27,2 +35,23 @@ const region = new Region(); | ||
}); | ||
test("encode simple region with color", () => { | ||
const region = new Region(); | ||
region.decode("2:10:#00EE55"); | ||
expect(region.segments).toMatchSnapshot(); | ||
expect(region.encode(true)).toEqual("2:10:#00EE55"); | ||
expect(region.encode(false)).toEqual("2:10:#00EE55"); | ||
}); | ||
test("encode simple region with color alpha", () => { | ||
const region = new Region(); | ||
region.decode("2:10:#00EE55A0"); | ||
expect(region.segments).toMatchSnapshot(); | ||
expect(region.encode(true)).toEqual("2:10:#00EE55A0"); | ||
expect(region.encode(false)).toEqual("2:10:#00EE55A0"); | ||
}); | ||
test("encode whole region with color", () => { | ||
const region = new Region(); | ||
region.decode("::#00EE55"); | ||
expect(region.segments).toMatchSnapshot(); | ||
expect(region.encode(true)).toEqual("-Infinity:Infinity:#00EE55"); | ||
expect(region.encode(false)).toEqual("::#00EE55"); | ||
}); | ||
test("encode multiple region", () => { | ||
@@ -33,5 +62,16 @@ const region = new Region({ min: 1, max: 100 }); | ||
expect(region.segments).toMatchSnapshot(); | ||
expect(region.encode(true)).toEqual(txt); | ||
expect(region.encode(true)).toEqual("1:5,10:20,30:50,50:100"); | ||
expect(region.encode()).toEqual(":5,10:20,30:50,50:"); | ||
}); | ||
test("encode multiple region with color", () => { | ||
const region = new Region({ min: 1, max: 100 }); | ||
const txt = "1:5:#00EE55,10:20,30:50:#00E800AA,50:100"; | ||
region.decode(txt); | ||
expect(region.segments).toMatchSnapshot(); | ||
expect(region.encode(true)).toEqual( | ||
"1:5:#00EE55,10:20,30:50:#00E800AA,50:100" | ||
); | ||
expect(region.encode()).toEqual(":5:#00EE55,10:20,30:50:#00E800AA,50:"); | ||
}); | ||
test("encode multiple and complex region", () => { | ||
@@ -44,2 +84,14 @@ const region = new Region({ min: 1, max: 100 }); | ||
}); | ||
test("encode multiple and complex region with color", () => { | ||
const region = new Region({ min: 1, max: 100 }); | ||
region.decode("::#00EE55,:20:#00E800AA,30::#00EE55,50:100,,0:200"); | ||
expect(region.segments).toMatchSnapshot(); | ||
expect(region.encode(true)).toEqual( | ||
"1:100:#00EE55,1:20:#00E800AA,30:100:#00EE55,50:100,1:100,1:100" | ||
); | ||
expect(region.encode()).toEqual( | ||
"::#00EE55,:20:#00E800AA,30::#00EE55,50:,:,:" | ||
); | ||
}); | ||
}); | ||
@@ -53,2 +105,3 @@ | ||
expect(region.min).toEqual(-Infinity); | ||
expect(region.color).toEqual(undefined); | ||
@@ -69,4 +122,14 @@ region.decode(null); | ||
expect(region.segments[0].end).toEqual(5); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
}); | ||
test("decode simple region with color", () => { | ||
const region = new Region(); | ||
region.decode("1:5:#AAAAAA"); | ||
expect(region.segments.length).toEqual(1); | ||
expect(region.segments[0].start).toEqual(1); | ||
expect(region.segments[0].end).toEqual(5); | ||
expect(region.segments[0].color).toEqual("#AAAAAA"); | ||
}); | ||
test("decode multiple region", () => { | ||
@@ -78,6 +141,20 @@ const region = new Region(); | ||
expect(region.segments[0].end).toEqual(5); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
expect(region.segments[1].start).toEqual(10); | ||
expect(region.segments[1].end).toEqual(15); | ||
expect(region.segments[1].color).toEqual(undefined); | ||
}); | ||
test("decode multiple region with color", () => { | ||
const region = new Region(); | ||
region.decode("1:5:#AAAAAA,10:15:#AAAAAA00"); | ||
expect(region.segments.length).toEqual(2); | ||
expect(region.segments[0].start).toEqual(1); | ||
expect(region.segments[0].end).toEqual(5); | ||
expect(region.segments[0].color).toEqual("#AAAAAA"); | ||
expect(region.segments[1].start).toEqual(10); | ||
expect(region.segments[1].end).toEqual(15); | ||
expect(region.segments[1].color).toEqual("#AAAAAA00"); | ||
}); | ||
test("decode region missing start and not initialised min", () => { | ||
@@ -89,2 +166,3 @@ const region = new Region(); | ||
expect(region.segments[0].end).toEqual(5); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
}); | ||
@@ -98,2 +176,3 @@ | ||
expect(region.segments[0].end).toEqual(Infinity); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
@@ -104,2 +183,3 @@ region.decode("1"); | ||
expect(region.segments[0].end).toEqual(Infinity); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
}); | ||
@@ -113,2 +193,3 @@ | ||
expect(region.segments[0].end).toEqual(5); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
}); | ||
@@ -122,2 +203,3 @@ | ||
expect(region.segments[0].end).toEqual(10); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
@@ -128,2 +210,3 @@ region.decode("1"); | ||
expect(region.segments[0].end).toEqual(10); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
}); | ||
@@ -137,4 +220,14 @@ | ||
expect(region.segments[0].end).toEqual(5); | ||
expect(region.segments[0].color).toEqual(undefined); | ||
}); | ||
test("decode region with inverted values with color", () => { | ||
const region = new Region(); | ||
region.decode("5:1:#000000"); | ||
expect(region.segments.length).toEqual(1); | ||
expect(region.segments[0].start).toEqual(1); | ||
expect(region.segments[0].end).toEqual(5); | ||
expect(region.segments[0].color).toEqual("#000000"); | ||
}); | ||
test("Fails decoding because of non-numeric chars", () => { | ||
@@ -156,9 +249,33 @@ const region = new Region(); | ||
test("Fails decoding because there should be at most 1 ':' per region", () => { | ||
test("Fails decoding because there should be at most 2 ':' per region", () => { | ||
const region = new Region(); | ||
try { | ||
region.decode("1:3:4"); | ||
region.decode("1:3:#000000:5"); | ||
fail("The decoding should fails"); | ||
} catch (e) {} | ||
}); | ||
test("Fails decoding because of wrong color format", () => { | ||
const region = new Region(); | ||
try { | ||
region.decode("2:10:#00ET5S"); | ||
fail("The decoding should fails"); | ||
} catch (e) {} | ||
try { | ||
region.decode("2:10:#000000000"); | ||
fail("The decoding should fails"); | ||
} catch (e) {} | ||
try { | ||
region.decode("2:10:aeghh"); | ||
fail("The decoding should fails"); | ||
} catch (e) {} | ||
try { | ||
region.decode("::dggS"); | ||
fail("The decoding should fails"); | ||
} catch (e) {} | ||
try { | ||
region.decode("::#000000II"); | ||
fail("The decoding should fails"); | ||
} catch (e) {} | ||
}); | ||
}); |
import Region from "./Region"; | ||
const DEFAULT_HIGLIGHT_COLOR = "#FFEB3B66"; | ||
const combineRegions = (region1, region2) => { | ||
@@ -11,2 +13,3 @@ if (!region1) return region2; | ||
this.element = element; | ||
this.element._highlightcolor = DEFAULT_HIGLIGHT_COLOR; | ||
this.region = new Region({ min, max }); | ||
@@ -29,2 +32,4 @@ this.fixedHighlight = null; | ||
); | ||
this.element._highlightcolor = | ||
this.element.getAttribute("highlightcolor") || DEFAULT_HIGLIGHT_COLOR; | ||
if ( | ||
@@ -93,11 +98,10 @@ this.element._highlightstart !== null && | ||
.append("rect") | ||
.style("opacity", 0.5) | ||
.attr("fill", "rgba(255, 235, 59, 0.8)") | ||
.style("pointer-events", "none") | ||
.merge(highlighs) | ||
.attr("fill", (d) => (d.color ? d.color : this.element._highlightcolor)) | ||
.attr("height", this.element._height) | ||
.attr("x", d => this.element.getXFromSeqPosition(d.start)) | ||
.attr("x", (d) => this.element.getXFromSeqPosition(d.start)) | ||
.attr( | ||
"width", | ||
d => this.element.getSingleBaseWidth() * (d.end - d.start + 1) | ||
(d) => this.element.getSingleBaseWidth() * (d.end - d.start + 1) | ||
); | ||
@@ -104,0 +108,0 @@ highlighs.exit().remove(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80738
731