mirror of
https://github.com/UnickSoft/graphonline.git
synced 2026-02-16 02:30:51 +00:00
Updated max stream. Improved visualisation.
This commit is contained in:
@@ -200,42 +200,33 @@ Application.prototype.setRenderPath = function(renderPath)
|
||||
Application.prototype.RedrawEdge = function(context, edge)
|
||||
{
|
||||
var arcDrawer = new BaseEdgeDrawer(context);
|
||||
var directArcDrawer = new DirectArcDrawer(context);
|
||||
var commonStyle = new CommonEdgeStyle(context);
|
||||
var selectedStyles = selectedEdgeStyles;
|
||||
|
||||
this._RedrawEdge(edge, arcDrawer, directArcDrawer, commonStyle, selectedStyles);
|
||||
this._RedrawEdge(edge, arcDrawer, commonStyle, selectedStyles);
|
||||
}
|
||||
|
||||
Application.prototype._RedrawEdge = function(edge, arcDrawer, directArcDrawer, commonStyle, selectedStyles)
|
||||
Application.prototype._RedrawEdge = function(edge, arcDrawer, commonStyle, selectedStyles)
|
||||
{
|
||||
var selectedGroup = this.handler.GetSelectedGroup(edge);
|
||||
var currentStyle = selectedGroup > 0 ?
|
||||
selectedStyles[(selectedGroup - 1) % selectedStyles.length] : commonStyle;
|
||||
|
||||
this._RedrawEdgeWithStyle(edge, currentStyle, arcDrawer, directArcDrawer, commonStyle, selectedStyles);
|
||||
this._RedrawEdgeWithStyle(edge, currentStyle, arcDrawer, commonStyle, selectedStyles);
|
||||
}
|
||||
|
||||
Application.prototype._RedrawEdgeWithStyle = function(edge, style, arcDrawer, directArcDrawer, commonStyle, selectedStyles)
|
||||
Application.prototype._RedrawEdgeWithStyle = function(edge, style, arcDrawer, commonStyle, selectedStyles)
|
||||
{
|
||||
if (!edge.isDirect)
|
||||
{
|
||||
arcDrawer.Draw(edge, style);
|
||||
}
|
||||
else
|
||||
{
|
||||
directArcDrawer.Draw(edge, style);
|
||||
}
|
||||
arcDrawer.Draw(edge, style);
|
||||
}
|
||||
|
||||
Application.prototype.RedrawEdgeProgress = function(context, edge, progress)
|
||||
{
|
||||
var arcDrawer = new ProgressArcDrawer(context, new BaseEdgeDrawer(context), progress);
|
||||
var directArcDrawer = new ProgressArcDrawer(context, new DirectArcDrawer(context), progress);
|
||||
var commonStyle = new CommonEdgeStyle(context);
|
||||
var selectedStyles = selectedEdgeStyles;
|
||||
|
||||
this._RedrawEdge(edge, arcDrawer, directArcDrawer, commonStyle, selectedStyles);
|
||||
this._RedrawEdge(edge, arcDrawer, commonStyle, selectedStyles);
|
||||
}
|
||||
|
||||
Application.prototype.RedrawEdges = function(context)
|
||||
|
||||
@@ -8,6 +8,9 @@ function BaseEdge(vertex1, vertex2, isDirect, weight, useWeight)
|
||||
{
|
||||
this.vertex1 = vertex1;
|
||||
this.vertex2 = vertex2;
|
||||
this.arrayStyleStart = "";
|
||||
this.arrayStyleFinish = "";
|
||||
|
||||
this.isDirect = isDirect;
|
||||
this.weight = Number(weight);
|
||||
this.text = "";
|
||||
@@ -29,6 +32,8 @@ BaseEdge.prototype.SaveToXML = function ()
|
||||
"hasPair=\"" + this.hasPair + "\" " +
|
||||
"id=\"" + this.id + "\" " +
|
||||
"text=\"" + this.text + "\" " +
|
||||
"arrayStyleStart=\"" + this.arrayStyleStart + "\" " +
|
||||
"arrayStyleFinish=\"" + this.arrayStyleFinish + "\" " +
|
||||
"></edge>";
|
||||
}
|
||||
|
||||
@@ -44,6 +49,8 @@ BaseEdge.prototype.LoadFromXML = function (xml, graph)
|
||||
this.useWeight = xml.attr('useWeight') == "true";
|
||||
this.id = parseInt(xml.attr('id'));
|
||||
this.text = xml.attr("text") == null ? "" : xml.attr("text");
|
||||
this.arrayStyleStart = xml.attr("arrayStyleStart") == null ? "" : xml.attr("arrayStyleStart");
|
||||
this.arrayStyleFinish = xml.attr("arrayStyleFinish") == null ? "" : xml.attr("arrayStyleFinish");
|
||||
}
|
||||
|
||||
BaseEdge.prototype.GetPixelLength = function ()
|
||||
@@ -66,4 +73,14 @@ BaseEdge.prototype.GetWeight = function ()
|
||||
BaseEdge.prototype.GetText = function ()
|
||||
{
|
||||
return this.text.length > 0 ? this.text : (this.useWeight ? this.weight.toString() : "");
|
||||
}
|
||||
}
|
||||
|
||||
BaseEdge.prototype.GetStartEdgeStyle = function ()
|
||||
{
|
||||
return this.arrayStyleStart;
|
||||
}
|
||||
|
||||
BaseEdge.prototype.GetFinishEdgeStyle = function ()
|
||||
{
|
||||
return (this.arrayStyleFinish != "" ? this.arrayStyleFinish : (this.isDirect ? "arrow" : ""));
|
||||
}
|
||||
|
||||
@@ -91,10 +91,38 @@ function BaseEdgeDrawer(context)
|
||||
BaseEdgeDrawer.prototype.Draw = function(baseEdge, arcStyle)
|
||||
{
|
||||
this.SetupStyle(baseEdge, arcStyle);
|
||||
|
||||
var positions = this.GetArcPositions(baseEdge.vertex1.position, baseEdge.vertex2.position, baseEdge.vertex1.model.diameter);
|
||||
|
||||
var length = baseEdge.model.width * 4;
|
||||
var width = baseEdge.model.width * 2;
|
||||
var position1 = baseEdge.vertex1.position;
|
||||
var position2 = baseEdge.vertex2.position;
|
||||
var direction = position1.subtract(position2);
|
||||
var pairShift = baseEdge.vertex1.model.diameter * 0.25;
|
||||
var realShift = (baseEdge.hasPair ? pairShift : 0);
|
||||
direction.normalize(1.0);
|
||||
var positions = this.GetArcPositionsShift(baseEdge.vertex1.position,
|
||||
baseEdge.vertex2.position, baseEdge.vertex1.model.diameter, baseEdge.vertex2.model.diameter, realShift);
|
||||
|
||||
this.DrawArc (positions[0], positions[1], arcStyle);
|
||||
var hasStartStyle = !position1.equals(position2) && baseEdge.GetStartEdgeStyle() != "";
|
||||
var hasFinishStyle = !position1.equals(position2) && baseEdge.GetFinishEdgeStyle() != "";
|
||||
|
||||
this.DrawArc (positions[0].subtract(direction.multiply(hasStartStyle ? -length / 2 : 0.0)),
|
||||
positions[1].subtract(direction.multiply(hasFinishStyle ? -length / 2 : 0.0)), arcStyle);
|
||||
|
||||
this.context.fillStyle = this.context.strokeStyle;
|
||||
this.context.lineWidth = 0;
|
||||
|
||||
if (hasStartStyle)
|
||||
{
|
||||
this.DrawArrow(positions[0], positions[1], length, width);
|
||||
}
|
||||
if (hasFinishStyle)
|
||||
{
|
||||
this.DrawArrow(positions[1], positions[0], length, width);
|
||||
}
|
||||
|
||||
this.SetupStyle(baseEdge, arcStyle);
|
||||
|
||||
if (baseEdge.GetText().length > 0)
|
||||
{
|
||||
this.DrawWeight(positions[0], positions[1], baseEdge.GetText(), arcStyle, baseEdge.hasPair);
|
||||
@@ -193,70 +221,25 @@ BaseEdgeDrawer.prototype.GetArcPositionsShift = function(position1, position2, d
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Direct Arc drawer.
|
||||
*/
|
||||
function DirectArcDrawer(context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
DirectArcDrawer.prototype = Object.create(BaseEdgeDrawer.prototype);
|
||||
|
||||
DirectArcDrawer.prototype.Draw = function(baseEdge, arcStyle)
|
||||
BaseEdgeDrawer.prototype.DrawArrow = function(position1, position2, length, width)
|
||||
{
|
||||
baseDrawer = this.CreateBase();
|
||||
baseDrawer.SetupStyle(baseEdge, arcStyle);
|
||||
|
||||
var length = baseEdge.model.width * 4;
|
||||
var width = baseEdge.model.width * 2;
|
||||
var position1 = baseEdge.vertex1.position;
|
||||
var position2 = baseEdge.vertex2.position;
|
||||
var direction = position1.subtract(position2);
|
||||
var pairShift = baseEdge.vertex1.model.diameter * 0.25;
|
||||
var realShift = (baseEdge.hasPair ? pairShift : 0);
|
||||
direction.normalize(1.0);
|
||||
var positions = this.GetArcPositionsShift(baseEdge.vertex1.position,
|
||||
baseEdge.vertex2.position, baseEdge.vertex1.model.diameter, baseEdge.vertex2.model.diameter, realShift);
|
||||
|
||||
baseDrawer.DrawArc (positions[0], positions[1].subtract(direction.multiply(-length / 2)), arcStyle);
|
||||
|
||||
this.context.fillStyle = this.context.strokeStyle;
|
||||
this.context.lineWidth = 0;
|
||||
this.DrawArrow(positions[0], positions[1], length, width);
|
||||
|
||||
if (baseEdge.GetText().length > 0)
|
||||
{
|
||||
baseDrawer.DrawWeight(positions[0], positions[1], baseEdge.GetText(), arcStyle, baseEdge.hasPair);
|
||||
}
|
||||
}
|
||||
|
||||
DirectArcDrawer.prototype.DrawArrow = function(position1, position2, length, width)
|
||||
{
|
||||
var direction = position2.subtract(position1);
|
||||
direction.normalize(1.0);
|
||||
var normal = direction.normal();
|
||||
|
||||
var pointOnLine = position2.subtract(direction.multiply(length));
|
||||
var pointOnLine = position1.subtract(direction.multiply(length));
|
||||
var point1 = pointOnLine.add(normal.multiply(width));
|
||||
var point2 = pointOnLine.add(normal.multiply(-width));
|
||||
|
||||
this.context.beginPath();
|
||||
this.context.moveTo(position2.x, position2.y);
|
||||
this.context.moveTo(position1.x, position1.y);
|
||||
this.context.lineTo(point1.x, point1.y);
|
||||
this.context.lineTo(point2.x, point2.y);
|
||||
this.context.lineTo(position2.x, position2.y);
|
||||
this.context.lineTo(position1.x, position1.y);
|
||||
this.context.closePath();
|
||||
this.context.fill();
|
||||
}
|
||||
|
||||
DirectArcDrawer.prototype.CreateBase = function()
|
||||
{
|
||||
return new BaseEdgeDrawer(this.context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function ProgressArcDrawer(context, baseDrawer, progress)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,9 @@ function FindMaxFlow(graph, app)
|
||||
this.selectedObjects = {};
|
||||
this.selectedEdges = [];
|
||||
this.resetUpText = [];
|
||||
|
||||
this.minEdgeSize = 2;
|
||||
this.maxEdgeSize = 12;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,24 +65,55 @@ FindMaxFlow.prototype.resultCallback = function(pathObjects, properties, results
|
||||
|
||||
var bFound = results.length > 0 && results[0].value < 1E5 && (results[0].type == 1 || results[0].type == 2) && results[0].value * 1 > 0.0;
|
||||
|
||||
var maxFlow = results[0].value * 1;
|
||||
|
||||
if (bFound)
|
||||
{
|
||||
this.selectedObjects = {};
|
||||
|
||||
var defaultDiameter = (new EdgeModel()).width;
|
||||
|
||||
var avgFlow = 0;
|
||||
var countEdges = 0;
|
||||
|
||||
for (var i = 0; i < pathObjects.length; i++)
|
||||
{
|
||||
if (pathObjects[i] instanceof BaseEdge)
|
||||
{
|
||||
avgFlow += properties[pathObjects[i].id]["flowValue"] * 1;
|
||||
countEdges += 1;
|
||||
}
|
||||
}
|
||||
avgFlow = avgFlow / countEdges;
|
||||
|
||||
for (var i = 0; i < pathObjects.length; i++)
|
||||
{
|
||||
if (pathObjects[i] instanceof BaseEdge)
|
||||
{
|
||||
this.selectedObjects[pathObjects[i].id] = 1;
|
||||
if (pathObjects[i].useWeight)
|
||||
var flow = properties[pathObjects[i].id]["flowValue"] * 1;
|
||||
if (pathObjects[i].useWeight || flow != pathObjects[i].GetWeight())
|
||||
{
|
||||
pathObjects[i].text = properties[pathObjects[i].id]["flowValue"] + " / " + pathObjects[i].GetWeight();
|
||||
pathObjects[i].text = flow + " / " + pathObjects[i].GetWeight();
|
||||
}
|
||||
if (!pathObjects[i].isDirect)
|
||||
{
|
||||
if (parseInt(properties[pathObjects[i].id]["backToFront"]) > 0)
|
||||
{
|
||||
pathObjects[i].arrayStyleStart = "arrow";
|
||||
}
|
||||
else
|
||||
{
|
||||
pathObjects[i].arrayStyleFinish = "arrow";
|
||||
}
|
||||
}
|
||||
|
||||
pathObjects[i].model.width = Math.max(Math.min((flow / avgFlow) * defaultDiameter, this.maxEdgeSize), this.minEdgeSize);
|
||||
}
|
||||
}
|
||||
this.selectedEdges = pathObjects;
|
||||
|
||||
this.message = g_maxFlowResult.replace("%1", (results[0].value * 1).toString()).replace("%2", this.firstObject.mainText).replace("%3", this.secondObject.mainText);
|
||||
this.message = g_maxFlowResult.replace("%1", (maxFlow).toString()).replace("%2", this.firstObject.mainText).replace("%3", this.secondObject.mainText);
|
||||
|
||||
this.selectedObjects[this.secondObject.id] = 3;
|
||||
this.selectedObjects[this.firstObject.id] = 1;
|
||||
@@ -164,6 +198,9 @@ BaseAlgorithm.prototype.restore = function()
|
||||
if (this.selectedEdges[i] instanceof BaseEdge)
|
||||
{
|
||||
this.selectedEdges[i].text = "";
|
||||
this.selectedEdges[i].arrayStyleStart = "";
|
||||
this.selectedEdges[i].arrayStyleFinish = "";
|
||||
this.selectedEdges[i].model.width = (new EdgeModel()).width;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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=3")?>" ></script>
|
||||
<script src="<?= Root("script/example.js?v=4")?>" ></script>
|
||||
</head>
|
||||
<!--
|
||||
<div class="pull-right">
|
||||
|
||||
Reference in New Issue
Block a user