Skip to content

Commit ee4f485

Browse files
committed
new version
1 parent ec75e68 commit ee4f485

File tree

2 files changed

+102
-16
lines changed

2 files changed

+102
-16
lines changed

flowchart-latest.js

Lines changed: 99 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// flowchart, v1.2.7
1+
// flowchart, v1.2.8
22
// Copyright (c)2014 Adriano Raiano (adrai).
33
// Distributed under MIT license
44
// http://adrai.github.io/flowchart.js
@@ -408,6 +408,8 @@
408408
this.connectedTo = [];
409409
this.symbolType = options.symbolType;
410410

411+
this.next_direction = options.next && options.next.direction ? options.next.direction : undefined;
412+
411413
this.text = this.chart.paper.text(0, 0, options.text);
412414
this.text.attr({
413415
'text-anchor': 'start',
@@ -519,22 +521,65 @@
519521

520522
Symbol.prototype.render = function() {
521523
if (this.next) {
522-
var bottomPoint = this.getBottom();
523-
var topPoint = this.next.getTop();
524524

525-
if (!this.next.isPositioned) {
526-
this.next.shiftY(this.getY() + this.height + (this.chart.options.symbols[this.symbolType]['line-length'] || this.chart.options['line-length']));
527-
this.next.setX(bottomPoint.x - this.next.width/2);
528-
this.next.isPositioned = true;
525+
var lineLength = this.chart.options.symbols[this.symbolType]['line-length'] || this.chart.options['line-length'];
529526

530-
this.next.render();
527+
if (this.next_direction === 'right') {
528+
529+
var rightPoint = this.getRight();
530+
var leftPoint = this.next.getLeft();
531+
532+
if (!this.next.isPositioned) {
533+
534+
this.next.setY(rightPoint.y - this.next.height/2);
535+
this.next.shiftX(this.group.getBBox().x + this.width + lineLength);
536+
537+
var self = this;
538+
(function shift() {
539+
var hasSymbolUnder = false;
540+
var symb;
541+
for (var i = 0, len = self.chart.symbols.length; i < len; i++) {
542+
symb = self.chart.symbols[i];
543+
544+
var diff = Math.abs(symb.getCenter().x - self.next.getCenter().x);
545+
if (symb.getCenter().y > self.next.getCenter().y && diff <= self.next.width/2) {
546+
hasSymbolUnder = true;
547+
break;
548+
}
549+
}
550+
551+
if (hasSymbolUnder) {
552+
self.next.setX(symb.getX() + symb.width + lineLength);
553+
shift();
554+
}
555+
})();
556+
557+
this.next.isPositioned = true;
558+
559+
this.next.render();
560+
}
561+
} else {
562+
var bottomPoint = this.getBottom();
563+
var topPoint = this.next.getTop();
564+
565+
if (!this.next.isPositioned) {
566+
this.next.shiftY(this.getY() + this.height + lineLength);
567+
this.next.setX(bottomPoint.x - this.next.width/2);
568+
this.next.isPositioned = true;
569+
570+
this.next.render();
571+
}
531572
}
532573
}
533574
};
534575

535576
Symbol.prototype.renderLines = function() {
536577
if (this.next) {
537-
this.drawLineTo(this.next);
578+
if (this.next_direction) {
579+
this.drawLineTo(this.next, '', this.next_direction);
580+
} else {
581+
this.drawLineTo(this.next);
582+
}
538583
}
539584
};
540585

@@ -665,6 +710,16 @@
665710
this.bottomStart = true;
666711
symbol.topEnd = true;
667712
maxX = bottom.x + lineLength/2;
713+
} else if ((origin === 'left')) {
714+
line = drawLine(this.chart, left, [
715+
{x: symbolTop.x + (left.x - symbolTop.x)/ 2, y: left.y},
716+
{x: symbolTop.x + (left.x - symbolTop.x)/ 2, y: symbolTop.y - lineLength/2},
717+
{x: symbolTop.x, y: symbolTop.y - lineLength/2},
718+
{x: symbolTop.x, y: symbolTop.y}
719+
], text);
720+
this.leftStart = true;
721+
symbol.topEnd = true;
722+
maxX = left.x;
668723
}
669724

670725
if (line) {
@@ -754,6 +809,30 @@
754809
Symbol.call(this, chart, options, symbol);
755810
}
756811
f.inherits(Start, Symbol);
812+
813+
814+
Start.prototype.render = function() {
815+
if (this.next) {
816+
var lineLength = this.chart.options.symbols[this.symbolType]['line-length'] || this.chart.options['line-length'];
817+
818+
var bottomPoint = this.getBottom();
819+
var topPoint = this.next.getTop();
820+
821+
if (!this.next.isPositioned) {
822+
this.next.shiftY(this.getY() + this.height + lineLength);
823+
this.next.setX(bottomPoint.x - this.next.width/2);
824+
this.next.isPositioned = true;
825+
826+
this.next.render();
827+
}
828+
}
829+
};
830+
831+
Start.prototype.renderLines = function() {
832+
if (this.next) {
833+
this.drawLineTo(this.next);
834+
}
835+
};
757836
function End(chart, options) {
758837
var symbol = chart.paper.rect(0, 0, 0, 0, 20);
759838
options = options || {};
@@ -1091,13 +1170,14 @@
10911170

10921171
var lines = [];
10931172
var prevBreak = 0;
1094-
for(var i=1, ii = input.length; i<ii; i++) {
1095-
if(input[i] === '\n' && input[i-1] !== '\\') {
1096-
var line = input.substring(prevBreak, i);
1097-
prevBreak = i + 1;
1098-
lines.push(line.replace(/\\\n/g, '\n'));
1173+
for (var i0 = 1, i0len = input.length; i0 < i0len; i0++) {
1174+
if(input[i0] === '\n' && input[i0 - 1] !== '\\') {
1175+
var line0 = input.substring(prevBreak, i0);
1176+
prevBreak = i0 + 1;
1177+
lines.push(line0.replace(/\\\n/g, '\n'));
10991178
}
11001179
}
1180+
11011181
if(prevBreak < input.length) {
11021182
lines.push(input.substr(prevBreak));
11031183
}
@@ -1129,6 +1209,11 @@
11291209
var endIndex = s.indexOf(')');
11301210
if (startIndex >= 0 && endIndex >= 0) {
11311211
next = flowSymb.substring(startIndex, endIndex);
1212+
if (next.indexOf(',') < 0) {
1213+
if (next !== 'yes' && next !== 'no') {
1214+
next = 'next, ' + next;
1215+
}
1216+
}
11321217
}
11331218
return next;
11341219
}

index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ <h3>Demo. Try editing me below</h3>
4747
or No?:>http://www.google.com
4848
io=>inputoutput: catch something...
4949

50-
st->op1->cond
50+
st->op1(right)->cond
5151
cond(yes)->io->e
52-
cond(no)->sub1->op1</div>
52+
cond(no)->sub1(left)->op1</div>
5353
<!-- </div>
5454
Theme:
5555
<select class="theme">
@@ -64,6 +64,7 @@ <h3>Demo. Try editing me below</h3>
6464
</section>
6565

6666
<b>Conditions can also be redirected like cond(yes, bottom) or cond(yes, right)</b>
67+
<b>... and the other symbols too... like op1(right)</b>
6768
<div class="inner">
6869
<section id="usage">
6970
<h3>Usage</h3>

0 commit comments

Comments
 (0)