DiagramKit

Diagram text in, a native SwiftUI view out.

DiagramKit reads Mermaid, PlantUML, D2 and DOT, and your users can pinch, pan, tap and export the result.

changes approved no yes Draft Review Build Tests pass? Ship

Console

▸ Rendered release-flow.mmd, layout dot, 5 nodes, 6 edges

Tap a box.

A MacBook showing the DiagramKit playground, with Mermaid source on the left and the diagram it draws on the right.A MacBook showing the DiagramKit playground, with Mermaid source on the left and the diagram it draws on the right.
An iPad note with a mindmap of a trip plan drawn by DiagramKit.An iPad note with a mindmap of a trip plan drawn by DiagramKit.

The phone runs DiagramKit’s own SVG export, so you can tap it here. The Mac and iPad are captures of real apps built with DiagramKit.

Whatever your users paste

DiagramKit detects the dialect, so one view handles all four.

An iPhone chat reply that includes a release flow diagram drawn by DiagramKit.An iPhone chat reply that includes a release flow diagram drawn by DiagramKit.
A diagram in a chat reply.

Mermaid

flowchart TD
    text[Diagram text]
    ir[Native IR]
    layout[GraphKit layout]
    view[DiagramView]
    tap[onElementTap]
    export[PNG, PDF, SVG]
    text --> ir
    ir --> layout
    layout --> view
    view --> tap
    view --> export

The direction goes in the header: TD is top down.

PlantUML

@startuml
rectangle "Diagram text" as text
rectangle "Native IR" as ir
rectangle "GraphKit layout" as layout
rectangle "DiagramView" as view
rectangle "onElementTap" as tap
rectangle "PNG, PDF, SVG" as export
text --> ir
ir --> layout
layout --> view
view --> tap
view --> export
@enduml

Every diagram sits between @startuml and @enduml.

D2

text: Diagram text
ir: Native IR
layout: GraphKit layout
view: DiagramView
tap: onElementTap
export: PNG, PDF, SVG
text -> ir
ir -> layout
layout -> view
view -> tap
view -> export

No header. A colon labels a shape, and -> draws an edge.

DOT

digraph {
    text [label="Diagram text"]
    ir [label="Native IR"]
    layout [label="GraphKit layout"]
    view [label="DiagramView"]
    tap [label="onElementTap"]
    export [label="PNG, PDF, SVG"]
    text -> ir
    ir -> layout
    layout -> view
    view -> tap
    view -> export
}

Graphviz’s own language, with attributes in square brackets.

Each dialect keeps its own defaults, so DOT draws ellipses and D2 draws heavier boxes. The layout underneath is the same.

Diagrams are data

Every node, edge, pie slice and Gantt bar comes back to your code as a DiagramElement when it’s tapped. Build drill-downs and navigation on it instead of shipping a picture.

PipelineScreen.swift

struct PipelineScreen: View {
    @State private var selected: String?

    var body: some View {
        DiagramRenderer(.mermaid(source))
            .onElementTap { element in
                if case let .node(id, _) = element {
                    selected = id
                }
            }
    }
}

Console

onElementTap .node(id: "text", label: "Diagram text")

onElementTap .node(id: "view", label: "DiagramView")

Malformed text doesn’t crash the view. .onError hands you the error, and you choose what to show.

Four themes, or yours

The MacBook playground with DiagramKit’s Light theme.
Light
The MacBook playground with DiagramKit’s Colorful theme.
Colorful
The MacBook playground with DiagramKit’s Dark theme.
Dark

DiagramView(mermaid: source, theme: .monochrome)

You can also pass your own theme conforming to DiagramTheme, or a dialect’s own theme, such as Mermaid’s forest. Themes don’t follow the system appearance on their own; you pick the theme for dark mode.

What it renders

What this edition renders, checked by DiagramKit’s own fidelity benchmark against each dialect’s reference renderer.

Diagram types by dialect, with fidelity grades
Diagram typeMermaidPlantUML
FlowchartSupportedNot in this dialect
SequenceSupportedSupported
ClassSupportedPartial
StateSupportedPartial†
Entity relationshipSupportedSupported
C4SupportedSupported
MindmapSupportedSupported
Git graphSupportedNot in this dialect
RequirementSupportedNot in this dialect
BlockSupportedNot in this dialect
KanbanSupportedNot in this dialect
ArchitecturePartialNot in this dialect
ZenUMLPartialNot in this dialect
PacketPartial†Not in this dialect
Use caseNot in this dialectSupported, provisional
ComponentNot in this dialectSupported
DeploymentNot in this dialectPartial†
ActivityNot in this dialectSupported
ObjectNot in this dialectSupported
Work breakdown structureNot in this dialectSupported, provisional
JSON and YAMLNot in this dialectSupported
Pie chartSupportedNot in this dialect
TimelineSupportedNot in this dialect
User journeySupportedNot in this dialect
Quadrant chartSupportedNot in this dialect
Radar chartSupportedNot in this dialect
XY chartSupportedNot in this dialect
GanttSupportedOn request
SankeyOn requestNot in this dialect
TreemapOn requestNot in this dialect
TimingNot in this dialectOn request
Salt (wireframes)Not in this dialectOn request
Network (nwdiag)Not in this dialectOn request
ArchiMateNot in this dialectOn request
DitaaNot in this dialectOn request
EBNF and regexNot in this dialectOn request
Chen EERNot in this dialectOn request

D2 containers, styled shapes, sql_table and class shapes. Raw Graphviz DOT goes straight to GraphKit, clusters included.

Why native

The usual way to show Mermaid in an app is a web view running mermaid.js. That puts a JavaScript runtime you don’t control inside your app, and a bundled script to keep current. Output can be hard to read in dark mode.

DiagramKit parses the source into a native model and lays it out with GraphKit, using Graphviz’s dot, neato, fdp and circo engines. What your users get is a SwiftUI view. It takes your theme, answers taps, and exports PNG, vector PDF and SVG.

PlantUML and D2 go through the same path, so there’s no second renderer to ship.

Requirements

Platforms
iOS 17, macOS 14 and visionOS 2.4, or later
Hardware
Apple silicon. Simulator builds need an Apple silicon Mac.
Delivery
An xcframework and a Swift package, from your download link after purchase
Layout
GraphKit, included

Not supported: Intel Macs, x86_64 simulators and CI runners, Mac Catalyst, watchOS, tvOS.

License

DiagramKit includes GraphKit, licensed for use inside DiagramKit. There’s a 14-day money-back guarantee if DiagramKit doesn’t work as described and we can’t fix it. Payments run through Paddle. DiagramKit also includes Graphviz under the Eclipse Public License 2.0 (source).

Buy a license