mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-04-23 08:26:38 +00:00
Enhance matrix display functionality and formatting.
This commit is contained in:
@@ -20,25 +20,55 @@ ShowDistanceMatrix.prototype.firstObject = null;
|
||||
// Path
|
||||
ShowDistanceMatrix.prototype.pathObjects = null;
|
||||
|
||||
ShowDistanceMatrix.prototype.GetIncidenceMatrix = function (rawMatrix)
|
||||
ShowDistanceMatrix.prototype.GetIncidenceMatrix = function (rawMatrix, res_columns_width)
|
||||
{
|
||||
let get_weight_str = function (i, j)
|
||||
{
|
||||
let str = "";
|
||||
if (i == j)
|
||||
{
|
||||
str += "0";
|
||||
}
|
||||
else if ((new Graph()).infinity == rawMatrix[i][j])
|
||||
{
|
||||
str += '\u221E';
|
||||
}
|
||||
else
|
||||
{
|
||||
str += rawMatrix[i][j];
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
for (var j = 0; j < rawMatrix.length; j++)
|
||||
{
|
||||
let max_length = 0;
|
||||
for (var i = 0; i < rawMatrix.length; i++)
|
||||
{
|
||||
let str = get_weight_str(i, j);
|
||||
let weight_len = str.length;
|
||||
// Make the length at least 2 if vertex name length > 1
|
||||
if (this.app.graph.vertices[j].mainText.toString().length > weight_len && weight_len == 1)
|
||||
{
|
||||
weight_len = 2;
|
||||
}
|
||||
max_length = Math.max(max_length, weight_len);
|
||||
}
|
||||
res_columns_width.push(max_length);
|
||||
}
|
||||
|
||||
var matrix = "";
|
||||
for (var i = 0; i < rawMatrix.length; i++)
|
||||
{
|
||||
for (var j = 0; j < rawMatrix[i].length; j++)
|
||||
{
|
||||
if (i == j)
|
||||
{
|
||||
matrix += "0";
|
||||
}
|
||||
else if ((new Graph()).infinity == rawMatrix[i][j])
|
||||
{
|
||||
matrix += '\u221E';
|
||||
}
|
||||
else
|
||||
{
|
||||
matrix += rawMatrix[i][j];
|
||||
}
|
||||
let weight_str = get_weight_str(i, j);
|
||||
if (weight_str.length < res_columns_width[j])
|
||||
{
|
||||
weight_str = " ".repeat(res_columns_width[j] - weight_str.length) + weight_str;
|
||||
}
|
||||
|
||||
matrix += weight_str;
|
||||
|
||||
if (j != rawMatrix[i].length - 1)
|
||||
{
|
||||
@@ -63,7 +93,39 @@ ShowDistanceMatrix.prototype.show = function()
|
||||
|
||||
var handler = g_Algorithms[g_AlgorithmIds.indexOf("OlegSh.FloidAlgorithm")](this.app.graph, this.app);
|
||||
|
||||
$( "#FloidMatrixField" ).val(this.GetIncidenceMatrix(handler.resultMatrix()));
|
||||
let ta = $("#FloidMatrixField");
|
||||
let topWrap = $("#floidMatrix_top_text");
|
||||
let sideWrap = $("#floidMatrix_side_text");
|
||||
|
||||
ta.on("scroll", function() {
|
||||
topWrap.scrollLeft(ta.scrollLeft());
|
||||
sideWrap.scrollTop(ta.scrollTop());
|
||||
});
|
||||
|
||||
let res_columns_width = [];
|
||||
|
||||
ta.val(this.GetIncidenceMatrix(handler.resultMatrix(), res_columns_width).trimEnd());
|
||||
ta.focus()[0].setSelectionRange(0, 0);
|
||||
|
||||
/* Make side and top text */
|
||||
let sideText = "";
|
||||
let topText = "";
|
||||
for (let i = 0; i < this.app.graph.vertices.length; i++)
|
||||
{
|
||||
/* Each vertex name max 3 symbols */
|
||||
sideText += this.app.graph.vertices[i].mainText.toString().slice(0, 3) + "\n";
|
||||
|
||||
let col_width = res_columns_width[i];
|
||||
let col_text = this.app.graph.vertices[i].mainText.toString();
|
||||
if (col_width < col_text.length)
|
||||
{
|
||||
col_text = col_text.slice(0, col_width);
|
||||
}
|
||||
col_text = col_text.padStart(col_width, " ");
|
||||
topText += col_text + " ";
|
||||
}
|
||||
$("#floidMatrix_top_text_text").html(topText);
|
||||
$("#floidMatrix_side_text_text").html(sideText + "\n");
|
||||
|
||||
$( "#floidMatrix" ).dialog({
|
||||
resizable: false,
|
||||
@@ -72,6 +134,11 @@ ShowDistanceMatrix.prototype.show = function()
|
||||
modal: true,
|
||||
title: g_minDistMatrixText,
|
||||
buttons: dialogButtons,
|
||||
dialogClass: 'EdgeDialog'
|
||||
dialogClass: 'EdgeDialog',
|
||||
open: function(event, ui) {
|
||||
/* Set width for side text */
|
||||
$("#floidMatrix_top_text").width(ta.width());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user