text: /*! Locuszoom 0.13.0-beta.4 */
  var LzIntervalsTrack=function(t){var e={};function a(r){if(e[r])return e[r].exports;var s=e[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,a),s.l=!0,s.exports}return a.m=t,a.c=e,a.d=function(t,e,r){a.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)a.d(r,s,function(e){return t[e]}.bind(null,s));return r},a.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(e,"a",e),e},a.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},a.p="",a(a.s=8)}({0:function(t,e){t.exports=d3},8:function(t,e,a){"use strict";a.r(e);var r=a(0);const s=Symbol.for("lzXCS"),i=Symbol.for("lzYCS"),n=Symbol.for("lzXCE"),l=Symbol.for("lzYCE");function o(t){const e=t.Adapters.get("BaseApiAdapter"),a=t.Widgets.get("_Button"),o=t.Widgets.get("BaseWidget");const c={start_field:"start",end_field:"end",track_label_field:"state_name",track_split_field:"state_id",track_split_order:"DESC",track_split_legend_to_y_axis:2,split_tracks:!0,track_height:15,track_vertical_spacing:3,bounding_box_padding:2,always_hide_legend:!1,color:"#B8B8B8",fill_opacity:1,tooltip_positioning:"vertical"},d=t.DataLayers.get("BaseDataLayer");const g={namespace:{intervals:"intervals"},closable:!1,show:{or:["highlighted","selected"]},hide:{and:["unhighlighted","unselected"]},html:"{{{{namespace[intervals]}}state_name|htmlescape}}<br>{{{{namespace[intervals]}}start|htmlescape}}-{{{{namespace[intervals]}}end|htmlescape}}"},u={namespace:{intervals:"intervals"},id:"intervals",type:"intervals",fields:["{{namespace[intervals]}}start","{{namespace[intervals]}}end","{{namespace[intervals]}}state_id","{{namespace[intervals]}}state_name","{{namespace[intervals]}}itemRgb"],id_field:"{{namespace[intervals]}}start",start_field:"{{namespace[intervals]}}start",end_field:"{{namespace[intervals]}}end",track_split_field:"{{namespace[intervals]}}state_name",track_label_field:"{{namespace[intervals]}}state_name",split_tracks:!1,always_hide_legend:!0,color:[{field:"{{namespace[intervals]}}itemRgb",scale_function:"to_rgb"},{field:"{{namespace[intervals]}}state_name",scale_function:"categorical_bin",parameters:{categories:[],values:[],null_value:"#B8B8B8"}}],legend:[],behaviors:{onmouseover:[{action:"set",status:"highlighted"}],onmouseout:[{action:"unset",status:"highlighted"}],onclick:[{action:"toggle",status:"selected",exclusive:!0}],onshiftclick:[{action:"toggle",status:"selected"}]},tooltip:g},_={id:"intervals",min_height:50,height:50,margin:{top:25,right:150,bottom:5,left:50},toolbar:function(){const e=t.Layouts.get("toolbar","standard_panel",{unnamespaced:!0});return e.widgets.push({type:"toggle_split_tracks",data_layer_id:"intervals",position:"right"}),e}(),axes:{},interaction:{drag_background_to_pan:!0,scroll_to_zoom:!0,x_linked:!0},legend:{hidden:!0,orientation:"horizontal",origin:{x:50,y:0},pad_from_bottom:5},data_layers:[u]},h={state:{},width:800,responsive_resize:!0,min_region_scale:2e4,max_region_scale:1e6,toolbar:t.Layouts.get("toolbar","standard_association",{unnamespaced:!0}),panels:[t.Layouts.get("panel","association"),t.Layouts.merge({unnamespaced:!0,min_height:120,height:120},_),t.Layouts.get("panel","genes")]};t.Adapters.add("IntervalLZ",class extends e{getURL(t,e,a){const r=`?filter=id in ${e.header.bedtracksource||this.params.source} and chromosome eq '${t.chr}' and start le ${t.end} and end ge ${t.start}`;return`${this.url}${r}`}}),t.DataLayers.add("intervals",class extends d{constructor(e){t.Layouts.merge(e,c),super(...arguments),this._previous_categories=[],this._categories=[]}initialize(){super.initialize(),this._statusnodes_group=this.svg.group.append("g").attr("class","lz-data-layer-intervals lz-data-layer-intervals-statusnode"),this._datanodes_group=this.svg.group.append("g").attr("class","lz-data_layer-intervals")}_arrangeTrackSplit(t){const{track_split_field:e}=this.layout,a={};return t.forEach(t=>{const r=t[e];Object.prototype.hasOwnProperty.call(a,r)||(a[r]=[]),a[r].push(t)}),a}_arrangeTracksLinear(t,e=!0){if(e)return[t];const{start_field:a,end_field:r}=this.layout,s=[[]];return t.forEach((t,e)=>{for(let e=0;e<s.length;e++){const i=s[e],n=i[i.length-1];if(!(n&&t[a]<n[r]&&n[a]<t[r]))return void i.push(t)}s.push([t])}),s}_assignTracks(t){const{x_scale:e}=this.parent,{start_field:a,end_field:r,bounding_box_padding:o,track_height:c}=this.layout,d=this.layout.split_tracks?this._arrangeTrackSplit(t):this._arrangeTracksLinear(t,!0),g=Object.keys(d);return"DESC"===this.layout.track_split_order&&g.reverse(),g.forEach((t,g)=>{d[t].forEach(t=>{t[s]=e(t[a]),t[n]=e(t[r]),t[i]=g*this.getTrackHeight()+o,t[l]=t[i]+c,t.track=g})}),[g,Object.values(d).reduce((t,e)=>t.concat(e),[])]}getElementStatusNodeId(t){if(this.layout.split_tracks){const e="object"==typeof t?t.track:t;return`${this.getBaseId()}-statusnode-${e}`.replace(/[^\w]/g,"_")}return null}getTrackHeight(){return this.layout.track_height+this.layout.track_vertical_spacing+2*this.layout.bounding_box_padding}_applyLayoutOptions(){const t=this,e=this._base_layout,a=this.layout,r=e.color.find((function(t){return t.scale_function&&"categorical_bin"===t.scale_function})),s=a.color.find((function(t){return t.scale_function&&"categorical_bin"===t.scale_function}));if(!r)throw new Error("Interval tracks must define a `categorical_bin` color scale");const i=r.parameters.categories.length&&r.parameters.values.length,n=e.legend&&e.legend.length;if(!!i^!!n)throw new Error("To use a manually specified color scheme, both color and legend options must be set.");const l=e.color.find((function(t){return t.scale_function&&"to_rgb"===t.scale_function})),o=l&&l.field,c=this._generateCategoriesFromData(this.data,o);if(!i&&!n){const e=this._makeColorScheme(c);s.parameters.categories=c.map((function(t){return t[0]})),s.parameters.values=e,this.layout.legend=c.map((function(e,a){const r=e[0],i={shape:"rect",width:9,label:e[1],color:s.parameters.values[a]};return i[t.layout.track_split_field]=r,i}))}}render(){this._applyLayoutOptions(),this._previous_categories=this._categories;const[t,e]=this._assignTracks(this.data);this._categories=t;if(!t.every((t,e)=>t===this._previous_categories[e]))return void this.updateSplitTrackAxis(t);const a=this._applyFilters(e);this._statusnodes_group.selectAll("rect").remove();const l=this._statusnodes_group.selectAll("rect").data(r.range(t.length));if(this.layout.split_tracks){const t=this.getTrackHeight();l.enter().append("rect").attr("class","lz-data_layer-intervals lz-data_layer-intervals-statusnode lz-data_layer-intervals-shared").attr("rx",this.layout.bounding_box_padding).attr("ry",this.layout.bounding_box_padding).merge(l).attr("id",t=>this.getElementStatusNodeId(t)).attr("x",0).attr("y",e=>e*t).attr("width",this.parent.layout.cliparea.width).attr("height",t-this.layout.track_vertical_spacing)}l.exit().remove();const o=this._datanodes_group.selectAll("rect").data(a,t=>t[this.layout.id_field]);o.enter().append("rect").merge(o).attr("id",t=>this.getElementId(t)).attr("x",t=>t[s]).attr("y",t=>t[i]).attr("width",t=>t[n]-t[s]).attr("height",this.layout.track_height).attr("fill",(t,e)=>this.resolveScalableParameter(this.layout.color,t,e)).attr("fill-opacity",(t,e)=>this.resolveScalableParameter(this.layout.fill_opacity,t,e)),o.exit().remove(),this._datanodes_group.call(this.applyBehaviors.bind(this)),this.parent&&this.parent.legend&&this.parent.legend.render()}_getTooltipPosition(t){return{x_min:t.data[s],x_max:t.data[n],y_min:t.data[i],y_max:t.data[l]}}updateSplitTrackAxis(t){const e=!!this.layout.track_split_legend_to_y_axis&&"y"+this.layout.track_split_legend_to_y_axis;if(this.layout.split_tracks){const a=+t.length||0,r=+this.layout.track_height||0,s=2*(+this.layout.bounding_box_padding||0)+(+this.layout.track_vertical_spacing||0),i=a*r+(a-1)*s;this.parent.scaleHeightToData(i),e&&this.parent.legend&&(this.parent.legend.hide(),this.parent.layout.axes[e]={render:!0,ticks:[],range:{start:i-this.layout.track_height/2,end:this.layout.track_height/2}},this.layout.legend.forEach(r=>{const s=r[this.layout.track_split_field];let i=t.findIndex(t=>t===s);-1!==i&&("DESC"===this.layout.track_split_order&&(i=Math.abs(i-a-1)),this.parent.layout.axes[e].ticks.push({y:i-1,text:r.label}))}),this.layout.y_axis={axis:this.layout.track_split_legend_to_y_axis,floor:1,ceiling:a}),this.parent_plot.positionPanels()}else e&&this.parent.legend&&(this.layout.always_hide_legend||this.parent.legend.show(),this.parent.layout.axes[e]={render:!1},this.parent.render());return this}toggleSplitTracks(){return this.layout.split_tracks=!this.layout.split_tracks,this.parent.legend&&!this.layout.always_hide_legend&&(this.parent.layout.margin.bottom=5+(this.layout.split_tracks?0:this.parent.legend.layout.height+5)),this.render(),this}_makeColorScheme(t){if(t.find(t=>t[2]))return t.map(t=>t[2]);const e=t.length;return e<=15?["rgb(212,212,212)","rgb(192,192,192)","rgb(128,128,128)","rgb(189,183,107)","rgb(233,150,122)","rgb(205,92,92)","rgb(138,145,208)","rgb(102,205,170)","rgb(255,255,0)","rgb(194,225,5)","rgb(0,100,0)","rgb(0,128,0)","rgb(50,205,50)","rgb(255,69,0)","rgb(255,0,0)"]:e<=18?["rgb(212,212,212)","rgb(192,192,192)","rgb(128,128,128)","rgb(189,183,107)","rgb(205,92,92)","rgb(138,145,208)","rgb(102,205,170)","rgb(255,255,0)","rgb(255,195,77)","rgb(255,195,77)","rgb(194,225,5)","rgb(194,225,5)","rgb(0,100,0)","rgb(0,128,0)","rgb(255,69,0)","rgb(255,69,0)","rgb(255,69,0)","rgb(255,0,0)"]:["rgb(212,212,212)","rgb(128,128,128)","rgb(112,48,160)","rgb(230,184,183)","rgb(138,145,208)","rgb(102,205,170)","rgb(255,255,102)","rgb(255,255,0)","rgb(255,255,0)","rgb(255,255,0)","rgb(255,195,77)","rgb(255,195,77)","rgb(255,195,77)","rgb(194,225,5)","rgb(194,225,5)","rgb(194,225,5)","rgb(194,225,5)","rgb(0,150,0)","rgb(0,128,0)","rgb(0,128,0)","rgb(0,128,0)","rgb(255,69,0)","rgb(255,69,0)","rgb(255,69,0)","rgb(255,0,0)"]}_generateCategoriesFromData(t,e){const a=this,r=this._base_layout.legend;if(r&&r.length)return r.map(t=>[t[this.layout.track_split_field],t.label,t.color]);const s={},i=[];return t.forEach(t=>{const r=t[a.layout.track_split_field];Object.prototype.hasOwnProperty.call(s,r)||(s[r]=null,i.push([r,t[this.layout.track_label_field],t[e]]))}),i}}),t.Layouts.add("tooltip","standard_intervals",g),t.Layouts.add("data_layer","intervals",u),t.Layouts.add("panel","intervals",_),t.Layouts.add("plot","interval_association",h),t.ScaleFunctions.add("to_rgb",(function(t,e){return e?`rgb(${e})`:null})),t.Widgets.add("toggle_split_tracks",class extends o{constructor(t){if(super(...arguments),t.data_layer_id||(t.data_layer_id="intervals"),!this.parent_panel.data_layers[t.data_layer_id])throw new Error("Toggle split tracks widget specifies an invalid data layer ID")}update(){const t=this.parent_panel.data_layers[this.layout.data_layer_id],e=t.layout.split_tracks?"Merge Tracks":"Split Tracks";return this.button?(this.button.setHtml(e),this.button.show(),this.parent.position(),this):(this.button=new a(this).setColor(this.layout.color).setHtml(e).setTitle("Toggle whether tracks are split apart or merged together").setOnclick(()=>{t.toggleSplitTracks(),this.scale_timeout&&clearTimeout(this.scale_timeout),this.scale_timeout=setTimeout(()=>{this.parent_panel.scaleHeightToData(),this.parent_plot.positionPanels()},0),this.update()}),this.update())}})}"undefined"!=typeof LocusZoom&&LocusZoom.use(o),e.default=o}}).default;
  //# sourceMappingURL=lz-intervals-track.min.js.map