auspice
Version:
Web app for visualizing pathogen evolution
1 lines • 13.3 kB
JavaScript
(self.webpackChunkauspice=self.webpackChunkauspice||[]).push([[601],{4601:(t,e,n)=>{"use strict";n.r(e),n.d(e,{default:()=>L});var r=n(82684),o=n(26439),i=n(1326),a=(n(2955),n(4667)),s=n(87899),c=n(72394),l=n(30600),u=n(59352),p=n(84055),f=n(74001),y=n(76367),h=n(48167),d=n(1608),v=n(14179),m=n(59995),g=n(12225),b=n(58640),x=n(92779),w=n(88982);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}var j=function(t,e){if(e&&e[t])return e[t].title;if((0,g.O$)(t)){var n=(0,g.kW)(t);return n.aa?"Genotype at ".concat(n.gene," pos ").concat(n.positions.join(", ")):"Genotype at Nuc. ".concat(n.positions.join(", "))}return t},k=function(t,e,n){return e<n?t?"and normalized to 100% at each time point for ".concat(e," out of a total of ").concat(n," tips"):"as a fraction of all sequences at each time point showing ".concat(e," out of a total of ").concat(n," tips"):""},S=function(t,e){return{y:(0,l.Z)().domain([0,e]).range([t.height-t.spaceBottom,t.spaceTop]),numTicksY:5}},P=function(t,e,n){!function(t){t.selectAll(".y.axis").remove()}(t);var r=(0,d.WU)(".0%");t.append("g").attr("class","y axis").attr("transform","translate(".concat(e.spaceLeft,",0)")).style("font-family",v.kU).style("font-size","12px").call((0,u.y4)(n.y).ticks(n.numTicksY).tickFormat(r))},A=function(t,e,n,r){if(n){!function(t){t.selectAll(".projection-pivot").remove(),t.selectAll(".projection-text").remove()}(t),t.append("g").attr("class","projection-pivot").append("line").attr("x1",e.x(parseFloat(n))).attr("x2",e.x(parseFloat(n))).attr("y1",e.y(1)).attr("y2",e.y(0)).style("visibility","visible").style("stroke","rgba(55,55,55,0.9)").style("stroke-width","2").style("stroke-dasharray","4 4");var o=.5*(e.x(parseFloat(n))+e.x.range()[1]);t.append("g").attr("class","projection-text").append("text").attr("x",o).attr("y",e.y(1)-3).style("pointer-events","none").style("fill","#555").style("font-family",v.kU).style("font-size",12).style("alignment-baseline","bottom").style("text-anchor","middle").text(r("Projection"))}};function E(){(0,i.Z)(this).attr("opacity",1)}function R(){(0,i.Z)(this).attr("opacity",.85),(0,i.Z)("#freqinfo").style("visibility","hidden"),(0,i.Z)("#vline").style("visibility","hidden")}var Z,q=function(t){var e=t.matrix,n=t.pivots,r=t.colorScale,o=function(t,e){for(var n=e.legendValues.filter((function(t){return void 0!==t})).reverse().map((function(t){return t.toString()})),r=n.length-1;r>=0;--r)-1===t.indexOf(n[r])&&n.splice(r,1);return t.length>n.length&&t.forEach((function(t){-1===n.indexOf(t)&&n.push(t)})),n}(Array.from(e.keys()),r),i=function(t,e,n){for(var r=[],o=0;o<t.length;o++){for(var i=[],a=0;a<e;a++)if(0===o)i.push([0,n.get(t[o])[a]]);else{var s=r[o-1][a][1];i.push([s,n.get(t[o])[a]+s])}r.push(i)}return r}(o,n.length,e),a=function(t){return t[t.length-1].reduce((function(t,e){return Math.max(t,e[1])}),0)}(i);return{categories:o,series:i,maxY:a}},B=function(t,e,n,r){var o,a=n.categories,s=n.series,l=r.colorBy,u=r.colorScale,p=r.colorOptions,f=r.pivots,d=r.projection_pivot,g=r.t;(o=t).selectAll("path").remove(),o.selectAll("line").remove(),o.selectAll("text").remove();var x=function(t,e){return function(n,r){return t[r]===m.Zi?"#ADB1B3":(0,y.B8)(e.scale(t[r])).toString()}}(a,u),k=function(t,e){return e.continuous?t.map((function(t){var n;return t===m.Zi?m.Zi:null!==(n=e.legendLabels)&&void 0!==n&&n.has(t)?e.legendLabels.get(t):(0,w.BI)(e.legendBounds[t],"num_date"===e.colorBy)})):t.slice()}(a,u),S=(0,h.Z)().x((function(t,n){return e.x(f[n])})).y0((function(t){return e.y(t[0])})).y1((function(t){return e.y(t[1])}));t.selectAll(".stream").data(s).enter().append("path").attr("d",S).attr("fill",x).attr("opacity",.85).on("mouseover",E).on("mouseout",R).on("mousemove",(function(t,n){var r=function(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,o,i=[],a=!0,s=!1;try{for(n=n.call(t);!(a=(r=n.next()).done)&&(i.push(r.value),!e||i.length!==e);a=!0);}catch(t){s=!0,o=t}finally{try{a||null==n.return||n.return()}finally{if(s)throw o}}return i}}(t,e)||function(t,e){if(t){if("string"==typeof t)return O(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)?O(t,e):void 0}}(t,e)||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.")}()}((0,c.Z)(this),1)[0],o=e.x.invert(r),a=f.reduce((function(t,e,n,r){return Math.abs(e-o)<Math.abs(r[t]-o)?n:t}),0),s=100*(t[a][1]-t[a][0]),u=s<1?"<1%":Math.round(s)+"%",y=e.x(f[a]),h=e.y(t[a][1]),m=e.y(t[a][0]);(0,i.Z)("#vline").style("visibility","visible").attr("x1",y).attr("x2",y).attr("y1",h).attr("y2",m);var x=y>.5*e.x.range()[1]?"":"".concat(y+25,"px"),w=y>.5*e.x.range()[1]?"".concat(e.x.range()[1]-y+25,"px"):"",S=h>.5*e.y(0)?"".concat(e.y(0)-50,"px"):"".concat(h+25,"px"),P=g("Frequency");d&&f[a]>d&&(P=g("Projected frequency")),(0,i.Z)("#freqinfo").style("left",x).style("right",w).style("top",S).style("padding-left","10px").style("padding-right","10px").style("padding-top","0px").style("padding-bottom","0px").style("visibility","visible").style("background-color","rgba(55,55,55,0.9)").style("color","white").style("font-family",v.kU).style("font-size",18).style("line-height",1).style("font-weight",300).html("<p>".concat(j(l,p),": ").concat(k[n],"</p>\n <p>").concat(g("Time point"),": ").concat((0,b.hT)(f[a]),"</p>\n <p>").concat(P,": ").concat(u,"</p>"))})),t.append("line").attr("id","vline").style("visibility","hidden").style("pointer-events","none").style("stroke","rgba(55,55,55,0.9)").style("stroke-width",4),function(t,e,n,r,o){var i=function(t,e,n,r){return t.map((function(t){for(var r=.15*n.y.domain()[1],o=0;o<t.length-3;o++){var i=o+3;if(t[o][1]-t[o][0]>r&&t[i][1]-t[i][0]>r)return[n.x(e[o+1]),(n.y((t[o][1]+t[o][0])/2)+n.y((t[i][1]+t[i][0])/2))/2]}return[void 0,void 0]}))}(e,n,o);t.selectAll(".streamLabels").data(r).enter().append("text").attr("x",(function(t,e){return i[e][0]})).attr("y",(function(t,e){return i[e][1]})).style("pointer-events","none").style("fill","white").style("font-family",v.kU).style("font-size",14).style("alignment-baseline","middle").text((function(t,e){return i[e][0]?t:""}))}(t,s,f,k,e)};function _(t){return _="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_(t)}function z(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function G(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?z(Object(n),!0).forEach((function(e){T(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):z(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function T(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function Y(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)}}function C(t,e){return C=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},C(t,e)}function D(t){return D=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},D(t)}n(61812);var F=(0,a.$j)((function(t){return{data:t.frequencies.data,pivots:t.frequencies.pivots,matrix:t.frequencies.matrix,nodes:t.tree.nodes,projection_pivot:t.frequencies.projection_pivot,version:t.frequencies.version,browserDimensions:t.browserDimensions.browserDimensions,colorBy:t.controls.colorBy,colorScale:t.controls.colorScale,colorOptions:t.metadata.colorings,normalizeFrequencies:t.controls.normalizeFrequencies,showOnlyPanels:t.controls.showOnlyPanels}}))(Z=function(t){!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&&C(t,e)}(y,t);var e,n,o,a,c=(o=y,a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}(),function(){var t,e=D(o);if(a){var n=D(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return function(t,e){if(e&&("object"===_(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(this,t)});function y(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,y),(e=c.call(this,t)).state={maxY:0},e}return e=y,(n=[{key:"calcChartGeom",value:function(t,e){return{width:t,height:e,spaceLeft:40,spaceRight:10,spaceBottom:20,spaceTop:10}}},{key:"recomputeRedrawAll",value:function(t,e){var n=this.calcChartGeom(e.width,e.height),r=q(G({},e));t.maxY=r.maxY,t.categories=r.categories;var o=function(t,e){return{x:(0,l.Z)().domain([e[0],e[e.length-1]]).range([t.spaceLeft,t.width-t.spaceRight])}}(n,e.pivots),i=S(n,r.maxY);t.scales=G(G({},o),i),function(t,e,n){var r=n.x.domain(),o=n.x.range(),i=(0,x.Rw)((0,p.Z)(r),(0,f.Z)(r),o[1]-o[0]).majorGridPoints;!function(t){t.selectAll(".x.axis").remove()}(t),t.append("g").attr("class","x axis").attr("transform","translate(0,".concat(e.height-e.spaceBottom,")")).style("font-family",v.kU).style("font-size","12px").call((0,u.LL)(n.x).tickValues(i.map((function(t){return t.position}))).tickFormat((function(t,e){return i[e].name})))}(t.svg,n,o),P(t.svg,n,i),B(t.svgStreamGroup,t.scales,r,G({},e)),A(t.svg,t.scales,e.projection_pivot,e.t)}},{key:"recomputeRedrawPartial",value:function(t,e,n){var r,o=q(G({},n)),i=t.maxY!==o.maxY,a=this.calcChartGeom(n.width,n.height);if(i){var s=S(a,o.maxY);P(t.svg,a,s),r=G(G({},t.scales),s)}else r=G({},t.scales);return B(t.svgStreamGroup,r,o,G({},n)),i&&A(t.svg,r,n.projection_pivot,n.t),G(G({},t),{},{scales:r,maxY:o.maxY,categories:o.categories})}},{key:"componentDidMount",value:function(){var t=(0,i.Z)(this.domRef),e=t.append("g"),n={svg:t,svgStreamGroup:e};this.props.matrix&&this.recomputeRedrawAll(n,this.props),this.setState(n)}},{key:"UNSAFE_componentWillReceiveProps",value:function(t){if(this.props.version===t.version);else if(!this.props.loaded&&t.loaded){var e=G({},this.state);this.recomputeRedrawAll(e,t),this.setState(e)}else{var n=this.recomputeRedrawPartial(this.state,this.props,t);n&&this.setState(n)}}},{key:"componentDidUpdate",value:function(t){if(t.width!==this.props.width||t.height!==this.props.height){var e=G({},this.state);this.recomputeRedrawAll(e,this.props),this.setState(e)}}},{key:"render",value:function(){var t=this,e=this.props.t,n=this.props.nodes[0],o=n.tipCount,i=n.fullTipCount;return r.createElement(s.Z,{infocard:this.props.showOnlyPanels,title:"".concat(e("Frequencies")," (").concat(e("colored by")," ").concat(j(this.props.colorBy,this.props.colorOptions)," ").concat(e(k(this.props.normalizeFrequencies,o,i)),")")},r.createElement("div",{id:"freqinfo",style:{zIndex:20,position:"absolute",borderRadius:"5px",padding:"10px",backgroundColor:"hsla(0,0%,100%,.9)",pointerEvents:"none",visibility:"hidden",fontSize:"14px"}}),r.createElement("svg",{id:"d3frequenciesSVG",width:this.props.width,height:this.props.height,style:{pointerEvents:"auto",overflow:"visible"}},r.createElement("g",null,r.createElement("g",null,r.createElement("g",null,r.createElement("g",null,r.createElement("g",{ref:function(e){t.domRef=e},id:"d3frequencies"})))))))}}])&&Y(e.prototype,n),y}(r.Component))||Z;const L=(0,o.Z)()(F)},63664:(t,e,n)=>{(e=n(55788)(!1)).push([t.id,'\n/* Variables - keep in sync with globalStyles.js*/\n:root {\n --darkGrey: #333;\n --medGrey: #888;\n}\n\n/* Normally elements with .overlay are children of the .brush, however\nthe overlay added on key-presses is is not a child of .brush */\n#d3entropy .overlay {\n fill: none;\n pointer-events: all;\n}\n\n#d3entropy .niceText {\n font-family: "Lato", "Helvetica Neue", "Helvetica", "sans-serif";\n font-size: 14px;\n font-style: italic;\n color: var(--medGrey);\n}\n\n.brush .selection {\n cursor: grab;\n cursor: -moz-grab;\n cursor: -webkit-grab;\n}\n\n#d3entropy .cdsText {\n pointer-events: none;\n}\n#d3entropy .cds {\n cursor: pointer;\n}\n\ntable.entropy-table {\n font-weight: 300;\n}\n\ntable.entropy-table td {\n padding-bottom: 3px;\n padding-right: 5px;\n}',""]),t.exports=e},61812:(t,e,n)=>{var r=n(63664);"string"==typeof r&&(r=[[t.id,r,""]]),n(14246)(r,{}),r.locals&&(t.exports=r.locals)}}]);