Skip to content

Commit 6650efc

Browse files
committed
fix: Note position
1 parent a4754ad commit 6650efc

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

packages/mermaid/src/diagrams/state/dataFetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export const dataFetcher = (
355355
let from = itemId;
356356
let to = noteData.id;
357357

358-
if (parsedItem.note.position === 'left_of') {
358+
if (parsedItem.note.position === 'left of') {
359359
from = noteData.id;
360360
to = itemId;
361361
}

packages/mermaid/src/diagrams/state/stateDb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface RootStmt {
9090
}
9191

9292
interface Note {
93-
position?: 'left_of' | 'right_of';
93+
position?: 'left of' | 'right of';
9494
text: string;
9595
}
9696

packages/mermaid/src/diagrams/state/stateDiagram-v2.spec.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { StateDB } from './stateDb.js';
44
describe('state diagram V2, ', function () {
55
// TODO - these examples should be put into ./parser/stateDiagram.spec.js
66
describe('when parsing an info graph it', function () {
7+
/** @type {StateDB} */
78
let stateDb;
89
beforeEach(function () {
910
stateDb = new StateDB(2);
@@ -346,6 +347,20 @@ describe('state diagram V2, ', function () {
346347
`;
347348

348349
parser.parse(str);
350+
expect(stateDb.getState('Active').note).toMatchInlineSnapshot(`
351+
{
352+
"position": "left of",
353+
"text": "this is a short<br>note",
354+
}
355+
`);
356+
expect(stateDb.getState('Inactive').note).toMatchInlineSnapshot(`
357+
{
358+
"position": "right of",
359+
"text": "A note can also
360+
be defined on
361+
several lines",
362+
}
363+
`);
349364
});
350365
it('should handle multiline notes with different line breaks', function () {
351366
const str = `stateDiagram-v2
@@ -356,6 +371,12 @@ describe('state diagram V2, ', function () {
356371
`;
357372

358373
parser.parse(str);
374+
expect(stateDb.getStates().get('State1').note).toMatchInlineSnapshot(`
375+
{
376+
"position": "right of",
377+
"text": "Line1<br>Line2<br>Line3<br>Line4<br>Line5",
378+
}
379+
`);
359380
});
360381
it('should handle floating notes', function () {
361382
const str = `stateDiagram-v2
@@ -366,15 +387,14 @@ describe('state diagram V2, ', function () {
366387
parser.parse(str);
367388
});
368389
it('should handle floating notes', function () {
369-
const str = `stateDiagram-v2\n
390+
const str = `stateDiagram-v2
370391
state foo
371392
note "This is a floating note" as N1
372393
`;
373-
374394
parser.parse(str);
375395
});
376396
it('should handle notes for composite (nested) states', function () {
377-
const str = `stateDiagram-v2\n
397+
const str = `stateDiagram-v2
378398
[*] --> NotShooting
379399
380400
state "Not Shooting State" as NotShooting {
@@ -389,6 +409,12 @@ describe('state diagram V2, ', function () {
389409
`;
390410

391411
parser.parse(str);
412+
expect(stateDb.getState('NotShooting').note).toMatchInlineSnapshot(`
413+
{
414+
"position": "right of",
415+
"text": "This is a note on a composite state",
416+
}
417+
`);
392418
});
393419

394420
it('A composite state should be able to link to itself', () => {

0 commit comments

Comments
 (0)