Published
Edited
May 11, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3
.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height])
.attr("font-size", 10)
.attr("font-family", "sans-serif");

const chords = chord(matrix);
const max = d3.max(d3.merge(matrix));

const group = svg
.append("g")
.selectAll("g")
.data(chords.groups)
.join("g");

group
.append("path")
.attr("fill", d => color(d.index))
.attr("stroke", d => d3.rgb(color(d.index)).darker())
.attr("d", arc);

const groupTick = group
.append("g")
.selectAll("g")
.data(d => groupTicks(d, parseInt(max / 6)))
.join("g")
.attr(
"transform",
d =>
`rotate(${(d.angle * 180) / Math.PI - 90}) translate(${outerRadius},0)`
);

groupTick
.append("line")
.attr("stroke", "#000")
.attr("x2", 6);

groupTick
// .filter(d => d.value % parseInt(max / 4) === 0)
.append('a')
.attr(
'href',
d => `https://ln.bigsun.xyz/channel/${channels[d.source.index]}`
)
.append("text")
.attr("x", 8)
.attr("dy", ".35em")
.attr("transfox564654rm", d =>
d.angle > Math.PI ? "rotate(180) translate(-16)" : null
)
.attr("text-anchor", d => "start")
.text(d =>
d.value
? `${d.value}sat`
: channel_map.has(channels[d.source.index])
? `${channel_map.get(channels[d.source.index]).peer.name} (${
channels[d.source.index]
})`
: channels[d.source.index]
);

svg
.append("g")
.attr("fill-opacity", 0.67)
.selectAll("path")
.data(chords)
.join("path")
.attr("d", ribbon)
.attr("fill", d => color(d.target.index))
.attr("stroke", d => d3.rgb(color(d.target.index)).darker());

return svg.node();
}
Insert cell
transfers = d3.rollup(
forwards.filter(filterFn),
reduceFn,
d => d.in_channel,
d => d.out_channel
)
Insert cell
Insert cell
Insert cell
Insert cell
matrix = {
let n = channels.length;
var matrix = new Array(n);
for (let i = 0; i < n; i++) {
var row = new Array(n);
for (let j = 0; j < n; j++) {
try {
row[j] = transfers.get(channels[i]).get(channels[j]) || 0;
} catch (err) {
row[j] = 0;
}
}
matrix[i] = row;
}

return matrix;
}
Insert cell
function groupTicks(d, step) {
const k = (d.endAngle - d.startAngle) / d.value;
return d3.range(0, d.value, step).map(value => {
return { value: value, angle: value * k + d.startAngle, source: d };
});
}
Insert cell
chord = d3
.chord()
.padAngle(0.05)
.sortSubgroups(d3.descending)
Insert cell
arc = d3.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius)
Insert cell
ribbon = d3.ribbon()
.radius(innerRadius)
Insert cell
outerRadius = Math.min(width, height) * 0.4 - 30
Insert cell
innerRadius = outerRadius - 20
Insert cell
height = Math.max(1040, width)
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more