mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
messageFont, noteFont, and actorFont getConfig() calls were not specifying the sequence object
take into account width of message over single actor for actors' max message width
This commit is contained in:
parent
083d0c90e2
commit
d42b95bab9
@ -306,7 +306,7 @@ const config = {
|
|||||||
*/
|
*/
|
||||||
labelBoxHeight: 20,
|
labelBoxHeight: 20,
|
||||||
messageFont: () => {
|
messageFont: () => {
|
||||||
const c = getConfig();
|
const c = getConfig().sequence;
|
||||||
return {
|
return {
|
||||||
fontFamily: c.messageFontFamily,
|
fontFamily: c.messageFontFamily,
|
||||||
fontSize: c.messageFontSize,
|
fontSize: c.messageFontSize,
|
||||||
@ -314,7 +314,7 @@ const config = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
noteFont: () => {
|
noteFont: () => {
|
||||||
const c = getConfig();
|
const c = getConfig().sequence;
|
||||||
return {
|
return {
|
||||||
fontFamily: c.noteFontFamily,
|
fontFamily: c.noteFontFamily,
|
||||||
fontSize: c.noteFontSize,
|
fontSize: c.noteFontSize,
|
||||||
@ -322,7 +322,7 @@ const config = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
actorFont: () => {
|
actorFont: () => {
|
||||||
const c = getConfig();
|
const c = getConfig().sequence;
|
||||||
return {
|
return {
|
||||||
fontFamily: c.actorFontFamily,
|
fontFamily: c.actorFontFamily,
|
||||||
fontSize: c.actorFontSize,
|
fontSize: c.actorFontSize,
|
||||||
|
@ -290,7 +290,7 @@ const drawMessage = function(g, msgModel) {
|
|||||||
totalOffset} H ${startx}`
|
totalOffset} H ${startx}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
totalOffset += 5;
|
totalOffset += conf.boxMargin;
|
||||||
|
|
||||||
line = g
|
line = g
|
||||||
.append('path')
|
.append('path')
|
||||||
@ -459,16 +459,20 @@ function adjustLoopHeightForWrap(loopWidths, msg, preMargin, postMargin, addLoop
|
|||||||
bounds.bumpVerticalPos(preMargin);
|
bounds.bumpVerticalPos(preMargin);
|
||||||
let heightAdjust = postMargin;
|
let heightAdjust = postMargin;
|
||||||
if (msg.id && msg.message && loopWidths[msg.id]) {
|
if (msg.id && msg.message && loopWidths[msg.id]) {
|
||||||
let loopWidth = loopWidths[msg.id].width;
|
if (msg.wrap) {
|
||||||
let textConf = conf.messageFont();
|
let loopWidth = loopWidths[msg.id].width;
|
||||||
msg.message = utils.wrapLabel(`[${msg.message}]`, loopWidth - 2 * conf.wrapPadding, textConf);
|
let textConf = conf.messageFont();
|
||||||
msg.width = loopWidth;
|
msg.message = utils.wrapLabel(`[${msg.message}]`, loopWidth - 2 * conf.wrapPadding, textConf);
|
||||||
|
msg.width = loopWidth;
|
||||||
|
|
||||||
// const lines = msg.message.split(common.lineBreakRegex).length;
|
// const lines = msg.message.split(common.lineBreakRegex).length;
|
||||||
const textDims = utils.calculateTextDimensions(msg.message, textConf);
|
const textDims = utils.calculateTextDimensions(msg.message, textConf);
|
||||||
const totalOffset = textDims.height - conf.labelBoxHeight;
|
const totalOffset = textDims.height - conf.labelBoxHeight;
|
||||||
heightAdjust = postMargin + totalOffset;
|
heightAdjust = postMargin + totalOffset;
|
||||||
logger.debug(`${totalOffset} - ${msg.message}`);
|
logger.debug(`${totalOffset} - ${msg.message}`);
|
||||||
|
} else {
|
||||||
|
msg.message = `[${msg.message}]`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addLoopFn(msg);
|
addLoopFn(msg);
|
||||||
bounds.bumpVerticalPos(heightAdjust);
|
bounds.bumpVerticalPos(heightAdjust);
|
||||||
@ -769,6 +773,16 @@ const getMaxMessageWidthPerActor = function(actors, messages) {
|
|||||||
maxMessageWidthPerActor[msg.from] || 0,
|
maxMessageWidthPerActor[msg.from] || 0,
|
||||||
messageWidth
|
messageWidth
|
||||||
);
|
);
|
||||||
|
} else if (isMessage && msg.from === msg.to) {
|
||||||
|
maxMessageWidthPerActor[msg.from] = Math.max(
|
||||||
|
maxMessageWidthPerActor[msg.from] || 0,
|
||||||
|
messageWidth / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
maxMessageWidthPerActor[msg.to] = Math.max(
|
||||||
|
maxMessageWidthPerActor[msg.to] || 0,
|
||||||
|
messageWidth / 2
|
||||||
|
);
|
||||||
} else if (msg.placement === parser.yy.PLACEMENT.RIGHTOF) {
|
} else if (msg.placement === parser.yy.PLACEMENT.RIGHTOF) {
|
||||||
maxMessageWidthPerActor[msg.from] = Math.max(
|
maxMessageWidthPerActor[msg.from] = Math.max(
|
||||||
maxMessageWidthPerActor[msg.from] || 0,
|
maxMessageWidthPerActor[msg.from] || 0,
|
||||||
@ -949,8 +963,25 @@ const buildMessageModel = function(msg, actors) {
|
|||||||
const fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0;
|
const fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0;
|
||||||
const toIdx = fromBounds[0] < toBounds[0] ? 0 : 1;
|
const toIdx = fromBounds[0] < toBounds[0] ? 0 : 1;
|
||||||
const allBounds = fromBounds.concat(toBounds);
|
const allBounds = fromBounds.concat(toBounds);
|
||||||
const msgModel = {
|
const boundedWidth = Math.abs(toBounds[toIdx] - fromBounds[fromIdx]);
|
||||||
width: Math.abs(toBounds[toIdx] - fromBounds[fromIdx]),
|
const msgDims = utils.calculateTextDimensions(msg.message, conf.messageFont());
|
||||||
|
if (msg.wrap && msg.message && !common.lineBreakRegex.test(msg.message)) {
|
||||||
|
msg.message = utils.wrapLabel(
|
||||||
|
msg.message,
|
||||||
|
Math.max(
|
||||||
|
msgDims.width + 2 * conf.wrapPadding,
|
||||||
|
boundedWidth - 2 * conf.wrapPadding,
|
||||||
|
conf.width
|
||||||
|
),
|
||||||
|
conf.messageFont()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
width: Math.max(
|
||||||
|
msgDims.width + 2 * conf.wrapPadding,
|
||||||
|
boundedWidth - 2 * conf.wrapPadding,
|
||||||
|
conf.width
|
||||||
|
),
|
||||||
height: 0,
|
height: 0,
|
||||||
startx: fromBounds[fromIdx],
|
startx: fromBounds[fromIdx],
|
||||||
stopx: toBounds[toIdx],
|
stopx: toBounds[toIdx],
|
||||||
@ -962,14 +993,6 @@ const buildMessageModel = function(msg, actors) {
|
|||||||
fromBounds: Math.min.apply(null, allBounds),
|
fromBounds: Math.min.apply(null, allBounds),
|
||||||
toBounds: Math.max.apply(null, allBounds)
|
toBounds: Math.max.apply(null, allBounds)
|
||||||
};
|
};
|
||||||
if (msg.wrap && msg.message && !common.lineBreakRegex.test(msg.message)) {
|
|
||||||
msgModel.message = utils.wrapLabel(
|
|
||||||
msg.message,
|
|
||||||
Math.max(msgModel.width - 2 * conf.wrapPadding, conf.width),
|
|
||||||
conf.messageFont()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return msgModel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const calculateLoopBounds = function(messages, actors) {
|
const calculateLoopBounds = function(messages, actors) {
|
||||||
@ -1052,10 +1075,13 @@ const calculateLoopBounds = function(messages, actors) {
|
|||||||
if (msgModel.startx === msgModel.stopx) {
|
if (msgModel.startx === msgModel.stopx) {
|
||||||
let from = actors[msg.from];
|
let from = actors[msg.from];
|
||||||
let to = actors[msg.to];
|
let to = actors[msg.to];
|
||||||
current.from = Math.min(from.x - from.width / 2, current.from);
|
current.from = Math.min(
|
||||||
current.to = Math.max(to.x + from.width / 2, current.to);
|
from.x - msgModel.width / 2,
|
||||||
current.width =
|
from.x - from.width / 2,
|
||||||
Math.max(current.width, Math.abs(current.to - current.from)) - conf.labelBoxWidth;
|
current.from
|
||||||
|
);
|
||||||
|
current.to = Math.max(to.x + msgModel.width / 2, to.x + from.width / 2, current.to);
|
||||||
|
current.width = Math.max(current.width, Math.abs(current.to - current.from));
|
||||||
} else {
|
} else {
|
||||||
current.from = Math.min(msgModel.startx, current.from);
|
current.from = Math.min(msgModel.startx, current.from);
|
||||||
current.to = Math.max(msgModel.stopx, current.to);
|
current.to = Math.max(msgModel.stopx, current.to);
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import common from '../common/common';
|
import common from '../common/common';
|
||||||
import utils from '../../utils';
|
|
||||||
import { logger } from '../../logger';
|
|
||||||
|
|
||||||
export const drawRect = function(elem, rectData) {
|
export const drawRect = function(elem, rectData) {
|
||||||
const rectElem = elem.append('rect');
|
const rectElem = elem.append('rect');
|
||||||
@ -323,11 +321,6 @@ export const drawLoop = function(elem, loopModel, labelText, conf) {
|
|||||||
txt.wrap = true;
|
txt.wrap = true;
|
||||||
|
|
||||||
let textElem = drawText(g, txt);
|
let textElem = drawText(g, txt);
|
||||||
let textHeight = Math.round(
|
|
||||||
textElem.map(te => (te._groups || te)[0][0].getBBox().height).reduce((acc, curr) => acc + curr)
|
|
||||||
);
|
|
||||||
const textDims = utils.calculateTextDimensions(txt.text, txt);
|
|
||||||
logger.debug(`loop: ${textHeight} vs ${textDims.height} ${txt.text}`, textDims);
|
|
||||||
|
|
||||||
if (typeof loopModel.sectionTitles !== 'undefined') {
|
if (typeof loopModel.sectionTitles !== 'undefined') {
|
||||||
loopModel.sectionTitles.forEach(function(item, idx) {
|
loopModel.sectionTitles.forEach(function(item, idx) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user