SequenceDiagram

fun SequenceDiagram(    modifier: Modifier = Modifier,     style: SequenceDiagramStyle = SequenceDiagramStyle.Default,     content: SequenceDiagramScope.() -> Unit)

A composable that draws a sequence diagram. The diagram is specified inside the content function by a DSL defined by SequenceDiagramScope.

Sequence diagrams consist of vertical participants with lines and arrows between them showing a sequence of interactions. Inside content, participants are created via createParticipant. Lines between participants are specified by the lineTo function.

Diagrams can also be decorated with notes anchored to participants via the noteToStartOf, noteToEndOf, and noteOver functions. Notes can contain arbitrary composable content, but the Note composable is recommended for consistent styling.

Since diagrams have a very complex layout, this composable does not try to rearrange the diagram to fit in the incoming constraints if it does not fit. Instead, the entire diagram will be scaled down to fit the max constraints.

Samples

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import com.zachklipp.seqdiag.ArrowHeadType
import com.zachklipp.seqdiag.BasicSequenceDiagramStyle
import com.zachklipp.seqdiag.Label
import com.zachklipp.seqdiag.LineStyle
import com.zachklipp.seqdiag.Note
import com.zachklipp.seqdiag.SequenceDiagram
import com.zachklipp.seqdiag.arrowHeadType
import com.zachklipp.seqdiag.color
import com.zachklipp.seqdiag.createParticipant
import com.zachklipp.seqdiag.noteOver
fun main() { 
   //sampleStart 
   // In addition to lines, notes can also be placed around participants.
SequenceDiagram {
    val alice = createParticipant { Note("Alice") }
    createParticipant { Note("Bob") }
    val carlos = createParticipant { Note("Carlos") }

    noteToStartOf(alice) { Note("Note to the start of Alice") }
    noteOver(alice) { Note("Note over Alice") }
    noteToEndOf(alice) { Note("Note to the end of Alice") }

    noteOver(alice, carlos) { Note("Note over multiple participants") }
} 
   //sampleEnd
}
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import com.zachklipp.seqdiag.ArrowHeadType
import com.zachklipp.seqdiag.BasicSequenceDiagramStyle
import com.zachklipp.seqdiag.Label
import com.zachklipp.seqdiag.LineStyle
import com.zachklipp.seqdiag.Note
import com.zachklipp.seqdiag.SequenceDiagram
import com.zachklipp.seqdiag.arrowHeadType
import com.zachklipp.seqdiag.color
import com.zachklipp.seqdiag.createParticipant
import com.zachklipp.seqdiag.noteOver
fun main() { 
   //sampleStart 
   // Specifies a simple sequence diagram that consists of three participants with some lines
// between them.
SequenceDiagram {
    val alice = createParticipant { Note("Alice") }
    val bob = createParticipant { Note("Bob") }
    val carlos = createParticipant { Note("Carlos") }

    // Lines can be specified between any two participants, with their
    alice.lineTo(bob)
        .label { Label("Hello!") }
    bob.lineTo(carlos)
        .label { Label("Alice says hi") }

    // Lines don't need to have labels, and they can be styled.
    carlos.lineTo(bob)
        .color(Color.Blue)
        .arrowHeadType(ArrowHeadType.Outlined)

    // Lines can span multiple participants.
    carlos.lineTo(alice)
        .label { Label("Hello back!") }
} 
   //sampleEnd
}

Parameters

style

The default layout and drawing properties for the diagram. See the documentation on SequenceDiagramStyle for more information.

content

The function that specifies the contents of the diagram by calling methods on the SequenceDiagramScope receiver.

Sources

Link copied to clipboard