feat(optimize): support state diagrams in the Optimize panel

Extend the Diagram Doctor beyond flowcharts to stateDiagram / stateDiagram-v2.

- New parseStateDiagram: states → nodes, transitions → edges in source order
  (including `[*]` pseudo-transitions, so linkStyle indices stay aligned);
  `[*]` itself is never a node. Composite states map to groups, notes are
  skipped. A parseDiagram() dispatcher feeds analyze/transforms.
- Fixes are tailored per kind (verified empirically against Mermaid 11):
  * ELK is flowchart-only (state diagrams reject `layout: elk`), so it's not
    offered and the no-ELK score penalty is skipped for state diagrams.
  * Spacing uses the `state` config key; direction is set via a `direction`
    statement rather than the header.
  * State diagrams can't style individual transitions — a `linkStyle` line
    renders as a stray node — so the dim-hubs fix and focus mode fade the
    busy *states* (e.g. CANCELLED) via classDef/class instead of dimming edges.
    Flowcharts keep edge dimming via linkStyle.
- Panel notice now covers flowcharts & state diagrams.

Verified in-browser: state-diagram dim/focus render with zero junk nodes;
flowchart ELK + linkStyle dimming still intact.
This commit is contained in:
2026-05-22 22:25:51 +03:00
parent e1b5f31f87
commit 6488acc7b9
3 changed files with 297 additions and 51 deletions

View File

@@ -57,10 +57,10 @@
<div class="notice faint">Open a diagram to analyse it.</div>
{:else if !a.supported}
<div class="notice">
<div class="muted">Decluttering is built for flowcharts.</div>
<div class="muted">Decluttering is built for flowcharts & state diagrams.</div>
<p class="faint">
This looks like a <code>{a.kind || 'different'}</code> diagram, so only
flowchart / graph sources can be analysed here.
This looks like a <code>{a.kind || 'different'}</code> diagram, which
can't be analysed here yet.
</p>
</div>
{:else if a.metrics && a.graph}