Skip to content

Component API

Complete API reference for the <xcode-graph> web component.

<xcode-graph>

The root component that orchestrates the entire graph visualization. It renders an interactive canvas with a sidebar for filtering, search, and node details.

Properties

Properties are set via JavaScript (not HTML attributes) using dot notation in Lit templates or direct assignment:

js
const el = document.querySelector('xcode-graph');
el.nodes = myNodes;
el.edges = myEdges;
el.layoutOptions = { configOverrides: { elkDirection: 'RIGHT' } };
PropertyTypeDefaultDescription
nodesGraphNode[]undefinedGraph nodes to visualize. Setting this (along with edges) triggers layout computation.
edgesGraphEdge[]undefinedGraph edges connecting the nodes.
layoutOptionsLayoutOptionsundefinedOptional layout configuration. Override ELK parameters, force strengths, or hook into layout lifecycle.
showUploadbooleanundefinedWhether to show the file upload overlay. Can also be set via the show-upload HTML attribute.
colorScheme'light' | 'dark' | 'auto''auto'Color scheme preference. 'auto' follows the user's system preference. Set to 'light' or 'dark' to force a specific mode.

Attributes

HTML attributes that can be set declaratively:

AttributeTypeDescription
show-uploadbooleanShow the file upload button in the bottom-left corner. Presence of the attribute enables it.
color-scheme'light' | 'dark' | 'auto'Force a color scheme. Defaults to 'auto' (follows system preference).
html
<!-- Enable file upload via attribute -->
<xcode-graph show-upload></xcode-graph>

<!-- Force light mode -->
<xcode-graph color-scheme="light"></xcode-graph>

Methods

loadRawGraph(raw: unknown): void

Load raw XcodeGraph JSON and transform it into the internal graph format. This is the easiest way to populate the component — pass the JSON output from tuist graph --format json or any tool that produces XcodeGraph-compatible JSON.

js
const res = await fetch('/my-graph.json');
const raw = await res.json();

const app = document.querySelector('xcode-graph');
app.loadRawGraph(raw);

Behavior:

  • Validates and transforms the raw JSON into GraphNode[] / GraphEdge[]
  • Sets nodes and edges automatically on success
  • Shows a warning toast if the transform produces compatibility warnings (e.g., unknown enum values)
  • Shows an error toast if the data contains no nodes
  • Shows a critical error toast if the JSON format is incompatible
  • Never throws — all errors are handled internally via toast notifications

Events

The root component does not dispatch custom events directly. Internal child components communicate via events that are handled within the component tree.

CSS Custom Properties

The component is fully themeable via --graph-* CSS custom properties. Set these on the <xcode-graph> element or any ancestor to customize the appearance.

Core Theme Properties

PropertyDefault (Dark)Default (Light)Description
--graph-bg#161617#f5f5f7Background color
--graph-bg-secondary#1c1c1e#ffffffCard/sidebar background
--graph-textrgba(225, 228, 232, 1)rgba(28, 28, 30, 1)Primary text color
--graph-text-mutedrgba(225, 228, 232, 0.5)rgba(28, 28, 30, 0.5)Muted/secondary text
--graph-accentrgba(124, 58, 237, 1)rgba(111, 44, 255, 1)Accent/brand color
--graph-accent-dimrgba(124, 58, 237, 0.15)rgba(111, 44, 255, 0.1)Dimmed accent for backgrounds
--graph-borderrgba(255, 255, 255, 0.08)rgba(0, 0, 0, 0.1)Border color
--graph-canvas-bgInherits from --graph-bgInherits from --graph-bgCanvas background
--graph-radius0.375rem0.375remBase border radius

Node Type Colors

PropertyDefault (Dark)Description
--graph-node-app#F59E0BApp target nodes
--graph-node-framework#0EA5E9Framework nodes
--graph-node-library#22C55ELibrary nodes
--graph-node-test#EC4899Test target nodes
--graph-node-cli#3B82F6CLI tool nodes
--graph-node-package#EAB308Package dependency nodes

Platform Colors

PropertyDefault (Dark)Default (Light)Description
--graph-platform-ios#007AFF#0064D2iOS platform accent
--graph-platform-macos#64D2FF#0891B2macOS platform accent
--graph-platform-tvos#B87BFF#7C3AEDtvOS platform accent
--graph-platform-watchos#5AC8FA#0284C7watchOS platform accent
--graph-platform-visionos#7D7AFF#6366F1visionOS platform accent

Typography

PropertyDefaultDescription
--graph-fontsystem-ui, -apple-system, sans-serifBody and heading font family
--graph-font-monoui-monospace, monospaceMonospace font family

Example: Custom Theme

html
<style>
  xcode-graph {
    --graph-bg: #0d1117;
    --graph-bg-secondary: #161b22;
    --graph-text: #c9d1d9;
    --graph-accent: #58a6ff;
    --graph-border: rgba(240, 246, 252, 0.1);
    --graph-node-app: #f78166;
    --graph-node-framework: #79c0ff;
    --graph-node-package: #d2a8ff;
  }
</style>

<xcode-graph show-upload></xcode-graph>

Color Scheme

By default (color-scheme="auto"), the component adapts to light and dark mode via the system's prefers-color-scheme. All internal tokens have both dark and light variants.

To force a specific mode regardless of system preference:

html
<xcode-graph color-scheme="light"></xcode-graph>
<xcode-graph color-scheme="dark"></xcode-graph>

The component sets a data-theme attribute on its host element (data-theme="light" or data-theme="dark") and the CSS color-scheme property so native browser elements (scrollbars, form controls) match the chosen mode.

You can override individual colors using the --graph-* properties above. Your overrides apply in both modes.

Sizing

The component fills its parent container. Set a width and height on the element or its container:

html
<xcode-graph style="width: 100%; height: 600px;"></xcode-graph>
css
xcode-graph {
  display: block;
  width: 100vw;
  height: 100vh;
}

<xcode-graph-file-upload>

An internal sub-component that renders a file upload button. It is automatically included when show-upload is set on the root component. You do not need to use this directly.

Behavior

  • Renders a button in the bottom-left corner of the canvas
  • Click to open a native file picker (.json files only)
  • Drag-and-drop a JSON file onto the canvas
  • Dispatches graph-file-loaded event with the parsed JSON
  • Shows error toast notifications for invalid JSON files

Events

EventDetailDescription
graph-file-loaded{ raw: unknown }Dispatched when a valid JSON file is loaded. raw is the parsed JSON value.