scatterplot = {
return {
init: function init(){
this.svg = d3.create("svg")
.attr("viewBox", [0,0,width,height]);
this.y = d3.scaleLinear()
.domain([0,10]).nice()
.range([height - margin.bottom, margin.top])
this.x = d3.scaleLinear()
.domain([0,10]).nice()
.range([margin.left, width - margin.right])
this.xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(this.x).ticks(width / 80))
.call(g => g.select(".domain").remove())
.call(g => g.append("text")
.attr("x", width)
.attr("y", margin.bottom - 4)
.attr("fill", "currentColor")
.attr("text-anchor", "end")
.text("Size (MB)"))
this.yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(this.y))
.call(g => g.select(".domain").remove())
.call(g => g.append("text")
.attr("x", -margin.left)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.text("time (ms)"))
this.svg.append("g")
.attr("class", "y axis")
.call(this.yAxis);
this.svg.append("g")
.attr("class", "x axis")
.call(this.xAxis);
},
update: function (new_data){
this.x.domain(d3.extent(new_data, d=>d.size));
this.y.domain(d3.extent(new_data, d=>d.time));
let circle = this.svg
.selectAll("circle")
.data(new_data, d=>{
let key = d.type+d.size
return d? key:this.id;
});
this.svg.select(".x.axis")
.call(this.xAxis);
this.svg.select(".y.axis")
.call(this.yAxis);
circle.join(
enter => enter.append('circle')
.attr("stroke-width", 0.5)
.attr("r", 0)
.attr("cx", d => {
return this.x(d.size)
})
.attr("cy", d => {
return this.y(d.time);
})
.attr("stroke", d => {
if(d.type == "row_major") return "red";
if(d.type == "col_major") return "blue";
})
.attr("fill", d => {
if(d.type == "row_major") return "red";
if(d.type == "col_major") return "blue";
})
.transition()
.attr("r", 1),
update => update.transition()
.attr("cy", d => this.y(d.time))
.attr("cx", d=>this.x(d.size))
,
exit => exit.remove()
)
}
}
}