This algo is for edge crossings minimization especially for out-trees (one root only), it combines d3.js and customized algo which uses brute force to search the optimal positions when it also preserves length information as much as possible.
LHS: original; RHS: modified
a. npm install
b. pip install networkx, pygraphviz, matplotlib
c. pip install Cython
{"nodes" : [<nodeObject> , <nodeObject>, ...], "links" : [<linkObject> , <linkObject>, ...]}
{id : <str, int, ...> , num : <the size of the node>, x : <float>, y : <float>}
{id : <nodeObjectID_1>_<nodeObjectID_2>, source : <nodeObject_1>, target : <nodeObject_2>, len : <float>}
It calls algo_improved.c extension to run the algo, if you want to modify some codes to cater for your needs, go to algo_improved.pyx. To save the changes, input following command in the terminal:
python setup_improved.py build_ext --inplace
you can customize if you want to have node labels, edge labels, radius information and scalar factor of raidus by modifying the variables WITH_NODE_LABELS, WITH_EDGE_LABELS, WITH_NODE_NUM_DISPLAY and NODE_NUM_SCALAR repectively. Furthermore, you should change the file path if the file path finished in step2 or step3 changes.
In main_{2,3}steps.js, we can add nodes that we would like to track to the array tracking, the tracking algo will be running during execution time including storing coordindate information into a file which is by default placed at ./tracking/trackingResults.json. Afterwards, we can execute tracking.py to see more information about nodes defined in the tracking array.
All scripts with nf.{js,py} at the end are for automation flow, which are added argument functionality.
a. | Generate coordinates by d3 simulation | preprocessing_nf.js |
b. | Optimize coordinates by algorithm | optimization_improved_nf.py |
c. | Fine Tuning by d3 simulation | fineTuning_nf.js |