mirror of
https://github.com/UnickSoft/graphonline.git
synced 2025-07-03 08:15:38 +00:00
Updated ModernGraphStyle algorithm.
This commit is contained in:
parent
063bfc91ec
commit
7a4d803717
@ -49,6 +49,9 @@ ModernGraphStyle.prototype.vertexVisualization = function()
|
||||
var degree = getVertexToVertexArray(this.graph, false);
|
||||
var graph = this.graph;
|
||||
var maxDegree = 0;
|
||||
var sumDegree = 0;
|
||||
|
||||
var sumOfDiameters = graph.vertices.length * (new VertexModel()).diameter;
|
||||
|
||||
// Search max vertex degree.
|
||||
for (var i = 0; i < graph.vertices.length; i++)
|
||||
@ -59,6 +62,7 @@ ModernGraphStyle.prototype.vertexVisualization = function()
|
||||
{
|
||||
var currentDegree = degree[vertex.id].length;
|
||||
maxDegree = Math.max(maxDegree, currentDegree);
|
||||
sumDegree = sumDegree + currentDegree;
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +74,9 @@ ModernGraphStyle.prototype.vertexVisualization = function()
|
||||
if (degree.hasOwnProperty(vertex.id))
|
||||
{
|
||||
var currentDegree = degree[vertex.id].length;
|
||||
vertex.model.diameter = (currentDegree / maxDegree) * (this.maxVertexSize - this.minVertexSize) + this.minVertexSize;
|
||||
//vertex.model.diameter = (currentDegree / maxDegree) * (this.maxVertexSize - this.minVertexSize) + this.minVertexSize;
|
||||
vertex.model.diameter = Math.max(Math.min((currentDegree / sumDegree) * sumOfDiameters, this.maxVertexSize), this.minVertexSize);
|
||||
//sumOfDiameters
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -83,6 +89,8 @@ ModernGraphStyle.prototype.edgeVisualization = function()
|
||||
{
|
||||
var graph = this.graph;
|
||||
var maxEdgeWeight = 0;
|
||||
var sumWeight = 0;
|
||||
var sumOfDiameters = graph.edges.length * (new EdgeModel()).width;
|
||||
|
||||
// Search max edge weight.
|
||||
for (var i = 0; i < graph.edges.length; i++)
|
||||
@ -91,6 +99,7 @@ ModernGraphStyle.prototype.edgeVisualization = function()
|
||||
if (edge.useWeight)
|
||||
{
|
||||
maxEdgeWeight = Math.max(maxEdgeWeight, edge.weight);
|
||||
sumWeight = sumWeight + edge.weight;
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +111,8 @@ ModernGraphStyle.prototype.edgeVisualization = function()
|
||||
var edge = graph.edges[i];
|
||||
if (edge.useWeight)
|
||||
{
|
||||
edge.model.width = (edge.weight / maxEdgeWeight) * (this.maxEdgeSize - this.minEdgeSize) + this.minEdgeSize;
|
||||
//edge.model.width = (edge.weight / maxEdgeWeight) * (this.maxEdgeSize - this.minEdgeSize) + this.minEdgeSize;
|
||||
edge.model.width = Math.max(Math.min((edge.weight / sumWeight) * sumOfDiameters, this.maxEdgeSize), this.minEdgeSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user