Add special actions for edges.

This commit is contained in:
Oleg Sh 2022-05-15 22:02:14 +02:00
parent 18eac65c92
commit 194715260d
15 changed files with 197 additions and 14 deletions

View File

@ -280,4 +280,9 @@ We have added Dutch translation 🇳🇱. Thank you Willie de Wit</a>";
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -280,4 +280,9 @@
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -243,4 +243,9 @@
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -281,4 +281,9 @@
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -280,4 +280,9 @@ We have added Dutch translation 🇳🇱. Thank you Willie de Wit</a>";
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -280,4 +280,9 @@ Tenemos traducciones en griego 🇬🇷.</a> <a href=\"https://github.com/UnickS
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -248,4 +248,9 @@
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -245,4 +245,9 @@
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -246,4 +246,9 @@
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -281,4 +281,10 @@
$g_lang['find_longest_path'] = "Поиск самого длинного пути";
$g_lang['length_of_longest_path_from'] = "Длина самого длинного пути ровна ";
$g_lang['additionl_actions'] = "Особые действия";
$g_lang['reverse_all_edges'] = "Поменять направление всех дуг";
$g_lang['make_all_undirected'] = "Сделать все дуги неориентированными";
$g_lang['make_all_directed'] = "Сделать все дуги ориентированными";
?>

View File

@ -242,4 +242,9 @@
$g_lang['find_longest_path'] = "Find the longest path";
$g_lang['length_of_longest_path_from'] = "Length of the longest path from ";
$g_lang['additionl_actions'] = "Special actions";
$g_lang['reverse_all_edges'] = "Reverse all edges";
$g_lang['make_all_undirected'] = "Make all edges undirected";
$g_lang['make_all_directed'] = "Make all edges directed";
?>

View File

