| 12345678910111213141516171819202122232425262728293031323334353637 |
- /* jquery.cytoscape-edgehandles.min.js */
- /**
- * This file is part of cytoscape.js 2.0.2.
- *
- * Cytoscape.js is free software: you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option) any
- * later version.
- *
- * Cytoscape.js is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public License along with
- * cytoscape.js. If not, see <http://www.gnu.org/licenses/>.
- */
-
- (function(a){var b={preview:true,handleSize:10,handleColor:"#ff0000",handleLineWidth:1,hoverDelay:150,enabled:true,lineType:"draw",edgeType:function(c,d){return"node"},loopAllowed:function(c){return false},nodeParams:function(c,d){return{}},edgeParams:function(c,d){return{}},start:function(c){},complete:function(e,d,c){},stop:function(c){}};a.fn.cytoscapeEdgehandles=function(e){var c=e;var d={destroy:function(){var g=a(this);var f=g.data("cyedgehandles");if(f==null){return}f.unbind();g.data("cyedgehandles",{});
- return g},option:function(g,j){var k=a(this);var i=k.data("cyedgehandles");if(i==null){return}var f=i.options;if(j===undefined){if(typeof g==typeof{}){var h=g;f=a.extend(true,{},b,h);i.options=f}else{return f[g]}}else{f[g]=j}k.data("cyedgehandles",i);return k},disable:function(){return d.option.apply(this,["enabled",false])},enable:function(){return d.option.apply(this,["enabled",true])},init:function(){var w=a.extend(true,{},b,e);var z=a(this);var h;var p=a("<canvas></canvas>");var I;var t,o;var g=false;
- var L=false;var v=false;var F,D,K;var s;var u=true;z.append(p);function f(){p.attr("height",z.height()).attr("width",z.width()).css({position:"absolute","z-index":"999"})}f();a(window).bind("resize",function(){f()});var y=p[0].getContext("2d");var J=z.data("cyedgehandles");if(J==null){J={}}J.options=w;function l(){return z.data("cyedgehandles").options}function r(){return l().enabled}function m(){return !r()}function C(){if(u){return}var M=z.width();var N=z.height();y.clearRect(0,0,M,N);u=true}var H,q,i;
- function G(){H=h.panningEnabled();q=h.zoomingEnabled();i=h.boxSelectionEnabled();h.zoomingEnabled(false).panningEnabled(false).boxSelectionEnabled(false)}function B(){h.zoomingEnabled(q).panningEnabled(H).boxSelectionEnabled(i)}function n(){C();h.nodes().removeClass("ui-cytoscape-edgehandles-hover").removeClass("ui-cytoscape-edgehandles-source").removeClass("ui-cytoscape-edgehandles-target");o=null;B()}function j(M,N){k(true);N.trigger("cyedgehandles.addpreview")}function A(M,N){M.edgesWith(N).filter(".ui-cytoscape-edgehandles-preview").remove();
- N.neighborhood("node.ui-cytoscape-edgehandles-preview").closedNeighborhood(".ui-cytoscape-edgehandles-preview").remove();N.trigger("cyedgehandles.removepreview")}function E(O,N,M){y.fillStyle=l().handleColor;y.strokeStyle=l().handleColor;y.beginPath();y.arc(O,N,M,0,2*Math.PI);y.closePath();y.fill();u=false}function x(R,P,M,Q){y.fillStyle=l().handleColor;y.strokeStyle=l().handleColor;y.lineWidth=l().handleLineWidth;switch(l().lineType){case"straight":y.beginPath();y.moveTo(R,P);y.lineTo(M,Q);y.closePath();
- y.stroke();break;case"draw":default:if(o==null){o=[[M,Q]]}else{o.push([M,Q])}y.beginPath();y.moveTo(R,P);for(var N=0;N<o.length;N++){var O=o[N];y.lineTo(O[0],O[1])}y.stroke();break}u=false}function k(W,M,S){var N=M?M:h.nodes(".ui-cytoscape-edgehandles-source");var U=S?S:h.nodes(".ui-cytoscape-edgehandles-target");var Q=W?"ui-cytoscape-edgehandles-preview":"";var X=h.collection();if(N.size()===0||U.size()===0){return}if(!M&&!S){if(!W&&l().preview){X=h.elements(".ui-cytoscape-edgehandles-preview").removeClass("ui-cytoscape-edgehandles-preview");
- l().complete(N,U,X);N.trigger("cyedgehandles.complete");return}else{h.elements(".ui-cytoscape-edgehandles-preview").remove()}}for(var T=0;T<U.length;T++){var V=U[T];switch(l().edgeType(N,V)){case"node":var ab=N.position();var aa=V.position();var O={x:(ab.x+aa.x)/2,y:(ab.y+aa.y)/2};var R=h.add(a.extend(true,{group:"nodes",position:O},l().nodeParams(N,V))).addClass(Q);var Z=h.add(a.extend(true,{group:"edges",data:{source:N.id(),target:R.id()}},l().edgeParams(N,V))).addClass(Q);var Y=h.add(a.extend(true,{group:"edges",data:{source:R.id(),target:V.id()}},l().edgeParams(N,V))).addClass(Q);
- X=X.add(R).add(Z).add(Y);break;case"flat":var P=h.add(a.extend(true,{group:"edges",data:{source:N.id(),target:V.id()}},l().edgeParams(N,V))).addClass(Q);X=X.add(P);break;default:V.removeClass("ui-cytoscape-edgehandles-target");break}}if(!W){l().complete(N,U,X);N.trigger("cyedgehandles.complete")}}z.cytoscape(function(U){h=this;H=h.panningEnabled();q=h.zoomingEnabled();i=h.boxSelectionEnabled();var V;var N;h.bind("zoom pan",N=function(){C()});var M;var Q,P,R,S,T,X,W,O;h.on("mouseover","node",Q=function(ae){if(m()||g||L||this.hasClass("ui-cytoscape-edgehandles-preview")||v){return
- }if(M){z[0].removeEventListener("mousedown",M,true)}var aa=this;var ac=this;var ad=aa.renderedPosition();var Z=aa.renderedOuterHeight();V=aa.id();C();K=l().handleSize/2*h.zoom();F=ad.x;D=ad.y-Z/2-K/2;E(F,D,K);aa.trigger("cyedgehandles.showhandle");function Y(ah){z[0].removeEventListener("mousedown",Y,true);var af=ah.pageX-z.offset().left;var ai=ah.pageY-z.offset().top;if(ah.button!==0){return}if(Math.abs(af-F)>K||Math.abs(ai-D)>K){return}if(v){return}g=true;ah.preventDefault();ah.stopPropagation();
- aa.addClass("ui-cytoscape-edgehandles-source");aa.trigger("cyedgehandles.start");function ag(aj){if(!g||v){return}var ak=a(this);g=false;a(window).unbind("mousemove",ab);k();n();l().stop(aa);aa.trigger("cyedgehandles.stop")}a(window).one("mouseup blur",ag).bind("mousemove",ab);G();l().start(aa);return false}function ab(ag){var af=ag.pageX-z.offset().left;var ah=ag.pageY-z.offset().top;C();E(F,D,K);x(F,D,af,ah);return false}z[0].addEventListener("mousedown",Y,true);M=Y}).on("mouseover touchover","node",P=function(){var Y=this;
- var Z=this;if(m()||this.hasClass("ui-cytoscape-edgehandles-preview")){return}if(g){clearTimeout(s);s=setTimeout(function(){var ab=h.nodes(".ui-cytoscape-edgehandles-source");var aa=Y.hasClass("ui-cytoscape-edgehandles-source");var ac=l().loopAllowed(Y);if(!aa||(aa&&ac)){Y.addClass("ui-cytoscape-edgehandles-hover");Y.toggleClass("ui-cytoscape-edgehandles-target");if(l().preview){if(Y.hasClass("ui-cytoscape-edgehandles-target")){j(ab,Z)}else{A(ab,Z)}}}},l().hoverDelay);return false}}).on("mouseout","node",R=function(){if(this.hasClass("ui-cytoscape-edgehandles-hover")){this.removeClass("ui-cytoscape-edgehandles-hover")
- }if(g){clearTimeout(s)}}).on("drag position","node",X=function(){setTimeout(C,50)}).on("grab","node",grabHandler=function(){L=true;setTimeout(function(){C()},5)}).on("free","node",T=function(){L=false}).on("cyedgehandles.forcestart","node",W=function(){v=true;C();var aa=this;var Y=aa;V=aa.id();aa.trigger("cyedgehandles.start");aa.addClass("ui-cytoscape-edgehandles-source");var Z=aa.renderedPosition();var ab=aa.renderedOuterHeight();var ag=aa.renderedOuterWidth();var ah=l().handleSize/2*h.zoom();var ad=Z.x;
- var ac=Z.y-ab/2-ah/2;E(ad,ac,ah);aa.trigger("cyedgehandles.showhandle");var af=function(am){z[0].removeEventListener("mousedown",af,true);z[0].removeEventListener("touchstart",af,true);var aj=(am.pageX!==undefined?am.pageX:am.originalEvent.touches[0].pageX)-z.offset().left;var ao=(am.pageY!==undefined?am.pageY:am.originalEvent.touches[0].pageY)-z.offset().top;var an=ah/2;var ak=Z.x-ag/2-an<=aj&&aj<=Z.x+ag/2+an&&Z.y-ab/2-an<=ao&&ao<=Z.y+ab/2+an;if(ak){G();g=true;var al=function(aq){var ap=(aq.pageX!==undefined?aq.pageX:aq.originalEvent.touches[0].pageX)-z.offset().left;
- var ar=(aq.pageY!==undefined?aq.pageY:aq.originalEvent.touches[0].pageY)-z.offset().top;C();E(ad,ac,ah);x(ad,ac,ap,ar)};z[0].addEventListener("mousemove",al,true);z[0].addEventListener("touchmove",al,true);a(window).one("mouseup touchend blur",function(){z[0].removeEventListener("mousemove",al,true);z[0].removeEventListener("touchmove",al,true);v=false;g=false;k();l().stop(aa);aa.trigger("cyedgehandles.stop");h.off("tap","node",ai);aa.off("remove",ae);n()});am.stopPropagation();am.preventDefault();
- return false}};z[0].addEventListener("mousedown",af,true);z[0].addEventListener("touchstart",af,true);var ae;aa.one("remove",function(){z[0].removeEventListener("mousedown",af,true);z[0].removeEventListener("touchstart",af,true);h.off("tap","node",ai)});var ai;h.one("tap","node",ai=function(){var ak=this;var aj=Y.id()===ak.id();var al=l().loopAllowed(ak);if(!aj||(aj&&al)){k(false,Y,ak)}v=false;l().stop(aa);aa.trigger("cyedgehandles.stop");z[0].removeEventListener("mousedown",af,true);z[0].removeEventListener("touchstart",af,true);
- aa.off("remove",ae);n()})}).on("remove","node",O=function(){var Y=this.id();if(Y===V){setTimeout(function(){n()},5)}});J.unbind=function(){h.off("mouseover","node",Q).off("mouseover","node",P).off("mouseout","node",R).off("drag position","node",X).off("grab","node",S).off("free","node",T).off("cyedgehandles.forcestart","node",W).off("remove","node",O);h.unbind("zoom pan",N)}});z.data("cyedgehandles",J)},start:function(f){$container=a(this);$container.cytoscape(function(g){var h=this;h.$("#"+f).trigger("cyedgehandles.forcestart")
- })}};if(d[c]){return d[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c=="object"||!c){return d.init.apply(this,arguments)}else{a.error("No such function `"+c+"` for jquery.cytoscapeEdgeHandles")}}return a(this)};a.fn.cyEdgehandles=a.fn.cytoscapeEdgehandles})(jQuery);
|