|
25 | 25 | </style> |
26 | 26 |
|
27 | 27 | <body> |
| 28 | + <h4 id="title"></h4> |
| 29 | + <svg id="graph"></svg> |
| 30 | + |
28 | 31 | <script src="https://d3js.org/d3.v4.min.js"></script> |
29 | 32 | <script> |
30 | 33 | // 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}, |
32 | 35 | width = 1400 - margin.left - margin.right, |
33 | 36 | height = 600 - margin.top - margin.bottom; |
34 | 37 |
|
35 | 38 | // append the svg object to the body of the page |
36 | 39 | // appends a 'group' element to 'svg' |
37 | 40 | // moves the 'group' element to the top left margin |
38 | | - var svg = d3.select("body").append("svg") |
| 41 | + var svg = d3.select("#graph") |
39 | 42 | .attr("width", width + margin.right + margin.left) |
40 | 43 | .attr("height", height + margin.top + margin.bottom) |
41 | 44 | .append("g") |
|
53 | 56 | d3.request(`http://localhost:3000/reputations`, function(error, res) { |
54 | 57 | if (error) throw error; |
55 | 58 |
|
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}`); |
58 | 62 |
|
59 | 63 | if (!reputations.length) { |
60 | | - console.log("No reputations found!"); |
| 64 | + d3.select("body").append("p").text("No reputations found!") |
61 | 65 | return; |
62 | 66 | } |
63 | 67 |
|
64 | | - keyLength = reputations[0].id.length; |
| 68 | + keyLength = reputations[0].key.length; |
65 | 69 |
|
66 | 70 | ////////////// |
67 | 71 | // Patricia Tree Rendering |
68 | 72 |
|
69 | | - const treeNodes = reputations.map(rep => newNode(rep.id, rep.value)); |
| 73 | + const treeNodes = reputations.map(rep => newNode(rep.key, rep.decimalValue)); |
70 | 74 | const treeRoot = treeNodes.reduce(insert, newNode("0x", null)); |
71 | 75 | root = d3.hierarchy(finalize(treeRoot)); |
72 | 76 |
|
|
0 commit comments