text: define(["mvc/history/job-dag","mvc/job/job-model","mvc/job/job-li","mvc/history/history-content-model","mvc/dataset/dataset-li","mvc/base-mvc","utils/localization","libs/d3"],function(a,b,c,d,e,f){window.JobDAG=a;var g=Backbone.View.extend(f.LoggableMixin).extend({className:"history-structure-component",_INITIAL_ZOOM_LEVEL:1,_MIN_ZOOM_LEVEL:.25,_LINK_ID_SEP:"-to-",_VERTEX_NAME_DATA_KEY:"vertex-name",JobItemClass:c.JobListItemView,ContentItemClass:e.DatasetListItemView,initialize:function(a){this.log(this+"(HistoryStructureComponent).initialize:",a),this.component=a.component,this._liMap={},this._createVertexItems(),this.zoomLevel=a.zoomLevel||this._INITIAL_ZOOM_LEVEL,this.layout=this._createLayout(a.layoutOptions)},_createVertexItems:function(){var a=this;a.component.eachVertex(function(b){var c,d=b.data.job?"job":"copy";"job"===d?c=a._createJobListItem(b):"copy"===d&&(c=a._createContentListItem(b)),a._liMap[b.name]=c}),a.debug("_liMap:",a._liMap)},_createJobListItem:function(a){this.debug("_createJobListItem:",a);var c=this,e=a.data,f=new b.Job(e.job),g=_.map(f.get("outputs"),function(a){var b="hda"===a.src?"dataset":"dataset_collection",e=d.typeIdStr(b,a.id);return c.model.contents.get(e)});f.outputCollection.reset(g),f.outputCollection.historyId=c.model.id;var h=new c.JobItemClass({model:f,tool:e.tool,jobData:e});return h.on("expanding expanded collapsing collapsed",c.renderGraph,c),h.foldout.on("view:expanding view:expanded view:collapsing view:collapsed",c.renderGraph,c),h},_createContentListItem:function(a){this.debug("_createContentListItem:",a);var b=this,c=a.data,e=d.typeIdStr(c.history_content_type,c.id);c=b.model.contents.get(e);var f=new b.ContentItemClass({model:c});return f.on("expanding expanded collapsing collapsed",b.renderGraph,b),f},layoutDefaults:{linkSpacing:16,linkWidth:0,linkHeight:0,jobWidth:300,jobHeight:300,jobSpacing:12,linkAdjX:4,linkAdjY:0},_createLayout:function(a){a=_.defaults(_.clone(a||{}),this.layoutDefaults);var b=this,c=_.values(b.component.vertices),d=_.extend(a,{nodeMap:{},links:[],svg:{width:0,height:0}});return c.forEach(function(a){var b={name:a.name,x:0,y:0};d.nodeMap[a.name]=b}),b.component.edges(function(a){var b={source:a.source,target:a.target};d.links.push(b)}),d},render:function(a){this.debug(this+".render:",a);var b=this;b.$el.html(["<header></header>",'<nav class="controls"></nav>','<figure class="graph"></figure>',"<footer></footer>"].join(""));var c=b.$graph();return b.component.eachVertex(function(a){b._liMap[a.name].render(0).$el.appendTo(c).data(b._VERTEX_NAME_DATA_KEY,a.name)}),b.renderGraph(),this},$graph:function(){return this.$(".graph")},renderGraph:function(a){function b(){c._updateLayout(),c.$graph().css("transform",["scale(",c.zoomLevel,",",c.zoomLevel,")"].join("")).width(c.layout.svg.width).height(c.layout.svg.height),c.renderSVG(),c.component.eachVertex(function(a){var b=c._liMap[a.name],d=c.layout.nodeMap[a.name];b.$el.css({top:d.y,left:d.x})})}this.debug(this+".renderGraph:",a);var c=this;return this.$el.is(":visible")?b():_.delay(b,0),this},_updateLayout:function(){this.debug(this+"._updateLayout:");var a=this,b=a.layout;b.linkHeight=b.linkSpacing*_.size(b.nodeMap),b.svg.height=b.linkHeight+b.jobHeight,b.svg.width=0;var c=0,d=b.linkHeight;return _.each(b.nodeMap,function(a){a.x=c,a.y=d,c+=b.jobWidth+b.jobSpacing}),b.svg.width=b.linkWidth=Math.max(b.svg.width,c),b.links.forEach(function(a){var c=b.nodeMap[a.source],d=b.nodeMap[a.target];a.x1=c.x+b.linkAdjX,a.y1=c.y+b.linkAdjY,a.x2=d.x+b.linkAdjX,a.y2=d.y+b.linkAdjY}),this.debug(JSON.stringify(b,null,"  ")),this.layout},renderSVG:function(){function a(a){d3.select(this).classed("highlighted",!0),c._liMap[a.source].$el.addClass("highlighted"),c._liMap[a.target].$el.addClass("highlighted")}function b(a){d3.select(this).classed("highlighted",!1),c._liMap[a.source].$el.removeClass("highlighted"),c._liMap[a.target].$el.removeClass("highlighted")}this.debug(this+".renderSVG:");var c=this,d=c.layout,e=d3.select(this.$graph().get(0)).select("svg");e.empty()&&(e=d3.select(this.$graph().get(0)).append("svg")),e.attr("width",d.svg.width).attr("height",d.svg.height);var f=e.selectAll(".connection").data(d.links);return f.enter().append("path").attr("class","connection").attr("id",function(a){return[a.source,a.target].join(c._LINK_ID_SEP)}).on("mouseover",a).on("mouseout",b),f.attr("d",function(a){return c._connectionPath(a)}),e.node()},_connectionPath:function(a){var b=0,c=(a.x2-a.x1)/this.layout.svg.width*this.layout.linkHeight;return["M",a.x1,",",a.y1," ","C",a.x1+b,",",a.y1-c," ",a.x2-b,",",a.y2-c," ",a.x2,",",a.y2].join("")},events:{"mouseover .graph > .list-item":function(a){this.highlightConnected(a.currentTarget,!0)},"mouseout  .graph > .list-item":function(a){this.highlightConnected(a.currentTarget,!1)}},highlightConnected:function(a,b){this.debug("highlightConnected",a,b),b=void 0!==b?b:!0;var c=this,d=c.component,e=b?jQuery.prototype.addClass:jQuery.prototype.removeClass,f=b?"connection highlighted":"connection",g=e.call($(a),"highlighted"),h=g.data(c._VERTEX_NAME_DATA_KEY);d.edges({target:h}).forEach(function(a){var b=a.source,d=c._liMap[b];e.call(d.$el,"highlighted"),c.$("#"+b+c._LINK_ID_SEP+h).attr("class",f)}),d.vertices[h].eachEdge(function(a){var b=a.target,d=c._liMap[b];e.call(d.$el,"highlighted"),c.$("#"+h+c._LINK_ID_SEP+b).attr("class",f)})},zoom:function(a){return this.zoomLevel=Math.min(1,Math.max(this._MIN_ZOOM_LEVEL,a)),this.renderGraph()},toString:function(){return"HistoryStructureComponent("+this.model.id+")"}}),h=g.extend({className:g.prototype.className+" vertical",layoutDefaults:_.extend(_.clone(g.prototype.layoutDefaults),{linkAdjX:0,linkAdjY:4}),_updateLayout:function(){this.debug(this+"._updateLayout:");var a=this,b=a.layout;b.linkWidth=b.linkSpacing*_.size(b.nodeMap),b.svg.width=b.linkWidth+b.jobWidth,b.svg.height=0;var c=b.linkWidth,d=0;return _.each(b.nodeMap,function(e,f){e.x=c,e.y=d;var g=a._liMap[f];d+=g.$el.height()+b.jobSpacing}),b.linkHeight=b.svg.height=Math.max(b.svg.height,d),b.links.forEach(function(a){var c=b.nodeMap[a.source],d=b.nodeMap[a.target];a.x1=c.x+b.linkAdjX,a.y1=c.y+b.linkAdjY,a.x2=d.x+b.linkAdjX,a.y2=d.y+b.linkAdjY}),this.debug(JSON.stringify(b,null,"  ")),b},_connectionPath:function(a){var b=0,c=(a.y2-a.y1)/this.layout.svg.height*this.layout.linkWidth;return["M",a.x1,",",a.y1," ","C",a.x1-c,",",a.y1+b," ",a.x2-c,",",a.y2-b," ",a.x2,",",a.y2].join("")},toString:function(){return"VerticalHistoryStructureComponent("+this.model.id+")"}}),i=Backbone.View.extend(f.LoggableMixin).extend({className:"history-structure",_layoutToComponentClass:{horizontal:g,vertical:h},_DEFAULT_LAYOUT:"vertical",initialize:function(a){this.layout=_.contains(a.layout,_.keys(this._layoutToComponentClass))?a.layout:this._DEFAULT_LAYOUT,this.log(this+"(HistoryStructureView).initialize:",a,this.model),this._processTools(a.tools),this._processJobs(a.jobs),this._createDAG()},_processTools:function(a){return this.tools=a||{},this.tools},_processJobs:function(a){return this.jobs=a||[],this.jobs},_createDAG:function(){this.dag=new a({historyContents:this.model.contents.toJSON(),tools:this.tools,jobs:this.jobs,excludeSetMetadata:!0,excludeErroredJobs:!0}),this.debug(this+".dag:",this.dag),this._createComponents()},_createComponents:function(){this.log(this+"._createComponents");var a=this;return a.componentViews=a.dag.weakComponentGraphArray().map(function(b){return a._createComponent(b)}),a.componentViews},_createComponent:function(a){this.log(this+"._createComponent:",a);var b=this._layoutToComponentClass[this.layout];return new b({model:this.model,component:a})},render:function(a){this.log(this+".render:",a);var b=this;return b.$el.addClass("clear").html(['<div class="controls"></div>','<div class="components"></div>'].join("")),b.componentViews.forEach(function(a){a.render().$el.appendTo(b.$components())}),b},$components:function(){return this.$(".components")},changeLayout:function(a){if(!(a in this._layoutToComponentClass))throw new Error(this+": unknown layout: "+a);return this.layout=a,this._createComponents(),this.render()},toString:function(){return"HistoryStructureView("+this.model.id+")"}});return i});
  //# sourceMappingURL=../../../maps/mvc/history/history-structure-view.js.map