Skip to content

Commit d8b61d1

Browse files
committed
new version
1 parent 0b6e613 commit d8b61d1

File tree

1 file changed

+66
-22
lines changed

1 file changed

+66
-22
lines changed

flowchart-latest.js

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// flowchart, v1.1.3
1+
// flowchart, v1.2.1
22
// Copyright (c)2013 Adriano Raiano (adrai).
33
// Distributed under MIT license
44
// http://adrai.github.io/flowchart.js
@@ -83,7 +83,7 @@
8383
// global object or to jquery.
8484
if (typeof module !== 'undefined' && module.exports) {
8585
module.exports = flowchart;
86-
} else {
86+
} else {
8787
root.flowchart = root.flowchart || flowchart;
8888
}
8989
// defaults
@@ -808,6 +808,32 @@
808808
options = options || {};
809809
Symbol.call(this, chart, options);
810810

811+
this.yes_direction = 'bottom';
812+
this.no_direction = 'right';
813+
if (options.yes && options.yes.direction && options.no && !options.no.direction) {
814+
if (options.yes.direction === 'right') {
815+
this.no_direction = 'bottom';
816+
this.yes_direction = 'right';
817+
} else {
818+
this.no_direction = 'right';
819+
this.yes_direction = 'bottom';
820+
}
821+
} else if (options.yes && !options.yes.direction && options.no && options.no.direction) {
822+
if (options.no.direction === 'right') {
823+
this.yes_direction = 'bottom';
824+
this.no_direction = 'right';
825+
} else {
826+
this.yes_direction = 'right';
827+
this.no_direction = 'bottom';
828+
}
829+
} else {
830+
this.yes_direction = 'bottom';
831+
this.no_direction = 'right';
832+
}
833+
834+
this.yes_direction = this.yes_direction || 'bottom';
835+
this.no_direction = this.no_direction || 'right';
836+
811837
this.text.attr({
812838
x: chart.options['text-margin'] * 2
813839
});
@@ -854,27 +880,36 @@
854880
f.inherits(Condition, Symbol);
855881

856882
Condition.prototype.render = function() {
857-
if (this.yes_symbol) {
883+
884+
if (this.yes_direction) {
885+
this[this.yes_direction + '_symbol'] = this.yes_symbol;
886+
}
887+
888+
if (this.no_direction) {
889+
this[this.no_direction + '_symbol'] = this.no_symbol;
890+
}
891+
892+
if (this.bottom_symbol) {
858893
var bottomPoint = this.getBottom();
859-
var topPoint = this.yes_symbol.getTop();
894+
var topPoint = this.bottom_symbol.getTop();
860895

861-
if (!this.yes_symbol.isPositioned) {
862-
this.yes_symbol.shiftY(this.getY() + this.height + this.chart.options['line-length']);
863-
this.yes_symbol.setX(bottomPoint.x - this.yes_symbol.width/2);
864-
this.yes_symbol.isPositioned = true;
896+
if (!this.bottom_symbol.isPositioned) {
897+
this.bottom_symbol.shiftY(this.getY() + this.height + this.chart.options['line-length']);
898+
this.bottom_symbol.setX(bottomPoint.x - this.bottom_symbol.width/2);
899+
this.bottom_symbol.isPositioned = true;
865900

866-
this.yes_symbol.render();
901+
this.bottom_symbol.render();
867902
}
868903
}
869904

870-
if (this.no_symbol) {
905+
if (this.right_symbol) {
871906
var rightPoint = this.getRight();
872-
var leftPoint = this.no_symbol.getLeft();
907+
var leftPoint = this.right_symbol.getLeft();
873908

874-
if (!this.no_symbol.isPositioned) {
909+
if (!this.right_symbol.isPositioned) {
875910

876-
this.no_symbol.setY(rightPoint.y - this.no_symbol.height/2);
877-
this.no_symbol.shiftX(this.group.getBBox().x + this.width + this.chart.options['line-length']);
911+
this.right_symbol.setY(rightPoint.y - this.right_symbol.height/2);
912+
this.right_symbol.shiftX(this.group.getBBox().x + this.width + this.chart.options['line-length']);
878913

879914
var self = this;
880915
(function shift() {
@@ -883,33 +918,33 @@
883918
for (var i = 0, len = self.chart.symbols.length; i < len; i++) {
884919
symb = self.chart.symbols[i];
885920

886-
var diff = Math.abs(symb.getCenter().x - self.no_symbol.getCenter().x);
887-
if (symb.getCenter().y > self.no_symbol.getCenter().y && diff <= self.no_symbol.width/2) {
921+
var diff = Math.abs(symb.getCenter().x - self.right_symbol.getCenter().x);
922+
if (symb.getCenter().y > self.right_symbol.getCenter().y && diff <= self.right_symbol.width/2) {
888923
hasSymbolUnder = true;
889924
break;
890925
}
891926
}
892927

893928
if (hasSymbolUnder) {
894-
self.no_symbol.setX(symb.getX() + symb.width + self.chart.options['line-length']);
929+
self.right_symbol.setX(symb.getX() + symb.width + self.chart.options['line-length']);
895930
shift();
896931
}
897932
})();
898933

899-
this.no_symbol.isPositioned = true;
934+
this.right_symbol.isPositioned = true;
900935

901-
this.no_symbol.render();
936+
this.right_symbol.render();
902937
}
903938
}
904939
};
905940

906941
Condition.prototype.renderLines = function() {
907942
if (this.yes_symbol) {
908-
this.drawLineTo(this.yes_symbol, this.chart.options['yes-text'], 'bottom');
943+
this.drawLineTo(this.yes_symbol, this.chart.options['yes-text'], this.yes_direction);
909944
}
910945

911946
if (this.no_symbol) {
912-
this.drawLineTo(this.no_symbol, this.chart.options['no-text'], 'right');
947+
this.drawLineTo(this.no_symbol, this.chart.options['no-text'], this.no_direction);
913948
}
914949
};
915950
function parse(input) {
@@ -1078,7 +1113,7 @@
10781113

10791114
chart.symbols[symbol.key] = symbol;
10801115

1081-
} else if(line.indexOf('->') >= 0) {
1116+
} else if (line.indexOf('->') >= 0) {
10821117
// flow
10831118
var flowSymbols = line.split('->');
10841119
for (var i = 0, lenS = flowSymbols.length; i < lenS; i++) {
@@ -1087,13 +1122,22 @@
10871122
var realSymb = getSymbol(flowSymb);
10881123
var next = getNextPath(flowSymb);
10891124

1125+
var direction;
1126+
if (next.indexOf(',') >= 0) {
1127+
var condOpt = next.split(',');
1128+
next = condOpt[0];
1129+
direction = condOpt[1].trim();
1130+
}
1131+
10901132
if (!chart.start) {
10911133
chart.start = realSymb;
10921134
}
10931135

10941136
if (i + 1 < lenS) {
10951137
var nextSymb = flowSymbols[i + 1];
10961138
realSymb[next] = getSymbol(nextSymb);
1139+
realSymb[next].direction = direction;
1140+
direction = undefined;
10971141
}
10981142
}
10991143

0 commit comments

Comments
 (0)