Skip to content

Commit 5fd0b42

Browse files
committed
docs: improve vgraph skill guidance
1 parent a81704c commit 5fd0b42

4 files changed

Lines changed: 54 additions & 54 deletions

File tree

skills/vgraph-development-assistant/SKILL.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: vgraph-development-assistant
3-
description: "Expert assistant for @visactor/vgraph, @visactor/react-vgraph, and @visactor/react-vgraph-ui. Use when the user asks to create, configure, debug, optimize, or review VGraph Graph/TreeGraph visualizations, graph data, GraphStructure, layouts (dag, force, compactBox, dendrogram, mindMap, indented, pipeline, nestedDag), behaviors (panZoom, dragCanvas, dragNode, brushSelect, highlightRelations), events (node:click, GRAPH_EVENTS), React Viewer integration, CommonFlowEditor/DAGFlowEditor, examples, blank-canvas bugs, layout bugs, performance issues, or migration/open-source docs for VGraph code."
3+
description: "Expert assistant for @visactor/vgraph, @visactor/react-vgraph, and @visactor/react-vgraph-ui. Use when the user asks to create, configure, debug, optimize, or review VGraph Graph/TreeGraph visualizations, graph data, GraphStructure, layouts (dag, force, compactBox, dendrogram, mindMap, indented, pipeline, nestedDag), behaviors (panZoom, dragCanvas, dragNode, brushSelect, highlightRelations), events (node:click, GRAPH_EVENTS), React Viewer integration, CommonFlowEditor/DAGFlowEditor, VGraph examples, API docs, demos, blank-canvas bugs, layout bugs, performance issues, or VGraph-specific migration guidance."
44
---
55

66
# VGraph Development Assistant
@@ -28,20 +28,20 @@ If a reasonable default exists, proceed with that default and name it.
2828

2929
## Mandatory Routing
3030

31-
Read only the files needed for the task. If you load one reference, read it completely.
32-
33-
| User intent or keywords | Read these files |
34-
| --- | --- |
35-
| Getting started, create graph, basic demo, simple snippet | `references/knowledge/00-overview.md`, then `references/examples/basic-graph.md` |
36-
| Standalone demo page, runnable HTML demo, previewable structure diagram, knowledge map showcase, code tab | `references/examples/demo-html-page.md`, plus the relevant graph/layout/behavior references below |
37-
| Graph vs TreeGraph vs GraphStructure | `references/knowledge/01-graph-treegraph.md`, then `references/type/graph-options.md` |
38-
| Data, nodes, edges, groups, TreeData, GraphData | `references/knowledge/02-data-model.md` |
39-
| Node, edge, group style, state, custom shape, anchors | `references/knowledge/03-node-edge-group.md`, then `references/type/model-options.md` |
40-
| Layout, dag, force, tree, compactBox, mindMap, nestedDag, pipeline | `references/knowledge/04-layouts.md`, then `references/examples/tree-graph.md` for tree tasks |
41-
| Behavior, interaction, drag, panZoom, brush select, events | `references/knowledge/05-behaviors-events.md`, then `references/type/event-types.md`, then `references/examples/events-behaviors.md` for code |
42-
| React node, Viewer, hooks, tooltip, context menu | `references/knowledge/06-react-integration.md`, then `references/examples/react-viewer.md` |
43-
| Editor, stack, node mover, edge editor, minimap, grid | `references/knowledge/07-components-editor.md` |
44-
| Blank canvas, not rendering, performance, memory, export, update bugs | `references/knowledge/08-performance-debugging.md` |
31+
Read only the files needed for the task. If you load one reference, read it completely. Do NOT load unrelated reference files just because they are nearby; keep answers grounded in the chosen route.
32+
33+
| User intent or keywords | Read | Do NOT load by default |
34+
| --- | --- | --- |
35+
| Getting started, create graph, basic demo, simple snippet | `references/knowledge/00-overview.md`, then `references/examples/basic-graph.md` | React/editor/performance references |
36+
| Standalone demo page, runnable HTML demo, previewable structure diagram, knowledge map showcase, code tab | `references/examples/demo-html-page.md`, plus the relevant graph/layout/behavior references below | All examples not used by the selected graph family |
37+
| Graph vs TreeGraph vs GraphStructure | `references/knowledge/01-graph-treegraph.md`, then `references/type/graph-options.md` | React/editor examples |
38+
| Data, nodes, edges, groups, TreeData, GraphData | `references/knowledge/02-data-model.md` | Layout examples unless layout is part of the question |
39+
| Node, edge, group style, state, custom shape, anchors | `references/knowledge/03-node-edge-group.md`, then `references/type/model-options.md` | Demo page reference |
40+
| Layout, dag, force, tree, compactBox, mindMap, nestedDag, pipeline | `references/knowledge/04-layouts.md`, then `references/examples/tree-graph.md` for tree tasks | React/editor references |
41+
| Behavior, interaction, drag, panZoom, brush select, events | `references/knowledge/05-behaviors-events.md`, then `references/type/event-types.md`, then `references/examples/events-behaviors.md` for code | Layout/debug references unless needed |
42+
| React node, Viewer, hooks, tooltip, context menu | `references/knowledge/06-react-integration.md`, then `references/examples/react-viewer.md` | Standalone HTML demo reference |
43+
| Editor, stack, node mover, edge editor, minimap, grid | `references/knowledge/07-components-editor.md` | React Viewer example unless DOM nodes are requested |
44+
| Blank canvas, not rendering, performance, memory, export, update bugs | `references/knowledge/08-performance-debugging.md` | Demo/examples unless reproducing |
4545

