From d759a1972818f21d2c2be03f78c314b391825a68 Mon Sep 17 00:00:00 2001 From: Unick Soft Date: Thu, 21 Jun 2018 23:02:23 +0300 Subject: [PATCH] Added distance matrix --- script/Appilcation.js | 5 +++ script/EventHandlers.js | 74 +++++++++++++++++++++++++++++++++++++++++ script/main.js | 5 +++ tpl/home.php | 7 ++-- 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/script/Appilcation.js b/script/Appilcation.js index 1cb4e25..e995aca 100644 --- a/script/Appilcation.js +++ b/script/Appilcation.js @@ -515,6 +515,11 @@ Application.prototype.SetHandlerMode = function(mode) var showIncidenceMatrix = new ShowIncidenceMatrix(this); showIncidenceMatrix.show(); } + else if (mode == "showDistanceMatrix") + { + var showDistanceMatrix = new ShowDistanceMatrix(this); + showDistanceMatrix.show(); + } else if (mode == "connectedComponent") { this.handler = new ConnectedComponentGraphHandler(this); diff --git a/script/EventHandlers.js b/script/EventHandlers.js index 794cc44..5a6b3b8 100644 --- a/script/EventHandlers.js +++ b/script/EventHandlers.js @@ -572,6 +572,80 @@ ShowIncidenceMatrix.prototype.show = function() } +/** + * Show distance matrix. + * + */ +function ShowDistanceMatrix(app) +{ + BaseHandler.apply(this, arguments); + this.app = app; + this.message = ""; +} + +// inheritance. +ShowDistanceMatrix.prototype = Object.create(BaseHandler.prototype); +// First selected. +ShowDistanceMatrix.prototype.firstObject = null; +// Path +ShowDistanceMatrix.prototype.pathObjects = null; + +ShowDistanceMatrix.prototype.GetIncidenceMatrix = function (rawMatrix) +{ + var matrix = ""; + for (var i = 0; i < rawMatrix.length; i++) + { + for (var j = 0; j < rawMatrix[i].length; j++) + { + if ((new Graph()).infinity == rawMatrix[i][j]) + { + matrix += '\u221E'; + } + else if (i == j) + { + matrix += "0"; + } + else + { + matrix += rawMatrix[i][j]; + } + + if (j != rawMatrix[i].length - 1) + { + matrix += ", "; + } + + } + matrix = matrix + "\n"; + } + + return matrix; +} + +ShowDistanceMatrix.prototype.show = function() +{ + var handler = this; + var dialogButtons = {}; + + dialogButtons[g_close] = function() { + $( this ).dialog( "close" ); + }; + + var handler = g_Algorithms[g_AlgorithmIds.indexOf("OlegSh.FloidAlgorithm")](this.app.graph, this.app); + + $( "#FloidMatrixField" ).val(this.GetIncidenceMatrix(handler.resultMatrix())); + + $( "#floidMatrix" ).dialog({ + resizable: false, + height: "auto", + width: "auto", + modal: true, + title: g_minDistMatrixText, + buttons: dialogButtons, + dialogClass: 'EdgeDialog' + }); +} + /** * Save dialog Graph handler. * diff --git a/script/main.js b/script/main.js index 75b3662..e7c7a2b 100644 --- a/script/main.js +++ b/script/main.js @@ -279,6 +279,11 @@ function postLoadPage() userAction(this.id); application.SetHandlerMode("showIncidenceMatrix"); } + document.getElementById('ShowDistanceMatrix').onclick = function () + { + userAction(this.id); + application.SetHandlerMode("showDistanceMatrix"); + } document.getElementById('GroupRename').onclick = function () { diff --git a/tpl/home.php b/tpl/home.php index dcad5fc..f88eafe 100755 --- a/tpl/home.php +++ b/tpl/home.php @@ -10,7 +10,7 @@ - +