From a2a5f7ef257e93e4109547bde191488cc13e0166 Mon Sep 17 00:00:00 2001 From: Unick Soft Date: Sun, 21 Jun 2020 22:28:29 +0200 Subject: [PATCH] Add readme.md --- sandbox/NewAlgorithm.js | 22 +++++++++++++++++++--- sandbox/README.md | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 sandbox/README.md diff --git a/sandbox/NewAlgorithm.js b/sandbox/NewAlgorithm.js index 8756f7b..5eef695 100644 --- a/sandbox/NewAlgorithm.js +++ b/sandbox/NewAlgorithm.js @@ -13,22 +13,25 @@ function NewAlgorithm(graph, app) // inheritance. NewAlgorithm.prototype = Object.create(BaseAlgorithm.prototype); +// Algorithm name NewAlgorithm.prototype.getName = function(local) { return "New algorithm"; } +// Id: CreatorName.AlgorithmName NewAlgorithm.prototype.getId = function() { return "Unknown.Unknown"; } -// @return message for user. +// @return message to user. NewAlgorithm.prototype.getMessage = function(local) { return this.message; } +// Callback is called, when user select vertex. NewAlgorithm.prototype.selectVertex = function(vertex) { this.message = "Processing..."; @@ -38,6 +41,7 @@ NewAlgorithm.prototype.selectVertex = function(vertex) return true; } +// Callback is called, when user deselect vertexs. NewAlgorithm.prototype.deselectAll = function() { this.selectObject = null; @@ -47,6 +51,9 @@ NewAlgorithm.prototype.deselectAll = function() return true; } +// After each action if method is called, +// if algorithm is not ready, it should return null +// otherwise return struct result. NewAlgorithm.prototype.result = function(resultCallback) { if (this.selectObject) @@ -54,6 +61,7 @@ NewAlgorithm.prototype.result = function(resultCallback) var result = {}; result["version"] = 1; + // This is not best way to search neighbours. for (var i = 0; i < this.graph.vertices.length; i ++) { var nextVertex = this.graph.vertices[i]; @@ -62,8 +70,10 @@ NewAlgorithm.prototype.result = function(resultCallback) this.neighbours.push(nextVertex); } + // Return selected objects. result.selectedObjects = this.neighbours; - this.message = "Found " + this.neighbours.length + " neighbours"; + // Change message + this.message = "Found " + this.neighbours.length + " neighbours"; return result; } @@ -73,21 +83,27 @@ NewAlgorithm.prototype.result = function(resultCallback) NewAlgorithm.prototype.getObjectSelectedGroup = function(object) { + // To select objects different color, we return different numbers. + // For deselected objects we return 0. return (object == this.selectObject) ? 1 : (this.neighbours.includes(object) ? 2 : 0); } +// This means nothing for now. Just return 0. NewAlgorithm.prototype.getPriority = function() { return 0; } -// Algorithm support multi graph +// Algorithm support multi graph or not. NewAlgorithm.prototype.IsSupportMultiGraph = function() { return false; } +// Our algorithm is not instant, because user should select vertex. +// For example search connected component is instant, +// because it is not wait any actions from user. NewAlgorithm.prototype.instance = function() { return false; diff --git a/sandbox/README.md b/sandbox/README.md new file mode 100644 index 0000000..d58daa6 --- /dev/null +++ b/sandbox/README.md @@ -0,0 +1,15 @@ +# About this content + +In this directory you can find simple page(index.html), which helps you to create new algorthm on graph on JavaScript. You don't need setuping webserver/php and other environment component. You can simple open index.html in browser and it should work. Also you find here algorithm sample (NewAlgorithm.js). + +# Algorithm creating + +Usualy algorithm is placed on js file. You can look sample NewAlgorithm.js, which search neighbors of vertex. + +As other examples you can look some of our algorithms in /script/plugins. Not all of them are just JS algorthms, some of them use cgi binary component. + +Description of majer classes you find in pdf: https://graphonline.ru/en/wiki/uploads/Development/GraphonlineAPI10En.pdf + +# Supports & feedback + +You can write on github to @UnickSoft or to email admin@graphonline.ru