Published
Edited
Jun 22, 2020
6 forks
47 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
align = d3.sankeyCenter
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
Insert cell
Insert cell
Insert cell
chart = {
let graph = clone(graph3);

const svg = d3
.create("svg")
.attr("width", svgWidth)
.attr("height", svgHeight);

let backgroundRect = svg
.append('rect')
.attr("x", 0)
.attr("y", 0)
.attr("width", svgWidth)
.attr("height", svgWidth)
.style("fill", bkdColour);

let defs = svg.append("defs");
let hash = defs
.append("pattern")
.attr("id", "hash")
.attr("width", 6)
.attr("height", 8)
.attr("patternUnits", "userSpaceOnUse")
.attr("patternTransform", "rotate(135)");

hash
.append("rect")
.attr("width", 3)
.attr("height", 8)
.attr("fill", mainColour);

let gradientStart = defs
.append("linearGradient")
.attr("id", "linearStart")
.attr("x1", 0)
.attr("y1", 0)
.attr("x2", "100%")
.attr("y2", 0);

let gradientBottom = defs
.append("linearGradient")
.attr("id", "linearBottom")
.attr("x1", 0)
.attr("y1", 0)
.attr("x2", 0)
.attr("y2", "100%");

let gradientMiddle = defs
.append("linearGradient")
.attr("id", "linearMiddle")
.attr("x1", 0)
.attr("y1", 0)
.attr("x2", 0)
.attr("y2", "100%");

gradientStart
.append("stop")
.attr("offset", "0%")
.attr("stop-color", bkdColour);
gradientStart
.append("stop")
.attr("offset", "100%")
.attr("stop-color", mainColour);

gradientBottom
.append("stop")
.attr("offset", "0%")
.attr("stop-color", mainColour);
gradientBottom
.append("stop")
.attr("offset", "50%")
.attr("stop-color", mainColour);
gradientBottom
.append("stop")
.attr("offset", "100%")
.attr("stop-color", bkdColour);

gradientMiddle
.append("stop")
.attr("offset", "0%")
.attr("stop-color", bkdColour);
gradientMiddle
.append("stop")
.attr("offset", "50%")
.attr("stop-color", mainColour);
gradientMiddle
.append("stop")
.attr("offset", "100%")
.attr("stop-color", mainColour);

let g = svg
.append("g")
.attr("transform", "translate(" + chartPadding + "," + chartPadding + ")");

let rects = g
.selectAll("rect")
.data(graph.nodes)
.join("rect")
.attr("x", d => d.x0)
.attr("y", d => d.y0)
.attr("height", nodeHeight)
.attr("width", nodeWidth)
.style("stroke", bkdColour)
.style("fill", nodeFill);

const link = g
.append("g")
.selectAll("g")
.data(graph.links)
.join("g")
.append("path")
.attr("fill", linkFill)
.attr("stroke-width", linkStrokeWidth)
.style("stroke", linkStroke)
.attr("d", d => d.path);

let labels = g
.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.selectAll("text")
.data(graph.nodes)
.join("text")
.attr("x", d => d.labelX)
.attr("y", d => d.labelY)
.attr("text-anchor", d => d.labelAlign)
.text(d => d.name);

if (rotate) {
svg.attr("width", svgHeight).attr("height", svgWidth);

labels
.attr("transform", function(d) {
return "rotate(270, " + d.labelX + ", " + d.labelY + ")";
})
.attr("dy", "0.35em");

let cx = chartHeight / 2 + chartPadding / 2;
let cy = chartHeight / 2 + chartPadding / 2;

g.attr(
"transform",
"translate(0, " + chartPadding + ") rotate(90, " + cx + ", " + cy + " )"
);
}

return svg.node();
}
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
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