{
const svg = d3.select(DOM.svg(width, height));
const bounds = svg
.append("g")
.attr(
"transform",
`translate(${dimensions.margin.left}, ${dimensions.margin.top})`
);
const yScale = d3
.scaleLinear()
.domain([
0,
d3.max(playerCum, d => d3.max(d.data, dd => dd.cumAcutalPoints))
])
.range([dimensions.boundedHeight, 0])
.nice();
const xScale = d3
.scaleLinear()
.domain([0, d3.max(playerCum, d => d3.max(d.data, dd => dd.cumGP))])
.range([0, dimensions.boundedWidth])
.nice();
const xAxisGenerator = d3.axisBottom().scale(xScale);
const yAxisGenerator = d3.axisLeft().scale(yScale);
let lineGenerator = d3
.line()
.x(d => xScale(d.cumGP))
.y(d => yScale(d.cumPoints));
// Draw data
const lines = bounds.append("g");
lines
.selectAll(".line")
.data(playerCum)
.enter()
.append("path")
.attr("d", d => lineGenerator(d.data))
.style("fill", "none")
.attr("class", "lines")
.style("stroke", d => color1(d.player))
.attr("stroke-opacity", d => {
return highlights.includes(d.player) ? 1 : .1;
})
.style("stroke-width", 2)
.style("stroke-linejoin", "round");
// .on("mouseenter", mouseEnter)
// .on("mouseout", mouseOut);
// console.log(bounds);
// // Draw peripherals
const xAxis = bounds
.append("g")
.attr("class", "x-axis")
.call(xAxisGenerator)
.style("transform", `translateY(${dimensions.boundedHeight}px)`)
.style('opacity', .5)
.call(g => g.select(".domain").remove())
.call(g =>
g
.append("text")
.attr("x", 0)
.attr("y", 30)
.attr("fill", "black")
.attr("text-anchor", "start")
.text("Games Played")
);
const yAxis = bounds
.append("g")
.call(yAxisGenerator)
.call(g => g.select(".domain").remove())
.style('opacity', .5)
.call(g =>
g
.select(".tick:last-of-type text")
.clone()
// .append("text")
.attr("x", 5)
// .attr("y", dimensions.margin.top + 30)
.attr("fill", "black")
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text("Adj. Points")
);
// bounds.append("g").call(grid);
// set initial domain for xAxis
// xScale.domain([0, yDomGames]);
// add label and circle
const playerLabel = bounds
.selectAll(".label")
.data(playerCum)
.enter()
.append("g")
.attr("transform", d => {
return `translate(${xScale(last(d.data).cumGP)}, ${yScale(
last(d.data).cumPoints
)})`;
})
.attr("class", "names")
.attr("opacity", d => {
return highlights.includes(d.player) ? 1 : .1;
});
// .on("mouseenter", mouseEnter)
// .on("mouseout", mouseOut);
const dots = playerLabel
.append("circle")
.attr("r", 4)
.style("stroke", "white")
.style("fill", d => d.colour);
const playerName = playerLabel
.append("text")
.attr("x", 10)
.attr("y", 5)
.style("font-size", ".8em")
.attr("fill", d => d.colour)
.text(d => d.player);
const playerGoals = playerLabel
.append("text")
.attr("x", 10)
.attr("y", 18)
.style("font-size", ".8em")
.attr("fill", d => d.colour)
.text(d => last(d.data).cumgoals);
// function mouseEnter(datum) {
// // console.log(datum);
// // let out = [];
// // out.push(datum);
// // console.log(out);
// //UPDATE FIRST CHART
// d3.selectAll(".lines").style('stroke-opacity', e => {
// return datum.player === e.player ? 1 : .1;
// });
// d3.selectAll(".names").style('opacity', e => {
// // console.log(e);
// return datum.player === e.player ? 1 : .1;
// });
// }
// function mouseOut(datum) {
// //UPDATE FIRST CHART
// d3.selectAll(".lines").style("stroke-opacity", d => {
// // console.log(d.player, highlights.includes(d.player));
// if (highlights.includes(d.player)) {
// return 1;
// } else {
// return .1;
// }
// });
// d3.selectAll(".names").style('opacity', e => {
// // console.log(e);
// return highlights.includes(e.player) ? 1 : .1;
// });
// }
return svg.node();
}