How to use the graphlib.Graph function in graphlib

To help you get started, we’ve selected a few graphlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ricklupton / d3-sankey-diagram / test / examples.js View on Github external
export function exampleWithLoop () {
  //
  //  f -------,    b<-,
  //  a -- b -- c -- e `
  //    `------ d -'
  //              \
  //      
github teambit / bit / src / scope / graph / scope-graph.ts View on Github external
static async buildGraphFromScope(scope: Scope): Promise {
    const graph = new Graph();
    const allModelComponents: ModelComponent[] = await scope.list();
    const buildGraphP = allModelComponents.map(async modelComponent => {
      const buildVersionP = modelComponent.listVersions().map(async versionNum => {
        const version = await modelComponent.loadVersion(versionNum, scope.objects);
        if (!version) {
          // a component might be in the scope with only the latest version
          return;
        }
        const id = modelComponent.toBitId().changeVersion(versionNum);
        this._addDependenciesToGraph(id, graph, version);
      });
      await Promise.all(buildVersionP);
    });
    await Promise.all(buildGraphP);
    return graph;
  }
github mermaid-js / mermaid / src / diagrams / state / stateRenderer.js View on Github external
export const draw = function(text, id) {
  conf = getConfig().state;
  parser.yy.clear();
  parser.parse(text);
  logger.debug('Rendering diagram ' + text);

  // /// / Fetch the default direction, use TD if none was found
  const diagram = d3.select(`[id='${id}']`);
  insertMarkers(diagram);

  // // Layout graph, Create a new directed graph
  const graph = new graphlib.Graph({
    multigraph: false,
    compound: true,
    // acyclicer: 'greedy',
    rankdir: 'RL'
    // ranksep: '20'
  });

  // // Default to assigning a new object as a label for each new edge.
  graph.setDefaultEdgeLabel(function() {
    return {};
  });

  const rootDoc = stateDb.getRootDoc();
  renderDoc(rootDoc, diagram);

  const padding = conf.padding;
github kube-HPC / hkube / core / api-server / lib / validation / api-validator.js View on Github external
_validateNodes(pipeline, opt) {
        const options = opt || {};
        const graph = new Graph();
        const links = [];

        pipeline.nodes.forEach((node) => {
            if (graph.node(node.nodeName)) {
                throw new InvalidDataError(`found duplicate node ${node.nodeName}`);
            }
            if (node.nodeName === 'flowInput') {
                throw new InvalidDataError(`pipeline ${pipeline.name} has invalid reserved name flowInput`);
            }

            if (node.input) {
                node.input.forEach((inp) => {
                    if (options.checkFlowInput) {
                        try {
                            parser.checkFlowInput({ flowInput: pipeline.flowInput, nodeInput: inp });
                        }
github teambit / bit / src / scope / graph / components-graph.ts View on Github external
export function buildComponentsGraph(components: Component[]): AllDependenciesGraphs {
  const graphDeps = new Graph();
  const graphDevDeps = new Graph();
  const graphCompilerDeps = new Graph();
  const graphTesterDeps = new Graph();
  components.forEach(component => {
    _setGraphEdges(component.id, component.dependencies, graphDeps);
    _setGraphEdges(component.id, component.devDependencies, graphDevDeps);
    _setGraphEdges(component.id, component.compilerDependencies, graphCompilerDeps);
    _setGraphEdges(component.id, component.testerDependencies, graphTesterDeps);
  });
  return { graphDeps, graphDevDeps, graphCompilerDeps, graphTesterDeps };
}
github teambit / bit / src / scope / graph / components-graph.ts View on Github external
export function buildComponentsGraphForComponentsAndVersion(
  components: ComponentsAndVersions[]
): AllDependenciesGraphs {
  const graphDeps = new Graph();
  const graphDevDeps = new Graph();
  const graphCompilerDeps = new Graph();
  const graphTesterDeps = new Graph();
  components.forEach(({ component, version, versionStr }) => {
    const bitId = component.toBitId().changeVersion(versionStr);
    _setGraphEdges(bitId, version.dependencies, graphDeps);
    _setGraphEdges(bitId, version.devDependencies, graphDevDeps);
    _setGraphEdges(bitId, version.compilerDependencies, graphCompilerDeps);
    _setGraphEdges(bitId, version.testerDependencies, graphTesterDeps);
  });
  return { graphDeps, graphDevDeps, graphCompilerDeps, graphTesterDeps };
}
github webiny / webiny-js / packages / app-admin / src / components / Install / useInstaller.js View on Github external
const createGraph = installers => {
        const graph = new Graph();
        installers.forEach(({ plugin }) => {
            graph.setNode(plugin.name, plugin);
        });

        installers.forEach(({ plugin: pl }) => {
            if (Array.isArray(pl.dependencies)) {
                pl.dependencies.forEach(dep => {
                    graph.setEdge(pl.name, dep);
                });
            }
        });

        validateGraph(graph);

        return graph;
    };
github teambit / bit / src / scope / graph / components-graph.ts View on Github external
export function buildComponentsGraphForComponentsAndVersion(
  components: ComponentsAndVersions[]
): AllDependenciesGraphs {
  const graphDeps = new Graph();
  const graphDevDeps = new Graph();
  const graphCompilerDeps = new Graph();
  const graphTesterDeps = new Graph();
  components.forEach(({ component, version, versionStr }) => {
    const bitId = component.toBitId().changeVersion(versionStr);
    _setGraphEdges(bitId, version.dependencies, graphDeps);
    _setGraphEdges(bitId, version.devDependencies, graphDevDeps);
    _setGraphEdges(bitId, version.compilerDependencies, graphCompilerDeps);
    _setGraphEdges(bitId, version.testerDependencies, graphTesterDeps);
  });
  return { graphDeps, graphDevDeps, graphCompilerDeps, graphTesterDeps };
}
github serverless / components / lib / index.js View on Github external
const getGraph = async () => {
  const graph = {
    nodes: new Graph(),
    data: await getComponents(),
    state: await readStateFile()
  }

  forEach((componentId) => {
    graph.nodes.setNode(componentId)
  }, keys(graph.data))

  forEachObjIndexed((component, componentId) => {
    component.dependencies = getDependencies(component.inputs)
    if (not(isEmpty(component.dependencies))) {
      forEach((dependencyId) => {
        graph.nodes.setEdge(componentId, dependencyId)
      }, component.dependencies)
    }
  }, graph.data)