Pantrix UI

Graph

Nodes and the links between them, laid out by the graph itself, on a ground that is moved and looked at closer by hand: a document's structure, an organisation, what depends on what.

import com.pantrixui.components.data.graph.PantrixGraph

Examples

A document's structure

An order's structure, each object and array a card: its name and its count in its head, its values of one line in its rows. An object or an array inside it is a card of its own, linked to it by its key or its index. The chosen card's head is filled; the level buttons open the cards with expandedToLevel, and a card's chevron closes it.

var chosen by remember { mutableStateOf("customer") }
var open by remember { mutableStateOf(expandedToLevel(ORDER_NODES, ORDER_LINKS, level = 3)) }
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
    PantrixButtonGroup(
        buttons = LEVELS.map { (name, level) ->
            GroupButton(
                text = name,
                onClick = { open = expandedToLevel(ORDER_NODES, ORDER_LINKS, level) },
                tagKey = "level_$name"
            )
        },
        size = ButtonSize.Small
    )
    PantrixGraph(
        nodes = ORDER_NODES,
        links = ORDER_LINKS,
        modifier = Modifier.fillMaxWidth().height(420.dp),
        selectedKey = chosen,
        onSelect = { chosen = it },
        expanded = open,
        onExpandedChange = { open = it },
        tagKey = "order"
    ) { node ->
        val card = ORDER.getValue(node.key)
        val colors = PantrixTheme.colors
        Column {
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(HEAD)
                    .background(if (selected) colors.primary.container else Color.Transparent)
                    .padding(start = 10.dp, end = 4.dp),
                verticalAlignment = Alignment.CenterVertically,
                horizontalArrangement = Arrangement.spacedBy(6.dp)
            ) {
                val head = if (selected) colors.primary.onContainer else colors.textPrimary
                PantrixText(text = card.title, style = PantrixTheme.typography.code, color = head)
                PantrixText(
                    text = card.count,
                    modifier = Modifier.weight(1f),
                    style = PantrixTheme.typography.code,
                    color = if (selected) head else colors.textSecondary
                )
                GraphFoldButton()
            }
            card.rows.forEach { (key, value) ->
                Row(modifier = Modifier.height(ROW).padding(horizontal = 10.dp)) {
                    PantrixText(text = "$key: ", style = PantrixTheme.typography.code, color = colors.primary.color)
                    PantrixText(
                        text = value,
                        style = PantrixTheme.typography.code,
                        maxLines = 1,
                        overflow = TextOverflow.Ellipsis
                    )
                }
            }
        }
    }
}

private val HEAD = 32.dp

private val ROW = 24.dp

private val ORDER = linkedMapOf(
    "$" to DocumentCard(
        "root",
        "order.json",
        "{11}",
        listOf(
            "id" to "\"ord_8842\"",
            "status" to "\"shipped\"",
            "createdAt" to "\"2026-10-28T14:32:00Z\"",
            "total" to "129.90",
            "currency" to "\"EUR\"",
            "paid" to "true",
            "coupon" to "null"
        )
    ),
    "customer" to DocumentCard(
        "customer",
        "customer",
        "{4}",
        listOf("name" to "\"Elif Yılmaz\"", "email" to "\"elif@example.com\"")
    ),
    "theme" to DocumentCard("theme", "theme", "{1}", listOf("accent" to "\"#0F766E\"")),
    "items" to DocumentCard("items", "items", "[2]", emptyList()),
    "items0" to DocumentCard(
        "item_0",
        "items[0]",
        "{4}",
        listOf("sku" to "\"TS-001\"", "qty" to "2", "price" to "39.95")
    ),
    "items1" to DocumentCard(
        "item_1",
        "items[1]",
        "{4}",
        listOf("sku" to "\"MG-014\"", "qty" to "1", "price" to "50.00")
    ),
    "shipping" to DocumentCard(
        "shipping",
        "shipping",
        "{3}",
        listOf("method" to "\"express\"", "eta" to "\"2026-11-04\"")
    ),
    "address" to DocumentCard("address", "address", "{2}", listOf("city" to "\"İzmir\"", "country" to "\"TR\""))
)

private val ORDER_NODES = ORDER.map { (key, card) ->
    val rows = card.rows.size
    val height = HEAD + ROW * rows + if (rows > 0) 6.dp else 0.dp
    GraphNode(key = key, label = "${card.title}, ${card.count}", size = DpSize(200.dp, height), tagKey = card.id)
}

private val ORDER_LINKS = listOf(
    GraphLink("$", "customer", "customer"),
    GraphLink("$", "theme", "theme"),
    GraphLink("$", "items", "items"),
    GraphLink("$", "shipping", "shipping"),
    GraphLink("items", "items0", "[0]"),
    GraphLink("items", "items1", "[1]"),
    GraphLink("shipping", "address", "address")
)

