0||this.selectedObject!=null)&&selectedObject!=null){if(this.selectedObjects.length==0){this.selectedObjects.push(this.selectedObject);this.selectedObject=null;this.selectedObjects.push(selectedObject);}
else if(!this.selectedObjects.includes(selectedObject)){this.selectedObjects.push(selectedObject);}
else if(severalSelect&&this.selectedObjects.includes(selectedObject)){var index=this.selectedObjects.indexOf(selectedObject);this.selectedObjects.splice(index,1);}
if(!this.selectedLogCtrl){userAction("GroupSelected.SelectCtrl");this.selectedLogCtrl=true;}}
else
{if(selectedObject!=null){this.selectedObject=selectedObject;}
if((selectedObject instanceof BaseVertex)&&selectedObject!=null){this.dragObject=selectedObject;this.message=g_moveCursorForMoving;}}
this.needRedraw=true;this.pressed=true;this.prevPosition=pos;this.app.canvas.style.cursor="move";}
DefaultHandler.prototype.MouseUp=function(pos)
{this.saveUndo=false;this.message=this.GetDefaultText();this.dragObject=null;this.pressed=false;this.app.canvas.style.cursor="auto";this.app.SetSelectionRect(null);this.groupingSelect=false;if(this.selectedObject!=null&&(this.selectedObject instanceof BaseVertex))
{this.message=g_textsSelectAndMove
+""
+""
+""
+"
";var handler=this;var callback=function(enumType){handler.RenameVertex(enumType.GetVertexText(0),handler.selectedObject);userAction("RenameVertex");};$('#message').unbind();$('#message').on('click','#renameButton',function(){var customEnum=new TextEnumVerticesCustom(handler.app);customEnum.ShowDialog(callback,g_rename,g_renameVertex,handler.selectedObject.mainText);});$('#message').on('click','#changeCommonStyle',function(){var selectedVertices=handler.app.GetSelectedVertices();var setupVertexStyle=new SetupVertexStyle(handler.app);setupVertexStyle.show(0,selectedVertices);});$('#message').on('click','#changeSelectedStyle',function(){var selectedVertices=handler.app.GetSelectedVertices();var setupVertexStyle=new SetupVertexStyle(handler.app);setupVertexStyle.show(1,selectedVertices);});}
else if(this.selectedObject!=null&&(this.selectedObject instanceof BaseEdge))
{this.message=g_textsSelectAndMove
+""
+" "+g_curveEdge+" "
+" "
+""
+""
+""
+"
";var handler=this;$('#message').unbind();$('#message').on('click','#editEdge',function(){handler.ShowEditEdgeDialog(handler.selectedObject);});$('#message').on('click','#incCurvel',function(){handler.app.PushToStack("ChangeCurvelEdge");handler.selectedObject.model.ChangeCurveValue(DefaultHandler.prototype.curveValue);handler.needRedraw=true;handler.app.redrawGraph();userAction("Edge.Bend");});$('#message').on('click','#decCurvel',function(){handler.app.PushToStack("ChangeCurvelEdge");handler.selectedObject.model.ChangeCurveValue(-DefaultHandler.prototype.curveValue);handler.needRedraw=true;handler.app.redrawGraph();userAction("Edge.Bend");});$('#message').on('click','#changeCommonStyle',function(){var selectedEdges=handler.app.GetSelectedEdges();var setupVertexStyle=new SetupEdgeStyle(handler.app);setupVertexStyle.show(0,selectedEdges);});$('#message').on('click','#changeSelectedStyle',function(){var selectedEdges=handler.app.GetSelectedEdges();var setupVertexStyle=new SetupEdgeStyle(handler.app);setupVertexStyle.show(1,selectedEdges);});}
else if(this.selectedObjects.length>0)
{this.message=g_dragGroupText+" "+g_selectGroupText+"";var hasVertices=false;var hasEdges=false;for(var i=0;i";this.message=this.message
+"    "
+""
this.message=this.message
+"     "
+""
+"";var handler=this;$('#message').unbind();$('#message').on('click','#DublicateSelected',function(){handler.app.PushToStack("DublicateSelection");userAction("GroupSelected.Dublicate");var newSelected=[];var copyVertex={};for(var i=0;i=1)
{var curve=handler.app.GetAvailableCurveValue(neighborEdges,newObject);newObject.model.SetCurveValue(curve);}}
newSelected.push(newObject);}}
handler.selectedObjects=newSelected;handler.needRedraw=true;handler.app.redrawGraph();});$('#message').on('click','#RemoveSelected',function(){handler.app.PushToStack("RemoveSelection");userAction("GroupSelected.Remove");for(var i=0;i"+g_selectGroupText+"";});if(hasEdges){$('#message').on('click','#changeCommonStyleEdge',function(){var selectedEdges=handler.app.GetSelectedEdges();var setupVertexStyle=new SetupEdgeStyle(handler.app);setupVertexStyle.show(0,selectedEdges);});$('#message').on('click','#changeSelectedStyleEdge',function(){var selectedEdges=handler.app.GetSelectedEdges();var setupVertexStyle=new SetupEdgeStyle(handler.app);setupVertexStyle.show(1,selectedEdges);});}
if(hasVertices){$('#message').on('click','#changeCommonStyleVertex',function(){var selectedVertices=handler.app.GetSelectedVertices();var setupVertexStyle=new SetupVertexStyle(handler.app);setupVertexStyle.show(0,selectedVertices);});$('#message').on('click','#changeSelectedStyleVertex',function(){var selectedVertices=handler.app.GetSelectedVertices();var setupVertexStyle=new SetupVertexStyle(handler.app);setupVertexStyle.show(1,selectedVertices);});}}
this.needRedraw=true;}
DefaultHandler.prototype.GetSelectedGroup=function(object)
{return(object==this.dragObject)||(object==this.selectedObject)?1:0||this.selectedObjects.includes(object);}
DefaultHandler.prototype.SelectObjectInRect=function(rect)
{this.selectedObjects=[];var vertices=this.app.graph.vertices;for(var i=0;i"+g_selectGroupText+""+" "+g_useContextMenuText+""+
this.GetSelectOneVertexMenu();}
DefaultHandler.prototype.SelectFirstVertexMenu=function(vertex1Text,vertex)
{this.selectedObject=vertex;this.MouseUp(new Point(0,0));}
DefaultHandler.prototype.UpdateFirstVertexMenu=function(vertex1Text)
{if(this.selectedObject)
{vertex1Text.value=this.selectedObject.mainText;}}
BaseHandler.prototype.GraphWasUpdated=function()
{this.MouseUp(new Point(0,0));}
doInclude([include("features/base_handler/index.js")])
function AddGraphHandler(app)
{this.removeStack=true;BaseHandler.apply(this,arguments);this.message=g_clickToAddVertex;this.addContextMenu();}
AddGraphHandler.prototype=Object.create(BaseHandler.prototype);AddGraphHandler.prototype.MouseDown=function(pos)
{this.app.PushToStack("Add");this.app.CreateNewGraph(pos.x,pos.y);this.needRedraw=true;this.inited=false;}
AddGraphHandler.prototype.InitControls=function()
{var enumVertexsText=document.getElementById("enumVertexsText");if(enumVertexsText)
{var enumsList=this.app.GetEnumVerticesList();for(var i=0;i"
+" "
+""
+" "+baseMessage;}
ConnectionGraphHandler.checkUseDefaultEdge=function(elem,app)
{app.setUseDefaultEdge(elem.checked);app.updateMessage();};ConnectionGraphHandler.prototype.GetUseDefaultEdgeCheckBox=function(){if(!this.app.hasDefaultEdge()){return"";}
return" "+""+" "+"
";}
ConnectionGraphHandler.prototype.InitControls=function(){BaseHandler.prototype.InitControls.call(this)
if(!this.app.hasDefaultEdge()){return;}
let app=this.app;$('#useDefaultEdge').unbind();$('#useDefaultEdge').change(function(){app.setUseDefaultEdge(this.checked);});$("#useDefaultEdge").prop("checked",this.app.getUseDefaultEdge());}
doInclude([include("features/base_handler/index.js")])
function DeleteGraphHandler(app)
{this.removeStack=true;BaseHandler.apply(this,arguments);this.message=g_selectObjectToDelete;this.addContextMenu();}
DeleteGraphHandler.prototype=Object.create(BaseHandler.prototype);DeleteGraphHandler.prototype.MouseDown=function(pos)
{var selectedObject=this.GetSelectedObject(pos);if(!this.app.IsCorrectObject(selectedObject))
return;this.app.PushToStack("Delete");this.app.DeleteObject(selectedObject);this.needRedraw=true;}
function DeleteAllHandler(app)
{BaseHandler.apply(this,arguments);}
DeleteAllHandler.prototype=Object.create(BaseHandler.prototype);DeleteAllHandler.prototype.clear=function()
{this.app.PushToStack("DeleteAll");this.app.CreateNewGraphObject();this.needRedraw=true;}
doInclude([include("features/base_handler/index.js")])
function AlgorithmGraphHandler(app,algorithm)
{BaseHandler.apply(this,arguments);this.algorithm=algorithm;this.SaveUpText();this.UpdateResultAndMessage();}
AlgorithmGraphHandler.prototype=Object.create(BaseHandler.prototype);AlgorithmGraphHandler.prototype.MouseMove=function(pos){}
AlgorithmGraphHandler.prototype.MouseDown=function(pos)
{this.app.setRenderPath([]);if(this.algorithm.instance())
{this.app.SetDefaultHandler();}
else
{var selectedObject=this.GetSelectedGraph(pos);if(selectedObject&&(selectedObject instanceof BaseVertex))
{if(this.algorithm.selectVertex(selectedObject))
{this.needRedraw=true;}
this.UpdateResultAndMessage();}
else if(selectedObject&&(selectedObject instanceof BaseEdge))
{if(this.algorithm.selectEdge(selectedObject))
{this.needRedraw=true;}
this.UpdateResultAndMessage();}
else
{if(this.algorithm.deselectAll())
{this.needRedraw=true;this.UpdateResultAndMessage();}}}}
AlgorithmGraphHandler.prototype.MouseUp=function(pos){}
AlgorithmGraphHandler.prototype.GetSelectedGroup=function(object)
{return this.algorithm.getObjectSelectedGroup(object);}
AlgorithmGraphHandler.prototype.RestoreAll=function()
{this.app.setRenderPath([]);if(this.algorithm.needRestoreUpText())
{this.RestoreUpText();}
if(this.algorithm.wantRestore())
{this.algorithm.restore();}}
AlgorithmGraphHandler.prototype.SaveUpText=function()
{this.vertexUpText={};var graph=this.app.graph;for(i=0;i0)
{this.zoomPlusButton=zoomPlusArray[0];this.zoomPlusButton.onclick=function()
{zoomFunc(one_scale);};}
let zoomMinusArray=canvasParent.getElementsByClassName("zoom-minus");if(zoomMinusArray.length>0)
{this.zoomMinusButton=zoomMinusArray[0];this.zoomMinusButton.onclick=function()
{zoomFunc(1.0/one_scale);};}
this.canvas.onmousemove=function(e)
{return preview.CanvasOnMouseMove(e);}
this.canvas.onmousedown=function(e)
{return preview.CanvasOnMouseDown(e);}
this.canvas.onmouseup=function(e)
{return preview.CanvasOnMouseUp(e);}
this.canvas.onwheel=function(e)
{var e=window.event||e;var delta=Math.max(-1,Math.min(1,(e.wheelDelta||-e.detail)));if(delta>0)
{zoomFunc(one_scale);}
else
{zoomFunc(1.0/one_scale);}}
this.canvas.removeEventListener("touchstart",touchHandler,true);this.canvas.removeEventListener("touchmove",touchHandler,true);this.canvas.removeEventListener("touchend",touchHandler,true);this.canvas.removeEventListener("touchcancel",touchHandler,true);this.canvas.addEventListener("touchstart",touchHandler,true);this.canvas.addEventListener("touchmove",touchHandler,true);this.canvas.addEventListener("touchend",touchHandler,true);this.canvas.addEventListener("touchcancel",touchHandler,true);this.redraw();setTimeout(function()
{this.redraw();}.bind(this),1000);}
GraphPreview.prototype.redraw=function()
{const ctx=this.canvas.getContext("2d");ctx.save();ctx.scale(this.canvasScale,this.canvasScale);ctx.translate(this.canvasPosition.x,this.canvasPosition.y);this.redrawGraph(ctx,this.canvasPosition);ctx.restore();}
GraphPreview.prototype.getRealWidth=function()
{return this.canvas.width/this.canvasScale;}
GraphPreview.prototype.getRealHeight=function()
{return this.canvas.height/this.canvasScale;}
GraphPreview.prototype.redrawGraph=function(context,backgroundPosition)
{var backgroundDrawer=new BaseBackgroundDrawer(context);backgroundDrawer.Draw(this.style.backgroundCommonStyle,Math.max(this.canvas.width,this.getRealWidth()),Math.max(this.canvas.height,this.getRealHeight()),backgroundPosition,this.canvasScale);for(i=0;i0)
{if(bboxSize.x>this.getRealWidth()||bboxSize.y>this.getRealHeight())
{this.canvasScale=Math.min(this.getRealWidth()/bboxSize.x,this.getRealHeight()/bboxSize.y);}
if(graphBBox.minPoint.x<0.0||graphBBox.minPoint.y<0.0||graphBBox.maxPoint.x>this.getRealWidth()||graphBBox.maxPoint.y>this.getRealHeight())
{this.canvasPosition=graphBBox.minPoint.inverse();}}}
GraphPreview.prototype.CanvasOnMouseMove=function(e)
{if(this.prevMousePos==null)
{return;}
var pos=this.getMousePos(this.canvas,e);let newPos=(new Point(pos.x,pos.y)).subtract(this.prevMousePos).multiply(this.canvasScale);this.canvasPosition=this.canvasPosition.add(newPos.multiply(1/this.canvasScale));this.redraw();this.callPositionUpdateCallback();}
GraphPreview.prototype.CanvasOnMouseDown=function(e)
{if(e.which!==1)return;var pos=this.getMousePos(this.canvas,e);this.prevMousePos=pos;}
GraphPreview.prototype.CanvasOnMouseUp=function(e)
{if(e.which!==1)return;this.prevMousePos=null;}
GraphPreview.prototype.getMousePos=function(canvas,e)
{var rect=canvas.getBoundingClientRect();return new Point((e.clientX-rect.left)/this.canvasScale-this.canvasPosition.x,(e.clientY-rect.top)/this.canvasScale-this.canvasPosition.y);}
GraphPreview.prototype.callPositionUpdateCallback=function()
{if(this.positionUpdateCallback!=null)
{this.positionUpdateCallback(this.canvasPosition,this.canvasScale);}}
{let modulDir="features/serialization/";doInclude([include("model/GraphMLCreator.js",modulDir)])}
function GraphMLCreator(nodes,arcs,ignoreNodes={})
{this.nodes=nodes;this.arcs=arcs;this.ignoreNodes=ignoreNodes;}
GraphMLCreator.prototype.GetXMLString=function()
{var mainHeader="";var directedHeader="";var undirectedHeader="";var defaultWeight=1.0;var weightKeyId="\"d0\"";var weightNode=""+""+defaultWeight+""+"";var xmlBody="";for(var i=0;i";}
var hasDirected=false;for(var i=0;i"+arc.weight+"";}
xmlBody=xmlBody+""+weightData+"":"/>")}
xml=mainHeader+weightNode+(hasDirected?directedHeader:undirectedHeader)+xmlBody+""
return xml;}
function BaseEnumVertices(app,startNumber)
{this.app=app;this.startNumber=startNumber;}
BaseEnumVertices.prototype.GetVertexText=function(id)
{return this.startNumber+id;}
BaseEnumVertices.prototype.GetVertexTextAsync=function(callback)
{callback(this);}
BaseEnumVertices.prototype.GetText=function()
{return this.startNumber+", "+(this.startNumber+1)+", "+(this.startNumber+2)+"...";}
BaseEnumVertices.prototype.GetValue=function()
{return"Numbers"+this.startNumber;}
function TextEnumTitle(app,title)
{BaseEnumVertices.apply(this,arguments);this.pattern="";this.title=title;}
TextEnumTitle.prototype=Object.create(BaseEnumVertices.prototype);TextEnumTitle.prototype.GetVertexText=function(id)
{return this.title;}
function TextEnumVertices(app)
{BaseEnumVertices.apply(this,arguments);this.pattern="ABCDEFGHIJKLMNOPQRSTUVWXYZ";}
TextEnumVertices.prototype=Object.create(BaseEnumVertices.prototype);TextEnumVertices.prototype.GetVertexText=function(id)
{var res="";res=this.pattern[id%this.pattern.length]+res;while(id>=this.pattern.length)
{id=Math.floor(id/this.pattern.length)-1;res=this.pattern[id%this.pattern.length]+res;}
return res;}
TextEnumVertices.prototype.GetText=function()
{return"A, B, ... Z";}
TextEnumVertices.prototype.GetValue=function()
{return"Latin";}
function TextEnumVerticesCyr(app)
{TextEnumVertices.apply(this,arguments);this.pattern="АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";}
TextEnumVerticesCyr.prototype=Object.create(TextEnumVertices.prototype);TextEnumVerticesCyr.prototype.GetText=function()
{return"А, Б, ... Я";}
TextEnumVerticesCyr.prototype.GetValue=function()
{return"Cyrillic";}
function TextEnumVerticesGreek(app)
{TextEnumVertices.apply(this,arguments);this.pattern="ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ";}
TextEnumVerticesGreek.prototype=Object.create(TextEnumVertices.prototype);TextEnumVerticesGreek.prototype.GetText=function()
{return"Α, Β, ... Ω";}
TextEnumVerticesGreek.prototype.GetValue=function()
{return"Greek";}
function TextEnumVerticesCustom(app)
{BaseEnumVertices.apply(this,arguments);this.pattern="";}
TextEnumVerticesCustom.prototype=Object.create(BaseEnumVertices.prototype);TextEnumVerticesCustom.prototype.GetText=function()
{return g_customEnumVertex;}
TextEnumVerticesCustom.prototype.GetValue=function()
{return"Custom";}
TextEnumVerticesCustom.prototype.GetVertexTextAsync=function(callback)
{this.ShowDialog(callback,g_addVertex,g_addVertex,"A");}
TextEnumVerticesCustom.prototype.ShowDialog=function(callback,buttonText,titleTitle,title)
{var dialogButtons={};app=this.app;dialogButtons[buttonText]=function(){app.PushToStack("RenameVertex");callback(new TextEnumTitle(app,$("#VertexTitle").val()));$(this).dialog("close");};$("#addVertex").dialog({resizable:false,height:"auto",width:"auto",modal:true,title:titleTitle,buttons:dialogButtons,dialogClass:'EdgeDialog',open:function(){$(this).off('submit').on('submit',function(){return false;});$("#VertexTitle").val(title);$("#VertexTitle").focus();}});}
var g_textsSelectAndMove="Drag objects";var g_moveCursorForMoving="Move cursor";var g_clickToAddVertex="Click to add vertex";var g_selectFirstVertexToConnect="Select first vertex to connect";var g_selectSecondVertexToConnect="Select second vertex to connect";var g_selectStartVertexForShortPath="Select start vertex for shortest path";var g_selectFinishVertexForShortPath="Select finish vertex for shortest path";var g_shortestPathResult="Shortest path is %d";var g_pathNotExists="Path does not exists";var g_selectObjectToDelete="Select object to delete";var g_addEdge="Add edge";var g_orintEdge="Directed";var g_notOrintEdge="Undirected";var g_adjacencyMatrixText="Adjacency Matrix";var g_save="Save";var g_cancel="Cancel";var g_save_graph="Save Graph";var g_shortestDistance="lowest-distance is ";var g_incidenceMatrixText="Incidence Matrix";var g_save_dialog="Save dialog";var g_close="close";var g_sickConnectedComponent="Sick connected component is ";var g_connectedComponent="Connected component is ";var g_what_do_you_think="What do you think about site?";var g_name="Name";var g_feedback="Feedback";var g_send="Send";var g_write_to_us="Write to us";var g_fixMatrix="Fix matrix";var g_readMatrixHelp="Matrix format help";var g_matrixWrongFormat="Matrix is wrong";var g_pairWrongFormat="Edge List is wrong";var g_fix="Fix"
var g_save_image_dialog="Save graph image";var g_fullReport="Full report";var g_shortReport="Short report";var g_hasEulerianLoop="Graph has Eulerian Loop";var g_hasNotEulerianLoop="Graph has not Eulerian Loop";var g_hasEulerianPath="Graph has Eulerian Path";var g_hasNotEulerianPath="Graph has not Eulerian Path";var g_processing="Processing...";var g_customEnumVertex="Custom";var g_addVertex="Add vertex";var g_renameVertex="Rename vertex";var g_rename="Rename";var g_language="en";var g_editWeight="Edit weight";var g_noWeight="No weight";var g_groupRename="Group rename";var g_vote="Vote";var g_recommendAlgorithm="Recommend algorithm";var g_graphOfMinDist="Graph of minimal distances.";var g_checkToSave="Check to save";var g_showDistMatrix="Show Distance matrix";var g_minDistMatrixText="Minimal distances matrix";var g_selectStartVertexForMaxFlow="Select source vertex for max flow";var g_selectFinishVertexForMaxFlow="Select sink vertex for max flow";var g_maxFlowResult="Maximum flow from %2 to %3 is %1";var g_flowNotExists="Flow from %1 to %2 does not exists";var g_sourceVertex="Source";var g_sinkVertex="Sink";var g_hasHamiltonianLoop="Graph has Hamiltonian Loop";var g_hasNotHamiltonianLoop="Graph has not Hamiltonian Loop";var g_hasHamiltonianPath="Graph has Hamiltonian Path";var g_hasNotHamiltonianPath="Graph has not Hamiltonian Path";var g_startTraversal="Select start traversal vector";var g_traversalOrder="Traversal order: ";var g_curveEdge="Curved edge";var g_Undo="Undo";var g_default="default";var g_vertexDraw="Vertex draw style";var g_edgeDraw="Edge draw style";var g_backgroundStyle="Background style";var g_GraphIsMultiMessage="Graph is multigraph";var g_GraphIsGeneralMessage="";var g_DefaultWeightPreset="no weight";var g_dragGroupText="Drag group.";var g_selectGroupText="Select using ctrl";var g_copyGroupeButton="Duplicate";var g_removeGroupeButton="Remove objects";var g_BFSName="Breadth-first search";var g_ColoringName="Graph coloring";var g_findConnectedComponent="Find connected components";var g_DFSName="Depth-first search";var g_EulerinLoopName="Find Eulerian cycle";var g_EulerinPath="Find Eulerian path";var g_FloidName="Floyd–Warshall algorithm";var g_GraphReorder="Arrange the graph";var g_HamiltoianCycleName="Find Hamiltonian cycle";var g_HamiltonianPath="Find Hamiltonian path";var g_MaxFlowName="Find Maximum flow";var g_minimumSpanningTree="Search of minimum spanning tree";var g_modernGraphStyleName="Visualization based on weight";var g_RadiusAndDiameter="Search graph radius and diameter";var g_findShortPathName="Find shortest path using Dijkstra's algorithm";var g_findShortPathBellmanFordName="Find shortest path using Bellman–Ford algorithm";var g_VerticesDegreeName="Calculate vertices degree";var g_SpanningTreeResult="Min Spanning Tree is";var g_SpanningTreeIgnoreDir="We ignored edges direction for calculation";var g_SpanningTreeNotConnected="Graph is not connected";var g_selectFirstGraphIsomorphismCheck="Select first graph for isomorphic check. Click to any node of graph";var g_selectSecondGraphIsomorphismCheck="Select second graph for isomorphic check. Click to any node of graph";var g_selectFirstGraphPatternCheck="Select a template graph by clicking to any node of graph";var g_selectSecondGraphForSearchSubgraph="Choose a graph in which we will look for isomorphic subgraphs. Click to any node of this graph";var g_graphsIsomorph="Graphs are isomorphic";var g_graphsNotIsomorph="Graphs are not isomorphic";var g_numberOfIsomorphSubgraphIs="Number of isomorphic subgraphs are ";var g_graphHasNoIsomorphSubgraph="Graph don't contain isomorphic subgraphs";var g_searchIsomorphSubgraph="Search isomorphic subgraphs";var g_subgraphNo="Isomorphic subgraph # ";var g_graphHasNoAtleast2Graphs="To use the algorithm, you need to create 2 separate graphs";var g_IsomorphismCheck="Check Graphs Isomorphism";var g_graphIsDisconnected="Graph is disconnected";var g_graphIsTrivial="Graph contains only one vertex";var g_graphRadius="Graph radius";var g_graphDiameter="Graph diameter";var g_vertexCentral="Central";var g_vertexPeripheral="Peripheral";var g_maximumDegreeOfGraph="The maximum degree of a graph is";var g_colorNumber="Color number is";var g_done="Done";var g_action="Action";var g_commonEdgeStyle="Common Edge Style";var g_selectedEdgeStyle="Selected Edge Style";var g_commonVertexStyle="Common Vertex Style";var g_selectedVertexStyle="Selected Vertex Style";var g_findAllPathes="Find all paths";var g_numberOfPathesFrom="Number of paths from "
var g_to=" to ";var g_are=" are ";var g_pathN="Path #";var g_selectFinishVertex="Select finish vertex";var g_selectStartVertex="Select start vertex";var g_findAllPathesFromVertex="Find all shortest paths from vertex";var g_distanceFrom="Distance from ";var g_pathTo="Path to ";var g_useContextMenuText="Use context menu for addition actions."
var g_findLongestPath="Find the longest path";var g_LengthOfLongestPathFrom="Length of the longest path from ";var g_additionalActions="Additional actions";var g_reverseAllEdges="Reverse all edges";var g_makeAllUndirected="Make all edges undirected";var g_makeAllDirected="Make all edges directed";var g_reuseSavedEdge="Reuse saved edge";var g_MaxClique="Max Clique";var g_MaxCliqueNotFound="Max Clique is not found";var g_MaxCliqueSizeIs="Max Clique size is ";var g_MaxCliqueContains=". Clique contains these vertecies: ";var g_wrongImageFormatPNGAndJPEG="Wrong image format. We support only JPEG and PNG.";var g_wrongImageSizeP1="Image size is too big. Image size must be less than {0} pixels.";var g_originalGraph="Original graph";var g_autoSavedGraph="Autosaved graph";var g_selectGraphToLoad="Would you like to load original graph or autosaved graph?";var g_vertexNamePlaceHolder="vertex name";function loadTexts()
{g_textsSelectAndMove=document.getElementById("SelectAndMoveObject").innerHTML;g_moveCursorForMoving=document.getElementById("MoveCursorForMoving").innerHTML;g_clickToAddVertex=document.getElementById("clickToAddVertex").innerHTML;g_selectFirstVertexToConnect=document.getElementById("selectFisrtVertextToConnect").innerHTML;g_selectSecondVertexToConnect=document.getElementById("selectSecondVertextToConnect").innerHTML;g_selectStartVertexForShortPath=document.getElementById("selectStartShortPathVertex").innerHTML;g_selectFinishVertexForShortPath=document.getElementById("selectFinishShortPathVertex").innerHTML;g_shortestPathResult=document.getElementById("shortPathResult").innerHTML;g_pathNotExists=document.getElementById("pathNotExists").innerHTML;g_selectObjectToDelete=document.getElementById("selectObjectToDelete").innerHTML;g_addEdge=document.getElementById("AddEdge").innerHTML;g_orintEdge=document.getElementById("OrintEdge").innerHTML;g_notOrintEdge=document.getElementById("NotOrintdge").innerHTML;g_adjacencyMatrixText=document.getElementById("AdjacencyMatrixText").innerHTML;g_save=document.getElementById("Save").innerHTML;g_cancel=document.getElementById("Cancel").innerHTML;g_shortestDistance=document.getElementById("shortestDist").innerHTML;g_incidenceMatrixText=document.getElementById("IncidenceMatrixText").innerHTML;g_save_dialog=document.getElementById("saveDialogTitle").innerHTML;g_close=document.getElementById("closeButton").innerHTML;g_sickConnectedComponent=document.getElementById("sickConnectedComponentResult").innerHTML;g_connectedComponent=document.getElementById("connectedComponentResult").innerHTML;g_what_do_you_think=document.getElementById("whatDoYouThink").innerHTML;g_name=document.getElementById("name").innerHTML;g_feedback=document.getElementById("feedback").innerHTML;g_send=document.getElementById("send").innerHTML;g_write_to_us=document.getElementById("writeToUs").innerHTML;g_fixMatrix=document.getElementById("fixMatrixButton").innerHTML;g_readMatrixHelp=document.getElementById("matrixHelp").innerHTML;g_matrixWrongFormat=document.getElementById("wronMatrixTitle").innerHTML;g_save_image_dialog=document.getElementById("saveImageDialogTitle").innerHTML;g_fullReport=document.getElementById("fullReport").innerHTML;g_shortReport=document.getElementById("shortReport").innerHTML;g_hasEulerianLoop=document.getElementById("hasEulerianLoop").innerHTML;g_hasNotEulerianLoop=document.getElementById("hasNotEulerianLoop").innerHTML;g_processing=document.getElementById("processing").innerHTML;g_customEnumVertex=document.getElementById("customEnumVertex").innerHTML;g_addVertex=document.getElementById("addVertexText").innerHTML;g_renameVertex=document.getElementById("renameVertex").innerHTML;g_rename=document.getElementById("renameText").innerHTML;g_language=document.getElementById("currentLanguage").innerHTML;g_editWeight=document.getElementById("editWeight").innerHTML;g_noWeight=document.getElementById("noWeight").innerHTML;g_groupRename=document.getElementById("groupeRenameText").innerHTML;g_vote=document.getElementById("voteText").innerHTML;g_recommendAlgorithm=document.getElementById("recommend_algorithm").innerHTML;g_hasEulerianPath=document.getElementById("hasEulerianPath").innerHTML;g_hasNotEulerianPath=document.getElementById("hasNotEulerianPath").innerHTML;g_graphOfMinDist=document.getElementById("graphOfMinDist").innerHTML;g_checkToSave=document.getElementById("checkToSave").innerHTML;g_showDistMatrix=document.getElementById("showDistMatrix").innerHTML;g_minDistMatrixText=document.getElementById("distMatrixText").innerHTML;g_selectStartVertexForMaxFlow=document.getElementById("selectStartVertexForMaxFlow").innerHTML;g_selectFinishVertexForMaxFlow=document.getElementById("selectFinishVertexForMaxFlow").innerHTML;g_maxFlowResult=document.getElementById("maxFlowResult").innerHTML;g_flowNotExists=document.getElementById("flowNotExists").innerHTML;g_sourceVertex=document.getElementById("sourceVertex").innerHTML;g_sinkVertex=document.getElementById("sinkVertex").innerHTML;g_hasHamiltonianLoop=document.getElementById("hasHamiltonianLoop").innerHTML;g_hasNotHamiltonianLoop=document.getElementById("hasNotHamiltonianLoop").innerHTML;g_hasHamiltonianPath=document.getElementById("hasHamiltonianPath").innerHTML;g_hasNotHamiltonianPath=document.getElementById("hasNotHamiltonianPath").innerHTML;g_startTraversal=document.getElementById("startTraversal").innerHTML;g_traversalOrder=document.getElementById("traversalOrder").innerHTML;g_curveEdge=document.getElementById("curveEdge").innerHTML;g_Undo=document.getElementById("undoTranslate").innerHTML;g_save_graph=document.getElementById("saveGraph").innerHTML;g_default=document.getElementById("default").innerHTML;g_vertexDraw=document.getElementById("vertexDrawStyle").innerHTML;g_edgeDraw=document.getElementById("edgeDrawStyle").innerHTML;g_backgroundStyle=document.getElementById("backgroundStyle").innerHTML;g_GraphIsMultiMessage=document.getElementById("graphIsMultiMessage").innerHTML;g_GraphIsGeneralMessage=document.getElementById("graphIsGeneralMessage").innerHTML;g_DefaultWeightPreset=document.getElementById("defaultWeightPreset").innerHTML;var isMac=navigator.platform.toUpperCase().indexOf('MAC')>=0;if(isMac)
g_selectGroupText=document.getElementById("selectGroupMac").innerHTML;else
g_selectGroupText=document.getElementById("selectGroupWin").innerHTML;g_dragGroupText=document.getElementById("dragSelectedGroup").innerHTML;g_copyGroupeButton=document.getElementById("copySelectedGroup").innerHTML;g_removeGroupeButton=document.getElementById("removeSelectedGroup").innerHTML;g_BFSName=document.getElementById("BFSName").innerHTML;g_ColoringName=document.getElementById("ColoringName").innerHTML;g_findConnectedComponent=document.getElementById("findConnectedComponent").innerHTML;g_DFSName=document.getElementById("DFSName").innerHTML;g_EulerinLoopName=document.getElementById("EulerinLoopName").innerHTML;g_EulerinPath=document.getElementById("EulerinPath").innerHTML;g_FloidName=document.getElementById("FloidName").innerHTML;g_GraphReorder=document.getElementById("GraphReorder").innerHTML;g_HamiltoianCycleName=document.getElementById("HamiltoianCycleName").innerHTML;g_HamiltonianPath=document.getElementById("HamiltonianPath").innerHTML;g_MaxFlowName=document.getElementById("MaxFlowName").innerHTML;g_minimumSpanningTree=document.getElementById("minimumSpanningTree").innerHTML;g_modernGraphStyleName=document.getElementById("modernGraphStyleName").innerHTML;g_RadiusAndDiameter=document.getElementById("RadiusAndDiameter").innerHTML;g_findShortPathName=document.getElementById("findShortPathName").innerHTML;g_findShortPathBellmanFordName=document.getElementById("findShortPathBellmanFordName").innerHTML;g_VerticesDegreeName=document.getElementById("VerticesDegreeName").innerHTML;g_SpanningTreeResult=document.getElementById("MinSpanningTreeResult").innerHTML;g_SpanningTreeIgnoreDir=document.getElementById("MinSpanningIgnoreDir").innerHTML;g_SpanningTreeNotConnected=document.getElementById("MinSpanningNotConnected").innerHTML;g_selectFirstGraphIsomorphismCheck=document.getElementById("SelectFirstGraphIsomorphismCheck").innerHTML;g_selectSecondGraphIsomorphismCheck=document.getElementById("SelectSecondGraphIsomorphismCheck").innerHTML;g_selectFirstGraphPatternCheck=document.getElementById("SelectFirstGraphPatternCheck").innerHTML;g_selectSecondGraphForSearchSubgraph=document.getElementById("SelectSecondGraphForSearchSubgraph").innerHTML;g_graphsIsomorph=document.getElementById("GraphsIsomorph").innerHTML;g_graphsNotIsomorph=document.getElementById("GraphsNotIsomorph").innerHTML;g_numberOfIsomorphSubgraphIs=document.getElementById("NumberOfIsomorphSubgraphIs").innerHTML;g_graphHasNoIsomorphSubgraph=document.getElementById("GraphHasNoIsomorphSubgraph").innerHTML;g_searchIsomorphSubgraph=document.getElementById("SearchIsomorphSubgraph").innerHTML;g_subgraphNo=document.getElementById("SubgraphNo").innerHTML;g_graphHasNoAtleast2Graphs=document.getElementById("GraphHasNoAtleast2Graphs").innerHTML;g_IsomorphismCheck=document.getElementById("IsomorphismCheck").innerHTML;g_graphIsDisconnected=document.getElementById("GraphIsDisconnected").innerHTML;g_graphIsTrivial=document.getElementById("GraphIsTrivial").innerHTML;g_graphRadius=document.getElementById("GraphRadius").innerHTML;g_graphDiameter=document.getElementById("GraphDiameter").innerHTML;g_vertexCentral=document.getElementById("VertexCentral").innerHTML;g_vertexPeripheral=document.getElementById("VertexPeripheral").innerHTML;g_maximumDegreeOfGraph=document.getElementById("MaximumDegreeOfGraph").innerHTML;g_colorNumber=document.getElementById("ColorNumber").innerHTML;g_done=document.getElementById("Done").innerHTML;g_action=document.getElementById("ActionText").innerHTML;g_commonEdgeStyle=document.getElementById("CommonEdgeStyleText").innerHTML;g_selectedEdgeStyle=document.getElementById("SelectedEdgeStyleText").innerHTML;g_commonVertexStyle=document.getElementById("CommonVertexStyleText").innerHTML;g_selectedVertexStyle=document.getElementById("SelectedVertexStyleText").innerHTML;g_findAllPathes=document.getElementById("FindAllPathes").innerHTML;g_numberOfPathesFrom=document.getElementById("NumberOfPathesFrom").innerHTML;g_to=document.getElementById("To").innerHTML;g_are=document.getElementById("Are").innerHTML;g_pathN=document.getElementById("PathN").innerHTML;g_selectFinishVertex=document.getElementById("SelectFinishVertex").innerHTML;g_selectStartVertex=document.getElementById("SelectStartVertex").innerHTML;g_findAllPathesFromVertex=document.getElementById("findAllPathsFromVertex").innerHTML;g_distanceFrom=document.getElementById("distanceFrom").innerHTML;g_pathTo=document.getElementById("pathTo").innerHTML;g_useContextMenuText=document.getElementById("UseContextMenuText").innerHTML;g_findLongestPath=document.getElementById("findLongestPath").innerHTML;g_LengthOfLongestPathFrom=document.getElementById("LengthOfLongestPathFrom").innerHTML;g_additionalActions=document.getElementById("additionlActions").innerHTML;g_reverseAllEdges=document.getElementById("reverseAllEdges").innerHTML;g_makeAllUndirected=document.getElementById("makeAllUndirected").innerHTML;g_makeAllDirected=document.getElementById("makeAllDirected").innerHTML;g_pairWrongFormat=document.getElementById("pairWrongFormat").innerHTML;g_fix=document.getElementById("fixButton").innerHTML;g_reuseSavedEdge=document.getElementById("reuseSavedEdge").innerHTML;g_MaxClique=document.getElementById("maxClique").innerHTML;g_MaxCliqueNotFound=document.getElementById("maxCliqueNotFound").innerHTML;g_MaxCliqueSizeIs=document.getElementById("maxCliqueSizeIs").innerHTML;g_MaxCliqueContains=document.getElementById("maxCliqueContains").innerHTML;g_wrongImageFormatPNGAndJPEG=document.getElementById("wrongImageFormatPNGAndJPEG").innerHTML;g_wrongImageSizeP1=document.getElementById("wrongImageSizeP1").innerHTML;g_originalGraph=document.getElementById("originalGraph").innerHTML;g_autoSavedGraph=document.getElementById("autoSavedGraph").innerHTML;g_selectGraphToLoad=document.getElementById("selectGraphToLoad").innerHTML;g_vertexNamePlaceHolder=document.getElementById("vertexNamePlaceHolder").innerHTML;}
function UndoStack(maxUndoStackSize){this.undoStack=[];this.maxUndoStackSize=maxUndoStackSize;}
UndoStack.prototype.PushToStack=function(actionName,dataToSave)
{var object={};object.actionName=actionName;object.data=dataToSave;this.undoStack.push(object);while(this.undoStack.length>this.maxUndoStackSize)
{this.undoStack.shift();}}
UndoStack.prototype.Undo=function()
{if(this.IsUndoStackEmpty())
return null;var state=this.undoStack.pop();return state.data;}
UndoStack.prototype.ClearUndoStack=function()
{this.undoStack=[];}
UndoStack.prototype.IsUndoStackEmpty=function()
{return(this.undoStack.length<=0);}
var DiskSaveLoad=function(){};DiskSaveLoad.LoadGraphFromDisk=function(graphName,callback)
{$.ajax({type:"GET",url:"/"+SiteDir+"backend/loadGraph.php?name="+graphName}).done(callback);}
DiskSaveLoad.SaveSVGGraphOnDisk=function(imageName,svgText,callback)
{$.ajax({type:"POST",url:"/"+SiteDir+"backend/saveSvg.php?name="+imageName,data:svgText,dataType:"text",contentType:"text/xml; charset=utf-8",success:callback});return imageName;}
DiskSaveLoad.SaveGraphOnDisk=function(savedGraphName,graphAsString,callback)
{$.ajax({type:"POST",url:"/"+SiteDir+"backend/saveGraph.php?name="+savedGraphName,data:graphAsString,dataType:"text"}).done(callback);}
DiskSaveLoad.SaveGraphImageOnDisk=function(imageName,rectParams,imageBase64Data,callback)
{$.ajax({type:"POST",url:"/"+SiteDir+"backend/saveImage.php?name="+imageName+rectParams,data:{base64data:imageBase64Data},dataType:"text",success:callback});}
DiskSaveLoad.SaveAutoSaveGraphOnDisk=function(savedGraphName,graphAsString,callback)
{$.ajax({type:"POST",url:"/"+SiteDir+"backend/saveGraph.php?name=autosave_"+savedGraphName,data:graphAsString,dataType:"text"}).done(callback);}
DiskSaveLoad.LoadAutoSaveGraphFromDisk=function(graphName,callback)
{$.ajax({type:"GET",url:"/"+SiteDir+"backend/loadGraph.php?name=autosave_"+graphName}).done(callback);}
DiskSaveLoad.RemoveAutoSaveGraphFromDisk=function(graphName,callback)
{$.ajax({type:"GET",url:"/"+SiteDir+"backend/removeGraph.php?name=autosave_"+graphName}).done(callback);}
var globalApplication=null;function Application(document,window,listener)
{this.document=document;this.listener=listener;this.canvas=this.document.getElementById('canvas');this.handler=new DefaultHandler(this);this.savedGraphName="";this.currentEnumVerticesType=new BaseEnumVertices(this,1);this.findPathReport=1;this.isTimerRender=false;globalApplication=this;this.renderPath=[];this.renderTimer=0;this.renderPathLength=0;this.renderPathCounter=0;this.renderPathLoops=0;this.enumVerticesTextList=[new BaseEnumVertices(this,1),new BaseEnumVertices(this,0),new TextEnumVertices(this),new TextEnumVerticesCyr(this),new TextEnumVerticesGreek(this),new TextEnumVerticesCustom(this)];this.SetDefaultTransformations();this.algorithmsValues={};this.undoStack=new UndoStack(this.maxUndoStackSize);this.style=new GraphFullStyle(function()
{this.redrawGraph();}.bind(this));this.edgePrintCommonStyle=new CommonPrintEdgeStyle();this.edgePrintSelectedStyles=FullArrayCopy(DefaultPrintSelectedEdgeStyles);this.vertexPrintCommonStyle=new CommonPrintVertexStyle();this.vertexPrintSelectedVertexStyles=FullArrayCopy(DefaultPrintSelectedGraphStyles);this.backgroundPrintStyle=new PrintBackgroundStyle();this.renderPathWithEdges=false;this.edgePresets=[1,3,5,7,11,42];this.maxEdgePresets=6;this.selectionRect=null;this.processEmscriptenFunction=null;this.defaultEdge=null;this.useDefaultEdge=false;this.lastSavedAutoSave="";this.lastGraphName="";this.lastUsedGraphs=[];};Application.prototype.graph=new Graph();Application.prototype.dragObject=-1;Application.prototype.handler=null;Application.prototype.status={};Application.prototype.graphNameLength=16;Application.prototype.maxUndoStackSize=8;Application.prototype.maxAutosaveSizeForCookie=2000;Application.prototype.autosaveTimeInterval=1000*60;Application.prototype.styliedGraphNamePostfix="ZZcst";Application.prototype.maxLastUsedGraphCount=5;Application.prototype.getMousePos=function(canvas,e)
{var rect=canvas.getBoundingClientRect();return{x:(e.clientX-rect.left)/this.canvasScale-this.canvasPosition.x,y:(e.clientY-rect.top)/this.canvasScale-this.canvasPosition.y};}
Application.prototype.redrawGraph=function()
{if(!this.isTimerRender)
{this._redrawGraphInWindow();this.GraphTypeChanged();}}
Application.prototype.redrawGraphTimer=function()
{if(this.isTimerRender)
{var context=this._redrawGraphInWindow();if(this.renderPath.length>1)
{context.save();context.scale(this.canvasScale,this.canvasScale);context.translate(this.canvasPosition.x,this.canvasPosition.y);var movePixelStep=16;var currentLength=0;var i=0
for(i=0;ithis.renderPathCounter)
{currentLength-=edge.GetPixelLength();break;}}
if(i>=this.renderPath.length-1)
{i=0;if(this.renderPathWithEdges)
i=1;this.renderPathCounter=0;currentLength=0;this.renderPathLoops+=1;}
var edge=null;var currentVertexId=this.renderPath[i];if(this.renderPathWithEdges)
{edge=this.graph.FindEdgeById(this.renderPath[i]);currentVertexId=this.renderPath[i-1];}
else if(this.renderMinPath)
{edge=this.graph.FindEdgeMin(this.renderPath[i],this.renderPath[i+1]);}
else
{edge=this.graph.FindEdge(this.renderPath[i],this.renderPath[i+1]);}
var progress=(this.renderPathCounter-currentLength)/edge.GetPixelLength();this.RedrawEdgeProgress(context,edge,edge.vertex1.id==currentVertexId?progress:1.0-progress);this.renderPathCounter+=movePixelStep;context.restore();}}
if(this.renderPathLoops>=5)
{this.stopRenderTimer();}}
Application.prototype._redrawGraphInWindow=function()
{var context=this.canvas.getContext('2d');context.save();context.scale(this.canvasScale,this.canvasScale);context.translate(this.canvasPosition.x,this.canvasPosition.y);this._RedrawGraph(context,{width:this.canvas.width,height:this.canvas.height,scale:this.canvasScale},this.canvasPosition,this.style.backgroundCommonStyle,true);context.restore();return context;}
Application.prototype._OffscreenRedrawGraph=function()
{var bbox=this.graph.getGraphBBox();var canvas=document.createElement('canvas');canvas.width=bbox.size().x;canvas.height=bbox.size().y;var context=canvas.getContext('2d');context.save();context.translate(bbox.minPoint.inverse().x,bbox.minPoint.inverse().y);this._RedrawGraph(context,{width:canvas.width,height:canvas.height,scale:1.0},bbox.minPoint.inverse(),this.style.backgroundCommonStyle,false);context.restore();return canvas;}
Application.prototype._PrintRedrawGraph=function()
{var bbox=this.graph.getGraphBBox();var canvas=document.createElement('canvas');canvas.width=bbox.size().x;canvas.height=bbox.size().y;var context=canvas.getContext('2d');context.save();context.translate(bbox.minPoint.inverse().x,bbox.minPoint.inverse().y);this._RedrawGraph(context,{width:canvas.width,height:canvas.height,scale:1.0},bbox.minPoint.inverse(),this.backgroundPrintStyle,false,this.vertexPrintCommonStyle,this.vertexPrintSelectedVertexStyles,this.edgePrintCommonStyle,this.edgePrintSelectedStyles);context.restore();return canvas;}
Application.prototype._printToSVG=function()
{var bbox=this.graph.getGraphBBox();var context=new C2S(bbox.size().x,bbox.size().y);context.save();context.translate(bbox.minPoint.inverse().x,bbox.minPoint.inverse().y);this._RedrawGraph(context,{width:bbox.size().x,height:bbox.size().y,scale:1.0},bbox.minPoint.inverse(),this.style.backgroundCommonStyle,false);context.restore();return context.getSerializedSvg();}
Application.prototype.updateRenderPathLength=function()
{this.renderPathLength=0;this.renderPathCounter=0;if(this.renderPath.length>1)
{for(var i=0;i0)
{this.startRenderTimer();}
else
{this.stopRenderTimer();}}
Application.prototype.setRenderPathWithEdges=function(renderPath)
{this.renderPath=renderPath;this.renderMinPath=false;this.renderPathWithEdges=true;if(this.renderPath.length>0)
{this.startRenderTimer();}
else
{this.stopRenderTimer();}}
Application.prototype.GetBaseArcDrawer=function(context,edge)
{var arcDrawer=new BaseEdgeDrawer(context);if(edge.model.type==EdgeModels.curve)
{var curvedArcDrawer=new CurvedArcDrawer(context,edge.model);arcDrawer=new BaseEdgeDrawer(context,{drawArc:curvedArcDrawer,startArrowDirection:curvedArcDrawer,finishArrowDirection:curvedArcDrawer,textCenterObject:curvedArcDrawer,getPointOnArc:curvedArcDrawer});}
return arcDrawer;}
Application.prototype.UpdateEdgeCurrentStyle=function(edge,ForceCommonStyle,ForceSelectedStyle)
{var commonStyle=(ForceCommonStyle===undefined)?this.style.edgeCommonStyle:ForceCommonStyle;var selectedStyle=(ForceSelectedStyle===undefined)?this.style.edgeSelectedStyles:ForceSelectedStyle;var selectedGroup=this.handler.GetSelectedGroup(edge);var selected=false;if(selectedGroup>0)
{selectedGroup=(selectedGroup-1)%selectedStyle.length;selected=true;}
var currentStyle=null;if(edge.hasOwnStyleFor((selected?1:0)+selectedGroup))
currentStyle=edge.getStyleFor((selected?1:0)+selectedGroup);else
currentStyle=selected?selectedStyle[selectedGroup]:commonStyle;edge.currentStyle=currentStyle;}
Application.prototype.RedrawEdge=function(context,edge)
{var curvedArcDrawer=new CurvedArcDrawer(context,edge.model)
var arcDrawer=this.GetBaseArcDrawer(context,edge);this._RedrawEdge(edge,arcDrawer);}
Application.prototype._RedrawEdge=function(edge,arcDrawer,commonStyle,selectedStyles)
{this._RedrawEdgeWithStyle(edge,edge.currentStyle,arcDrawer,commonStyle,selectedStyles);}
Application.prototype._RedrawEdgeWithStyle=function(edge,style,arcDrawer,commonStyle,selectedStyles)
{arcDrawer.Draw(edge,style.GetStyle({},edge));}
Application.prototype.RedrawEdgeProgress=function(context,edge,progress)
{var progressDraw=new ProgressArcDrawer(context,this.GetBaseArcDrawer(context,edge),progress);var arcDrawer=new BaseEdgeDrawer(context,{drawObject:progressDraw});this._RedrawEdge(edge,arcDrawer,this.style.edgeCommonStyle,this.style.edgeSelectedStyles);}
Application.prototype.UpdateEdgesCurrentStyle=function(ForceCommonStyle,ForceSelectedStyle)
{for(i=0;i0)
{selectedGroup=(selectedGroup-1)%selectedStyle.length;selected=true;}
var currentStyle=null;if(this.graph.vertices[i].hasOwnStyleFor((selected?1:0)+selectedGroup)&&!force)
currentStyle=this.graph.vertices[i].getStyleFor((selected?1:0)+selectedGroup);else
currentStyle=selected?selectedStyle[selectedGroup]:commonStyle;this.graph.vertices[i].currentStyle=currentStyle;}}
Application.prototype.RedrawSelectionRect=function(context)
{context.lineWidth=1.0/this.canvasScale;context.strokeStyle=this.style.edgeSelectedStyles[0].strokeStyle;context.setLineDash([6,3]);context.beginPath();context.rect(this.selectionRect.left(),this.selectionRect.top(),this.selectionRect.size().x,this.selectionRect.size().y);context.closePath();context.stroke();context.setLineDash([]);}
Application.prototype.updateMessage=function()
{this.listener.updateMessage(this.handler.GetMessage());this.handler.InitControls();}
Application.prototype.CanvasOnMouseMove=function(e)
{var pos=this.getMousePos(this.canvas,e);this.handler.MouseMove(pos);if(this.handler.IsNeedRedraw())
{this.handler.RestRedraw();this.redrawGraph();}
this.updateMessage();}
Application.prototype.CanvasOnMouseDown=function(e)
{if(e.which!==1)return;var pos=this.getMousePos(this.canvas,e);this.handler.MouseDown(pos);if(this.handler.IsNeedRedraw())
{this.handler.RestRedraw();this.redrawGraph();}
this.updateMessage();}
Application.prototype.CanvasOnMouseUp=function(e)
{if(e.which!==1)return;var pos=this.getMousePos(this.canvas,e);this.handler.MouseUp(pos);if(this.handler.IsNeedRedraw())
{this.handler.RestRedraw();this.redrawGraph();}
this.updateMessage();}
Application.prototype.multCanvasScale=function(factor,zoom_to=null)
{if(zoom_to)
{var pos1=this.getMousePos(this.canvas,zoom_to);this.canvasScale*=factor;var pos2=this.getMousePos(this.canvas,zoom_to);this.canvasPosition=this.canvasPosition.add(new Point(pos2.x-pos1.x,pos2.y-pos1.y));}
else
{var oldRealWidth=this.GetRealWidth();var oldRealHeight=this.GetRealHeight();this.canvasScale*=factor;this.canvasPosition=this.canvasPosition.add(new Point((this.GetRealWidth()-oldRealWidth)/2.0,(this.GetRealHeight()-oldRealHeight)/2.0));}
this.redrawGraph();}
Application.prototype.setCanvasScale=function(factor)
{var oldRealWidth=this.GetRealWidth();var oldRealHeight=this.GetRealHeight();this.canvasScale=factor;this.canvasPosition=this.canvasPosition.add(new Point((this.GetRealWidth()-oldRealWidth)/2.0,(this.GetRealHeight()-oldRealHeight)/2.0));this.redrawGraph();}
Application.prototype.onCanvasMove=function(point)
{this.canvasPosition=this.canvasPosition.add(point.multiply(1/this.canvasScale));this.redrawGraph();}
Application.prototype.AddNewVertex=function(vertex)
{return this.graph.AddNewVertex(vertex);}
Application.prototype.AddNewEdge=function(edge,replaceIfExists)
{return this.graph.AddNewEdge(edge,replaceIfExists);}
Application.prototype.CreateNewGraph=function(x,y)
{var app=this;this.currentEnumVerticesType.GetVertexTextAsync(function(enumType)
{app.graph.AddNewVertex(new BaseVertex(x,y,enumType));app.redrawGraph();});}
Application.prototype.CreateNewGraphEx=function(x,y,vertexEnume)
{return this.graph.AddNewVertex(new BaseVertex(x,y,vertexEnume));}
Application.prototype.CreateNewArc=function(graph1,graph2,isDirect,weight,replaceIfExist,upText)
{var edge=this.AddNewEdge(new BaseEdge(graph1,graph2,isDirect,weight,upText),replaceIfExist);this.graph.FixEdgeCurve(edge);var edgeObject=this.graph.edges[edge];if(edgeObject.useWeight)
this.UpdateEdgePresets(edgeObject.weight);return edge;}
Application.prototype.DeleteEdge=function(edgeObject)
{var vertex1=edgeObject.vertex1;var vertex2=edgeObject.vertex2;var hasPair=this.graph.hasPair(edgeObject);this.graph.DeleteEdge(edgeObject);if(hasPair)
{var pairEdges=this.FindAllEdges(vertex2.id,vertex1.id);if(pairEdges.length==1&&pairEdges[0].model.default)
pairEdges[0].model.type=EdgeModels.line;}}
Application.prototype.DeleteVertex=function(graphObject)
{this.graph.DeleteVertex(graphObject);}
Application.prototype.DeleteObject=function(object)
{if(object instanceof BaseVertex)
{this.DeleteVertex(object);}
else if(object instanceof BaseEdge)
{this.DeleteEdge(object);}}
Application.prototype.IsCorrectObject=function(object)
{return(object instanceof BaseVertex)||(object instanceof BaseEdge);}
Application.prototype.FindVertex=function(id)
{return this.graph.FindVertex(id);}
Application.prototype.FindEdge=function(id1,id2)
{return this.graph.FindEdge(id1,id2);}
Application.prototype.FindEdgeAny=function(id1,id2)
{return this.graph.FindEdgeAny(id1,id2);}
Application.prototype.FindAllEdges=function(id1,id2)
{return this.graph.FindAllEdges(id1,id2);}
Application.prototype.SetHandler=function(newHandler)
{if(this.handler)
{this.handler.RestoreAll();}
this.handler=newHandler;this.ToDefaultStateAndRedraw();}
Application.prototype.ToDefaultStateAndRedraw=function()
{this.setRenderPath([]);this.updateMessage();this.redrawGraph();}
Application.prototype.getParameterByName=function(name)
{name=name.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var regex=new RegExp("[\\?&]"+name+"=([^]*)"),results=regex.exec(location.search);return results===null?"":decodeURIComponent(results[1].replace(/\+/g," "));}
Application.prototype.onPostLoadEvent=function()
{this.SetEnumVerticesType(document.cookie.replace(/(?:(?:^|.*;\s*)enumType\s*\=\s*([^;]*).*$)|^.*$/,"$1"));var wasLoad=false;let startAutoSave=true;var matrix=document.getElementById("inputMatrix").innerHTML;var separator=document.getElementById("separator").innerHTML=="space"?" ":",";console.log(matrix);console.log("separator: \""+separator+"\"");matrix=(matrix.length<=0)?this.getParameterByName("matrix"):matrix;if(matrix.length>0)
{if(!this.SetAdjacencyMatrixSmart(matrix,separator))
{userAction("AdjacencyMatrix.Failed");this.listener.ShowAdjacencyMatrixErrorDialog(matrix);}
else
{userAction("AdjacencyMatrix.Success");}
this.updateMessage();this.redrawGraph();wasLoad=true;}
var matrix=document.getElementById("inputIncidenceMatrix").innerHTML;matrix=(matrix.length<=0)?this.getParameterByName("incidenceMatrix"):matrix;if(matrix.length>0)
{if(!this.SetIncidenceMatrixSmart(matrix))
{userAction("IncidenceMatrix.Failed");this.listener.ShowIncidenceMatrixErrorDialog(matrix);}
else
{userAction("IncidenceMatrix.Success");}
this.updateMessage();this.redrawGraph();wasLoad=true;}
var pairs=document.getElementById("inputPair").innerHTML;if(pairs.length>0)
{pairs=pairs.replaceAll('>','>');pairs=pairs.replaceAll('<','<');if(!this.SetPairSmart(pairs))
{userAction("Pair.Failed");this.listener.ShowPairErrorDialog(pairs);}
else
{userAction("Pair.Success");}
this.updateMessage();this.redrawGraph();wasLoad=true;}
if(!wasLoad)
{var graphName=this.getParameterByName("graph");var is_user_graph=graphName.length>0;if(!is_user_graph)
{graphName=document.cookie.replace(/(?:(?:^|.*;\s*)graphName\s*\=\s*([^;]*).*$)|^.*$/,"$1");}
if(!is_user_graph&&this.hasAutoSave())
{userAction("LoadGraphFromAutoSave");this.loadAutoSave();}
else if(graphName.length>0)
{if(this.getAutoSaveRefGraphCookie()==graphName)
{this.showSelectGraphDialog(graphName);console.log("Show select graph dialog");startAutoSave=false;}
else
{userAction("LoadGraphFromDisk");this.LoadGraphFromDisk(graphName);}}}
if(this.undoStack.IsUndoStackEmpty())
document.getElementById('GraphUndo').style.display='none';this.updateMessage();this.redrawGraph();if(startAutoSave)
{this.startAutoSaveTimer();}}
Application.prototype.onLoad=function()
{this.canvas=this.document.getElementById('canvas');this.SetDefaultHandler()
this.updateMessage();this.redrawGraph();this.LoadLastUsedGraphsFromCookie();this.UpdateLastUsedGraphsMenu();}
Application.prototype.NeedRedraw=function()
{this.updateMessage();this.redrawGraph();}
Application.prototype.SetStatus=function(name,value)
{this.status[name]=value;}
Application.prototype.GetStatus=function()
{return this.status[name];}
Application.prototype.GetAdjacencyMatrix=function()
{return this.graph.GetAdjacencyMatrixStr();}
Application.prototype.TestAdjacencyMatrix=function(matrix,rowsObj,colsObj,separator)
{if(separator===undefined)
{separator=",";}
return this.graph.TestAdjacencyMatrix(matrix,rowsObj,colsObj,separator);}
Application.prototype.SetAdjacencyMatrix=function(matrix,separator)
{if(separator===undefined)
{separator=",";}
var res=true;var r={};var c={};if(!this.TestAdjacencyMatrix(matrix,r,c,separator))
{$.get("/"+SiteDir+"backend/addFailedMatrix.php?text=adjacency&matrix="+encodeURIComponent(matrix),function(data){;});res=false;}
this.graph.SetAdjacencyMatrix(matrix,new Point(this.GetRealWidth(),this.GetRealHeight()),this.currentEnumVerticesType,separator);this.AutoAdjustViewport();this.redrawGraph();return res;}
Application.prototype.SetPair=function(pair)
{var res=true;var r={};var c={};if(!this.TestPair(pair))
{$.get("/"+SiteDir+"backend/addFailedMatrix.php?text=pair&matrix="+encodeURIComponent(pair),function(data){;});res=false;}
this.graph.SetPair(pair,new Point(this.GetRealWidth(),this.GetRealHeight()),this.currentEnumVerticesType);this.AutoAdjustViewport();this.redrawGraph();return res;}
Application.prototype.GetIncidenceMatrix=function()
{return this.graph.GetIncidenceMatrix();}
Application.prototype.TestIncidenceMatrix=function(matrix,rowsObj,colsObj)
{return this.graph.TestIncidenceMatrix(matrix,rowsObj,colsObj);}
Application.prototype.TestPair=function(pair)
{return this.graph.TestPair(pair);}
Application.prototype.SetIncidenceMatrix=function(matrix)
{var res=true;var r={};var c={};if(!this.TestIncidenceMatrix(matrix,r,c))
{$.get("/"+SiteDir+"backend/addFailedMatrix.php?text=incidence&matrix="+encodeURIComponent(matrix),function(data){;});res=false;}
this.graph.SetIncidenceMatrix(matrix,new Point(this.GetRealWidth(),this.GetRealHeight()),this.currentEnumVerticesType);this.AutoAdjustViewport();this.redrawGraph();return res;}
Application.prototype.Test=function()
{this.graph.VerticesReposition(new Point(this.GetRealWidth(),this.GetRealHeight()),this.graph.vertices);this.redrawGraph();}
Application.prototype.SetAdjacencyMatrixSmart=function(matrix,separator)
{if(separator===undefined)
{separator=",";}
var res=false;if(this.TestAdjacencyMatrix(matrix,{},{},separator))
{res=this.SetAdjacencyMatrix(matrix,separator);}
else if(this.TestIncidenceMatrix(matrix,{},{}))
{res=this.SetIncidenceMatrix(matrix);}
else
{res=this.SetAdjacencyMatrix(matrix);}
return res;}
Application.prototype.SetIncidenceMatrixSmart=function(matrix)
{var res=false;if(this.TestIncidenceMatrix(matrix,{},{}))
{res=this.SetIncidenceMatrix(matrix);}
else if(this.TestAdjacencyMatrix(matrix,{},{}))
{res=this.SetAdjacencyMatrix(matrix);}
else
{res=this.SetIncidenceMatrix(matrix);}
return res;}
Application.prototype.SetPairSmart=function(pair)
{var res=false;if(this.TestPair(pair))
{res=this.SetPair(pair);}
else
{res=false;}
return res;}
Application.prototype.SaveGraphOnDisk=function()
{var graphAsString=this.graph.SaveToXML(this.SaveUserSettings());var app=this;if(this.savedGraphName.length<=0)
{this.savedGraphName=this.GetNewGraphName();}
DiskSaveLoad.SaveGraphOnDisk(this.savedGraphName,graphAsString,function(msg)
{document.cookie="graphName="+app.savedGraphName;app.removeAutosave();app.lastGraphName=app.savedGraphName;app.PushLastUsedGraph(app.savedGraphName);});}
Application.prototype.SaveGraphImageOnDisk=function(showDialogCallback)
{var imageName=this.GetNewName();this.stopRenderTimer();this.redrawGraph();var bbox=this.graph.getGraphBBox();var rectParams="";if(this.IsGraphFitOnViewport())
{var canvasWidth=this.GetRealWidth();var canvasHeight=this.GetRealHeight();var canvasPositionInverse=this.canvasPosition.inverse();var pos=bbox.minPoint.subtract(canvasPositionInverse);rectParams="&x="+Math.round(pos.x*this.canvasScale)+"&y="+Math.round(pos.y*this.canvasScale)
+"&width="+Math.round(bbox.size().x*this.canvasScale)+"&height="+Math.round(bbox.size().y*this.canvasScale);}
var imageBase64Data=this.canvas.toDataURL();DiskSaveLoad.SaveGraphImageOnDisk(imageName,rectParams,imageBase64Data,showDialogCallback);return imageName;}
Application.prototype.SaveFullGraphImageOnDisk=function(showDialogCallback,forPrint)
{var imageName=this.GetNewName();this.stopRenderTimer();var canvas=forPrint?this._PrintRedrawGraph():this._OffscreenRedrawGraph();var bbox=this.graph.getGraphBBox();var rectParams="";rectParams="&x=0"+"&y=0"+"&width="+bbox.size().x+"&height="+bbox.size().y;var imageBase64Data=canvas.toDataURL();DiskSaveLoad.SaveGraphImageOnDisk(imageName,rectParams,imageBase64Data,showDialogCallback);return imageName;}
Application.prototype.SaveSVGGraphOnDisk=function(showDialogCallback)
{var imageName=this.GetNewName();this.stopRenderTimer();var svgText=this._printToSVG();DiskSaveLoad.SaveSVGGraphOnDisk(imageName,svgText,showDialogCallback);return imageName;}
Application.prototype.LoadGraphFromString=function(str)
{var graph=new Graph();var userSettings={};graph.LoadFromXML(str,userSettings);if(userSettings.hasOwnProperty("data")&&userSettings["data"].length>0)
this.LoadUserSettings(userSettings["data"]);this.SetDefaultTransformations();this.graph=graph;if(this.graph.isNeedReposition())
{this.graph.VerticesReposition(new Point(this.GetRealWidth(),this.GetRealHeight()),this.graph.vertices);}
this.AutoAdjustViewport();if(this.handler!=null)
{this.handler.GraphWasUpdated();this.handler.RestRedraw();}
this.updateMessage();this.redrawGraph();}
Application.prototype.LoadNewGraphFromString=function(str)
{this.LoadGraphFromString(str);this.lastGraphName="";}
Application.prototype.LoadGraphFromDisk=function(graphName)
{var app=this;DiskSaveLoad.LoadGraphFromDisk(graphName,function(msg)
{app.LoadGraphFromString(msg);app.removeAutosave();app.lastGraphName=graphName;});}
Application.prototype.GetNewGraphName=function()
{var name=this.GetNewName();if(this.style.isVertexCommonStyleCustom||this.style.isVertexSelectedVertexStylesCustom||this.style.isBackgroundCommonStyleCustom||this.style.isEdgeCommonStyleCustom||this.style.isEdgeSelectedStylesCustom)
{name=name+this.styliedGraphNamePostfix;}
return name;}
Application.prototype.GetNewName=function()
{var name="";var possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";for(var i=0;i0)
{if(bboxSize.x>this.GetRealWidth()||bboxSize.y>this.GetRealHeight())
{this.canvasScale=Math.min(this.GetRealWidth()/bboxSize.x,this.GetRealHeight()/bboxSize.y);}
if(graphBBox.minPoint.x<0.0||graphBBox.minPoint.y<0.0||graphBBox.maxPoint.x>this.GetRealWidth()||graphBBox.maxPoint.y>this.GetRealHeight())
{this.canvasPosition=graphBBox.minPoint.inverse();}}}
Application.prototype.OnAutoAdjustViewport=function()
{this.SetDefaultTransformations();this.AutoAdjustViewport();this.redrawGraph();}
Application.prototype.getAlgorithmNames=function()
{var res=[];for(var i=0;i=Math.floor(point.x)&&Math.floor(canvasPositionInverse.y+canvasHeight)>=Math.floor(point.y));}
Application.prototype.IsGraphFitOnViewport=function()
{graphBBox=this.graph.getGraphBBox();var canvasWidth=this.GetRealWidth();var canvasHeight=this.GetRealHeight();var canvasPositionInverse=this.canvasPosition.inverse();return(Math.floor(canvasPositionInverse.x)<=Math.floor(graphBBox.minPoint.x)&&Math.floor(canvasPositionInverse.y)<=Math.floor(graphBBox.minPoint.y)&&Math.floor(canvasPositionInverse.x+canvasWidth)>=Math.floor(graphBBox.maxPoint.x)&&Math.floor(canvasPositionInverse.y+canvasHeight)>=Math.floor(graphBBox.maxPoint.y));}
Application.prototype.PushToStack=function(actionName)
{this.undoStack.PushToStack(actionName,this.graph.SaveToXML(this.SaveUserSettings()));document.getElementById('GraphUndo').style.display='inline-block';}
Application.prototype.Undo=function()
{let data=this.undoStack.Undo();if(data==null)
return;this.graph=new Graph();var userSettings={};this.graph.LoadFromXML(data,userSettings);if(userSettings.hasOwnProperty("data")&&userSettings["data"].length>0)
this.LoadUserSettings(userSettings["data"]);if(this.handler!=null)
{this.handler.GraphWasUpdated();this.handler.RestRedraw();}
this.redrawGraph();if(this.undoStack.IsUndoStackEmpty())
document.getElementById('GraphUndo').style.display='none';}
Application.prototype.SaveUserSettings=function()
{return"{"+this.style.Save()+"}";}
Application.prototype.LoadUserSettings=function(json)
{this.style.Load(json);}
Application.prototype.SetVertexStyle=function(index,style)
{if(index==0)
{this.style.vertexCommonStyle=style;this.style.isVertexCommonStyleCustom=true;}
else
{this.style.vertexSelectedVertexStyles[index-1]=style;this.style.isVertexSelectedVertexStylesCustom=true;}}
Application.prototype.ResetVertexStyle=function(index)
{if(index==0)
{this.style.vertexCommonStyle=new CommonVertexStyle();this.style.isVertexCommonStyleCustom=false;}
else
{this.style.vertexSelectedVertexStyles=FullArrayCopy(DefaultSelectedGraphStyles);this.style.isVertexSelectedVertexStylesCustom=false;}}
Application.prototype.SetEdgeStyle=function(index,style)
{if(index==0)
{this.style.edgeCommonStyle=style;this.style.isEdgeCommonStyleCustom=true;}
else
{this.style.edgeSelectedStyles[index-1]=style;this.style.isEdgeSelectedStylesCustom=true;}}
Application.prototype.ResetEdgeStyle=function(index)
{if(index==0)
{this.style.edgeCommonStyle=new CommonEdgeStyle();this.style.isEdgeCommonStyleCustom=false;}
else
{this.style.edgeSelectedStyles=FullArrayCopy(DefaultSelectedEdgeStyles);this.style.isEdgeSelectedStylesCustom=false;}}
Application.prototype.SetBackgroundStyle=function(style)
{this.style.backgroundCommonStyle=style;this.style.isBackgroundCommonStyleCustom=true;}
Application.prototype.ResetBackgroundStyle=function()
{this.style.backgroundCommonStyle=new CommonBackgroundStyle();this.style.isBackgroundCommonStyleCustom=false;}
Application.prototype.GetAvailableCurveValue=function(neighborEdges,originalEdge)
{return this.graph.GetAvailableCurveValue(neighborEdges,originalEdge);}
Application.prototype.GraphTypeChanged=function()
{this.listener.OnGraphTypeChanged(this.graph.isMulti());}
Application.prototype.UpdateEdgePresets=function(weight)
{var oldPresets=this.edgePresets;this.edgePresets=[1];oldPresets.unshift(weight);for(var i=0;i=this.maxEdgePresets)
break;}}
Application.prototype.GetEdgePresets=function()
{return this.edgePresets;}
Application.prototype.SetSelectionRect=function(rect)
{this.selectionRect=rect;}
Application.prototype.GetSelectionRect=function(rect)
{return this.selectionRect;}
Application.prototype.GetStyle=function(type,styleName,object,index)
{var correctIndex=index;if(correctIndex==undefined)
correctIndex=0;if(type=="vertex")
{if(styleName=="common")
{return object!==undefined?object.getStyleFor(0):this.style.vertexCommonStyle;}
else if(styleName=="selected")
{return object!==undefined&&object.hasOwnStyleFor(correctIndex+1)?object.getStyleFor(correctIndex+1):this.style.vertexSelectedVertexStyles[correctIndex];}
else if(styleName=="printed")
{return this.vertexPrintCommonStyle;}
else if(styleName=="printedSelected")
{return this.vertexPrintSelectedVertexStyles[correctIndex];}
return null;}
else if(type=="edge")
{if(styleName=="common")
{return object!==undefined?object.getStyleFor(0):this.style.edgeCommonStyle;}
else if(styleName=="selected")
{return object!==undefined&&object.hasOwnStyleFor(correctIndex+1)?object.getStyleFor(correctIndex+1):this.style.edgeSelectedStyles[correctIndex];}
else if(styleName=="printed")
{return this.edgePrintCommonStyle;}
else if(styleName=="printedSelected")
{return this.edgePrintSelectedStyles[correctIndex];}
return null;}
return null;}
Application.prototype._RedrawGraph=function(context,canvasParams,backgroundPosition,backgroundStyle,bDrawSelectedRect,forceVertexCommon,forceVertexSelected,forceEdgeCommon,forceEdgeSelected)
{var backgroundDrawer=new BaseBackgroundDrawer(context);backgroundDrawer.Draw(backgroundStyle,Math.max(canvasParams.width,this.GetRealWidth()),Math.max(canvasParams.height,this.GetRealHeight()),backgroundPosition,canvasParams.scale);this.UpdateEdgesCurrentStyle(forceEdgeCommon,forceEdgeSelected);this.UpdateNodesCurrentStyle(forceVertexCommon,forceVertexSelected);this.RedrawEdges(context);this.RedrawNodes(context);if(bDrawSelectedRect&&this.selectionRect!=null)
this.RedrawSelectionRect(context);}
Application.prototype.GetSelectedVertices=function()
{var res=[];for(i=0;i0)
{res.push(this.graph.vertices[i]);}}
return res;}
Application.prototype.GetSelectedEdges=function()
{var res=[];for(i=0;i0)
{res.push(this.graph.edges[i]);}}
return res;}
Application.prototype.SetDefaultVertexSize=function(diameter)
{var oldDefaultDiameter=this.GetDefaultVertexSize();this.style.defaultVertexSize=diameter;for(i=0;i0&&str.length<=this.graphNameLength+this.styliedGraphNamePostfix.length;}
Application.prototype.saveAutoSave=function(graphXML,callback)
{compress_text_into_zip_base64(graphXML,function(base64Str){if(this.lastSavedAutoSave==base64Str)
{if(callback)
{callback();}
return;}
if(base64Str.length0);}
Application.prototype.loadAutoSave=function(callback)
{let app=this;this.getAutoSaveGraph(function(xmlGraph){app.LoadGraphFromString(xmlGraph);app.lastGraphName=app.getAutoSaveRefGraphCookie();if(callback)
{callback();}});}
Application.prototype.getAutoSaveGraph=function(callback)
{let autoSaveData=this.getAutoSaveCookie();if(autoSaveData.length<0)
{console.log("Auto save to cookie is empty");return;}
let app=this;if(!this.isAutoSaveGraphName(autoSaveData))
{this.loadGraphFromZippedBase64(autoSaveData,function(xmlGraph){console.log("Load graph from cookie");if(callback)
{callback(xmlGraph);}});return;}
DiskSaveLoad.LoadAutoSaveGraphFromDisk(autoSaveData,function(xmlGraph)
{if(callback)
{callback(xmlGraph);}});}
Application.prototype.removeAutosave=function(callback)
{let autoSaveData=this.getAutoSaveCookie();this.lastSavedAutoSave="";let app=this;if(autoSaveData.length<0)
{console.log("Auto save to cookie is empty");return;}
if(!this.isAutoSaveGraphName(autoSaveData))
{app.removeAutoSaveCookie();console.log("Remove auto save from cookie");if(callback)
{callback();}
return;}
DiskSaveLoad.RemoveAutoSaveGraphFromDisk(autoSaveData,function(msg)
{app.removeAutoSaveCookie();console.log("Remove auto save file");if(callback)
{callback();}});}
Application.prototype.setAutoSaveCookie=function(value)
{var now=new Date();var time=now.getTime();var expireTime=time+1000*3600*24*7;now.setTime(expireTime);document.cookie='auto_save='+value+';expires='+now.toUTCString()+';path=/';document.cookie='auto_save_ref_graph='+this.lastGraphName+';expires='+now.toUTCString()+';path=/';}
Application.prototype.removeAutoSaveCookie=function(value)
{document.cookie="auto_save=;path=/";document.cookie="auto_save_ref_graph=;path=/";}
Application.prototype.getAutoSaveCookie=function(value)
{return document.cookie.replace(/(?:(?:^|.*;\s*)auto_save\s*\=\s*([^;]*).*$)|^.*$/,"$1");}
Application.prototype.getAutoSaveRefGraphCookie=function(value)
{return document.cookie.replace(/(?:(?:^|.*;\s*)auto_save_ref_graph\s*\=\s*([^;]*).*$)|^.*$/,"$1");}
Application.prototype.CreateNewGraphObject=function()
{this.graph=new Graph();this.savedGraphName="";this.lastGraphName="";}
Application.prototype.showSelectGraphDialog=function(graphName)
{let app=this;DiskSaveLoad.LoadGraphFromDisk(graphName,function(graphOriginXML)
{app.getAutoSaveGraph(function(xmlGraph){let remove_id_from_xml=function(graphXML)
{graphXML=graphXML.replace(/uidEdge=\"([0-9]+)\"/i,"")
graphXML=graphXML.replaceAll(/id=\"([0-9]+)\"/g,"")
return graphXML;};if(remove_id_from_xml(xmlGraph)==remove_id_from_xml(graphOriginXML))
{app.onSelectOgirinalGraph(graphName);return;}
var autosaveGraph=new Graph();var userSettings1={};autosaveGraph.LoadFromXML(xmlGraph,userSettings1);let styleAutoSave=new GraphFullStyle(null);if(userSettings1.hasOwnProperty("data")&&userSettings1["data"].length>0)
styleAutoSave.Load(userSettings1["data"]);var originalGraph=new Graph();var userSettings2={};originalGraph.LoadFromXML(graphOriginXML,userSettings2);let styleOriginal=new GraphFullStyle(null);if(userSettings2.hasOwnProperty("data")&&userSettings2["data"].length>0)
styleOriginal.Load(userSettings2["data"]);(new SelectGraphDialog(app,originalGraph,styleOriginal,autosaveGraph,styleAutoSave,function(){app.onSelectOgirinalGraph(graphName);},function(){app.onSelectAutosaveGraph();})).show();});});}
Application.prototype.startAutoSaveTimer=function()
{setInterval(function()
{var graphXML=this.graph.SaveToXML(this.SaveUserSettings());this.saveAutoSave(graphXML);}.bind(this),this.autosaveTimeInterval);}
Application.prototype.onSelectOgirinalGraph=function(graphName)
{this.LoadGraphFromDisk(graphName);this.startAutoSaveTimer();userAction("LoadGraphFromDisk_userSelect");console.log("User selected original graph");}
Application.prototype.onSelectAutosaveGraph=function()
{this.loadAutoSave();this.startAutoSaveTimer();userAction("LoadGraphFromAutoSave_userSelect");console.log("User selected auto-save graph");}
Application.prototype.UpdateLastUsedGraphsMenu=function()
{let isEmpty=this.lastUsedGraphs.length==0;document.getElementById('LastUsedGraphsMenu').style.display=isEmpty?'none':'block';let graphsList=document.getElementById('LastUsedGraphsList');graphsList.innerHTML='';if(isEmpty)
{return;}
let FormatGraphName=function(graph)
{let MAX_GRAPH_NAME_LENGTH=20;let graphName=graph.graph;if(graphName.length>MAX_GRAPH_NAME_LENGTH)
{graphName=graphName.substring(0,MAX_GRAPH_NAME_LENGTH/2)+"..."+
graphName.substring(graphName.length-MAX_GRAPH_NAME_LENGTH/2);}
return graphName+" "+""+
graph.date.toLocaleDateString(g_language+"-"+g_language);};for(let i=0;i"+""+
FormatGraphName(graph)+""+"";}}
Application.prototype.PushLastUsedGraph=function(graphName)
{let graph={graph:graphName,date:new Date()};let index=this.lastUsedGraphs.findIndex(function(item){return item.graph==graphName;});if(index>=0)
{this.UpdateLastUsedGraphsMenu();return;}
this.lastUsedGraphs.unshift(graph);if(this.lastUsedGraphs.length>this.maxLastUsedGraphCount)
{this.lastUsedGraphs.pop();}
this.SaveLastUsedGraphsToCookie();this.UpdateLastUsedGraphsMenu();}
Application.prototype.SaveLastUsedGraphsToCookie=function()
{let graphs=JSON.stringify(this.lastUsedGraphs);var now=new Date();var time=now.getTime();var expireTime=time+1000*3600*24*7;now.setTime(expireTime);document.cookie="lastUsedGraphs="+graphs+';expires='+now.toUTCString()+";path=/";}
Application.prototype.LoadLastUsedGraphsFromCookie=function()
{let graphs=document.cookie.replace(/(?:(?:^|.*;\s*)lastUsedGraphs\s*\=\s*([^;]*).*$)|^.*$/,"$1");if(graphs.length>0)
{this.lastUsedGraphs=JSON.parse(graphs);for(let i=0;i0)
{self.application.multCanvasScale(1.3,e);}
else
{self.application.multCanvasScale(1.0/1.3,e);}}}
Editor.prototype.initKeyActions=function(){let self=this;function getCharCode(event){if(event.which==null){return event.keyCode;}
if(event.which!=0&&event.charCode!=0){return event.which;}
return null;}
function getChar(event){return String.fromCharCode(getCharCode(event));}
function selectHandler(buttonName,handler)
{userAction(buttonName+"_shortcut");self.restButtons(buttonName);self.application.SetHandler(handler);}
document.onkeypress=function(e)
{if(event.defaultPrevented||($('#addVertex').hasClass('ui-dialog-content')&&$('#addVertex').dialog('isOpen'))||($('#adjacencyMatrix').hasClass('ui-dialog-content')&&$('#adjacencyMatrix').dialog('isOpen'))||($('#addEdge').hasClass('ui-dialog-content')&&$('#addEdge').dialog('isOpen'))||($('#incidenceMatrix').hasClass('ui-dialog-content')&&$('#incidenceMatrix').dialog('isOpen'))||($('#saveDialog').hasClass('ui-dialog-content')&&$('#saveDialog').dialog('isOpen'))||($('#saveImageDialog').hasClass('ui-dialog-content')&&$('#saveImageDialog').dialog('isOpen'))||($('#GroupRenameDialog').hasClass('ui-dialog-content')&&$('#GroupRenameDialog').dialog('isOpen'))||$('#developerTools').css("display")!="none"||($('#NeedAlgorithm').hasClass('ui-dialog-content')&&$('#NeedAlgorithm').dialog('isOpen'))||$('#CanvasSearchText:focus').is(":focus")||$('#Vertex1:focus').is(":focus")||$('#Vertex2:focus').is(":focus"))
{console.log("prevent");return;}
var key=getChar(event);var code=getCharCode(event);console.log(key+" code="+code);var evtobj=window.event?event:e;var isCtrl=evtobj?evtobj.ctrlKey:false;var moveValue=10;if(code==61||code==43)
{self.application.multCanvasScale(1.5);}
else if(code==45)
{self.application.multCanvasScale(1/1.5);}
else if(key=='w'||key=='ц')
{self.application.onCanvasMove(new Point(0,moveValue));}
else if(key=='s'||key=='ы')
{self.application.onCanvasMove(new Point(0,-moveValue));}
else if(key=='a'||key=='ф')
{self.application.onCanvasMove(new Point(moveValue,0));}
else if(key=='d'||key=='в')
{self.application.onCanvasMove(new Point(-moveValue,0));}
else if(key=='v'||key=='м')
{selectHandler('AddGraph',new AddGraphHandler(self.application));}
else if(key=='e'||key=='у')
{selectHandler('ConnectGraphs',new ConnectionGraphHandler(self.application));}
else if(key=='r'||key=='к')
{selectHandler('DeleteObject',new DeleteGraphHandler(self.application));}
else if(key=='m'||key=='ь')
{selectHandler('Default',new DefaultHandler(self.application));}
else if(code==26&&isCtrl)
{userAction("Key_GraphUndo");self.application.Undo();}}
$(document).keydown(function(event){if(event.which=="17"||event.which=="91")
g_ctrlPressed=true;});$(document).keyup(function(){g_ctrlPressed=false;});}
Editor.prototype.initButtonActions=function()
{let self=this;document.getElementById('ShowAdjacencyMatrix').onclick=function()
{userAction(this.id);var showAdjacencyMatrix=new ShowAdjacencyMatrix(self.application);showAdjacencyMatrix.show();}
document.getElementById('ShowIncidenceMatrix').onclick=function()
{userAction(this.id);var showIncidenceMatrix=new ShowIncidenceMatrix(self.application);showIncidenceMatrix.show();}
document.getElementById('ShowDistanceMatrix').onclick=function()
{userAction(this.id);var showDistanceMatrix=new ShowDistanceMatrix(self.application);showDistanceMatrix.show();}
document.getElementById('GroupRename').onclick=function()
{userAction(this.id);var groupRenameVertices=new GroupRenameVertices(self.application);groupRenameVertices.show();}
document.getElementById('groupRenameButton').onclick=function()
{userAction(this.id);var groupRenameVertices=new GroupRenameVertices(self.application);groupRenameVertices.show();}
document.getElementById('Default').onclick=function()
{userAction(this.id);self.restButtons('Default');self.application.SetHandler(new DefaultHandler(self.application));document.getElementById('Default').className="btn btn-primary btn-sm";}
document.getElementById('AddGraph').onclick=function()
{userAction(this.id);self.restButtons('AddGraph');self.application.SetHandler(document.getElementById('AddGraph').className!=""?new AddGraphHandler(self.application):new DefaultHandler(self.application));}
document.getElementById('ConnectGraphs').onclick=function()
{userAction(this.id);self.restButtons('ConnectGraphs');self.application.SetHandler(document.getElementById('ConnectGraphs').className!=""?new ConnectionGraphHandler(self.application):new DefaultHandler(self.application));}
document.getElementById('DeleteObject').onclick=function()
{userAction(this.id);self.restButtons('DeleteObject');self.application.SetHandler(document.getElementById('DeleteObject').className!=""?new DeleteGraphHandler(self.application):new DefaultHandler(self.application));}
document.getElementById('DeleteAll').onclick=function()
{userAction(this.id);var removeAll=new DeleteAllHandler(self.application);removeAll.clear();self.application.ToDefaultStateAndRedraw();}
document.getElementById('SaveGraph').onclick=function()
{userAction(this.id);var savedDialogGraphHandler=new SavedDialogGraphHandler(self.application);savedDialogGraphHandler.show();}
document.getElementById('NewGraph').onclick=function()
{userAction(this.id);var removeAll=new DeleteAllHandler(self.application);removeAll.clear();self.application.ToDefaultStateAndRedraw();self.application.SetDefaultTransformations();}
document.getElementById('SaveGraphImage').onclick=function()
{userAction(this.id);var savedDialogGraphImageHandler=new SavedDialogGraphImageHandler(self.application);savedDialogGraphImageHandler.showWorkspace();}
document.getElementById('SaveFullGraphImage').onclick=function()
{userAction(this.id);var savedDialogGraphImageHandler=new SavedDialogGraphImageHandler(self.application);savedDialogGraphImageHandler.showFullgraph();}
document.getElementById('SavePrintGraphImage').onclick=function()
{userAction(this.id);var savedDialogGraphImageHandler=new SavedDialogGraphImageHandler(self.application);savedDialogGraphImageHandler.showPrint();}
document.getElementById('SaveSvgGraphImage').onclick=function()
{userAction(this.id);var savedDialogGraphImageHandler=new SavedDialogGraphImageHandler(self.application);savedDialogGraphImageHandler.showSvg();}
document.getElementById('Zoom100').onclick=function()
{userAction(this.id);self.application.setCanvasScale(1.0);}
document.getElementById('Zoom50').onclick=function()
{userAction(this.id);self.application.setCanvasScale(50/100);}
document.getElementById('Zoom25').onclick=function()
{userAction(this.id);self.application.setCanvasScale(25/100);}
document.getElementById('ZoomFit').onclick=function()
{userAction(this.id);self.application.OnAutoAdjustViewport();}
document.getElementById('ZoomIn').onclick=function()
{userAction(this.id);self.application.multCanvasScale(1.5);}
document.getElementById('ZoomOut').onclick=function()
{userAction(this.id);self.application.multCanvasScale(1.0/1.5);}
document.getElementById('MoveWorspace').onclick=function()
{userAction(this.id);self.restButtons('Default');self.application.SetHandler(new DefaultHandler(self.application));document.getElementById('Default').className="btn btn-primary btn-sm";}
document.getElementById('SetupVertexStyle').onclick=function()
{userAction(this.id);var setupVertexStyle=new SetupVertexStyle(self.application);setupVertexStyle.show(0);}
document.getElementById('SetupVertexStyleSelected').onclick=function()
{userAction(this.id);var setupVertexStyle=new SetupVertexStyle(self.application);setupVertexStyle.show(1);}
document.getElementById('SetupEdgeStyle').onclick=function()
{userAction(this.id);var setupEdgeStyle=new SetupEdgeStyle(self.application);setupEdgeStyle.show(0);}
document.getElementById('SetupEdgeStyleSelected').onclick=function()
{userAction(this.id);var setupEdgeStyle=new SetupEdgeStyle(self.application);setupEdgeStyle.show(1);}
document.getElementById('SetupBackgroundStyle').onclick=function()
{userAction(this.id);var setupBackgroundStyle=new SetupBackgroundStyle(self.application);setupBackgroundStyle.show();}
document.getElementById('GraphUndo').onclick=function()
{userAction(this.id);self.application.Undo();}
document.getElementById('runUserScript').onclick=function()
{}
document.getElementById('submitUserScript').onclick=function()
{var script=document.getElementById('userScript');var data="message="+script.value+"&";$.ajax({type:"POST",url:"/feedback",data:data});$("#sentAlgorithm").dialog({resizable:false,height:"auto",width:400,modal:true,dialogClass:'EdgeDialog'});}
document.getElementById('devToolsZoom').onclick=function()
{var devTools=document.getElementById('developerTools');if(devTools.hasOwnProperty("isMin")&&!devTools["isMin"])
{devTools["isMin"]=true;devTools.style.width="30%";}
else
{devTools["isMin"]=false;devTools.style.width="100%";}}
document.getElementById('ExportGraph').onclick=function()
{userAction(this.id);var graphAsString=self.application.graph.SaveToXML("");var savedGraphName=self.application.GetNewGraphName();var element=document.createElement('a');element.setAttribute('href','data:text/plain;charset=utf-8,'+encodeURIComponent(graphAsString));element.setAttribute('download',"graph_"+savedGraphName+".graphml");element.style.display='none';document.body.appendChild(element);element.click();document.body.removeChild(element);}
document.getElementById('ImportGraph').onclick=function()
{userAction(this.id);if(ImportGraphFiles){ImportGraphFiles.click();}}
document.getElementById('openAlgorithmList').onclick=function()
{return;}
document.getElementById('Fullscreen').onclick=function()
{var idList=["h1Header","h1Text","navigation","footerContent","bottom_adv"];self.fullscreen=!self.fullscreen
userAction(self.fullscreen?"fullscreen_on":"fullscreen_off");for(var i=0;i{let datalist=document.getElementById('vertexListCanvas');const options=datalist.options;for(let i=options.length-1;i>=0;i--){options[i].remove();}
self.application.graph.vertices.forEach(vertex=>{const option=document.createElement('option');option.value=vertex.mainText;datalist.appendChild(option);});});document.getElementById('CanvasSearchText').addEventListener('input',function(event){let vertex=self.application.GetVertexByName(event.target.value);if(vertex!=null)
{let size=vertex.getBBox(vertex.getStyleFor(0));let point1=vertex.position.add(new Point(-size.x/2,-size.y/2));let point2=vertex.position.add(new Point(size.x/2,size.y/2));if(!self.application.IsPointFitOnViewport(point1)||!self.application.IsPointFitOnViewport(point2))
{self.application.canvasPosition=vertex.position.inverse().add(new Point(self.application.GetRealWidth()/2,self.application.GetRealHeight()/2));self.application.redrawGraph();}
self.HighlightVertex(vertex);}
else
{self.StopArrowForVertexTimer();}});}
Editor.prototype.StopArrowForVertexTimer=function()
{if(this.arrowForVertexTimer!=null)
{clearInterval(this.arrowForVertexTimer);this.arrowForVertexTimer=null;}
this.arrowForVertex.style.display="none";}
Editor.prototype.HighlightVertex=function(vertex)
{let pos=vertex.position.add(new Point(vertex.model.diameter/2*Math.sin(Math.PI/4)+this.arrowForVertex.clientWidth*0,-vertex.model.diameter/2*Math.sin(Math.PI/4)-40/this.application.canvasScale));let posInWindow=this.application.GraphPosToCanvasPos(pos);this.arrowForVertex.style.top=posInWindow.y+'px';this.arrowForVertex.style.left=posInWindow.x+'px';this.arrowForVertex.style.color=InvertColor(this.application.style.backgroundCommonStyle.commonColor);this.arrowForVertex.style.display="block";if(this.arrowForVertexTimer==null)
{this.arrowForVertexTimer=setInterval(function()
{if(this.arrowForVertex.style.display=="none")
{this.arrowForVertex.style.display="block";}
else
{this.arrowForVertex.style.display="none";}}.bind(this),400)}}
Editor.prototype.initVoteButton=function()
{let self=this;if(document.getElementById('VoteButton')!==null)
document.getElementById('VoteButton').onclick=function()
{var dialogButtons={};for(var i=0;i<6&&document.getElementById('vote'+i)!==null;i++)
{document.getElementById('vote'+i)["voteIndex"]=i;document.getElementById('vote'+i).onclick=function()
{console.log("Vote"+self["voteIndex"]);$.ajax({type:"GET",url:"/"+SiteDir+"backend/vote.php?index="+self["voteIndex"],dataType:"text"});$("#voteDialog").dialog('close');$("#VoteButton").hide();}}
dialogButtons[g_close]=function(){$(self).dialog("close");};$("#voteDialog").dialog({resizable:false,title:g_vote,width:400,modal:true,dialogClass:'EdgeDialog',buttons:dialogButtons,});}}
Editor.prototype.initAlgorithmList=function()
{return;let showHideCategory=function(button,elementsListName){let width=$(button).width();let elementsList=$(elementsListName);var hideMark=button.querySelector('span[name="hideMark"]')
var showMark=button.querySelector('span[name="showMark"]')
if(elementsList.is(":visible")){elementsList.hide();$(hideMark).show();$(showMark).hide();}else{elementsList.show();$(hideMark).hide();$(showMark).show();}
$(button).width(width);userAction("algCategory_"+elementsListName);}
$(document.getElementById("algorithmCategoryBtn1").querySelector('span[name="hideMark"]')).hide();$(document.getElementById("algorithmCategoryBtn0").querySelector('span[name="hideMark"]')).hide();$('#algorithmCategoryBtn1').click(function(){showHideCategory(this,"#algorithmCategoryElements1");});$('#algorithmCategoryBtn0').click(function(){showHideCategory(this,"#algorithmCategoryElements0");});}
Editor.prototype.init=function()
{this.application.onLoad();this.initMouseActions();this.initKeyActions();this.initButtonActions();this.initVoteButton();let self=this;loadAsyncAlgorithms(function(){self.createAlgorithmMenu();});var devTools=document.getElementById('developerTools');devTools.style.left=0;resizeCanvas();this.application.onPostLoadEvent();this.initAlgorithmList();}
Editor.prototype.redraw=function(){this.application.redrawGraph();}
Editor.prototype.createAlgorithmMenu=function()
{let self=this;var algorithmBaseId="Algo";var algorithms=this.application.getAlgorithmNames();var index=0;for(var i=0;i','>');pair=pair.replaceAll('<','<');dialogButtons[g_readMatrixHelp]=function(){window.location.assign(g_language=="ru"?"./wiki/Справка/СписокРебер":"./wiki/Help/EdgeList");};dialogButtons[g_fix]=function(){window.location.assign("./create_graph_by_edge_list?pair="+pair);};dialogButtons[g_close]=function(){$(this).dialog("close");};$("#pairErrorInc").dialog({resizable:false,title:g_pairWrongFormat,width:400,modal:true,dialogClass:'EdgeDialog',buttons:dialogButtons,});}
Editor.prototype.ShowAdjacencyMatrixErrorDialog=function(matrix)
{var dialogButtons={};matrixRes=matrix.replace(/\n/g,'%0A');dialogButtons[g_readMatrixHelp]=function(){window.location.assign(g_language=="ru"?"./wiki/Справка/МатрицаСмежности#matrixFormat":"./wiki/Help/AdjacencyMatrix#matrixFormat");};dialogButtons[g_fixMatrix]=function(){window.location.assign("./create_graph_by_matrix?matrix="+matrixRes);};dialogButtons[g_close]=function(){$(this).dialog("close");};$("#matrixError").dialog({resizable:false,title:g_matrixWrongFormat,width:400,modal:true,dialogClass:'EdgeDialog',buttons:dialogButtons,});}
Editor.prototype.SetDefaultHandler=function()
{this.restButtons('Default');this.application.SetHandler(new DefaultHandler(this.application));}
Editor.prototype.OnGraphTypeChanged=function(isMulti)
{$("#CanvasMessage").text(isMulti?g_GraphIsMultiMessage:g_GraphIsGeneralMessage);}
Editor.prototype.updateMessage=function(message)
{$("#message").html(message);}
let DisableEmscripten=false;let PostLoadedCalled=false;let editor=new Editor(document,window);function resizeCanvas()
{var adv=document.getElementById('bottom_info');var canvas=document.getElementById('canvas');canvas.width=document.getElementById('canvasSection').offsetWidth;var mainContainer=document.getElementById('mainContainer');var offset=(mainContainer.offsetTop+mainContainer.offsetHeight)-(canvas.offsetTop+canvas.offsetHeight)+
($("#footerContent").css("display")==='block'?0:24);canvas.height=$(window).height()-document.getElementById('canvas').offsetTop-
(adv&&$("#bottom_info").css("display")==='block'?document.getElementById('bottom_info').offsetHeight:0)-
($("#footer").css("display")==='block'?document.getElementById('footer').offsetHeight:0)-offset;editor.redraw();}
function touchHandler(event)
{var touches=event.changedTouches,first=touches[0],type="";switch(event.type)
{case"touchstart":type="mousedown";break;case"touchmove":type="mousemove";break;case"touchend":type="mouseup";break;default:return;}
var simulatedEvent=document.createEvent("MouseEvent");simulatedEvent.initMouseEvent(type,true,true,window,1,first.screenX,first.screenY,first.clientX,first.clientY,false,false,false,false,0,null);first.target.dispatchEvent(simulatedEvent);event.preventDefault();}
function handelImportGraph(files){var graphFileToLoad=files[0];var fileReader=new FileReader();fileReader.onload=function(fileLoadedEvent){var textFromFileLoaded=fileLoadedEvent.target.result;editor.application.LoadNewGraphFromString(textFromFileLoaded);editor.application.saveAutoSave(textFromFileLoaded);ImportGraphFiles.value="";};fileReader.readAsText(graphFileToLoad,"UTF-8");}
function postLoadPage()
{if(!PostLoadedCalled)
{loadTexts();editor.init();PostLoadedCalled=true;}}
$(document).ready(function()
{window.onresize=function(event)
{resizeCanvas();}
document.getElementById('canvas').addEventListener("touchstart",touchHandler,true);document.getElementById('canvas').addEventListener("touchmove",touchHandler,true);document.getElementById('canvas').addEventListener("touchend",touchHandler,true);document.getElementById('canvas').addEventListener("touchcancel",touchHandler,true);var isMobile=navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i);if(!isMobile&&!DisableEmscripten){let fullPathToGraphffoline="features/graphoffline/Graphoffline.Emscripten.js"+"?v="+globalVersion;doIncludeAsync([include(fullPathToGraphffoline),],()=>{Module['onRuntimeInitialized']=onRuntimeInitialized;var process=Module.cwrap('ProcessAlgorithm','string',['string']);function onRuntimeInitialized(){editor.application.setEmscripten(process);}})}});moduleLoader.endCacheLoading();