scatterplotCanvas = {
const context = DOM.context2d(width, height);
let domainX = d3.extent(movies, d => d[attributeX]);
let domainY = d3.extent(movies, d => d[attributeY]);
var width_new = width - margin.left - margin.right - (2*radius);
var height_new = height - margin.top - margin.bottom - (2*radius);
function mapX(value) {
value = (value-domainX[0])/(domainX[1]-domainX[0]);
value = width_new * value;
value = value + margin.left + radius;
return value;
}
function mapY(value) {
value = (value-domainY[0])/(domainY[1]-domainY[0]);
value = height_new * value;
var height_start = height - radius - margin.bottom;
value = height_start - value;
return value;
}
function draw() {
context.clearRect(0, 0, width, height);
context.fillStyle = backgroundColor;
context.fillRect(
margin.left,
margin.top,
width - margin.left - margin.right,
height - margin.top - margin.bottom
);
movies.forEach(item => {
if (item.original_language != "en") {
context.fillStyle = "#0B243B";
} else {context.fillStyle = "#0174DF";}
context.beginPath();
context.arc(
mapX(item[attributeX]),
mapY(item[attributeY]),
item.rating/2,
0,
2 * Math.PI
);
context.globalAlpha = 0.4;
context.fill();
});
}
draw();
return context.canvas;
}