private val LEVELS = listOf("1" to 1, "2" to 2, "3" to 3, "All" to Int.MAX_VALUE)

private class DocumentCard(
    val id: String,
    val title: String,
    val count: String,
    val rows: List<Pair<String, String>>
)

From the top down, with buttons of its own

A team from the top down, as on a phone's narrow screen; the zoom buttons stand in the screen's own toolbar, not in the graph's corner: GraphState zooms in, zooms out, goes back to 100% and fits.

val graph = rememberGraphState(initialZoom = 0.8f, zoomRange = 0.5f..1.5f)
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
    Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp)) {
        PantrixIconButton(
            imageVector = PantrixIcons.ZoomOut,
            contentDescription = "Zoom out",
            onClick = graph::zoomOut,
            size = ButtonSize.Small,
            enabled = graph.canZoomOut,
            tagKey = "team_out"
        )
        PantrixText(text = "%${(graph.zoom * 100).roundToInt()}", modifier = Modifier.padding(horizontal = 4.dp))
        PantrixIconButton(
            imageVector = PantrixIcons.ZoomIn,
            contentDescription = "Zoom in",
            onClick = graph::zoomIn,
            size = ButtonSize.Small,
            enabled = graph.canZoomIn,
            tagKey = "team_in"
        )
        PantrixButton(
            text = "%100",
            onClick = { graph.zoomTo(1f) },
            variant = ButtonVariant.Text,
            size = ButtonSize.Small,
            tagKey = "team_actual"
        )
        PantrixIconButton(
            imageVector = PantrixIcons.FitScreen,
            contentDescription = "Fit",
            onClick = graph::fit,
            size = ButtonSize.Small,
            tagKey = "team_fit"
        )
        PantrixText(
            text = "${graph.zoomRange.start.percent()}–${graph.zoomRange.endInclusive.percent()}",
            color = PantrixTheme.colors.textSecondary,
            style = PantrixTheme.typography.footnote
        )
    }
    PantrixGraph(
        nodes = TEAM.map { person -> GraphNode(key = person.id, label = person.name, size = PERSON) },
        links = TEAM.mapNotNull { person -> person.lead?.let { GraphLink(from = it, to = person.id) } },
        modifier = Modifier.fillMaxWidth().height(360.dp),
        state = graph,
        direction = GraphDirection.TopToBottom,
        zoomButtons = false,
        tagKey = "team"
    ) { node ->
        Column(modifier = Modifier.padding(horizontal = 10.dp, vertical = 6.dp)) {
            PantrixText(text = node.label, style = PantrixTheme.typography.label)
            PantrixText(
                text = TEAM.first { it.id == node.key }.role,
                style = PantrixTheme.typography.caption,
                color = PantrixTheme.colors.textSecondary
            )
        }
    }
}

private fun Float.percent() = "%${(this * 100).roundToInt()}"

private val TEAM = listOf(
    Person("lead", "Deniz", "Product lead", null),
    Person("design", "Ece", "Design", "lead"),
    Person("mobile", "Kerem", "Mobile", "lead"),
    Person("web", "Mert", "Web", "lead"),
    Person("ui", "Selin", "Interface", "design"),
    Person("research", "Bora", "Research", "design"),
    Person("android", "Aslı", "Android", "mobile"),
    Person("ios", "Can", "iOS", "mobile"),
    Person("frontend", "Defne", "Front end", "web")
)

private val PERSON = DpSize(132.dp, 52.dp)

private class Person(
    val id: String,
    val name: String,
    val role: String,
    val lead: String?
)

Layers and arrows

A release's steps: some steps have links from two steps, so the graph is laid out in layers, its links with heads at their ends; the link from the build to the signing passes through the tests' layer. The links' shape is chosen; the zoom buttons are the PantrixGraphZoom over the graph. How a link that closes a circle is drawn is on the "Diagnostics" page.

var shape by remember { mutableStateOf(GraphLinkShape.Curve) }
val graph = rememberGraphState()
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
    PantrixSegmentButton(
        options = LINK_SHAPES.map { (name, value) -> SegmentOption(value, name, tagKey = name.lowercase()) },
        selected = shape,
        onSelect = { shape = it },
        fullWidth = false,
        tagKey = "shape"
    )
    PantrixGraphZoom(state = graph, tagKey = "pipeline")
    PantrixGraph(
        nodes = STEPS.map { (id, label) -> GraphNode(key = id, label = label, size = STEP) },
        links = STEP_LINKS,
        modifier = Modifier.fillMaxWidth().height(320.dp),
        state = graph,
        zoomButtons = false,
        style = GraphStyle(linkShape = shape, arrowSize = 7.dp, layerGap = 56.dp),
        tagKey = "pipeline"
    ) { node -> PantrixText(text = node.label, modifier = Modifier.padding(10.dp)) }
}

