All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.joint.clean.min.js Maven / Gradle / Ivy

There is a newer version: 5.2.2
Show newest version
/*! JointJS v0.9.2 - JavaScript diagramming library  2014-09-16 


This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
if("object"==typeof exports)var _=require("lodash");var joint={version:"0.9.2",dia:{},ui:{},layout:{},shapes:{},format:{},connectors:{},routers:{},util:{hashCode:function(t){var e=0;if(0==t.length)return e;for(var n=0;t.length>n;n++){var i=t.charCodeAt(n);e=(e<<5)-e+i,e&=e}return e},getByPath:function(t,e,n){n=n||".";for(var i,r=e.split(n);r.length;){if(i=r.shift(),!(i in t))return void 0;t=t[i]}return t},setByPath:function(t,e,n,i){i=i||".";var r=e.split(i),o=t,s=0;if(e.indexOf(i)>-1){for(var a=r.length;a-1>s;s++)o=o[r[s]]||(o[r[s]]={});o[r[a-1]]=n}else t[e]=n;return t},unsetByPath:function(t,e,n){n=n||".";var i=e.lastIndexOf(n);if(i>-1){var r=joint.util.getByPath(t,e.substr(0,i),n);r&&delete r[e.slice(i+1)]}else delete t[e];return t},flattenObject:function(t,e,n){e=e||".";var i={};for(var r in t)if(t.hasOwnProperty(r)){var o="object"==typeof t[r];if(o&&n&&n(t[r])&&(o=!1),o){var s=this.flattenObject(t[r],e,n);for(var a in s)s.hasOwnProperty(a)&&(i[r+e+a]=s[a])}else i[r]=t[r]}return i},uuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=0|16*Math.random(),n="x"==t?e:8|3&e;return n.toString(16)})},guid:function(t){return this.guid.id=this.guid.id||1,t.id=void 0===t.id?"j_"+this.guid.id++:t.id,t.id},mixin:function(){for(var t=arguments[0],e=1,n=arguments.length;n>e;e++){var i=arguments[e];(Object(i)===i||_.isFunction(i)||null!==i&&void 0!==i)&&_.each(i,function(e,n){return this.mixin.deep&&Object(e)===e?(t[n]||(t[n]=_.isArray(e)?[]:{}),this.mixin(t[n],e),void 0):(t[n]!==e&&(this.mixin.supplement&&t.hasOwnProperty(n)||(t[n]=e)),void 0)},this)}return t},supplement:function(){this.mixin.supplement=!0;var t=this.mixin.apply(this,arguments);return this.mixin.supplement=!1,t},deepMixin:function(){this.mixin.deep=!0;var t=this.mixin.apply(this,arguments);return this.mixin.deep=!1,t},deepSupplement:function(){this.mixin.deep=this.mixin.supplement=!0;var t=this.mixin.apply(this,arguments);return this.mixin.deep=this.mixin.supplement=!1,t},normalizeEvent:function(t){return t.originalEvent&&t.originalEvent.changedTouches&&t.originalEvent.changedTouches.length?t.originalEvent.changedTouches[0]:t},nextFrame:function(){var t,e="undefined"!=typeof window;if(e&&(t=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame),!t){var n=0;t=function(t){var e=(new Date).getTime(),i=Math.max(0,16-(e-n)),r=setTimeout(function(){t(e+i)},i);return n=e+i,r}}return e?_.bind(t,window):t}(),cancelFrame:function(){var t,e="undefined"!=typeof window;return e&&(t=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.msCancelAnimationFrame||window.msCancelRequestAnimationFrame||window.oCancelAnimationFrame||window.oCancelRequestAnimationFrame||window.mozCancelAnimationFrame||window.mozCancelRequestAnimationFrame),t=t||clearTimeout,e?_.bind(t,window):t}(),breakText:function(t,e,n,i){i=i||{};var r=e.width,o=e.height,s=i.svgDocument||V("svg").node,a=V("").attr(n||{}).node,l=a.firstChild,c=document.createTextNode("");l.appendChild(c),s.appendChild(a),i.svgDocument||document.body.appendChild(s);for(var u,h=t.split(" "),f=[],d=[],p=0,g=0,m=h.length;m>p;p++){var v=h[p];if(c.data=d[g]?d[g]+" "+v:v,r>=l.getComputedTextLength())d[g]=c.data,u&&(f[g++]=!0,u=0);else{if(!d[g]||u){var y=!!u;if(u=v.length-1,y||!u){if(!u){if(!d[g]){d=[];break}h.splice(p,2,v+h[p+1]),m--,f[g++]=!0,p--;continue}h[p]=v.substring(0,u),h[p+1]=v.substring(u)+h[p+1]}else h.splice(p,1,v.substring(0,u),v.substring(u)),m++,g&&!f[g-1]&&g--;p--;continue}g++,p--}if(o!==void 0){var x=x||1.25*a.getBBox().height;if(x*d.length>o){d.splice(Math.floor(o/x));break}}}return i.svgDocument?s.removeChild(a):document.body.removeChild(s),d.join("\n")},imageToDataUri:function(t,e){if("data:"===t.substr(0,"data:".length))return setTimeout(function(){e(null,t)},0);var n=document.createElement("canvas"),i=document.createElement("img");i.onload=function(){var r=n.getContext("2d");n.width=i.width,n.height=i.height,r.drawImage(i,0,0);try{var o=(t.split(".").pop()||"png","jpeg"),s=n.toDataURL(o)}catch(a){if(/\.svg$/.test(t)){var l=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");l.open("GET",t,!1),l.send(null);var c=l.responseText;return e(null,"data:image/svg+xml,"+encodeURIComponent(c))}console.error(i.src,"fails to convert",a)}e(null,s)},i.ononerror=function(){e(Error("Failed to load image."))},i.src=t},timing:{linear:function(t){return t},quad:function(t){return t*t},cubic:function(t){return t*t*t},inout:function(t){if(0>=t)return 0;if(t>=1)return 1;var e=t*t,n=e*t;return 4*(.5>t?n:3*(t-e)+n-.75)},exponential:function(t){return Math.pow(2,10*(t-1))},bounce:function(t){for(var e=0,n=1;1;e+=n,n/=2)if(t>=(7-4*e)/11){var i=(11-6*e-11*t)/4;return-i*i+n*n}},reverse:function(t){return function(e){return 1-t(1-e)}},reflect:function(t){return function(e){return.5*(.5>e?t(2*e):2-t(2-2*e))}},clamp:function(t,e,n){return e=e||0,n=n||1,function(i){var r=t(i);return e>r?e:r>n?n:r}},back:function(t){return t||(t=1.70158),function(e){return e*e*((t+1)*e-t)}},elastic:function(t){return t||(t=1.5),function(e){return Math.pow(2,10*(e-1))*Math.cos(20*Math.PI*t/3*e)}}},interpolate:{number:function(t,e){var n=e-t;return function(e){return t+n*e}},object:function(t,e){var n=_.keys(t);return function(i){var r,o,s={};for(r=n.length-1;-1!=r;r--)o=n[r],s[o]=t[o]+(e[o]-t[o])*i;return s}},hexColor:function(t,e){var n=parseInt(t.slice(1),16),i=parseInt(e.slice(1),16),r=255&n,o=(255&i)-r,s=65280&n,a=(65280&i)-s,l=16711680&n,c=(16711680&i)-l;return function(t){var e=255&r+o*t,n=65280&s+a*t,i=16711680&l+c*t;return"#"+(1<<24|e|n|i).toString(16).slice(1)}},unit:function(t,e){var n=/(-?[0-9]*.[0-9]*)(px|em|cm|mm|in|pt|pc|%)/,i=n.exec(t),r=n.exec(e),o=r[1].indexOf("."),s=o>0?r[1].length-o-1:0,t=+i[1],a=+r[1]-t,l=i[2];return function(e){return(t+a*e).toFixed(s)+l}}},filter:{blur:function(t){var e=_.isFinite(t.x)?t.x:2;return _.template('',{stdDeviation:_.isFinite(t.y)?[e,t.y]:e})},dropShadow:function(t){var e="SVGFEDropShadowElement"in window?'':'';return _.template(e,{dx:t.dx||0,dy:t.dy||0,opacity:_.isFinite(t.opacity)?t.opacity:1,color:t.color||"black",blur:_.isFinite(t.blur)?t.blur:4})},grayscale:function(t){var e=_.isFinite(t.amount)?t.amount:1;return _.template('',{a:.2126+.7874*(1-e),b:.7152-.7152*(1-e),c:.0722-.0722*(1-e),d:.2126-.2126*(1-e),e:.7152+.2848*(1-e),f:.0722-.0722*(1-e),g:.2126-.2126*(1-e),h:.0722+.9278*(1-e)})},sepia:function(t){var e=_.isFinite(t.amount)?t.amount:1;return _.template('',{a:.393+.607*(1-e),b:.769-.769*(1-e),c:.189-.189*(1-e),d:.349-.349*(1-e),e:.686+.314*(1-e),f:.168-.168*(1-e),g:.272-.272*(1-e),h:.534-.534*(1-e),i:.131+.869*(1-e)})},saturate:function(t){var e=_.isFinite(t.amount)?t.amount:1;return _.template('',{amount:1-e})},hueRotate:function(t){return _.template('',{angle:t.angle||0})},invert:function(t){var e=_.isFinite(t.amount)?t.amount:1;return _.template('',{amount:e,amount2:1-e})},brightness:function(t){return _.template('',{amount:_.isFinite(t.amount)?t.amount:1})},contrast:function(t){var e=_.isFinite(t.amount)?t.amount:1;return _.template('',{amount:e,amount2:.5-e/2})}},format:{number:function(t,e,n){function i(t){for(var e=t.length,i=[],r=0,o=n.grouping[0];e>0&&o>0;)i.push(t.substring(e-=o,e+o)),o=n.grouping[r=(r+1)%n.grouping.length];return i.reverse().join(n.thousands)}n=n||{currency:["$",""],decimal:".",thousands:",",grouping:[3]};var r=/(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i,o=r.exec(t),s=o[1]||" ",a=o[2]||">",l=o[3]||"",c=o[4]||"",u=o[5],h=+o[6],f=o[7],d=o[8],p=o[9],g=1,m="",v="",y=!1;switch(d&&(d=+d.substring(1)),(u||"0"===s&&"="===a)&&(u=s="0",a="=",f&&(h-=Math.floor((h-1)/4))),p){case"n":f=!0,p="g";break;case"%":g=100,v="%",p="f";break;case"p":g=100,v="%",p="r";break;case"b":case"o":case"x":case"X":"#"===c&&(m="0"+p.toLowerCase());case"c":case"d":y=!0,d=0;break;case"s":g=-1,p="r"}"$"===c&&(m=n.currency[0],v=n.currency[1]),"r"!=p||d||(p="g"),null!=d&&("g"==p?d=Math.max(1,Math.min(21,d)):("e"==p||"f"==p)&&(d=Math.max(0,Math.min(20,d))));var x=u&&f;if(y&&e%1)return"";var b=0>e||0===e&&0>1/e?(e=-e,"-"):l,w=v;if(0>g){var _=this.prefix(e,d);e=_.scale(e),w=_.symbol+v}else e*=g;e=this.convert(p,e,d);var k=e.lastIndexOf("."),C=0>k?e:e.substring(0,k),j=0>k?"":n.decimal+e.substring(k+1);!u&&f&&n.grouping&&(C=i(C));var T=m.length+C.length+j.length+(x?0:b.length),V=h>T?Array(T=h-T+1).join(s):"";return x&&(C=i(V+C)),b+=m,e=C+j,("<"===a?b+e+V:">"===a?V+b+e:"^"===a?V.substring(0,T>>=1)+b+e+V.substring(T):b+(x?e:V+e))+w},string:function(t,e){for(var n,i="{",r=!1,o=[];-1!==(n=t.indexOf(i));){var s,a,l;if(s=t.slice(0,n),r){a=s.split(":"),l=a.shift().split("."),s=e;for(var c=0;l.length>c;c++)s=s[l[c]];a.length&&(s=this.number(a,s))}o.push(s),t=t.slice(n+1),i=(r=!r)?"}":"{"}return o.push(t),o.join("")},convert:function(t,e,n){switch(t){case"b":return e.toString(2);case"c":return String.fromCharCode(e);case"o":return e.toString(8);case"x":return e.toString(16);case"X":return e.toString(16).toUpperCase();case"g":return e.toPrecision(n);case"e":return e.toExponential(n);case"f":return e.toFixed(n);case"r":return(e=this.round(e,this.precision(e,n))).toFixed(Math.max(0,Math.min(20,this.precision(e*(1+1e-15),n))));default:return e+""}},round:function(t,e){return e?Math.round(t*(e=Math.pow(10,e)))/e:Math.round(t)},precision:function(t,e){return e-(t?Math.ceil(Math.log(t)/Math.LN10):1)},prefix:function(t,e){var n=_.map(["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],function(t,e){var n=Math.pow(10,3*abs(8-e));return{scale:e>8?function(t){return t/n}:function(t){return t*n},symbol:t}}),i=0;return t&&(0>t&&(t*=-1),e&&(t=d3.round(t,this.precision(t,e))),i=1+Math.floor(1e-12+Math.log(t)/Math.LN10),i=Math.max(-24,Math.min(24,3*Math.floor((0>=i?i+1:i-1)/3)))),n[8+i/3]}}}};if("object"==typeof exports&&(module.exports=joint),"object"==typeof exports)var joint={dia:{Link:require("./joint.dia.link").Link,Element:require("./joint.dia.element").Element},shapes:require("../plugins/shapes")},Backbone=require("backbone"),_=require("lodash"),g=require("./geometry");if(joint.dia.GraphCells=Backbone.Collection.extend({initialize:function(){this.on("change:z",this.sort,this)},model:function(t,e){if("link"===t.type)return new joint.dia.Link(t,e);var n=t.type.split(".")[0],i=t.type.split(".")[1];return joint.shapes[n]&&joint.shapes[n][i]?new joint.shapes[n][i](t,e):new joint.dia.Element(t,e)},comparator:function(t){return t.get("z")||0},getConnectedLinks:function(t,e){e=e||{},_.isUndefined(e.inbound)&&_.isUndefined(e.outbound)&&(e.inbound=e.outbound=!0);var n=[];return this.each(function(i){var r=i.get("source"),o=i.get("target");r&&r.id===t.id&&e.outbound&&n.push(i),o&&o.id===t.id&&e.inbound&&n.push(i)}),n}}),joint.dia.Graph=Backbone.Model.extend({initialize:function(){this.set("cells",new joint.dia.GraphCells),this.get("cells").on("all",this.trigger,this),this.get("cells").on("remove",this.removeCell,this)},toJSON:function(){var t=Backbone.Model.prototype.toJSON.apply(this,arguments);return t.cells=this.get("cells").toJSON(),t},fromJSON:function(t,e){if(!t.cells)throw Error("Graph JSON must contain cells array.");this.set(_.omit(t,"cells"),e),this.resetCells(t.cells,e)},clear:function(t){this.trigger("batch:start"),this.get("cells").remove(this.get("cells").models,t),this.trigger("batch:stop")},_prepareCell:function(t){return t instanceof Backbone.Model&&_.isUndefined(t.get("z"))?t.set("z",this.maxZIndex()+1,{silent:!0}):_.isUndefined(t.z)&&(t.z=this.maxZIndex()+1),t},maxZIndex:function(){var t=this.get("cells").last();return t?t.get("z")||0:0},addCell:function(t,e){return _.isArray(t)?this.addCells(t,e):(this.get("cells").add(this._prepareCell(t),e||{}),this)},addCells:function(t,e){return e=e||{},e.position=t.length,_.each(t,function(t){e.position--,this.addCell(t,e)},this),this},resetCells:function(t,e){return this.get("cells").reset(_.map(t,this._prepareCell,this),e),this},removeCell:function(t,e,n){n&&n.disconnectLinks?this.disconnectLinks(t):this.removeLinks(t),this.get("cells").remove(t,{silent:!0})},getCell:function(t){return this.get("cells").get(t)},getElements:function(){return this.get("cells").filter(function(t){return t instanceof joint.dia.Element})},getLinks:function(){return this.get("cells").filter(function(t){return t instanceof joint.dia.Link})},getConnectedLinks:function(t,e){return this.get("cells").getConnectedLinks(t,e)},getNeighbors:function(t){var e=this.getConnectedLinks(t),n=[],i=this.get("cells");return _.each(e,function(e){var r=e.get("source"),o=e.get("target");if(!r.x){var s=i.get(r.id);s!==t&&n.push(s)}if(!o.x){var a=i.get(o.id);a!==t&&n.push(a)}}),n},disconnectLinks:function(t){_.each(this.getConnectedLinks(t),function(e){e.set(e.get("source").id===t.id?"source":"target",g.point(0,0))})},removeLinks:function(t){_.invoke(this.getConnectedLinks(t),"remove")},findModelsFromPoint:function(t){return _.filter(this.getElements(),function(e){return e.getBBox().containsPoint(t)})},findModelsInArea:function(t){return _.filter(this.getElements(),function(e){return e.getBBox().intersect(t)})},getBBox:function(t){var e={x:1/0,y:1/0},n={x:0,y:0};return _.each(t,function(t){var i=t.getBBox();e.x=Math.min(e.x,i.x),e.y=Math.min(e.y,i.y),n.x=Math.max(n.x,i.x+i.width),n.y=Math.max(n.y,i.y+i.height)}),g.rect(e.x,e.y,n.x-e.x,n.y-e.y)}}),"object"==typeof exports&&(module.exports.Graph=joint.dia.Graph),"object"==typeof exports)var joint={util:require("./core").util,dia:{Link:require("./joint.dia.link").Link}},Backbone=require("backbone"),_=require("lodash");if(joint.dia.Cell=Backbone.Model.extend({constructor:function(t,e){var n,i=t||{};this.cid=_.uniqueId("c"),this.attributes={},e&&e.collection&&(this.collection=e.collection),e&&e.parse&&(i=this.parse(i,e)||{}),(n=_.result(this,"defaults"))&&(i=_.merge({},n,i)),this.set(i,e),this.changed={},this.initialize.apply(this,arguments)},toJSON:function(){var t=this.constructor.prototype.defaults.attrs||{},e=this.attributes.attrs,n={};_.each(e,function(e,i){var r=t[i];_.each(e,function(t,e){_.isObject(t)&&!_.isArray(t)?_.each(t,function(t,o){r&&r[e]&&_.isEqual(r[e][o],t)||(n[i]=n[i]||{},(n[i][e]||(n[i][e]={}))[o]=t)}):r&&_.isEqual(r[e],t)||(n[i]=n[i]||{},n[i][e]=t)})});var i=_.cloneDeep(_.omit(this.attributes,"attrs"));return i.attrs=n,i},initialize:function(t){t&&t.id||this.set("id",joint.util.uuid(),{silent:!0}),this._transitionIds={},this.processPorts(),this.on("change:attrs",this.processPorts,this)},processPorts:function(){var t=this.ports,e={};_.each(this.get("attrs"),function(t){t&&t.port&&(_.isUndefined(t.port.id)?e[t.port]={id:t.port}:e[t.port.id]=t.port)});var n={};if(_.each(t,function(t,i){e[i]||(n[i]=!0)}),this.collection&&!_.isEmpty(n)){var i=this.collection.getConnectedLinks(this,{inbound:!0});_.each(i,function(t){n[t.get("target").port]&&t.remove()});var r=this.collection.getConnectedLinks(this,{outbound:!0});_.each(r,function(t){n[t.get("source").port]&&t.remove()})}this.ports=e},remove:function(t){var e=this.collection;e&&e.trigger("batch:start");var n=this.get("parent");if(n){var i=this.collection&&this.collection.get(n);i.unembed(this)}return _.invoke(this.getEmbeddedCells(),"remove",t),this.trigger("remove",this,this.collection,t),e&&e.trigger("batch:stop"),this},toFront:function(){return this.collection&&this.set("z",(this.collection.last().get("z")||0)+1),this},toBack:function(){return this.collection&&this.set("z",(this.collection.first().get("z")||0)-1),this},embed:function(t){if(this.get("parent")==t.id)throw Error("Recursive embedding not allowed.");return this.trigger("batch:start"),t.set("parent",this.id),this.set("embeds",_.uniq((this.get("embeds")||[]).concat([t.id]))),this.trigger("batch:stop"),this},unembed:function(t){this.trigger("batch:start");var e=t.id;return t.unset("parent"),this.set("embeds",_.without(this.get("embeds"),e)),this.trigger("batch:stop"),this},getEmbeddedCells:function(){return this.collection?_.map(this.get("embeds")||[],function(t){return this.collection.get(t)},this):[]},clone:function(t){t=t||{};var e=Backbone.Model.prototype.clone.apply(this,arguments);if(e.set("id",joint.util.uuid(),{silent:!0}),e.set("embeds",""),!t.deep)return e;var n=_.sortBy(this.getEmbeddedCells(),function(t){return t instanceof joint.dia.Element}),i=[e],r={};return _.each(n,function(t){var n=t.clone({deep:!0});e.embed(n[0]),_.each(n,function(n){if(n instanceof joint.dia.Link)return n.get("source").id==this.id&&n.prop("source",{id:e.id}),n.get("target").id==this.id&&n.prop("target",{id:e.id}),r[t.id]=n,void 0;i.push(n);var o=this.collection.getConnectedLinks(t,{inbound:!0});_.each(o,function(t){var e=r[t.id]||t.clone();r[t.id]=e,e.prop("target",{id:n.id})});var s=this.collection.getConnectedLinks(t,{outbound:!0});_.each(s,function(t){var e=r[t.id]||t.clone();r[t.id]=e,e.prop("source",{id:n.id})})},this)},this),i=i.concat(_.values(r))},prop:function(t,e,n){var i="/";if(_.isString(t)){if(e!==void 0){var r=t,o=r.split("/"),s=o[0];if(1==o.length)return this.set(s,e,n);var a={},l=a,c=s;_.each(_.rest(o),function(t){l=l[c]=_.isFinite(Number(t))?[]:{},c=t}),a=joint.util.setByPath(a,r,e,"/");var u=_.merge({},this.attributes,a);return this.set(s,u[s],n)}return joint.util.getByPath(this.attributes,t,i)}return this.set(_.merge({},this.attributes,t),e)},attr:function(t,e,n){var i=this.get("attrs"),r="/";if(_.isString(t)){if(e!==void 0){var o={};return joint.util.setByPath(o,t,e,r),this.set("attrs",_.merge({},i,o),n)}return joint.util.getByPath(i,t,r)}return this.set("attrs",_.merge({},i,t),e,n)},removeAttr:function(t,e){if(_.isArray(t))return _.each(t,function(t){this.removeAttr(t,e)},this),this;var n=joint.util.unsetByPath(_.merge({},this.get("attrs")),t,"/");return this.set("attrs",n,_.extend({dirty:!0},e))},transition:function(t,e,n,i){i=i||"/";var r={duration:100,delay:10,timingFunction:joint.util.timing.linear,valueFunction:joint.util.interpolate.number};n=_.extend(r,n);var o,s=0,a=_.bind(function(e){var i,r,l;s=s||e,e-=s,r=e/n.duration,1>r?this._transitionIds[t]=i=joint.util.nextFrame(a):(r=1,delete this._transitionIds[t]),l=o(n.timingFunction(r)),n.transitionId=i,this.prop(t,l,n),i||this.trigger("transition:end",this,t)},this),l=_.bind(function(r){this.stopTransitions(t),o=n.valueFunction(joint.util.getByPath(this.attributes,t,i),e),this._transitionIds[t]=joint.util.nextFrame(r),this.trigger("transition:start",this,t)},this);return _.delay(l,n.delay,a)},getTransitions:function(){return _.keys(this._transitionIds)},stopTransitions:function(t,e){e=e||"/";var n=t&&t.split(e);return _(this._transitionIds).keys().filter(n&&function(t){return _.isEqual(n,t.split(e).slice(0,n.length))}).each(function(t){joint.util.cancelFrame(this._transitionIds[t]),delete this._transitionIds[t],this.trigger("transition:end",this,t)},this),this},addTo:function(t){return t.addCell(this),this},findView:function(t){return t.findViewByModel(this)}}),joint.dia.CellView=Backbone.View.extend({tagName:"g",attributes:function(){return{"model-id":this.model.id}},constructor:function(t){this._configure(t),Backbone.View.apply(this,arguments)},_configure:function(t){this.options&&(t=_.extend({},_.result(this,"options"),t)),this.options=t,this.options.id=this.options.id||joint.util.guid(this)},initialize:function(){_.bindAll(this,"remove","update"),this.$el.data("view",this),this.listenTo(this.model,"remove",this.remove),this.listenTo(this.model,"change:attrs",this.onChangeAttrs)},onChangeAttrs:function(t,e,n){return n.dirty?this.render():this.update()},_ensureElement:function(){var t;if(this.el)t=_.result(this,"el");else{var e=_.extend({id:this.id},_.result(this,"attributes"));this.className&&(e["class"]=_.result(this,"className")),t=V(_.result(this,"tagName"),e).node}this.setElement(t,!1)},findBySelector:function(t){var e="."===t?this.$el:this.$el.find(t);return e},notify:function(t){if(this.paper){var e=Array.prototype.slice.call(arguments,1);this.trigger.apply(this,[t].concat(e)),this.paper.trigger.apply(this.paper,[t,this].concat(e))}},getStrokeBBox:function(t){var e=!!t;t=t||this.el;var n,i=V(t).bbox(!1,this.paper.viewport);return n=e?V(t).attr("stroke-width"):this.model.attr("rect/stroke-width")||this.model.attr("circle/stroke-width")||this.model.attr("ellipse/stroke-width")||this.model.attr("path/stroke-width"),n=parseFloat(n)||0,g.rect(i).moveAndExpand({x:-n/2,y:-n/2,width:n,height:n})},getBBox:function(){return V(this.el).bbox()},highlight:function(t){t=t?this.$(t)[0]||this.el:this.el,V(t).addClass("highlighted")},unhighlight:function(t){t=t?this.$(t)[0]||this.el:this.el,V(t).removeClass("highlighted")},findMagnet:function(t){var e=this.$(t);if(0===e.length||e[0]===this.el){var n=this.model.get("attrs")||{};return n["."]&&n["."].magnet===!1?void 0:this.el}return e.attr("magnet")?e[0]:this.findMagnet(e.parent())},applyFilter:function(t,e){var n=this.findBySelector(t),i=e.name+this.paper.svg.id+joint.util.hashCode(JSON.stringify(e));if(!this.paper.svg.getElementById(i)){var r=joint.util.filter[e.name]&&joint.util.filter[e.name](e.args||{});if(!r)throw Error("Non-existing filter "+e.name);var o=V(r);o.attr({filterUnits:"objectBoundingBox",x:-1,y:-1,width:3,height:3}),e.attrs&&o.attr(e.attrs),o.node.id=i,V(this.paper.svg).defs().append(o)}n.each(function(){V(this).attr("filter","url(#"+i+")")})},applyGradient:function(t,e,n){var i=this.findBySelector(t),r=n.type+this.paper.svg.id+joint.util.hashCode(JSON.stringify(n));if(!this.paper.svg.getElementById(r)){var o=["<"+n.type+">",_.map(n.stops,function(t){return''}).join(""),""].join(""),s=V(o);n.attrs&&s.attr(n.attrs),s.node.id=r,V(this.paper.svg).defs().append(s)}i.each(function(){V(this).attr(e,"url(#"+r+")")})},getSelector:function(t,e){if(t===this.el)return e;var n=$(t).index();return e=t.tagName+":nth-child("+(n+1)+")"+" "+(e||""),this.getSelector($(t).parent()[0],e+" ")},pointerdblclick:function(t,e,n){this.notify("cell:pointerdblclick",t,e,n)},pointerclick:function(t,e,n){this.notify("cell:pointerclick",t,e,n)},pointerdown:function(t,e,n){this.model.collection&&(this.model.trigger("batch:start"),this._collection=this.model.collection),this.notify("cell:pointerdown",t,e,n)},pointermove:function(t,e,n){this.notify("cell:pointermove",t,e,n)},pointerup:function(t,e,n){this.notify("cell:pointerup",t,e,n),this._collection&&(this._collection.trigger("batch:stop"),delete this._collection)}}),"object"==typeof exports&&(module.exports.Cell=joint.dia.Cell,module.exports.CellView=joint.dia.CellView),"object"==typeof exports)var joint={util:require("./core").util,dia:{Cell:require("./joint.dia.cell").Cell,CellView:require("./joint.dia.cell").CellView}},Backbone=require("backbone"),_=require("lodash");if(joint.dia.Element=joint.dia.Cell.extend({defaults:{position:{x:0,y:0},size:{width:1,height:1},angle:0},position:function(t,e){this.set("position",{x:t,y:e})},translate:function(t,e,n){if(e=e||0,0===t&&0===e)return this;var i=this.get("position")||{x:0,y:0},r={x:i.x+t||0,y:i.y+e||0};return n&&n.transition?(_.isObject(n.transition)||(n.transition={}),this.transition("position",r,_.extend({},n.transition,{valueFunction:joint.util.interpolate.object}))):(this.set("position",r,n),_.invoke(this.getEmbeddedCells(),"translate",t,e,n)),this},resize:function(t,e){return this.trigger("batch:start"),this.set("size",{width:t,height:e}),this.trigger("batch:stop"),this},rotate:function(t,e,n){if(n){var i=this.getBBox().center(),r=this.get("size"),o=this.get("position");i.rotate(n,(this.get("angle")||0)-t);var s=i.x-r.width/2-o.x,a=i.y-r.height/2-o.y;this.trigger("batch:start"),this.translate(s,a),this.rotate(t,e),this.trigger("batch:stop")}else this.set("angle",e?t:((this.get("angle")||0)+t)%360);return this},getBBox:function(){var t=this.get("position"),e=this.get("size");return g.rect(t.x,t.y,e.width,e.height)}}),joint.dia.ElementView=joint.dia.CellView.extend({className:function(){return"element "+this.model.get("type").split(".").join(" ")},initialize:function(){_.bindAll(this,"translate","resize","rotate"),joint.dia.CellView.prototype.initialize.apply(this,arguments),this.listenTo(this.model,"change:position",this.translate),this.listenTo(this.model,"change:size",this.resize),this.listenTo(this.model,"change:angle",this.rotate)},update:function(t,e){var n=this.model.get("attrs"),i=V(this.$(".rotatable")[0]);if(i){var r=i.attr("transform");i.attr("transform","")}var o=[];_.each(e||n,function(t,e){var n=this.findBySelector(e);if(0!==n.length){var i=["style","text","html","ref-x","ref-y","ref-dx","ref-dy","ref-width","ref-height","ref","x-alignment","y-alignment","port"];_.isObject(t.filter)&&(i.push("filter"),this.applyFilter(e,t.filter)),_.isObject(t.fill)&&(i.push("fill"),this.applyGradient(e,"fill",t.fill)),_.isObject(t.stroke)&&(i.push("stroke"),this.applyGradient(e,"stroke",t.stroke)),_.isUndefined(t.text)||n.each(function(){V(this).text(t.text+"",{lineHeight:t.lineHeight})});var r=_.omit(t,i);n.each(function(){V(this).attr(r)}),t.port&&n.attr("port",_.isUndefined(t.port.id)?t.port:t.port.id),t.style&&n.css(t.style),_.isUndefined(t.html)||n.each(function(){$(this).html(t.html+"")}),_.isUndefined(t["ref-x"])&&_.isUndefined(t["ref-y"])&&_.isUndefined(t["ref-dx"])&&_.isUndefined(t["ref-dy"])&&_.isUndefined(t["x-alignment"])&&_.isUndefined(t["y-alignment"])&&_.isUndefined(t["ref-width"])&&_.isUndefined(t["ref-height"])||_.each(n,function(t,e,n){var i=$(t);i.selector=n.selector,o.push(i)})}},this);var s=this.el.getBBox();e=e||{},_.each(o,function(t){var i=e[t.selector],r=i?_.merge({},n[t.selector],i):n[t.selector];this.positionRelative(t,s,r)},this),i&&i.attr("transform",r||"")},positionRelative:function(t,e,n){function i(t){return _.isNumber(t)&&!_.isNaN(t)}var r=n.ref,o=parseFloat(n["ref-x"]),s=parseFloat(n["ref-y"]),a=parseFloat(n["ref-dx"]),l=parseFloat(n["ref-dy"]),c=n["y-alignment"],u=n["x-alignment"],h=parseFloat(n["ref-width"]),f=parseFloat(n["ref-height"]),d=_.contains(_.pluck(_.pluck(t.parents("g"),"className"),"baseVal"),"scalable");r&&(e=V(this.findBySelector(r)[0]).bbox(!1,this.el));var p=V(t[0]);p.attr("transform")&&p.attr("transform",p.attr("transform").replace(/translate\([^)]*\)/g,"").trim()||"");var g=0,m=0;if(i(h)&&(h>=0&&1>=h?p.attr("width",h*e.width):p.attr("width",Math.max(h+e.width,0))),i(f)&&(f>=0&&1>=f?p.attr("height",f*e.height):p.attr("height",Math.max(f+e.height,0))),i(a))if(d){var v=V(this.$(".scalable")[0]).scale();g=e.x+e.width+a/v.sx}else g=e.x+e.width+a;if(i(l))if(d){var v=V(this.$(".scalable")[0]).scale();m=e.y+e.height+l/v.sy}else m=e.y+e.height+l;if(i(o))if(o>0&&1>o)g=e.x+e.width*o;else if(d){var v=V(this.$(".scalable")[0]).scale();g=e.x+o/v.sx}else g=e.x+o;if(i(s))if(s>0&&1>s)m=e.y+e.height*s;else if(d){var v=V(this.$(".scalable")[0]).scale();m=e.y+s/v.sy}else m=e.y+s;var y=p.bbox(!1,this.paper.viewport);"middle"===c?m-=y.height/2:i(c)&&(m+=c>-1&&1>c?y.height*c:c),"middle"===u?g-=y.width/2:i(u)&&(g+=u>-1&&1>u?y.width*u:u),p.translate(g,m)},renderMarkup:function(){var t=this.model.markup||this.model.get("markup");if(!t)throw Error("properties.markup is missing while the default render() implementation is used.");var e=V(t);V(this.el).append(e)},render:function(){return this.$el.empty(),this.renderMarkup(),this.update(),this.resize(),this.rotate(),this.translate(),this},scale:function(t,e){V(this.el).scale(t,e)},resize:function(){var t=this.model.get("size")||{width:1,height:1},e=this.model.get("angle")||0,n=V(this.$(".scalable")[0]);if(n){var i=n.bbox(!0);n.attr("transform","scale("+t.width/(i.width||1)+","+t.height/(i.height||1)+")");var r=V(this.$(".rotatable")[0]),o=r&&r.attr("transform");if(o&&"null"!==o){r.attr("transform",o+" rotate("+-e+","+t.width/2+","+t.height/2+")");var s=n.bbox(!1,this.paper.viewport);this.model.set("position",{x:s.x,y:s.y}),this.rotate()}this.update()}},translate:function(){var t=this.model.get("position")||{x:0,y:0};V(this.el).attr("transform","translate("+t.x+","+t.y+")")},rotate:function(){var t=V(this.$(".rotatable")[0]);if(t){var e=this.model.get("angle")||0,n=this.model.get("size")||{width:1,height:1},i=n.width/2,r=n.height/2;t.attr("transform","rotate("+e+","+i+","+r+")")}},pointerdown:function(t,e,n){if(t.target.getAttribute("magnet")&&this.paper.options.validateMagnet.call(this.paper,this,t.target)){this.model.trigger("batch:start");var i=this.paper.getDefaultLink(this,t.target);i.set({source:{id:this.model.id,selector:this.getSelector(t.target),port:$(t.target).attr("port")},target:{x:e,y:n}}),this.paper.model.addCell(i),this._linkView=this.paper.findViewByModel(i),this._linkView.startArrowheadMove("target")}else this._dx=e,this._dy=n,joint.dia.CellView.prototype.pointerdown.apply(this,arguments)},pointermove:function(t,e,n){if(this._linkView)this._linkView.pointermove(t,e,n);else{var i=this.paper.options.gridSize,r=_.isFunction(this.options.interactive)?this.options.interactive(this,"pointermove"):this.options.interactive;if(r!==!1){var o=this.model.get("position");this.model.translate(g.snapToGrid(o.x,i)-o.x+g.snapToGrid(e-this._dx,i),g.snapToGrid(o.y,i)-o.y+g.snapToGrid(n-this._dy,i))}this._dx=g.snapToGrid(e,i),this._dy=g.snapToGrid(n,i),joint.dia.CellView.prototype.pointermove.apply(this,arguments)}},pointerup:function(t,e,n){this._linkView?(this._linkView.pointerup(t,e,n),delete this._linkView,this.model.trigger("batch:stop")):joint.dia.CellView.prototype.pointerup.apply(this,arguments)}}),"object"==typeof exports&&(module.exports.Element=joint.dia.Element,module.exports.ElementView=joint.dia.ElementView),"object"==typeof exports)var joint={dia:{Cell:require("./joint.dia.cell").Cell,CellView:require("./joint.dia.cell").CellView}},Backbone=require("backbone"),_=require("lodash"),g=require("./geometry");if(joint.dia.Link=joint.dia.Cell.extend({markup:['','','','','','','',''].join(""),labelMarkup:['',"","",""].join(""),toolMarkup:['','','','',"Remove link.","",'','','',"Link options.","",""].join(""),vertexMarkup:['','','','',"Remove vertex.","",""].join(""),arrowheadMarkup:['','',""].join(""),defaults:{type:"link"},disconnect:function(){return this.set({source:g.point(0,0),target:g.point(0,0)})
},label:function(t,e){t=t||0;var n=this.get("labels")||[];if(0===arguments.length||1===arguments.length)return n[t];var i=_.merge({},n[t],e),r=n.slice();return r[t]=i,this.set({labels:r})},translate:function(t,e,n){var i={},r=this.get("source"),o=this.get("target"),s=this.get("vertices");return r.id||(i.source={x:r.x+t,y:r.y+e}),o.id||(i.target={x:o.x+t,y:o.y+e}),s&&s.length&&(i.vertices=_.map(s,function(n){return{x:n.x+t,y:n.y+e}})),this.set(i,n)}}),joint.dia.LinkView=joint.dia.CellView.extend({className:function(){return _.unique(this.model.get("type").split(".").concat("link")).join(" ")},options:{shortLinkLength:100},initialize:function(){joint.dia.CellView.prototype.initialize.apply(this,arguments),"function"!=typeof this.constructor.prototype.watchSource&&(this.constructor.prototype.watchSource=this._createWatcher("source"),this.constructor.prototype.watchTarget=this._createWatcher("target")),this._labelCache={},this._markerCache={},this.startListening()},startListening:function(){this.listenTo(this.model,"change:markup",this.render),this.listenTo(this.model,"change:smooth change:manhattan change:router change:connector",this.update),this.listenTo(this.model,"change:toolMarkup",function(){this.renderTools().updateToolsPosition()}),this.listenTo(this.model,"change:labels change:labelMarkup",function(){this.renderLabels().updateLabelPositions()}),this.listenTo(this.model,"change:vertices change:vertexMarkup",function(){this.renderVertexMarkers().update()}),this.listenTo(this.model,"change:source",function(t,e){this.watchSource(t,e).update()}),this.listenTo(this.model,"change:target",function(t,e){this.watchTarget(t,e).update()})},render:function(){this.$el.empty();var t=V(this.model.get("markup")||this.model.markup);if(_.isArray(t)||(t=[t]),this._V={},_.each(t,function(t){var e=t.attr("class");e&&(this._V[$.camelCase(e)]=t)},this),!this._V.connection)throw Error("link: no connection path in the markup");return this.renderTools(),this.renderVertexMarkers(),this.renderArrowheadMarkers(),V(this.el).append(t),this.renderLabels(),this.watchSource(this.model,this.model.get("source")).watchTarget(this.model,this.model.get("target")).update(),this},renderLabels:function(){if(!this._V.labels)return this;this._labelCache={};var t=$(this._V.labels.node).empty(),e=this.model.get("labels")||[];if(!e.length)return this;var n=_.template(this.model.get("labelMarkup")||this.model.labelMarkup),i=V(n());return _.each(e,function(e,n){var r=i.clone().node;this._labelCache[n]=V(r);var o=$(r).find("text"),s=$(r).find("rect"),a=_.extend({"text-anchor":"middle","font-size":14},joint.util.getByPath(e,"attrs/text","/"));o.attr(_.omit(a,"text")),_.isUndefined(a.text)||V(o[0]).text(a.text+""),t.append(r);var l=V(o[0]).bbox(!0,t[0]);V(o[0]).translate(0,-l.height/2);var c=_.extend({fill:"white",rx:3,ry:3},joint.util.getByPath(e,"attrs/rect","/"));s.attr(_.extend(c,{x:l.x,y:l.y-l.height/2,width:l.width,height:l.height}))},this),this},renderTools:function(){if(!this._V.linkTools)return this;var t=$(this._V.linkTools.node).empty(),e=_.template(this.model.get("toolMarkup")||this.model.toolMarkup),n=V(e());return t.append(n.node),this._toolCache=n,this},renderVertexMarkers:function(){if(!this._V.markerVertices)return this;var t=$(this._V.markerVertices.node).empty(),e=_.template(this.model.get("vertexMarkup")||this.model.vertexMarkup);return _.each(this.model.get("vertices"),function(n,i){t.append(V(e(_.extend({idx:i},n))).node)}),this},renderArrowheadMarkers:function(){if(!this._V.markerArrowheads)return this;var t=$(this._V.markerArrowheads.node);t.empty();var e=_.template(this.model.get("arrowheadMarkup")||this.model.arrowheadMarkup);return this._V.sourceArrowhead=V(e({end:"source"})),this._V.targetArrowhead=V(e({end:"target"})),t.append(this._V.sourceArrowhead.node,this._V.targetArrowhead.node),this},update:function(){_.each(this.model.get("attrs"),function(t,e){_.isObject(t.filter)?(this.findBySelector(e).attr(_.omit(t,"filter")),this.applyFilter(e,t.filter)):this.findBySelector(e).attr(t)},this);var t=this.route=this.findRoute(this.model.get("vertices")||[]);this._findConnectionPoints(t);var e=this.getPathData(t);return this._V.connection.attr("d",e),this._V.connectionWrap&&this._V.connectionWrap.attr("d",e),this._translateAndAutoOrientArrows(this._V.markerSource,this._V.markerTarget),this.updateLabelPositions(),this.updateToolsPosition(),this.updateArrowheadMarkers(),delete this.options.perpendicular,this},_findConnectionPoints:function(t){var e,n,i,r,o=_.first(t);e=this.getConnectionPoint("source",this.model.get("source"),o||this.model.get("target")).round();var s=_.last(t);n=this.getConnectionPoint("target",this.model.get("target"),s||e).round();var a=this._markerCache;this._V.markerSource&&(a.sourceBBox=a.sourceBBox||this._V.markerSource.bbox(!0),i=g.point(e).move(o||n,-1*a.sourceBBox.width*this._V.markerSource.scale().sx).round()),this._V.markerTarget&&(a.targetBBox=a.targetBBox||this._V.markerTarget.bbox(!0),r=g.point(n).move(s||e,-1*a.targetBBox.width*this._V.markerTarget.scale().sx).round()),a.sourcePoint=i||e,a.targetPoint=r||n,this.sourcePoint=e,this.targetPoint=n},updateLabelPositions:function(){if(!this._V.labels)return this;var t=this.model.get("labels")||[];if(!t.length)return this;var e=this._V.connection.node,n=e.getTotalLength();return _.each(t,function(t,i){var r=t.position;r=r>n?n:r,r=0>r?n+r:r,r=r>1?r:n*r;var o=e.getPointAtLength(r);this._labelCache[i].attr("transform","translate("+o.x+", "+o.y+")")},this),this},updateToolsPosition:function(){if(!this._V.linkTools)return this;var t="",e=40;this.getConnectionLength()s);)n=i.slice();return-1===a&&(a=0,n.splice(a,0,t)),this.model.set("vertices",n),a},sendToken:function(t,e,n){e=e||1e3,V(this.paper.viewport).append(t),V(t).animateAlongPath({dur:e+"ms",repeatCount:1},this._V.connection.node),_.delay(function(){V(t).remove(),n&&n()},e)},findRoute:function(t){var e=this.model.get("router");if(!e){if(!this.model.get("manhattan"))return t;e={name:"orthogonal"}}var n=joint.routers[e.name];if(!_.isFunction(n))throw"unknown router: "+e.name;var i=n.call(this,t||[],e.args||{},this);return i},getPathData:function(t){var e=this.model.get("connector");if(e||(e=this.model.get("smooth")?{name:"smooth"}:{name:"normal"}),!_.isFunction(joint.connectors[e.name]))throw"unknown connector: "+e.name;var n=joint.connectors[e.name].call(this,this._markerCache.sourcePoint,this._markerCache.targetPoint,t||this.model.get("vertices")||{},e.args||{},this);return n},getConnectionPoint:function(t,e,n){var i;if(e=e||{x:0,y:0},n=n||{x:0,y:0},this._isPoint(e))i=g.point(e);else{var r,o="source"===t?this.sourceBBox:this.targetBBox;if(this._isPoint(n))r=g.point(n);else{var s="source"===t?this.targetBBox:this.sourceBBox;r=g.rect(s).intersectionWithLineFromCenterToPoint(g.rect(o).center()),r=r||g.rect(s).center()}if(this.paper.options.perpendicularLinks||this.options.perpendicular){var a,l=g.rect(0,r.y,this.paper.options.width,1),c=g.rect(r.x,0,1,this.paper.options.height);if(l.intersect(g.rect(o)))switch(a=g.rect(o).sideNearestToPoint(r)){case"left":i=g.point(o.x,r.y);break;case"right":i=g.point(o.x+o.width,r.y);break;default:i=g.rect(o).center()}else if(c.intersect(g.rect(o)))switch(a=g.rect(o).sideNearestToPoint(r)){case"top":i=g.point(r.x,o.y);break;case"bottom":i=g.point(r.x,o.y+o.height);break;default:i=g.rect(o).center()}else i=g.rect(o).intersectionWithLineFromCenterToPoint(r),i=i||g.rect(o).center()}else if(this.paper.options.linkConnectionPoint){var u="target"===t?this.targetView:this.sourceView,h="target"===t?this.targetMagnet:this.sourceMagnet;i=this.paper.options.linkConnectionPoint(this,u,h,r)}else i=g.rect(o).intersectionWithLineFromCenterToPoint(r),i=i||g.rect(o).center()}return i},_isModel:function(t){return t&&t.id},_isPoint:function(t){return!this._isModel(t)},_makeSelector:function(t){var e='[model-id="'+t.id+'"]';return t.port?e+=' [port="'+t.port+'"]':t.selector&&(e+=" "+t.selector),e},getConnectionLength:function(){return this._V.connection.node.getTotalLength()},getPointAtLength:function(t){return this._V.connection.node.getPointAtLength(t)},_beforeArrowheadMove:function(){this.model.trigger("batch:start"),this._z=this.model.get("z"),this.model.set("z",Number.MAX_VALUE),this.el.style.pointerEvents="none",this.paper.options.markAvailable&&this._markAvailableMagnets()},_afterArrowheadMove:function(){this._z&&(this.model.set("z",this._z),delete this._z),this.el.style.pointerEvents="visiblePainted",this.paper.options.markAvailable&&this._unmarkAvailableMagnets(),this.model.trigger("batch:stop")},_createValidateConnectionArgs:function(t){function e(t,e){return n[o]=t,n[o+1]=t.el===e?void 0:e,n}var n=[];n[4]=t,n[5]=this;var i,r=0,o=0;"source"===t?(r=2,i="target"):(o=2,i="source");var s=this.model.get(i);return s.id&&(n[r]=this.paper.findViewByModel(s.id),n[r+1]=s.selector&&n[r].el.querySelector(s.selector)),e},_markAvailableMagnets:function(){var t=this.paper.model.getElements(),e=this.paper.options.validateConnection;_.chain(t).map(this.paper.findViewByModel,this.paper).each(function(t){var n="false"!==t.el.getAttribute("magnet")&&e.apply(this.paper,this._validateConnectionArgs(t,null)),i=_.filter(t.el.querySelectorAll("[magnet]"),function(n){return e.apply(this.paper,this._validateConnectionArgs(t,n))},this);n&&V(t.el).addClass("available-magnet"),_.each(i,function(t){V(t).addClass("available-magnet")}),(n||i.length)&&V(t.el).addClass("available-cell")},this)},_unmarkAvailableMagnets:function(){_.each(this.paper.el.querySelectorAll(".available-cell, .available-magnet"),function(t){V(t).removeClass("available-magnet").removeClass("available-cell")})},startArrowheadMove:function(t){this._action="arrowhead-move",this._arrowhead=t,this._validateConnectionArgs=this._createValidateConnectionArgs(this._arrowhead),this._beforeArrowheadMove()},pointerdown:function(t,e,n){function i(t){return _.isObject(r)&&r[t]===!1?!1:!0}joint.dia.CellView.prototype.pointerdown.apply(this,arguments),this._dx=e,this._dy=n;var r=_.isFunction(this.options.interactive)?this.options.interactive(this,"pointerdown"):this.options.interactive;if(r!==!1){var o=t.target.getAttribute("class");switch(o){case"marker-vertex":i("vertexMove")&&(this._action="vertex-move",this._vertexIdx=t.target.getAttribute("idx"));break;case"marker-vertex-remove":case"marker-vertex-remove-area":i("vertexRemove")&&this.removeVertex(t.target.getAttribute("idx"));break;case"marker-arrowhead":i("arrowheadMove")&&this.startArrowheadMove(t.target.getAttribute("end"));break;default:var s=t.target.parentNode.getAttribute("event");s?"remove"===s?this.model.remove():this.paper.trigger(s,t,this,e,n):i("vertexAdd")&&(this._vertexIdx=this.addVertex({x:e,y:n}),this._action="vertex-move")}this.paper.trigger("link:pointerdown",t,this,e,n)}},pointermove:function(t,e,n){switch(joint.dia.CellView.prototype.pointermove.apply(this,arguments),this._action){case"vertex-move":var i=_.clone(this.model.get("vertices"));i[this._vertexIdx]={x:e,y:n},this.model.set("vertices",i);break;case"arrowhead-move":if(this.paper.options.snapLinks){var r=this.paper.options.snapLinks.radius||50,o=this.paper.findViewsInArea({x:e-r,y:n-r,width:2*r,height:2*r});this._closestView&&this._closestView.unhighlight(this._closestEnd.selector),this._closestView=this._closestEnd=null;var s,a=g.point(e,n),l=Number.MAX_VALUE;_.each(o,function(t){"false"!==t.el.getAttribute("magnet")&&(s=t.model.getBBox().center().distance(a),r>s&&l>s&&this.paper.options.validateConnection.apply(this.paper,this._validateConnectionArgs(t,null))&&(l=s,this._closestView=t,this._closestEnd={id:t.model.id})),t.$("[magnet]").each(_.bind(function(e,n){var i=V(n).bbox(!1,this.paper.viewport);s=a.distance({x:i.x+i.width/2,y:i.y+i.height/2}),r>s&&l>s&&this.paper.options.validateConnection.apply(this.paper,this._validateConnectionArgs(t,n))&&(l=s,this._closestView=t,this._closestEnd={id:t.model.id,selector:t.getSelector(n),port:n.getAttribute("port")})},this))},this),this._closestView&&this._closestView.highlight(this._closestEnd.selector),this.model.set(this._arrowhead,this._closestEnd||{x:e,y:n})}else{var c="mousemove"===t.type?t.target:document.elementFromPoint(t.clientX,t.clientY);this._targetEvent!==c&&(this._magnetUnderPointer&&this._viewUnderPointer.unhighlight(this._magnetUnderPointer),this._viewUnderPointer=this.paper.findView(c),this._viewUnderPointer?(this._magnetUnderPointer=this._viewUnderPointer.findMagnet(c),this._magnetUnderPointer&&this.paper.options.validateConnection.apply(this.paper,this._validateConnectionArgs(this._viewUnderPointer,this._magnetUnderPointer))?this._magnetUnderPointer&&this._viewUnderPointer.highlight(this._magnetUnderPointer):this._magnetUnderPointer=null):this._magnetUnderPointer=null),this._targetEvent=c,this.model.set(this._arrowhead,{x:e,y:n})}}this._dx=e,this._dy=n},pointerup:function(){joint.dia.CellView.prototype.pointerup.apply(this,arguments),"arrowhead-move"===this._action&&(this.paper.options.snapLinks?(this._closestView&&this._closestView.unhighlight(this._closestEnd.selector),this._closestView=this._closestEnd=null):(this._magnetUnderPointer&&(this._viewUnderPointer.unhighlight(this._magnetUnderPointer),this.model.set(this._arrowhead,{id:this._viewUnderPointer.model.id,selector:this._viewUnderPointer.getSelector(this._magnetUnderPointer),port:$(this._magnetUnderPointer).attr("port")})),delete this._viewUnderPointer,delete this._magnetUnderPointer,delete this._staticView,delete this._staticMagnet),this._afterArrowheadMove()),delete this._action}}),"object"==typeof exports&&(module.exports.Link=joint.dia.Link,module.exports.LinkView=joint.dia.LinkView),joint.dia.Paper=Backbone.View.extend({className:"paper",options:{width:800,height:600,origin:{x:0,y:0},gridSize:50,perpendicularLinks:!1,elementView:joint.dia.ElementView,linkView:joint.dia.LinkView,snapLinks:!1,markAvailable:!1,defaultLink:new joint.dia.Link,validateMagnet:function(t,e){return"passive"!==e.getAttribute("magnet")},validateConnection:function(t,e,n,i,r){return("target"===r?n:t)instanceof joint.dia.ElementView}},events:{mousedown:"pointerdown",dblclick:"mousedblclick",click:"mouseclick",touchstart:"pointerdown",mousemove:"pointermove",touchmove:"pointermove"},constructor:function(t){this._configure(t),Backbone.View.apply(this,arguments)},_configure:function(t){this.options&&(t=_.extend({},_.result(this,"options"),t)),this.options=t},initialize:function(){_.bindAll(this,"addCell","sortCells","resetCells","pointerup","asyncRenderCells"),this.svg=V("svg").node,this.viewport=V("g").node,V(this.svg).append(V("defs").node),V(this.viewport).attr({"class":"viewport"}),V(this.svg).append(this.viewport),this.$el.append(this.svg),this.setOrigin(),this.setDimensions(),this.listenTo(this.model,"add",this.onAddCell),this.listenTo(this.model,"reset",this.resetCells),this.listenTo(this.model,"sort",this.sortCells),$(document).on("mouseup touchend",this.pointerup),this._mousemoved=!1},remove:function(){$(document).off("mouseup touchend",this.pointerup),Backbone.View.prototype.remove.call(this)},setDimensions:function(t,e){t=this.options.width=t||this.options.width,e=this.options.height=e||this.options.height,V(this.svg).attr({width:t,height:e}),this.trigger("resize",t,e)},setOrigin:function(t,e){this.options.origin.x=t||0,this.options.origin.y=e||0,V(this.viewport).translate(t,e,{absolute:!0}),this.trigger("translate",t,e)},fitToContent:function(t,e,n,i){_.isObject(t)?(i=t,t=i.gridWidth||1,e=i.gridHeight||1,n=i.padding||0):(i=i||{},t=t||1,e=e||1,n=n||0);var r=V(this.viewport).bbox(!0,this.svg),o=V(this.viewport).scale();r.x*=o.sx,r.y*=o.sy,r.width*=o.sx,r.height*=o.sy;var s=Math.max(Math.ceil((r.width+r.x)/t),1)*t,a=Math.max(Math.ceil((r.height+r.y)/e),1)*e,l=0,c=0;("negative"==i.allowNewOrigin&&0>r.x||"positive"==i.allowNewOrigin&&r.x>=0||"any"==i.allowNewOrigin)&&(l=Math.ceil(-r.x/t)*t,l+=n,s+=l),("negative"==i.allowNewOrigin&&0>r.y||"positive"==i.allowNewOrigin&&r.y>=0||"any"==i.allowNewOrigin)&&(c=Math.ceil(-r.y/e)*e,c+=n,a+=c),s+=n,a+=n;var u=s!=this.options.width||a!=this.options.height,h=l!=this.options.origin.x||c!=this.options.origin.y;h&&this.setOrigin(l,c),u&&this.setDimensions(s,a)},scaleContentToFit:function(t){var e=this.getContentBBox();if(e.width&&e.height){t=t||{},_.defaults(t,{padding:0,preserveAspectRatio:!0,scaleGrid:null,minScale:0,maxScale:Number.MAX_VALUE});var n=t.padding,i=t.minScaleX||t.minScale,r=t.maxScaleX||t.maxScale,o=t.minScaleY||t.minScale,s=t.maxScaleY||t.maxScale,a=t.fittingBBox||{x:this.options.origin.x,y:this.options.origin.y,width:this.options.width,height:this.options.height};a=g.rect(a).moveAndExpand({x:n,y:n,width:-2*n,height:-2*n});var l=V(this.viewport).scale(),c=a.width/e.width*l.sx,u=a.height/e.height*l.sy;if(t.preserveAspectRatio&&(c=u=Math.min(c,u)),t.scaleGrid){var h=t.scaleGrid;c=h*Math.floor(c/h),u=h*Math.floor(u/h)}c=Math.min(r,Math.max(i,c)),u=Math.min(s,Math.max(o,u)),this.scale(c,u);var f=this.getContentBBox(),d=a.x-f.x,p=a.y-f.y;this.setOrigin(d,p)}},getContentBBox:function(){var t=this.viewport.getBoundingClientRect(),e=this.viewport.getScreenCTM(),n=this.viewport.getCTM(),i=g.rect({x:t.left-e.e+n.e,y:t.top-e.f+n.f,width:t.width,height:t.height});return i},createViewForModel:function(t){var e,n=t.get("type"),i=n.split(".")[0],r=n.split(".")[1];return e=joint.shapes[i]&&joint.shapes[i][r+"View"]?new joint.shapes[i][r+"View"]({model:t,interactive:this.options.interactive}):t instanceof joint.dia.Element?new this.options.elementView({model:t,interactive:this.options.interactive}):new this.options.linkView({model:t,interactive:this.options.interactive})},onAddCell:function(t,e,n){if(this.options.async&&n.async!==!1&&_.isNumber(n.position)){if(this._asyncCells=this._asyncCells||[],this._asyncCells.push(t),0==n.position){if(this._frameId)throw"another asynchronous rendering in progress";this.asyncRenderCells(this._asyncCells),delete this._asyncCells}}else this.addCell(t)},addCell:function(t){var e=this.createViewForModel(t);V(this.viewport).append(e.el),e.paper=this,e.render(),$(e.el).find("image").on("dragstart",function(){return!1})},resetCells:function(t){$(this.viewport).empty();var e=t.models.slice();e.sort(function(t){return t instanceof joint.dia.Link?1:-1}),this._frameId&&(joint.util.cancelFrame(this._frameId),delete this._frameId),this.options.async?this.asyncRenderCells(e):(_.each(e,this.addCell,this),this.sortCells())},asyncRenderCells:function(t){var e=!1;this._frameId&&_.each(_.range(this.options.async&&this.options.async.batchSize||50),function(){var n=t.shift();e=!n,e||this.addCell(n)},this),e?(delete this._frameId,this.sortCells(),this.trigger("render:done")):this._frameId=joint.util.nextFrame(_.bind(function(){this.asyncRenderCells(t)},this))},sortCells:function(){var t=$(this.viewport).children("[model-id]"),e=this.model.get("cells");this.sortElements(t,function(t,n){var i=e.get($(t).attr("model-id")),r=e.get($(n).attr("model-id"));return(i.get("z")||0)>(r.get("z")||0)?1:-1})},sortElements:function(t,e){var n=$(t),i=n.map(function(){var t=this,e=t.parentNode,n=e.insertBefore(document.createTextNode(""),t.nextSibling);return function(){if(e===this)throw Error("You can't sort elements if any one is a descendant of another.");e.insertBefore(this,n),e.removeChild(n)}});return Array.prototype.sort.call(n,e).each(function(t){i[t].call(this)})},scale:function(t,e,n,i){e=e||t,_.isUndefined(n)&&(n=0,i=0),V(this.viewport).attr("transform","");var r=this.options.origin.x,o=this.options.origin.y;if(n||i||r||o){var s=r-n*(t-1),a=o-i*(e-1);this.setOrigin(s,a)}return V(this.viewport).scale(t,e),this.trigger("scale",t,e,n,i),this},rotate:function(t,e,n){if(_.isUndefined(e)){var i=this.viewport.getBBox();e=i.width/2,n=i.height/2}V(this.viewport).rotate(t,e,n)},findView:function(t){var e=this.$(t);return 0===e.length||e[0]===this.el?void 0:e.data("view")?e.data("view"):this.findView(e.parent())},findViewByModel:function(t){var e=_.isString(t)?t:t.id,n=this.$('[model-id="'+e+'"]');return n.length?n.data("view"):void 0},findViewsFromPoint:function(t){t=g.point(t);var e=_.map(this.model.getElements(),this.findViewByModel);return _.filter(e,function(e){return g.rect(V(e.el).bbox(!1,this.viewport)).containsPoint(t)},this)},findViewsInArea:function(t){t=g.rect(t);var e=_.map(this.model.getElements(),this.findViewByModel);return _.filter(e,function(e){return t.intersect(g.rect(V(e.el).bbox(!1,this.viewport)))},this)},getModelById:function(t){return this.model.getCell(t)},snapToGrid:function(t){var e=V(this.viewport).toLocalPoint(t.x,t.y);return{x:g.snapToGrid(e.x,this.options.gridSize),y:g.snapToGrid(e.y,this.options.gridSize)}},getDefaultLink:function(t,e){return _.isFunction(this.options.defaultLink)?this.options.defaultLink.call(this,t,e):this.options.defaultLink.clone()},mousedblclick:function(t){t.preventDefault(),t=joint.util.normalizeEvent(t);var e=this.findView(t.target),n=this.snapToGrid({x:t.clientX,y:t.clientY});e?e.pointerdblclick(t,n.x,n.y):this.trigger("blank:pointerdblclick",t,n.x,n.y)},mouseclick:function(t){if(!this._mousemoved){t=joint.util.normalizeEvent(t);var e=this.findView(t.target),n=this.snapToGrid({x:t.clientX,y:t.clientY});e?e.pointerclick(t,n.x,n.y):this.trigger("blank:pointerclick",t,n.x,n.y)}this._mousemoved=!1},pointerdown:function(t){t=joint.util.normalizeEvent(t);var e=this.findView(t.target),n=this.snapToGrid({x:t.clientX,y:t.clientY});e?(this.sourceView=e,e.pointerdown(t,n.x,n.y)):this.trigger("blank:pointerdown",t,n.x,n.y)},pointermove:function(t){if(t.preventDefault(),t=joint.util.normalizeEvent(t),this.sourceView){this._mousemoved=!0;var e=this.snapToGrid({x:t.clientX,y:t.clientY});this.sourceView.pointermove(t,e.x,e.y)}},pointerup:function(t){t=joint.util.normalizeEvent(t);var e=this.snapToGrid({x:t.clientX,y:t.clientY});this.sourceView?(this.sourceView.pointerup(t,e.x,e.y),this.sourceView=null):this.trigger("blank:pointerup",t,e.x,e.y)}}),"object"==typeof exports)var joint={util:require("../src/core").util,shapes:{},dia:{Element:require("../src/joint.dia.element").Element,ElementView:require("../src/joint.dia.element").ElementView}},_=require("lodash");joint.shapes.basic={},joint.shapes.basic.Generic=joint.dia.Element.extend({defaults:joint.util.deepSupplement({type:"basic.Generic",attrs:{".":{fill:"#FFFFFF",stroke:"none"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.basic.Rect=joint.shapes.basic.Generic.extend({markup:'',defaults:joint.util.deepSupplement({type:"basic.Rect",attrs:{rect:{fill:"#FFFFFF",stroke:"black",width:100,height:60},text:{"font-size":14,text:"","ref-x":.5,"ref-y":.5,ref:"rect","y-alignment":"middle","x-alignment":"middle",fill:"black","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Text=joint.shapes.basic.Generic.extend({markup:'',defaults:joint.util.deepSupplement({type:"basic.Text",attrs:{text:{"font-size":18,fill:"black"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Circle=joint.shapes.basic.Generic.extend({markup:'',defaults:joint.util.deepSupplement({type:"basic.Circle",size:{width:60,height:60},attrs:{circle:{fill:"#FFFFFF",stroke:"black",r:30,transform:"translate(30, 30)"},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-y":.5,ref:"circle","y-alignment":"middle",fill:"black","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Image=joint.shapes.basic.Generic.extend({markup:'',defaults:joint.util.deepSupplement({type:"basic.Image",attrs:{text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-dy":20,ref:"image","y-alignment":"middle",fill:"black","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Path=joint.shapes.basic.Generic.extend({markup:'',defaults:joint.util.deepSupplement({type:"basic.Path",size:{width:60,height:60},attrs:{path:{fill:"#FFFFFF",stroke:"black"},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-dy":20,ref:"path","y-alignment":"middle",fill:"black","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Rhombus=joint.shapes.basic.Path.extend({defaults:joint.util.deepSupplement({type:"basic.Rhombus",attrs:{path:{d:"M 30 0 L 60 30 30 60 0 30 z"},text:{"ref-y":.5}}},joint.shapes.basic.Path.prototype.defaults)}),joint.shapes.basic.PortsModelInterface={initialize:function(){this.updatePortsAttrs(),this.on("change:inPorts change:outPorts",this.updatePortsAttrs,this),this.constructor.__super__.constructor.__super__.initialize.apply(this,arguments)},updatePortsAttrs:function(){var t=this.get("attrs");_.each(this._portSelectors,function(e){t[e]&&delete t[e]}),this._portSelectors=[];var e={};_.each(this.get("inPorts"),function(t,n,i){var r=this.getPortAttrs(t,n,i.length,".inPorts","in");this._portSelectors=this._portSelectors.concat(_.keys(r)),_.extend(e,r)},this),_.each(this.get("outPorts"),function(t,n,i){var r=this.getPortAttrs(t,n,i.length,".outPorts","out");this._portSelectors=this._portSelectors.concat(_.keys(r)),_.extend(e,r)},this),this.attr(e,{silent:!0}),this.processPorts(),this.trigger("process:ports")},getPortSelector:function(t){var e=".inPorts",n=this.get("inPorts").indexOf(t);if(0>n&&(e=".outPorts",n=this.get("outPorts").indexOf(t),0>n))throw Error("getPortSelector(): Port doesn't exist.");return e+">g:nth-child("+(n+1)+")>circle"}},joint.shapes.basic.PortsViewInterface={initialize:function(){this.listenTo(this.model,"process:ports",this.update),joint.dia.ElementView.prototype.initialize.apply(this,arguments)},update:function(){this.renderPorts(),joint.dia.ElementView.prototype.update.apply(this,arguments)},renderPorts:function(){var t=this.$(".inPorts").empty(),e=this.$(".outPorts").empty(),n=_.template(this.model.portMarkup);_.each(_.filter(this.model.ports,function(t){return"in"===t.type}),function(e,i){t.append(V(n({id:i,port:e})).node)}),_.each(_.filter(this.model.ports,function(t){return"out"===t.type}),function(t,i){e.append(V(n({id:i,port:t})).node)})}},joint.shapes.basic.TextBlock=joint.shapes.basic.Generic.extend({markup:['','','
',"",'',""].join(""),defaults:joint.util.deepSupplement({type:"basic.TextBlock",attrs:{rect:{fill:"#ffffff",stroke:"#000000",width:80,height:100},text:{fill:"#000000","font-size":14,"font-family":"Arial, helvetica, sans-serif"},".content":{text:"",ref:"rect","ref-x":.5,"ref-y":.5,"y-alignment":"middle","x-alignment":"middle"}},content:""},joint.shapes.basic.Generic.prototype.defaults),initialize:function(){"undefined"!=typeof SVGForeignObjectElement&&(this.setForeignObjectSize(this,this.get("size")),this.setDivContent(this,this.get("content")),this.listenTo(this,"change:size",this.setForeignObjectSize),this.listenTo(this,"change:content",this.setDivContent)),joint.shapes.basic.Generic.prototype.initialize.apply(this,arguments)},setForeignObjectSize:function(t,e){t.attr({".fobj":_.clone(e),div:{style:_.clone(e)}})},setDivContent:function(t,e){t.attr({div:{html:e}})}}),joint.shapes.basic.TextBlockView=joint.dia.ElementView.extend({initialize:function(){joint.dia.ElementView.prototype.initialize.apply(this,arguments),"undefined"==typeof SVGForeignObjectElement&&(this.noSVGForeignObjectElement=!0,this.listenTo(this.model,"change:content",function(t){this.updateContent(t)}))},update:function(t,e){if(this.noSVGForeignObjectElement){var n=this.model,i=_.omit(e||n.get("attrs"),".content");joint.dia.ElementView.prototype.update.call(this,n,i),(!e||_.has(e,".content"))&&this.updateContent(n,e)}else joint.dia.ElementView.prototype.update.call(this,n,e)},updateContent:function(t,e){var n=_.merge({},(e||t.get("attrs"))[".content"]);delete n.text;var i=joint.util.breakText(t.get("content"),t.get("size"),n,{svgDocument:this.paper.svg}),r=joint.util.setByPath({},".content",n,"/");r[".content"].text=i,joint.dia.ElementView.prototype.update.call(this,t,r)}}),"object"==typeof exports&&(module.exports=joint.shapes.basic),joint.routers.orthogonal=function(){function t(t,e){return t.ye.y&&t.x===e.x?"up":t.xe.y?["up","right"]:t.ye.x?t.y>e.y?["up","left"]:t.ye.y?["up"]:["down"],_.contains(i,n))return n;var r=_.first(i);switch(n){case"down":if("up"===r)return _.last(i);break;case"up":if("down"===r)return _.last(i);break;case"left":if("right"===r)return _.last(i);break;case"right":if("left"===r)return _.last(i)}return r}function n(t,n,i){var r=e(t,n,i);return"down"===r||"up"===r?{x:t.x,y:n.y,d:r}:{x:n.x,y:t.y,d:r}}function i(e){e=(e||[]).slice();var i=[],s=r.center(),a=o.center();e.length||(Math.abs(s.x-a.x)f;f++){u=e[f],h=e[f+1],c=_.last(i),f>0&&(l=u,l.d=c?t(c,u):"top",i.push(l),c=l);var d=c&&c.d;l=n(u,h,d),g.point(l).equals(g.point(u))||g.point(l).equals(g.point(h))||i.push(l) }return i}var r,o;return function(t){return r=this.sourceBBox,o=this.targetBBox,i(t)}}(),joint.routers.manhattan=function(){"use strict";function t(t,e){for(var n,i=[],r={x:0,y:0},o=e;n=t[o];){var s=n.difference(o);s.equals(r)||(i.unshift(o),r=s),o=n}return i.unshift(o),i}function e(t,e,n){var i=n.step,r=t.center(),o=_.chain(n.directionMap).pick(e).map(function(e){var n=e.x*t.width/2,o=e.y*t.height/2,s=g.point(r).offset(n,o).snapToGrid(i);return t.containsPoint(s)&&s.offset(e.x*i,e.y*i),s}).value();return o}function n(t,e,n){var i=360/n,r=Math.floor(t.theta(e)/i);return n-r}function i(i,r,o,s){var a=s.reversed?s.endDirections:s.startDirections,l=s.reversed?s.startDirections:s.endDirections,c=i instanceof g.rect?e(i,a,s):[i],u=r instanceof g.rect?e(r,l,s):[r],h=c.length>1?i.center():c[0],f=u.length>1?r.center():u[0],d=_.filter(u,function(t){var e=""+g.point(t).snapToGrid(s.mapGridSize),n=_.every(o[e],function(e){return!e.containsPoint(t)});return n});if(d.length)for(var p=s.step,m=s.penalties,v=_.chain(d).invoke("snapToGrid",p).min(function(t){return s.estimateCost(h,t)}).value(),y={},x={},b={},w=s.directions,k=w.length,C=k/2,j=s.previousDirIndexes||{},T={},V={},A=_.chain(c).invoke("snapToGrid",p).each(function(t){var e=""+t;x[e]=0,b[e]=s.estimateCost(t,v),j[e]=j[e]||n(h,t,k),V[e]=!0}).map(function(t){return""+t}).sortBy(function(t){return b[t]}).value(),M=s.maximumLoops,S=s.maxAllowedDirectionChange;A.length&&M--;){var E=A[0],P=g.point(E);if(v.equals(P))return s.previousDirIndexes=_.pick(j,E),t(y,P);A.splice(0,1),V[z]=null,T[z]=!0;for(var B=j[E],F=x[E],L=0;k>L;L++){var N=Math.abs(L-B);if(N>C&&(N=k-N),!(N>S)){var $=w[L],O=g.point(P).offset($.offsetX,$.offsetY),z=""+O;if(!T[z]){var q=""+g.point(O).snapToGrid(s.mapGridSize),D=_.every(o[q],function(t){return!t.containsPoint(O)});if(D){var R=_.has(V,z),I=F+$.cost;if((!R||x[z]>I)&&(y[z]=P,j[z]=L,x[z]=I,b[z]=I+s.estimateCost(O,v)+m[N],!R)){var G=_.sortedIndex(A,z,function(t){return b[t]});A.splice(G,0,z),V[z]=!0}}}}}}return s.fallbackRoute(h,f,s)}function r(t,e){e.directions=_.result(e,"directions"),e.penalties=_.result(e,"penalties"),e.paddingBox=_.result(e,"paddingBox"),this.options.perpendicular=!!e.perpendicular;var n=e.reversed="source"===this.lastEndChange,r=n?g.rect(this.targetBBox):g.rect(this.sourceBBox),o=n?g.rect(this.sourceBBox):g.rect(this.targetBBox);r.moveAndExpand(e.paddingBox),o.moveAndExpand(e.paddingBox);for(var s=this.model,a=this.paper.model,l=_.chain(e.excludeEnds).map(s.get,s).pluck("id").map(a.getCell,a).value(),c=e.mapGridSize,u=_.chain(a.getElements()).difference(l).reject(function(t){return _.contains(e.excludeTypes,t.get("type"))}).invoke("getBBox").invoke("moveAndExpand",e.paddingBox).foldl(function(t,e){for(var n=e.origin().snapToGrid(c),i=e.corner().snapToGrid(c),r=n.x;i.x>=r;r+=c)for(var o=n.y;i.y>=o;o+=c){var s=r+"@"+o;t[s]=t[s]||[],t[s].push(e)}return t},{}).value(),h=[],f=_.map(t,g.point),d=r.center(),p=0,m=f.length;m>=p;p++){var v=null,y=x||r,x=f[p];if(!x){x=o;var b=!this.model.get("source").id||!this.model.get("target").id;if(b&&_.isFunction(e.draggingRoute)){var w=y instanceof g.rect?y.center():y;v=e.draggingRoute(w,x.origin(),e)}}v=v||i(y,x,u,e);var k=_.first(v);k&&k.equals(d)&&v.shift(),d=_.last(v)||d,h=h.concat(v)}return n?h.reverse():h}var o={step:10,perpendicular:!0,mapGridSize:100,excludeEnds:[],excludeTypes:["basic.Text"],maximumLoops:500,startDirections:["left","right","top","bottom"],endDirections:["left","right","top","bottom"],directionMap:{right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0},top:{x:0,y:-1}},maxAllowedDirectionChange:1,paddingBox:function(){var t=this.step;return{x:-t,y:-t,width:2*t,height:2*t}},directions:function(){var t=this.step;return[{offsetX:t,offsetY:0,cost:t},{offsetX:0,offsetY:t,cost:t},{offsetX:-t,offsetY:0,cost:t},{offsetX:0,offsetY:-t,cost:t}]},penalties:function(){return[0,this.step/2,this.step]},estimateCost:function(t,e){return t.manhattanDistance(e)},fallbackRoute:function(t,e,n){var i=n.prevDirIndexes||{},r=(i[t]||0)%2?g.point(t.x,e.y):g.point(e.x,t.y);return[r,e]},draggingRoute:null};return function(t,e,n){return r.call(n,t,_.extend({},o,e))}}(),joint.routers.metro=function(){if(!_.isFunction(joint.routers.manhattan))throw"Metro requires the manhattan router.";var t={diagonalCost:null,directions:function(){var t=this.step,e=this.diagonalCost||Math.ceil(Math.sqrt(t*t<<1));return[{offsetX:t,offsetY:0,cost:t},{offsetX:t,offsetY:t,cost:e},{offsetX:0,offsetY:t,cost:t},{offsetX:-t,offsetY:t,cost:e},{offsetX:-t,offsetY:0,cost:t},{offsetX:-t,offsetY:-t,cost:e},{offsetX:0,offsetY:-t,cost:t},{offsetX:t,offsetY:-t,cost:e}]},fallbackRoute:function(t,e){var n=t.theta(e),i={x:e.x,y:t.y},r={x:t.x,y:e.y};if(n%180>90){var o=i;i=r,r=o}var s=45>n%90?i:r,a=g.line(t,s),l=90*Math.ceil(n/90),c=g.point.fromPolar(a.squaredLength(),g.toRad(l+135),s),u=g.line(e,c),h=a.intersection(u);return h?[h.round(),e]:[e]}};return function(e,n,i){return joint.routers.manhattan(e,_.extend({},t,n),i)}}(),joint.connectors.normal=function(t,e,n){var i=["M",t.x,t.y];return _.each(n,function(t){i.push(t.x,t.y)}),i.push(e.x,e.y),i.join(" ")},joint.connectors.rounded=function(t,e,n,i){var r,o,s,a,l,c,u=i.radius||10,h=["M",t.x,t.y];return _.each(n,function(i,f){l=n[f-1]||t,c=n[f+1]||e,s=a||g.point(i).distance(l)/2,a=g.point(i).distance(c)/2,r=g.point(i).move(l,-Math.min(u,s)).round(),o=g.point(i).move(c,-Math.min(u,a)).round(),h.push(r.x,r.y,"S",i.x,i.y,o.x,o.y,"L")}),h.push(e.x,e.y),h.join(" ")},joint.connectors.smooth=function(t,e,n){var i;if(n.length)i=g.bezier.curveThroughPoints([t].concat(n).concat([e]));else{var r=t.x




© 2015 - 2024 Weber Informatics LLC | Privacy Policy