draw_radar = {
let strokeSize = 0.5;
const svgRadar = d3.create("svg")
.attr("viewBox", [0, 0, diameter, diameter])
.style('background', '#fff')
.attr('id', 'radarSVG')
.attr('width',1024)
const pie = d3.pie().value(d => d);
for (let trackNumber = 0; trackNumber < teTracks.length; trackNumber++) {
const pieGroup = svgRadar.append('g')
.attr('transform', `translate(${diameter / 2},${diameter / 2})`)
.attr('id', `track_${trackNumber}`);
const arc = d3.arc()
.innerRadius(teTracks[trackNumber].zoneRadiusInner)
.outerRadius(teTracks[trackNumber].zoneRadiusOuter)
const g = pieGroup.selectAll('.arc')
.data(() => {
let flippy = pie(teTracks[trackNumber].sectors)
if(textRings.includes(trackNumber)) {
let temp = flippy[1].startAngle
flippy[1].startAngle = flippy[1].endAngle
flippy[1].endAngle = temp
temp = flippy[2].startAngle
flippy[2].startAngle = flippy[2].endAngle
flippy[2].endAngle = temp
}
return flippy
})
.enter().append('g')
// add class names to define quadrant and zone.
.attr('class', (d, idx) => `${teTracks[trackNumber].sectorsQuadrant[idx]} ${zoneName[teTracks[trackNumber].zone]}`)
.attr('id', (d, idx) => { // add an id to each sector so we can address it.
teTracks[trackNumber].xy.push(arc.centroid(d)) // >>> "hacky mc hack face", way to get the center point of each sector
return `sector${idx}_${trackNumber}`
});
g.append('path')
.attr('d', arc) // svg d attribute defines a path to be drawn.
.attr('class','arc')
.attr('id', (d, idx) => `path${idx}_${trackNumber}`)
.style('fill', (d, sector) => teTracks[trackNumber].sectorColour[sector])
// .style('stroke', (d, sector) => teTracks[trackNumber].sectorColour[sector]) // invisable sectors
.style('stroke', '#2F0080') // visable sectors
.style('stroke-width', strokeSize);
}
// make arcs to add "zoneName[]" text.
// textRings[] array containing the track numbers to add the text too
// sector0_5 the group to append the text too Sector number _ track number
// path0_5 p sector numbr _ track
for (let txtTrack = 0; txtTrack < textRings.length; ++txtTrack) {
for (let q = 0; q < 4; ++q) {
svgRadar.select(`#sector${q}_${textRings[txtTrack]}`)
.append("text")
.attr('text-anchor','middle')
.attr('font-family','Verdana')
.attr('font-size',sectorSize )
.attr('dy', () => (q==1||q==2)? -sectorSize*0.33: sectorSize)
.style("fill", "#FFF")
.style("stroke", "#000")
.append("textPath")
.attr("xlink:href", `#path${q}_${textRings[txtTrack]}`)
.attr('startOffset','25%')
.text(zoneName[q]); // will fix text used later
}
}
return svgRadar.node()
}