Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
49190cf
feat: cherry-picked from 1513-resize-external-labels
timonlazarviadee Jul 23, 2025
844c64d
feat: height of labels sticks to the text height
timonlazarviadee Jul 30, 2025
5c6d5b6
feat: corrected behavior for TextAnnotations
timonlazarviadee Aug 19, 2025
da1f406
feat: fixed the tests because of the new behavior
timonlazarviadee Aug 19, 2025
d83810b
style: removed unused import and beautified code
timonlazarviadee Aug 26, 2025
2943e1f
Merge remote-tracking branch 'origin/develop' into 1513-dynamic-resiz…
timonlazarviadee Aug 26, 2025
9654edb
Allow copying in ModdleCopy.js
timKraeuter Sep 17, 2025
ef75e4e
Implement copying and add test
timKraeuter Sep 18, 2025
86dd5ce
chore: update github/codeql-action action to v4
renovate[bot] Oct 8, 2025
d604e3b
chore: update actions/setup-node action to v6
renovate[bot] Oct 15, 2025
8e98782
fix: stabilized label rendering
timonlazarviadee Oct 20, 2025
092b2d0
fix: linting errors
timonlazarviadee Oct 20, 2025
440ac37
Merge remote-tracking branch 'origin/develop' into 1513-dynamic-resiz…
timonlazarviadee Oct 20, 2025
5101ece
chore: refactored label resizing
timonlazarviadee Oct 27, 2025
aacabe5
Merge branch 'bpmn-io:develop' into develop
timonlazarviadee Oct 28, 2025
7d6105a
Merge branch 'bpmn-io:develop' into develop
timonlazarviadee Nov 17, 2025
93bc9b9
fix: deleted unecessary function
timonlazarviadee Nov 17, 2025
64900c3
Merge remote-tracking branch 'origin/develop' into 1513-dynamic-resiz…
timonlazarviadee Nov 17, 2025
f690e25
fix: fixed pipeline and corrected behavior
timonlazarviadee Dec 16, 2025
9bff096
fix: added new test for resizing TextAnnotations
timonlazarviadee Dec 22, 2025
e497038
fix: added test for textannotation
timonlazarviadee Jan 12, 2026
2f393e8
fix: corrected test expectations
timonlazarviadee Jan 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 86 additions & 17 deletions lib/draw/BpmnRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
import Ids from 'ids';

import { black } from './BpmnRenderUtil';
import { measureTextLines } from '../features/modeling/BpmnUpdater';

var markerIds = new Ids();

Expand Down Expand Up @@ -1037,10 +1038,12 @@ export default function BpmnRenderer(
}

function renderLabel(parentGfx, label, attrs = {}) {

// additional Padding for left and right to stabilize the rendering
attrs = assign({
size: {
width: 100
}
},
}, attrs);