private val STEPS = listOf(
    "code" to "Code",
    "build" to "Build",
    "unit" to "Unit tests",
    "ui" to "UI tests",
    "sign" to "Signing",
    "release" to "Release"
)

private val STEP_LINKS = listOf(
    GraphLink("code", "build"),
    GraphLink("build", "unit"),
    GraphLink("build", "ui"),
    GraphLink("unit", "sign"),
    GraphLink("ui", "sign"),
    GraphLink("build", "sign", "package"),
    GraphLink("sign", "release")
)

private val STEP = DpSize(128.dp, 40.dp)

private val LINK_SHAPES = listOf(
    "Curve" to GraphLinkShape.Curve,
    "Elbow" to GraphLinkShape.Elbow,
    "Straight" to GraphLinkShape.Straight
)

Thousands of cards

Fifteen hundred cards: only those in view and at its edges are composed, and the layout is worked out away from the main thread. The graph is fitted as it opens; the button chooses a card at random and brings it into view.

val graph = rememberGraphState()
var chosen by remember { mutableStateOf<String?>(null) }
LaunchedEffect(Unit) { graph.fit() }
chosen?.let { key -> LaunchedEffect(key) { graph.bringIntoView(key) } }
Column(verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)) {
    PantrixButton(
        text = "Go to a card at random",
        onClick = { chosen = LARGE_NODES.random().key },
        variant = ButtonVariant.Outline,
        size = ButtonSize.Small,
        tagKey = "random"
    )
    PantrixGraph(
        nodes = LARGE_NODES,
        links = LARGE_LINKS,
        modifier = Modifier.fillMaxWidth().height(360.dp),
        state = graph,
        selectedKey = chosen,
        onSelect = { chosen = it },
        tagKey = "large"
    ) { node -> PantrixText(text = node.label, modifier = Modifier.padding(horizontal = 10.dp, vertical = 6.dp)) }
}

private val LARGE_NODES = List(LARGE) { GraphNode(key = "k$it", label = "Card $it", size = DpSize(96.dp, 32.dp)) }

private val LARGE_LINKS = List(LARGE - 1) { GraphLink(from = "k${it / 3}", to = "k${it + 1}") }

private const val LARGE = 1500

Its own colours, and cards that are measured

A graph with colours of its own, a plain ground and links at right angles; its cards are given no size, and each is measured as large as its content. A card makes its own button that closes it with toggle(): closed, it writes how many children it has, and while the keys are on it, it puts a mark at its side.

var open by remember { mutableStateOf(setOf("pantrix", "foundation", "components")) }
val colors = PantrixTheme.colors
PantrixGraph(
    nodes = MODULES.map { (id, _) -> GraphNode(key = id, label = id.replaceFirstChar { it.uppercase() }) },
    links = MODULES.mapNotNull { (id, parent) -> parent?.let { GraphLink(from = it, to = id) } },
    modifier = Modifier.fillMaxWidth().height(300.dp),
    expanded = open,
    onExpandedChange = { open = it },
    ground = GraphGround.Plain,
    style = GraphStyle(linkShape = GraphLinkShape.Elbow, layerGap = 48.dp),
    colors = GraphColors(
        ground = colors.info.container,
        node = colors.surface,
        border = colors.info.color,
        link = colors.info.color,
        linkLabel = colors.info.onContainer
    ),
    tagKey = "modules"
) { node ->
    val children = MODULES.count { it.second == node.key }
    Row(modifier = Modifier.padding(8.dp), verticalAlignment = Alignment.CenterVertically) {
        PantrixText(text = if (focused) "▸ ${node.label}" else node.label)
        if (hasChildren) {
            PantrixButton(
                text = if (expanded) "Close" else "Open ($children)",
                onClick = { toggle() },
                variant = ButtonVariant.Text,
                size = ButtonSize.ExtraSmall,
                tagKey = "toggle_${node.key}"
            )
        }
    }
}

private val MODULES = listOf(
    "pantrix" to null,
    "foundation" to "pantrix",
    "components" to "pantrix",
    "testing" to "pantrix",
    "theme" to "foundation",
    "tokens" to "foundation",
    "a11y" to "foundation",
    "elements" to "components",
    "data" to "components",
    "chart" to "components"
)

API

nodes

Nodes and the links between them, laid out by the graph itself, on a ground that is moved and looked at closer by hand: a document's structure, an organisation, what depends on what.

