Skip to content

Instantly share code, notes, and snippets.

@maxandersen
Created March 15, 2021 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxandersen/134765925c450c047f34b67a759248ee to your computer and use it in GitHub Desktop.
Save maxandersen/134765925c450c047f34b67a759248ee to your computer and use it in GitHub Desktop.
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS org.diagramsascode:diagramsascode-image:0.1.2
import java.io.File;
import java.io.IOException;
import org.diagramsascode.core.Diagram;
import org.diagramsascode.image.SequenceDiagramImage;
import org.diagramsascode.sequence.constraint.SequenceDiagramConstraints;
import org.diagramsascode.sequence.edge.Message;
import org.diagramsascode.sequence.node.Participant;
class diagrams {
public static void main(String[] args) throws IOException {
// Create the participants (that exchange messages)
Participant participant1 = new Participant("Client");
Participant participant2 = new Participant("Server");
// Create the request and response message
Message message1 = new Message(participant1, participant2, "Request Message");
Message message2 = new Message(participant2, participant1, "Response Message");
// Build the diagram
Diagram diagram = Diagram.builder()
.withNodes(participant1, participant2)
.withEdges(message1, message2)
.withConstraints(new SequenceDiagramConstraints())
.build();
// Create the image of the diagram and write it to a PNG file.
File outputFile = File.createTempFile("sequence", ".png");
SequenceDiagramImage.of(diagram).writeToPngFile(outputFile);
System.out.println("Sequence diagram written to: " + outputFile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment