mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
Merge pull request #1511 from cmmoran/feature/1483_long_messages
Fixed config *font helpers
This commit is contained in:
commit
3365fa174d
@ -306,7 +306,7 @@ const config = {
|
||||
*/
|
||||
labelBoxHeight: 20,
|
||||
messageFont: () => {
|
||||
const c = getConfig();
|
||||
const c = getConfig().sequence;
|
||||
return {
|
||||
fontFamily: c.messageFontFamily,
|
||||
fontSize: c.messageFontSize,
|
||||
@ -314,7 +314,7 @@ const config = {
|
||||
};
|
||||
},
|
||||
noteFont: () => {
|
||||
const c = getConfig();
|
||||
const c = getConfig().sequence;
|
||||
return {
|
||||
fontFamily: c.noteFontFamily,
|
||||
fontSize: c.noteFontSize,
|
||||
@ -322,7 +322,7 @@ const config = {
|
||||
};
|
||||
},
|
||||
actorFont: () => {
|
||||
const c = getConfig();
|
||||
const c = getConfig().sequence;
|
||||
return {
|
||||
fontFamily: c.actorFontFamily,
|
||||
fontSize: c.actorFontSize,
|
||||
|
@ -290,7 +290,7 @@ const drawMessage = function(g, msgModel) {
|
||||
totalOffset} H ${startx}`
|
||||
);
|
||||
} else {
|
||||
totalOffset += 5;
|
||||
totalOffset += conf.boxMargin;
|
||||
|
||||
line = g
|
||||
.append('path')
|
||||
@ -459,6 +459,7 @@ function adjustLoopHeightForWrap(loopWidths, msg, preMargin, postMargin, addLoop
|
||||
bounds.bumpVerticalPos(preMargin);
|
||||
let heightAdjust = postMargin;
|
||||
if (msg.id && msg.message && loopWidths[msg.id]) {
|
||||
if (msg.wrap) {
|
||||
let loopWidth = loopWidths[msg.id].width;
|
||||
let textConf = conf.messageFont();
|
||||
msg.message = utils.wrapLabel(`[${msg.message}]`, loopWidth - 2 * conf.wrapPadding, textConf);
|
||||
@ -469,6 +470,9 @@ function adjustLoopHeightForWrap(loopWidths, msg, preMargin, postMargin, addLoop
|
||||
const totalOffset = textDims.height - conf.labelBoxHeight;
|
||||
heightAdjust = postMargin + totalOffset;
|
||||
logger.debug(`${totalOffset} - ${msg.message}`);
|
||||
} else {
|
||||
msg.message = `[${msg.message}]`;
|
||||
}
|
||||
}
|
||||
addLoopFn(msg);
|
||||
bounds.bumpVerticalPos(heightAdjust);
|
||||
@ -769,6 +773,16 @@ const getMaxMessageWidthPerActor = function(actors, messages) {
|
||||
maxMessageWidthPerActor[msg.from] || 0,
|
||||
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) {
|
||||
maxMessageWidthPerActor[msg.from] = Math.max(
|
||||
maxMessageWidthPerActor[msg.from] || 0,
|
||||
@ -949,8 +963,25 @@ const buildMessageModel = function(msg, actors) {
|
||||
const fromIdx = fromBounds[0] <= toBounds[0] ? 1 : 0;
|
||||
const toIdx = fromBounds[0] < toBounds[0] ? 0 : 1;
|
||||
const allBounds = fromBounds.concat(toBounds);
|
||||
const msgModel = {
|
||||
width: Math.abs(toBounds[toIdx] - fromBounds[fromIdx]),
|
||||
const boundedWidth = 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,
|
||||
startx: fromBounds[fromIdx],
|
||||
stopx: toBounds[toIdx],
|
||||
@ -962,14 +993,6 @@ const buildMessageModel = function(msg, actors) {
|
||||
fromBounds: Math.min.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) {
|
||||
@ -1052,10 +1075,13 @@ const calculateLoopBounds = function(messages, actors) {
|
||||
if (msgModel.startx === msgModel.stopx) {
|
||||
let from = actors[msg.from];
|
||||
let to = actors[msg.to];
|
||||
current.from = Math.min(from.x - from.width / 2, current.from);
|
||||
current.to = Math.max(to.x + from.width / 2, current.to);
|
||||
current.width =
|
||||
Math.max(current.width, Math.abs(current.to - current.from)) - conf.labelBoxWidth;
|
||||
current.from = Math.min(
|
||||
from.x - msgModel.width / 2,
|
||||
from.x - from.width / 2,
|
||||
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 {
|
||||
current.from = Math.min(msgModel.startx, current.from);
|
||||
current.to = Math.max(msgModel.stopx, current.to);
|
||||
|
@ -1,6 +1,4 @@
|
||||
import common from '../common/common';
|
||||
import utils from '../../utils';
|
||||
import { logger } from '../../logger';
|
||||
|
||||
export const drawRect = function(elem, rectData) {
|
||||
const rectElem = elem.append('rect');
|
||||
@ -323,11 +321,6 @@ export const drawLoop = function(elem, loopModel, labelText, conf) {
|
||||
txt.wrap = true;
|
||||
|
||||
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') {
|
||||
loopModel.sectionTitles.forEach(function(item, idx) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user