4646
Do not load all references by default. For simple code-generation requests, one knowledge file plus one example file is usually enough.
4747

@@ -76,7 +76,9 @@ For simple examples, API usage, configuration help, or debugging answers, prefer
7676

7777
A standard demo page should include a `Demo` tab for the live VGraph canvas and a `Code` tab for the core runnable TypeScript/JavaScript. The Code tab should be a fixed-size panel with internal scrolling (`overflow: auto`) so long examples do not expand the whole page or hide the live demo. Include a copy-code action when practical.
7878

79-
For large trees, knowledge maps, organization charts, or any graph that can overwhelm the viewport, add readability controls by default. Use `panZoom` and `dragCanvas`, start from a conservative overview when it helps users understand the top-level structure, and provide controls such as "expand all", "collapse details", search, filter, group focus, or fit-to-view. Implement tree collapse by keeping source data immutable, deriving visible `children` from a collapsed-ID set, and refreshing the graph with `graph.data(visibleTree)`. For non-tree Graph/DAG demos, do not force tree-collapse patterns onto edge-list data; prefer viewport, filtering, grouping, highlighting, or progressive disclosure controls.
79+
For large trees, knowledge maps, organization charts, or any graph that can overwhelm the viewport, add readability controls by default. Use `panZoom` and `dragCanvas`, start from a conservative overview when it helps users understand the top-level structure, and provide controls such as "expand all", "collapse details", search, filter, group focus, or fit-to-view. For `TreeGraph` hierarchy expand/collapse, use native `collapse`, `expand`, or `toggleCollapse` first so the interaction stays a visibility/layout operation instead of a full data replacement. For non-tree Graph/DAG demos, do not force tree-collapse patterns onto edge-list data; prefer viewport, filtering, grouping, highlighting, or progressive disclosure controls.
80+
81+
For knowledge-system or structure-map demos, preserve semantic shape before visual polish. Decide whether the requested content is a strict hierarchy, a DAG, or a general network. For school-stage or curriculum maps, keep the main levels explicit (for example stage -> subject -> topic -> skill) and avoid turning cross-links into primary parent-child edges. If the user asks for expand/collapse on a hierarchy, use `TreeGraph` native `collapse`, `expand`, or `toggleCollapse` first; do not rebuild a visible tree and call `graph.data(...)` on each click unless the user specifically needs data filtering or virtualization.
8082

8183
After creating a standalone HTML demo, verify that it renders without console errors. If the environment supports browser preview, start or reuse a local static/dev server and provide the accessible URL; if browser preview is unavailable, say what validation was skipped and why.
8284

@@ -93,4 +95,4 @@ After creating a standalone HTML demo, verify that it renders without console er
9395

9496
## Verification Habit
9597

96-
For generated snippets, make sure the imports exist in the repo exports and the chosen data shape matches the chosen graph class. For debugging, report the smallest falsifiable check first: container size, graph size, data IDs, edge endpoints, layout choice, behavior conflicts, then React lifecycle.
98+
For generated snippets, make sure the imports exist in `packages/vgraph/src/index.ts` or the relevant package export, and verify non-obvious config fields against source typings or implementation before suggesting them. For debugging, report the smallest falsifiable check first: container size, graph size, data IDs, edge endpoints, layout choice, behavior conflicts, then React lifecycle.

skills/vgraph-development-assistant/references/examples/demo-html-page.md

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ A polished standalone demo should contain:
1515
- For large tree or hierarchy demos, an initial collapsed view and controls such as `Expand all` and `Collapse details`.
1616
- For large non-tree Graph/DAG demos, readability controls such as fit-to-view, search/highlight, filtering, grouping, or progressive disclosure. Do not force tree-collapse patterns onto edge-list data.
1717

18+
Keep generic HTML/CSS minimal. Spend tokens on VGraph data shape, layout,
19+
behaviors, interaction controls, and runtime verification rather than decorative
20+
page chrome.
21+
1822
## Minimal HTML shell
1923

