in packages/tablesorter-powerbi/src/TableSorterVisual.ts [556:590]
function updateRankingColumns(rankingInfo: IRankingInfo, data: ITableSorterRow[]) {
"use strict";
if (rankingInfo) {
// const data = this._data.data;
const ranks = rankingInfo.values.slice(0).reverse();
const runningRankTotal = {};
const rankCounts = {};
data.forEach(result => {
const itemRank = result[rankingInfo.column.displayName];
ranks.forEach(rank => {
if (LOWER_NUMBER_HIGHER_VALUE ? (itemRank <= rank) : (itemRank >= rank)) {
rankCounts[rank] = (rankCounts[rank] || 0) + 1;
}
});
});
const precision = Math.max((data.length + "").length - 2, 0);
data.forEach((result, j) => {
// The bucket that this item belongs to
const itemRank = result[rankingInfo.column.displayName];
// Go through each bucket in the entire dataset
for (const rank of ranks) {
const positionInBucket = runningRankTotal[rank] = runningRankTotal[rank] || 0;
const propName = `GENERATED_RANK_LEVEL_${rank}`;
let value = 0;
if (LOWER_NUMBER_HIGHER_VALUE ? (itemRank <= rank) : (itemRank >= rank)) {
const position = ((rankCounts[rank] - runningRankTotal[rank]) / rankCounts[rank]) * 100;
value = parseFloat(position.toFixed(precision));
runningRankTotal[rank] = positionInBucket + 1;
}
result[propName] = value;
}
});
}
}