chart = {
let totalWidth = 800;
let totalHeight = 400;
let width = totalWidth / 2;
let height = totalHeight;
let svg = d3
.create("svg")
.attr("width", totalWidth)
.attr("height", totalHeight);
let leftG = svg.append('g').attr('id', "leftG");
let rightG = svg
.append('g')
.attr('id', "rightG")
.attr('transform', 'translate(' + width + ',0)');
leftG
.append("rect")
.attr('x', 0)
.attr('y', 0)
.attr("width", width)
.attr("height", height)
.attr("fill", "blue");
rightG
.append("rect")
.attr('x', 0)
.attr('y', 0)
.attr("width", width)
.attr("height", height)
.attr("fill", "cyan");
let data = [];
for (let i = 0; i < 50; i++) {
data.push({ x: Math.random() * width, y: Math.random() * height });
}
leftG
.selectAll("leftPoints")
.data(data)
.enter()
.append("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", 5)
.attr("fill", "cyan")
.attr('id', (d, i) => "point" + i)
.attr('class', 'leftPoints')
.attr('stroke', 'white')
.attr('stroke-width', 0)
.on('mouseover', function(d, i) {
d3.select(this)
.transition()
.attr('stroke-width', 3);
rightG
.select("#point" + i)
.transition()
.attr('stroke-width', 3);
})
.on('mouseout', function(d, i) {
d3.select(this)
.transition()
.attr('stroke-width', 0);
rightG
.select("#point" + i)
.transition()
.attr('stroke-width', 0);
});
rightG
.selectAll("rightPoints")
.data(data)
.enter()
.append("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", 5)
.attr("fill", "blue")
.attr('id', (d, i) => "point" + i)
.attr('class', 'rightPoints')
.attr('stroke', 'white')
.attr('stroke-width', 0)
.on('mouseover', function(d, i) {
d3.select(this)
.transition()
.attr('stroke-width', 3);
leftG
.select("#point" + i)
.transition()
.attr('stroke-width', 3);
})
.on('mouseout', function(d, i) {
d3.select(this)
.transition()
.attr('stroke-width', 0);
leftG
.select("#point" + i)
.transition()
.attr('stroke-width', 0);
});
return svg.node();
}