ABotWroteThis
When building character relationship maps for fiction editors, screenwriting apps, or interactive narrative tools, the most reliable architecture splits the graph into two distinct layers: an automatically computed, undirected co-appearance reference layer derived from structured scenes, and an author-declared, directed asymmetric relationship layer that stores dramatic intent. Never infer a relationship from scene co-appearance counts, and never let computed statistics overwrite what the writer explicitly declared.
Most graph tutorials treat characters as uniform nodes connected by weighted undirected edges whenever two names appear in the same chapter or scene. In real storytelling tools, that shortcut breaks down fast. Two rivals trapped in a courtroom, a shopkeeper handing over a receipt, and a detective interrogating a witness all share a scene—yet none of those pairings share the same dramatic bond, and the two people in the room rarely feel the same way about each other.
Three UX traps in narrative relationship graphs
Tool builders commonly run into three failure modes when turning manuscript data into visual character graphs:
- Conflating physical proximity with narrative relationship. If an engine turns every shared scene into a permanent graph edge, ensemble scenes—banquets, council meetings, street chases—flood the canvas with meaningless lines. Even worse, if the writer deletes a noise edge and the parser regenerates it on the next save, the tool fights the author.
- Modeling asymmetric bonds as single symmetric labels. A single undirected label like "colleagues" or "lovers" hides half the drama. In long-form fiction and branching narratives, Character A may view Character B with blind loyalty (trust: 85), while Character B views Character A with quiet suspicion (trust: 30). Without optional two-way perspective edges, writers have to cram contradictory motives into a freeform note.
- Flattening a multi-chapter story into one static hairball. By chapter forty, a cast of thirty characters creates an unreadable web if every node is drawn at the same size and every historical shift is stacked on top of the present. Without visual hierarchy by narrative weight and chapter-level slicing, the canvas stops helping the writer spot missing connections.
The fix is architectural restraint: separate observed structural facts (who spoke in which scene) from authored narrative semantics (who trusts, fears, or owes whom at a given chapter).
A layered data model and runnable Python 3.9 reference script
Disclaimer: All data structures, field names, and Python code below are generic teaching examples created solely for this tutorial. They do not represent the internal code, data structures, or implementation of any commercial writing tool.
To keep computed stats from colliding with authorial intent, model the graph around four rules:
- Anchor co-appearance to explicit speaker turns, not raw prose guesses. When a structured editor separates speaker lines from narrative description, counting who spoke in each scene is deterministic and exact. Mentions inside prose paragraphs or scene summaries belong in companion appearance heatmaps rather than automatic graph edges.
- Make co-appearance an optional, suppressed reference layer. Compute undirected
(A, B)co-appearance pairs on demand, keep the overlay off by default until toggled, and suppress any co-appearance reference line if the author has already declared a formal relationship betweenAandB. That way, toggling the reference overlay surfaces unexplained pairings—"these two shared twelve scenes, yet I never defined their relationship"—without duplicating edges the writer already drew. - Support both symmetric and two-way asymmetric declared edges. Let a declared link stay a single shared label when appropriate, or flip into two directed records (
(source, target)and(target, source)) with independent labels, custom metric sliders (such as trust from 0 to 100), and chapter checkpoints. - Keep role-tier calculations strictly advisory. Counting scenes, dialogue lines, and declared links lets the editor display a gentle tier hint (for example, suggesting "supporting" based on scene presence), while leaving the actual node size and tier classification under manual control.
Below is a self-contained Python 3.9 standard-library script demonstrating this layered computation and chapter-slice projection:
"""Generic teaching example: layered character co-appearance & asymmetric relationships. Note: Generic data model for tutorial purposes only; not tied to any specific product. """ from collections import defaultdict from dataclasses import dataclass from itertools import combinations from typing import Dict, List, Optional, Tuple @dataclass(frozen=True) class SceneRecord: chapter: int scene_id: str speakers: Tuple[str, ...] dialogue_counts: Dict[str, int] @dataclass(frozen=True) class DeclaredEdge: chapter: int source: str target: str label: str trust_score: int def build_coappearance_refs( scenes: List[SceneRecord], max_chapter: Optional[int] = None ) -> Dict[Tuple[str, str], List[str]]: refs: Dict[Tuple[str, str], List[str]] = defaultdict(list) for sc in scenes: if max_chapter is not None and sc.chapter > max_chapter: continue unique_speakers = sorted(set(sc.speakers)) for a, b in combinations(unique_speakers, 2): refs[(a, b)].append(sc.scene_id) return dict(refs) def active_declared_edges( edges: List[DeclaredEdge], max_chapter: Optional[int] = None ) -> Dict[Tuple[str, str], DeclaredEdge]: latest: Dict[Tuple[str, str], DeclaredEdge] = {} for edge in sorted(edges, key=lambda e: e.chapter): if max_chapter is not None and edge.chapter > max_chapter: continue latest[(edge.source, edge.target)] = edge return latest def render_canvas_layers( scenes: List[SceneRecord], edges: List[DeclaredEdge], max_chapter: Optional[int] = None, show_coappearance_refs: bool = True, ) -> dict: declared = active_declared_edges(edges, max_chapter) declared_pairs = {tuple(sorted(pair)) for pair in declared} coapp = build_coappearance_refs(scenes, max_chapter) suppressed_refs = {} visible_refs = {} if show_coappearance_refs: for pair, scene_ids in sorted(coapp.items()): if pair in declared_pairs: suppressed_refs[pair] = len(scene_ids) else: visible_refs[pair] = scene_ids scene_hits: Dict[str, int] = defaultdict(int) line_hits: Dict[str, int] = defaultdict(int) rel_hits: Dict[str, int] = defaultdict(int) for sc in scenes: if max_chapter is not None and sc.chapter > max_chapter: continue for sp in set(sc.speakers): scene_hits[sp] += 1 for sp, count in sc.dialogue_counts.items(): line_hits[sp] += count for a, b in declared_pairs: rel_hits[a] += 1 rel_hits[b] += 1 tier_suggestions = {} for char in sorted(set(scene_hits) | set(rel_hits)): sc_n = scene_hits[char] ln_n = line_hits[char] rl_n = rel_hits[char] suggested = ( "lead" if sc_n >= 3 and ln_n >= 6 else ("supporting" if sc_n >= 2 or rl_n >= 1 else "minor") ) tier_suggestions[char] = ( f"suggested={suggested} ({sc_n} scenes / {ln_n} lines / {rl_n} declared links)" ) return { "declared": declared, "visible_coappearance_refs": visible_refs, "suppressed_coappearance_count": suppressed_refs, "tier_suggestions": tier_suggestions, } if __name__ == "__main__": sample_scenes = [ SceneRecord(1, "ch1-s1", ("Elena", "Marcus"), {"Elena": 3, "Marcus": 2}), SceneRecord(1, "ch1-s2", ("Elena", "Sora"), {"Elena": 2, "Sora": 2}), SceneRecord(2, "ch2-s1", ("Elena", "Marcus", "Sora"), {"Elena": 2, "Marcus": 2, "Sora": 1}), SceneRecord(3, "ch3-s1", ("Marcus", "Vex"), {"Marcus": 2, "Vex": 2}), ] sample_edges = [ DeclaredEdge(1, "Elena", "Marcus", "relies_on", 78), DeclaredEdge(1, "Marcus", "Elena", "withholds_truth_from", 35), DeclaredEdge(3, "Elena", "Marcus", "suspects_betrayal", 20), ] for ch in (2, 3): result = render_canvas_layers(sample_scenes, sample_edges, max_chapter=ch) print(f"=== Canvas Slice Through Chapter {ch} ===") for (src, dst), edge in result["declared"].items(): print(f" [Declared] {src} -> {dst}: {edge.label} (trust={edge.trust_score}, ch={edge.chapter})") for pair, sids in result["visible_coappearance_refs"].items(): print(f" [Ref Line] {pair[0]} -- {pair[1]}: co-appeared in {sids}") for pair, cnt in result["suppressed_coappearance_count"].items(): print(f" [Suppressed Ref] {pair[0]} -- {pair[1]}: {cnt} shared scenes (covered by declared edge)") for char, hint in result["tier_suggestions"].items(): print(f" [Tier Hint] {char}: {hint}") Running this script locally on Python 3.9.6 produces the following exact output:
=== Canvas Slice Through Chapter 2 === [Declared] Elena -> Marcus: relies_on (trust=78, ch=1) [Declared] Marcus -> Elena: withholds_truth_from (trust=35, ch=1) [Ref Line] Elena -- Sora: co-appeared in ['ch1-s2', 'ch2-s1'] [Ref Line] Marcus -- Sora: co-appeared in ['ch2-s1'] [Suppressed Ref] Elena -- Marcus: 2 shared scenes (covered by declared edge) [Tier Hint] Elena: suggested=lead (3 scenes / 7 lines / 1 declared links) [Tier Hint] Marcus: suggested=supporting (2 scenes / 4 lines / 1 declared links) [Tier Hint] Sora: suggested=supporting (2 scenes / 3 lines / 0 declared links) === Canvas Slice Through Chapter 3 === [Declared] Elena -> Marcus: suspects_betrayal (trust=20, ch=3) [Declared] Marcus -> Elena: withholds_truth_from (trust=35, ch=1) [Ref Line] Elena -- Sora: co-appeared in ['ch1-s2', 'ch2-s1'] [Ref Line] Marcus -- Sora: co-appeared in ['ch2-s1'] [Ref Line] Marcus -- Vex: co-appeared in ['ch3-s1'] [Suppressed Ref] Elena -- Marcus: 2 shared scenes (covered by declared edge) [Tier Hint] Elena: suggested=lead (3 scenes / 7 lines / 1 declared links) [Tier Hint] Marcus: suggested=lead (3 scenes / 6 lines / 1 declared links) [Tier Hint] Sora: suggested=supporting (2 scenes / 3 lines / 0 declared links) [Tier Hint] Vex: suggested=minor (1 scenes / 2 lines / 0 declared links) Notice three deliberate behaviors in that output:
- Suppression prevents double clutter: Because
ElenaandMarcusalready have declared edges, their two shared scenes are counted in[Suppressed Ref]rather than drawing redundant dashed lines over the solid relationship arrows. - Asymmetric chapter updates stay independent: In Chapter 3,
Elena -> Marcusflips tosuspects_betrayal (trust=20), whileMarcus -> Elenakeeps its Chapter 1 state (withholds_truth_from,trust=35). Updating one side of a relationship never resets the other. - Unlinked co-appearances stand out clearly:
Elena -- Soraappears as a dashed reference line across two scenes (ch1-s2,ch2-s1), signaling to the writer that two recurring characters share stage time without an explicit relationship card yet.
Visual hierarchy, suppression rules, and chapter slicing on the canvas
Data separation only pays off if the canvas UI reinforces the same boundaries. Four interaction patterns keep a growing cast legible without fighting the writer:
- Scale node footprints across a five-tier hierarchy: Render lead characters as large cards showing portraits, key identity traits, and character arcs; shrink supporting characters to compact cards with scene and line counters; reduce minor or cameo roles to minimal name badges; and offer a one-click filter to hide walk-on extras. Pairing that with faction filtering and relationship-density grouping (high-density hubs vs. isolated nodes) stops a forty-character cast from overwhelming the viewport.
- Respect manual layout alongside auto-arrangement: Writers encode spatial meaning into where they drop cards—putting rivals across from each other or clustering a family in one corner. Provide both a full auto-layout pass and a gentler "re-tidy" pass that cleans up overlaps while preserving manual coordinates.
- Make two-way perspectives explicit in the edge editor: Let the user click a node, pick a target, and toggle "two-way perspective." When enabled, present two separate direction labels, two independent numeric sliders (0–100) with a customizable metric name (such as trust, loyalty, or debt), a freeform notes area for shifting motives, and an automatic read-only list of shared scenes below.
- Keep companion appearance heatmaps non-intrusive: Beyond speaker lines, an appearance heatmap can include formal character links and whole-word name or alias mentions in prose and scene summaries to show who dominates the page count. Even there, avoid nagging alerts like "Character X has not appeared in 12 chapters"—surface the chapter list on hover and let the author decide whether a disappearance is a continuity slip or an intentional mystery.
Practical checklist before shipping a narrative graph
Before releasing a character relationship feature in a writing or narrative-design tool, verify these five engineering checks:
| Check | Expected behavior | Why it matters |
|---|---|---|
| Layer isolation | Co-appearance lines stay toggleable (default off) and never create declared edges | Prevents ensemble scenes from polluting canonical relationships |
| Edge suppression | Pairs with a declared edge do not also render a co-appearance dashed line | Keeps the canvas readable and avoids duplicate visual tracks |
| Asymmetric state | Directed edges A -> B and B -> A store independent labels, scores, and chapter checkpoints | Preserves dramatic irony, betrayal, and unrequited motives |
| Advisory stats | Scene counts and line counts produce tier suggestions only, never silent mutations | Protects intentional cameos and slow-burn reveals from auto-reclassification |
| Chapter slicing | Selecting Chapter N filters both declared edges and co-appearance up to N | Lets writers inspect shifting alliances at any point in the draft |
Keeping structural analytics strictly downstream of authored prose—and strictly separate from declared relationship semantics—gives narrative tools the best of both worlds: deterministic diagnostics when the writer wants a sanity check, and zero automated interference when the story breaks a pattern on purpose.
This article was drafted with AI assistance. The code samples were run locally before publishing, and the external facts were checked against public sources as of December 3, 2026.
