|
1 |
| -// flowchart, v1.1.3 |
| 1 | +// flowchart, v1.2.1 |
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 | + 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 | + |
811 | 837 | this.text.attr({
|
812 | 838 | x: chart.options['text-margin'] * 2
|
813 | 839 | });
|
|
854 | 880 | f.inherits(Condition, Symbol);
|
855 | 881 |
|
856 | 882 | 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) { |
858 | 893 | var bottomPoint = this.getBottom();
|
859 |
| - var topPoint = this.yes_symbol.getTop(); |
| 894 | + var topPoint = this.bottom_symbol.getTop(); |
860 | 895 |
|
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; |
865 | 900 |
|
866 |
| - this.yes_symbol.render(); |
| 901 | + this.bottom_symbol.render(); |
867 | 902 | }
|
868 | 903 | }
|
869 | 904 |
|
870 |
| - if (this.no_symbol) { |
| 905 | + if (this.right_symbol) { |
871 | 906 | var rightPoint = this.getRight();
|
872 |
| - var leftPoint = this.no_symbol.getLeft(); |
| 907 | + var leftPoint = this.right_symbol.getLeft(); |
873 | 908 |
|
874 |
| - if (!this.no_symbol.isPositioned) { |
| 909 | + if (!this.right_symbol.isPositioned) { |
875 | 910 |
|
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']); |
878 | 913 |
|
879 | 914 | var self = this;
|
880 | 915 | (function shift() {
|
|
883 | 918 | for (var i = 0, len = self.chart.symbols.length; i < len; i++) {
|
884 | 919 | symb = self.chart.symbols[i];
|
885 | 920 |
|
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) { |
888 | 923 | hasSymbolUnder = true;
|
889 | 924 | break;
|
890 | 925 | }
|
891 | 926 | }
|
892 | 927 |
|
893 | 928 | 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']); |
895 | 930 | shift();
|
896 | 931 | }
|
897 | 932 | })();
|
898 | 933 |
|
899 |
| - this.no_symbol.isPositioned = true; |
| 934 | + this.right_symbol.isPositioned = true; |
900 | 935 |
|
901 |
| - this.no_symbol.render(); |
| 936 | + this.right_symbol.render(); |
902 | 937 | }
|
903 | 938 | }
|
904 | 939 | };
|
905 | 940 |
|
906 | 941 | Condition.prototype.renderLines = function() {
|
907 | 942 | 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); |
909 | 944 | }
|
910 | 945 |
|
911 | 946 | 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); |
913 | 948 | }
|
914 | 949 | };
|
915 | 950 | function parse(input) {
|
|
1078 | 1113 |
|
1079 | 1114 | chart.symbols[symbol.key] = symbol;
|
1080 | 1115 |
|
1081 |
| - } else if(line.indexOf('->') >= 0) { |
| 1116 | + } else if (line.indexOf('->') >= 0) { |
1082 | 1117 | // flow
|
1083 | 1118 | var flowSymbols = line.split('->');
|
1084 | 1119 | for (var i = 0, lenS = flowSymbols.length; i < lenS; i++) {
|
|
1087 | 1122 | var realSymb = getSymbol(flowSymb);
|
1088 | 1123 | var next = getNextPath(flowSymb);
|
1089 | 1124 |
|
| 1125 | + var direction; |
| 1126 | + if (next.indexOf(',') >= 0) { |
| 1127 | + var condOpt = next.split(','); |
| 1128 | + next = condOpt[0]; |
| 1129 | + direction = condOpt[1].trim(); |
| 1130 | + } |
| 1131 | + |
1090 | 1132 | if (!chart.start) {
|
1091 | 1133 | chart.start = realSymb;
|
1092 | 1134 | }
|
1093 | 1135 |
|
1094 | 1136 | if (i + 1 < lenS) {
|
1095 | 1137 | var nextSymb = flowSymbols[i + 1];
|
1096 | 1138 | realSymb[next] = getSymbol(nextSymb);
|
| 1139 | + realSymb[next].direction = direction; |
| 1140 | + direction = undefined; |
1097 | 1141 | }
|
1098 | 1142 | }
|
1099 | 1143 |
|
|
0 commit comments