visualization = {
const data = delimited_text;
const svg = d3.create('svg')
.attr("width", width)
.attr("height", height);
const g = svg.append('g').attr('transform','translate(0,20)').attr('id','texts');
const text = g.append('text').attr('font-size',fontSize);
const tspan = text.selectAll('tspan')
.data(data)
.enter().append('tspan');
const tspan2 = tspan.selectAll('tspan')
.data(d=>d.text.split(' ').map(dd=>({text:dd,category:d.category,style:d.style})))
.enter().append('tspan');
const tspan3 = tspan2.selectAll('tspan')
.data(d=>[d,{text:' ',category:'white-space',style:'white-space'}])
.enter().append('tspan')
.attr('class',(d,i)=>i==0?'text':'white-space')
.attr('fill',d=>color(d.category))
.text(d=>d.text)
const g2 = svg.append('g').attr('transform','translate(0,20)').attr('id','lines');
const lines = []
setTimeout(function(){
tspan2.each(function(d){
const bcr=this.getBoundingClientRect();
if (bcr.x+bcr.width>width){
d3.select(this).attr('x',0).attr('dy',dy);
}
})
let first_y;
let first_x;
d3.selectAll('tspan.text').each(function(d){
const bcr = this.getBoundingClientRect();
const css = window.getComputedStyle(this, null);
if (!first_y) first_y=bcr.y;
if (!first_x) first_x=bcr.x;
const obj = {
text:d.text,
width:bcr.width,
height:bcr.height,
x:bcr.x-first_x,
y:bcr.y-first_y,
category:d.category,
style:d.style
}
lines.push(obj);
})
g2.selectAll('line')
.data(lines)
.enter()
.append('line')
.attr('x1',d=>d.x)
.attr('x2',d=>d.x+d.width)
.attr('y1',d=>d.y+y_pos(d.style))
.attr('y2',d=>d.y+y_pos(d.style))
.attr('stroke',d=>color(d.category))
}, 50);
return svg.node();
}