How to support rich text with automatic text wrapping in JointJS? #3139
-
IntroductionHi JointJS team, I have a question about text rendering in dia.Element regarding automatic text wrapping and styled text. Originally, my implementation was using textWrap only, because at that time:
export const GenericMarkup: dia.MarkupJSON = [
{
tagName: 'rect',
selector: 'body'
},
// titleText + bodyText
{
tagName: 'g',
selector: 'textGroup',
children: [
{
tagName: 'path',
selector: 'textGroupBg'
},
{
tagName: 'text',
selector: 'titleText'
},
{
tagName: 'text',
selector: 'bodyText',
}
]
}
];
// attr setting
bodyText: {
x: 'calc(w / 2)',
y: 44,
fontSize: 14,
fontWeight: 700,
text: e.bodyText ?? '',
textAnchor: 'middle',
dominantBaseline: 'auto',
textWrap: {
width: 'calc(w - 20)',
height: undefined,
preserveSpaces: true
},
displayEmpty: true,
lineHeight: 17,
fill: 'var(--theia-diagram-${typeName}-header-text-color)'
}Later, new requirements were introduced: Different parts of the same text need different styles i try to add children under bodyText like: {
tagName: 'text',
selector: 'bodyText',
children: []
}then set the children content: cell.attr('bodytext/children', buildBodyText())
export function buildBodyText(): dia.MarkupNodeJSON['children'] {
const children: dia.MarkupNodeJSON['children'] = [];
children.push({
tagName: 'tspan',
attributes: {
fontWeight: 'bold',
fill: '#cf7e7eff'
},
textContent: 'nameContent,nameContent.nameContent,nameContent,nameContent'
});
children.push({
tagName: 'tspan',
attributes: {
fontWeight: 'bold',
fill: '#6d7ff5ff'
},
textContent: 'nameryping'
});
return children;
}but it doesn't wrok. My question:
at the same time? Thanks for your help. Steps to reproduceNo response Restrictions & ConstraintsNo response Does your question relate to JointJS or JointJS+. Select both if applicable.JointJS |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
|
Hello! Currently our annotations functionality is not supported with text wrap enabled. To achieve your goal you should use foreignObject with styled html inside. Here is a tutorial on how to use foreign object inside of the JointJS shapes. |
Beta Was this translation helpful? Give feedback.


Hello! Currently our annotations functionality is not supported with text wrap enabled. To achieve your goal you should use foreignObject with styled html inside. Here is a tutorial on how to use foreign object inside of the JointJS shapes.