-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add viz by generating svg image #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marcusschiesser
wants to merge
9
commits into
main
Choose a base branch
from
ms/add-viz
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c9277f1
add pre-commit hook
marcusschiesser c624228
programmatically generate dot file
marcusschiesser d58478e
generate static graph with graphology
marcusschiesser 68a1801
add browser viz using sigma
marcusschiesser 46179ca
fix lint
marcusschiesser 8c64791
add send events
marcusschiesser 7b34078
add awaited events
marcusschiesser 5f46ed3
clean up parser
marcusschiesser 20d14a6
Merge branch 'main' into ms/add-viz
himself65 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/llamaindex.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + Sigma.JS + TS + Llamaindex</title> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "browser", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@llama-flow/core": "latest", | ||
"@llama-flow/viz": "workspace:*", | ||
"graphology": "^0.26.0", | ||
"graphology-layout-force": "^0.2.4", | ||
"react": "^19.1.0", | ||
"react-dom": "^19.1.0", | ||
"sigma": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^19.1.2", | ||
"@types/react-dom": "^19.1.2", | ||
"@vitejs/plugin-react-swc": "^3.9.0", | ||
"globals": "^16.0.0", | ||
"typescript": "~5.8.3", | ||
"vite": "^6.3.2" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import "./style.css"; | ||
import Sigma from "sigma"; | ||
import { workflow } from "./workflow"; | ||
import { toSigma } from "@llama-flow/viz"; | ||
import ForceSupervisor from "graphology-layout-force/worker"; | ||
|
||
const container = document.getElementById("app") as HTMLElement; | ||
|
||
// const graph = new Graph(); | ||
// graph.addNode("John", { x: 0, y: 10, size: 5, label: "John", color: "blue" }); | ||
// graph.addNode("Mary", { x: 10, y: 0, size: 3, label: "Mary", color: "red" }); | ||
// graph.addEdge("John", "Mary"); | ||
const graph = toSigma(workflow.getGraph()); | ||
|
||
graph.nodes().forEach((node, i) => { | ||
const angle = (i * 2 * Math.PI) / graph.order; | ||
graph.setNodeAttribute(node, "x", 100 * Math.cos(angle)); | ||
graph.setNodeAttribute(node, "y", 100 * Math.sin(angle)); | ||
}); | ||
|
||
const layout = new ForceSupervisor(graph); | ||
layout.start(); | ||
|
||
new Sigma(graph, container); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
html, | ||
body, | ||
#app { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; /* Prevents scrollbars if graph is larger than viewport */ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { createWorkflow, workflowEvent, getContext } from "@llama-flow/core"; | ||
import { withGraph } from "@llama-flow/viz"; | ||
|
||
//#region define workflow events | ||
const startEvent = workflowEvent<string>({ | ||
debugLabel: "start", | ||
}); | ||
const branchAEvent = workflowEvent<string>({ | ||
debugLabel: "branchA", | ||
}); | ||
const branchBEvent = workflowEvent<string>({ | ||
debugLabel: "branchB", | ||
}); | ||
const branchCEvent = workflowEvent<string>({ | ||
debugLabel: "branchC", | ||
}); | ||
const branchCompleteEvent = workflowEvent<string>({ | ||
debugLabel: "branchComplete", | ||
}); | ||
const allCompleteEvent = workflowEvent<string>({ | ||
debugLabel: "allComplete", | ||
}); | ||
const stopEvent = workflowEvent<string>({ | ||
debugLabel: "stop", | ||
}); | ||
//#endregion | ||
|
||
//#region defines workflow | ||
const workflow = withGraph(createWorkflow()); | ||
workflow.handle([startEvent], async () => { | ||
// emit 3 different events, handled separately | ||
const { sendEvent, stream } = getContext(); | ||
sendEvent(branchAEvent.with("Branch A")); | ||
sendEvent(branchBEvent.with("Branch B")); | ||
sendEvent(branchCEvent.with("Branch C")); | ||
|
||
const results = await stream.filter(branchCompleteEvent).take(3).toArray(); | ||
|
||
return allCompleteEvent.with(results.map((e) => e.data).join(", ")); | ||
}); | ||
|
||
workflow.handle([branchAEvent], (branchA) => { | ||
return branchCompleteEvent.with(branchA.data); | ||
}); | ||
|
||
workflow.handle([branchBEvent], (branchB) => { | ||
return branchCompleteEvent.with(branchB.data); | ||
}); | ||
|
||
workflow.handle([branchCEvent], (branchC) => { | ||
return branchCompleteEvent.with(branchC.data); | ||
}); | ||
|
||
workflow.handle([allCompleteEvent], (allComplete) => { | ||
return stopEvent.with(allComplete.data); | ||
}); | ||
|
||
export { workflow }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./lib", | ||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUncheckedSideEffectImports": true | ||
}, | ||
"include": ["src"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./lib", | ||
"tsBuildInfoFile": "./lib/.tsbuildinfo" | ||
}, | ||
"files": [], | ||
"references": [ | ||
{ "path": "./tsconfig.app.json" }, | ||
{ "path": "./tsconfig.node.json" } | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./lib", | ||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", | ||
"target": "ES2022", | ||
"lib": ["ES2023"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"noEmit": true, | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUncheckedSideEffectImports": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from "vite"; | ||
import react from "@vitejs/plugin-react-swc"; | ||
|
||
// https://vite.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { createWorkflow, workflowEvent, getContext } from "@llama-flow/core"; | ||
import { withGraph } from "@llama-flow/viz"; | ||
|
||
//#region define workflow events | ||
const startEvent = workflowEvent<string>({ | ||
debugLabel: "start", | ||
}); | ||
const branchAEvent = workflowEvent<string>({ | ||
debugLabel: "branchA", | ||
}); | ||
const branchBEvent = workflowEvent<string>({ | ||
debugLabel: "branchB", | ||
}); | ||
const branchCEvent = workflowEvent<string>({ | ||
debugLabel: "branchC", | ||
}); | ||
const branchCompleteEvent = workflowEvent<string>({ | ||
debugLabel: "branchComplete", | ||
}); | ||
const allCompleteEvent = workflowEvent<string>({ | ||
debugLabel: "allComplete", | ||
}); | ||
const stopEvent = workflowEvent<string>({ | ||
debugLabel: "stop", | ||
}); | ||
//#endregion | ||
|
||
//#region defines workflow | ||
const workflow = withGraph(createWorkflow()); | ||
workflow.handle([startEvent], async () => { | ||
// emit 3 different events, handled separately | ||
const { sendEvent, stream } = getContext(); | ||
sendEvent(branchAEvent.with("Branch A")); | ||
sendEvent(branchBEvent.with("Branch B")); | ||
sendEvent(branchCEvent.with("Branch C")); | ||
|
||
const results = await stream.filter(branchCompleteEvent).take(3).toArray(); | ||
|
||
return allCompleteEvent.with(results.map((e) => e.data).join(", ")); | ||
}); | ||
|
||
workflow.handle([branchAEvent], (branchA) => { | ||
return branchCompleteEvent.with(branchA.data); | ||
}); | ||
|
||
workflow.handle([branchBEvent], (branchB) => { | ||
return branchCompleteEvent.with(branchB.data); | ||
}); | ||
|
||
workflow.handle([branchCEvent], (branchC) => { | ||
return branchCompleteEvent.with(branchC.data); | ||
}); | ||
|
||
workflow.handle([allCompleteEvent], (allComplete) => { | ||
return stopEvent.with(allComplete.data); | ||
}); | ||
|
||
//#endregion | ||
|
||
const graph = workflow.getGraph(); | ||
console.log("--- Graph Nodes ---"); | ||
graph.forEachNode((node, attributes) => { | ||
console.log(`Node: ${node}, Attributes: ${JSON.stringify(attributes)}`); | ||
}); | ||
|
||
console.log("\n--- Graph Edges ---"); | ||
graph.forEachEdge((edge, attributes, source, target) => { | ||
console.log( | ||
`Edge from ${source} to ${target} (ID: ${edge}), Attributes: ${JSON.stringify(attributes)}`, | ||
); | ||
}); | ||
console.log("--- End of Graph Details ---"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@llama-flow/viz", | ||
"version": "0.1.0", | ||
"description": "Visualization components for LlamaFlow", | ||
"type": "module", | ||
"main": "dist/index.cjs", | ||
"types": "dist/index.d.ts", | ||
"module": "dist/index.js", | ||
"exports": { | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
}, | ||
"default": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "bunchee", | ||
"dev": "bunchee --watch" | ||
}, | ||
"devDependencies": { | ||
"@babel/types": "^7.27.1", | ||
"@llama-flow/core": "workspace:*", | ||
"@types/node": "^22.15.19", | ||
"bunchee": "^6.5.1" | ||
}, | ||
"peerDependencies": { | ||
"@llama-flow/core": "workspace:*" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/run-llama/llama-flow.git", | ||
"directory": "packages/viz" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@babel/parser": "^7.27.2", | ||
"graphology": "^0.26.0" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to be latest after release