-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathflow-graph-cdn.html
More file actions
69 lines (64 loc) · 2.97 KB
/
Copy pathflow-graph-cdn.html
File metadata and controls
69 lines (64 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>jmGraph FlowGraph - 第三方使用示例(CDN)</title>
<style>
html, body { margin: 0; height: 100%; font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; }
#app { width: 100vw; height: 100vh; background: #f8fafc; }
.bar { position: fixed; top: 12px; left: 12px; z-index: 10; display: flex; gap: 8px; }
button { padding: 6px 12px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; cursor: pointer; }
button:hover { border-color: #6366f1; }
</style>
</head>
<body>
<div class="bar">
<button data-act="layout">自动布局</button>
<button data-act="fit">适应视图</button>
<button data-act="zoom-in">放大</button>
<button data-act="zoom-out">缩小</button>
<button data-act="run">模拟运行</button>
<button data-act="png">导出PNG</button>
</div>
<div id="app"></div>
<!--
第三方项目最小形态:直接 import 已发布的 jmgraph 包的子路径,
无需本地安装。等价于本地项目里的 `import { createFlowGraph } from 'jmgraph/components'`。
-->
<script type="module">
import { createFlowGraph, STATUS_META } from 'https://esm.sh/jmgraph/components';
const stages = [
{ id: 'fetch_user', type: 'fetch', inputs: [], outputs: ['user'], dependsOn: [] },
{ id: 'fetch_order', type: 'fetch', inputs: [], outputs: ['order'], dependsOn: [] },
{ id: 'normalize', type: 'transform', inputs: [{ from: 'fetch_user.user' }, { from: 'fetch_order.order' }], outputs: ['rows'], dependsOn: ['fetch_user', 'fetch_order'] },
{ id: 'score', type: 'script', inputs: [{ from: 'normalize.rows' }], outputs: ['scores'], dependsOn: ['normalize'] },
{ id: 'notify', type: 'agent', inputs: [{ from: 'score.scores' }], outputs: [], dependsOn: ['score'] }
];
const fg = createFlowGraph('#app', {
stages,
mode: 'edit',
onSelect: id => console.log('选中节点:', id),
onError: (err, ctx) => console.error('[flow]', ctx, err)
});
fg.autoLayout();
fg.fit();
document.querySelector('.bar').addEventListener('click', e => {
const act = e.target.dataset.act;
if (!act) return;
if (act === 'layout') fg.autoLayout();
else if (act === 'fit') fg.fit();
else if (act === 'zoom-in') fg.zoomIn();
else if (act === 'zoom-out') fg.zoomOut();
else if (act === 'png') fg.exportPNG('jmgraph-flow');
else if (act === 'run') {
fg.setRunStatus({ fetch_user: 'success', fetch_order: 'success', normalize: 'running' });
setTimeout(() => fg.setRunStatus({
fetch_user: 'success', fetch_order: 'success',
normalize: 'success', score: 'running', notify: 'pending'
}), 900);
}
});
</script>
</body>
</html>