Socket
Socket
Sign inDemoInstall

dagre

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dagre - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

browser.js

28

index.js

@@ -1,2 +0,26 @@

require('./dagre.js');
module.exports = dagre;
/*
Copyright (c) 2012-2013 Chris Pettitt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
exports.dot = require("./lib/dot");
exports.Graph = require("./lib/Graph");
exports.layout = require("./lib/layout/layout");
exports.util = require("./lib/util");
exports.version = require("./lib/version");
{
"name": "dagre",
"version": "0.0.5",
"version": "0.1.0",
"description": "Directed graph rendering",

@@ -17,5 +17,7 @@ "main": "index.js",

"devDependencies": {
"browserify": "2.28.x",
"chai": "1.7.x",
"mocha": "1.12.x",
"pegjs": "0.7.x",
"mocha": "1.5.x",
"chai": "1.3.x"
"uglify-js": "1.2.3"
},

@@ -27,3 +29,22 @@ "author": "Chris Pettitt <chris@samsarin.com>",

},
"license": "MIT"
"license": "MIT",
"testling": {
"files": [
"test/**/*.js"
],
"browsers": [
"ie/8..latest",
"firefox/17..latest",
"firefox/nightly",
"chrome/22..latest",
"chrome/canary",
"opera/12..latest",
"opera/next",
"safari/5.1..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
],
"harness": "mocha"
}
}
# dagre - Directed graph rendering
[![Build Status](https://secure.travis-ci.org/cpettitt/dagre.png)](http://travis-ci.org/cpettitt/dagre)
[![browser support](https://ci.testling.com/cpettitt/dagre.png)](https://ci.testling.com/cpettitt/dagre)
Dagre is a JavaScript library that makes it easy to lay out directed graphs on

@@ -23,3 +27,3 @@ the client-side.

Try our [interactive demo](http://cpettitt.github.com/project/dagre/latest/demo.html)!
Try our [interactive demo](http://cpettitt.github.com/project/dagre/latest/demo/demo.html)!

@@ -32,4 +36,2 @@ If you've checked out the project, you can build the Dagre library and then try

[![Build Status](https://secure.travis-ci.org/cpettitt/dagre.png)](http://travis-ci.org/cpettitt/dagre)
Before building this library you need to install the [npm package manager].

@@ -45,2 +47,26 @@

## Contact
We've been manging bugs and enhancement request through our [issue
tracker](https://github.com/cpettitt/dagre/issues).
We also have a [google group](https://groups.google.com/group/dagre) for
questions and discussion.
## Third Party Examples
Dagre has been included as a part of some very cool projects. Here are just a
couple that stand out:
[JointJS](http://www.daviddurman.com/automatic-graph-layout-with-jointjs-and-dagre.html)
has a plugin that uses dagre for layout. JointJS focuses on rendering and
interaction with diagrams, which synergizes well with Dagre. If you want the
ability to move nodes and manipulate edges interactively, this is a good place
to start!
Jonathan Mace has a
[demo](http://cs.brown.edu/people/jcmace/d3/graph.html?id=small.json) that
makes it possible to interactively explore graphs. In his demo, you can
highlight paths, collapse subgraphs, via detailed node information, and more!
## References

@@ -47,0 +73,0 @@

4

src/version.js

@@ -1,1 +0,3 @@

dagre.version = "0.0.5";
var fs = require("fs");
var package = JSON.parse(fs.readFileSync(__dirname + "/../package.json", "utf8"));
console.log("module.exports = '" + package.version + "';");

@@ -1,5 +0,2 @@

chai = require("chai"),
assert = chai.assert,
dagre = require("../index");
var chai = require("chai");
chai.Assertion.includeStack = true;

@@ -1,6 +0,9 @@

require("../common");
var common = require("../common"),
assert = require("chai").assert,
Graph = require("../../lib/Graph"),
layout = require("../../lib/layout/layout");
describe("dagre.layout", function() {
describe("layout", function() {
it("preserves edge ids for graphs with edges spanning multiple ranks", function() {
var g = dagre.graph();
var g = new Graph();
g.addNode(1);

@@ -12,5 +15,20 @@ g.addNode(2);

g.addEdge("1->3", 1, 3);
dagre.layout.apply(g);
layout.apply(g);
assert.include(g.edges(), "1->3");
});
it("preforms simple layout without error", function() {
var nodes = [{width: 10, height: 10}, {width: 10, height: 10}];
var edges = [{source: nodes[0], target: nodes[1]}];
layout()
.nodes(nodes)
.edges(edges)
.run();
// Simple check. nodes[0] should be above nodes[1].
var n0y = nodes[0].dagre.y;
var n1y = nodes[1].dagre.y;
assert.isTrue(n0y < n1y, "nodes[0] (" + n0y + ") should be above nodes[1] (" + n1y + ")");
});
});

@@ -1,8 +0,11 @@

require("../common");
var common = require("../common"),
assert = require("chai").assert,
dot = require("../../lib/dot"),
order = require("../../lib/layout/order");
describe("dagre.layout", function() {
describe("order", function() {
it("sets order = 0 for a single node", function() {
var g = dagre.dot.toGraph("digraph { A [rank=0] }");
var g = dot.toGraph("digraph { A [rank=0] }");
dagre.layout.order().run(g);
order().run(g);

@@ -13,5 +16,5 @@ assert.equal(g.node("A").order, 0);

it("sets order = 0 for 2 connected nodes on different ranks", function() {
var g = dagre.dot.toGraph("digraph { A [rank=0]; B [rank=1]; A -> B }");
var g = dot.toGraph("digraph { A [rank=0]; B [rank=1]; A -> B }");
dagre.layout.order().run(g);
order().run(g);

@@ -23,5 +26,5 @@ assert.equal(g.node("A").order, 0);

it("sets order = 0 for 2 unconnected nodes on different ranks", function() {
var g = dagre.dot.toGraph("digraph { A [rank=0]; B [rank=1]; }");
var g = dot.toGraph("digraph { A [rank=0]; B [rank=1]; }");
dagre.layout.order().run(g);
order().run(g);

@@ -33,5 +36,5 @@ assert.equal(g.node("A").order, 0);

it("sets order = 0, 1 for 2 nodes on the same rank", function() {
var g = dagre.dot.toGraph("digraph { A [rank=0]; B [rank=0]; }");
var g = dot.toGraph("digraph { A [rank=0]; B [rank=0]; }");
dagre.layout.order().run(g);
order().run(g);

@@ -46,28 +49,52 @@ if (g.node("A").order === 0) {

it("finds minimal crossings", function() {
var str = "digraph { A [rank=0]; B [rank=0]; C [rank=0]; D [rank=1]; E [rank=1]; " +
"A -> D; B -> D; B -> E; C -> D; C -> E }";
var g = dagre.dot.toGraph(str);
describe("finds minimial crossings", function() {
it("graph1", function() {
var str = "digraph { A [rank=0]; B [rank=0]; C [rank=1]; D [rank=1]; " +
"A -> D; B -> C; }";
var g = dot.toGraph(str);
var layering = dagre.layout.order().run(g);
var layering = order().run(g);
assert.equal(dagre.layout.order.crossCount(g, layering), 1);
assert.equal(order().crossCount(g, layering), 0);
});
it("graph2", function() {
var str = "digraph { A [rank=0]; B [rank=0]; C [rank=0]; D [rank=1]; E [rank=1]; " +
"A -> D; B -> D; B -> E; C -> D; C -> E }";
var g = dot.toGraph(str);
var layering = order().run(g);
assert.equal(order().crossCount(g, layering), 1);
});
it("graph3", function() {
var str = "digraph { A [rank=0]; B [rank=0]; C [rank=0];" +
"D [rank=1]; E [rank=1]; F [rank=1];" +
"G [rank=2]; H [rank=2]; I [rank=2];" +
"A -> E; B -> D; C -> F; D -> I; E -> H; F -> G }";
var g = dot.toGraph(str);
var layering = order().run(g);
assert.equal(order().crossCount(g, layering), 0);
});
});
});
describe("dagre.layout.bilayerCrossCount", function() {
describe("order().bilayerCrossCount", function() {
it("calculates 0 crossings for an empty graph", function() {
var g = dagre.dot.toGraph("digraph {}");
var g = dot.toGraph("digraph {}");
var layer1 = [];
var layer2 = [];
assert.equal(dagre.layout.order.bilayerCrossCount(g, layer1, layer2), 0);
assert.equal(order().bilayerCrossCount(g, layer1, layer2), 0);
});
it("calculates 0 crossings for 2 layers with no crossings", function() {
var g = dagre.dot.toGraph("digraph {11 -> 21; 12 -> 22; 13 -> 23}");
var g = dot.toGraph("digraph {11 -> 21; 12 -> 22; 13 -> 23}");
var layer1 = [11, 12, 13];
var layer2 = [21, 22, 23];
assert.equal(dagre.layout.order.bilayerCrossCount(g, layer1, layer2), 0);
assert.equal(order().bilayerCrossCount(g, layer1, layer2), 0);
});

@@ -77,7 +104,7 @@

// Here we have 12 -> 22 crossing 13 -> 21
var g = dagre.dot.toGraph("digraph {11 -> 21; 12 -> 21; 12 -> 22; 13 -> 21; 13 -> 22}");
var g = dot.toGraph("digraph {11 -> 21; 12 -> 21; 12 -> 22; 13 -> 21; 13 -> 22}");
var layer1 = [11, 12, 13];
var layer2 = [21, 22];
assert.equal(dagre.layout.order.bilayerCrossCount(g, layer1, layer2), 1);
assert.equal(order().bilayerCrossCount(g, layer1, layer2), 1);
});

@@ -87,18 +114,8 @@

// Here we have 11 -> 22 crossing 12 -> 21 and 13 -> 21, and we have 12 -> 22 crossing 13 -> 21
var g = dagre.dot.toGraph("digraph {11 -> 22; 12 -> 21; 12 -> 22; 13 -> 21; 13 -> 22}");
var g = dot.toGraph("digraph {11 -> 22; 12 -> 21; 12 -> 22; 13 -> 21; 13 -> 22}");
var layer1 = [11, 12, 13];
var layer2 = [21, 22];
assert.equal(dagre.layout.order.bilayerCrossCount(g, layer1, layer2), 3);
assert.equal(order().bilayerCrossCount(g, layer1, layer2), 3);
});
it("calculates the correct weight of crossings with edge weights", function() {
var g = dagre.dot.toGraph("digraph {11 -> 22 [weight=2]; 12 -> 21 [weight=3]; }");
var layer1 = [11, 12];
var layer2 = [21, 22];
function edgeWeight(e) { return g.edge(e).weight; }
assert.equal(dagre.layout.order.bilayerCrossCount(g, layer1, layer2, edgeWeight), 6);
});
});

@@ -1,8 +0,11 @@

require("../common");
var common = require("../common"),
assert = require("chai").assert,
dot = require("../../lib/dot"),
rank = require("../../lib/layout/rank");
describe("dagre.layout.rank", function() {
describe("layout/rank", function() {
it("assigns rank 0 to a node in a singleton graph", function() {
var g = dagre.dot.toGraph("digraph { A }");
var g = dot.toGraph("digraph { A }");
dagre.layout.rank().run(g);
rank(g);

@@ -13,5 +16,5 @@ assert.equal(g.node("A").rank, 0);

it("assigns successive ranks to succesors", function() {
var g = dagre.dot.toGraph("digraph { A -> B }");
var g = dot.toGraph("digraph { A -> B }");
dagre.layout.rank().run(g);
rank(g);

@@ -25,5 +28,5 @@ assert.equal(g.node("A").rank, 0);

// below both of them.
var g = dagre.dot.toGraph("digraph { A -> B; B -> C; A -> C }");
var g = dot.toGraph("digraph { A -> B; B -> C; A -> C }");
dagre.layout.rank().run(g);
rank(g);

@@ -36,5 +39,5 @@ assert.equal(g.node("A").rank, 0);

it("uses an edge's minLen attribute to determine rank", function() {
var g = dagre.dot.toGraph("digraph { A -> B [minLen=2] }");
var g = dot.toGraph("digraph { A -> B [minLen=2] }");
dagre.layout.rank().run(g);
rank(g);

@@ -41,0 +44,0 @@ assert.equal(g.node("A").rank, 0);

@@ -1,49 +0,14 @@

require("./common");
var common = require("./common"),
assert = require("chai").assert,
util = require("../lib/util"),
graph = require("../lib/Graph");
var assert2 = require("assert");
describe("dagre.util.components", function() {
it("returns all nodes in a connected graph", function() {
var g = dagre.graph();
[1, 2, 3].forEach(function(u) { g.addNode(u); });
g.addEdge("A", 1, 2);
g.addEdge("B", 2, 3);
var cmpts = dagre.util.components(g);
assert.deepEqual(cmpts.map(function(cmpt) { return cmpt.sort(); }),
[[1, 2, 3]]);
describe("util.sum", function() {
it("returns the sum of all elements in the array", function() {
assert.equal(util.sum([1,2,3,4]), 10);
});
it("returns maximal subsets of connected nodes", function() {
var g = dagre.graph();
[1, 2, 3, 4, 5, 6].forEach(function(u) { g.addNode(u); });
g.addEdge("A", 1, 2);
g.addEdge("B", 2, 3);
g.addEdge("C", 4, 5);
var cmpts = dagre.util.components(g).sort(function(x, y) { return y.length - x.length; });
assert2.deepEqual(cmpts.map(function(cmpt) { return cmpt.sort(); }),
[[1, 2, 3], [4, 5], [6]]);
it("returns 0 if there are no elements in the array", function() {
assert.equal(util.sum([]), 0);
});
});
describe("dagre.util.prim", function() {
it("returns a deterministic minimal spanning tree", function() {
var g = dagre.graph();
[1, 2, 3, 4].forEach(function(u) { g.addNode(u); });
g.addEdge("12", 1, 2);
g.addEdge("13", 1, 3);
g.addEdge("24", 2, 4);
g.addEdge("34", 3, 4);
var weights = { 12: 1, 13: 2, 24: 3, 34: 4 };
var st = dagre.util.prim(g, function(u, v) { return weights[[u,v].sort().join("")]; });
Object.keys(st).forEach(function(x) { st[x].sort(); });
assert.deepEqual({1: [2, 3], 2: [1, 4], 3: [1], 4: [2]}, st);
});
it("returns a single field for a single node graph", function() {
var g = dagre.graph();
g.addNode(1);
assert.deepEqual({1: []}, dagre.util.prim(g));
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc