Skip to content

Commit d4d4235

Browse files
docs: add Diagram specification and update how-to guide
New documentation: - Add reference/specs/diagram.md with complete API documentation - Document direction parameter, Mermaid output, and schema grouping Updates: - Add Diagram to mkdocs.yaml navigation - Add Diagram to specs index - Update read-diagrams.ipynb with new features: - Layout direction examples - Mermaid output examples - Schema grouping examples Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c427c8e commit d4d4235

4 files changed

Lines changed: 345 additions & 36 deletions

File tree

mkdocs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ nav:
102102
- Semantic Matching: reference/specs/semantic-matching.md
103103
- Primary Keys: reference/specs/primary-keys.md
104104
- Fetch API: reference/specs/fetch-api.md
105+
- Diagram: reference/specs/diagram.md
105106
- Type System:
106107
- Types: reference/specs/type-system.md
107108
- Codec API: reference/specs/codec-api.md

src/how-to/read-diagrams.ipynb

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,22 +1280,61 @@
12801280
"cell_type": "markdown",
12811281
"id": "cell-ops-ref",
12821282
"metadata": {},
1283-
"source": [
1284-
"**Operation Reference:**\n",
1285-
"\n",
1286-
"| Operation | Meaning |\n",
1287-
"|-----------|--------|\n",
1288-
"| `dj.Diagram(schema)` | Entire schema |\n",
1289-
"| `dj.Diagram(Table) - N` | Table + N levels upstream |\n",
1290-
"| `dj.Diagram(Table) + N` | Table + N levels downstream |\n",
1291-
"| `D1 + D2` | Union of two diagrams |\n",
1292-
"| `D1 * D2` | Intersection (common nodes) |\n",
1293-
"\n",
1294-
"**Finding paths:** Use intersection to find connection paths:\n",
1295-
"```python\n",
1296-
"(dj.Diagram(upstream) + 100) * (dj.Diagram(downstream) - 100)\n",
1297-
"```"
1298-
]
1283+
"source": "**Operation Reference:**\n\n| Operation | Meaning |\n|-----------|--------|\n| `dj.Diagram(schema)` | Entire schema |\n| `dj.Diagram(Table) - N` | Table + N levels upstream |\n| `dj.Diagram(Table) + N` | Table + N levels downstream |\n| `D1 + D2` | Union of two diagrams |\n| `D1 * D2` | Intersection (common nodes) |\n\n**Finding paths:** Use intersection to find connection paths:\n```python\n(dj.Diagram(upstream) + 100) * (dj.Diagram(downstream) - 100)\n```"
1284+
},
1285+
{
1286+
"cell_type": "markdown",
1287+
"id": "2lmw6tar3w8",
1288+
"source": "## Layout Direction\n\nControl the flow direction of diagrams via configuration:\n\n| Direction | Description |\n|-----------|-------------|\n| `\"TB\"` | Top to bottom (default) |\n| `\"LR\"` | Left to right |\n\n```python\n# Set globally\ndj.config.display.diagram_direction = \"LR\"\n\n# Or override temporarily\nwith dj.config.override(display__diagram_direction=\"LR\"):\n dj.Diagram(schema).draw()\n```",
1289+
"metadata": {}
1290+
},
1291+
{
1292+
"cell_type": "code",
1293+
"id": "7nsvct1qdqu",
1294+
"source": "# Horizontal layout using config override\nwith dj.config.override(display__diagram_direction=\"LR\"):\n display(dj.Diagram(schema))",
1295+
"metadata": {},
1296+
"execution_count": null,
1297+
"outputs": []
1298+
},
1299+
{
1300+
"cell_type": "markdown",
1301+
"id": "ogpr8cqsife",
1302+
"source": "## Mermaid Output\n\nGenerate [Mermaid](https://mermaid.js.org/) syntax for embedding diagrams in Markdown documentation, GitHub, or web pages:",
1303+
"metadata": {}
1304+
},
1305+
{
1306+
"cell_type": "code",
1307+
"id": "vlq9xju4bm",
1308+
"source": "# Generate Mermaid syntax\nprint((dj.Diagram(Subject) + 2).make_mermaid())",
1309+
"metadata": {},
1310+
"execution_count": null,
1311+
"outputs": []
1312+
},
1313+
{
1314+
"cell_type": "markdown",
1315+
"id": "jsi0zuoxzvn",
1316+
"source": "Copy this output into any Mermaid-compatible viewer (GitHub Markdown, MkDocs with mermaid plugin, https://mermaid.live) to render the diagram.\n\n**Saving to file:**\n```python\ndj.Diagram(schema).save(\"pipeline.mmd\") # .mmd or .mermaid extension\n```",
1317+
"metadata": {}
1318+
},
1319+
{
1320+
"cell_type": "markdown",
1321+
"id": "pqet0vo8pwp",
1322+
"source": "## Schema Grouping\n\nWhen visualizing multi-schema pipelines, group tables by their database schema for clarity:",
1323+
"metadata": {}
1324+
},
1325+
{
1326+
"cell_type": "code",
1327+
"id": "9dx25khprlm",
1328+
"source": "# Group tables by schema (shows dashed boxes around each schema)\ndj.Diagram(schema).draw(group_by_schema=True)",
1329+
"metadata": {},
1330+
"execution_count": null,
1331+
"outputs": []
1332+
},
1333+
{
1334+
"cell_type": "markdown",
1335+
"id": "cyv4xl01iow",
1336+
"source": "**When to use schema grouping:**\n- Visualizing pipelines spanning multiple schemas\n- Understanding which tables belong to which database\n- Documentation for multi-schema architectures\n\n**Saving with grouping:**\n```python\ndj.Diagram(schema1) + dj.Diagram(schema2)\ndiag.save(\"multi_schema.svg\", group_by_schema=True)\n```",
1337+
"metadata": {}
12991338
},
13001339
{
13011340
"cell_type": "markdown",
@@ -1347,24 +1386,7 @@
13471386
"cell_type": "markdown",
13481387
"id": "cell-summary-md",
13491388
"metadata": {},
1350-
"source": [
1351-
"## Summary\n",
1352-
"\n",
1353-
"| Visual | Meaning |\n",
1354-
"|--------|--------|\n",
1355-
"| **Thick solid** | One-to-one extension |\n",
1356-
"| **Thin solid** | One-to-many containment |\n",
1357-
"| **Dashed** | Reference (independent identity) |\n",
1358-
"| **Underlined** | Introduces new dimension |\n",
1359-
"| **Orange dots** | Renamed FK via `.proj()` |\n",
1360-
"| **Colors** | Green=Manual, Gray=Lookup, Red=Computed, Blue=Imported |\n",
1361-
"\n",
1362-
"## Related\n",
1363-
"\n",
1364-
"- [Entity Integrity: Dimensions](../explanation/entity-integrity.md#schema-dimensions)\n",
1365-
"- [Semantic Matching](../reference/specs/semantic-matching.md)\n",
1366-
"- [Schema Design Tutorial](../tutorials/basics/02-schema-design.ipynb)"
1367-
]
1389+
"source": "## Summary\n\n| Visual | Meaning |\n|--------|--------|\n| **Thick solid** | One-to-one extension |\n| **Thin solid** | One-to-many containment |\n| **Dashed** | Reference (independent identity) |\n| **Underlined** | Introduces new dimension |\n| **Orange dots** | Renamed FK via `.proj()` |\n| **Colors** | Green=Manual, Gray=Lookup, Red=Computed, Blue=Imported |\n\n| Feature | Method |\n|---------|--------|\n| Layout direction | `dj.config.display.diagram_direction` |\n| Mermaid output | `.make_mermaid()` |\n| Schema grouping | `.draw(group_by_schema=True)` |\n\n## Related\n\n- [Diagram Specification](../reference/specs/diagram.md)\n- [Entity Integrity: Dimensions](../explanation/entity-integrity.md#schema-dimensions)\n- [Semantic Matching](../reference/specs/semantic-matching.md)\n- [Schema Design Tutorial](../tutorials/basics/02-schema-design.ipynb)"
13681390
},
13691391
{
13701392
"cell_type": "code",
@@ -1405,4 +1427,4 @@
14051427
},
14061428
"nbformat": 4,
14071429
"nbformat_minor": 5
1408-
}
1430+
}

0 commit comments

Comments
 (0)