colorHexbinTernaryPlot = {
const node = DOM.svg(width, height);
const svg = d3.select(node);
const chart = svg
.append("g")
.attr("transform", `translate(${width / 2} ${height / 2 + yOffset})`)
.attr("height", 300)
.attr("font-family", "sans-serif")
.attr("id", "chart");
const defs = chart.append("defs");
defs
.append("clipPath")
.attr("id", "trianglePath")
.append("path")
.attr("d", hexBinTernaryPlot.triangle());
const axisLabelsGroup = chart
.append("g")
.attr("class", "axis-labels")
.call(axisLabels, hexBinTernaryPlot.axisLabels());
const gridLinesPaths = hexBinTernaryPlot
.gridLines()
.map(axisGrid => axisGrid.map(d3.line()).join(" "));
const gridGroup = chart
.append("g")
.attr("class", "grid")
.call(grid, gridLinesPaths);
const axisTicksGroups = chart
.append("g")
.attr("class", "ternary-ticks")
.attr("font-size", 10)
.selectAll("g")
.data(hexBinTernaryPlot.ticks())
.join("g")
.attr("class", "axis-ticks");
axisTicksGroups.call(ticks);
chart
.append("g")
.attr("stroke", "#000")
.attr("stroke-opacity", 0.1)
.attr("clip-path", "url(#trianglePath)")
.selectAll("path")
.data(bins)
.join("path")
.attr("d", hexbin.hexagon())
.attr("transform", d => `translate(${d.x},${d.y})`)
.attr("fill", d => color(d.length))
.append("title")
.text(d =>
d
.map(
e => `${e.country}: ${e.agriculture}%, ${e.industry}%, ${e.service}%`
)
.join("\n")
);
return node;
}