Skip to content

MiniMap ​

An interactive overview of the graph showing all nodes, edges, and the current viewport position. Click and drag to pan the main viewport; pinch or magnify to zoom it when zoomable is enabled. Pan and zoom gestures are active only while the canvas is interactive (SwiftFlowState.isInteractive).

Basic Usage ​

swift
SwiftFlow(nodes: nodes, edges: edges, ...) { node in
    MyNodeView(node: node)
} overlay: {
    MiniMap()
}

Color Mapping ​

Assign colors dynamically based on node properties:

swift
MiniMap(nodeColorMapper: { props in
    switch props.type {
    case "input":    return .green
    case "output":   return .orange
    case "process":  return .blue
    default:         return .gray
    }
})

Custom Node Rendering ​

Provide a custom view for each node in the minimap:

swift
MiniMap { props in
    Circle()
        .fill(props.selected ? .blue : .gray)
        .overlay(
            Circle()
                .stroke(props.selected ? .white : .clear, lineWidth: 1)
        )
}

Customization ​

swift
MiniMap(
    nodeColor: .gray.opacity(0.4),
    selectedNodeColor: .cyan,
    nodeStrokeColor: .white.opacity(0.5),
    nodeStrokeWidth: 1,
    nodeBorderRadius: 2,
    maskColor: .black.opacity(0.5),
    width: 200,
    height: 150,
    pannable: true,
    zoomable: false,
    position: .bottomLeft
)

Parameters ​

ParameterTypeDefaultDescription
nodeColorColor?nilNode fill color; nil uses theme.minimapNodeColor
nodeColorMapper((MiniMapNodeProps) -> Color)?nilDynamic color by node properties
selectedNodeColorColor?nilSelected node fill color; nil uses theme.minimapSelectedNodeColor
nodeStrokeColorColor.clearNode border color
nodeStrokeWidthCGFloat0Node border width
nodeBorderRadiusCGFloat1Node corner radius
maskColorColor.gray.opacity(0.1)Color covering the area outside the visible viewport
widthCGFloat150MiniMap width
heightCGFloat100MiniMap height
pannableBooltrueClick-drag to pan main viewport
zoomableBoolfalsePinch/magnify to zoom main viewport
positionPanelPosition.bottomRightPanel position on canvas
nodeContent((MiniMapNodeProps) -> NodeContent)?nilCustom node view

MiniMapNodeProps ​

swift
public struct MiniMapNodeProps: Sendable {
    public let id: String
    public let x: CGFloat
    public let y: CGFloat
    public let width: CGFloat
    public let height: CGFloat
    public let selected: Bool
    public let type: String
}

How It Works ​

The MiniMap reads all visible nodes and the current viewport from SwiftFlowState, then computes a bounding box covering both the visible canvas area and every node, so the viewport indicator stays accurate even when the graph is small or far away. It scales the whole box to fit within its frame; a blue rectangle indicates the current viewport position. Edges are rendered as simple straight lines below the nodes at reduced opacity.

The MiniMap is drawn on a material background whose opacity is theme.minimapBackgroundOpacity, and maskColor covers everything outside the visible viewport (React Flow semantics). Its VoiceOver label comes from accessibilityConfig.minimapAriaLabel.

Dragging within the MiniMap pans the main canvas viewport proportionally; when zoomable is true, a magnification gesture zooms the main viewport around its current center. Both gestures respect the canvas isInteractive state and are ignored while it is disabled. When pannable is false, the MiniMap acts as a read-only overview.

SwiftUI-native node graph editor.