(function(e){"use strict";u8.Base.GraphModel=function(e){$.extend(this,u8.Base.GraphModel.defaults,e);this.bind(e);this.vertices=this.vertices||[];this.edges=this.edges||[]};u8.Base.GraphModel.defaults={};$.extend(u8.Base.GraphModel.prototype,{dispose:function(){if(this._isDisposed){return}this.unbind();this._isDisposed=true},getData:function(e){return this.data&&this.data[e]},getVertex:function(t){return this.vertices.find(e.eq("id",t))},getEdge:function(t){return this.edges.find(e.eq("id",t))},getOutgoingEdges:function(e){return this.edges.filter(function(t){return t.source==e})},getIncomingEdges:function(e){return this.edges.filter(function(t){return t.target==e})},toTransport:function(){return{vertices:this.vertices,edges:this.edges}},addVertex:function(e,t){if(!e){return}var i=this.getVertex(e.id);if(i){return}if(!isNaN(t)){this.vertices.splice(t,0,e)}else{this.vertices.push(e)}this._onUpdate({what:"addVertex",value:e})},addEdge:function(e,t){if(!e){return}var i=this.getEdge(e.id);if(i){return}if(!isNaN(t)){this.edges.splice(t,0,e)}else{this.edges.push(e)}this._onUpdate({what:"addEdge",value:e})},removeVertex:function(t){var i=this.vertices.indexWhere(e.eq("id",t));if(i<0){return undefined}var s=this.vertices[i];var r=this.getIncomingEdges(t);for(var n=0;n<r.length;n++){this.removeEdge(r[n].id)}this.vertices.splice(i,1);this._onUpdate({what:"removeVertex",value:s});return s},removeEdge:function(t){var i=this.edges.indexWhere(e.eq("id",t));if(i<0){return undefined}var s=this.edges[i];this.edges.splice(i,1);this._onUpdate({what:"removeEdge",value:s});return s},isEmpty:function(){return!this.vertices||!this.vertices.length},toGML:function(){var e=['<graphml xmlns="http://graphml.graphdrawing.org/xmlns">'];e.push(['<graph id="G" edgedefault="directed" parse.nodes="8" parse.edges="7" parse.order="nodesfirst" parse.nodeids="free" parse.edgeids="free">']);var t=this.data;var i=u8.Base.Xml.escape;var s=function(e){var i=t[e];return i&&i.tableCaption.text||e};for(var r=0;r<this.vertices.length;r++){var n=this.vertices[r];e.push(['<node id="'+i(s(n.id))+'" />'])}for(r=0;r<this.edges.length;r++){var d=this.edges[r];e.push(['<edge id="'+i("e"+r)+'" source="'+i(s(d.source))+'" target="'+i(s(d.target))+'" />'])}e.push(["</graph>"]);e.push(["</graphml>"]);return e.join("")},_onUpdate:function(e){this.raise("Update",e)}});u8.Base.GraphModel.makeClass({name:"GraphModel",events:["Update"]});var t={};u8.Base.Graphs={createLayout:function(e,i){return t[e].create(i)},addLayout:function(e,i){t[e]=i}}})(u8._);