Skip to content

Commit bc5f73d

Browse files
committed
Fix for issue #37
Updated dependencies to dagre/dagre-d3
1 parent ec90946 commit bc5f73d

13 files changed

+660
-191
lines changed

dist/mermaid.full.js

Lines changed: 133 additions & 82 deletions
Large diffs are not rendered by default.

dist/mermaid.full.min.js

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mermaid.slim.js

Lines changed: 128 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(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){
1+
(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){
22
!function() {
33
var d3 = {
44
version: "3.4.13"
@@ -9252,7 +9252,8 @@ var util = require("./util");
92529252
module.exports = {
92539253
"default": normal,
92549254
"normal": normal,
9255-
"vee": vee
9255+
"vee": vee,
9256+
"undirected": undirected
92569257
};
92579258

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

9295+
function undirected(parent, id, edge, type) {
9296+
var marker = parent.append("marker")
9297+
.attr("id", id)
9298+
.attr("viewBox", "0 0 10 10")
9299+
.attr("refX", 9)
9300+
.attr("refY", 5)
9301+
.attr("markerUnits", "strokeWidth")
9302+
.attr("markerWidth", 8)
9303+
.attr("markerHeight", 6)
9304+
.attr("orient", "auto");
9305+
9306+
var path = marker.append("path")
9307+
.attr("d", "M 0 5 L 10 5")
9308+
.style("stroke-width", 1)
9309+
.style("stroke-dasharray", "1,0");
9310+
util.applyStyle(path, edge[type + "Style"]);
9311+
}
9312+
92949313
},{"./util":26}],4:[function(require,module,exports){
92959314
var util = require("./util");
92969315

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

9406+
// Save DOM element in the path group, and set ID
9407+
svgPaths.each(function(e) {
9408+
var edge = g.edge(e);
9409+
edge.elem = this;
9410+
if (edge.id) {
9411+
d3.select(this).attr("id", edge.id);
9412+
}
9413+
});
9414+
93879415
svgPaths.selectAll("path.path")
93889416
.each(function(e) {
93899417
var edge = g.edge(e);
@@ -9398,7 +9426,6 @@ function createEdgePaths(selection, g, arrows) {
93989426
util.applyTransition(domEdge, g)
93999427
.attr("d", function(e) { return calcPoints(g, e); });
94009428

9401-
if (edge.id) { domEdge.attr("id", edge.id); }
94029429
util.applyStyle(domEdge, edge.style);
94039430
});
94049431

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

95169543
if (node.id) { thisGroup.attr("id", node.id); }
95179544
if (node.labelId) { labelGroup.attr("id", node.labelId); }
9518-
util.applyClass(thisGroup, node.class, (thisGroup.classed("update") ? "update " : "") + "node");
9545+
util.applyClass(thisGroup, node["class"],
9546+
(thisGroup.classed("update") ? "update " : "") + "node");
95199547

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

1014710175
var intersectRect = require("./intersect/intersect-rect"),
1014810176
intersectEllipse = require("./intersect/intersect-ellipse"),
10149-
intersectCircle = require("./intersect/intersect-circle");
10177+
intersectCircle = require("./intersect/intersect-circle"),
10178+
intersectPolygon = require("./intersect/intersect-polygon");
1015010179

1015110180
module.exports = {
1015210181
rect: rect,
1015310182
ellipse: ellipse,
10154-
circle: circle
10183+
circle: circle,
10184+
diamond: diamond
1015510185
};
1015610186

1015710187
function rect(parent, bbox, node) {
@@ -10200,7 +10230,29 @@ function circle(parent, bbox, node) {
1020010230
return shapeSvg;
1020110231
}
1020210232

10203-
},{"./intersect/intersect-circle":12,"./intersect/intersect-ellipse":13,"./intersect/intersect-rect":17}],26:[function(require,module,exports){
10233+
// Circumscribe an ellipse for the bounding box with a diamond shape. I derived
10234+
// the function to calculate the diamond shape from:
10235+
// http://mathforum.org/kb/message.jspa?messageID=3750236
10236+
function diamond(parent, bbox, node) {
10237+
var w = (bbox.width * Math.SQRT2) / 2,
10238+
h = (bbox.height * Math.SQRT2) / 2,
10239+
points = [
10240+
{ x: 0, y: -h },
10241+
{ x: -w, y: 0 },
10242+
{ x: 0, y: h },
10243+
{ x: w, y: 0 }
10244+
],
10245+
shapeSvg = parent.insert("polygon", ":first-child")
10246+
.attr("points", points.map(function(p) { return p.x + "," + p.y; }).join(" "));
10247+
10248+
node.intersect = function(p) {
10249+
return intersectPolygon(node, points, p);
10250+
};
10251+
10252+
return shapeSvg;
10253+
}
10254+
10255+
},{"./intersect/intersect-circle":12,"./intersect/intersect-ellipse":13,"./intersect/intersect-polygon":16,"./intersect/intersect-rect":17}],26:[function(require,module,exports){
1020410256
var _ = require("./lodash");
1020510257

1020610258
// Public utility functions
@@ -10257,7 +10309,7 @@ function applyTransition(selection, g) {
1025710309
}
1025810310

1025910311
},{"./lodash":21}],27:[function(require,module,exports){
10260-
module.exports = "0.3.3";
10312+
module.exports = "0.4.2";
1026110313

1026210314
},{}],28:[function(require,module,exports){
1026310315
/*
@@ -10644,7 +10696,7 @@ function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
1064410696
var weight = g.edge(edge),
1064510697
w = edge.w,
1064610698
wEntry = g.node(w);
10647-
wEntry.in -= weight;
10699+
wEntry["in"] -= weight;
1064810700
assignBucket(buckets, zeroIdx, wEntry);
1064910701
});
1065010702

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

1066110713
_.each(g.nodes(), function(v) {
10662-
fasGraph.setNode(v, { v: v, in: 0, out: 0 });
10714+
fasGraph.setNode(v, { v: v, "in": 0, out: 0 });
1066310715
});
1066410716

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

1067610728
var buckets = _.range(maxOut + maxIn + 3).map(function() { return new List(); });
@@ -10686,10 +10738,10 @@ function buildState(g, weightFn) {
1068610738
function assignBucket(buckets, zeroIdx, entry) {
1068710739
if (!entry.out) {
1068810740
buckets[0].enqueue(entry);
10689-
} else if (!entry.in) {
10741+
} else if (!entry["in"]) {
1069010742
buckets[buckets.length - 1].enqueue(entry);
1069110743
} else {
10692-
buckets[entry.out - entry.in + zeroIdx].enqueue(entry);
10744+
buckets[entry.out - entry["in"] + zeroIdx].enqueue(entry);
1069310745
}
1069410746
}
1069510747

@@ -11705,7 +11757,7 @@ function resolveConflicts(entries, cg) {
1170511757
_.each(entries, function(entry, i) {
1170611758
var tmp = mappedEntries[entry.v] = {
1170711759
indegree: 0,
11708-
in: [],
11760+
"in": [],
1170911761
out: [],
1171011762
vs: [entry.v],
1171111763
i: i
@@ -11750,7 +11802,7 @@ function doResolveConflicts(sourceSet) {
1175011802

1175111803
function handleOut(vEntry) {
1175211804
return function(wEntry) {
11753-
wEntry.in.push(vEntry);
11805+
wEntry["in"].push(vEntry);
1175411806
if (--wEntry.indegree === 0) {
1175511807
sourceSet.push(wEntry);
1175611808
}
@@ -11760,7 +11812,7 @@ function doResolveConflicts(sourceSet) {
1176011812
while (sourceSet.length) {
1176111813
var entry = sourceSet.pop();
1176211814
entries.push(entry);
11763-
_.each(entry.in.reverse(), handleIn(entry));
11815+
_.each(entry["in"].reverse(), handleIn(entry));
1176411816
_.each(entry.out, handleOut(entry));
1176511817
}
1176611818

@@ -12022,6 +12074,7 @@ function postorder(g) {
1202212074
"use strict";
1202312075

1202412076
var _ = require("../lodash"),
12077+
Graph = require("../graphlib").Graph,
1202512078
util = require("../util");
1202612079

1202712080
/*
@@ -12225,74 +12278,71 @@ function verticalAlignment(g, layering, conflicts, neighborFn) {
1222512278
}
1222612279

1222712280
function horizontalCompaction(g, layering, root, align, reverseSep) {
12228-
// We use local variables for these parameters instead of manipulating the
12229-
// graph because it becomes more verbose to access them in a chained manner.
12230-
var shift = {},
12231-
shiftNeighbor = {},
12232-
sink = {},
12233-
xs = {},
12234-
pred = {},
12235-
graphLabel = g.graph(),
12236-
sepFn = sep(graphLabel.nodesep, graphLabel.edgesep, reverseSep);
12237-
12238-
_.each(layering, function(layer) {
12239-
_.each(layer, function(v, order) {
12240-
sink[v] = v;
12241-
shift[v] = Number.POSITIVE_INFINITY;
12242-
pred[v] = layer[order - 1];
12243-
});
12244-
});
12281+
// This portion of the algorithm differs from BK due to a number of problems.
12282+
// Instead of their algorithm we construct a new block graph and do two
12283+
// sweeps. The first sweep places blocks with the smallest possible
12284+
// coordinates. The second sweep removes unused space by moving blocks to the
12285+
// greatest coordinates without violating separation.
12286+
var xs = {},
12287+
blockG = buildBlockGraph(g, layering, root, reverseSep);
12288+
12289+
// First pass, assign smallest coordinates via DFS
12290+
var visited = {};
12291+
function pass1(v) {
12292+
if (!_.has(visited, v)) {
12293+
visited[v] = true;
12294+
xs[v] = _.reduce(blockG.inEdges(v), function(max, e) {
12295+
pass1(e.v);
12296+
return Math.max(max, xs[e.v] + blockG.edge(e));
12297+
}, 0);
12298+
}
12299+
}
12300+
_.each(blockG.nodes(), pass1);
1224512301

12246-
_.each(g.nodes(), function(v) {
12247-
if (root[v] === v) {
12248-
placeBlock(g, layering, sepFn, root, align, shift, shiftNeighbor, sink, pred, xs, v);
12302+
function pass2(v) {
12303+
if (visited[v] !== 2) {
12304+
visited[v]++;
12305+
var min = _.reduce(blockG.outEdges(v), function(min, e) {
12306+
pass2(e.w);
12307+
return Math.min(min, xs[e.w] - blockG.edge(e));
12308+
}, Number.POSITIVE_INFINITY);
12309+
if (min !== Number.POSITIVE_INFINITY) {
12310+
xs[v] = Math.max(xs[v], min);
12311+
}
1224912312
}
12250-
});
12313+
}
12314+
_.each(blockG.nodes(), pass2);
1225112315

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

12260-
// Cascade shifts as necessary
12261-
var w = shiftNeighbor[sink[root[v]]];
12262-
if (w && shift[w] !== Number.POSITIVE_INFINITY) {
12263-
xs[v] += shift[w];
12264-
}
12265-
}
12266-
});
12317+
// Assign x coordinates to all nodes
12318+
_.each(align, function(v) {
12319+
xs[v] = xs[root[v]];
1226712320
});
1226812321

1226912322
return xs;
1227012323
}
1227112324

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

12276-
var w = v,
12277-
u;
12278-
do {
12279-
if (pred[w]) {
12280-
u = root[pred[w]];
12281-
placeBlock(g, layering, sepFn, root, align, shift, shiftNeighbor, sink, pred, xs, u);
12282-
if (sink[v] === v) {
12283-
sink[v] = sink[u];
12284-
}
12326+
function buildBlockGraph(g, layering, root, reverseSep) {
12327+
var blockGraph = new Graph(),
12328+
graphLabel = g.graph(),
12329+
sepFn = sep(graphLabel.nodesep, graphLabel.edgesep, reverseSep);
1228512330

12286-
var delta = sepFn(g, w, pred[w]);
12287-
if (sink[v] !== sink[u]) {
12288-
shift[sink[u]] = Math.min(shift[sink[u]], xs[v] - xs[u] - delta);
12289-
shiftNeighbor[sink[u]] = sink[v];
12290-
} else {
12291-
xs[v] = Math.max(xs[v], xs[u] + delta);
12292-
}
12293-
}
12294-
w = align[w];
12295-
} while (w !== v);
12331+
_.each(layering, function(layer) {
12332+
var u;
12333+
_.each(layer, function(v) {
12334+
var vRoot = root[v];
12335+
blockGraph.setNode(vRoot);
12336+
if (u) {
12337+
var uRoot = root[u],
12338+
prevMax = blockGraph.edge(uRoot, vRoot);
12339+
blockGraph.setEdge(uRoot, vRoot, Math.max(sepFn(g, v, u), prevMax || 0));
12340+
}
12341+
u = v;
12342+
});
12343+
});
12344+
12345+
return blockGraph;
1229612346
}
1229712347

1229812348
/*
@@ -12419,7 +12469,7 @@ function width(g, v) {
1241912469
return g.node(v).width;
1242012470
}
1242112471

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

1242512475
var _ = require("../lodash"),
@@ -13130,7 +13180,7 @@ function notime(name, fn) {
1313013180
}
1313113181

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

1313513185
},{}],58:[function(require,module,exports){
1313613186
/**
@@ -24757,7 +24807,7 @@ module.exports={
2475724807
"dependencies": {
2475824808
"chalk": "^0.5.1",
2475924809
"d3": "~3.4.13",
24760-
"dagre-d3": "~0.3.3",
24810+
"dagre-d3": "~0.4.2",
2476124811
"he": "^0.5.0",
2476224812
"minimist": "^1.1.0",
2476324813
"mkdirp": "^0.5.0",
@@ -24782,6 +24832,7 @@ module.exports={
2478224832
"gulp-data": "^1.1.1",
2478324833
"gulp-ext-replace": "~0.1.0",
2478424834
"gulp-hogan": "^1.1.0",
24835+
"gulp-insert": "^0.4.0",
2478524836
"gulp-istanbul": "^0.4.0",
2478624837
"gulp-jasmine": "~1.0.1",
2478724838
"gulp-jison": "~1.0.0",
@@ -31017,4 +31068,4 @@ module.exports.cloneCssStyles = function(svg, classes){
3101731068
}
3101831069
};
3101931070

31020-
},{}]},{},[102])
31071+
},{}]},{},[102]) })();

dist/mermaid.slim.min.js

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var bump = require('gulp-bump');
1212
var tag_version = require('gulp-tag-version');
1313
var jshint = require('gulp-jshint');
1414
var stylish = require('jshint-stylish');
15+
var insert = require('gulp-insert');
1516

1617
var paths = {
1718
scripts: ['./src/**/*.js', '!**/parser/*.js']
@@ -91,6 +92,8 @@ gulp.task('slimDist', function() {
9192
});
9293
})*/
9394
.pipe(rename('mermaid.slim.js'))
95+
.pipe(insert.prepend('(function () { var define = undefined; '))
96+
.pipe(insert.append(' })();'))
9497
.pipe(gulp.dest('./dist/'))
9598
.pipe(uglify())
9699
.pipe(extReplace('.min.js'))

0 commit comments

Comments
 (0)