Advertisement
hecrus

Settings for ForceDirected

Aug 28th, 2021
1,225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var defaultOptions = {
  2.                 //id of the visualization container
  3.                 injectInto: contID,
  4.                 //Enable zooming and panning
  5.                 //by scrolling and DnD
  6.                 Navigation: {
  7.                     enable: true,
  8.                     //Enable panning events only if we're dragging the empty
  9.                     //canvas (and not a node).
  10.                     panning: 'avoid nodes',
  11.                     zooming: 10 //zoom speed. higher is more sensible
  12.                 },
  13.                 // Change node and edge styles such as
  14.                 // color and width.
  15.                 // These properties are also set per node
  16.                 // with dollar prefixed data-properties in the
  17.                 // JSON structure.
  18.                 Node: {
  19.                     overridable: true
  20.                 },
  21.                 Edge: {
  22.                     overridable: true,
  23.                     color: '#23A4FF',
  24.                     lineWidth: 0.4
  25.                 },
  26.                 //Native canvas text styling
  27.                 Label: {
  28.                     type: as.vis.options.labelType, //Native or HTML
  29.                     size: 10,
  30.                     style: 'bold', color: '#222'
  31.                 },
  32.                 //Add Tips
  33.                 Tips: {
  34.                     enable: true,
  35.                     onShow: function (tip, node) {
  36.                         var callback = as.crud2callbacks[tableCode + "_showGraphTip"];
  37.                         if (callback) {
  38.                             callback(tip, node);
  39.                         } else {
  40.                             //count connections
  41.                             var count = 0;
  42.                             node.eachAdjacency(function () { count++; });
  43.                             //display node info in tooltip
  44.                             var s = "<div class='as-visGraphTipTitle'>" + node.name + "</div>";
  45.                             if (node.data.$tip) {
  46.                                 s += "<div class='as-visGraphTipText text-muted'>" + node.data.$tip+"</div>";
  47.                             }
  48.                             tip.innerHTML = s;
  49.                         }
  50.                     }
  51.                 },
  52.                 // Add node events
  53.                 Events: {
  54.                     enable: true,
  55.                     type: 'Native',
  56.                     //Change cursor style when hovering a node
  57.                     onMouseEnter: function () {
  58.                         fd.canvas.getElement().style.cursor = 'move';
  59.                     },
  60.                     onMouseLeave: function () {
  61.                         fd.canvas.getElement().style.cursor = '';
  62.                     },
  63.                     //Update node positions when dragged
  64.                     onDragMove: function (node, eventInfo, e) {
  65.                         var pos = eventInfo.getPos();
  66.                         node.pos.setc(pos.x, pos.y);
  67.                         fd.plot();
  68.                     },
  69.                     //Implement the same handler for touchscreens
  70.                     onTouchMove: function (node, eventInfo, e) {
  71.                         $jit.util.event.stop(e); //stop default touchmove event
  72.                         this.onDragMove(node, eventInfo, e);
  73.                     },
  74.                     //Add also a click handler to nodes
  75.                     onClick: function (node) {
  76.                         if (!node) return;
  77.                         var callback = as.crud2callbacks[tableCode + "_clickGraphNode"];
  78.                         if (callback) {
  79.                             callback(node);
  80.                         } else {
  81.                             var s = "<h4>" + node.name + "</h4>";
  82.                             var list = [];
  83.                             node.eachAdjacency(function (adj) {
  84.                                 list.push(adj.nodeTo.name);
  85.                             });
  86.                             var el = $jit.id('as-visGraphNodePanel');
  87.                             if(el) el.innerHTML = s + "<p class='text-muted small'>" + list.join(", ") +  "</p>";                            
  88.                         }
  89.                     }
  90.                 },
  91.                 //Number of iterations for the FD algorithm
  92.                 iterations: 200,
  93.                 //Edge length
  94.                 levelDistance: 100,
  95.                 // Add text to the labels. This method is only triggered
  96.                 // on label creation and only for DOM labels (not native canvas ones).
  97.                 onCreateLabel: function (domElement, node) {
  98.                     domElement.innerHTML = node.name;
  99.                     var style = domElement.style;
  100.                     style.fontSize = "0.8em";
  101.                     style.color = "#ddd";
  102.                 },
  103.                 // Change node styles when DOM labels are placed
  104.                 // or moved.
  105.                 onPlaceLabel: function (domElement, node) {
  106.                     var style = domElement.style;
  107.                     var left = parseInt(style.left);
  108.                     var top = parseInt(style.top);
  109.                     var w = domElement.offsetWidth;
  110.                     style.left = (left - w / 2) + 'px';
  111.                     style.top = (top + 10) + 'px';
  112.                     style.display = '';
  113.                 }
  114.             };
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement