-
Notifications
You must be signed in to change notification settings - Fork 8
/
cytoscape-view-utilities.js
1 lines (1 loc) · 10.7 KB
/
cytoscape-view-utilities.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("geometric")):"function"==typeof define&&define.amd?define(["geometric"],t):"object"==typeof exports?exports.cytoscapeViewUtilities=t(require("geometric")):e.cytoscapeViewUtilities=t(e.geometric)}(window,(function(e){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var i=t[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(o,i,function(t){return e[t]}.bind(null,i));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){var o;function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function(){"use strict";var r=function(e){if(e){var t={highlightStyles:[],selectStyles:{},setVisibilityOnHide:!1,setDisplayOnHide:!0,zoomAnimationDuration:1500,neighbor:function(e){return!1},neighborSelectTime:500,lassoStyle:{lineColor:"#d67614",lineWidth:3},htmlElem4marqueeZoom:"",marqueeZoomCursor:"se-resize",isShowEdgesBetweenVisibleNodes:!0},o=n(1),r=n(2);e("core","viewUtilities",(function(e){var n=this;function l(e){return e.scratch("_viewUtilities")||e.scratch("_viewUtilities",{}),e.scratch("_viewUtilities")}if("get"===e)return l(n).instance;t=function e(t){t=t||{};for(var n=1;n<arguments.length;n++){var o=arguments[n];if(o)for(var r in o)o.hasOwnProperty(r)&&(Array.isArray(o[r])?t[r]=o[r].slice():"object"===i(o[r])?t[r]=e(t[r],o[r]):t[r]=o[r])}return t}({},t,e);var s=r(n,t);if(n.undoRedo){var u=n.undoRedo(null,!0);o(n,u,s)}if(l(n).instance=s,!l(n).initialized){l(n).initialized=!0;var a=!1;document.addEventListener("keydown",(function(e){"Shift"==e.key&&(a=!0)})),document.addEventListener("keyup",(function(e){"Shift"==e.key&&(a=!1)})),n.on("taphold","node, edge",(function(e){var o,i=e.target||e.cyTarget,r=!1,l=setTimeout((function(){a&&(n.elements().unselect(),(o=t.neighbor(i))&&o.select(),i.lock(),i.unselectify(),r=!0)}),t.neighborSelectTime-500);n.one("tapend",(function(){r?setTimeout((function(){i.selectify(),i.unlock(),r=!1}),100):clearTimeout(l)})),n.one("drag","node",(function(e){var t=e.target||e.cyTarget;i==t&&!1===r&&clearTimeout(l)}))}))}return l(n).instance}))}};e.exports&&(e.exports=r),void 0===(o=function(){return r}.call(t,n,t,e))||(e.exports=o),"undefined"!=typeof cytoscape&&r(cytoscape)}()},function(e,t){function n(e,t,n){function o(t){t=t||e.elements();for(var o=n.getAllHighlightClasses(),i=[],r=0;r<o.length;r++)i.push(t.filter(".".concat(o[r],":visible")));var l=o.map((function(e){return"."+e})).join(",");return i.push(t.filter(":visible").not(l)),i}function i(e){for(var t=e.current,o=[],i=0;i<e.length-1;i++)o.push(n.highlight(e[i],i));return o.push(n.removeHighlights(e[e.length-1])),o.current=t,o}function r(e){return function(t){var i=o();return t.firstTime?n[e](t.eles,t.idx):function(e){for(var t=e.current,o=[],i=0;i<t.length-1;i++)o.push(n.highlight(t[i],i));o.push(n.removeHighlights(t[t.length-1])),o.current=t}(t),i.current=o(),i}}t.action("highlightNeighbors",r("highlightNeighbors"),i),t.action("highlight",r("highlight"),i),t.action("removeHighlights",r("removeHighlights"),i)}e.exports=function(e,t,o){n(e,t,o),function(e,t,n){function o(e){return n.show(e)}function i(e){return n.hide(e)}t.action("show",o,i),t.action("hide",i,o),t.action("showHiddenNeighbors",(function(e){return n.showHiddenNeighbors(e)}),i)}(0,t,o)}},function(e,t,n){e.exports=function(e,t){var o=[],i=0,r=!1,l=!1,s=!1,u=!1,a=!1,c=null;function h(){u=null,a||(d(!0),a=!0,l=!1,s=!1,r&&(b.disableMarqueeZoom(),r=!1))}function d(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(t.htmlElem4marqueeZoom){var n=null;t.htmlElem4marqueeZoom.startsWith(".")&&(n=document.getElementsByClassName(t.htmlElem4marqueeZoom.substr(1))[0]),t.htmlElem4marqueeZoom.startsWith("#")&&(n=document.getElementById(t.htmlElem4marqueeZoom.substr(1))),n?e?n.style.cursor=c:(c=n.style.cursor,t.marqueeZoomCursor.includes(".")?n.style.cursor="url('".concat(t.marqueeZoomCursor,"'), pointer"):n.style.cursor=t.marqueeZoomCursor):console.log("element not found!")}}function g(){t.selectStyles.node&&e.style().selector("node:selected").css(t.selectStyles.node).update(),t.selectStyles.edge&&e.style().selector("edge:selected").css(t.selectStyles.edge).update()}function f(n){var i=o[n],r=t.highlightStyles[n].node,l=t.highlightStyles[n].edge;e.style().selector("node."+i).css(r).update(),e.style().selector("edge."+i).css(l).update()}function y(n,i){e.startBatch();for(var r=0;r<t.highlightStyles.length;r++)n.removeClass(o[r]);n.addClass(o[i]),e.endBatch()}function m(e){return e.add(e.descendants()).closedNeighborhood()}!function(){for(var e=0;e<t.highlightStyles.length;e++){var n="__highligtighted__"+i;o.push(n),i++,f(e)}g(),document.addEventListener("keydown",(function(e){"Control"!=e.key&&"Shift"!=e.key&&"Meta"!=e.key||("Control"==e.key||"Meta"==e.key?s=!0:"Shift"==e.key&&(l=!0),a=!1,clearTimeout(u),u=setTimeout(h,750),s&&l&&!r&&(b.enableMarqueeZoom(),r=!0))})),document.addEventListener("keyup",(function(e){"Control"!=e.key&&"Shift"!=e.key&&"Meta"!=e.key||(a=!0,"Shift"==e.key?l=!1:"Control"!=e.key&&"Meta"!=e.key||(s=!1),!r||l&&s||(b.disableMarqueeZoom(),r=!1))}))}();var p,v,b={};b.hide=function(e){return(e=(e=e.filter(":visible")).union(e.connectedEdges())).unselect(),t.setVisibilityOnHide&&e.css("visibility","hidden"),t.setDisplayOnHide&&e.css("display","none"),e},b.show=function(e){if(e=e.not(":visible"),t.isShowEdgesBetweenVisibleNodes){var n=e.connectedEdges((function(t){return!(!t.source().visible()&&!e.contains(t.source())||!t.target().visible()&&!e.contains(t.target()))}));e=e.union(n)}return e.unselect(),t.setVisibilityOnHide&&e.css("visibility","visible"),t.setDisplayOnHide&&e.css("display","element"),e},b.showHiddenNeighbors=function(e){return this.show(m(e))},b.highlight=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return y(e,t),e},b.getHighlightStyles=function(){return t.highlightStyles},b.highlightNeighbors=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.highlight(m(e),t)},b.removeHighlights=function(n){e.startBatch(),null!=n&&null!=n.length||(n=e.elements());for(var i=0;i<t.highlightStyles.length;i++)n.removeClass(o[i]);return e.endBatch(),n},b.isHighlighted=function(e){for(var n=!1,i=0;i<t.highlightStyles.length;i++)e.is("."+o[i]+":visible")&&(n=!0);return n},b.changeHighlightStyle=function(e,n,o){t.highlightStyles[e].node=n,t.highlightStyles[e].edge=o,f(e),g()},b.addHighlightStyle=function(e,n){var r={node:e,edge:n};t.highlightStyles.push(r);var l="__highligtighted__"+i;o.push(l),i++,f(t.highlightStyles.length-1),g()},b.removeHighlightStyle=function(n){n<0||n>t.highlightStyles.length-1||(e.elements().removeClass(o[n]),t.highlightStyles.splice(n,1),o.splice(n,1))},b.getAllHighlightClasses=function(){for(var e=[],n=0;n<t.highlightStyles.length;n++)e.push(o[n]);return o},b.zoomToSelected=function(n){var o,i=n.boundingBox(),r=Math.abs(i.x1-i.x2),l=Math.abs(i.y1-i.y2);return o=r>=200||l>=200?50:e.width()<e.height()?(200-r)/2*e.width()/200:(200-l)/2*e.height()/200,e.animate({fit:{eles:n,padding:o}},{duration:t.zoomAnimationDuration}),n},b.enableMarqueeZoom=function(n){var o,i,s,u;d(!1),r=!0,e.autounselectify(!0),e.one("tapstart",p=function(e){1==l&&(o=e.position.x,i=e.position.y,s=void 0)}),e.one("tapend",v=function(r){if(s=r.position.x,u=r.position.y,null==o||null==s)return e.autounselectify(!1),void(n&&n());if(o>s){var l=o;o=s,s=l}if(i>u){l=i;i=u,u=l}var a;s-o<200&&(o-=a=(200-(s-o))/2,s+=a);u-i<200&&(i-=a=(200-(u-i))/2,u+=a);if(o>e.elements().boundingBox().x2||s<e.elements().boundingBox().x1||i>e.elements().boundingBox().y2||u<e.elements().boundingBox().y1)return e.autounselectify(!1),void(n&&n());var c=Math.min(e.width()/Math.abs(s-o),e.height()/Math.abs(u-i)),h=e.width()/2-(e.pan().x+c*(o+s)/2),d=e.height()/2-(e.pan().y+c*(i+u)/2);e.animate({panBy:{x:h,y:d},zoom:c,duration:t.zoomAnimationDuration,complete:function(){n&&n(),e.autounselectify(!1)}})})},b.disableMarqueeZoom=function(){d(!0),e.off("tapstart",p),e.off("tapend",v),e.autounselectify(!1),r=!1};var S=n(3);return b.changeLassoStyle=function(e){e.lineWidth&&(t.lassoStyle.lineWidth=e.lineWidth),e.lineColor&&(t.lassoStyle.lineColor=e.lineColor)},b.enableLassoMode=function(n){var o=!1,i=document.createElement("canvas");i.id="lasso-canvas";var r=e.container();r.appendChild(i);var l=r.offsetWidth,s=r.offsetHeight;i.width=l,i.height=s,i.setAttribute("style","z-index: 1000; position: absolute; top: 0; left: 0;"),e.panningEnabled(!1),e.zoomingEnabled(!1),e.autounselectify(!0);var u=[];i.onclick=function(l){if(0==o){o=!0;var s=i.getContext("2d");s.strokeStyle=t.lassoStyle.lineColor,s.lineWidth=t.lassoStyle.lineWidth,s.lineJoin="round",e.panningEnabled(!1),e.zoomingEnabled(!1),e.autounselectify(!0);var a=l.offsetX,c=l.offsetY;u.push([a,c]),i.onmouseleave=function(t){o=!1,r.removeChild(i),i=null,e.panningEnabled(!0),e.zoomingEnabled(!0),e.autounselectify(!1),n&&n()},i.onmousemove=function(e){s.beginPath(),u.push([e.offsetX,e.offsetY]),s.moveTo(a,c),s.lineTo(e.offsetX,e.offsetY),a=e.offsetX,c=e.offsetY,s.stroke(),s.closePath()}}else{var h=e.elements();u.push(u[0]);for(var d=0;d<h.length;d++)if(h[d].isEdge()){var g=[h[d].sourceEndpoint().x*e.zoom()+e.pan().x,h[d].sourceEndpoint().y*e.zoom()+e.pan().y],f=[h[d].targetEndpoint().x*e.zoom()+e.pan().x,h[d].targetEndpoint().y*e.zoom()+e.pan().y];S.pointInPolygon(g,u)&&S.pointInPolygon(f,u)&&h[d].select()}else{e.autounselectify(!1);var y=[[h[d].renderedBoundingBox().x1,h[d].renderedBoundingBox().y1],[h[d].renderedBoundingBox().x1,h[d].renderedBoundingBox().y2],[h[d].renderedBoundingBox().x2,h[d].renderedBoundingBox().y2],[h[d].renderedBoundingBox().x2,h[d].renderedBoundingBox().y1]];(S.polygonIntersectsPolygon(y,u)||S.polygonInPolygon(y,u)||S.polygonInPolygon(u,y))&&h[d].select()}o=!1,r.removeChild(i),i=null,e.panningEnabled(!0),e.zoomingEnabled(!0),n&&n()}}},b.disableLassoMode=function(){var t=document.getElementById("lasso-canvas");t&&(t.parentElement.removeChild(t),t=null),e.panningEnabled(!0),e.zoomingEnabled(!0),e.autounselectify(!1)},b}},function(t,n){t.exports=e}])}));