Skip to content

Commit

Permalink
ParentCell title longer than its width fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
moarsoarse committed May 31, 2024
1 parent d73a24b commit 31fa538
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/js/structurizr-diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -3684,7 +3684,9 @@ structurizr.ui.Diagram = function(id, diagramIsEditable, constructionCompleteCal
padding = { top: 20, right: 20, bottom: 50, left: 20 };
}

let metaDataWidth=0;
if (metadataText && metadataText.length > 0) {
metaDataWidth = calculateWidth(metadataText, fontSize);
padding.bottom = padding.bottom + fontSize + fontSize + metaDataFontSizeDifference;
} else {
padding.bottom = padding.bottom + fontSize;
Expand Down Expand Up @@ -3717,17 +3719,30 @@ structurizr.ui.Diagram = function(id, diagramIsEditable, constructionCompleteCal
bottom: padding.bottom,
left: padding.left
};

//find the width of title, i.e. icon+name/metadata
const iconWidth = parentCell._computedStyle.icon ? parentCell.attr('.structurizrIcon')['width'] : 0;
const nameWidth = calculateWidth(parentCell.attr('.structurizrName').text,fontSize);
const titleWidth = Math.max(nameWidth, metaDataWidth) + iconWidth;
const childrenWidth = maxX - minX;

let newWidth=padding.left + padding.right;
if (titleWidth > childrenWidth) {
//position so that children are centered
newWidth += titleWidth;
minX = minX - (titleWidth - childrenWidth)/2
} else {
newWidth+= childrenWidth;
}

var newWidth = maxX - minX + padding.left + padding.right;
var newHeight = maxY - minY + padding.top + padding.bottom;
var newX = minX - padding.left;
var newY = minY - padding.top;

var margin = 15;
var refX = (margin / newWidth);

if (parentCell._computedStyle.icon !== undefined) {
var iconWidth = parentCell.attr('.structurizrIcon')['width'];

if (iconWidth > 0) {
var iconHeight = parentCell.attr('.structurizrIcon')['height'];
parentCell.attr({
'.structurizrIcon': {
Expand Down

0 comments on commit 31fa538

Please sign in to comment.