ParameterTypeDefaultWhat it is
nodesList<GraphNode>the graph's nodes. No two have one key.
linksList<GraphLink>the links between them, by the nodes' keys. A link to a key no node has is refused.
modifierModifierModifierthe graph's modifier. The graph fills the room it is given, which it needs: in a room without a bound it is as large as its cards at the zoom it starts at.
stateGraphStaterememberGraphState()where the graph is moved to and how close it is looked at.
directionGraphDirectionGraphDirection.StartToEndwhich way the graph goes from a node to its children.
selectedKeyString?nullthe key of the chosen card, or null for none.
onSelect((String) -> Unit)?nullcalled with the key of the card a press or a key chose. Null: no card is chosen by the graph.
expandedSet<String>?nullthe keys of the open cards, or null for a graph that does not close: every card open.
onExpandedChange((Set<String>) -> Unit)?nullcalled with the keys that are to be open after a card was opened or closed. The graph changes nothing by itself.
groundGraphGroundGraphGround.Dotswhat the ground shows behind the cards.
zoomButtonsBooleantruewhether the graph's own zoom buttons stand in its lower corner at the end, a PantrixGraphZoom.
styleGraphStyle?nullthis call's own style: over every enclosing one and under the density. Only the fields it sets change, on every platform.
colorsGraphColors?nullthis graph's own colours, where they are not the theme's: the ones set here, with the theme's for the rest.
tagKeyString?nullthe graph's automation key: the graph is Graph_<tagKey> and a card in it Graph_<tagKey>.Node_<key>, by its node's own tag key where it has one. What a press or a key does is reported as a Graph event: select, expand and collapse with the node's key, and zoom with where the keys took it, in, out or fit.
node@Composable GraphNodeScope.(GraphNode) -> Unitwhat a card shows for its node, inside the frame the graph gives it.

GraphStyle

PantrixGraph's geometry: its cards' frames, the room between its layers and its cards, its links and its ground.

ParameterTypeDefaultWhat it is
shapeShapeSpecShapeSpec.UnspecifiedA card's shape: ShapeRole.Medium.
elevationDpDp.UnspecifiedHow high a card stands off the ground, by its shadow: none on iOS, where cards lie flat.
borderWidthDpDp.UnspecifiedHow wide the edge around a card is.
selectedBorderWidthDpDp.UnspecifiedHow wide the edge around the chosen card is, in the colour that marks it.
layerGapDpDp.UnspecifiedThe room between two layers, along the way the graph goes, which the links cross and their labels are written in.
siblingGapDpDp.UnspecifiedThe room between two cards of one layer, and between two subtrees.
contentPaddingDpDp.UnspecifiedThe room around the cards, between them and the ground's edge, when the graph is fitted to its view or scrolled to an end.
linkWidthDpDp.UnspecifiedHow wide a link is drawn.
linkShapeGraphLinkShape?nullHow a link is drawn: GraphLinkShape.Curve.
arrowSizeDpDp.UnspecifiedHow long the head at the end of a link is, which points at the node it goes to: none, as a tree's links need none. A graph whose links go both ways between two layers shows which way with one.
dotSpacingDpDp.UnspecifiedHow far apart the dots of GraphGround.Dots stand, at the graph's own size: they grow and shrink with it, and are drawn twice as far apart where they would stand closer than half of it.
dotSizeDpDp.UnspecifiedHow wide a dot of the ground is.
zoomPaddingDpDp.UnspecifiedHow far the graph's own zoom buttons stand from the corner of its view.
labelRoleTypeRole?nullThe type a link's label is written in: TypeRole.Caption.

GraphColors

What a PantrixGraph is painted with, where it does not take the theme's colours: a colour that is set is used, and one that is left out stays the theme's.

ParameterTypeDefaultWhat it is
groundColorColor.UnspecifiedThe fill behind the cards: the theme's background, a step from the surface the cards are.
dotsColorColor.UnspecifiedThe dots of GraphGround.Dots: the theme's divider.
nodeColorColor.UnspecifiedA card's fill: the theme's surface.
contentColorColor.UnspecifiedWhat a card's content is written in where it sets no colour of its own: what reads on node, the theme's textPrimary on its own surface.
borderColorColor.UnspecifiedThe edge around a card: the theme's border.
selectedBorderColorColor.UnspecifiedThe edge around the chosen card, which marks it: the primary role's colour.
linkColorColor.UnspecifiedA link: the theme's textDisabled, quieter than the cards it joins.
linkLabelColorColor.UnspecifiedA link's label, written on a patch of ground over the link: the theme's textSecondary.
focusRingColorColor.UnspecifiedThe ring around the card the keys are on: the theme's focusRing.

Accessibility