Fix self loop edges visualisation.

This commit is contained in:
Oleg Sh 2022-07-14 21:24:17 +02:00
parent 9aa9888e4b
commit f3f54b6646
3 changed files with 23 additions and 9 deletions

View File

@ -434,8 +434,10 @@ BaseEdgeDrawer.prototype.GetTextCenterPoint = function (position1, position2, ha
var centerPoint = Point.interpolate(position1, position2, 0.5); var centerPoint = Point.interpolate(position1, position2, 0.5);
if (position1.equals(position2)) if (position1.equals(position2))
{ {
centerPoint.y = centerPoint.y - Math.cos(this.model.GetLoopShiftAngel()) * this.model.GetLoopSize() * 2; let sinVal = Math.sin(this.model.GetLoopShiftAngel());
centerPoint.x = centerPoint.x - Math.sin(this.model.GetLoopShiftAngel()) * this.model.GetLoopSize() * 2; let cosVal = Math.cos(this.model.GetLoopShiftAngel());
centerPoint.x = centerPoint.x - cosVal * this.model.GetLoopSize();
centerPoint.y = centerPoint.y - (sinVal + Math.sign(sinVal) * 1.0) * this.model.GetLoopSize();
} }
return centerPoint; return centerPoint;
@ -547,8 +549,10 @@ CurvedArcDrawer.prototype.GetTextCenterPoint = function (position1, position2, h
var centerPoint = this.model.GetCurvePoint(position1, position2, 0.5) var centerPoint = this.model.GetCurvePoint(position1, position2, 0.5)
if (position1.equals(position2)) if (position1.equals(position2))
{ {
centerPoint.y = centerPoint.y - Math.cos(this.model.GetLoopShiftAngel()) * this.model.GetLoopSize() * 2; let sinVal = Math.sin(this.model.GetLoopShiftAngel());
centerPoint.x = centerPoint.x - Math.sin(this.model.GetLoopShiftAngel()) * this.model.GetLoopSize() * 2; let cosVal = Math.cos(this.model.GetLoopShiftAngel());
centerPoint.x = centerPoint.x - cosVal * this.model.GetLoopSize();
centerPoint.y = centerPoint.y - (sinVal + Math.sign(sinVal) * 1.0) * this.model.GetLoopSize();
} }
return centerPoint; return centerPoint;

View File

@ -205,19 +205,29 @@ EdgeModel.prototype.SetCurveValue = function (value)
EdgeModel.prototype.GetLoopSize = function () EdgeModel.prototype.GetLoopSize = function ()
{ {
if (Math.abs(this.curveValue) <= 0.01) if (Math.abs(this.curveValue) <= 0.01)
{ // without this condition arc disappears when curveValue=0 {
// without this condition arc disappears when curveValue=0
return this.sizeOfLoop; return this.sizeOfLoop;
} }
else else
{ // bigger curveValue -> bigger loop size {
return this.sizeOfLoop*Math.abs(this.curveValue)*(1/this.defaultCurve); // bigger curveValue -> bigger loop size
let normalCurve = this.curveValue;
if (this.type == EdgeModels.line) {
normalCurve = this.defaultCurve;
}
else if (normalCurve >= 0.0) {
normalCurve += this.defaultCurve
}
return this.sizeOfLoop * Math.abs(normalCurve) * (1 / this.defaultCurve);
} }
} }
EdgeModel.prototype.GetLoopShiftAngel = function () EdgeModel.prototype.GetLoopShiftAngel = function ()
{ {
if (this.curveValue > 0) if (this.type == EdgeModels.line || this.curveValue >= 0.0)
{ // shift to top-left { // shift to top-left
return this.loopShiftAngel; return this.loopShiftAngel;
} }

View File

@ -11,7 +11,7 @@
<script src="<?= Root('i/js/dev/jquery-ui.js')?>"></script> <script src="<?= Root('i/js/dev/jquery-ui.js')?>"></script>
<script src="<?= Root('i/js/dev/jquery.feedback_me.js')?>"></script> <script src="<?= Root('i/js/dev/jquery.feedback_me.js')?>"></script>
<script src="<?= Root("script/canvas2svg.js")?>" ></script> <script src="<?= Root("script/canvas2svg.js")?>" ></script>
<script src="<?= Root("script/example.js?v=65")?>" ></script> <script src="<?= Root("script/example.js?v=66")?>" ></script>
<!-- Yandex.RTB --> <!-- Yandex.RTB -->
<script>window.yaContextCb=window.yaContextCb||[]</script> <script>window.yaContextCb=window.yaContextCb||[]</script>