src/reducers.js
// Note: return one histogram for each neighbor node type.  The input is already sorted
return one histogram for each neighbor node type.  The input is already sorted
return one histogram for each neighbor node type . The input is already sorted
function countNeighborSets(neighborMasksByType, selectedNodes) {
    if (selectedNodes.length === 0) return { allCounts: [], bins: [], countsByType: [] };
    let cnts = [],
        histos = [];
    for (let i = 0; i < neighborMasksByType[0].length; i++) {
        cnts.push({});
    }
    for (let nid of selectedNodes) {
        for (let i = 0; i < neighborMasksByType[0].length; i++) {
            const nei = neighborMasksByType[nid][i].toArray();
            for (let b of nei) {
                if (!cnts[i].hasOwnProperty(b)) {
                    cnts[i][b] = 0;
                }
                cnts[i][b]++;
            }
        }
    }
    const binGen = d3bin().thresholds(selectedNodes.length);
    let allCounts = [],
        allCountsMapping = {},
        countsByType = [];
    for (let c of cnts) {
        const idx = Object.keys(c);
        const temp = [];
        for (let i of idx) {
            temp.push({ id: i, cnt: c[i] });
            allCountsMapping[i] = c[i];
        }
        temp.sort((a, b) => b.cnt - a.cnt);
        allCounts = allCounts.concat(temp);
        countsByType.push(temp);
        histos.push(binGen(temp.map((t) => t.cnt)));
    }
    return { allCounts, allCountsMapping, bins: histos, countsByType };
}
function countNeighborSets ( neighborMasksByType , selectedNodes ) { if ( selectedNodes . length === 0 ) return { allCounts : [ ] , bins : [ ] , countsByType : [ ] } ; let cnts = [ ] , histos = [ ] ; for ( let i = 0 ; i < neighborMasksByType [ 0 ] . length ; i ++ ) { cnts . push ( { } ) ; } for ( let nid of selectedNodes ) { for ( let i = 0 ; i < neighborMasksByType [ 0 ] . length ; i ++ ) { const nei = neighborMasksByType [ nid ] [ i ] . toArray ( ) ; for ( let b of nei ) { if ( ! cnts [ i ] . hasOwnProperty ( b ) ) { cnts [ i ] [ b ] = 0 ; } cnts [ i ] [ b ] ++ ; } } } const binGen = d3bin ( ) . thresholds ( selectedNodes . length ) ; let allCounts = [ ] , allCountsMapping = { } , countsByType = [ ] ; for ( let c of cnts ) { const idx = Object . keys ( c ) ; const temp = [ ] ; for ( let i of idx ) { temp . push ( { id : i , cnt : c [ i ] } ) ; allCountsMapping [ i ] = c [ i ] ; } temp . sort ( ( a , b ) => b . cnt - a . cnt ) ; allCounts = allCounts . concat ( temp ) ; countsByType . push ( temp ) ; histos . push ( binGen ( temp . map ( ( t ) => t . cnt ) ) ) ; } return { allCounts , allCountsMapping , bins : histos , countsByType } ; }
Note: return one histogram for each neighbor node type.
Note : return one histogram for each neighbor node type .
// Init // Count // TODO:  use a smarter thresholds later // const thresholds = []; // for (let i = 1; i < selectedNodes.length + 1; i++) { //    thresholds.push(i - 0.01); // } // console.log(thresholds); // Flatten the cnts array // Sort // Compute bins of counts