viz = {
const viz = d3.create("div").attr("class","viz")
const svg = viz.append("svg")
.attr("width",w)
.attr("height",h)
.attr("viewBox",[0,0,w,h])
const size = 600;
const squareSize = 60;
const authorTooltip = d3.select("body")
.append("div")
.attr("class","writerTooltip")
.style("visibility","hidden")
const scale = d3.scaleLinear()
.domain([0,10])
.range([0,size]);
const swatch = swatches({
colour: d3.scaleOrdinal(["Autores","","Revistas","Lugares",
"Críticos","Artístas","Cursos"],
["#fed7af", "#00ffff", "#89065b", "#ffea47", "#e94f37",
"#6477b9", "#fbd1fb", "#ffa50a", "#ffffff"]),
swatchRadius: 10,})
const author = svg.append("g").attr("class","legend")
.attr("transform",`translate(${w/2-310},100)`)
.append(()=>swatch);
const waffle = svg.append("g")
.attr("transform",`translate(${w/2-290},200)`)
.selectAll("rect")
.data(data)
.enter()
.append("a")
.attr("xlink:href",d=>d.Work)
.attr("target","_blank")
.append("rect")
.attr("class","waffle")
.attr("x",(d,i)=>{
const n = i % 10
return scale(n)
})
.attr("y",(d,i)=>{
const n = Math.floor(i/10)
return scale(n)
})
.attr("width",squareSize-10)
.attr("height",squareSize-10)
.attr("stroke-width",1.5)
.attr("stroke",d=>colorScale(d.Type))
.style("fill",d=> {if (d.Awards!="-"){return pattern.url()}
else {return "transparent"}})
.on("mousemove",function (event,d){
d3.select(this).style("opacity",1).attr("stroke-width",3)
authorTooltip.transition()
.duration(200)
.style("visibility","visible")
authorTooltip.html("<h1>"+d.Name+"("+d.YearWritten+")"+"</h1><br/>"+d.About)
.style("transform","translateY(-55%)")
.style("left",(event.x)+10+"px")
.style("top",(event.y)-15+"px")
})
.on("mouseout",function (event,d){
d3.select(this).style("opacity",1).attr("stroke-width",2)
authorTooltip.transition().style("visibility","hidden")
})
svg.call(pattern)
return viz.node()
}