Skip to content

Commit

Permalink
Fix for issue #37
Browse files Browse the repository at this point in the history
Updated dependencies to dagre/dagre-d3
  • Loading branch information
knsv committed Mar 7, 2015
1 parent ec90946 commit bc5f73d
Show file tree
Hide file tree
Showing 13 changed files with 660 additions and 191 deletions.
215 changes: 133 additions & 82 deletions dist/mermaid.full.js

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions dist/mermaid.full.min.js

Large diffs are not rendered by default.

205 changes: 128 additions & 77 deletions dist/mermaid.slim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function () { var define = undefined; (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
!function() {
var d3 = {
version: "3.4.13"
Expand Down Expand Up @@ -9252,7 +9252,8 @@ var util = require("./util");
module.exports = {
"default": normal,
"normal": normal,
"vee": vee
"vee": vee,
"undirected": undirected
};

function normal(parent, id, edge, type) {
Expand Down Expand Up @@ -9291,6 +9292,24 @@ function vee(parent, id, edge, type) {
util.applyStyle(path, edge[type + "Style"]);
}

function undirected(parent, id, edge, type) {
var marker = parent.append("marker")
.attr("id", id)
.attr("viewBox", "0 0 10 10")
.attr("refX", 9)
.attr("refY", 5)
.attr("markerUnits", "strokeWidth")
.attr("markerWidth", 8)
.attr("markerHeight", 6)
.attr("orient", "auto");

var path = marker.append("path")
.attr("d", "M 0 5 L 10 5")
.style("stroke-width", 1)
.style("stroke-dasharray", "1,0");
util.applyStyle(path, edge[type + "Style"]);
}

},{"./util":26}],4:[function(require,module,exports){
var util = require("./util");

Expand Down Expand Up @@ -9384,6 +9403,15 @@ function createEdgePaths(selection, g, arrows) {
util.applyTransition(svgPaths, g)
.style("opacity", 1);

// Save DOM element in the path group, and set ID
svgPaths.each(function(e) {
var edge = g.edge(e);
edge.elem = this;
if (edge.id) {
d3.select(this).attr("id", edge.id);
}
});

svgPaths.selectAll("path.path")
.each(function(e) {
var edge = g.edge(e);
Expand All @@ -9398,7 +9426,6 @@ function createEdgePaths(selection, g, arrows) {
util.applyTransition(domEdge, g)
.attr("d", function(e) { return calcPoints(g, e); });

if (edge.id) { domEdge.attr("id", edge.id); }
util.applyStyle(domEdge, edge.style);
});

Expand Down Expand Up @@ -9515,7 +9542,8 @@ function createNodes(selection, g, shapes) {

if (node.id) { thisGroup.attr("id", node.id); }
if (node.labelId) { labelGroup.attr("id", node.labelId); }
util.applyClass(thisGroup, node.class, (thisGroup.classed("update") ? "update " : "") + "node");
util.applyClass(thisGroup, node["class"],
(thisGroup.classed("update") ? "update " : "") + "node");

if (_.has(node, "width")) { bbox.width = node.width; }
if (_.has(node, "height")) { bbox.height = node.height; }
Expand Down Expand Up @@ -10146,12 +10174,14 @@ function createOrSelectGroup(root, name) {

var intersectRect = require("./intersect/intersect-rect"),
intersectEllipse = require("./intersect/intersect-ellipse"),
intersectCircle = require("./intersect/intersect-circle");
intersectCircle = require("./intersect/intersect-circle"),
intersectPolygon = require("./intersect/intersect-polygon");

module.exports = {
rect: rect,
ellipse: ellipse,
circle: circle
circle: circle,
diamond: diamond
};

function rect(parent, bbox, node) {
Expand Down Expand Up @@ -10200,7 +10230,29 @@ function circle(parent, bbox, node) {
return shapeSvg;
}

},{"./intersect/intersect-circle":12,"./intersect/intersect-ellipse":13,"./intersect/intersect-rect":17}],26:[function(require,module,exports){
// Circumscribe an ellipse for the bounding box with a diamond shape. I derived
// the function to calculate the diamond shape from:
// http://mathforum.org/kb/message.jspa?messageID=3750236
function diamond(parent, bbox, node) {
var w = (bbox.width * Math.SQRT2) / 2,
h = (bbox.height * Math.SQRT2) / 2,
points = [
{ x: 0, y: -h },
{ x: -w, y: 0 },
{ x: 0, y: h },
{ x: w, y: 0 }
],
shapeSvg = parent.insert("polygon", ":first-child")
.attr("points", points.map(function(p) { return p.x + "," + p.y; }).join(" "));

node.intersect = function(p) {
return intersectPolygon(node, points, p);
};

return shapeSvg;
}

},{"./intersect/intersect-circle":12,"./intersect/intersect-ellipse":13,"./intersect/intersect-polygon":16,"./intersect/intersect-rect":17}],26:[function(require,module,exports){
var _ = require("./lodash");

// Public utility functions
Expand Down Expand Up @@ -10257,7 +10309,7 @@ function applyTransition(selection, g) {
}

},{"./lodash":21}],27:[function(require,module,exports){
module.exports = "0.3.3";
module.exports = "0.4.2";

},{}],28:[function(require,module,exports){
/*
Expand Down Expand Up @@ -10644,7 +10696,7 @@ function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
var weight = g.edge(edge),
w = edge.w,
wEntry = g.node(w);
wEntry.in -= weight;
wEntry["in"] -= weight;
assignBucket(buckets, zeroIdx, wEntry);
});

Expand All @@ -10659,7 +10711,7 @@ function buildState(g, weightFn) {
maxOut = 0;

_.each(g.nodes(), function(v) {
fasGraph.setNode(v, { v: v, in: 0, out: 0 });
fasGraph.setNode(v, { v: v, "in": 0, out: 0 });
});

// Aggregate weights on nodes, but also sum the weights across multi-edges
Expand All @@ -10670,7 +10722,7 @@ function buildState(g, weightFn) {
edgeWeight = prevWeight + weight;
fasGraph.setEdge(e.v, e.w, edgeWeight);
maxOut = Math.max(maxOut, fasGraph.node(e.v).out += weight);
maxIn = Math.max(maxIn, fasGraph.node(e.w).in += weight);
maxIn = Math.max(maxIn, fasGraph.node(e.w)["in"] += weight);
});

var buckets = _.range(maxOut + maxIn + 3).map(function() { return new List(); });
Expand All @@ -10686,10 +10738,10 @@ function buildState(g, weightFn) {
function assignBucket(buckets, zeroIdx, entry) {
if (!entry.out) {
buckets[0].enqueue(entry);
} else if (!entry.in) {
} else if (!entry["in"]) {
buckets[buckets.length - 1].enqueue(entry);
} else {
buckets[entry.out - entry.in + zeroIdx].enqueue(entry);
buckets[entry.out - entry["in"] + zeroIdx].enqueue(entry);
}
}

Expand Down Expand Up @@ -11705,7 +11757,7 @@ function resolveConflicts(entries, cg) {
_.each(entries, function(entry, i) {
var tmp = mappedEntries[entry.v] = {
indegree: 0,
in: [],
"in": [],
out: [],
vs: [entry.v],
i: i
Expand Down Expand Up @@ -11750,7 +11802,7 @@ function doResolveConflicts(sourceSet) {

function handleOut(vEntry) {
return function(wEntry) {
wEntry.in.push(vEntry);
wEntry["in"].push(vEntry);
if (--wEntry.indegree === 0) {
sourceSet.push(wEntry);
}
Expand All @@ -11760,7 +11812,7 @@ function doResolveConflicts(sourceSet) {
while (sourceSet.length) {
var entry = sourceSet.pop();
entries.push(entry);
_.each(entry.in.reverse(), handleIn(entry));
_.each(entry["in"].reverse(), handleIn(entry));
_.each(entry.out, handleOut(entry));
}

Expand Down Expand Up @@ -12022,6 +12074,7 @@ function postorder(g) {
"use strict";

var _ = require("../lodash"),
Graph = require("../graphlib").Graph,
util = require("../util");

/*
Expand Down Expand Up @@ -12225,74 +12278,71 @@ function verticalAlignment(g, layering, conflicts, neighborFn) {
}

function horizontalCompaction(g, layering, root, align, reverseSep) {
// We use local variables for these parameters instead of manipulating the
// graph because it becomes more verbose to access them in a chained manner.
var shift = {},
shiftNeighbor = {},
sink = {},
xs = {},
pred = {},
graphLabel = g.graph(),
sepFn = sep(graphLabel.nodesep, graphLabel.edgesep, reverseSep);

_.each(layering, function(layer) {
_.each(layer, function(v, order) {
sink[v] = v;
shift[v] = Number.POSITIVE_INFINITY;
pred[v] = layer[order - 1];
});
});
// This portion of the algorithm differs from BK due to a number of problems.
// Instead of their algorithm we construct a new block graph and do two
// sweeps. The first sweep places blocks with the smallest possible
// coordinates. The second sweep removes unused space by moving blocks to the
// greatest coordinates without violating separation.
var xs = {},
blockG = buildBlockGraph(g, layering, root, reverseSep);

// First pass, assign smallest coordinates via DFS
var visited = {};
function pass1(v) {
if (!_.has(visited, v)) {
visited[v] = true;
xs[v] = _.reduce(blockG.inEdges(v), function(max, e) {
pass1(e.v);
return Math.max(max, xs[e.v] + blockG.edge(e));
}, 0);
}
}
_.each(blockG.nodes(), pass1);

_.each(g.nodes(), function(v) {
if (root[v] === v) {
placeBlock(g, layering, sepFn, root, align, shift, shiftNeighbor, sink, pred, xs, v);
function pass2(v) {
if (visited[v] !== 2) {
visited[v]++;
var min = _.reduce(blockG.outEdges(v), function(min, e) {
pass2(e.w);
return Math.min(min, xs[e.w] - blockG.edge(e));
}, Number.POSITIVE_INFINITY);
if (min !== Number.POSITIVE_INFINITY) {
xs[v] = Math.max(xs[v], min);
}
}
});
}
_.each(blockG.nodes(), pass2);

_.each(layering, function(layer) {
_.each(layer, function(v) {
xs[v] = xs[root[v]];
// This line differs from the source paper. See
// http://www.inf.uni-konstanz.de/~brandes/publications/ for details.
if (v === root[v] && shift[sink[root[v]]] < Number.POSITIVE_INFINITY) {
xs[v] += shift[sink[root[v]]];

// Cascade shifts as necessary
var w = shiftNeighbor[sink[root[v]]];
if (w && shift[w] !== Number.POSITIVE_INFINITY) {
xs[v] += shift[w];
}
}
});
// Assign x coordinates to all nodes
_.each(align, function(v) {
xs[v] = xs[root[v]];
});

return xs;
}

function placeBlock(g, layering, sepFn, root, align, shift, shiftNeighbor, sink, pred, xs, v) {
if (_.has(xs, v)) return;
xs[v] = 0;

var w = v,
u;
do {
if (pred[w]) {
u = root[pred[w]];
placeBlock(g, layering, sepFn, root, align, shift, shiftNeighbor, sink, pred, xs, u);
if (sink[v] === v) {
sink[v] = sink[u];
}
function buildBlockGraph(g, layering, root, reverseSep) {
var blockGraph = new Graph(),
graphLabel = g.graph(),
sepFn = sep(graphLabel.nodesep, graphLabel.edgesep, reverseSep);

var delta = sepFn(g, w, pred[w]);
if (sink[v] !== sink[u]) {
shift[sink[u]] = Math.min(shift[sink[u]], xs[v] - xs[u] - delta);
shiftNeighbor[sink[u]] = sink[v];
} else {
xs[v] = Math.max(xs[v], xs[u] + delta);
}
}
w = align[w];
} while (w !== v);
_.each(layering, function(layer) {
var u;
_.each(layer, function(v) {
var vRoot = root[v];
blockGraph.setNode(vRoot);
if (u) {
var uRoot = root[u],
prevMax = blockGraph.edge(uRoot, vRoot);
blockGraph.setEdge(uRoot, vRoot, Math.max(sepFn(g, v, u), prevMax || 0));
}
u = v;
});
});

return blockGraph;
}

/*
Expand Down Expand Up @@ -12419,7 +12469,7 @@ function width(g, v) {
return g.node(v).width;
}

},{"../lodash":37,"../util":56}],51:[function(require,module,exports){
},{"../graphlib":34,"../lodash":37,"../util":56}],51:[function(require,module,exports){
"use strict";

var _ = require("../lodash"),
Expand Down Expand Up @@ -13130,7 +13180,7 @@ function notime(name, fn) {
}

},{"./graphlib":34,"./lodash":37}],57:[function(require,module,exports){
module.exports = "0.6.4";
module.exports = "0.7.1";

},{}],58:[function(require,module,exports){
/**
Expand Down Expand Up @@ -24757,7 +24807,7 @@ module.exports={
"dependencies": {
"chalk": "^0.5.1",
"d3": "~3.4.13",
"dagre-d3": "~0.3.3",
"dagre-d3": "~0.4.2",
"he": "^0.5.0",
"minimist": "^1.1.0",
"mkdirp": "^0.5.0",
Expand All @@ -24782,6 +24832,7 @@ module.exports={
"gulp-data": "^1.1.1",
"gulp-ext-replace": "~0.1.0",
"gulp-hogan": "^1.1.0",
"gulp-insert": "^0.4.0",
"gulp-istanbul": "^0.4.0",
"gulp-jasmine": "~1.0.1",
"gulp-jison": "~1.0.0",
Expand Down Expand Up @@ -31017,4 +31068,4 @@ module.exports.cloneCssStyles = function(svg, classes){
}
};

},{}]},{},[102])
},{}]},{},[102]) })();
26 changes: 13 additions & 13 deletions dist/mermaid.slim.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var bump = require('gulp-bump');
var tag_version = require('gulp-tag-version');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var insert = require('gulp-insert');

var paths = {
scripts: ['./src/**/*.js', '!**/parser/*.js']
Expand Down Expand Up @@ -91,6 +92,8 @@ gulp.task('slimDist', function() {
});
})*/
.pipe(rename('mermaid.slim.js'))
.pipe(insert.prepend('(function () { var define = undefined; '))
.pipe(insert.append(' })();'))
.pipe(gulp.dest('./dist/'))
.pipe(uglify())
.pipe(extReplace('.min.js'))
Expand Down
Loading

0 comments on commit bc5f73d

Please sign in to comment.