mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-10-31 02:44:17 +01:00 
			
		
		
		
	#1033 Better handling of multiline notes
This commit is contained in:
		| @@ -7,13 +7,14 @@ describe('State diagram', () => { | |||||||
|       ` |       ` | ||||||
|     stateDiagram |     stateDiagram | ||||||
|     State1: The state with a note |     State1: The state with a note | ||||||
|  |     note right of State1 | ||||||
|  |       Important information! You\ncan write | ||||||
|  |       notes with multiple lines... | ||||||
|  |       Here is another line... | ||||||
|  |       And another line... | ||||||
|  |     end note | ||||||
|     `, |     `, | ||||||
|       {} |       {} | ||||||
|     ); |     ); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|     // note right of State1 |  | ||||||
|     //   Important information! You\ncan write |  | ||||||
|     //   notes with multiple lines... |  | ||||||
|     //   Here is another line... |  | ||||||
|     // end note |  | ||||||
|   | |||||||
| @@ -272,17 +272,22 @@ const _drawLongText = (_text, x, y, g) => { | |||||||
|   let text = _text.replace(/\r\n/g, '<br/>'); |   let text = _text.replace(/\r\n/g, '<br/>'); | ||||||
|   text = text.replace(/\n/g, '<br/>'); |   text = text.replace(/\n/g, '<br/>'); | ||||||
|   const lines = text.split(/<br\/?>/gi); |   const lines = text.split(/<br\/?>/gi); | ||||||
|  |  | ||||||
|  |   let tHeight = 1.25 * getConfig().state.noteMargin; | ||||||
|   for (const line of lines) { |   for (const line of lines) { | ||||||
|     const txt = line.trim(); |     const txt = line.trim(); | ||||||
|  |  | ||||||
|     if (txt.length > 0) { |     if (txt.length > 0) { | ||||||
|       const span = textElem.append('tspan'); |       const span = textElem.append('tspan'); | ||||||
|       span.text(txt); |       span.text(txt); | ||||||
|  |       if (tHeight === 0) { | ||||||
|         const textBounds = span.node().getBBox(); |         const textBounds = span.node().getBBox(); | ||||||
|       textHeight += textBounds.height; |         tHeight += textBounds.height; | ||||||
|  |       } | ||||||
|  |       // console.warn('textBounds', textBounds); | ||||||
|  |       textHeight += tHeight; | ||||||
|       span.attr('x', x + getConfig().state.noteMargin); |       span.attr('x', x + getConfig().state.noteMargin); | ||||||
|       span.attr('y', y + textHeight + 1.25 * getConfig().state.noteMargin); |       span.attr('y', y + textHeight + 1.25 * getConfig().state.noteMargin); | ||||||
|       // textWidth = Math.max(textBounds.width, textWidth); |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   return { textWidth: textElem.node().getBBox().width, textHeight }; |   return { textWidth: textElem.node().getBBox().width, textHeight }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Knut Sveidqvist
					Knut Sveidqvist