Skip to content

Commit 7b4a736

Browse files
committed
Include root hash in tree visualizer
1 parent 6707e0e commit 7b4a736

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

packages/reputation-miner/ReputationMinerClient.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ class ReputationMinerClient {
4040

4141
// Serve data for visualizers
4242
this._app.get("/reputations", async (req, res) => {
43+
const currentHash = await this._miner.getRootHash();
4344
const reputations = Object.keys(this._miner.reputations).map(key => {
4445
const decimalValue = ethers.utils.bigNumberify(`0x${this._miner.reputations[key].slice(2, 66)}`, 16).toString();
4546
return { key, decimalValue }
4647
})
47-
return res.status(200).send(reputations);
48+
return res.status(200).send({ rootHash: currentHash, reputations: reputations });
4849
});
4950

5051
this._app.get("/network", async (req, res) => {

packages/reputation-miner/viz/repTree.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@
2525
</style>
2626

2727
<body>
28+
<h4 id="title"></h4>
29+
<svg id="graph"></svg>
30+
2831
<script src="https://d3js.org/d3.v4.min.js"></script>
2932
<script>
3033
// Set the dimensions and margins of the diagram
31-
var margin = {top: 30, right: 200, bottom: 30, left: 30},
34+
var margin = {top: 30, right: 182, bottom: 30, left: 8},
3235
width = 1400 - margin.left - margin.right,
3336
height = 600 - margin.top - margin.bottom;
3437

3538
// append the svg object to the body of the page
3639
// appends a 'group' element to 'svg'
3740
// moves the 'group' element to the top left margin
38-
var svg = d3.select("body").append("svg")
41+
var svg = d3.select("#graph")
3942
.attr("width", width + margin.right + margin.left)
4043
.attr("height", height + margin.top + margin.bottom)
4144
.append("g")
@@ -53,20 +56,21 @@
5356
d3.request(`http://localhost:3000/reputations`, function(error, res) {
5457
if (error) throw error;
5558

56-
const reputations = JSON.parse(res.response)
57-
.map(rep => { return { id: rep.key, value: rep.decimalValue } });
59+
const { rootHash, reputations } = JSON.parse(res.response);
60+
61+
d3.select("#title").text(`Root Hash: ${rootHash}`);
5862

5963
if (!reputations.length) {
60-
console.log("No reputations found!");
64+
d3.select("body").append("p").text("No reputations found!")
6165
return;
6266
}
6367

64-
keyLength = reputations[0].id.length;
68+
keyLength = reputations[0].key.length;
6569

6670
//////////////
6771
// Patricia Tree Rendering
6872

69-
const treeNodes = reputations.map(rep => newNode(rep.id, rep.value));
73+
const treeNodes = reputations.map(rep => newNode(rep.key, rep.decimalValue));
7074
const treeRoot = treeNodes.reduce(insert, newNode("0x", null));
7175
root = d3.hierarchy(finalize(treeRoot));
7276

0 commit comments

Comments
 (0)