scatterplot = {
return {
init: function init(){
this.svg = d3.create("svg")
.attr("viewBox", [0,0,width,height]);
if (!(log)){
this.y = d3.scaleLinear()
.domain([0,10]).nice()
.range([height - margin.bottom, margin.top])
}
if (log){
this.y = d3.scaleLog()
.base(10)
.domain([0.1, 200])
.range([height - margin.bottom, margin.top])
.clamp(true);
}
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));
if (!(log)) this.y.domain(d3.extent(new_data, d=>d.time));
if (log) this.y.domain([0.0001, d3.max(new_data, d=>d.time)]);
this.svg.select(".x.axis")
// .transition()
.call(this.xAxis);
this.svg.select(".y.axis")
// .transition()
.call(this.yAxis);
let plot = this;
function onMouseOver(d,i,c){
console.log(d,i,c);
// Specify where to put label of text
debugger;
plot.svg.append('text')
.attr('id', "t" + i.size + "-" + i.type)
.attr('x', plot.x(i.size) + 3)
.attr('y', plot.y(i.time) - 5)
.text(i.dim + ' - ' + i.samples);
}
function onMouseOut(d,i){
// Select text by id and then remove
d3.select("#"+CSS.escape("t" + i.size + "-" + i.type)).remove(); // Remove text location
}
let circle = this.svg//.append("g")
.selectAll("circle")
.data(new_data, d=>{
let key = d.type+d.size
return d? key:this.id;
});
// circle.exit().remove();
// debugger;
circle.join(
enter => enter.append('circle')
.attr("stroke-width", 0.5)
// .attr("fill", "none")
.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";
})
.on("mouseover", onMouseOver)
.on("mouseout", onMouseOut)
.transition()
.attr("r", 1)
,
update => update.transition()
.attr("cy", d => this.y(d.time))
.attr("cx", d=>this.x(d.size))
,
exit => exit.remove()
)
}
}
}