src/reducers.js
// attrs is the histogram data for all nodes (for computing sub-distribution of selected nodes)
attrs is the histogram data for all nodes (for computing sub-distribution of selected nodes)
attrs is the histogram data for all nodes ( for computing sub - distribution of selected nodes )
function summarizeNodeAttrs(nodes, attrMeta, nodeTypes, attrs = null, included = null) {
    let res = attrMeta.map((a) => ({ ...a }));
    for (let a of res) {
        if (a.type === "scalar") {
            a.values = []; 
        } else if (a.type === "categorical") {
            a.values = {}; 
        }
    }
    function countValues(n) {
        for (let a of res) {
            if (nodeTypes[n.typeId].name === a.nodeType) {
                if (a.type === "scalar") {
                    a.values.push(+n[a.name]);
                } else if (a.type === "categorical") {
                    if (!a.values.hasOwnProperty(n[a.name])) {
                        a.values[n[a.name]] = 0;
                    }
                    a.values[n[a.name]]++;
                }
            }
        }
    }
    if (included !== null) {
        for (let nid of included) {
            countValues(nodes[nid]);
        }
    } else {
        for (let n of nodes) {
            countValues(n);
        }
    }
    const thresCnt = 10;
    for (let i = 0; i < res.length; i++) {
        let a = res[i];
        if (a.type === "scalar") {
            if (attrs) {
                a.bins = attrs[i].binGen(a.values);
            } else {
                let s = scaleLinear().domain(extent(a.values)).nice(thresCnt);
                a.binGen = d3bin().domain(s.domain()).thresholds(s.ticks(thresCnt));
                a.bins = a.binGen(a.values);
            }
        } else {
            if (attrs) {
                a.bins = attrs[i].bins.map((b) => ({ v: b.v, c: a.values[b.v] }));
            } else {
                a.bins = Object.keys(a.values)
                    .sort((x, y) => a.values[x] - a.values[y])
                    .map((x) => ({ v: x, c: a.values[x] }));
            }
        }
    }
    return res;
}
function summarizeNodeAttrs ( nodes , attrMeta , nodeTypes , attrs = null , included = null ) { let res = attrMeta . map ( ( a ) => ( { ... a } ) ) ; for ( let a of res ) { if ( a . type === "scalar" ) { a . values = [ ] ; } else if ( a . type === "categorical" ) { a . values = { } ; } } function countValues ( n ) { for ( let a of res ) { if ( nodeTypes [ n . typeId ] . name === a . nodeType ) { if ( a . type === "scalar" ) { a . values . push ( + n [ a . name ] ) ; } else if ( a . type === "categorical" ) { if ( ! a . values . hasOwnProperty ( n [ a . name ] ) ) { a . values [ n [ a . name ] ] = 0 ; } a . values [ n [ a . name ] ] ++ ; } } } } if ( included !== null ) { for ( let nid of included ) { countValues ( nodes [ nid ] ) ; } } else { for ( let n of nodes ) { countValues ( n ) ; } } const thresCnt = 10 ; for ( let i = 0 ; i < res . length ; i ++ ) { let a = res [ i ] ; if ( a . type === "scalar" ) { if ( attrs ) { a . bins = attrs [ i ] . binGen ( a . values ) ; } else { let s = scaleLinear ( ) . domain ( extent ( a . values ) ) . nice ( thresCnt ) ; a . binGen = d3bin ( ) . domain ( s . domain ( ) ) . thresholds ( s . ticks ( thresCnt ) ) ; a . bins = a . binGen ( a . values ) ; } } else { if ( attrs ) { a . bins = attrs [ i ] . bins . map ( ( b ) => ( { v : b . v , c : a . values [ b . v ] } ) ) ; } else { a . bins = Object . keys ( a . values ) . sort ( ( x , y ) => a . values [ x ] - a . values [ y ] ) . map ( ( x ) => ( { v : x , c : a . values [ x ] } ) ) ; } } } return res ; }
attrs is the histogram data for all nodes (for computing sub-distribution of selected nodes)
attrs is the histogram data for all nodes ( for computing sub - distribution of selected nodes )
// Init // The attribute values, used for compuing stats // A mapping from value to count // if (included) { //     // Only record the nodes when computing partial histogram data //     a.nodeIds = []; // } // Count // if (included) { //     a.nodeIds.push(n.id); // } // Binning