");return}var title=field.title;var disabled=field.disabled;var help=field.help;var value=field.value;var showLabel=field.showLabel;var style=field.style||"";var col="";var labelColumn="";if(this.formStyle==="horizontal"){col=field.col||"col-xs-8"}if(showLabel===undefined){showLabel="checkbox"!==type&&"button"!==type&&"radio"!==type;showLabel=showLabel||field.options!==undefined}var id=_this.prefix+"_"+name;if(title===undefined){title=name.replace(/_/g," ");title=title[0].toUpperCase()+title.substring(1)}var endingDiv=false;if(showLabel){html.push('
');endingDiv=true}}else if(isFieldStart&&this.formStyle==="horizontal"){html.push('
');endingDiv=true}if("radio"===type){if(field.options){_.each(field.options,function(choice){var isChoiceObject=_.isObject(choice)&&choice.value!==undefined;var optionValue=isChoiceObject?choice.value:choice;var optionText=isChoiceObject?choice.name:choice;var selected=value===optionValue;html.push('
');html.push(' ");if(choice.icon){html.push(' ')}optionText=optionText[0].toUpperCase()+optionText.substring(1);html.push(optionText);html.push("
")})}else{html.push('
');html.push(' ");html.push(value[0].toUpperCase()+value.substring(1));html.push("
")}}else if("checkbox"===type){html.push('
');html.push(' ");html.push(title);html.push("
")}else if("checkbox-list"===type){html.push('
')}else if("select"==type||type=="bootstrap-select"){if(type=="bootstrap-select"){html.push('
");_.each(field.options,function(choice){if(choice&&choice.divider){html.push(' ')}else{html.push('");html.push(optionText);html.push(" ")}});html.push(" ");if(field.type=="bootstrap-select"&&field.toggle){html.push('
All | None
');_this.$form.on("click","[data-name="+name+"_all]",function(evt){evt.preventDefault();var $select=_this.$form.find("[name="+name+"]");$select.selectpicker("val",$.map($select.find("option"),function(o){return $(o).val()}));$select.trigger("change")});_this.$form.on("click","[data-name="+name+"_none]",function(evt){evt.preventDefault();var $select=_this.$form.find("[name="+name+"]");$select.selectpicker("val",[]);$select.trigger("change")})}}else if("textarea"==type){html.push('
")}else if("button"==type){html.push('
');if(field.icon){html.push(' ')}html.push(value?value:title);html.push(" ")}else if("custom"===type){html.push(value)}else if("file"===type){var isMultiple=field.multiple==null?false:field.multiple;html.push('
');var options=[];if(field.options){options=options.concat(field.options)}options.push("My Computer");options.push("URL");if(field.text!=null){options.push(field.text)}_.each(options,function(choice,index){var isChoiceObject=_.isObject(choice)&&choice.value!==undefined;var optionValue=isChoiceObject?choice.value:choice;var optionText=isChoiceObject?choice.name:choice;html.push('");html.push(optionText);html.push(" ")});html.push(" ");html.push("
");html.push(' ');if(field.text){html.push(' ')}html.push("
");html.push('
");_this.$form.on("change","[name="+name+"_picker]",function(evt){var $this=$(this);var val=$this.val();var showUrlInput=val==="URL";var showTextInput=val===field.text;if("Dropbox"===val){var options={success:function(results){var val=!isMultiple?results[0].link:results.map(function(result){return result.link});_this.setValue(name,val);_this.trigger("change",{name:name,value:val})},linkType:"direct",multiselect:isMultiple};Dropbox.choose(options);_this.$form.find("[name="+name+"_picker]").selectpicker("val","")}else if("My Computer"===val){_this.$form.find("[name="+name+"_file]").click();_this.$form.find("[name="+name+"_picker]").selectpicker("val","")}_this.$form.find("[name="+name+"_url]").css("display",showUrlInput?"":"none");_this.$form.find("[name="+name+"_text]").css("display",showTextInput?"":"none")});_this.$form.on("keyup","[name="+name+"_url]",function(evt){var text=$.trim($(this).val());if(isMultiple){text=text.split(",").filter(function(t){t=$.trim(t);return t!==""})}_this.setValue(name,text);if(evt.which===13){_this.trigger("change",{name:name,value:text})}});_this.$form.on("keyup","[name="+name+"_text]",function(evt){var text=$.trim($(this).val());_this.setValue(name,text);if(evt.which===13){_this.trigger("change",{name:name,value:text})}});_this.$form.on("change","[name="+name+"_file]",function(evt){var files=evt.target.files;_this.setValue(name,isMultiple?files:files[0]);_this.trigger("change",{name:name,value:isMultiple?files:files[0]})})}else{type=type==null?"text":type;if(type==="div"){html.push('
");if(type==="div"){html.push("
")}}if(help!==undefined){html.push('
');html.push(help);html.push(" ")}return endingDiv},append:function(fields){var html=[];var _this=this;var isArray=morpheus.Util.isArray(fields);if(!isArray){fields=[fields]}html.push('
');var endingDiv=false;_.each(fields,function(field,index){endingDiv||_this._append(html,field,index===0)});html.push("
");if(endingDiv){html.push("
")}var $div=$(html.join(""));this.$form.append($div);var checkBoxLists=$div.find(".checkbox-list");if(checkBoxLists.length>0){var checkBoxIndex=0;_.each(fields,function(field){if(field.type==="checkbox-list"){var list=new morpheus.CheckBoxList({responsive:false,$el:$(checkBoxLists[checkBoxIndex]),items:field.options});$(checkBoxLists[checkBoxIndex]).data("morpheus.checkbox-list",list);checkBoxIndex++}})}$div.find(".selectpicker").selectpicker({iconBase:"fa",tickIcon:"fa-check",style:"btn-default btn-sm"})},clear:function(){this.$form.empty()},getValue:function(name){var $v=this.$form.find("[name="+name+"]");if($v.length===0){$v=this.$form.find("[name="+name+"_picker]")}return morpheus.FormBuilder.getValue($v)},setOptions:function(name,options,selectFirst){var $select=this.$form.find("[name="+name+"]");var checkBoxList=$select.data("morpheus.checkbox-list");if(checkBoxList){checkBoxList.setItems(options)}else{var html=[];var selection=$select.val();_.each(options,function(choice){var isChoiceObject=_.isObject(choice)&&choice.value!==undefined;if(choice&&choice.divider){html.push('
')}else{html.push('
");html.push(optionText);html.push(" ")}});$select.html(html.join(""));$select.val(selection);if(selectFirst&&$select.val()==null){if($select[0].options.length>0){$select.val($select[0].options[0].value)}}if($select.hasClass("selectpicker")){$select.selectpicker("refresh");$select.selectpicker("render")}}},find:function(name){return this.$form.find("[name="+name+"]")},setHelpText:function(name,value){var v=this.$form.find("[data-name="+name+"_help]");v.html(value)},setValue:function(name,value){var v=this.$form.find("[name="+name+"]");if(v.length===0){v=this.$form.find("[name="+name+"_picker]");if(v.data("type")==="file"){v.val(value);v.selectpicker("render");v.data("files",value);return}}var type=v.attr("type");var list=v.data("morpheus.checkbox-list");if(list){list.setValue(value)}else{if(type==="radio"){v.filter("[value="+value+"]").prop("checked",true)}else if(type==="checkbox"){v.prop("checked",value)}else{v.val(value)}if(v.hasClass("selectpicker")){v.selectpicker("render")}}},setVisible:function(name,visible){var $div=this.$form.find("[name="+name+"]").parents(".form-group");if(visible){$div.show()}else{$div.hide()}},remove:function(name){var $div=this.$form.find("[name="+name+"]").parents(".form-group");$div.remove()},setEnabled:function(name,enabled){var $div=this.$form.find("[name="+name+"]");$div.attr("disabled",!enabled);if(!enabled){$div.parents(".form-group").find("label").addClass("text-muted")}else{$div.parents(".form-group").find("label").removeClass("text-muted")}}};morpheus.Util.extend(morpheus.FormBuilder,morpheus.Events);morpheus.GradientColorSupplier=function(){morpheus.AbstractColorSupplier.call(this);this._updateScale()};morpheus.GradientColorSupplier.prototype={createInstance:function(){return new morpheus.GradientColorSupplier},getColor:function(row,column,value){if(isNaN(value)){return this.missingColor}var min=this.min;var max=this.max;var colors=this.colors;if(value<=min){return colors[0]}else if(value>=max){return colors[colors.length-1]}var fraction=morpheus.SteppedColorSupplier.linearScale(value,min,max,0,100)/100;return this.colorScale(fraction)},setFractions:function(options){morpheus.AbstractColorSupplier.prototype.setFractions.call(this,options);this._updateScale()},_updateScale:function(){this.colorScale=d3.scale.linear().domain(this.fractions).range(this.colors).clamp(true)}};morpheus.Util.extend(morpheus.GradientColorSupplier,morpheus.AbstractColorSupplier);morpheus.Grid=function(options){this.options=options;var _this=this;var grid;this.items=options.items;this.modelToView=null;this.viewOrder=null;function getItemColumnValue(item,column){return column.getter(item)}this.filter=new morpheus.CombinedGridFilter;var model={getLength:function(){return _this.viewOrder!=null?_this.viewOrder.length:_this.items.length},getItem:function(index){return _this.items[_this.viewOrder!=null?_this.viewOrder[index]:index]}};this.$el=options.$el;var gridOptions=$.extend({},{select:true,headerRowHeight:0,showHeaderRow:false,multiColumnSort:true,multiSelect:false,topPanelHeight:0,enableColumnReorder:false,enableTextSelectionOnCells:true,forceFitColumns:true,dataItemColumnValueExtractor:getItemColumnValue,defaultFormatter:function(row,cell,value,columnDef,dataContext){if(_.isNumber(value)){return morpheus.Util.nf(value)}else if(morpheus.Util.isArray(value)){var s=[];for(var i=0,length=value.length;i
0){s.push(", ")}var val=value[i];s.push(value[i])}return s.join("")}else{return value}}},options.gridOptions||{});grid=new Slick.Grid(options.$el,model,options.columns,gridOptions);this.grid=grid;grid.registerPlugin(new morpheus.AutoTooltips2);grid.onCellChange.subscribe(function(e,args){_this.trigger("edit",args)});if(gridOptions.select){grid.setSelectionModel(new Slick.RowSelectionModel({selectActiveRow:true,multiSelect:gridOptions.multiSelect}));grid.getSelectionModel().onSelectedRangesChanged.subscribe(function(e){var nitems=grid.getDataLength();_this.trigger("selectionChanged",{selectedRows:grid.getSelectedRows().filter(function(row){return row>=0&&row<=nitems})})})}grid.onSort.subscribe(function(e,args){_this.sortCols=args.sortCols;_this._updateMappings();grid.invalidate()});options.$el.on("click",function(e){var cell=grid.getCellFromEvent(e);if(cell){_this.trigger("click",{row:cell.row,target:e.target})}});options.$el.on("dblclick",function(e){var cell=grid.getCellFromEvent(e);if(cell){_this.trigger("dblclick",{row:cell.row,target:e.target})}});if(options.sort){var gridSortColumns=[];var gridColumns=grid.getColumns();var sortCols=[];options.sort.forEach(function(c){var column=null;for(var i=0;i=0&&row<=nitems})},getSelectedItems:function(){var rows=this.grid.getSelectedRows();var selection=[];for(var i=0,nrows=rows.length;i=0?this.viewOrder[viewIndex]:-1:viewIndex},_updateMappings:function(){var selectedViewIndices=this.grid.getSelectionModel()!=null?this.grid.getSelectedRows():null;var selectedModelIndices=[];if(selectedViewIndices){for(var i=0,length=selectedViewIndices.length;i0){if(this.viewOrder==null){this.viewOrder=[];for(var i=0,length=this.items.length;i-1){var div=document.createElement("div");document.body.appendChild(div);var $d=$(div);$d.css({position:"absolute",left:-1e3,top:-1e3});var $row=$('");var $cell=$row.find(".slick-cell");var $header=$row.find(".slick-header-column");$row.appendTo($d);var maxWidth=Math.min(parseInt(gridWidth/2),400);var getColumnWidth=function(column){var w=$header.html(column.name).outerWidth()+13;if(column.prototypeValue){$cell.html(column.prototypeValue);w=Math.max($cell.outerWidth(),w)}else{for(var i=0,nrows=Math.min(items.length,10);igridWidth){}$d.remove();this.grid.resizeCanvas()}}};morpheus.Util.extend(morpheus.Grid,morpheus.Events);morpheus.AutoTooltips2=function(options){var _grid;var _self=this;var tip;function init(grid){_grid=grid;$(_grid.getCanvasNode()).on("mouseover",".slick-row",showToolTip);$(_grid.getCanvasNode()).on("mouseout",".slick-row",hideToolTip);$(_grid.getCanvasNode()).on("mouseup",hideAll)}function destroy(){$(_grid.getCanvasNode()).off("mouseover",showToolTip);$(_grid.getCanvasNode()).off("mouseout",hideToolTip);$(_grid.getCanvasNode()).off("mouseup",hideAll)}function hideToolTip(e){var cell=_grid.getCellFromEvent(e);if(cell){var $node=$(_grid.getCellNode(cell.row,cell.cell));if($node.data("bs.tooltip")){$node.tooltip("hide")}}}function hideAll(){$(_grid.getCanvasNode()).find("[data-original-title]").attr("data-original-title","").tooltip("hide")}function hideHeaderToolTip(e){var $node=$(e.target);if($node.data("bs.tooltip")){$node.tooltip("hide")}}function showHeaderToolTip(e){var show=false;var $node=$(e.target);if($node[0].scrollWidth>$node[0].offsetWidth){show=true;var $name=$node.find(".slick-column-name");if(!$node.data("bs.tooltip")){$node.tooltip({placement:"auto",html:true,container:"body",trigger:"manual"})}$node.attr("data-original-title",$name.text());if(show){$node.tooltip("show")}else{$node.tooltip("hide")}}}function showToolTip(e){var cell=_grid.getCellFromEvent(e);if(cell){var $node=$(_grid.getCellNode(cell.row,cell.cell));var text="";var c=_grid.getColumns()[cell.cell];var show=false;var $checkNode=$node.find(".slick-cell-wrapper");if(c.alwaysShowTooltip||$checkNode[0].scrollWidth>$checkNode[0].offsetWidth){var item=_grid.getDataItem(cell.row);text=c.tooltip(item,c.getter(item));show=true}$node.attr("data-original-title",text);var hasTip=$node.data("bs.tooltip");if(!hasTip){$node.tooltip({placement:"auto",html:true,container:"body",trigger:"manual"})}if(show){$node.tooltip("show")}else if(hasTip){$node.tooltip("hide")}}}function handleHeaderMouseEnter(e,args){var column=args.column,$node=$(e.target).closest(".slick-header-column");if(!column.toolTip){$node.attr("title",$node.innerWidth()<$node[0].scrollWidth?column.name:"")}}$.extend(this,{init:init,destroy:destroy})};morpheus.CombinedGridFilter=function(){this.filters=[]};morpheus.CombinedGridFilter.prototype={add:function(filter){this.filters.push(filter)},getFilters:function(){return this.filters},get:function(index){return this.filters[index]},set:function(index,f){this.filters[index]=f},init:function(){for(var i=0;i ");this.currentValue=null;this.legend=new morpheus.LegendWithStops;this.colorScheme=options.colorScheme||new morpheus.HeatMapColorScheme(new morpheus.Project(new morpheus.Dataset({rows:0,columns:0})));this.legend.on("added",function(e){var fractions=_this.colorScheme.getFractions();fractions.push(e.fraction);var colors=_this.colorScheme.getColors();colors.push("black");_this.colorScheme.setFractions({fractions:fractions,colors:colors});var newIndex=_this.getFractionIndex(e.fraction,"black");_this.setSelectedIndex(newIndex);_this.fireChanged()}).on("selectedIndex",function(e){_this.setSelectedIndex(e.selectedIndex)}).on("delete",function(index){_this.deleteSelectedStop()}).on("moved",function(e){var fraction=e.fraction;var fractions=_this.colorScheme.getFractions();fractions[_this.legend.selectedIndex]=fraction;var color=_this.colorScheme.getColors()[_this.legend.selectedIndex];_this.colorScheme.setFractions({fractions:fractions,colors:_this.colorScheme.getColors()});_this.legend.selectedIndex=_this.getFractionIndex(e.fraction,color);var fractionToValue=d3.scale.linear().domain([0,1]).range([_this.colorScheme.getMin(),_this.colorScheme.getMax()]).clamp(true);_this.formBuilder.setValue("selected_value",fractionToValue(fractions[_this.legend.selectedIndex]));_this.fireChanged()});var $row=$("
");$row.css("height","50px").css("width","300px").css("margin-left","auto").css("margin-right","auto");$row.appendTo(this.$div);$(this.legend.canvas).appendTo($row);var formBuilder=new morpheus.FormBuilder;var items=[];items=items.concat({name:"selected_color",type:"color",style:"max-width: 50px;"},{name:"selected_value",type:"text",style:"max-width: 100px;"},[{name:"delete",type:"button",value:"Delete Selected Color Stop"},{name:"add",type:"button",value:"Add Color Stop"}],{name:"minimum",type:"text",style:"max-width: 100px;"},{name:"maximum",type:"text",style:"max-width: 100px;"});if(options.showRelative){items=items.concat({name:"relative_color_scheme",type:"checkbox",help:"A relative color scheme uses the minimum and maximum values in each row"+" to convert values to colors"});items=items.concat({name:"transform_values",type:"select",value:0,options:[{name:"None",value:0},{name:"Subtract row mean, divide by row standard deviation",value:morpheus.AbstractColorSupplier.Z_SCORE},{name:"Subtract row median, divide by row median absolute deviation",value:morpheus.AbstractColorSupplier.ROBUST_Z_SCORE}]})}items=items.concat({name:"missing_color",type:"color",style:"max-width: 50px;"});items.push({name:"stepped_colors",type:"checkbox",value:false,help:"Intervals include left end point and exclude right end point, except for the highest interval"});_.each(items,function(item){formBuilder.append(item)});this.getFractionIndex=function(fraction,color){var fractions=_this.colorScheme.getFractions();var colors=_this.colorScheme.getColors();for(var i=0,len=fractions.length;i
=0&&_.indexOf(fractions,val)!==-1){val-=.1}val=Math.max(0,val);fractions.push(val);var colors=_this.colorScheme.getColors();colors.push("black");_this.colorScheme.setFractions({fractions:fractions,colors:colors});var newIndex=_this.getFractionIndex(e.fraction,"black");_this.setSelectedIndex(newIndex);_this.fireChanged()});formBuilder.$form.find("[name=delete]").on("click",function(e){_this.deleteSelectedStop()});formBuilder.$form.find("[name=transform_values]").on("change",function(e){_this.colorScheme.setTransformValues(parseInt(formBuilder.getValue("transform_values")));_this.fireChanged()});formBuilder.$form.on("keyup","[name=selected_value]",_.debounce(function(e){var val=parseFloat($(this).val());if(!isNaN(val)){_this.setSelectedValue(val);_this.fireChanged()}},100));formBuilder.$form.on("change","[name=selected_color]",function(e){var colors=_this.colorScheme.getColors();colors[_this.legend.selectedIndex]=$(this).val();_this.colorScheme.setFractions({fractions:_this.colorScheme.getFractions(),colors:colors});_this.fireChanged()});formBuilder.$form.on("change","[name=missing_color]",function(e){var color=$(this).val();_this.colorScheme.setMissingColor(color);_this.fireChanged(false)});formBuilder.$form.on("change","[name=stepped_colors]",function(e){_this.colorScheme.setStepped($(this).prop("checked"));_this.fireChanged()});formBuilder.$form.on("keyup","[name=minimum]",_.debounce(function(e){var val=parseFloat($(this).val());if(!isNaN(val)){_this.colorScheme.setMin(val);_this.setSelectedIndex(_this.legend.selectedIndex);_this.fireChanged(false)}},100));formBuilder.$form.on("keyup","[name=maximum]",_.debounce(function(e){var val=parseFloat($(this).val());if(!isNaN(val)){_this.colorScheme.setMax(val);_this.setSelectedIndex(_this.legend.selectedIndex);_this.fireChanged(false)}},100));formBuilder.$form.on("change","[name=relative_color_scheme]",_.throttle(function(e){_this.legend.selectedIndex=-1;var scalingMode=$(this).prop("checked")?morpheus.HeatMapColorScheme.ScalingMode.RELATIVE:morpheus.HeatMapColorScheme.ScalingMode.FIXED;_this.colorScheme.setScalingMode(scalingMode);_this.setColorScheme(_this.colorScheme);_this.fireChanged()},100));this.formBuilder=formBuilder};morpheus.HeatMapColorSchemeChooser.prototype={deleteSelectedStop:function(){var fractions=this.colorScheme.getFractions();fractions.splice(this.legend.selectedIndex,1);var colors=this.colorScheme.getColors();colors.splice(this.legend.selectedIndex,1);this.colorScheme.setFractions({fractions:fractions,colors:colors});this.formBuilder.$form.find("[name^=selected],[name=delete]").prop("disabled",true);this.legend.setSelectedIndex(-1);this.fireChanged()},setSelectedValue:function(val){var valueToFraction=d3.scale.linear().domain([this.colorScheme.getMin(),this.colorScheme.getMax()]).range([0,1]).clamp(true);var fractions=this.colorScheme.getFractions();var fraction=valueToFraction(val);fractions[this.legend.selectedIndex]=fraction;var color=this.colorScheme.getColors()[this.legend.selectedIndex];this.colorScheme.setFractions({fractions:fractions,colors:this.colorScheme.getColors()});this.legend.selectedIndex=this.getFractionIndex(fraction,color)},setSelectedIndex:function(index){var fractions=this.colorScheme.getFractions();if(index>=fractions.length){index=-1}this.legend.setSelectedIndex(index);var formBuilder=this.formBuilder;formBuilder.$form.find("[name^=selected],[name=delete]").prop("disabled",this.legend.selectedIndex===-1);if(this.legend.selectedIndex!==-1){var fractionToValue=d3.scale.linear().domain([0,1]).range([this.colorScheme.getMin(),this.colorScheme.getMax()]).clamp(true);formBuilder.setValue("selected_value",fractionToValue(fractions[this.legend.selectedIndex]));var context=this.legend.canvas.getContext("2d");var colors=this.colorScheme.getColors();context.fillStyle=colors[this.legend.selectedIndex];formBuilder.setValue("selected_color",context.fillStyle)}else{formBuilder.setValue("selected_value","")}this.draw()},setMinMax:function(){if(this.colorScheme.getScalingMode()===morpheus.HeatMapColorScheme.ScalingMode.RELATIVE){this.colorScheme.setMin(0);this.colorScheme.setMax(1)}},dispose:function(){this.off("change");this.legend.destroy();this.formBuilder.$form.off("keyup","input");this.formBuilder.$form.off("change","[name=relative_color_scheme]")},restoreCurrentValue:function(){if(this.colorScheme.setCurrentValue){this.colorScheme.setCurrentValue(this.currentValue)}},setCurrentValue:function(value){this.currentValue=value;if(this.colorScheme&&this.colorScheme.setCurrentValue){this.colorScheme.setCurrentValue(this.currentValue)}this.setColorScheme(this.colorScheme)},setColorScheme:function(colorScheme){this.colorScheme=colorScheme;this.setMinMax();if(colorScheme.setCurrentValue){colorScheme.setCurrentValue(this.currentValue)}this.formBuilder.setValue("relative_color_scheme",colorScheme.getScalingMode()===morpheus.HeatMapColorScheme.ScalingMode.RELATIVE?true:false);this.formBuilder.setValue("transform_values",colorScheme.getTransformValues());this.formBuilder.setEnabled("transform_values",colorScheme.getScalingMode()!==morpheus.HeatMapColorScheme.ScalingMode.RELATIVE);this.formBuilder.$form.find("[name=minimum],[name=maximum]").prop("disabled",colorScheme.getScalingMode()===morpheus.HeatMapColorScheme.ScalingMode.RELATIVE);this.formBuilder.setValue("minimum",this.colorScheme.getMin());this.formBuilder.setValue("maximum",this.colorScheme.getMax());this.formBuilder.setValue("stepped_colors",this.colorScheme.isStepped());this.formBuilder.setValue("missing_color",this.colorScheme.getMissingColor());this.draw()},getFractionToStopPix:function(){return d3.scale.linear().clamp(true).domain([0,1]).range([this.legend.border,this.legend.getUnscaledWidth()-this.legend.border])},fireChanged:function(noreset){this.trigger("change");if(noreset!==false){this.setColorScheme(this.colorScheme)}},draw:function(){var colorScheme=this.colorScheme;if(colorScheme.getScalingMode()===morpheus.HeatMapColorScheme.ScalingMode.RELATIVE){colorScheme.setMin(0);colorScheme.setMax(1)}var fractions=colorScheme.getFractions();var colors=colorScheme.getColors();var fractionToStopPix=this.getFractionToStopPix();this.legend.draw(fractions,colors,colorScheme.isStepped(),fractionToStopPix)}};morpheus.Util.extend(morpheus.HeatMapColorSchemeChooser,morpheus.Events);morpheus.HeatMapColorSchemeLegend=function(heatMap,$keyContent){var colorScheme=heatMap.heatmap.getColorScheme();var colorByValues=colorScheme.getColorByValues();var totalHeight;$keyContent.empty();var ntracks=colorByValues.length;colorByValues.forEach(function(value){if(value!=null||ntracks===1){if(value!="null"){var $label=$(''+value+"
");$keyContent.append($label);totalHeight+=$label.height()}var trackLegend=new morpheus.ColorSupplierLegend(colorScheme,value);$(trackLegend.canvas).css("position","");trackLegend.repaint();trackLegend.on("selectionChanged",function(){heatMap.heatmap.setInvalid(true);heatMap.heatmap.repaint()});$keyContent.append($(trackLegend.canvas));totalHeight+=trackLegend.getUnscaledHeight()}});if(heatMap.options.$key){$keyContent.append(heatMap.options.$key);totalHeight+=heatMap.options.$key.height()}var $edit=$('');$edit.find("[data-name=options]").on("click",function(e){e.preventDefault();heatMap.showOptions();morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"options"})});totalHeight+=$edit.height();$keyContent.append($edit);$keyContent.css({"text-overflow":"ellipsis",overflow:"hidden",width:250+"px",height:totalHeight+"px"})};morpheus.HeatMapColorSchemeLegend.drawColorScheme=function(context,colorScheme,width,printing,hideText,legendHeight){if(!legendHeight){legendHeight=12}context.font="11px "+morpheus.CanvasUtil.getFontFamily(context);var names=colorScheme.getNames();var hasNames=names!=null;if(hasNames){morpheus.HeatMapColorSchemeLegend.drawColorSchemeVertically(context,colorScheme,colorScheme.getHiddenValues(),printing)}else{morpheus.HeatMapColorSchemeLegend.draw(context,colorScheme.getFractions(),colorScheme.getColors(),width,legendHeight,colorScheme.isStepped());context.strokeStyle="LightGrey";context.strokeRect(0,0,width,legendHeight);if(hideText){return}var map=d3.scale.linear().domain([0,1]).range([0,width]).clamp(true);var fractionToValue=d3.scale.linear().domain([0,1]).range([colorScheme.getMin(),colorScheme.getMax()]).clamp(true);context.textAlign="center";context.textBaseline="top";context.fillStyle="black";if(colorScheme.getScalingMode()===morpheus.HeatMapColorScheme.ScalingMode.RELATIVE){context.fillText("row min",0,14);context.fillText("row max",width,legendHeight+2)}else{var fractions=colorScheme.getFractions();var lastTextPixEnd=-1;var halfway=parseInt(fractions.length/2);for(var i=0;ilastTextPixEnd){context.fillText(text,pix,legendHeight+2)}lastTextPixEnd=pix+textWidth/2}var lastTextPixStart=1e4;for(var i=fractions.length-1;i>=halfway;i--){var pix=map(fractions[i]);var text="";if(hasNames){text=names[i]!=""?names[i]+" ("+fractionToValue(fractions[i])+")":names[i]}else{text=morpheus.Util.nf(fractionToValue(fractions[i]))}var textWidth=context.measureText(text).width;var textPixEnd=pix+textWidth/2;if(textPixEndthis.rowCachedMax?d:this.rowCachedMax;this.rowCachedMin=d=0||project.getHoverRowIndex()>=0){var height=rowPositions.getItemSize(project.getHoverColumnIndex());var width=columnPositions.getItemSize(project.getHoverColumnIndex());var y=project.getHoverRowIndex()===-1?rowPositions.getPosition(rowPositions.getLength()-1):rowPositions.getPosition(project.getHoverRowIndex());var x=project.getHoverColumnIndex()===-1?columnPositions.getPosition(0):columnPositions.getPosition(project.getHoverColumnIndex());if(project.getHoverColumnIndex()!==-1){context.strokeRect(x-clip.x,0,width,this.getUnscaledHeight())}if(project.getHoverRowIndex()!==-1){context.strokeRect(0,y-clip.y,this.getUnscaledWidth(),height)}if(project.getHoverColumnIndex()!==-1&&project.getHoverRowIndex()!==-1){context.strokeStyle="black";context.lineWidth=3;context.strokeRect(x-clip.x+1.5,y-clip.y+1.5,width-1.5,height-1.5);if(project.isSymmetric()){var y2=rowPositions.getPosition(project.getHoverColumnIndex());var x2=columnPositions.getPosition(project.getHoverRowIndex());context.strokeRect(x2-clip.x+1.5,y2-clip.y+1.5,width-1.5,height-1.5)}}}var left=morpheus.Positions.getLeft(clip,columnPositions);var right=morpheus.Positions.getRight(clip,columnPositions);var top=morpheus.Positions.getTop(clip,rowPositions);var bottom=morpheus.Positions.getBottom(clip,rowPositions);context.strokeStyle="rgb(0,0,0)";context.lineWidth=2;context.translate(-clip.x,-clip.y);var selectedElements=project.getElementSelectionModel().getViewIndices();if(selectedElements!=null){selectedElements.forEach(function(id){var rowIndex=id.getArray()[0];var columnIndex=id.getArray()[1];if(rowIndex>=top&&rowIndex=left&&columnIndex7&&rowPositions.getSize()>7;var nf;if(drawValues){nf=this.drawValuesFormat;var fontSize=columnPositions.getSize();context.font=fontSize+"px "+fontFamily;var textWidth=context.measureText("-99.9").width;fontSize=(columnPositions.getSize()-1)/textWidth*fontSize;fontSize=Math.min(fontSize,17);context.font=fontSize+"px "+morpheus.CanvasUtil.getFontFamily(context)}var seriesNameToIndex={};for(var i=0;i0){var condition=null;for(var ci=0,nconditions=conditions.length;ci7&&cellRowSize>7&&!isNaN(value)){context.fillStyle="rgb(0,0,0)";context.fillText(nf(value),px+xoffset+cellColumnSize/2,py+yoffset+cellRowSize/2,cellColumnSize)}if(hasElementDrawCallback){elementDrawCallback(context,dataset,row,column,px,py,columnSize,rowSize)}}}if(drawGrid&&rowPositions.getSize()>10&&columnPositions.getSize()>10){context.strokeStyle=this.gridColor;context.lineWidth=this.gridThickness;context.beginPath();for(var row=top;row10&&rowSize>10;if(grid){context.rect(px,py,columnSize,rowSize)}}}context.stroke()}context.lineWidth=1}};morpheus.Util.extend(morpheus.HeatMapElementCanvas,morpheus.AbstractCanvas);morpheus.HeatMapElementCanvas.getSelectedSpans=function(set){var array=[];if(set.size()>0){var index=0;var start=index;var viewIndices=set.values();viewIndices.sort(function(a,b){return a===b?0:a1){array.push([viewIndices[start],viewIndices[index-1]]);start=index}index++}if(start==0){array.push([viewIndices[0],viewIndices[viewIndices.length-1]])}else{array.push([viewIndices[start],viewIndices[index-1]])}}return array};morpheus.KeyboardCharMap=["","","","CANCEL","","","HELP","","BACKSPACE","TAB","","","CLEAR","ENTER","ENTER_SPECIAL","","SHIFT","CONTROL","ALT","PAUSE","CAPS_LOCK","KANA","EISU","JUNJA","FINAL","HANJA","","Escape","CONVERT","NONCONVERT","ACCEPT","MODECHANGE","Space","Page Up","Page Down","End","Home","Left","Up","Right","Down","SELECT","PRINT","EXECUTE","PRINTSCREEN","INSERT","Delete","","0","1","2","3","4","5","6","7","8","9","COLON","SEMICOLON","LESS_THAN","Equals","GREATER_THAN","QUESTION_MARK","AT","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","OS_KEY","","CONTEXT_MENU","","SLEEP","0","1","2","3","4","5","6","7","8","9","MULTIPLY","+","SEPARATOR","SUBTRACT","DECIMAL","DIVIDE","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","F13","F14","F15","F16","F17","F18","F19","F20","F21","F22","F23","F24","","","","","","","","","NUM_LOCK","SCROLL_LOCK","WIN_OEM_FJ_JISHO","WIN_OEM_FJ_MASSHOU","WIN_OEM_FJ_TOUROKU","WIN_OEM_FJ_LOYA","WIN_OEM_FJ_ROYA","","","","","","","","","","CIRCUMFLEX","EXCLAMATION","DOUBLE_QUOTE","HASH","DOLLAR","PERCENT","AMPERSAND","UNDERSCORE","OPEN_PAREN","CLOSE_PAREN","ASTERISK","Plus","PIPE","-","OPEN_CURLY_BRACKET","CLOSE_CURLY_BRACKET","TILDE","","","","","VOLUME_MUTE","VOLUME_DOWN","VOLUME_UP","","","SEMICOLON","EQUALS","COMMA","MINUS","PERIOD","/","BACK_QUOTE","","","","","","","","","","","","","","","","","","","","","","","","","","","OPEN_BRACKET","BACK_SLASH","CLOSE_BRACKET","QUOTE","","META","ALTGR","","WIN_ICO_HELP","WIN_ICO_00","","WIN_ICO_CLEAR","","","WIN_OEM_RESET","WIN_OEM_JUMP","WIN_OEM_PA1","WIN_OEM_PA2","WIN_OEM_PA3","WIN_OEM_WSCTRL","WIN_OEM_CUSEL","WIN_OEM_ATTN","WIN_OEM_FINISH","WIN_OEM_COPY","WIN_OEM_AUTO","WIN_OEM_ENLW","WIN_OEM_BACKTAB","ATTN","CRSEL","EXSEL","EREOF","PLAY","ZOOM","","PA1","WIN_OEM_CLEAR",""];morpheus.HeatMapKeyListener=function(heatMap){var allActions=heatMap.getActionManager().getActions();var actions=allActions.filter(function(a){return a.cb!=null&&a.which!=null});allActions.sort(function(a,b){a=a.name.toLowerCase();b=b.name.toLowerCase();return a===b?0:a0){e.preventDefault();e.stopPropagation();var blob=new Blob([text]);var url=window.URL.createObjectURL(blob);morpheus.HeatMap.showTool(new morpheus.OpenFileTool({file:url}),heatMap)}}});$keyelement.on("mousewheel",function(e){var scrolly=e.deltaY*e.deltaFactor;var scrollx=e.deltaX*e.deltaFactor;var stop=false;if(e.altKey){heatMap.zoom(scrolly>0,{rows:true,columns:true});stop=true}else{if(scrolly!==0){var scrollTop=heatMap.scrollTop();if(heatMap.scrollTop(scrollTop-scrolly)!==scrollTop){stop=true}}if(scrollx!==0){var scrollLeft=heatMap.scrollLeft();if(heatMap.scrollLeft(scrollLeft+scrollx)!==scrollLeft){stop=true}}}if(stop&&heatMap.options.standalone){e.preventDefault();e.stopPropagation()}});function shortcutToString(sc){var s=[""];if(sc.commandKey){s.push(morpheus.Util.COMMAND_KEY)}if(sc.shiftKey){s.push("Shift+")}if(sc.which){s.push(morpheus.KeyboardCharMap[sc.which[0]])}s.push(" ");return s.join("")}this.showKeyMapReference=function(){var html=[];html.push('');allActions.forEach(function(sc){html.push("");html.push(shortcutToString(sc));html.push(" ");if(sc.icon){html.push(' ')}html.push(sc.name);html.push(" ")});html.push("
");morpheus.FormBuilder.showInModal({title:"Keyboard Shortcuts",html:html.join(""),focus:document.activeElement})}};morpheus.HeatMapOptions=function(heatMap){var items=[{name:"color_by",required:true,help:"Use a different color scheme for distinct row annotation values",type:"select",options:["(None)"].concat(morpheus.MetadataUtil.getMetadataNames(heatMap.getProject().getFullDataset().getRowMetadata())),value:heatMap.heatmap.getColorScheme().getSeparateColorSchemeForRowMetadataField()},{name:"color_by_value",required:true,type:"select",options:[]}];items.push({name:"size_by",required:true,type:"select",options:["(None)"].concat(morpheus.DatasetUtil.getSeriesNames(heatMap.getProject().getFullDataset()))});items.push({name:"size_by_minimum",title:"Size by minimum",required:true,type:"text",style:"max-width: 100px;"});items.push({name:"size_by_maximum",title:"Size by maximum",required:true,type:"text",style:"max-width: 100px;"});items.push({name:"conditional_rendering",required:true,type:"button"});items.push({type:"separator"});var createColorSchemeOptions=function(){var colorSchemeOptions=[{name:"relative",value:"relative"},{name:"binary",value:"binary"},{name:"MAF",value:"MAF"},{name:"fixed (-1.5, -0.1, 0.1, 1.5)",value:"cn"}];var savedColorSchemeKeys=[];if(localStorage.getItem("morpheus-colorScheme")!=null){savedColorSchemeKeys=_.keys(JSON.parse(localStorage.getItem("morpheus-colorScheme")))}if(savedColorSchemeKeys.length>0){colorSchemeOptions.push({divider:true});colorSchemeOptions=colorSchemeOptions.concat(savedColorSchemeKeys)}colorSchemeOptions.push({divider:true});colorSchemeOptions.push("My Computer...");return colorSchemeOptions};items.push([{name:"saved_color_scheme",required:true,type:"bootstrap-select",options:createColorSchemeOptions()},{name:"load_color_scheme",type:"button"},{name:"delete_color_scheme",type:"button"}]);items.push({name:"save_color_scheme",type:"button"});var displayItems=[{disabled:heatMap.getProject().getFullDataset().getColumnCount()!==heatMap.getProject().getFullDataset().getRowCount(),name:"link_rows_and_columns",help:"For square matrices",required:true,type:"checkbox",style:"max-width: 100px;",value:heatMap.getProject().isSymmetric()},{name:"show_row_number",required:true,type:"checkbox",value:heatMap.isShowRowNumber()},{name:"show_grid",required:true,type:"checkbox",value:heatMap.heatmap.isDrawGrid()},{name:"grid_thickness",required:true,type:"text",style:"max-width: 100px;",value:morpheus.Util.nf(heatMap.heatmap.getGridThickness())},{name:"grid_color",required:true,type:"color",style:"max-width: 50px;",value:heatMap.heatmap.getGridColor()},{name:"row_size",required:true,type:"text",style:"max-width: 100px;",value:morpheus.Util.nf(heatMap.heatmap.getRowPositions().getSize())},{name:"column_size",required:true,type:"text",style:"max-width: 100px;",value:morpheus.Util.nf(heatMap.heatmap.getColumnPositions().getSize())},{name:"show_values",required:true,type:"checkbox",value:heatMap.heatmap.isDrawValues()},{name:"number_of_fraction_digits",required:true,type:"number",min:0,step:1,style:"max-width: 100px;",value:morpheus.Util.getNumberFormatPatternFractionDigits(heatMap.heatmap.getDrawValuesFormat().toJSON().pattern)}];if(heatMap.rowDendrogram){displayItems.push({name:"row_dendrogram_line_thickness",required:true,type:"text",style:"max-width: 100px;",value:morpheus.Util.nf(heatMap.rowDendrogram?heatMap.rowDendrogram.lineWidth:1)})}if(heatMap.columnDendrogram){displayItems.push({name:"column_dendrogram_line_thickness",required:true,type:"text",style:"max-width: 100px;",value:morpheus.Util.nf(heatMap.columnDendrogram?heatMap.columnDendrogram.lineWidth:1)})}displayItems.push({name:"info_window",required:true,type:"select",style:"max-width:130px;",options:[{name:"Fixed To Top",value:0},{name:"New Window",value:1}],value:heatMap.tooltipMode});displayItems.push({name:"inline_tooltip",required:true,type:"checkbox",value:heatMap.options.inlineTooltip});var colorSchemeFormBuilder=new morpheus.FormBuilder;_.each(items,function(item){colorSchemeFormBuilder.append(item)});var displayFormBuilder=new morpheus.FormBuilder;_.each(displayItems,function(item){displayFormBuilder.append(item)});var colorSchemeChooser=new morpheus.HeatMapColorSchemeChooser({showRelative:true,colorScheme:heatMap.heatmap.getColorScheme()});var updatingSizer=false;function colorSchemeChooserUpdated(){if(heatMap.heatmap.getColorScheme().getSizer&&heatMap.heatmap.getColorScheme().getSizer()!=null){colorSchemeFormBuilder.setValue("size_by",heatMap.heatmap.getColorScheme().getSizer().getSeriesName());colorSchemeFormBuilder.setEnabled("size_by_minimum",heatMap.heatmap.getColorScheme().getSizer().getSeriesName()!=null);colorSchemeFormBuilder.setEnabled("size_by_maximum",heatMap.heatmap.getColorScheme().getSizer().getSeriesName()!=null);if(!updatingSizer){colorSchemeFormBuilder.setValue("size_by_minimum",heatMap.heatmap.getColorScheme().getSizer().getMin());colorSchemeFormBuilder.setValue("size_by_maximum",heatMap.heatmap.getColorScheme().getSizer().getMax())}}}colorSchemeChooser.on("change",function(){colorSchemeChooserUpdated();heatMap.heatmap.setInvalid(true);heatMap.heatmap.repaint();colorSchemeChooser.restoreCurrentValue()});function createMetadataField(isColumns){var options=[];var value={};_.each(heatMap.getVisibleTrackNames(isColumns),function(name){value[name]=true});_.each(morpheus.MetadataUtil.getMetadataNames(isColumns?heatMap.getProject().getFullDataset().getColumnMetadata():heatMap.getProject().getFullDataset().getRowMetadata()),function(name){options.push(name)});var field={type:"bootstrap-select",search:options.length>10,name:isColumns?"column_annotations":"row_annotations",multiple:true,value:value,options:options,toggle:true};return field}var annotationsBuilder=new morpheus.FormBuilder;annotationsBuilder.append(createMetadataField(false));annotationsBuilder.append(createMetadataField(true));function annotationsListener($select,isColumns){var names=[];_.each(heatMap.getVisibleTrackNames(isColumns),function(name){names.push(name)});var values=$select.val();var selectedNow=_.difference(values,names);var unselectedNow=_.difference(names,values);var tracks=[];_.each(selectedNow,function(name){tracks.push({name:name,isColumns:isColumns,visible:true})});_.each(unselectedNow,function(name){tracks.push({name:name,isColumns:isColumns,visible:false})});heatMap.setTrackVisibility(tracks);colorSchemeChooser.restoreCurrentValue()}var $ca=annotationsBuilder.$form.find("[name=column_annotations]");$ca.on("change",function(e){annotationsListener($(this),true)});var $ra=annotationsBuilder.$form.find("[name=row_annotations]");$ra.on("change",function(e){annotationsListener($(this),false)});var annotationOptionsTabId=_.uniqueId("morpheus");var heatMapOptionsTabId=_.uniqueId("morpheus");var displayOptionsTabId=_.uniqueId("morpheus");var $metadataDiv=$('
');$metadataDiv.append($(annotationsBuilder.$form));var $heatMapDiv=$('
');$heatMapDiv.append(colorSchemeChooser.$div);$heatMapDiv.append($(colorSchemeFormBuilder.$form));var $displayDiv=$('
');$displayDiv.append($(displayFormBuilder.$form));displayFormBuilder.setEnabled("grid_thickness",heatMap.heatmap.isDrawGrid());displayFormBuilder.setEnabled("grid_color",heatMap.heatmap.isDrawGrid());displayFormBuilder.$form.find("[name=show_grid]").on("click",function(e){var grid=$(this).prop("checked");displayFormBuilder.setEnabled("grid_thickness",grid);displayFormBuilder.setEnabled("grid_color",grid);heatMap.heatmap.setDrawGrid(grid);heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()});var $fractionDigits=displayFormBuilder.$form.find("[name=number_of_fraction_digits]");displayFormBuilder.$form.find("[name=show_values]").on("click",function(e){var drawValues=$(this).prop("checked");heatMap.heatmap.setDrawValues(drawValues);heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()});$fractionDigits.on("keyup input",_.debounce(function(){var n=parseInt($(this).val());if(n>=0){heatMap.heatmap.setDrawValuesFormat(morpheus.Util.createNumberFormat("."+n+"f"));heatMap.heatmap.setInvalid(true);heatMap.heatmap.repaint()}},100));displayFormBuilder.$form.find("[name=inline_tooltip]").on("click",function(e){heatMap.options.inlineTooltip=$(this).prop("checked")});displayFormBuilder.$form.find("[name=grid_color]").on("change",function(e){var value=$(this).val();heatMap.heatmap.setGridColor(value);heatMap.heatmap.setInvalid(true);heatMap.heatmap.repaint()});displayFormBuilder.$form.find("[name=grid_thickness]").on("keyup",_.debounce(function(e){var value=parseFloat($(this).val());if(!isNaN(value)){heatMap.heatmap.setGridThickness(value);heatMap.heatmap.setInvalid(true);heatMap.heatmap.repaint()}},100));displayFormBuilder.$form.find("[name=row_size]").on("keyup",_.debounce(function(e){var value=parseFloat($(this).val());if(!isNaN(value)){heatMap.heatmap.getRowPositions().setSize(value);heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()}},100));displayFormBuilder.$form.find("[name=info_window]").on("change",function(e){heatMap.setTooltipMode(parseInt($(this).val()))});displayFormBuilder.find("link_rows_and_columns").on("click",function(e){var checked=$(this).prop("checked");if(checked){heatMap.getProject().setSymmetric(heatMap)}else{heatMap.getProject().setSymmetric(null)}});displayFormBuilder.find("show_row_number").on("click",function(e){var checked=$(this).prop("checked");heatMap.setShowRowNumber(checked);heatMap.revalidate()});var $colorByValue=colorSchemeFormBuilder.$form.find("[name=color_by_value]");var separateSchemesField=heatMap.heatmap.getColorScheme().getSeparateColorSchemeForRowMetadataField();if(separateSchemesField!=null){var v=heatMap.project.getFullDataset().getRowMetadata().getByName(separateSchemesField);if(v!=null){$colorByValue.html(morpheus.Util.createOptions(morpheus.VectorUtil.createValueToIndexMap(v).keys()))}}if(separateSchemesField!=null){colorSchemeChooser.setCurrentValue($colorByValue.val())}if(heatMap.heatmap.getColorScheme().getSizer&&heatMap.heatmap.getColorScheme().getSizer()!=null&&heatMap.heatmap.getColorScheme().getSizer().getSeriesName()){colorSchemeFormBuilder.setValue("size_by",heatMap.heatmap.getColorScheme().getSizer().getSeriesName())}colorSchemeFormBuilder.$form.find("[name=size_by]").on("change",function(e){var series=$(this).val();if(series=="(None)"){series=null}colorSchemeChooser.colorScheme.getSizer().setSeriesName(series);colorSchemeChooser.fireChanged()});colorSchemeFormBuilder.$form.find("[name=size_by_minimum]").on("keyup",_.debounce(function(e){updatingSizer=true;colorSchemeChooser.colorScheme.getSizer().setMin(parseFloat($(this).val()));colorSchemeChooser.fireChanged(true);updatingSizer=false},100));colorSchemeFormBuilder.$form.find("[name=size_by_maximum]").on("keyup",_.debounce(function(e){updatingSizer=true;colorSchemeChooser.colorScheme.getSizer().setMax(parseFloat($(this).val()));colorSchemeChooser.fireChanged(true);updatingSizer=false},100));colorSchemeFormBuilder.$form.find("[name=conditional_rendering]").on("click",function(e){e.preventDefault();var conditionalRenderingUI=new morpheus.ConditionalRenderingUI(heatMap);morpheus.FormBuilder.showInModal({title:"Conditional Rendering",html:conditionalRenderingUI.$div,close:"Close",modalClass:"morpheus-sub-modal"})});colorSchemeFormBuilder.find("save_color_scheme").on("click",function(e){e.preventDefault();var saveColorSchemeFormBuilder=new morpheus.FormBuilder;saveColorSchemeFormBuilder.append({name:"save_to",type:"radio",value:"Browser Storage",options:["Browser Storage","File"]});saveColorSchemeFormBuilder.append({name:"color_scheme_name",type:"text"});saveColorSchemeFormBuilder.append({name:"file_name",type:"text"});saveColorSchemeFormBuilder.setVisible("file_name",false);saveColorSchemeFormBuilder.find("save_to").on("change",function(){var isBrowser=$(this).val()==="Browser Storage";saveColorSchemeFormBuilder.setVisible("file_name",!isBrowser);saveColorSchemeFormBuilder.setVisible("color_scheme_name",isBrowser)});morpheus.FormBuilder.showOkCancel({title:"Save Color Scheme",ok:true,cancel:true,draggable:true,content:saveColorSchemeFormBuilder.$form,appendTo:heatMap.getContentEl(),align:"right",okCallback:function(){var colorSchemeText=JSON.stringify(heatMap.heatmap.getColorScheme().toJSON());if(saveColorSchemeFormBuilder.getValue("save_to")==="Browser Storage"){var name=saveColorSchemeFormBuilder.getValue("color_scheme_name").trim();if(name===""){name="my color scheme"}var colorSchemeObject=localStorage.getItem("morpheus-colorScheme");if(colorSchemeObject==null){colorSchemeObject={}}else{colorSchemeObject=JSON.parse(colorSchemeObject)}colorSchemeObject[name]=colorSchemeText;localStorage.setItem("morpheus-colorScheme",JSON.stringify(colorSchemeObject));colorSchemeFormBuilder.setOptions("saved_color_scheme",createColorSchemeOptions())}else{var name=saveColorSchemeFormBuilder.getValue("file_name").trim();if(name===""){name="color_scheme.json"}var blob=new Blob([colorSchemeText],{type:"application/json"});saveAs(blob,name)}},focus:heatMap.getFocusEl()})});colorSchemeFormBuilder.setEnabled("delete_color_scheme",false);colorSchemeFormBuilder.find("delete_color_scheme").on("click",function(){var key=colorSchemeFormBuilder.getValue("saved_color_scheme");var savedColorSchemes=JSON.parse(localStorage.getItem("morpheus-colorScheme"));delete savedColorSchemes[key];localStorage.setItem("morpheus-colorScheme",JSON.stringify(savedColorSchemes));colorSchemeFormBuilder.setOptions("saved_color_scheme",createColorSchemeOptions())});colorSchemeFormBuilder.find("saved_color_scheme").on("change",function(){colorSchemeFormBuilder.setEnabled("delete_color_scheme",["relative","cn","MAF","binary","My Computer..."].indexOf(colorSchemeFormBuilder.getValue("saved_color_scheme"))===-1)});colorSchemeFormBuilder.find("load_color_scheme").on("click",function(e){var val=colorSchemeFormBuilder.getValue("saved_color_scheme");var repaint=true;if(val==="relative"){heatMap.heatmap.getColorScheme().setColorSupplierForCurrentValue(morpheus.AbstractColorSupplier.fromJSON(morpheus.HeatMapColorScheme.Predefined.RELATIVE()))}else if(val==="cn"){heatMap.heatmap.getColorScheme().setColorSupplierForCurrentValue(morpheus.AbstractColorSupplier.fromJSON(morpheus.HeatMapColorScheme.Predefined.CN()))}else if(val==="MAF"){heatMap.heatmap.getColorScheme().setColorSupplierForCurrentValue(morpheus.AbstractColorSupplier.fromJSON(morpheus.HeatMapColorScheme.Predefined.MAF()))}else if(val==="binary"){heatMap.heatmap.getColorScheme().setColorSupplierForCurrentValue(morpheus.AbstractColorSupplier.fromJSON(morpheus.HeatMapColorScheme.Predefined.BINARY()))}else if(val==="My Computer..."){repaint=false;var $file=$(' ');$file.appendTo(heatMap.getContentEl());$file.click();$file.on("change",function(evt){var files=evt.target.files;morpheus.Util.getText(evt.target.files[0]).done(function(text){var json=JSON.parse($.trim(text));heatMap.heatmap.getColorScheme().fromJSON(json);colorSchemeChooser.setColorScheme(heatMap.heatmap.getColorScheme());heatMap.heatmap.setInvalid(true);heatMap.heatmap.repaint()}).fail(function(){morpheus.FormBuilder.showInModal({title:"Error",html:"Unable to read color scheme."})}).always(function(){$file.remove()})})}else{var savedColorSchemes=JSON.parse(localStorage.getItem("morpheus-colorScheme"));var scheme=JSON.parse(savedColorSchemes[val]);heatMap.heatmap.getColorScheme().fromJSON(scheme)}if(repaint){colorSchemeChooser.setColorScheme(heatMap.heatmap.getColorScheme());heatMap.heatmap.setInvalid(true);heatMap.heatmap.repaint()}colorSchemeChooser.restoreCurrentValue()});colorSchemeFormBuilder.$form.find("[name=color_by]").on("change",function(e){var colorByField=$(this).val();if(colorByField=="(None)"){colorByField=null}var colorByValue=null;heatMap.heatmap.getColorScheme().setSeparateColorSchemeForRowMetadataField(colorByField);if(colorByField!=null){$colorByValue.html(morpheus.Util.createOptions(morpheus.VectorUtil.createValueToIndexMap(heatMap.project.getFullDataset().getRowMetadata().getByName(colorByField)).keys()));colorByValue=$colorByValue.val()}else{$colorByValue.html("")}heatMap.heatmap.getColorScheme().setCurrentValue(colorByValue);colorSchemeChooser.setCurrentValue(colorByValue);heatMap.heatmap.setInvalid(true);heatMap.heatmap.repaint();colorSchemeChooser.setColorScheme(heatMap.heatmap.getColorScheme())});$colorByValue.on("change",function(e){if(heatMap.heatmap.getColorScheme().getSeparateColorSchemeForRowMetadataField()==null){colorSchemeChooser.setCurrentValue(null);heatMap.heatmap.getColorScheme().setCurrentValue(null);colorSchemeChooser.setColorScheme(heatMap.heatmap.getColorScheme())}else{colorSchemeChooser.setCurrentValue($colorByValue.val());colorSchemeChooser.setColorScheme(heatMap.heatmap.getColorScheme())}});displayFormBuilder.$form.find("[name=column_size]").on("keyup",_.debounce(function(e){heatMap.heatmap.getColumnPositions().setSize(parseFloat($(this).val()));heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()},100));displayFormBuilder.$form.find("[name=row_gap_size]").on("keyup",_.debounce(function(e){heatMap.rowGapSize=parseFloat($(this).val());heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()},100));displayFormBuilder.$form.find("[name=column_gap_size]").on("keyup",_.debounce(function(e){heatMap.columnGapSize=parseFloat($(this).val());heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()},100));displayFormBuilder.$form.find("[name=squish_factor]").on("keyup",_.debounce(function(e){var f=parseFloat($(this).val());heatMap.heatmap.getColumnPositions().setSquishFactor(f);heatMap.heatmap.getRowPositions().setSquishFactor(f);heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()},100));displayFormBuilder.$form.find("[name=row_dendrogram_line_thickness]").on("keyup",_.debounce(function(e){heatMap.rowDendrogram.lineWidth=parseFloat($(this).val());heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()},100));displayFormBuilder.$form.find("[name=column_dendrogram_line_thickness]").on("keyup",_.debounce(function(e){heatMap.columnDendrogram.lineWidth=parseFloat($(this).val());heatMap.revalidate();colorSchemeChooser.restoreCurrentValue()},100));var $tab=$('
');$metadataDiv.appendTo($tab);$heatMapDiv.appendTo($tab);$displayDiv.appendTo($tab);var $div=$("
");var $ul=$('");$ul.appendTo($div);$tab.appendTo($div);colorSchemeChooser.setColorScheme(heatMap.heatmap.getColorScheme());colorSchemeChooserUpdated();$ul.find("[role=tab]:eq(1)").tab("show");morpheus.FormBuilder.showInModal({title:"Options",html:$div,close:"Close",focus:heatMap.getFocusEl(),onClose:function(){$div.find("input").off("keyup");$ca.off("change");$ra.off("change");$div.remove();colorSchemeChooser.dispose()}})};morpheus.HeatMapSizer=function(){this.seriesName=null;this.sizeByScale=d3.scale.linear().domain([this.min,this.max]).range([0,1]).clamp(true)};morpheus.HeatMapSizer.prototype={min:0,max:1,copy:function(){var sizer=new morpheus.HeatMapSizer;sizer.seriesName=this.seriesName;sizer.min=this.min;sizer.max=this.max;sizer.sizeByScale=this.sizeByScale.copy();return sizer},valueToFraction:function(value){return this.sizeByScale(value)},setMin:function(min){this.min=min;this.sizeByScale=d3.scale.linear().domain([this.min,this.max]).range([0,1]).clamp(true)},setMax:function(max){this.max=max;this.sizeByScale=d3.scale.linear().domain([this.min,this.max]).range([0,1]).clamp(true)},getMin:function(){return this.min},getMax:function(){return this.max},getSeriesName:function(){return this.seriesName},setSeriesName:function(name){this.seriesName=name}};morpheus.HeatMapToolBar=function(heatMap){this.heatMap=heatMap;this.rowSearchResultModelIndices=[];this.columnSearchResultModelIndices=[];var _this=this;var layout=[''];layout.push('
');layout.push('
');layout.push("
");var $el=$(layout.join(""));var searchHtml=[];var $searchForm=$('');$searchForm.on("submit",function(e){e.preventDefault()});searchHtml.push('');searchHtml.push('');searchHtml.push(' Rows');searchHtml.push(" ");searchHtml.push('');searchHtml.push(' Columns');searchHtml.push(" ");searchHtml.push('');searchHtml.push(' '+" Values");searchHtml.push(" ");searchHtml.push('');searchHtml.push(' Row Dendrogram');searchHtml.push(" ");searchHtml.push('');searchHtml.push(' Column Dendrogram');searchHtml.push(" ");searchHtml.push("
");function createSearchOptionsMenu(){searchHtml.push('');searchHtml.push(' ');searchHtml.push('");searchHtml.push("
")}function createSearchMenu(dataName,navigation){searchHtml.push('');searchHtml.push('
');searchHtml.push(' ');searchHtml.push("
");searchHtml.push('
');searchHtml.push('');searchHtml.push(' ');if(navigation){searchHtml.push(' ');searchHtml.push(' ');searchHtml.push(' ')}searchHtml.push(" ");searchHtml.push("
");searchHtml.push("
");searchHtml.push(" ")}if(heatMap.options.toolbar.searchRows||heatMap.options.toolbar.searchColumns||heatMap.options.toolbar.searchValues){createSearchOptionsMenu()}if(heatMap.options.toolbar.searchRows){createSearchMenu("searchRowsGroup",true)}if(heatMap.options.toolbar.searchColumns){createSearchMenu("searchColumnsGroup",true)}if(heatMap.options.toolbar.searchValues){createSearchMenu("searchValuesGroup",false)}createSearchMenu("searchRowDendrogramGroup",false);createSearchMenu("searchColumnDendrogramGroup",false);if(heatMap.options.toolbar.dimensions){searchHtml.push('
');searchHtml.push('
');searchHtml.push(' ');searchHtml.push("")}var $menus=$('
');function createMenu(menuName,actions,minWidth){if(!minWidth){minWidth="0px"}var menu=[];var dropdownId=_.uniqueId("morpheus");menu.push('");$(menu.join("")).appendTo($menus)}if(heatMap.options.menu){if(heatMap.options.menu.File){createMenu("File",heatMap.options.menu.File,"240px")}if(heatMap.options.menu.View){createMenu("Edit",heatMap.options.menu.Edit)}if(heatMap.options.menu.View){createMenu("View",heatMap.options.menu.View,"170px")}if(heatMap.options.menu.Tools){createMenu("Tools",heatMap.options.menu.Tools)}if(heatMap.options.menu.Help){createMenu("Help",heatMap.options.menu.Help,"220px")}}$(searchHtml.join("")).appendTo($searchForm);var $lineOneColumn=$el.find("[data-name=toolbar]");$menus.appendTo($lineOneColumn);$searchForm.appendTo($lineOneColumn);var toolbarHtml=['
'];toolbarHtml.push('
');if(heatMap.options.toolbar.zoom){var dropdownId=_.uniqueId("morpheus");toolbarHtml.push('
")}toolbarHtml.push('
');if(heatMap.options.toolbar.sort){toolbarHtml.push('
')}if(heatMap.options.toolbar.options){toolbarHtml.push('
')}toolbarHtml.push('
');if(heatMap.options.toolbar.openFile){toolbarHtml.push('
')}if(heatMap.options.toolbar.saveImage){toolbarHtml.push('
')}if(heatMap.options.toolbar.saveDataset){toolbarHtml.push('
')}if(heatMap.options.toolbar.saveSession){toolbarHtml.push('
')}toolbarHtml.push('
');if(heatMap.options.toolbar.filter){toolbarHtml.push('
')}if(heatMap.options.toolbar.chart&&typeof echarts!=="undefined"){toolbarHtml.push('
')}if(heatMap.options.toolbar.colorKey){toolbarHtml.push('
');toolbarHtml.push('
');toolbarHtml.push(' ');toolbarHtml.push('");toolbarHtml.push("
")}toolbarHtml.push("
");var $toolbar=$(toolbarHtml.join(""));$toolbar.find("[data-action]").on("click",function(e){e.preventDefault();heatMap.getActionManager().execute($(this).data("action"))}).on("blur",function(e){if(document.activeElement===document.body){heatMap.focus()}});$menus.on("click","li > a",function(e){e.preventDefault();heatMap.getActionManager().execute($(this).data("action"))}).on("blur",function(e){if(document.activeElement===document.body){heatMap.focus()}});if(heatMap.options.toolbar.$customButtons){heatMap.options.toolbar.$customButtons.appendTo($toolbar)}$toolbar.appendTo($lineOneColumn);$el.prependTo(heatMap.$content);this.$tip=$el.find("[data-name=tip]");$el.find('[data-toggle="tooltip"]').tooltip({placement:"bottom",container:"body",trigger:"hover"}).on("click",function(){$(this).tooltip("hide")});var $key=$el.find("[data-name=key]");var $keyContent=$el.find("[data-name=keyContent]");$key.dropdown().parent().on("show.bs.dropdown",function(){new morpheus.HeatMapColorSchemeLegend(heatMap,$keyContent);morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"colorKey"})});var searchHelpHtml=[];searchHelpHtml.push("
Symbols ");searchHelpHtml.push('
');searchHelpHtml.push("Term Description ");searchHelpHtml.push("*
Quote a search term for an"+" exact"+" match. Example: "root beer"
');searchHelpHtml.push("-
Exclude matches using -"+" modifier. ");searchHelpHtml.push("..
Separate numbers by two"+" periods"+" without spaces to"+" see numbers that fall within a range.. Example: 1..10
");searchHelpHtml.push("<= < > >= =
Perform a"+" numeric"+" search."+" Example: >4
");searchHelpHtml.push("
");searchHelpHtml.push("
Search fields ");searchHelpHtml.push('
You can restrict your search to any field by typing the field name followed by a colon ":" and then the term you are looking for. For example, to search for matches containing "beer" in the beverage field, you can enter:'+" beverage:beer
");searchHelpHtml.push("Note that searches only include metadata fields that are displayed. You"+" can search a hidden field by performing a field search.");searchHelpHtml.push("
You can search for an exact list of values by enclosing the list of"+" values in parentheses. For example: pet:(cat dog)
"+" searches all pets that are either cats or dogs.
");var $searchHelp=$(searchHelpHtml.join(""));$el.find("[data-name=searchHelp]").on("click",function(e){e.preventDefault();morpheus.FormBuilder.showInModal({title:"Search Help",html:$searchHelp,appendTo:heatMap.getContentEl(),focus:heatMap.getFocusEl()})});var $searchRowsGroup=$searchForm.find("[data-name=searchRowsGroup]");var $searchColumnsGroup=$searchForm.find("[data-name=searchColumnsGroup]");var $searchValuesGroup=$searchForm.find("[data-name=searchValuesGroup]");var $searchRowDendrogramGroup=$searchForm.find("[data-name=searchRowDendrogramGroup]");var $searchColumnDendrogramGroup=$searchForm.find("[data-name=searchColumnDendrogramGroup]");this.$searchRowDendrogramGroup=$searchRowDendrogramGroup;this.$searchColumnDendrogramGroup=$searchColumnDendrogramGroup;this.matchMode="contains";this.matchAllPredicates=false;var $searchToggle=$searchForm.find("[name=searchToggle]");var nameToSearchObject={};function getSearchElements($group,searchName,cb){var obj={$group:$group,$search:$group.find("[name=search]"),$searchResultsWrapper:$group.find("[data-name=searchResultsWrapper]"),$searchResults:$group.find("[data-name=searchResults]"),$previousMatch:$group.find("[name=previousMatch]"),$nextMatch:$group.find("[name=nextMatch]"),$matchesToTop:$group.find("[name=matchesToTop]"),$toggleButton:$searchToggle.filter("[data-search="+searchName+"]").parent()};nameToSearchObject[searchName]=obj;return obj}var $searchOptions=$el.find("[data-name=searchOptions]");$searchOptions.on("click","li > a",function(e){e.preventDefault();var $this=$(this);var group=$this.data("group");if(group==="matchMode"){_this.matchMode=$this.data("name")}else{_this.matchAllPredicates=$this.data("name")==="matchAll"}var $searchField;if(_this.rowSearchObject.$search.is(":visible")){$searchField=_this.rowSearchObject.$search}else if(_this.columnSearchObject.$search.is(":visible")){$searchField=_this.rowSearchObject.$search}else if(_this.rowDendrogramSearchObject.$search.is(":visible")){$searchField=_this.rowSearchObject.$search}else if(_this.columnDendrogramSearchObject.$search.is(":visible")){$searchField=_this.rowSearchObject.$search}else if(_this.valueSearchObject.$search.is(":visible")){$searchField=_this.rowSearchObject.$search}if($searchField){$searchField.trigger($.Event("keyup",{keyCode:13,which:13}))}var $span=$(this).find("span");if($span.data("type")==="toggle"){$searchOptions.find("[data-group="+group+"] > [data-type=toggle]").removeClass("dropdown-checkbox"+" fa"+" fa-check");$span.addClass("dropdown-checkbox fa fa-check")}morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"searchMatchMode"})});this.rowSearchObject=getSearchElements($searchRowsGroup,"rows",function(){_this.search(true)});this.columnSearchObject=getSearchElements($searchColumnsGroup,"columns",function(){_this.search(false)});this.rowDendrogramSearchObject=getSearchElements($searchRowDendrogramGroup,"rowDendrogram",function(){_this.searchDendrogram(false)});this.columnDendrogramSearchObject=getSearchElements($searchColumnDendrogramGroup,"columnDendrogram",function(){_this.searchDendrogram(false)});this.valueSearchObject=getSearchElements($searchValuesGroup,"values",function(){searchValues()});if(!heatMap.options.toolbar.searchRows){this.rowSearchObject.$toggleButton.hide();this.rowSearchObject.$group.css("display","none")}if(!heatMap.options.toolbar.searchColumns){this.columnSearchObject.$toggleButton.hide();this.columnSearchObject.$group.css("display","none")}if(!heatMap.options.toolbar.searchValues){this.valueSearchObject.$toggleButton.hide();this.valueSearchObject.$group.css("display","none")}this.rowDendrogramSearchObject.$toggleButton.hide();this.rowDendrogramSearchObject.$group.hide();this.columnDendrogramSearchObject.$toggleButton.hide();this.columnDendrogramSearchObject.$group.hide();this.rowDendrogramSearchObject.$searchResultsWrapper.show();this.columnDendrogramSearchObject.$searchResultsWrapper.show();this.valueSearchObject.$searchResultsWrapper.show();this.rowSearchObject.$search.css({"border-top":"3.8px solid #e6e6e6","border-bottom":"3.8px solid #e6e6e6",width:"240px"});this.columnSearchObject.$search.css({"border-right":"3.8px solid #e6e6e6","border-left":"3.8px solid #e6e6e6",width:"240px"});this.$valueSearchResults=$searchValuesGroup.find("[name=searchResults]");this.$valueTextField=$searchValuesGroup.find("[name=search]");this.$dimensionsLabel=$el.find("[data-name=dim]");this.$selectionLabel=$el.find("[data-name=selection]");$searchToggle.on("change",function(e){var search=$(this).data("search");for(var name in nameToSearchObject){var searchObject=nameToSearchObject[name];if(name===search){searchObject.$group.css("display","inline-block");searchObject.$search.focus()}else{searchObject.$group.css("display","none")}}});this.toggleSearch=function(){var $visible=$searchToggle.filter(":visible");var $checked=$searchToggle.filter(":checked");var $next=$visible.eq($visible.index($checked)+1);if(!$next.length){$next=$visible.first()}$next.click()};for(var i=0;i<$searchToggle.length;i++){var $button=$($searchToggle[i]);if($button.parent().css("display")==="block"){$button.click();break}}heatMap.on("dendrogramAnnotated",function(e){if(e.isColumns){_this.rowDendrogramSearchObject.$toggleButton.show()}else{_this.columnDendrogramSearchObject.$toggleButton.show()}});heatMap.on("dendrogramChanged",function(e){if(e.isColumns){_this.rowDendrogramSearchObject.$group.hide();_this.rowDendrogramSearchObject.$toggleButton.hide()}else{_this.columnDendrogramSearchObject.$group.hide();_this.columnDendrogramSearchObject.$toggleButton.hide()}});var project=heatMap.getProject();morpheus.Util.autosuggest({$el:this.rowSearchObject.$search,filter:function(terms,cb){var indices=[];var meta=project.getSortedFilteredDataset().getRowMetadata();heatMap.getVisibleTrackNames(false).forEach(function(name){var index=morpheus.MetadataUtil.indexOf(meta,name);if(index!==-1){indices.push(index)}});meta=new morpheus.MetadataModelColumnView(meta,indices);morpheus.MetadataUtil.autocomplete(meta)(terms,cb)},select:function(){_this.search(true)}});this.rowSearchObject.$search.on("keyup",_.debounce(function(e){if(e.which===13){e.preventDefault()}_this.search(true);morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"searchRows"})},500));morpheus.Util.autosuggest({$el:this.columnSearchObject.$search,filter:function(terms,cb){var indices=[];var meta=project.getSortedFilteredDataset().getColumnMetadata();heatMap.getVisibleTrackNames(true).forEach(function(name){var index=morpheus.MetadataUtil.indexOf(meta,name);if(index!==-1){indices.push(index)}});meta=new morpheus.MetadataModelColumnView(meta,indices);morpheus.MetadataUtil.autocomplete(meta)(terms,cb)},select:function(){_this.search(false)}});this.columnSearchObject.$search.on("keyup",_.debounce(function(e){if(e.which===13){e.preventDefault()}_this.search(false);morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"searchColumns"})},500));morpheus.Util.autosuggest({$el:this.rowDendrogramSearchObject.$search,filter:function(tokens,cb){var d=heatMap.getDendrogram(false);if(!d.searchTerms){cb([])}else{var token=tokens!=null&&tokens.length>0?tokens[tokens.selectionStartIndex]:"";token=$.trim(token);if(token===""){cb([])}else{morpheus.Util.autocompleteArrayMatcher(token,cb,d.searchTerms,null,10)}}},select:function(){_this.searchDendrogram(false)}});this.rowDendrogramSearchObject.$search.on("keyup",_.debounce(function(e){if(e.which===13){e.preventDefault()}_this.searchDendrogram(false);morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"searchRowDendrogram"})},500));morpheus.Util.autosuggest({$el:this.columnDendrogramSearchObject.$search,filter:function(tokens,cb){var d=heatMap.getDendrogram(true);if(!d.searchTerms){cb([])}else{var token=tokens!=null&&tokens.length>0?tokens[tokens.selectionStartIndex]:"";token=$.trim(token);if(token===""){cb([])}else{morpheus.Util.autocompleteArrayMatcher(token,cb,d.searchTerms,null,10)}}},select:function(){_this.searchDendrogram(true)}});this.columnDendrogramSearchObject.$search.on("keyup",_.debounce(function(e){if(e.which===13){e.preventDefault()}_this.searchDendrogram(true);morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"searchColumnDendrogram"})},500));function searchValues(){var $searchResultsLabel=_this.$valueSearchResults;var text=$.trim(_this.$valueTextField.val());if(text===""){$searchResultsLabel.html("");project.getElementSelectionModel().setViewIndices(null)}else{var viewIndices=morpheus.DatasetUtil.searchValues({dataset:project.getSortedFilteredDataset(),text:text,matchAllPredicates:_this.matchAllPredicates,defaultMatchMode:_this.matchMode});project.getElementSelectionModel().setViewIndices(viewIndices);$searchResultsLabel.html(viewIndices.size()+" match"+(viewIndices.size()===1?"":"es"))}}morpheus.Util.autosuggest({$el:this.$valueTextField,filter:function(terms,cb){morpheus.DatasetUtil.autocompleteValues(project.getSortedFilteredDataset())(terms,cb)},select:function(){searchValues()}});this.$valueTextField.on("keyup",_.debounce(function(e){if(e.which===13){_this.$valueTextField.autocomplete("close");e.preventDefault()}searchValues()},500));this.toggleControls=function(){if($lineOneColumn.css("display")==="none"){$lineOneColumn.css("display","");_this.rowSearchObject.$search.focus()}else{$lineOneColumn.css("display","none");$(_this.heatMap.heatmap.canvas).focus()}};this.$el=$el;var updateFilterStatus=function(){if(heatMap.getProject().getRowFilter().isEnabled()||heatMap.getProject().getColumnFilter().isEnabled()){_this.$el.find("[name=filterButton]").addClass("btn-primary")}else{_this.$el.find("[name=filterButton]").removeClass("btn-primary")}};updateFilterStatus();this.columnSearchObject.$matchesToTop.on("click",function(e){e.preventDefault();var $this=$(this);$this.toggleClass("btn-primary");_this.setSelectionOnTop({isColumns:true,isOnTop:$this.hasClass("btn-primary"),updateButtonStatus:false});morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"columnMatchesToTop"})});this.rowSearchObject.$matchesToTop.on("click",function(e){e.preventDefault();var $this=$(this);$this.toggleClass("btn-primary");_this.setSelectionOnTop({isColumns:false,isOnTop:$this.hasClass("btn-primary"),updateButtonStatus:false});morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"rowMatchesToTop"})});project.on("rowSortOrderChanged.morpheus",function(e){if(_this.searching){return}_this._updateSearchIndices(false);_this.rowSearchObject.$matchesToTop.removeClass("btn-primary")});project.on("columnSortOrderChanged.morpheus",function(e){if(_this.searching){return}_this._updateSearchIndices(true);_this.columnSearchObject.$matchesToTop.removeClass("btn-primary")});heatMap.getProject().on("rowFilterChanged.morpheus",function(e){_this.search(true);updateFilterStatus()});heatMap.getProject().on("columnFilterChanged.morpheus",function(e){_this.search(false);updateFilterStatus()});heatMap.getProject().on("datasetChanged.morpheus",function(){_this.search(true);_this.search(false);updateFilterStatus()});heatMap.getProject().getRowSelectionModel().on("selectionChanged.morpheus",function(){_this.updateSelectionLabel()});heatMap.getProject().getColumnSelectionModel().on("selectionChanged.morpheus",function(){_this.updateSelectionLabel()});this.rowSearchResultViewIndicesSorted=null;this.currentRowSearchIndex=0;this.columnSearchResultViewIndicesSorted=null;this.currentColumnSearchIndex=-1;this.columnSearchObject.$previousMatch.on("click",function(){_this.currentColumnSearchIndex--;if(_this.currentColumnSearchIndex<0){_this.currentColumnSearchIndex=_this.columnSearchResultViewIndicesSorted.length-1}heatMap.scrollLeft(heatMap.getHeatMapElementComponent().getColumnPositions().getPosition(_this.columnSearchResultViewIndicesSorted[_this.currentColumnSearchIndex]));morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"previousColumnMatch"})});this.rowSearchObject.$previousMatch.on("click",function(){_this.currentRowSearchIndex--;if(_this.currentRowSearchIndex<0){_this.currentRowSearchIndex=_this.rowSearchResultViewIndicesSorted.length-1}heatMap.scrollTop(heatMap.getHeatMapElementComponent().getRowPositions().getPosition(_this.rowSearchResultViewIndicesSorted[_this.currentRowSearchIndex]));morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"previousRowMatch"})});this.columnSearchObject.$nextMatch.on("click",function(){_this.next(true);morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"nextColumnMatch"})});this.rowSearchObject.$nextMatch.on("click",function(){_this.next(false);morpheus.Util.trackEvent({eventCategory:"ToolBar",eventAction:"nextRowMatch"})});this.updateDimensionsLabel();this.updateSelectionLabel()};morpheus.HeatMapToolBar.HIGHLIGHT_SEARCH_MODE=0;morpheus.HeatMapToolBar.FILTER_SEARCH_MODE=1;morpheus.HeatMapToolBar.MATCHES_TO_TOP_SEARCH_MODE=2;morpheus.HeatMapToolBar.SELECT_MATCHES_SEARCH_MODE=3;morpheus.HeatMapToolBar.prototype={quickColumnFilter:false,searching:false,rowSearchMode:morpheus.HeatMapToolBar.SELECT_MATCHES_SEARCH_MODE,columnSearchMode:morpheus.HeatMapToolBar.SELECT_MATCHES_SEARCH_MODE,_updateSearchIndices:function(isColumns){var project=this.heatMap.getProject();if(isColumns){var viewIndices=[];var modelIndices=this.columnSearchResultModelIndices;for(var i=0,length=modelIndices.length;i
=this.columnSearchResultViewIndicesSorted.length){this.currentColumnSearchIndex=0}heatMap.scrollLeft(heatMap.getHeatMapElementComponent().getColumnPositions().getPosition(this.columnSearchResultViewIndicesSorted[this.currentColumnSearchIndex]))}else{this.currentRowSearchIndex++;if(this.currentRowSearchIndex>=this.rowSearchResultViewIndicesSorted.length){this.currentRowSearchIndex=0}heatMap.scrollTop(heatMap.getHeatMapElementComponent().getRowPositions().getPosition(this.rowSearchResultViewIndicesSorted[this.currentRowSearchIndex]))}},getSearchField:function(type){if(type===morpheus.HeatMapToolBar.COLUMN_SEARCH_FIELD){return this.columnSearchObject.$search}else if(type===morpheus.HeatMapToolBar.ROW_SEARCH_FIELD){return this.rowSearchObject.$search}else if(type===morpheus.HeatMapToolBar.COLUMN_DENDROGRAM_SEARCH_FIELD){return this.columnDendrogramSearchObject.$search}else if(type===morpheus.HeatMapToolBar.ROW_DENDROGRAM_SEARCH_FIELD){return this.rowDendrogramSearchObject.$search}},setSearchText:function(options){var $tf=options.isColumns?this.columnSearchObject.$search:this.rowSearchObject.$search;var existing=options.append?$.trim($tf.val()):"";if(existing!==""){existing+=" "}if(options.onTop){options.isColumns?this.columnSearchObject.$matchesToTop.addClass("btn-primary"):this.rowSearchObject.$matchesToTop.addClass("btn-primary")}$tf.val(existing+options.text);this.search(!options.isColumns);if(options.scrollTo){this.next(options.isColumns)}},updateDimensionsLabel:function(){var p=this.heatMap.getProject();var d=p.getFullDataset();var f=p.getSortedFilteredDataset();var text=[];if(f.getRowCount()!==d.getRowCount()){text.push("");text.push(morpheus.Util.intFormat(f.getRowCount()));text.push("/");text.push(morpheus.Util.intFormat(d.getRowCount()));text.push(" ")}else{text.push(morpheus.Util.intFormat(f.getRowCount()))}text.push(" rows by ");if(f.getColumnCount()!==d.getColumnCount()){text.push("");text.push(morpheus.Util.intFormat(f.getColumnCount()));text.push("/");text.push(morpheus.Util.intFormat(d.getColumnCount()));text.push(" ")}else{text.push(morpheus.Util.intFormat(f.getColumnCount()))}text.push(" columns");this.$dimensionsLabel.html(text.join(""))},updateSelectionLabel:function(){var nc=this.heatMap.getProject().getColumnSelectionModel().count();var nr=this.heatMap.getProject().getRowSelectionModel().count();var text=[];text.push(morpheus.Util.intFormat(nr)+" row");if(nr!==1){text.push("s")}text.push(", ");text.push(morpheus.Util.intFormat(nc)+" column");if(nc!==1){text.push("s")}text.push(" selected");this.$selectionLabel.html(text.join(""))},searchDendrogram:function(isColumns){var searchObject=isColumns?this.columnDendrogramSearchObject:this.rowDendrogramSearchObject;var text=$.trim(searchObject.$search.val());var dendrogram=isColumns?this.heatMap.columnDendrogram:this.heatMap.rowDendrogram;var $searchResults=searchObject.$searchResults;var matches=morpheus.DendrogramUtil.search({rootNode:dendrogram.tree.rootNode,text:text,matchAllPredicates:this.matchAllPredicates,defaultMatchMode:this.matchMode});if(matches===-1){$searchResults.html("")}else{$searchResults.html(matches+" match"+(matches===1?"":"es"))}if(matches<=0){var positions=isColumns?this.heatMap.getHeatMapElementComponent().getColumnPositions():this.heatMap.getHeatMapElementComponent().getRowPositions();positions.setSquishedIndices(null);if(isColumns){this.heatMap.getProject().setGroupColumns([],true)}else{this.heatMap.getProject().setGroupRows([],true)}positions.setSize(isColumns?this.heatMap.getFitColumnSize():this.heatMap.getFitRowSize())}else{morpheus.DendrogramUtil.squishNonSearchedNodes(this.heatMap,isColumns)}this.heatMap.updateDataset();this.heatMap.revalidate()},search:function(isRows){this.searching=true;var isMatchesOnTop=isRows?this.rowSearchObject.$matchesToTop.hasClass("btn-primary"):this.columnSearchObject.$matchesToTop.hasClass("btn-primary");var heatMap=this.heatMap;var project=heatMap.getProject();var sortKeys=isRows?project.getRowSortKeys():project.getColumnSortKeys();sortKeys=sortKeys.filter(function(key){return!(key instanceof morpheus.MatchesOnTopSortKey&&key.toString()==="matches on top")});var dataset=project.getSortedFilteredDataset();var $searchResultsLabel=isRows?this.rowSearchObject.$searchResults:this.columnSearchObject.$searchResults;var searchText=!isRows?$.trim(this.columnSearchObject.$search.val()):$.trim(this.rowSearchObject.$search.val());var metadata=isRows?dataset.getRowMetadata():dataset.getColumnMetadata();var visibleIndices=[];heatMap.getVisibleTrackNames(!isRows).forEach(function(name){var index=morpheus.MetadataUtil.indexOf(metadata,name);if(index!==-1){visibleIndices.push(index)}});var fullModel=metadata;metadata=new morpheus.MetadataModelColumnView(metadata,visibleIndices);var searchResultViewIndices=morpheus.MetadataUtil.search({model:metadata,fullModel:fullModel,text:searchText,isColumns:!isRows,matchAllPredicates:this.matchAllPredicates,defaultMatchMode:this.matchMode});if(searchText===""){$searchResultsLabel.html("");if(isRows){this.rowSearchObject.$searchResultsWrapper.hide()}else{this.columnSearchObject.$searchResultsWrapper.hide()}}else{$searchResultsLabel.html(searchResultViewIndices.length+" match"+(searchResultViewIndices.length===1?"":"es"));if(isRows){this.rowSearchObject.$searchResultsWrapper.show()}else{this.columnSearchObject.$searchResultsWrapper.show()}}var searchResultsModelIndices=[];if(searchResultViewIndices!=null){for(var i=0,length=searchResultViewIndices.length;i0){tipText.push(separator)}tipText.push(pair.name);tipText.push(": ");if(_.isArray(pair.value)){for(var i=0;i0){tipText.push(", ")}tipText.push(pair.value[i])}}else{tipText.push(pair.value)}tipText.push(" ")})}}if(rowIndex!==-1&&columnIndex!==-1){var tooltipSeriesIndices=options.tooltipSeriesIndices?options.tooltipSeriesIndices:morpheus.Util.sequ32(dataset.getSeriesCount());for(var i=0,nseries=tooltipSeriesIndices.length;i0);if(heatMap.options.symmetric&&dataset.getValue(rowIndex,columnIndex,tooltipSeriesIndices[i])!==dataset.getValue(columnIndex,rowIndex,tooltipSeriesIndices[i])){morpheus.HeatMapTooltipProvider._matrixValueToString(heatMap,dataset,columnIndex,rowIndex,tooltipSeriesIndices[i],tipText,separator,false)}}if(quick){var quickRowTracks=heatMap.rowTracks.filter(function(t){return t.settings.inlineTooltip});morpheus.HeatMapTooltipProvider._tracksToString(quickRowTracks,dataset.getRowMetadata(),rowIndex,tipText,separator);morpheus.HeatMapTooltipProvider._tracksToString(heatMap.columnTracks.filter(function(t){return t.settings.inlineTooltip}),dataset.getColumnMetadata(),columnIndex,tipText,separator)}}else if(quick){if(rowIndex!==-1){morpheus.HeatMapTooltipProvider._tracksToString(heatMap.rowTracks.filter(function(t){return t.settings.inlineTooltip&&options.name!==t.getName()}),dataset.getRowMetadata(),rowIndex,tipText,separator)}if(columnIndex!==-1){morpheus.HeatMapTooltipProvider._tracksToString(heatMap.columnTracks.filter(function(t){return t.settings.inlineTooltip&&options.name!==t.getName()}),dataset.getColumnMetadata(),columnIndex,tipText,separator)}}if(!quick){if(rowIndex!==-1){morpheus.HeatMapTooltipProvider._metadataToString(options,heatMap.rowTracks,dataset.getRowMetadata(),rowIndex,tipText,separator)}if(columnIndex!==-1){morpheus.HeatMapTooltipProvider._metadataToString(options,heatMap.columnTracks,dataset.getColumnMetadata(),columnIndex,tipText,separator)}}else if(options.name!=null){var metadata=rowIndex!==-1?dataset.getRowMetadata():dataset.getColumnMetadata();var vector=metadata.getByName(options.name);var track=heatMap.getTrack(options.name,columnIndex!==-1);var colorByName=track!=null?track.settings.colorByField:null;var additionalVector=colorByName!=null?metadata.getByName(colorByName):null;morpheus.HeatMapTooltipProvider.vectorToString(vector,rowIndex!==-1?rowIndex:columnIndex,tipText,separator,additionalVector)}var rowNodes=[];var columnNodes=[];var selectedRowNodes=[];var selectedColumnNodes=[];if(options.rowNodes){rowNodes=options.rowNodes}if(options.columnNodes){columnNodes=options.columnNodes}if(!quick){if(heatMap.rowDendrogram){selectedRowNodes=_.values(heatMap.rowDendrogram.selectedRootNodeIdToNode)}if(heatMap.columnDendrogram){selectedColumnNodes=_.values(heatMap.columnDendrogram.selectedRootNodeIdToNode)}if(selectedRowNodes.length>0&&rowNodes.length>0){var nodeIds={};_.each(selectedRowNodes,function(n){nodeIds[n.id]=true});rowNodes=_.filter(rowNodes,function(n){return nodeIds[n.id]===undefined})}if(selectedColumnNodes.length>0&&columnNodes.length>0){var nodeIds={};_.each(selectedColumnNodes,function(n){nodeIds[n.id]=true});columnNodes=_.filter(columnNodes,function(n){return nodeIds[n.id]===undefined})}}morpheus.HeatMapTooltipProvider._nodesToString(tipText,rowNodes,null,separator);morpheus.HeatMapTooltipProvider._nodesToString(tipText,columnNodes,null,separator);if(!quick){if(selectedRowNodes.length>0){morpheus.HeatMapTooltipProvider._nodesToString(tipText,selectedRowNodes,heatMap.rowDendrogram._selectedNodeColor,separator)}if(selectedColumnNodes.length>0){morpheus.HeatMapTooltipProvider._nodesToString(tipText,selectedColumnNodes,heatMap.columnDendrogram._selectedNodeColor,separator)}}};morpheus.HeatMapTooltipProvider._matrixValueToString=function(heatMap,dataset,rowIndex,columnIndex,seriesIndex,tipText,separator,showSeriesNameInTooltip){var val=dataset.getValue(rowIndex,columnIndex,seriesIndex);if(val!=null){var nf=heatMap.getHeatMapElementComponent().getDrawValuesFormat();if(val.toObject||!_.isNumber(val)){var obj=val.toObject?val.toObject():val;if(morpheus.Util.isArray(obj)){var v=morpheus.Util.toString(obj);if(tipText.length>0){tipText.push(separator)}if(showSeriesNameInTooltip){tipText.push(dataset.getName(seriesIndex));tipText.push(": ")}tipText.push("");tipText.push(v);tipText.push(" ")}else{var keys=_.keys(obj);if(keys.length===0){var v=morpheus.Util.toString(obj);if(tipText.length>0){tipText.push(separator)}if(showSeriesNameInTooltip){tipText.push(dataset.getName(seriesIndex));tipText.push(": ")}tipText.push("");tipText.push(v);tipText.push(" ")}else{for(var i=0,nkeys=keys.length;i0){tipText.push(separator)}tipText.push(key);tipText.push(": ");tipText.push(v);tipText.push(" ")}}if(_.isNumber(val)){tipText.push(separator);tipText.push("Value: ");tipText.push(nf(val));tipText.push(" ")}}}}else{if(tipText.length>0){tipText.push(separator)}if(showSeriesNameInTooltip){tipText.push(dataset.getName(seriesIndex));tipText.push(": ")}tipText.push("");tipText.push(nf(val));tipText.push(" ")}}};morpheus.HeatMapTooltipProvider.vectorToString=function(vector,index,tipText,separator,additionalVector){var arrayValueToString=function(arrayFieldName,arrayVal){if(arrayVal!=null){if(arrayFieldName!=null){if(tipText.length>0){tipText.push(separator)}tipText.push(arrayFieldName)}if(arrayVal.toObject){tipText.push(" ");var obj=arrayVal.toObject();var keys=_.keys(obj);_.each(keys,function(key){var subVal=obj[key];if(subVal!=null&&subVal!=""){if(tipText.length>0){tipText.push(separator)}tipText.push(key);tipText.push(": ");tipText.push(morpheus.Util.toString(subVal));tipText.push(" ")}})}else{tipText.push(": ");tipText.push(morpheus.Util.toString(arrayVal));tipText.push(" ")}}};if(vector!=null){var primaryVal=vector.getValue(index);if(primaryVal!=null&&primaryVal!=""){var primaryFields=vector.getProperties().get(morpheus.VectorKeys.FIELDS);if(primaryFields!=null){var visibleFieldIndices=vector.getProperties().get(morpheus.VectorKeys.VISIBLE_FIELDS);if(visibleFieldIndices===undefined){visibleFieldIndices=morpheus.Util.seq(primaryFields.length)}var additionalFieldNames=additionalVector!=null?additionalVector.getProperties().get(morpheus.VectorKeys.FIELDS):null;var additionalVal=additionalFieldNames!=null?additionalVector.getValue(index):null;if(tipText.length>0){tipText.push(separator)}tipText.push(vector.getName());for(var j=0;j0){tipText.push(separator)}tipText.push(additionalVector.getName());for(var j=0;j0){tipText.push(separator)}tipText.push(vector.getName());tipText.push(": ");var obj=primaryVal.summary;var keys=_.keys(obj);for(var i=0,nkeys=keys.length;i0){tipText.push(separator)}tipText.push(key);tipText.push(": ");tipText.push(v);tipText.push(" ")}}}else{if(tipText.length>0){tipText.push(separator)}tipText.push(vector.getName());tipText.push(": ");tipText.push(morpheus.Util.toString(primaryVal));tipText.push(" ")}}}};morpheus.HeatMapTooltipProvider._tracksToString=function(tracks,metadata,index,tipText,separator){for(var i=0;i0){tipText.push(separator)}if(color){tipText.push('')}tipText.push(name);tipText.push(": ");if(_.isArray(value)){for(var i=0;i0){tipText.push(", ")}tipText.push(morpheus.Util.toString(value[i]))}}else{tipText.push(morpheus.Util.toString(value))}tipText.push(" ");if(color){tipText.push(" ")}}};_.each(nodes,function(node){if(node.info){for(var name in node.info){var value=node.info[name];renderField(name,value)}}renderField("height",node.height);renderField("depth",node.depth);var nLeafNodes=1+Math.abs(node.maxIndex-node.minIndex);if(nLeafNodes>0){renderField("# of leaf nodes",nLeafNodes)}})};morpheus.HeatMapTrackColorLegend=function(tracks,colorModel){morpheus.AbstractCanvas.call(this,false);this.tracks=tracks;this.colorModel=colorModel;this.canvas.style.position=""};morpheus.HeatMapTrackColorLegend.prototype={getPreferredSize:function(){var tracks=this.tracks;var colorModel=this.colorModel;var xpix=0;var ypix=0;var maxYPix=0;var canvas=this.canvas;var context=canvas.getContext("2d");context.font="12px "+morpheus.CanvasUtil.getFontFamily(context);for(var i=0;i0?maxYPix+12:0}},draw:function(clip,context){var tracks=this.tracks;var colorModel=this.colorModel;var xpix=0;for(var i=0;i0?maxYPix+30:0}},draw:function(clip,context){var tracks=this.tracks;var model=this.model;var xpix=0;var ypix=0;context.textAlign="left";context.textBaseline="top";context.font="12px "+morpheus.CanvasUtil.getFontFamily(context);context.fillStyle=morpheus.CanvasUtil.FONT_COLOR;context.strokeStyle="black";var font=context.font;for(var i=0;i0?maxYPix+30:0}},draw:function(clip,context){var tracks=this.tracks;var shapeModel=this.shapeModel;var xpix=0;var ypix=0;context.textAlign="left";context.textBaseline="top";context.font="12px "+morpheus.CanvasUtil.getFontFamily(context);context.fillStyle=morpheus.CanvasUtil.FONT_COLOR;context.strokeStyle="black";for(var i=0;i ")}else{this.$el=$(options.el)}this.rowGapSize=options.rowGapSize;this.columnGapSize=options.columnGapSize;this.actionManager=new morpheus.ActionManager;this.actionManager.heatMap=this;this.$el.addClass("morpheus");if(this.options.dataset==null){var datasetFormBuilder=new morpheus.FormBuilder;datasetFormBuilder.append({name:"file",type:"file"});this.options.dataset=$.Deferred();morpheus.FormBuilder.showOkCancel({title:"Dataset",appendTo:this.getContentEl(),focus:this.getFocusEl(),content:datasetFormBuilder.$form,okCallback:function(){var file=datasetFormBuilder.getValue("file");morpheus.DatasetUtil.read(file).done(function(dataset){_this.options.dataset.resolve(dataset)}).fail(function(err){_this.options.dataset.reject(err)})},cancelCallback:function(){_this.options.dataset.reject("Session cancelled.")}})}if(this.options.name==null){this.options.name=morpheus.Util.getBaseFileName(morpheus.Util.getFileName(this.options.dataset.file?this.options.dataset.file:this.options.dataset))}var isPrimary=this.options.parent==null;if(this.options.parent==null){if(!morpheus.Util.isHeadless()){if(this.options.tabManager==null){this.tabManager=new morpheus.TabManager({landingPage:function(){if(_this.options.landingPage==null){_this.options.landingPage=new morpheus.LandingPage({tabManager:_this.tabManager});_this.options.landingPage.$el.prependTo(_this.$el)}return _this.options.landingPage},autohideTabBar:this.options.autohideTabBar})}else{this.tabManager=this.options.tabManager}if(this.options.tabManager==null){this.tabManager.appendTo(this.$el)}}}else{if(this.options.inheritFromParent){this.popupItems=this.options.parent.popupItems;if(!this.options.tabOpened){this.options.tabOpened=this.options.parent.options.tabOpened}this.options.drawCallback=this.options.parent.options.drawCallback}this.tabManager=this.options.parent.tabManager}this.$content=$("
");this.$content.css({width:"100%","user-select":"none","-webkit-user-select":"none","-webkit-user-drag":"none","-webkit-tap-highlight-color":"rgba(0, 0, 0, 0)","-moz-user-select":"none","-moz-user-drag":"none","-moz-tap-highlight-color":"rgba(0, 0, 0, 0)","-ms-user-select":"none","-ms-user-drag":"none","-ms-tap-highlight-color":"rgba(0, 0, 0, 0)","-o-user-select":"none","-o-user-drag":"none","-o-tap-highlight-color":"rgba(0, 0, 0, 0)","overflow-x":"visible","overflow-y":"visible"});this.$content.on("remove.morpheus",function(){_this.$content.off("remove.morpheus");_this.dispose()});if(!morpheus.Util.isHeadless()){var tab=this.tabManager.add({$el:this.$content,closeable:this.options.closeable,rename:this.options.rename,title:this.options.name,object:this,focus:this.options.focus});this.tabId=tab.id;this.$tabPanel=tab.$panel}if(options.$loadingImage){options.$loadingImage.appendTo(this.$content)}this.options.dataSource=!options.dataset?"":options.dataset.file?options.dataset.file:options.dataset;this._togglingInfoWindow=false;var promises=[];if(options.promises){for(var i=0;i
Cause: ");message.push(err.message)}if(_this.options.error){_this.options.error(message)}morpheus.FormBuilder.showInModal({title:"Error",html:message.join(""),appendTo:_this.getContentEl(),focus:_this.getFocusEl()})});promises.push(deferred);var datasetOverlay=null;if(options.datasetOverlay){var d=options.datasetOverlay.file?morpheus.DatasetUtil.read(options.datasetOverlay.file,options.datasetOverlay.options):morpheus.DatasetUtil.read(options.datasetOverlay);d.done(function(dataset){datasetOverlay=dataset});promises.push(d)}$.when.apply($,promises).done(function(){if(_this.options.$loadingImage){_this.options.$loadingImage.remove()}if(_this.options.dataset==null){return _this.tabManager.remove(_this.tabId)}_this._init();if(datasetOverlay){morpheus.DatasetUtil.overlay({dataset:_this.options.dataset,newDataset:datasetOverlay,rowAnnotationName:"id",newRowAnnotationName:"id",columnAnnotationName:"id",newColumnAnnotationName:"id"})}heatMapLoaded()})}};morpheus.HeatMap.SPACE_BETWEEN_HEAT_MAP_AND_ANNOTATIONS=6;morpheus.HeatMap.showTool=function(tool,heatMap,callback){if(tool.gui){var gui=tool.gui(heatMap.getProject());var formBuilder=new morpheus.FormBuilder;_.each(gui,function(item){formBuilder.append(item)});var tabId=heatMap.getTabManager().getActiveTabId();if(tool.init){tool.init(heatMap.getProject(),formBuilder,{heatMap:heatMap})}heatMap.trigger("beforeToolShown",{tool:tool,formBuilder:formBuilder});var okCallback=function(){var $dialogContent=$("
');var value=null;var $dialog=morpheus.FormBuilder.showInDraggableDiv({$content:$dialogContent,appendTo:heatMap.getContentEl(),width:"auto"});var input={};_.each(gui,function(item){input[item.name]=formBuilder.getValue(item.name)});setTimeout(function(){value=tool.execute({heatMap:heatMap,project:heatMap.getProject(),input:input});if(value instanceof Worker){$dialogContent.find("button").css("display","").on("click",function(){value.terminate()});value.onerror=function(e){value.terminate();morpheus.FormBuilder.showInModal({title:"Error",html:e,close:"Close",focus:heatMap.getFocusEl(),appendTo:heatMap.getContentEl()});if(e.stack){console.log(e.stack)}};var terminate=_.bind(value.terminate,value);value.terminate=function(){terminate();$dialog.remove();if(callback){callback(input)}}}else{if(value!=null&&typeof value.done==="function"){value.always(function(){if(callback){callback(input)}$dialog.remove()})}else{if(callback){callback(input)}$dialog.remove()}}},20);setTimeout(function(){if(!(value instanceof Worker)){$dialog.remove()}},5e3)};var $formDiv;tool.ok=function(){$formDiv.modal("hide");okCallback()};var guiOptions=$.extend({},{ok:true},gui.options);$formDiv=morpheus.FormBuilder.showOkCancel({title:tool.toString(),apply:tool.apply,ok:guiOptions.ok,cancel:guiOptions.cancel,size:guiOptions.size,draggable:true,content:formBuilder.$form,appendTo:heatMap.getContentEl(),align:"right",okCallback:okCallback,focus:heatMap.getFocusEl()})}else{tool.execute({heatMap:heatMap,project:heatMap.getProject(),input:{}});if(callback){callback({})}}};morpheus.HeatMap.getSpaces=function(groupByKeys,length,gapSize){var previousArray=[];var nkeys=groupByKeys.length;for(var keyIndex=0;keyIndex