How to use the graphology.UndirectedGraph function in graphology

To help you get started, we’ve selected a few graphology 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 jacomyal / sigma.js / examples / components.js View on Github external
const components = connectedComponents(graph);

components.forEach(component => {
  if (component.length < 10)
    component.forEach(node => graph.dropNode(node));
});

const map = louvain(graph);
let communities = {};

for (const node in map) {
  const c = map[node];

  if (!(c in communities))
    communities[c] = new UndirectedGraph();

  const h = communities[c];

  h.mergeNode(node, graph.getNodeAttributes(node));

  graph.edges(node).forEach(edge => {
    const target = graph.opposite(node, edge);

    if (node < target || map[target] !== c)
      return;

    h.mergeEdge(node, target);
  });
}

communities = Object.values(communities)
github jacomyal / sigma.js / examples / components.js View on Github external
position: absolute;
      height: 300px;
      border-right: 1px solid black;
      border-bottom: 1px solid black;
    }
    .subcontainer:nth-child(1),
    .subcontainer:nth-child(2),
    .subcontainer:nth-child(3) {
      border-top: 1px solid black;
    }
  
`;

const mainContainer = document.getElementById('container');

const graph = new UndirectedGraph({defaultNodeAttributes: {size: 3}});

data.forEach(({source, target}) => {
  graph.mergeEdge(source, target);
});

graph.nodes().forEach(node => {
  graph.setNodeAttribute(node, 'label', node);
  graph.setNodeAttribute(node, 'size', scale(graph.degree(node)));
});

const components = connectedComponents(graph);

components.forEach(component => {
  if (component.length < 10)
    component.forEach(node => graph.dropNode(node));
});
github jacomyal / sigma.js / examples / tiny.js View on Github external
import {UndirectedGraph} from 'graphology';
import WebGLRenderer from '../src/renderers/webgl';

const container = document.getElementById('container');

const graph = new UndirectedGraph();

graph.addNode('Jessica', {
  label: 'Jessica',
  x: 1,
  y: 1,
  color: '#FF0',
  size: 10
});

graph.addNode('Truman', {
  label: 'Truman',
  x: 0,
  y: 0,
  color: '#00F',
  size: 5
});
github jacomyal / sigma.js / examples / animations.js View on Github external
const xExtent = extent(miserables.nodes.map(n => n.x));
const yExtent = extent(miserables.nodes.map(n => n.y));

const nodeSizeScale = scaleLinear()
  .domain(nodeSizeExtent)
  .range([3, 15]);

const xScale = scaleLinear()
  .domain(xExtent)
  .range([0, 1]);

const yScale = scaleLinear()
  .domain(yExtent)
  .range([0, 1]);

const graph = new UndirectedGraph();

miserables.nodes.forEach((node, i) => {
  node.size = nodeSizeScale(node.size);
  node.x = xScale(node.x);
  node.y = yScale(node.y);
  graph.addNode(i, node);
});

miserables.edges.forEach(edge => {
  graph.addEdge(+edge.source, +edge.target, {color: '#ccc'});
});

const container = document.getElementById('container');

const renderer = new WebGLRenderer(graph, container);

graphology

A robust and multipurpose Graph object for JavaScript.

MIT
Latest version published 10 months ago

Package Health Score

73 / 100
Full package analysis