src/components/graph/graph.helper.js
function updateNodeHighlightedValue(nodes, links, config, id, value = false) {
    const highlightedNode = value ? id : "";
    const node = Object.assign({}, nodes[id], { highlighted: value });
    let updatedNodes = Object.assign({}, nodes, { [id]: node });

    // when highlightDegree is 0 we want only to highlight selected node
    if (links[id] && config.highlightDegree !== 0) {
        updatedNodes = Object.keys(links[id]).reduce((acc, linkId) => {
            const updatedNode = Object.assign({}, updatedNodes[linkId], { highlighted: value });

            return Object.assign(acc, { [linkId]: updatedNode });
        }, updatedNodes);
    }

    return {
        nodes: updatedNodes,
        highlightedNode,
    };
}
function updateNodeHighlightedValue(nodes, links, config, id, value = false) {
    const highlightedNode = value ? id : "";
    const node = Object.assign({}, nodes[id], { highlighted: value });
    let updatedNodes = Object.assign({}, nodes, { [id]: node });

    // when highlightDegree is 0 we want only to highlight selected node
    if (links[id] && config.highlightDegree !== 0) {
        updatedNodes = Object.keys(links[id]).reduce((acc, linkId) => {
            const updatedNode = Object.assign({}, updatedNodes[linkId], { highlighted: value });

            return Object.assign(acc, { [linkId]: updatedNode });
        }, updatedNodes);
    }

    return {
        nodes: updatedNodes,
        highlightedNode,
    };
}
function updateNodeHighlightedValue ( nodes , links , config , id , value = false ) { const highlightedNode = value ? id : "" ; const node = Object . assign ( { } , nodes [ id ] , { highlighted : value } ) ; let updatedNodes = Object . assign ( { } , nodes , { [ id ] : node } ) ; // when highlightDegree is 0 we want only to highlight selected node if ( links [ id ] && config . highlightDegree !== 0 ) { updatedNodes = Object . keys ( links [ id ] ) . reduce ( ( acc , linkId ) => { const updatedNode = Object . assign ( { } , updatedNodes [ linkId ] , { highlighted : value } ) ; return Object . assign ( acc , { [ linkId ] : updatedNode } ) ; } , updatedNodes ) ; } return { nodes : updatedNodes , highlightedNode , } ; }
This function updates the highlighted value for a given node and also updates highlight props.
@param {Object.<string, Object>} nodes - an object containing all nodes mapped by their id.
@param {Object.<string, Object>} links - an object containing a matrix of connections of the graph.
@param {Object} config - an object containing rd3g consumer defined configurations {@link #config config} for the graph.
@param {string} id - identifier of node to update.
@param {string} value - new highlight value for given node.
@returns {Object} returns an object containing the updated nodes
and the id of the highlighted node.
@memberof Graph/helper
This function updates the highlighted value for a given node and also updates highlight props .