Diagram
Renders interactive, draggable diagrams in the browser using Cytoscape.js from context-supplied nodes and edges.
Workflow
- Extract nodes and edges — read labels, connections, and any grouping/color hints from the user's request or conversation context.
- Assign colors and positions — choose a color scheme and set x/y coordinates for a readable layout. See TEMPLATE.md for layout patterns.
- Write the HTML file — write a complete self-contained file to
/tmp/diagram.htmlusing the Cytoscape.js template. See TEMPLATE.md for the full template. - Render in browser — follow
_shared/chrome-devtools-render.mdto open/tmp/diagram.html, wait for render, screenshot, and fix-and-reload if needed.wait_fora string from the legend or a node label. See TROUBLESHOOTING.md for diagram-specific fixes.
Self-review checklist
Before delivering, verify ALL:
- Screenshot shows all nodes with readable text — no overflow, no overlap
- Solid edges are solid, dashed edges are dashed (check
dashed: 'yes'notdashed: true) -
cy.fit(cy.elements(), 60)is the last line of the script - CDN URL is exactly
https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.29.2/cytoscape.min.js - Legend matches the color scheme used in the diagram
- Hint text
drag nodes · scroll to zoom · drag background to panis present - No node has
widthorheightset tolabel— always use explicit pixel values -
wait_foris called beforetake_screenshot
Golden rules
Hard rules. Never violate these.
- Never use boolean edge attributes. Cytoscape selectors do not reliably match boolean data values. Always store edge style flags as strings:
dashed: 'yes'ordashed: 'no'. Use selectoredge[dashed = "yes"]. - Never render to PNG. Always write
/tmp/diagram.htmland open in browser. Static images cannot be dragged or zoomed by the user. - Always call
cy.fitlast.cy.fit(cy.elements(), 60)must be the final line in the script block. Without it, the diagram may render off-screen or at wrong zoom. - Always use
new_pagefor first open. Usemcp__chrome-devtools__new_pagewithurl: file:///tmp/diagram.html. Only usenavigate_pagewithtype: reloadfor subsequent reloads. - Always wait before screenshotting. Call
wait_foron a text string that appears after Cytoscape renders (legend text or a node label). Never calltake_screenshotimmediately afternew_page. - Never set node dimensions to
label. Always use explicit pixel widths and heights (e.g.width: 200px,height: 80px). Thelabelvalue causes unpredictable sizing. - Always use
text-wrap: wrapwithtext-max-width. Without these, long labels overflow node boundaries invisibly.
Reference files
| File | Contents |
|---|---|
| TEMPLATE.md | Complete Cytoscape.js HTML template, color palette, layout patterns for common diagram types |
| TROUBLESHOOTING.md | Failure diagnosis table: symptoms, causes, fixes |