|
1 |
| -// flowchart, v1.1.3 |
| 1 | +// flowchart, v1.2.0 |
2 | 2 | // Copyright (c)2013 Adriano Raiano (adrai).
|
3 | 3 | // Distributed under MIT license
|
4 | 4 | // http://adrai.github.io/flowchart.js
|
|
83 | 83 | // global object or to jquery.
|
84 | 84 | if (typeof module !== 'undefined' && module.exports) {
|
85 | 85 | module.exports = flowchart;
|
86 |
| - } else { |
| 86 | + } else { |
87 | 87 | root.flowchart = root.flowchart || flowchart;
|
88 | 88 | }
|
89 | 89 | // defaults
|
|
808 | 808 | options = options || {};
|
809 | 809 | Symbol.call(this, chart, options);
|
810 | 810 |
|
| 811 | + if (options.yes.direction && !options.no.direction) { |
| 812 | + if (options.yes.direction === 'right') { |
| 813 | + options.no.direction = 'bottom'; |
| 814 | + } else { |
| 815 | + options.no.direction = 'right'; |
| 816 | + } |
| 817 | + } else if (!options.yes.direction && options.no.direction) { |
| 818 | + if (options.no.direction === 'right') { |
| 819 | + options.yes.direction = 'bottom'; |
| 820 | + } else { |
| 821 | + options.yes.direction = 'right'; |
| 822 | + } |
| 823 | + } else { |
| 824 | + options.yes.direction = 'bottom'; |
| 825 | + options.no.direction = 'right'; |
| 826 | + } |
| 827 | + |
| 828 | + this.options = options; |
| 829 | + |
811 | 830 | this.text.attr({
|
812 | 831 | x: chart.options['text-margin'] * 2
|
813 | 832 | });
|
|
854 | 873 | f.inherits(Condition, Symbol);
|
855 | 874 |
|
856 | 875 | Condition.prototype.render = function() {
|
857 |
| - if (this.yes_symbol) { |
| 876 | + |
| 877 | + this[this.options.yes.direction + '_symbol'] = this.yes_symbol; |
| 878 | + this[this.options.no.direction + '_symbol'] = this.no_symbol; |
| 879 | + |
| 880 | + if (this.bottom_symbol) { |
858 | 881 | var bottomPoint = this.getBottom();
|
859 |
| - var topPoint = this.yes_symbol.getTop(); |
| 882 | + var topPoint = this.bottom_symbol.getTop(); |
860 | 883 |
|
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; |
| 884 | + if (!this.bottom_symbol.isPositioned) { |
| 885 | + this.bottom_symbol.shiftY(this.getY() + this.height + this.chart.options['line-length']); |
| 886 | + this.bottom_symbol.setX(bottomPoint.x - this.bottom_symbol.width/2); |
| 887 | + this.bottom_symbol.isPositioned = true; |
865 | 888 |
|
866 |
| - this.yes_symbol.render(); |
| 889 | + this.bottom_symbol.render(); |
867 | 890 | }
|
868 | 891 | }
|
869 | 892 |
|
870 |
| - if (this.no_symbol) { |
| 893 | + if (this.right_symbol) { |
871 | 894 | var rightPoint = this.getRight();
|
872 |
| - var leftPoint = this.no_symbol.getLeft(); |
| 895 | + var leftPoint = this.right_symbol.getLeft(); |
873 | 896 |
|
874 |
| - if (!this.no_symbol.isPositioned) { |
| 897 | + if (!this.right_symbol.isPositioned) { |
875 | 898 |
|
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']); |
| 899 | + this.right_symbol.setY(rightPoint.y - this.right_symbol.height/2); |
| 900 | + this.right_symbol.shiftX(this.group.getBBox().x + this.width + this.chart.options['line-length']); |
878 | 901 |
|
879 | 902 | var self = this;
|
880 | 903 | (function shift() {
|
|
883 | 906 | for (var i = 0, len = self.chart.symbols.length; i < len; i++) {
|
884 | 907 | symb = self.chart.symbols[i];
|
885 | 908 |
|
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) { |
| 909 | + var diff = Math.abs(symb.getCenter().x - self.right_symbol.getCenter().x); |
| 910 | + if (symb.getCenter().y > self.right_symbol.getCenter().y && diff <= self.right_symbol.width/2) { |
888 | 911 | hasSymbolUnder = true;
|
889 | 912 | break;
|
890 | 913 | }
|
891 | 914 | }
|
892 | 915 |
|
893 | 916 | if (hasSymbolUnder) {
|
894 |
| - self.no_symbol.setX(symb.getX() + symb.width + self.chart.options['line-length']); |
| 917 | + self.right_symbol.setX(symb.getX() + symb.width + self.chart.options['line-length']); |
895 | 918 | shift();
|
896 | 919 | }
|
897 | 920 | })();
|
898 | 921 |
|
899 |
| - this.no_symbol.isPositioned = true; |
| 922 | + this.right_symbol.isPositioned = true; |
900 | 923 |
|
901 |
| - this.no_symbol.render(); |
| 924 | + this.right_symbol.render(); |
902 | 925 | }
|
903 | 926 | }
|
904 | 927 | };
|
905 | 928 |
|
906 | 929 | Condition.prototype.renderLines = function() {
|
907 | 930 | if (this.yes_symbol) {
|
908 |
| - this.drawLineTo(this.yes_symbol, this.chart.options['yes-text'], 'bottom'); |
| 931 | + this.drawLineTo(this.yes_symbol, this.chart.options['yes-text'], this.options.yes.direction); |
909 | 932 | }
|
910 | 933 |
|
911 | 934 | if (this.no_symbol) {
|
912 |
| - this.drawLineTo(this.no_symbol, this.chart.options['no-text'], 'right'); |
| 935 | + this.drawLineTo(this.no_symbol, this.chart.options['no-text'], this.options.no.direction); |
913 | 936 | }
|
914 | 937 | };
|
915 | 938 | function parse(input) {
|
|
1078 | 1101 |
|
1079 | 1102 | chart.symbols[symbol.key] = symbol;
|
1080 | 1103 |
|
1081 |
| - } else if(line.indexOf('->') >= 0) { |
| 1104 | + } else if (line.indexOf('->') >= 0) { |
1082 | 1105 | // flow
|
1083 | 1106 | var flowSymbols = line.split('->');
|
1084 | 1107 | for (var i = 0, lenS = flowSymbols.length; i < lenS; i++) {
|
|
1087 | 1110 | var realSymb = getSymbol(flowSymb);
|
1088 | 1111 | var next = getNextPath(flowSymb);
|
1089 | 1112 |
|
| 1113 | + var direction; |
| 1114 | + if (next.indexOf(',') >= 0) { |
| 1115 | + var condOpt = next.split(','); |
| 1116 | + next = condOpt[0]; |
| 1117 | + direction = condOpt[1].trim(); |
| 1118 | + } |
| 1119 | + |
1090 | 1120 | if (!chart.start) {
|
1091 | 1121 | chart.start = realSymb;
|
1092 | 1122 | }
|
1093 | 1123 |
|
1094 | 1124 | if (i + 1 < lenS) {
|
1095 | 1125 | var nextSymb = flowSymbols[i + 1];
|
1096 | 1126 | realSymb[next] = getSymbol(nextSymb);
|
| 1127 | + realSymb[next].direction = direction; |
| 1128 | + direction = undefined; |
1097 | 1129 | }
|
1098 | 1130 | }
|
1099 | 1131 |
|
|
0 commit comments