sentenceArcsStructs_new = {
const radius = 4
const sty=24
const titleposy=15
const titleposx=margin.left-5
const nodehpos=483
const labelhpos=nodehpos-178
const maxlabelwidth=40
const container = d3.select(DOM.svg(width+margin.left+margin.right,
sentenceheight+margin.top+margin.bottom+24))
container.append("style").text(`
.synt__info{
font-size: 13px;
font-weight: normal;
font-style: italic;
font-family: Palatino;
}
.synt__categ{
font-size: 10px;
font-weight: normal;
font-family: Palatino;
}
`)
container
.append("text")
.attr("x", titleposx)
.attr("y", titleposy)
.attr("text-anchor", "middle")
.attr("alignment-baseline", "middle")
//.attr("class","text-warning")
.attr("font-family", 'inherit')
.style("text-anchor", "start")
.text("Clauses");
container
.append("text")
.attr("x", margin.left+labelhpos)
.attr("y", titleposy)
.attr("text-anchor", "middle")
.attr("alignment-baseline", "middle")
//.attr("class","synt__label")
.attr("font-family", 'inherit')
.style("text-anchor", "start")
.text("Function/type");
//.text("Funzioni e tipi");
/*
container.append("style").text(`
.synt__info{
font-size: 16px;
font-weight: normal;
font-style: italic;
font-family: Book Antiqua,Palatino,Palatino Linotype,Palatino LT STD,Georgia,serif;
}
.synt__categ{
font-size: 12px;
font-weight: normal;
font-family: Book Antiqua,Palatino,Palatino Linotype,Palatino LT STD,Georgia,serif;
}
.synt__label{
font-size: 16px;
font-weight: bold;
font-family: Book Antiqua,Palatino,Palatino Linotype,Palatino LT STD,Georgia,serif;
}
`)
*/
const arcGroup = container
.attr ("id", "periodograph")
.attr("width",null)
.attr("height",null)
.attr("name", lisid)
.append("g")
//.style('pointer-events', 'all')
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
// create the nodes
const nodes = arcGroup.selectAll("nodes")
.data(data_frasi.nodes.slice(1))
.enter().append("circle")
.attr("cx", margin.left+nodehpos)
.attr("cy", d => sty+yScale(d.visible))
.attr("r", radius)
//.attr("fill", d=> sentenceFunctionsColor(d.type))
.attr("fill", d => colorssp(maptypestopalette[d.type]))
.attr("id", d => d.visible)
function ypostxt(label){
//delta = (_fontsize * textarea.split("\n").length) / 2;
const label_array = wrap_text_array(label, maxlabelwidth);
return yScale(label)+ -(8 * label_array.length)/2
//return label_array.length<3? yScale(label)+3: yScale(label)-(5*(label_array.length-1))
}
function syntfunctype(funty){
const funty_array = wrap_text_array(funty, maxlabelwidth);
return (funty_array.length<2? 0: -(2.5 * funty_array.length))
}
// This code builds up the SVG path element; see nodesAndArcs for details
function buildArc(d) {
let start = sty+yScale(idToNode[d.source].visible);
let end = sty+yScale(idToNode[d.target].visible);
let lor=true;
let nodeoffset=4
if (isNaN(start))
return
const arcPath = ['M', margin.left+nodehpos+nodeoffset, start, 'A', (Math.abs(start - end)/2), ',', Math.abs(start-end)/2, 0,0,",",
lor ? 1: 0, margin.left+nodehpos+nodeoffset, end].join(' ');
return arcPath;
}
function buildReverseArc(d) {
let start = sty+yScale(idToNode[d.source].visible);
let end = sty+yScale(idToNode[d.target].visible);
let lor=true;
let nodeoffset=4
if (start < end && d.type.includes ('coord')){//.includes('coord')){
//console.log('here')
lor=false;
nodeoffset=-4
}
else
return
if (start==null)
return
const arcPath = ['M', margin.left+nodehpos+nodeoffset, start, 'A', Math.abs(start - end)/2, ',', Math.abs(start-end)/2, 0,0,",",
lor ? 1: 0, margin.left+nodehpos+nodeoffset, end].join(' ');
//console.log(start+' - '+end+', '+d.type+'; '+arcPath)
return arcPath;
}
// create the arcs
var arcs = arcGroup.selectAll("arcs")
.data(data_frasi.links.slice(1))
.enter().append("path")
.attr("d", d => buildArc(d))
.style("fill", "none")
.style('stroke-width', 0.2)
.attr("stroke", 'lightgray');//d => sentenceFunctionsColor(d.type));
// create the arcs for Coordinate
var arcs_coord = arcGroup.selectAll("arcs")
.data(data_frasi.links.slice(1))
.enter().append("path")
.attr("d", d => buildReverseArc(d))
.style("fill", "none")
.style('stroke-width', 0.2)
.attr("stroke", 'lightgray');//d => sentenceFunctionsColor(d.type));
// create the node labels
const nodeLabels = arcGroup.selectAll("nodeLabels")
.data(data_frasi.nodes.slice(1))
.enter().append("text")
//.attr("x", margin.left+labelhpos)
.attr("x", margin.left-10)
//.attr("y", d => yScale(d.visible))
.attr("dominant-baseline", "middle")
.attr("y", d=>sty+ yScale(d.visible)+syntfunctype(d.visible))
.attr("class","synt__info")
.style("font-family","Book Antiqua,Palatino,Palatino Linotype,Palatino LT STD,Georgia,serif")
.style("text-anchor", "start")
.text(d => d.visible)
// the synctatic function and types
const syntfun = arcGroup.selectAll("syntfun")
.data(data_frasi.nodes.slice(1))
.enter().append("text")
//.attr("x", margin.left-10)
.attr("x", margin.left+labelhpos)
.attr("y", d => sty+ yScale(d.visible)+syntfunctype(clauseFunctions[d.type]+", "+getTypes(d.s_type)))
//.attr("y", d=>ypostxt(d.visible))
.attr("dominant-baseline", "middle")
.attr("class","synt__categ")
.style("text-anchor", "start")
.style("font-family","Book Antiqua,Palatino,Palatino Linotype,Palatino LT STD,Georgia,serif")
.style("letter-spacing", 0)
.text(d=> clauseFunctions[d.type]+", "+getTypes(d.s_type))
// mouseover animations
nodes.on('mouseover', function(event, d) {
// Highlight selected node
d3.select(this).style("fill", d=>colorssp(maptypestopalette[d.type]));//sentenceFunctionsColor2(d.type));
var targetids=[]
// Highlight arcs
arcs
.style('stroke', function (arcd) {
if (arcd.source === d.id) { targetids.push(arcd.target)}; if (arcd.target === d.id) { targetids.push(arcd.source)};
return arcd.source === d.id || arcd.target === d.id ? d=> sentenceFunctionsColor2(d.type) : 'lightgray';})//d=> sentenceFunctionsColor(d.type);})
.style('stroke-width', function (arcd) {
return arcd.source === d.id || arcd.target === d.id ? 2 : 0.3;})
//arcs_coord
arcs_coord
.style('stroke', function (arcd) {
if (arcd.source === d.id) { targetids.push(arcd.target)}; if (arcd.target === d.id) { targetids.push(arcd.source)};
return arcd.source === d.id || arcd.target === d.id ? d=> sentenceFunctionsColor2(d.type) : 'lightgray';})
.style('stroke-width', function (arcd) {
return arcd.source === d.id || arcd.target === d.id ? 2 : 0.3;})
// Highlight syntactic types
syntfun
.style('fill', function (syntfund) {
//return syntfund.visible+syntfund.s_type === d.visible+d.s_type ? 'steelblue' : 'black' ;});
return (syntfund.visible+syntfund.s_type === d.visible+d.s_type || targetids.includes(syntfund.id)) ? darken('steelblue') : 'black' ;})
.style('font-weight', function (syntfund) {
//return syntfund.visible+syntfund.s_type === d.visible+d.s_type ? 'steelblue' : 'black' ;});
return (syntfund.visible+syntfund.s_type === d.visible+d.s_type || targetids.includes(syntfund.id)) ? 'bold' : 'normal' ;});
// Highlight node labels
nodeLabels
.style("fill", function (nodeLabeld){
return nodeLabeld.id == d.id || targetids.includes(nodeLabeld.id) ? 'black' : 'black';})
.style('font-weight', function (nodeLabeld) {
return nodeLabeld.id == d.id || targetids.includes(nodeLabeld.id) ? 'bold' : 'normal';})
});
// remove highlighting when user mouse moves out of node by restoring default colors and thickness
nodes.on('mouseout', function (event, d) {
nodes.style("fill", d=> colorssp(maptypestopalette[d.type]));//sentenceFunctionsColor(d.type));
arcs.style('stroke', 'lightgray')
arcs.style('stroke-width', 0.5);
arcs_coord.style('stroke', 'lightgray')
arcs_coord.style('stroke-width', 0.5);
syntfun.style('fill','black');
syntfun.style('font-weight','normal');
//nodeLabels.style('fill','black');
nodeLabels.style('font-weight','normal');
nodeLabels.attr("class","synt__info")
});
container.selectAll("text")
.each(function(d, i) { wrap_text_nchar(d3.select(this), maxlabelwidth) });
return container.node();
}