Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] refactor: make sequence/svgDraw typesafe #5484

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
13 changes: 13 additions & 0 deletions demos/sequence.html
Expand Up @@ -238,6 +238,19 @@ <h1>Sequence diagram demos</h1>
Alice-xJohn: Hello John, how are you?
John--xAlice: Great!
</pre>
<pre class="mermaid">
sequenceDiagram
Alice->>Bob: Hello Bob, how are you ?
Bob->>Alice: Fine, thank you. And you?
create participant Carl
Alice->>Carl: Hi Carl!
create actor D as Donald
Carl->>D: Hi!
destroy Carl
Alice-xCarl: We are too many
destroy Bob
Bob->>Alice: I agree
</pre>
<script type="module">
import mermaid from './mermaid.esm.mjs';
mermaid.initialize({
Expand Down
18 changes: 12 additions & 6 deletions packages/mermaid/src/diagrams/common/commonTypes.ts
@@ -1,3 +1,5 @@
import type { SVG } from '../../diagram-api/types';

Check failure on line 1 in packages/mermaid/src/diagrams/common/commonTypes.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean '../../diagram-api/types.js'?

export interface RectData {
x: number;
y: number;
Expand All @@ -21,6 +23,7 @@
stopy: number;
fill: string;
stroke: string;
anchored: SVG;
}

export interface TextData {
Expand All @@ -32,20 +35,23 @@
class?: string;
}

export interface TextObject {
x: number;
y: number;
export interface TextObject extends TextData {
dy?: string;
width: number;
height: number;
fill?: string;
anchor?: string;
'text-anchor': string;
style: string;
textMargin: number;
rx: number;
ry: number;
tspan: boolean;
valign?: string;
valign: string;
dominantBaseline: string;
alignmentBaseline: string;
fontSize?: string | number;
fontWeight?: string | number;
fontFamily?: string;
wrap?: boolean;
}

export type D3RectElement = d3.Selection<SVGRectElement, unknown, Element | null, unknown>;
Expand Down
5 changes: 5 additions & 0 deletions packages/mermaid/src/diagrams/common/svgDrawCommon.ts
Expand Up @@ -124,6 +124,11 @@ export const getTextObj = (): TextObject => {
rx: 0,
ry: 0,
tspan: true,
dominantBaseline: 'auto',
alignmentBaseline: 'auto',
text: '',
anchor: 'start',
valign: 'middle',
};
return testObject;
};
8 changes: 1 addition & 7 deletions packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts
Expand Up @@ -831,13 +831,7 @@ export const draw = async function (_text: string, id: string, _version: string,
activationData.starty = verticalPos - 6;
verticalPos += 12;
}
svgDraw.drawActivation(
diagram,
activationData,
verticalPos,
conf,
actorActivations(msg.from.actor).length
);
svgDraw.drawActivation(activationData, verticalPos, actorActivations(msg.from.actor).length);

bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos);
}
Expand Down