Skip to content

Commit

Permalink
fix(diagrams): [sequenceDiagram] remove unnecessary stroke in message…
Browse files Browse the repository at this point in the history
… text
  • Loading branch information
hikerpig committed Jan 5, 2024
1 parent cb39807 commit 7c91c61
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-steaks-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pintora/diagrams': patch
---

[sequenceDiagram] remove unnecessary stroke in message text
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ exports[`sequence-artist draw cross mark to 1`] = `
"fontFamily": "Source Code Pro, sans-serif",
"fontSize": 16,
"fontWeight": 400,
"stroke": "#3b4044",
"text": "Message",
"textAlign": "center",
"textBaseline": "top",
Expand Down Expand Up @@ -589,7 +588,6 @@ exports[`sequence-artist match example snapshot 1`] = `
"fontFamily": "Source Code Pro, sans-serif",
"fontSize": 16,
"fontWeight": 400,
"stroke": "#3b4044",
"text": "render this",
"textAlign": "center",
"textBaseline": "top",
Expand Down Expand Up @@ -654,7 +652,6 @@ exports[`sequence-artist match example snapshot 1`] = `
"fontFamily": "Source Code Pro, sans-serif",
"fontSize": 16,
"fontWeight": 400,
"stroke": "#3b4044",
"text": "Has input changed?",
"textAlign": "center",
"textBaseline": "top",
Expand Down Expand Up @@ -759,7 +756,6 @@ exports[`sequence-artist match example snapshot 1`] = `
"fontFamily": "Source Code Pro, sans-serif",
"fontSize": 16,
"fontWeight": 400,
"stroke": "#3b4044",
"text": "your figure here",
"textAlign": "center",
"textBaseline": "top",
Expand Down
16 changes: 12 additions & 4 deletions packages/pintora-diagrams/src/sequence/artist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class Model {
let boxInfo = this.boxInfos.get(id)
if (id) {
if (!boxInfo) {
const fontConfig = messageFont(conf)
const fontConfig = boxFont(conf)
boxInfo = {
width: 0,
actorMarks: [],
Expand Down Expand Up @@ -589,7 +589,7 @@ function adjustLoopSizeForWrap(
if (msg.id && msg.text && loopWidths[msg.id]) {
const loopMinWidth = model.loopMinWidths[msg.id] || 0
loopWidth = Math.max(loopWidths[msg.id].width, loopMinWidth)
const textConf = messageFont(conf)
const textConf = boxFont(conf)
msg.text = `[${msg.text}]`
msg.wrap = true

Expand All @@ -614,6 +614,15 @@ export const messageFont = (cnf: SequenceConf) => {
const actorFont = messageFont
const noteFont = messageFont

/** get box - such as loop and box - font config from conf */
export const boxFont = (cnf: SequenceConf) => {
return {
fontFamily: cnf.messageFontFamily,
fontSize: cnf.messageFontSize,
fontWeight: cnf.boxFontWeight || cnf.messageFontWeight,
}
}

function splitBreaks(text: string) {
return text.split('\n')
}
Expand All @@ -634,7 +643,6 @@ const drawMessage = function (msgModel: MessageModel): DrawResult<Group> {
textAlign: 'center',
textBaseline: 'top',
fill: conf.messageTextColor,
stroke: conf.messageTextColor,
}

// console.log('drawMessage', msgModel.text, msgModel.width, msgModel)
Expand Down Expand Up @@ -1059,7 +1067,7 @@ function drawParticipantBoxes(context: SequenceArtistContext) {
})
boxesGroup.children.push(rect)
if (participantBox.text) {
const fontConfig = messageFont(conf)
const fontConfig = boxFont(conf)
const textMark = makeMark('text', {
text: participantBox.text,
x: startx + width / 2,
Expand Down
5 changes: 5 additions & 0 deletions packages/pintora-diagrams/src/sequence/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export type SequenceConf = {
messageFontSize: number
messageFontWeight: MarkAttrs['fontWeight']
messageTextColor: string
/**
* font weight of box - such as loop and box
*/
boxFontWeight: MarkAttrs['fontWeight']
wrapPadding: number
labelBoxWidth: number
labelBoxHeight: number
Expand Down Expand Up @@ -64,6 +68,7 @@ export const defaultConfig: SequenceConf = {
messageFontFamily: DEFAULT_FONT_FAMILY,
messageFontWeight: 400,
messageTextColor: PALETTE.normalDark,
boxFontWeight: 700, // bold
wrapPadding: 10,
labelBoxWidth: 50,
labelBoxHeight: 20,
Expand Down

0 comments on commit 7c91c61

Please sign in to comment.