findDataNeighbors = (data,benchmarkElement,compareField,countAboveBelow,sortType) => {
if (!sortType) {sortType = d3.descending}
let toNum = (text) => Number(text.replace(/,/g,''))
let sortedData = d3.sort(data, (a,b) => sortType(toNum(a[compareField]),toNum(b[compareField])));
let benchmarkIndex = sortedData.indexOf(benchmarkElement);
let countAbove, countBelow;
if (benchmarkIndex < countAboveBelow) {
let leftover = countAboveBelow - benchmarkIndex;
countAbove = countAboveBelow + leftover;
countBelow = benchmarkIndex;
} else if (benchmarkIndex > data.length - countAboveBelow) {
let leftover = data.length - benchmarkIndex;
countAbove = leftover;
countBelow = countAboveBelow + leftover;
} else {
countAbove = countBelow = countAboveBelow;
}
return sortedData.slice(benchmarkIndex-countAbove,benchmarkIndex+countAbove);
}