var text = textRenderer.createText(label || '', attrs);
Expand Down Expand Up @@ -1074,15 +1077,21 @@ export default function BpmnRenderer(

function renderExternalLabel(parentGfx, element, attrs = {}) {
var box = {
width: 90,
height: 30,
width: element.width,
height: element.height,
x: element.width / 2 + element.x,
y: element.height / 2 + element.y
};

return renderLabel(parentGfx, getLabel(element), {
box: box,
fitBox: true,
padding: {
top: 0,
left: -2,
right: -2,
bottom: 0
},
style: assign(
{},
textRenderer.getExternalStyle(),
Expand Down Expand Up @@ -2164,6 +2173,10 @@ export default function BpmnRenderer(
return renderTask(parentGfx, element, attrs);
},
'bpmn:TextAnnotation': function(parentGfx, element, attrs = {}) {
if (element.correctBounds) {
changeBounds(element.correctBounds, element);
element.correctBounds = undefined;
}
attrs = pickAttrs(attrs, [
'fill',
'stroke',
Expand All @@ -2175,12 +2188,34 @@ export default function BpmnRenderer(
width,
height
} = getBounds(element, attrs);

width = Math.ceil(width / 20) * 20;
var textElement = drawRect(parentGfx, width, height, 0, 0, {
fill: 'none',
stroke: 'none'
});

var semantic = getSemantic(element),
text = semantic.get('text') || '';
var renderedLabel = renderLabel(parentGfx, text, {
align: 'left-top',
box: getBounds(element, attrs),
padding: {
top: 2,
left: +2,
right: +5,
bottom: 0
},
style: {
fill: getLabelColor(element, defaultLabelColor, defaultStrokeColor, attrs.stroke)
}
});

height = getTextHeightForTextAnnotation(renderedLabel);
textElement.setAttribute('height', height);
width = getTextWidthForTextAnnotation(renderedLabel, width);
element.width = width;
textElement.setAttribute('width', width);

var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
xScaleFactor: 1,
yScaleFactor: 1,
Expand All @@ -2195,19 +2230,6 @@ export default function BpmnRenderer(
drawPath(parentGfx, textPathData, {
stroke: getStrokeColor(element, defaultStrokeColor, attrs.stroke)
});

var semantic = getSemantic(element),
text = semantic.get('text') || '';

renderLabel(parentGfx, text, {
align: 'left-top',
box: getBounds(element, attrs),
padding: 7,
style: {
fill: getLabelColor(element, defaultLabelColor, defaultStrokeColor, attrs.stroke)
}
});

return textElement;
},
'bpmn:Transaction': function(parentGfx, element, attrs = {}) {
Expand Down Expand Up @@ -2305,6 +2327,11 @@ export default function BpmnRenderer(
return task;
},
'label': function(parentGfx, element, attrs = {}) {
if (element.correctBounds) {
changeBounds(element.correctBounds, element);
element.correctBounds = undefined;
}

return renderExternalLabel(parentGfx, element, attrs);
}
};
Expand Down Expand Up @@ -2410,4 +2437,46 @@ function pickAttrs(attrs, keys = []) {

return pickedAttrs;
}, {});
}

function changeBounds(newBounds, element) {
element.x = newBounds.x;
element.y = newBounds.y;
element.width = newBounds.width;
element.height = newBounds.height;
}


function getTextHeightForTextAnnotation(text) {
return Math.max(text.lastChild.y.animVal[0].value, 30) + 10;
}

function getTextWidthForTextAnnotation(text, width) {

if ((text.textContent === '')) {
return 100;
}

let lineLengths = Array.from(measureTextLines(text.textContent, getStyleFromTextannotation(text), width + 5, true))
.map(elem => elem.width);

return Math.round(Math.max(...lineLengths));
}

function getStyleFromTextannotation(text) {
const styleString = text.attributes.style.nodeValue;

let style = Object.fromEntries(
styleString
.split(';')
.map(part => part.trim())
.filter(Boolean)
.map(part => {
const [ key, value ] = part.split(':').map(s => s.trim());
return [ key, value ];
})
);
style['lineHeight'] = text.attributes.lineHeight.nodeValue;

return style;
}
8 changes: 5 additions & 3 deletions lib/features/label-editing/LabelEditingProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ LabelEditingProvider.prototype.activate = function(element) {
// external labels
if (isLabelExternal(element)) {
assign(options, {
autoResize: true
resizable: true,
autoResize: true,
});

// keep background and border for external labels
Expand Down Expand Up @@ -393,7 +394,8 @@ LabelEditingProvider.prototype.getEditingBBox = function(element) {
});
}

var width = 90 * zoom,
// making sure that editing box is correct
var width = bbox.width + 10 * zoom,
paddingTop = 7 * zoom,
paddingBottom = 4 * zoom;

Expand All @@ -402,7 +404,7 @@ LabelEditingProvider.prototype.getEditingBBox = function(element) {
assign(bounds, {
width: width,
height: bbox.height + paddingTop + paddingBottom,
x: mid.x - width / 2,
x: bbox.x,
y: bbox.y - paddingTop
});

Expand Down
Loading