2024
For a real standalone HTML file, use an executable module script. Prefer a local
@@ -130,7 +134,13 @@ for (const tab of tabs) {
130134

131135
## Tree collapse pattern
132136

133-
Use `TreeGraph` for nested `children` data. Keep the original full tree immutable, derive a visible tree from collapsed IDs, and call `graph.data(visibleTree)` after each toggle.
137+
Use `TreeGraph` for nested `children` data. Prefer the native collapse API:
138+
`graph.collapse(node)`, `graph.expand(node)`, or `graph.toggleCollapse(node)`.
139+
Do not implement ordinary expand/collapse by deriving a new visible tree and
140+
calling `graph.data(...)` on every click; that turns a visibility interaction
141+
into a data update, re-layout, redraw, and possible animation replay. Use the
142+
visible-tree pattern only when the user needs true data filtering,
143+
virtualization, or server-side paging.
134144

135145
```ts
136146
import { TreeGraph, panZoom, dragCanvas } from "@visactor/vgraph";
@@ -143,7 +153,6 @@ interface TreeNode {
143153
children?: TreeNode[];
144154
}
145155

146-
const collapsedIds = new Set<string>();
147156
const nodeMap = new Map<string, TreeNode>();
148157

149158
function walkTree(node: TreeNode, visitor: (node: TreeNode) => void) {
@@ -153,33 +162,14 @@ function walkTree(node: TreeNode, visitor: (node: TreeNode) => void) {
153162

154163
walkTree(sourceTree, node => {
155164
nodeMap.set(node.id, node);
156-
if (node.children?.length && node.level === "module") {
157-
collapsedIds.add(node.id);
158-
}
165+
node.collapsed = Boolean(node.children?.length && node.level === "module");
159166
});
160167

161-
function cloneVisibleNode(node: TreeNode): TreeNode {
162-
const children = node.children ?? [];
163-
const collapsed = children.length > 0 && collapsedIds.has(node.id);
164-
const next: TreeNode = {
165-
...node,
166-
collapsed,
167-
name: children.length ? `${collapsed ? "" : ""} ${node.name}` : node.name
168-
};
169-
170-
if (children.length && !collapsed) {
171-
next.children = children.map(cloneVisibleNode);
172-
} else {
173-
delete next.children;
174-
}
175-
176-
return next;
177-
}
178-
179168
const graph = new TreeGraph({
180169
container: "container",
181170
width,
182171
height,
172+
animate: false,
183173
layout: {
184174
type: "compactBox",
185175
options: { direction: "LR" }
@@ -197,26 +187,23 @@ const graph = new TreeGraph({
197187
})
198188
});
199189

200-
function renderTree() {
201-
graph.data(cloneVisibleNode(sourceTree));
202-
}
203-
204190
graph.addBehavior(panZoom, { sensitivity: 4 });
205191
graph.addBehavior(dragCanvas);
206192

207193
graph.on("node:click", ev => {
208194
const id = ev?.target?.get?.("id");
209195
if (!id || !nodeMap.get(id)?.children?.length) return;
210196

211-
if (collapsedIds.has(id)) collapsedIds.delete(id);
212-
else collapsedIds.add(id);
213-
214-
renderTree();
197+
graph.toggleCollapse(ev.target);
215198
});
216199

217-
renderTree();
200+
graph.data(sourceTree);
218201
```
219202

203+
Set `animate: false` for static knowledge-map demos when repeated expand/collapse
204+
should feel instant and not replay layout transitions. Keep animation on only
205+
when the transition itself is part of the requested experience.
206+
220207
## Verification
221208

222209
After creating the HTML file, open it through a local static/dev server when possible and check the browser console. The expected result is a visible graph in the Demo tab, a scrollable Code tab, working copy-code behavior if included, and no console errors. If browser preview is unavailable, state that runtime validation was skipped instead of implying it passed.

skills/vgraph-development-assistant/references/knowledge/04-layouts.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ Batch pattern:
3333
const autoDraw = graph.disableAutoDraw();
3434
const autoLayout = graph.disableAutoLayout();
3535

36-
graph.updateData(nextData);
37-
38-
graph.enableAutoLayout(autoLayout);
39-
graph.enableAutoDraw(autoDraw);
36+
try {
37+
graph.updateData(nextData);
38+
} finally {
39+
graph.enableAutoLayout(autoLayout);
40+
graph.enableAutoDraw(autoDraw);
41+
}
4042
```
4143

4244
If layout still does not appear to run:

skills/vgraph-development-assistant/references/knowledge/05-behaviors-events.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ Some behaviors accept options:
2525

2626
```ts
2727
graph.addBehavior(panZoom, { sensitivity: 5 });
28-
graph.addBehavior(dragCanvas, { eventType: "right" });
28+
graph.addBehavior(dragCanvas, {
29+
shouldTrigger(event) {
30+
return !event.target || event.target.type === "canvas";
31+
}
32+
});
2933
```
3034

35+
`dragCanvas` does not expose an `eventType: "right"` option. Its built-in
36+
trigger rejects right-button drags (`nativeEvent.buttons === 2`). Use
37+
`shouldTrigger`, `canvasOnly`, `xOnly`, `yOnly`, `limit`, or behavior mode
38+
switching instead of inventing event-type configuration.
39+
3140
Remove by behavior config or type string:
3241

3342
```ts

0 commit comments

Comments
 (0)