Skip to content
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

Feat/show-concurrency #3

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Hash Graph Visualization

![Screenshot 2024-10-02 at 10 54 38 AM](https://github.com/user-attachments/assets/c1f2c5f1-5c4a-465d-a4b5-386e2c25ae91)
<img width="1512" alt="image" src="https://github.com/user-attachments/assets/390feb54-6c66-4e9a-b2af-bcac75388ccc">

9 changes: 4 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<title>Topology - Canvas</title>
</head>

<body>
<body style="max-height: 100vh;">
<div style="margin-bottom: 10px">
<p>Connected to <span id="peerId"></span></p>
<p>peers: <span id="peers"></span></p>
Expand All @@ -27,11 +27,10 @@
<button id="paintRed" style="display:none;">Paint Red</button>
<button id="paintGreen" style="display:none;">Paint Green</button>
<button id="paintBlue" style="display:none;">Paint Blue</button>
<svg id="dag-svg" height="200" style="position: absolute; left: 75%; top: 50%; transform: translate(-50%, -50%);">
<g />
</svg>
<script type="module" src="/src/index.ts"></script>
<p>Vertices will be submitted in 5 second intervals</p>
</div>
<svg id="dag-svg" width="1" height="1" style="transform: translate(50%, 50%); rotate: -90deg"></svg>
<script type="module" src="/src/index.ts"></script>
</body>

</html>
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"@types/d3": "^7.4.3",
"@types/node": "^22.5.5",
"dagre-d3": "^0.6.4",
"ts-loader": "^9.5.1",
"typescript": "^5.6.2",
"vite": "^5.4.6",
"vite-plugin-node-polyfills": "^0.22.0",
"ts-loader": "^9.5.1"
"vite-plugin-node-polyfills": "^0.22.0"
},
"dependencies": {
"@topology-foundation/blueprints": "^0.2.0",
Expand All @@ -23,15 +23,15 @@
"@topology-foundation/object": "^0.2.0",
"@types/d3": "^7.4.3",
"@types/dagre-d3": "^0.6.6",
"d3": "^7.9.0",
"ts-node": "^10.9.2",
"crypto-browserify": "^3.12.0",
"assemblyscript": "^0.27.29",
"stream-browserify": "^3.0.0",
"vm-browserify": "^1.1.2",
"uint8arrays": "^5.1.0",
"crypto-browserify": "^3.12.0",
"d3": "^7.9.0",
"memfs": "^4.11.1",
"process": "^0.11.10",
"react-spring": "^9.7.4"
"react-spring": "^9.7.4",
"stream-browserify": "^3.0.0",
"ts-node": "^10.9.2",
"uint8arrays": "^5.1.0",
"vm-browserify": "^1.1.2"
}
}
37 changes: 30 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ let peers: string[] = [];
let discoveryPeers: string[] = [];
let objectPeers: string[] = [];

async function paint(color: string){
await new Promise((resolve) => setTimeout(resolve, 10000 - Date.now() % 10000));
if (color === "red") colorCRO.paint("#CC0000");
else if (color === "green") colorCRO.paint("#006600");
else if (color === "blue") colorCRO.paint("#0000CC");
else return;
render();
}

const render = () => {
if (topologyObject) {
const gridIdElement = <HTMLSpanElement>document.getElementById("gridId");
Expand Down Expand Up @@ -53,7 +62,7 @@ const render = () => {
paintBlue.style.display = "inline";
}

// Here he hashgraph is rendered
// Here the hashgraph is rendered

const graph_viz = createGraph();

Expand Down Expand Up @@ -136,23 +145,37 @@ async function main() {
});

const button_paint_red = <HTMLButtonElement>document.getElementById("paintRed");
button_paint_red.addEventListener("click", () => {
colorCRO.paint("#CC0000"); // red
button_paint_red.addEventListener("click", async () => {
paint("red");
render();
});

const button_paint_green = <HTMLButtonElement>document.getElementById("paintGreen");
button_paint_green.addEventListener("click", () => {
colorCRO.paint("#006600"); // green
button_paint_green.addEventListener("click", async () => {
paint("green");
render();
});

const button_paint_blue = <HTMLButtonElement>document.getElementById("paintBlue");
button_paint_blue.addEventListener("click", () => {
colorCRO.paint("#0000CC"); // blue
button_paint_blue.addEventListener("click", async () => {
paint("blue");
render();
});

document.addEventListener("keydown", (e) => {
if (!colorCRO) return;
if (e.key === "r") {
paint("red");
render();
} else if (e.key === "g") {
paint("green");
render();
} else if (e.key === "b") {
paint("blue");
render();
}
});

}

main();
22 changes: 11 additions & 11 deletions src/util/hash-graph-viz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ export function renderGraph(graph: dagreD3.graphlib.Graph) {

// Dynamically set the SVG width and height based on graph size
svg.attr("width", graphWidth);
svg.attr("height", Math.max(graphHeight, 200)); // Ensuring minimum height

svg.attr("height", graphHeight);
// Adjust zoom to fit the graph
const svgWidth = parseInt(svg.attr("width")!);
const svgHeight = parseInt(svg.attr("height")!);
// const svgWidth = parseInt(svg.attr("width")!);
// const svgHeight = parseInt(svg.attr("height")!);

const xCenterOffset = (svgWidth - graphWidth) / 2;
const yCenterOffset = (svgHeight - graphHeight) / 2;
// const xCenterOffset = (svgWidth - graphWidth) / 2;
// const yCenterOffset = (svgHeight - graphHeight) / 2;

// Set initial transform to position and scale the graph
svg.call(
zoom.transform as any,
d3.zoomIdentity.translate(xCenterOffset, yCenterOffset)
);
// // Set initial transform to position and scale the graph
// svg.call(
// zoom.transform as any,
// d3.zoomIdentity.translate(xCenterOffset, yCenterOffset)
// );
}, 0);
}