Skip to content

Commit 20ac6be

Browse files
committed
include and display tx value and fee
1 parent 01e02e6 commit 20ac6be

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function visualize(txGraph, containerSelector, margin) {
3838
.sort(function(a, b) { return b.dy - a.dy; });
3939

4040
link.append("title")
41-
.text(function(d) { return d.source.name + " → " + d.target.name + "\n" + d.value; });
41+
.text(function(d) { return d.source.name + " → " + d.target.name });
4242

4343
var node = svg.append("g").selectAll(".node")
4444
.data(data.nodes)
@@ -56,7 +56,7 @@ function visualize(txGraph, containerSelector, margin) {
5656
.style("fill", function(d) { return d.color = color(d.name.replace(/ .*/, "")); })
5757
.style("stroke", function(d) { return d3.rgb(d.color).darker(2); })
5858
.append("title")
59-
.text(function(d) { return d.name + "\n" + d.value; });
59+
.text(function(d) { return d.name + "\nvalue: " + d.value + "\nfee: " + d.fee; });
6060

6161
node.append("text")
6262
.attr("x", -6)
@@ -106,7 +106,12 @@ function visualize(txGraph, containerSelector, margin) {
106106
function exportData(graph) {
107107
var txNodes = graph.getAllNodes()
108108
var nodes = txNodes.map(function(n) {
109-
return { name: n.id }
109+
var value, fee
110+
if(n.tx) {
111+
value = n.tx.value
112+
fee = n.tx.fee
113+
}
114+
return { name: n.id, fee: fee, value: value }
110115
})
111116

112117
var links = txNodes.reduce(function(memo, n, i) {

test/visualize.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ describe('visualize', function() {
88
var txs = buildTxs()
99
var graph = new TxGraph()
1010

11-
txs.forEach(function(tx) { graph.addTx(tx) })
11+
txs.forEach(function(tx) {
12+
tx.value = parseInt(Math.random() * 1000)
13+
tx.fee = parseInt(Math.random() * 10)
14+
graph.addTx(tx)
15+
})
1216

1317
describe('exportData', function() {
1418
var data = exportData(graph)
@@ -17,6 +21,14 @@ describe('visualize', function() {
1721
var expectedIds = [0, 3, 4, 15, 16, 13, 2, 5, 7, 14, 1, 10, 6, 11, 8, 9, 12]
1822
var actualNames = data.nodes.map(function(n) { return n.name })
1923
assert.deepEqual(actualNames, expectedIds.map(fakeTxId))
24+
25+
data.nodes.forEach(function(n) {
26+
var tx = graph.findNodeById(n.name).tx
27+
if(!tx) return;
28+
29+
assert.equal(n.fee, tx.fee)
30+
assert.equal(n.value, tx.value)
31+
})
2032
})
2133

2234
it('returns the expected links', function() {

0 commit comments

Comments
 (0)