code: function handleMessageFromMainThread(message) {
      var kind = message.data.kind;
      var payload = message.data.payload;
  
      if (kind === messageKind.init) {
        graph = fromjson(payload.graph);
        var options = JSON.parse(payload.options);
  
        init(graph, options);
      } else if (kind === messageKind.step) {
        step();
      } else if (kind === messageKind.pinNode) {
        pinNode(payload.nodeId, payload.isPinned);
      } else if (kind === messageKind.setNodePosition) {
        setNodePosition(payload.nodeId, payload.x, payload.y, payload.z);
      }
      // TODO: listen for graph changes from main thread and update layout here.
    }
docs: public API is over. Below are private methods only.