Skip to content

Commit

Permalink
Merge pull request #1 from bjowes/master
Browse files Browse the repository at this point in the history
Added new shapes!
  • Loading branch information
knsv committed Nov 27, 2014
2 parents d522241 + 28f6b93 commit 2893297
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/*
40 changes: 34 additions & 6 deletions dist/mermaid.full.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/mermaid.full.min.js

Large diffs are not rendered by default.

40 changes: 34 additions & 6 deletions dist/mermaid.slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,10 @@ var addVertices = function (vert, g) {
_shape = 'question';
break;
case 'odd':
_shape = 'question';
_shape = 'rect_left_inv_arrow';
break;
case 'circle':
_shape = 'circle';
break;
}

Expand Down Expand Up @@ -810,12 +813,13 @@ var draw = function (text, id) {
// Add custom shape for rhombus type of boc (decision)
render.shapes().question = function (parent, bbox, node) {
var w = bbox.width,
h = bbox.height * 3,
h = bbox.height,
s = (w + h) * 0.8,
points = [
{x: w / 2, y: 0},
{x: w, y: -h / 2},
{x: w / 2, y: -h},
{x: 0, y: -h / 2}
{x: s / 2, y: 0},
{x: s, y: -s / 2},
{x: s / 2, y: -s},
{x: 0, y: -s / 2}
];
shapeSvg = parent.insert("polygon", ":first-child")
.attr("points", points.map(function (d) {
Expand All @@ -825,6 +829,30 @@ var draw = function (text, id) {
.style("stroke", "#333")
.attr("rx", 5)
.attr("ry", 5)
.attr("transform", "translate(" + (-s / 2) + "," + (s * 2 / 4) + ")");
node.intersect = function (point) {
return dagreD3.intersect.polygon(node, points, point);
};
return shapeSvg;
};

// Add custom shape for box with inverted arrow on left side
render.shapes().rect_left_inv_arrow = function (parent, bbox, node) {
var w = bbox.width,
h = bbox.height,
points = [
{x: -h/2, y: 0},
{x: w, y: 0},
{x: w, y: -h},
{x: -h/2, y: -h},
{x: 0, y: -h/2},
];
shapeSvg = parent.insert("polygon", ":first-child")
.attr("points", points.map(function (d) {
return d.x + "," + d.y;
}).join(" "))
.style("fill", "#fff")
.style("stroke", "#333")
.attr("transform", "translate(" + (-w / 2) + "," + (h * 2 / 4) + ")");
node.intersect = function (point) {
return dagreD3.intersect.polygon(node, points, point);
Expand Down
6 changes: 3 additions & 3 deletions dist/mermaid.slim.min.js

Large diffs are not rendered by default.

40 changes: 34 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ var addVertices = function (vert, g) {
_shape = 'question';
break;
case 'odd':
_shape = 'question';
_shape = 'rect_left_inv_arrow';
break;
case 'circle':
_shape = 'circle';
break;
}

Expand Down Expand Up @@ -180,12 +183,13 @@ var draw = function (text, id) {
// Add custom shape for rhombus type of boc (decision)
render.shapes().question = function (parent, bbox, node) {
var w = bbox.width,
h = bbox.height * 3,
h = bbox.height,
s = (w + h) * 0.8,
points = [
{x: w / 2, y: 0},
{x: w, y: -h / 2},
{x: w / 2, y: -h},
{x: 0, y: -h / 2}
{x: s / 2, y: 0},
{x: s, y: -s / 2},
{x: s / 2, y: -s},
{x: 0, y: -s / 2}
];
shapeSvg = parent.insert("polygon", ":first-child")
.attr("points", points.map(function (d) {
Expand All @@ -195,6 +199,30 @@ var draw = function (text, id) {
.style("stroke", "#333")
.attr("rx", 5)
.attr("ry", 5)
.attr("transform", "translate(" + (-s / 2) + "," + (s * 2 / 4) + ")");
node.intersect = function (point) {
return dagreD3.intersect.polygon(node, points, point);
};
return shapeSvg;
};

// Add custom shape for box with inverted arrow on left side
render.shapes().rect_left_inv_arrow = function (parent, bbox, node) {
var w = bbox.width,
h = bbox.height,
points = [
{x: -h/2, y: 0},
{x: w, y: 0},
{x: w, y: -h},
{x: -h/2, y: -h},
{x: 0, y: -h/2},
];
shapeSvg = parent.insert("polygon", ":first-child")
.attr("points", points.map(function (d) {
return d.x + "," + d.y;
}).join(" "))
.style("fill", "#fff")
.style("stroke", "#333")
.attr("transform", "translate(" + (-w / 2) + "," + (h * 2 / 4) + ")");
node.intersect = function (point) {
return dagreD3.intersect.polygon(node, points, point);
Expand Down
12 changes: 12 additions & 0 deletions test/web.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<script src="../dist/mermaid.full.js"></script>
<script>
Expand Down Expand Up @@ -41,6 +42,17 @@
e(orphan);
style eag red;
</div>
<h1>Shapes</h1>
<div class="mermaid">
graph TD;
sq[Square shape]-->ci(Circle shape);
od>Odd shape]---|Two line<br>edge comment|ro;
od2>Really long text in an Odd shape]-->od3>Really long text with linebreak<br>in an Odd shape];
di[Diamond is broken]-->ro{Rounded<br>square<br>shape};
di[Diamond is broken]-->ro2{Rounded square shape};
e(Inner circle);
style e red;
</div>

</body>
</html>

0 comments on commit 2893297

Please sign in to comment.