Skip to content

Commit

Permalink
Fix #8
Browse files Browse the repository at this point in the history
Considers all possible positions of compound labels during bound update
  • Loading branch information
hasanbalci committed Dec 16, 2020
1 parent 2272e41 commit 3d9b690
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
26 changes: 18 additions & 8 deletions layout-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,18 +574,28 @@ LNode.prototype.updateBounds = function () {
var width = childGraph.getRight() - childGraph.getLeft();
var height = childGraph.getBottom() - childGraph.getTop();

if (this.labelWidth > width) {
this.rect.x -= (this.labelWidth - width) / 2;
this.setWidth(this.labelWidth);
if (this.labelWidth) {
if (this.labelPosHorizontal == "left") {
this.rect.x -= this.labelWidth;
this.setWidth(width + this.labelWidth);
} else if (this.labelPosHorizontal == "center" && this.labelWidth > width) {
this.rect.x -= (this.labelWidth - width) / 2;
this.setWidth(this.labelWidth);
} else if (this.labelPosHorizontal == "right") {
this.setWidth(width + this.labelWidth);
}
}

if (this.labelHeight > height) {
if (this.labelPos == "center") {
if (this.labelHeight) {
if (this.labelPosVertical == "top") {
this.rect.y -= this.labelHeight;
this.setHeight(height + this.labelHeight);
} else if (this.labelPosVertical == "center" && this.labelHeight > height) {
this.rect.y -= (this.labelHeight - height) / 2;
} else if (this.labelPos == "top") {
this.rect.y -= this.labelHeight - height;
this.setHeight(this.labelHeight);
} else if (this.labelPosVertical == "bottom") {
this.setHeight(height + this.labelHeight);
}
this.setHeight(this.labelHeight);
}
}
}
Expand Down
29 changes: 21 additions & 8 deletions src/LNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,32 @@ LNode.prototype.updateBounds = function () {
var width = childGraph.getRight() - childGraph.getLeft();
var height = childGraph.getBottom() - childGraph.getTop();

if(this.labelWidth > width){
this.rect.x -= (this.labelWidth - width) / 2;
this.setWidth(this.labelWidth);
if(this.labelWidth){
if(this.labelPosHorizontal == "left"){
this.rect.x -= (this.labelWidth);
this.setWidth(width + this.labelWidth);
}
else if(this.labelPosHorizontal == "center" && this.labelWidth > width){
this.rect.x -= (this.labelWidth - width) / 2;
this.setWidth(this.labelWidth);
}
else if(this.labelPosHorizontal == "right"){
this.setWidth(width + this.labelWidth);
}
}

if(this.labelHeight > height){
if(this.labelPos == "center"){
if(this.labelHeight){
if(this.labelPosVertical == "top"){
this.rect.y -= (this.labelHeight);
this.setHeight(height + this.labelHeight);
}
else if(this.labelPosVertical == "center" && this.labelHeight > height){
this.rect.y -= (this.labelHeight - height) / 2;
this.setHeight(this.labelHeight);
}
else if(this.labelPos == "top"){
this.rect.y -= (this.labelHeight - height);
else if(this.labelPosVertical == "bottom"){
this.setHeight(height + this.labelHeight);
}
this.setHeight(this.labelHeight);
}
}
}
Expand Down

0 comments on commit 3d9b690

Please sign in to comment.