Published
Edited
May 16, 2022
6 stars
Also listed in…
Sankey
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable hovered = null
Insert cell
Insert cell
Insert cell
tradingDayData[day_index].options.filter((x) => {
return +x.expiry === clicked?.name;
})
Insert cell
filteredData = tradingDayData[day_index].options.filter((x) => {
if (clicked) {
if (clicked.depth === 0) {
return clicked.name === +x.expiry && x[valueProperty] > valueLimit;
} else if (clicked.depth === 1) {
return clicked.name === +x.strike && x[valueProperty] > valueLimit;
} else if (clicked.depth === 2) {
return clicked.name === x.type && x[valueProperty] > valueLimit;
}
} else return x[valueProperty] > valueLimit;
})
Insert cell
// valueProp = "volume"
Insert cell
DayData = {
const rolledup = d3.rollups(
filteredData,
(v) => [v, d3.sum(v, (d) => d[valueProperty])],
(d) => +d.expiry,
(d) => d.strike
);
return rolledup;
}
Insert cell
DayData[0] //[0][1]
Insert cell
Insert cell
mutable tempArr = []
Insert cell
nodes = links.reduce((acc, each) => {
//source
const sourceMatch = acc.filter((d) => d.name === each.source);
if (sourceMatch.length === 0) {
acc.push({ name: each.source }); //dataItem: each.dataItem
}

//target
const targetMatch = acc.filter((d) => d.name === each.target);
if (targetMatch.length === 0) {
acc.push({ name: each.target }); //, dataItem: each.dataItem
}
return acc;
}, [])
Insert cell
SankeyLayout = Sankey.sankey()
.nodeId((d) => d.name)
.nodeSort((a, b) => {
d3.descending(a.name, b.name);
})
.nodeWidth(nodeWidth)
.nodePadding(padding)
.nodeId((d) => d.name)
.nodeAlign(Sankey.sankeyLeft)
.extent([
[5, 5],
[width, height]
])
// .nodeSort(customSorting) //(a, b) => d3.descending(a.value, b.value))
.linkSort((a, b) => d3.descending(a.value, b.value))
Insert cell
Insert cell
selectedDataSearch = (search) =>
tradingDayData[day_index].options.find((item) => item.OC.series === search)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
leftMargin = 120
Insert cell
verticalPadding = labelSize / 2
Insert cell
viewBox = `${-leftMargin} ${-verticalPadding} ${width + 250} ${
height + verticalPadding
}`.split(" ")

Insert cell
labelPositioner = (d) => {
const startLabel = (d) => d.depth === 0;
const strikeLabel = (d) => d.depth === 2;
// (d) => d.x0 < leftMargin;
// const endLabel = (d) => d.x0 > width - 100;

// ? d.x0 - (d.x1 - d.x0) / 2
return `translate(${
startLabel(d) ? d.x0 - leftMargin : strikeLabel(d) ? d.x1 + 15 : d.x1 + 15
},${(d.y1 + d.y0) / 2})`;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more