mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 08:50:13 +02:00
render node property borders
of rect
node
This commit is contained in:
@@ -313,6 +313,8 @@ const rect = (parent, node) => {
|
|||||||
// add the rect
|
// add the rect
|
||||||
const rect = shapeSvg.insert('rect', ':first-child');
|
const rect = shapeSvg.insert('rect', ':first-child');
|
||||||
|
|
||||||
|
const totalWidth = bbox.width + node.padding;
|
||||||
|
const totalHeight = bbox.height + node.padding;
|
||||||
rect
|
rect
|
||||||
.attr('class', 'basic label-container')
|
.attr('class', 'basic label-container')
|
||||||
.attr('style', node.style)
|
.attr('style', node.style)
|
||||||
@@ -320,8 +322,12 @@ const rect = (parent, node) => {
|
|||||||
.attr('ry', node.ry)
|
.attr('ry', node.ry)
|
||||||
.attr('x', -bbox.width / 2 - halfPadding)
|
.attr('x', -bbox.width / 2 - halfPadding)
|
||||||
.attr('y', -bbox.height / 2 - halfPadding)
|
.attr('y', -bbox.height / 2 - halfPadding)
|
||||||
.attr('width', bbox.width + node.padding)
|
.attr('width', totalWidth)
|
||||||
.attr('height', bbox.height + node.padding);
|
.attr('height', totalHeight);
|
||||||
|
// TODO warn if unknown property is given
|
||||||
|
if (node.props?.borders) {
|
||||||
|
applyNodePropertyBorders(rect, node.props.borders, totalWidth, totalHeight);
|
||||||
|
}
|
||||||
|
|
||||||
updateNodeBounds(node, rect);
|
updateNodeBounds(node, rect);
|
||||||
|
|
||||||
@@ -332,6 +338,43 @@ const rect = (parent, node) => {
|
|||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function applyNodePropertyBorders(rect, borders, totalWidth, totalHeight) {
|
||||||
|
const strokeDashArray = [];
|
||||||
|
const addBorder = (length) => {
|
||||||
|
strokeDashArray.push(length);
|
||||||
|
strokeDashArray.push(0);
|
||||||
|
};
|
||||||
|
const skipBorder = (length) => {
|
||||||
|
strokeDashArray.push(0);
|
||||||
|
strokeDashArray.push(length);
|
||||||
|
};
|
||||||
|
if (borders.includes('t')) {
|
||||||
|
log.debug('add top border');
|
||||||
|
addBorder(totalWidth);
|
||||||
|
} else {
|
||||||
|
skipBorder(totalWidth);
|
||||||
|
}
|
||||||
|
if (borders.includes('r')) {
|
||||||
|
log.debug('add right border');
|
||||||
|
addBorder(totalHeight);
|
||||||
|
} else {
|
||||||
|
skipBorder(totalHeight);
|
||||||
|
}
|
||||||
|
if (borders.includes('b')) {
|
||||||
|
log.debug('add bottom border');
|
||||||
|
addBorder(totalWidth);
|
||||||
|
} else {
|
||||||
|
skipBorder(totalWidth);
|
||||||
|
}
|
||||||
|
if (borders.includes('l')) {
|
||||||
|
log.debug('add left border');
|
||||||
|
addBorder(totalHeight);
|
||||||
|
} else {
|
||||||
|
skipBorder(totalHeight);
|
||||||
|
}
|
||||||
|
rect.attr('stroke-dasharray', strokeDashArray.join(' '));
|
||||||
|
}
|
||||||
|
|
||||||
const rectWithTitle = (parent, node) => {
|
const rectWithTitle = (parent, node) => {
|
||||||
// const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes);
|
// const { shapeSvg, bbox, halfPadding } = labelHelper(parent, node, 'node ' + node.classes);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user