Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(store, options) {
options = options || {};
const pathPrefix = options.pathPrefix || '';
const skipDrafts = options.skipDrafts || false;
const draftIds = new Set();
this.store = store;
this.graph = new Graph();
// Hydrating graph & filtering drafts
models.forEach(model => {
store[model] = store[model].filter(item => {
if (skipDrafts && item.draft) {
draftIds.add(item.id);
return false;
}
// Tagging model
item.model = model;
this.graph.addNode(item.id);
return true;
});
});
function Batch() {
if (!(this instanceof Batch))
return new Batch();
// Properties
this.graph = new MultiDirectedGraph();
this.relationshipsToDelete = {};
this.generateNodeId = createIncrementalId();
this.generateEdgeId = createIncrementalId();
}
// Making some modules global for the custom scripts to consume
var d3 = require('d3');
window.d3 = d3;
var numeric = require('numeric');
window.numeric = numeric;
// Requiring some graphology libraries we are going to make global for the user
var graphology = require('graphology');
graphology.library = require('graphology-library/browser');
window.graphology = graphology;
window.Graph = graphology;
var randomLayout = graphology.library.layout.random;
var forceAtlas2Layout = graphology.library.layoutForceAtlas2;
window.layout = {
random: randomLayout,
forceAtlas2: forceAtlas2Layout
};
window.ForceAtlas2Layout = graphology.library.FA2Layout;
window.louvain = graphology.library.communitiesLouvain;
// Requiring sigma
window.SigmaWebGLRenderer = require('sigma/renderers/webgl').default;
// Requiring own modules
require('./view_upload/upload.js');
require('./view_board/board.js');
require('./recipes/_recipes_list_.js');
assert.throws(function() {
new Sigma(new Graph(), null);
}, /renderer/);
});
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)
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));
});
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
});
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);