Comparing version 0.3.9 to 0.3.10
@@ -0,1 +1,6 @@ | ||
v0.3.10 | ||
======= | ||
* Add support for 'BT' and 'RL' rankDir values. | ||
v0.3.9 | ||
@@ -2,0 +7,0 @@ ====== |
@@ -15,3 +15,5 @@ var util = require('./util'), | ||
// Use network simplex algorithm in ranking | ||
rankSimplex: false | ||
rankSimplex: false, | ||
// Rank direction. Valid values are (TB, LR) | ||
rankDir: 'TB' | ||
}; | ||
@@ -33,3 +35,3 @@ | ||
self.rankSep = delegateProperty(position.rankSep); | ||
self.rankDir = delegateProperty(position.rankDir); | ||
self.rankDir = util.propertyAccessor(self, config, 'rankDir'); | ||
self.debugAlignment = delegateProperty(position.debugAlignment); | ||
@@ -95,3 +97,7 @@ | ||
g.graph({}); | ||
// Initial graph attributes | ||
var graphValue = inputGraph.graph() || {}; | ||
g.graph({ | ||
rankDir: graphValue.rankDir || config.rankDir | ||
}); | ||
@@ -98,0 +104,0 @@ return g; |
@@ -13,4 +13,3 @@ var util = require('./util'); | ||
universalSep: null, | ||
rankSep: 30, | ||
rankDir: 'TB' | ||
rankSep: 30 | ||
}; | ||
@@ -27,3 +26,2 @@ | ||
self.rankSep = util.propertyAccessor(self, config, 'rankSep'); | ||
self.rankDir = util.propertyAccessor(self, config, 'rankDir'); | ||
self.debugLevel = util.propertyAccessor(self, config, 'debugLevel'); | ||
@@ -65,7 +63,9 @@ | ||
balance(g, layering, xss); | ||
g.eachNode(function(v) { | ||
var xs = []; | ||
for (var alignment in xss) { | ||
posXDebug(alignment, g, v, xss[alignment][v]); | ||
xs.push(xss[alignment][v]); | ||
var alignmentX = xss[alignment][v]; | ||
posXDebug(alignment, g, v, alignmentX); | ||
xs.push(alignmentX); | ||
} | ||
@@ -76,14 +76,21 @@ xs.sort(function(x, y) { return x - y; }); | ||
// Translate layout so left edge of bounding rectangle has coordinate 0 | ||
var minX = util.min(g.nodes().map(function(u) { return posX(g, u) - width(g, u) / 2; })); | ||
g.eachNode(function(u) { posX(g, u, posX(g, u) - minX); }); | ||
// Align y coordinates with ranks | ||
var y = 0; | ||
var y = 0, reverseY = g.graph().rankDir === 'BT' || g.graph().rankDir === 'RL'; | ||
layering.forEach(function(layer) { | ||
var maxHeight = util.max(layer.map(function(u) { return height(g, u); })); | ||
y += maxHeight / 2; | ||
layer.forEach(function(u) { posY(g, u, y); }); | ||
layer.forEach(function(u) { | ||
posY(g, u, reverseY ? -y : y); | ||
}); | ||
y += maxHeight / 2 + config.rankSep; | ||
}); | ||
// Translate layout so that top left corner of bounding rectangle has | ||
// coordinate (0, 0). | ||
var minX = util.min(g.nodes().map(function(u) { return posX(g, u) - width(g, u) / 2; })); | ||
var minY = util.min(g.nodes().map(function(u) { return posY(g, u) - height(g, u) / 2; })); | ||
g.eachNode(function(u) { | ||
posX(g, u, posX(g, u) - minX); | ||
posY(g, u, posY(g, u) - minY); | ||
}); | ||
} | ||
@@ -345,4 +352,5 @@ | ||
function width(g, u) { | ||
switch (config.rankDir) { | ||
switch (g.graph().rankDir) { | ||
case 'LR': return g.node(u).height; | ||
case 'RL': return g.node(u).height; | ||
default: return g.node(u).width; | ||
@@ -353,4 +361,5 @@ } | ||
function height(g, u) { | ||
switch(config.rankDir) { | ||
switch(g.graph().rankDir) { | ||
case 'LR': return g.node(u).width; | ||
case 'RL': return g.node(u).width; | ||
default: return g.node(u).height; | ||
@@ -370,16 +379,14 @@ } | ||
function posX(g, u, x) { | ||
switch (config.rankDir) { | ||
case 'LR': | ||
if (arguments.length < 3) { | ||
return g.node(u).y; | ||
} else { | ||
g.node(u).y = x; | ||
} | ||
break; | ||
default: | ||
if (arguments.length < 3) { | ||
return g.node(u).x; | ||
} else { | ||
g.node(u).x = x; | ||
} | ||
if (g.graph().rankDir === 'LR' || g.graph().rankDir === 'RL') { | ||
if (arguments.length < 3) { | ||
return g.node(u).y; | ||
} else { | ||
g.node(u).y = x; | ||
} | ||
} else { | ||
if (arguments.length < 3) { | ||
return g.node(u).x; | ||
} else { | ||
g.node(u).x = x; | ||
} | ||
} | ||
@@ -389,16 +396,14 @@ } | ||
function posXDebug(name, g, u, x) { | ||
switch (config.rankDir) { | ||
case 'LR': | ||
if (arguments.length < 3) { | ||
return g.node(u)[name]; | ||
} else { | ||
g.node(u)[name] = x; | ||
} | ||
break; | ||
default: | ||
if (arguments.length < 3) { | ||
return g.node(u)[name]; | ||
} else { | ||
g.node(u)[name] = x; | ||
} | ||
if (g.graph().rankDir === 'LR' || g.graph().rankDir === 'RL') { | ||
if (arguments.length < 3) { | ||
return g.node(u)[name]; | ||
} else { | ||
g.node(u)[name] = x; | ||
} | ||
} else { | ||
if (arguments.length < 3) { | ||
return g.node(u)[name]; | ||
} else { | ||
g.node(u)[name] = x; | ||
} | ||
} | ||
@@ -408,16 +413,14 @@ } | ||
function posY(g, u, y) { | ||
switch (config.rankDir) { | ||
case 'LR': | ||
if (arguments.length < 3) { | ||
return g.node(u).x; | ||
} else { | ||
g.node(u).x = y; | ||
} | ||
break; | ||
default: | ||
if (arguments.length < 3) { | ||
return g.node(u).y; | ||
} else { | ||
g.node(u).y = y; | ||
} | ||
if (g.graph().rankDir === 'LR' || g.graph().rankDir === 'RL') { | ||
if (arguments.length < 3) { | ||
return g.node(u).x; | ||
} else { | ||
g.node(u).x = y; | ||
} | ||
} else { | ||
if (arguments.length < 3) { | ||
return g.node(u).y; | ||
} else { | ||
g.node(u).y = y; | ||
} | ||
} | ||
@@ -424,0 +427,0 @@ } |
@@ -5,3 +5,3 @@ /* | ||
exports.min = function(values) { | ||
return Math.min.apply(null, values); | ||
return Math.min.apply(Math, values); | ||
}; | ||
@@ -13,3 +13,3 @@ | ||
exports.max = function(values) { | ||
return Math.max.apply(null, values); | ||
return Math.max.apply(Math, values); | ||
}; | ||
@@ -16,0 +16,0 @@ |
@@ -1,1 +0,1 @@ | ||
module.exports = '0.3.9'; | ||
module.exports = '0.3.10'; |
{ | ||
"name": "dagre", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"description": "Graph layout for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75562
1835