{
const svg = d3.select(DOM.svg(1000,6080))
svg.style('background-color', '#1d1b3d')
gdp.forEach((country) => {
let allValues = Object.keys(country)
.filter((key) => key !== 'score' && key !== 'Country Name' )
.map((key) =>
country[key] + wiggle >= target &&
country[key] - wiggle <= target ?
100 : 100 - Math.abs(country[key] - target)
)
country.score = allValues.reduce((a, b) => a + b, 0)
});
gdp.sort( (a, b) => b.score - a.score)
const sliceCount = gdp.columns.length -1;
const wedge = tau / sliceCount;
const padding = wedge/16;
let possition = { left:margin, top:margin }
gdp.forEach((data) => {
let i = 0;
let g = svg.append("g")
.attr("width", width)
.attr("height", height)
let left = possition.left + padding,
top = possition.top + padding;
heading(g, data['Country Name'], left, top)
possition.left += width;
if((possition.left + width) > (1000-margin) ) {
possition.left = margin;
possition.top += height;
}
g.selectAll("path")
.data( Object.keys(data)
.filter((key) => key !== 'score' && key !== 'Country Name')
.map((key) => data[key])
)
.enter()
.append("path")
.attr("transform", "translate(" + [(width/2)+left, (height/2)+top] + ")")
.style("fill", d => {
const num = parseFloat(d);
const inRange = (num+wiggle) > target && (num-wiggle) < target;
const onTheMark = num+(wiggle*2) > target && num-(wiggle*2) < target;
return inRange ? "#86e5ce" : onTheMark ? "#fec670" : "#fb7f82";
})
.attr("d", d3.arc()
.innerRadius(innerRadius)
.outerRadius(d => scale(d))
.startAngle(d => {
let start = (wedge * i) + padding;
i++;
return start;
})
.endAngle(() => (wedge * i) - padding)
)
donut(g, left, top)
});
return svg.node()
}