Sigma.js 2.63 KB
Newer Older
James Laver's avatar
James Laver committed
1 2
'use strict';

3
const sigma = require('sigma/src/garg.js').sigma;
James Laver's avatar
James Laver committed
4

James Laver's avatar
James Laver committed
5 6
if (typeof window !== 'undefined') {
  window.sigma = sigma;
James Laver's avatar
James Laver committed
7 8
}

9 10
require('sigma/plugins/garg.js').init(sigma, window);

James Laver's avatar
James Laver committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
function _sigma(left, right, opts) {
  try {
    return right(new sigma(opts));
  } catch(e) {
    return left(e);
  }
}

function graphRead(left, right, sigma, data) {
  try {
    return right(sigma.graph.read(data));
  } catch(e) {
    return left(e);
  }
}
26
function refresh(sigma) { sigma.refresh(); }
James Laver's avatar
James Laver committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
function addRenderer(left, right, sigma, renderer) {
  try {
    return right(sigma.addRenderer(renderer));
  } catch(e) {
    return left(e);
  }
}
function killRenderer(left, right, sigma, renderer) {
  try {
    sigma.killRenderer(renderer);
    return right(sigma)
  } catch(e) {
    return left(e);
  }
}
42 43 44 45 46 47
function getRendererContainer(sigma) {
  return sigma.renderers[0].container;
}
function setRendererContainer(sigma, el) {
  sigma.renderers[0].container = el;
}
James Laver's avatar
James Laver committed
48 49 50 51 52 53 54 55
function killSigma(left, right, sigma) {
  try {
    sigma.kill()
    return right(null)
  } catch(e) {
    return left(e);
  }
}
56 57
function clear(sigma) { sigma.graph.clear(); }
function bind(sigma, event, handler) { sigma.bind(event, handler); }
58
function unbind(sigma, event) { sigma.unbind(event); }
59 60
function forEachNode(sigma, handler) { sigma.graph.nodes().forEach(handler); }
function forEachEdge(sigma, handler) { sigma.graph.edges().forEach(handler); }
61
function setSettings(sigma, settings) { sigma.settings(settings); }
62 63 64 65
function startForceAtlas2(sigma, settings) { sigma.startForceAtlas2(settings); }
function stopForceAtlas2(sigma) { sigma.stopForceAtlas2(); }
function killForceAtlas2(sigma) { sigma.killForceAtlas2(); }
function isForceAtlas2Running(sigma) { return sigma.isForceAtlas2Running(); }
James Laver's avatar
James Laver committed
66

67 68 69 70 71 72 73 74 75
function getCameras(sigma) {
  // For some reason, sigma.cameras is an object with integer keys
  return Object.values(sigma.cameras);
};

function goTo(cam, props) {
  return cam.goTo(props);
};

James Laver's avatar
James Laver committed
76 77
exports._sigma = _sigma;
exports._graphRead = graphRead;
78
exports._refresh = refresh;
James Laver's avatar
James Laver committed
79 80
exports._addRenderer = addRenderer;
exports._killRenderer = killRenderer;
81 82
exports._getRendererContainer = getRendererContainer;
exports._setRendererContainer = setRendererContainer;
James Laver's avatar
James Laver committed
83
exports._killSigma = killSigma
84 85
exports._clear = clear;
exports._bind = bind;
86
exports._unbind = unbind;
87 88
exports._forEachNode = forEachNode;
exports._forEachEdge = forEachEdge;
89
exports._setSettings = setSettings;
90 91 92 93
exports._startForceAtlas2 = startForceAtlas2;
exports._stopForceAtlas2 = stopForceAtlas2;
exports._killForceAtlas2 = killForceAtlas2;
exports._isForceAtlas2Running = isForceAtlas2Running;
94 95
exports._getCameras = getCameras;
exports._goTo = goTo;