@ -1035,6 +1035,8 @@ ConnectionGraphHandler.prototype.SelectVertex = function(selectedObject)
ConnectionGraphHandler.prototype.MouseDown = function(pos)
{
$('#message').unbind();
var selectedObject = this.GetSelectedGraph(pos);
if (selectedObject && (selectedObject instanceof BaseVertex))
{
@ -1055,7 +1057,55 @@ ConnectionGraphHandler.prototype.GetSelectedGroup = function(object)
ConnectionGraphHandler.prototype.SelectFirst = function()
{
this.firstObject = null;
let hasEdges = this.app.graph.hasEdges();
let hasDirectedEdges = this.app.graph.hasDirectEdge();
let hasUndirectedEdges = this.app.graph.hasUndirectEdge();
this.message = g_selectFisrtVertexToConnect + this.GetSelect2VertexMenu();
if (!hasEdges) {
return;
}
this.message =
". <div class=\"btn-group\" style=\"float:right; position: relative; margin-left: 8px\">"
+ "<button type=\"button\" class=\"btn btn-default btn-sm dropdown-toggle\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\">"
+ g_additionlActions + " <span class=\"caret\"></span>"
+ " </button> "
+ "<ul class=\"dropdown-menu dropdown-menu-right\" style=\"z-index:15; position: absolute;\">"
+ (hasDirectedEdges ? " <li><a href=\"#\" id=\"reverseAll\">" + g_reverseAllEdges + "</a></li>" : "")
+ (hasDirectedEdges ? " <li><a href=\"#\" id=\"makeAllUndirected\">" + g_makeAllUndirected + "</a></li>" : "")
+ (hasUndirectedEdges ? " <li><a href=\"#\" id=\"makeAllDirected\">" + g_makeAllDirected + "</a></li>" : "")
+ "</ul>"
+ "</div> " + this.message;
let handler = this;
$('#message').on('click', '#reverseAll', function() {
handler.app.PushToStack("ReverseAllEdges");
handler.app.graph.reverseAllEdges();
handler.app.redrawGraph();
userAction("ReverseAllEdges");
});
$('#message').on('click', '#makeAllUndirected', function(){
handler.app.PushToStack("makeAllEdgesUndirected");
handler.app.graph.makeAllEdgesUndirected();
handler.app.redrawGraph();
userAction("makeAllEdgesUndirected");
});
$('#message').on('click', '#makeAllDirected', function(){
handler.app.PushToStack("makeAllEdgesDirected");
handler.app.graph.makeAllEdgesDirected();
handler.app.redrawGraph();
userAction("makeAllEdgesDirected");
});
}
ConnectionGraphHandler.prototype.SelectSecond = function(selectedObject)

View File

@ -986,6 +986,26 @@ Graph.prototype.hasDirectEdge = function ()
return res;
}
Graph.prototype.hasUndirectEdge = function ()
{
var res = false;
for (var i = 0; i < this.edges.length; i++)
{
if(!this.edges[i].isDirect)
{
res = true;
break;
}
}
return res;
}
Graph.prototype.hasEdges = function ()
{
return this.edges.length > 0;
}
Graph.prototype.clampPositions = function (viewportSize)
{
var diameter = (new VertexModel()).diameter;
@ -1179,3 +1199,44 @@ Graph.prototype.GetAvalibleCruvledValue = function(neighbourEdges, originalEdge)
return defaultValue;
}
Graph.prototype.reverseAllEdges = function ()
{
for (var i = 0; i < this.edges.length; i++)
{
if(this.edges[i].isDirect)
{
let v1 = this.edges[i].vertex1;
this.edges[i].vertex1 = this.edges[i].vertex2;
this.edges[i].vertex2 = v1;
}
}
this.isMultiGraph = this.checkMutiGraph();
}
Graph.prototype.makeAllEdgesDirected = function ()
{
for (var i = 0; i < this.edges.length; i++)
{
if(!this.edges[i].isDirect)
{
this.edges[i].isDirect = true;
}
}
this.isMultiGraph = this.checkMutiGraph();
}
Graph.prototype.makeAllEdgesUndirected = function ()
{
for (var i = 0; i < this.edges.length; i++)
{
if(this.edges[i].isDirect)
{
this.edges[i].isDirect = false;
}
}
this.isMultiGraph = this.checkMutiGraph();
}

View File

@ -189,6 +189,11 @@ 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_additionlActions = "Additional actions";
var g_reverseAllEdges = "Reverse all edges";
var g_makeAllUndirected = "Make all edges undirected";
var g_makeAllDirected = "Make all edges directed";
function loadTexts()
{
g_textsSelectAndMove = document.getElementById("SelectAndMoveObject").innerHTML;
@ -385,4 +390,9 @@ function loadTexts()
g_findLongestPath = document.getElementById("findLongestPath").innerHTML;
g_LengthOfLongestPathFrom = document.getElementById("LengthOfLongestPathFrom").innerHTML;
g_additionlActions = document.getElementById("additionlActions").innerHTML;
g_reverseAllEdges = document.getElementById("reverseAllEdges").innerHTML;
g_makeAllUndirected = document.getElementById("makeAllUndirected").innerHTML;
g_makeAllDirected = document.getElementById("makeAllDirected").innerHTML;
}

View File

@ -10,7 +10,7 @@
<script src="<?= Root('i/js/dev/jquery-ui.js')?>"></script>
<script src="<?= Root('i/js/dev/jquery.feedback_me.js')?>"></script>
<script src="<?= Root("script/example.js?v=62")?>" ></script>
<script src="<?= Root("script/example.js?v=63")?>" ></script>
<!-- Yandex.RTB -->
<script>window.yaContextCb=window.yaContextCb||[]</script>
@ -839,6 +839,12 @@
<p id="findLongestPath" class="translation"><?= L('find_longest_path')?></p>
<p id="LengthOfLongestPathFrom" class="translation"><?= L('length_of_longest_path_from')?></p>
<p id="additionlActions" class="translation"><?= L('additionl_actions')?></p>
<p id="reverseAllEdges" class="translation"><?= L('reverse_all_edges')?></p>
<p id="makeAllUndirected" class="translation"><?= L('make_all_undirected')?></p>
<p id="makeAllDirected" class="translation"><?= L('make_all_directed')?></p>
</section>
<!--
<script>