{ let max = d3.max(dataL, d=>d3.max(d.teams,k=>k.score));
let domainLigas = d3.extent(dataL, d=>+d.ligaN);
let colorsLigas = d3.quantize(d3.interpolateHcl("#f3a012" ,"#7625a2"), (domainLigas[1]-domainLigas[0])+1 );
let scaleLigas = d3.scaleOrdinal().domain(d3.range(domainLigas[0],domainLigas[1]+1,1)).range(colorsLigas);
let domainLeaders = d3.extent(dataL, d=>+d.teamBattle.nbLeaders);
let colorsLeaders = d3.quantize(d3.interpolateHcl("#903c74" ,"#560b3e"), (domainLeaders[1]-domainLeaders[0])+1 );
let scaleLeaders = d3.scaleOrdinal().domain(d3.range(domainLeaders[0],domainLeaders[1]+1,1)).range(colorsLeaders);
dataL.sort( (a,b)=>a.startAt-b.startAt );
let order = dataL.map(d=>d.time.short);
let opctRelProm = 0.46;
return Plot.plot({
marginBottom:60,
marginTop:68,
insetBottom:6,
insetLeft:4,
width:1000,
height:640,
x:{tickRotate:0, domain:order, reverse:true, tickSize:0},
fx: {grid: true},
marks: [
Plot.tickY(dataL, {x:d=>d.time.short, y:max, dy:-58, stroke:d=>scaleLigas(+d.ligaN), strokeWidth:7}),
//Plot.tickY(dataL, {x:d=>d.time.short, y:max, dy:idy, stroke:d=>scaleLeaders(d.teamBattle.nbLeaders), strokeWidth:10}),
//Text Liga Division number
/*
Plot.barY(dataL, {x:d=>d.time.short, y1:max ,y2:max-26, dy:-54, stroke:d=>scaleLigas(+d.ligaN),
//fill:d=>scaleLeaders(d.teamBattle.nbLeaders),
strokeWidth:2, r:2,
}),
*/
Plot.text(dataL, {x:d=>d.time.short,y:max, dy:-44, text: d=>d.fullName.split(" ").slice(-1), fontSize:17, fontWeight:"bold", fill:d=>scaleLigas(+d.ligaN) }),
//Plot.text(dataL, {x:d=>d.time.short,y:max, dy:-28, text: d=>d.teamBattle.nbLeaders+" players", fontSize:8 }),
//Number Leaders
Plot.text(dataL, {x:d=>d.time.short,y:max, dy:-22, fontSize:11, //fill:"white", strokeWidth:8,fontWeight:"bold",
//stroke:d=>scaleLeaders(d.teamBattle.nbLeaders),
//fontWeight:d=>d.teamBattle.nbLeaders*100,
text: d=>d.teamBattle.nbLeaders+"👤"
//text: d=>""+d.teamBattle.nbLeaders+"", fontWeight:"bold", fontSize:9,
}),
//Time Control background and text
Plot.barY(dataL, {x:d=>d.time.short,y1:0 ,y2:max, fill:d=>d.timeControl, strokeWidth:1, stroke:d=>(d.timeControl==rdHighlight?"gray":"none"), strokeOpacity:1, fillOpacity:d=>(d.timeControl==rdHighlight?0.1:0.08)
//opacity:0.08
}),
//Plot.barY(dataL, {x:d=>d.time.short,y1:0 ,y2:max, fill:d=>d.timeControl, opacity:0.02 }),
Plot.text(dataL, {x:d=>d.time.short,y1:0 ,y:max, dy:-6, fill:d=>d.timeControl, text: d=>d.timeControl}),
//Division Promotion
Plot.barY(dataL, {x:d=>d.time.short, y1:d=>d.teams.find(e=>e.rank==1).score ,y2:d=>d.teams.find(e=>e.rank==3).score, stroke:"black",
strokeWidth:0.4, r:1,
//fx:d=>d.timeControl,
fill:"green", opacity:opctRelProm }),
//Division Staying
Plot.barY(dataL, {x:d=>d.time.short, y1:d=>d.teams.find(e=>e.rank==3).score ,y2:d=>d.teams.find(e=>e.rank==8).score, stroke:"none",
strokeWidth:0.4,
//fx:d=>d.timeControl,
fill:"lightgray",opacity:opctRelProm }),
//Division Relegation
Plot.barY(dataL, {x:d=>d.time.short, y1:d=>d.teams.find(e=>e.rank==8).score ,y2:d=>d.teams.find(e=>e.rank==d.teams.length).score, stroke:"black",
strokeWidth:0.4, r:1,
//fx:d=>d.timeControl,
fill:"red",opacity:opctRelProm }),
//Transparent Overlay for link
Plot.barY(dataL, {x:d=>d.time.short, y1:d=>d.teams.find(e=>e.rank==1).score ,y2:d=>d.teams.find(e=>e.rank==d.teams.length).score,
//fx:d=>d.timeControl,
fill:"transparent", stroke:"none", href:d=>"https://lichess.org/tournament/"+d.id, target:"_blank", }),
Plot.ruleY([200], {strokeDasharray:"3 8", strokeWidth:0.4, opacity:0.6}),
//Tick for the Teams Rank
Plot.tickY(dataL, {x:d=>d.time.short, y:d=>d.teams.find(e=>e.id==iptTeamId).score ,
//fx:d=>d.timeControl,
stroke:"black", strokeWidth:1 }),
//Marker (dot) for the Teams Rank
Plot.link(dataL, {x:d=>d.time.short, y:d=>d.teams.find(e=>e.id==iptTeamId).score, //dx:-18,
marker:"dot",
//fx:d=>d.timeControl,
stroke:"black", strokeWidth:1.2 }),
//Text Team rank - points
Plot.text(dataL, {x:d=>d.time.short, y:d=>d.teams.find(e=>e.id==iptTeamId).score ,
//fx:d=>d.timeControl,
stroke:"black", fill:"black", stroke:"white", dy:9, dx:3, strokeWidth:0, fontSize:10, fontStyle:"italic",
text:d=>{let team = d.teams.find(e=>e.id==iptTeamId);
return team.score+" pts"} }),
//Text Team rank - #X
Plot.text(dataL, {x:d=>d.time.short, y:d=>d.teams.find(e=>e.id==iptTeamId).score ,
//fx:d=>d.timeControl,
stroke:"black", fill:"black", stroke:"white", dy:-8, dx:-12, strokeWidth:2, fontSize:15, fontWeight:"bold", fontStyle:"italic",
text:d=>{let team = d.teams.find(e=>e.id==iptTeamId);
return team.rank+"."} }),
]
})
}