Skip to content

Commit 2279a3e

Browse files
committed
feat: default graph output is mermaid at directory level
1 parent e086a4d commit 2279a3e

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/treemapper/cli.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def _warn_diff_only_flags(args: argparse.Namespace) -> None:
176176

177177
@dataclass
178178
class GraphArgs:
179-
format: str = "json"
179+
format: str = "mermaid"
180180
summary: bool = False
181-
level: str = "fragment"
181+
level: str = "directory"
182182
edge_types: list[str] | None = None
183183
mermaid: bool = False
184184
cycles: bool = False
@@ -264,16 +264,16 @@ def _build_graph_parser() -> argparse.ArgumentParser:
264264
graph_parser.add_argument(
265265
"-f",
266266
"--format",
267-
choices=["json", "graphml"],
268-
default="json",
269-
help="Graph output format (default: json)",
267+
choices=["mermaid", "json", "graphml"],
268+
default="mermaid",
269+
help="Graph output format (default: mermaid)",
270270
)
271271
graph_parser.add_argument("--summary", action="store_true", help="Print graph summary statistics")
272272
graph_parser.add_argument(
273273
"--level",
274274
choices=["fragment", "file", "directory"],
275-
default="fragment",
276-
help="Granularity level for graph operations (default: fragment)",
275+
default="directory",
276+
help="Granularity level for graph operations (default: directory)",
277277
)
278278
graph_parser.add_argument(
279279
"--edge-types",

src/treemapper/treemapper.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,15 @@ def _format_blast_radius(g: GraphArgs, pg: Any) -> str:
187187
return "\n".join(lines)
188188

189189

190-
def _graph_to_string(pg: Any, fmt: str) -> str:
190+
def _graph_to_string(pg: Any, fmt: str, level: str = "directory") -> str:
191+
from .diffctx.graph_analytics import quotient_graph, to_mermaid
191192
from .diffctx.graph_export import graph_to_graphml_string, graph_to_json_string
192193

193194
if fmt == "graphml":
194195
return graph_to_graphml_string(pg)
196+
if fmt == "mermaid":
197+
qg = quotient_graph(pg, level=level)
198+
return to_mermaid(qg)
195199
return graph_to_json_string(pg)
196200

197201

@@ -230,7 +234,7 @@ def _handle_graph_mode(args: ParsedArgs) -> str:
230234

231235
has_analysis_flag = any([g.summary, g.cycles, g.hotspots is not None, g.metrics, g.impact, g.blast_radius, g.mermaid])
232236
if not has_analysis_flag:
233-
parts.append(_graph_to_string(pg, g.format))
237+
parts.append(_graph_to_string(pg, g.format, level=g.level))
234238

235239
return "\n".join(parts) + "\n" if parts else ""
236240

tests/test_graph.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,14 @@ def test_edge_type_filter(self, tmp_path):
361361

362362

363363
class TestGraphCLI:
364-
def test_default_json_export(self, graph_git_project):
364+
def test_default_mermaid_export(self, graph_git_project):
365365
result = _run_graph_cli([".", "-q"], cwd=graph_git_project)
366366
assert result.returncode == 0
367+
assert result.stdout.startswith("graph LR")
368+
369+
def test_json_format(self, graph_git_project):
370+
result = _run_graph_cli([".", "-f", "json", "-q"], cwd=graph_git_project)
371+
assert result.returncode == 0
367372
data = json.loads(result.stdout)
368373
assert data["type"] == "project_graph"
369374

@@ -401,7 +406,7 @@ def test_metrics(self, graph_git_project):
401406

402407
def test_output_file(self, graph_git_project):
403408
out_file = graph_git_project / "graph.json"
404-
result = _run_graph_cli([".", "-o", str(out_file), "-q"], cwd=graph_git_project)
409+
result = _run_graph_cli([".", "-f", "json", "-o", str(out_file), "-q"], cwd=graph_git_project)
405410
assert result.returncode == 0
406411
assert out_file.exists()
407412
data = json.loads(out_file.read_text())

0 commit comments

Comments
 (0)