function dict_to_pie()

in static/plugins/downloads.js [23:37]


function dict_to_pie(dict, limit=10) {
    const keys = Object.keys(dict);
    keys.sort((a,b) => { return dict[b] - dict[a]});
    const keys_top = keys.slice(0,limit);
    const pie_array = [];
    let others = 0;
    for (const key of keys) {
        if (key !== "Other" && keys_top.includes(key)) pie_array.push({name: key, value: dict[key]});
        else others += dict[key];
    }
    if (others > 0) { // were there any others?
        pie_array.push({name: "Other", value: others});
    }
    return pie_array.sort((a,b) => b.value - a.value)
}