chart = {
let parent = this;
parent = document.createElement("div");
const svg = d3.select(DOM.svg(width, height));
const g = svg
.append("g")
.attr("transform", (d, i) => `translate(${margin.left} ${margin.top})`);
const members = svg
.append("g")
.attr("fill", "steelblue")
.selectAll("rect")
.data(data.filter(d => d.count !== 0))
.enter()
.append("rect")
.attr("x", (d) => x(d.start + d.count-1))
.attr("y", (d) => y(d.name))
.attr("rx", 3)
.attr("fill", (d) => color(d.region))
.attr("height", y.bandwidth()-(y.bandwidth()/50))
.attr("width", x.bandwidth()-(x.bandwidth()/50));
const places = svg.append('g')
.selectAll("circle")
.data(data.filter(d => d.country === "Secretary" && d.count !== 0))
.enter()
.append("circle")
.attr('cx', (d) => x(d.start + d.count -1) + (x.bandwidth()/2))
.attr('cy', (d) => y(d.name) + (y.bandwidth()/2))
.attr('r', 6)
// .attr('stroke', 'white')
.attr("fill", "white");
// .attr("opacity", (d) => opacity(d.count))
// .attr("height", y.bandwidth())
// .attr("width", (d) => x(d.end) - x(d.start));
var s = svg.selectAll(".shapes")
.data(data.filter(d => d.mark === 2))
var sg = s.enter()
.append("g")
.attr("class", "shapes")
.attr("transform", function(d,i) {
return "translate(" + (x(d.start + d.count -1) + (x.bandwidth()/2)) + ","+ (y(d.name) + (y.bandwidth()/2))+ ")"
})
.attr("fill", "white")
.attr("stroke-width", 1)
sg.append("path")
.attr("d", function(d) {return d3.symbol().type(d3.symbolStar).size("75")()})
.attr("stroke", "black")
// .attr('cx', (d) => x(d.start + d.count -1) + (x.bandwidth()/2))
//.attr('cy', (d) => y(d.name) + (y.bandwidth()/2))
const tooltip = d3.select(document.createElement("div")).call(createTooltip);
const line = svg
.append("line")
.attr("y1", margin.top - 10)
.attr("y2", height - margin.bottom)
.attr("stroke", "pink")
.style("pointer-events", "none");
// members.attr("transform", (d, i) => `translate(0 ${y(i)})`);
members
.each(getRect)
.on("mouseover", function (event, d) {
let [xt, yt] = d3.pointer(event);
d3.select(this).select("rect").attr("fill", "white");
tooltip.style("opacity", 1).html(getTooltipContent(d));
})
.on("mouseleave", function (event, d) {
d3.select(this).select("rect").attr("fill", color(d.region));
tooltip.style("opacity", 0);
svg.selectAll(".yAxis .tick").selectAll("text").style("fill", "white")
});
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
svg.on("mousemove", function (event, d) {
let [xt, yt] = d3.pointer(event);
line.attr("transform", `translate(${xt} 0)`);
yt += 20;
svg.selectAll(".yAxis .tick").each(function(d) {
d3.select(this).select("text").style("fill", function() {
var value = data.filter(function(e) {
return e.years === x.invert(xt) && e.count !== 0 && d === e.name
})[0];
return value ? "yellow" : "black";})
})
if (xt > width / 2) xt -= 100;
tooltip.style("left", xt + "px").style("top", yt + "px");
});
parent.appendChild(svg.node());
parent.appendChild(tooltip.node());
parent.groups = members;
//let offset = height - margin.bottom / 3 + 50;
let offset = margin.top + 420;
svg
.append("text")
.attr("class", "header")
.attr("x", 370)
.attr("y", offset -420)
.attr("dy", "1em")
.attr("text-anchor", "start")
.style("font-size", width / 60)
.style("font-weight", 400)
//.style("text-transform", "uppercase")
.html("")
// .append("tspan")
.attr("font-weight", 700)
.text("circle = Secretary, star = Chair of Trustees");
svg
.append("text")
.attr("class", "header")
.attr("x", margin.left)
.attr("y", offset -250)
.attr("dy", "1em")
.attr("text-anchor", "start")
.style("font-size", width / 60)
.style("font-weight", 400)
// .style("text-transform", "uppercase")
.html("")
// .append("tspan")
.attr("font-weight", 700)
.text("Median number of Trustees by Year = 9");
svg
.append("text")
.attr("class", "header")
.attr("x", margin.left)
.attr("y", offset -200)
.attr("dy", "1em")
.attr("text-anchor", "start")
.style("font-size",18)
.style("font-weight", 400)
// .style("text-transform", "uppercase")
.html("")
// .append("tspan")
.attr("font-weight", 700)
.text("Median number of years as Trustee/Secretary = 4");
svg
.append("text")
.attr("class", "header")
.attr("x", margin.left)
.attr("y", offset -350)
.attr("dy", "1em")
.attr("text-anchor", "start")
.style("font-size",18)
.style("font-weight", 400)
// .style("text-transform", "uppercase")
.html("")
// .append("tspan")
.attr("font-weight", 700)
.text("AVERAGE Age when Appointed (Median): 52 (55). AVERAGE Age when Resigned (Median): 57 (58)");
svg
.append("text")
.attr("class", "header")
.attr("x", margin.left)
.attr("y", offset -300)
.attr("dy", "1em")
.attr("text-anchor", "start")
.style("font-size",18)
.style("font-weight", 400)
// .style("text-transform", "uppercase")
.html("")
// .append("tspan")
.attr("font-weight", 700)
.text("AGE RANGE when Appointed: 25-65. AGE RANGE when Resigned 32-74");
g.append("g")
.attr("transform", `translate(${margin.left / 3 - 5},${-15})`)
.append(() =>
legend({
color: color,
title: "",
width: 300
})
);
svg
.append("text")
.attr("class", "legend_footer")
.attr("x", width - margin.left)
.attr("y", height - margin.bottom / 3)
.text(footer);
//AVERAGE Age when Appointed (Median): 52 (55). AVERAGE Age when Resigned (Median): 57 (58)
//AGE RANGE when Appointed: 25-65. AGE RANGE when Resigned 32-74
// console.log(JSON.stringify(data))
return parent;
}