Skip to content

Commit

Permalink
Adjust Fragment width according to simple assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCoder committed Nov 8, 2024
1 parent 6321863 commit ac2aadc
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,4 @@ export default {
* {
border-color: inherit;
}
.fragment {
min-width: 200px;
}
</style>
17 changes: 9 additions & 8 deletions src/components/DiagramFrame/SeqDiagram/WidthOfContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export function TotalWidth(ctx: any, coordinates: Coordinates) {
coordinates,
);

return Math.max(
return (
coordinates.distance(leftParticipant, rightParticipant) +
border.left +
border.right +
coordinates.half(leftParticipant) +
coordinates.half(rightParticipant) +
extraWidth,
350,
border.left +
border.right +
coordinates.half(leftParticipant) +
coordinates.half(rightParticipant) +
extraWidth
);
}

Expand All @@ -42,15 +41,17 @@ function extraWidthDueToSelfMessage(
coordinates: Coordinates,
) {
const allMessages = AllMessages(ctx);
console.log("allMessages", allMessages);
const widths = allMessages
.filter((m) => m.from === m.to)
// 37 is arrow width (30) + half occurrence width(7)
.map(
(s) =>
WidthProviderOnBrowser(s.signature, TextType.MessageContent) +
WidthProviderOnBrowser(s.label, TextType.MessageContent) +
37 -
coordinates.distance(s.from, rightParticipant) -
coordinates.half(rightParticipant),
);
console.debug("extraWidthDueToSelfMessage", widths);
return Math.max.apply(null, [0, ...widths]);
}
32 changes: 32 additions & 0 deletions src/parser/MessageLabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// The label in the rendered diagram.
// `a->b.label`: `label`.
// `a->b.label()`: `label`.
// `a=b()`: `b`. Invocation.
// `a=b`: `a=b`. Simple assignment.
// `new A`: `«create»`.
// `new A(1)`: `«1»`.

import sequenceParser from "../generated-parser/sequenceParser";

const seqParser = sequenceParser;
const MessageContext = seqParser.MessageContext;
const AsyncMessageContext = seqParser.AsyncMessageContext;
const CreationContext = seqParser.CreationContext;

// @ts-ignore
MessageContext.prototype.Label = function () {
// @ts-ignore
if (this.isSimpleAssignment()) {
// @ts-ignore
return this.Assignment()?.getLabel() + "=" + this.SignatureText();
}
// @ts-ignore
return this.SignatureText();
};

// @ts-ignore
AsyncMessageContext.prototype.Label =
AsyncMessageContext.prototype.SignatureText;

// @ts-ignore
CreationContext.prototype.Label = CreationContext.prototype.SignatureText;
1 change: 1 addition & 0 deletions src/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "./RefContext";
import "./Origin";
import "./Divider/DividerContext";
import "./SignatureText";
import "./MessageLabel";
import "./Messages/MessageContext";
import "./From";
import "./key/Key";
Expand Down
9 changes: 4 additions & 5 deletions src/positioning/MessageContextListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ export class MessageContextListener extends sequenceParserListener {
if (this.isBlind) {
return;
}
const from = ctx.From();
const owner = ctx?.Owner();
const signature = ctx?.SignatureText();
this.ownableMessages.push({
from: from,
signature: signature,
from: ctx.From(),
signature: ctx?.SignatureText(),
label: ctx?.Label(),
type,
to: owner,
to: owner || ctx.From(),
});
};

Expand Down
8 changes: 8 additions & 0 deletions src/positioning/OwnableMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ export interface OwnableMessage {
from: string;
to: string;
signature: string;
// The label in the rendered diagram.
// `a->b.label`: `label`.
// `a->b.label()`: `label`.
// `a=b()`: `b`. Invocation.
// `a=b`: `a=b`. Simple assignment.
// `new A`: `«create»`.
// `new A(1)`: `«1»`.
label: string;
type: OwnableMessageType;
}

0 comments on commit ac2aadc

Please sign in to comment.