|
1 |
| -// flowchart, v1.2.12 |
| 1 | +// flowchart, v1.3.0 |
2 | 2 | // Copyright (c)2014 Adriano Raiano (adrai).
|
3 | 3 | // Distributed under MIT license
|
4 | 4 | // http://adrai.github.io/flowchart.js
|
|
111 | 111 | 'inputoutput': {},
|
112 | 112 | 'operation': {},
|
113 | 113 | 'subroutine': {}
|
114 |
| - } |
| 114 | + }//, |
| 115 | + // 'flowstate' : { |
| 116 | + // 'past' : { 'fill': '#CCCCCC', 'font-size': 12}, |
| 117 | + // 'current' : {'fill': 'yellow', 'font-color': 'red', 'font-weight': 'bold'}, |
| 118 | + // 'future' : { 'fill': '#FFFF99'}, |
| 119 | + // 'invalid': {'fill': '#444444'} |
| 120 | + // } |
115 | 121 | };
|
116 | 122 | function _defaults(options, defaultOptions) {
|
117 | 123 | if (!options || typeof options === 'function') {
|
|
439 | 445 | this.symbol = symbol;
|
440 | 446 | this.connectedTo = [];
|
441 | 447 | this.symbolType = options.symbolType;
|
| 448 | + this.flowstate = (options.flowstate || 'future'); |
442 | 449 |
|
443 | 450 | this.next_direction = options.next && options['direction_next'] ? options['direction_next'] : undefined;
|
444 |
| - |
| 451 | + |
445 | 452 | this.text = this.chart.paper.text(0, 0, options.text);
|
446 | 453 | //Raphael does not support the svg group tag so setting the text node id to the symbol node id plus t
|
447 | 454 | if (options.key) { this.text.node.id = options.key + 't'; }
|
448 | 455 | this.text.attr({
|
449 | 456 | 'text-anchor': 'start',
|
450 |
| - 'font-size': (this.chart.options.symbols[this.symbolType]['font-size'] || this.chart.options['font-size']), |
451 |
| - 'x': (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), |
452 |
| - stroke: (this.chart.options.symbols[this.symbolType]['font-color'] || this.chart.options['font-color']) |
| 457 | + 'x' : this.getAttr('text-margin'), |
| 458 | + 'stroke' : this.getAttr('font-color'), |
| 459 | + 'font-size' : this.getAttr('font-size') |
453 | 460 | });
|
454 | 461 |
|
455 |
| - var font = (this.chart.options.symbols[this.symbolType]['font'] || this.chart.options['font']); |
456 |
| - var fontF = (this.chart.options.symbols[this.symbolType]['font-family'] || this.chart.options['font-family']); |
457 |
| - var fontW = (this.chart.options.symbols[this.symbolType]['font-weight'] || this.chart.options['font-weight']); |
| 462 | + var font = this.getAttr('font'); |
| 463 | + var fontF = this.getAttr('font-family'); |
| 464 | + var fontW = this.getAttr('font-weight'); |
458 | 465 |
|
459 | 466 | if (font) this.text.attr({ 'font': font });
|
460 | 467 | if (fontF) this.text.attr({ 'font-family': fontF });
|
461 | 468 | if (fontW) this.text.attr({ 'font-weight': fontW });
|
462 | 469 |
|
463 | 470 | if (options.link) { this.text.attr('href', options.link); }
|
464 | 471 | if (options.target) { this.text.attr('target', options.target); }
|
465 |
| - if (this.chart.options.symbols[this.symbolType]['maxWidth'] || this.chart.options['maxWidth']) { |
| 472 | + var maxWidth = this.getAttr('maxWidth'); |
| 473 | + if (maxWidth) { |
466 | 474 | // using this approach: http://stackoverflow.com/a/3153457/22466
|
467 |
| - var maxWidth = this.chart.options.symbols[this.symbolType]['maxWidth'] || this.chart.options['maxWidth']; |
468 | 475 | var words = options.text.split(' ');
|
469 | 476 | var tempText = "";
|
470 | 477 | for (var i=0, ii=words.length; i<ii; i++) {
|
|
478 | 485 | }
|
479 | 486 | this.text.attr("text", tempText.substring(1));
|
480 | 487 | }
|
| 488 | + |
481 | 489 | this.group.push(this.text);
|
482 | 490 |
|
483 | 491 | if (symbol) {
|
484 |
| - symbol.attr({ |
485 |
| - stroke: (this.chart.options.symbols[this.symbolType]['element-color'] || this.chart.options['element-color']), |
486 |
| - 'stroke-width': (this.chart.options.symbols[this.symbolType]['line-width'] || this.chart.options['line-width']), |
487 |
| - width: this.text.getBBox().width + 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), |
488 |
| - height: this.text.getBBox().height + 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), |
489 |
| - fill: (this.chart.options.symbols[this.symbolType]['fill'] || this.chart.options['fill']) |
490 |
| - }); |
491 |
| - if (options.link) { symbol.attr('href', options.link); } |
| 492 | + var tmpMargin = this.getAttr('text-margin'); |
| 493 | + |
| 494 | + symbol.attr({ |
| 495 | + 'fill' : this.getAttr('fill'), |
| 496 | + 'stroke' : this.getAttr('element-color'), |
| 497 | + 'stroke-width' : this.getAttr('line-width'), |
| 498 | + 'width' : this.text.getBBox().width + 2 * tmpMargin, |
| 499 | + 'height' : this.text.getBBox().height + 2 * tmpMargin |
| 500 | + }); |
| 501 | + |
| 502 | + if (options.link) { symbol.attr('href', options.link); } |
492 | 503 | if (options.target) { symbol.attr('target', options.target); }
|
493 | 504 | if (options.key) { symbol.node.id = options.key; }
|
494 | 505 |
|
|
501 | 512 |
|
502 | 513 | this.initialize();
|
503 | 514 | }
|
| 515 | + |
504 | 516 | }
|
505 | 517 |
|
| 518 | + /* Gets the attribute based on Flowstate, Symbol-Name and default, first found wins */ |
| 519 | + Symbol.prototype.getAttr = function(attName) { |
| 520 | + if (!this.chart) { |
| 521 | + return undefined; |
| 522 | + } |
| 523 | + var opt3 = (this.chart.options) ? this.chart.options[attName] : undefined; |
| 524 | + var opt2 = (this.chart.options.symbols) ? this.chart.options.symbols[this.symbolType][attName] : undefined; |
| 525 | + var opt1; |
| 526 | + if (this.chart.options.flowstate && this.chart.options.flowstate[this.flowstate]) { |
| 527 | + opt1 = this.chart.options.flowstate[this.flowstate][attName]; |
| 528 | + } |
| 529 | + return (opt1 || opt2 || opt3); |
| 530 | + }; |
| 531 | + |
506 | 532 | Symbol.prototype.initialize = function() {
|
507 |
| - this.group.transform('t' + (this.chart.options.symbols[this.symbolType]['line-width'] || this.chart.options['line-width']) + ',' + (this.chart.options.symbols[this.symbolType]['line-width'] || this.chart.options['line-width'])); |
| 533 | + this.group.transform('t' + this.getAttr('line-width') + ',' + this.getAttr('line-width')); |
508 | 534 |
|
509 | 535 | this.width = this.group.getBBox().width;
|
510 | 536 | this.height = this.group.getBBox().height;
|
|
566 | 592 | Symbol.prototype.render = function() {
|
567 | 593 | if (this.next) {
|
568 | 594 |
|
569 |
| - var lineLength = this.chart.options.symbols[this.symbolType]['line-length'] || this.chart.options['line-length']; |
| 595 | + var lineLength = this.getAttr('line-length'); |
570 | 596 |
|
571 | 597 | if (this.next_direction === 'right') {
|
572 | 598 |
|
|
655 | 681 |
|
656 | 682 | var maxX = 0,
|
657 | 683 | line,
|
658 |
| - lineLength = this.chart.options.symbols[this.symbolType]['line-length'] || this.chart.options['line-length'], |
659 |
| - lineWith = this.chart.options.symbols[this.symbolType]['line-width'] || this.chart.options['line-width']; |
| 684 | + lineLength = this.getAttr('line-length'), |
| 685 | + lineWith = this.getAttr('line-width'); |
660 | 686 |
|
661 | 687 | if ((!origin || origin === 'bottom') && isOnSameColumn && isUnder) {
|
662 | 688 | line = drawLine(this.chart, bottom, symbolTop, text);
|
|
894 | 920 | Symbol.call(this, chart, options, symbol);
|
895 | 921 |
|
896 | 922 | symbol.attr({
|
897 |
| - width: this.text.getBBox().width + 4 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']) |
| 923 | + width: this.text.getBBox().width + 4 * this.getAttr('text-margin') |
898 | 924 | });
|
899 | 925 |
|
900 | 926 | this.text.attr({
|
901 |
| - 'x': 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']) |
| 927 | + 'x': 2 * this.getAttr('text-margin') |
902 | 928 | });
|
903 | 929 |
|
904 | 930 | var innerWrap = chart.paper.rect(0, 0, 0, 0);
|
905 | 931 | innerWrap.attr({
|
906 |
| - x: (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), |
907 |
| - stroke: (this.chart.options.symbols[this.symbolType]['element-color'] || this.chart.options['element-color']), |
908 |
| - 'stroke-width': (this.chart.options.symbols[this.symbolType]['line-width'] || this.chart.options['line-width']), |
909 |
| - width: this.text.getBBox().width + 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), |
910 |
| - height: this.text.getBBox().height + 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), |
911 |
| - fill: (this.chart.options.symbols[this.symbolType]['fill'] || this.chart.options['fill']) |
| 932 | + x: this.getAttr('text-margin'), |
| 933 | + stroke: this.getAttr('element-color'), |
| 934 | + 'stroke-width': this.getAttr('line-width'), |
| 935 | + width: this.text.getBBox().width + 2 * this.getAttr('text-margin'), |
| 936 | + height: this.text.getBBox().height + 2 * this.getAttr('text-margin'), |
| 937 | + fill: this.getAttr('fill') |
912 | 938 | });
|
913 | 939 | if (options.key) { innerWrap.node.id = options.key + 'i'; }
|
914 | 940 |
|
915 |
| - var font = (this.chart.options.symbols[this.symbolType]['font'] || this.chart.options['font']); |
916 |
| - var fontF = (this.chart.options.symbols[this.symbolType]['font-family'] || this.chart.options['font-family']); |
917 |
| - var fontW = (this.chart.options.symbols[this.symbolType]['font-weight'] || this.chart.options['font-weight']); |
| 941 | + var font = this.getAttr('font'); |
| 942 | + var fontF = this.getAttr('font-family'); |
| 943 | + var fontW = this.getAttr('font-weight'); |
918 | 944 |
|
919 | 945 | if (font) innerWrap.attr({ 'font': font });
|
920 | 946 | if (fontF) innerWrap.attr({ 'font-family': fontF });
|
|
931 | 957 | function InputOutput(chart, options) {
|
932 | 958 | options = options || {};
|
933 | 959 | Symbol.call(this, chart, options);
|
934 |
| - |
| 960 | + this.textMargin = this.getAttr('text-margin'); |
| 961 | + |
935 | 962 | this.text.attr({
|
936 |
| - x: (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']) * 3 |
| 963 | + x: this.textMargin * 3 |
937 | 964 | });
|
938 | 965 |
|
939 |
| - var width = this.text.getBBox().width + 4 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']); |
940 |
| - var height = this.text.getBBox().height + 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']); |
941 |
| - var startX = (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']); |
| 966 | + var width = this.text.getBBox().width + 4 * this.textMargin; |
| 967 | + var height = this.text.getBBox().height + 2 * this.textMargin; |
| 968 | + var startX = this.textMargin; |
942 | 969 | var startY = height/2;
|
943 | 970 |
|
944 | 971 | var start = {x: startX, y: startY};
|
945 | 972 | var points = [
|
946 |
| - {x: startX - (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), y: height}, |
947 |
| - {x: startX - (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']) + width, y: height}, |
948 |
| - {x: startX - (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']) + width + 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), y: 0}, |
949 |
| - {x: startX - (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']) + 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']), y: 0}, |
| 973 | + {x: startX - this.textMargin, y: height}, |
| 974 | + {x: startX - this.textMargin + width, y: height}, |
| 975 | + {x: startX - this.textMargin + width + 2 * this.textMargin, y: 0}, |
| 976 | + {x: startX - this.textMargin + 2 * this.textMargin, y: 0}, |
950 | 977 | {x: startX, y: startY}
|
951 | 978 | ];
|
952 | 979 |
|
953 | 980 | var symbol = drawPath(chart, start, points);
|
954 | 981 |
|
955 | 982 | symbol.attr({
|
956 |
| - stroke: (this.chart.options.symbols[this.symbolType]['element-color'] || this.chart.options['element-color']), |
957 |
| - 'stroke-width': (this.chart.options.symbols[this.symbolType]['line-width'] || this.chart.options['line-width']), |
958 |
| - fill: (this.chart.options.symbols[this.symbolType]['fill'] || this.chart.options['fill']) |
| 983 | + stroke: this.getAttr('element-color'), |
| 984 | + 'stroke-width': this.getAttr('line-width'), |
| 985 | + fill: this.getAttr('fill') |
959 | 986 | });
|
960 | 987 | if (options.link) { symbol.attr('href', options.link); }
|
961 | 988 | if (options.target) { symbol.attr('target', options.target); }
|
|
974 | 1001 |
|
975 | 1002 | InputOutput.prototype.getLeft = function() {
|
976 | 1003 | var y = this.getY() + this.group.getBBox().height/2;
|
977 |
| - var x = this.getX() + (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']); |
| 1004 | + var x = this.getX() + this.textMargin; |
978 | 1005 | return {x: x, y: y};
|
979 | 1006 | };
|
980 | 1007 |
|
981 | 1008 | InputOutput.prototype.getRight = function() {
|
982 | 1009 | var y = this.getY() + this.group.getBBox().height/2;
|
983 |
| - var x = this.getX() + this.group.getBBox().width - (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']); |
| 1010 | + var x = this.getX() + this.group.getBBox().width - this.textMargin; |
984 | 1011 | return {x: x, y: y};
|
985 | 1012 | };
|
986 | 1013 | function Condition(chart, options) {
|
987 | 1014 | options = options || {};
|
988 | 1015 | Symbol.call(this, chart, options);
|
989 |
| - |
| 1016 | + this.textMargin = this.getAttr('text-margin'); |
990 | 1017 | this.yes_direction = 'bottom';
|
991 | 1018 | this.no_direction = 'right';
|
992 | 1019 | if (options.yes && options['direction_yes'] && options.no && !options['direction_no']) {
|
|
1014 | 1041 | this.no_direction = this.no_direction || 'right';
|
1015 | 1042 |
|
1016 | 1043 | this.text.attr({
|
1017 |
| - x: (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']) * 2 |
| 1044 | + x: this.textMargin * 2 |
1018 | 1045 | });
|
1019 | 1046 |
|
1020 |
| - var width = this.text.getBBox().width + 3 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']); |
| 1047 | + var width = this.text.getBBox().width + 3 * this.textMargin; |
1021 | 1048 | width += width/2;
|
1022 |
| - var height = this.text.getBBox().height + 2 * (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin']); |
| 1049 | + var height = this.text.getBBox().height + 2 * this.textMargin; |
1023 | 1050 | height += height/2;
|
1024 | 1051 | height = Math.max(width * 0.5, height);
|
1025 | 1052 | var startX = width/4;
|
1026 | 1053 | var startY = height/4;
|
1027 | 1054 |
|
1028 | 1055 | this.text.attr({
|
1029 |
| - x: startX + (this.chart.options.symbols[this.symbolType]['text-margin'] || this.chart.options['text-margin'])/2 |
| 1056 | + x: startX + this.textMargin/2 |
1030 | 1057 | });
|
1031 | 1058 |
|
1032 | 1059 | var start = {x: startX, y: startY};
|
|
1041 | 1068 | var symbol = drawPath(chart, start, points);
|
1042 | 1069 |
|
1043 | 1070 | symbol.attr({
|
1044 |
| - stroke: (this.chart.options.symbols[this.symbolType]['element-color'] || this.chart.options['element-color']), |
1045 |
| - 'stroke-width': (this.chart.options.symbols[this.symbolType]['line-width'] || this.chart.options['line-width']), |
1046 |
| - fill: (this.chart.options.symbols[this.symbolType]['fill'] || this.chart.options['fill']) |
| 1071 | + stroke: this.getAttr('element-color'), |
| 1072 | + 'stroke-width': this.getAttr('line-width'), |
| 1073 | + fill: this.getAttr('fill') |
1047 | 1074 | });
|
1048 | 1075 | if (options.link) { symbol.attr('href', options.link); }
|
1049 | 1076 | if (options.target) { symbol.attr('target', options.target); }
|
|
1070 | 1097 | this[this.no_direction + '_symbol'] = this.no_symbol;
|
1071 | 1098 | }
|
1072 | 1099 |
|
1073 |
| - var lineLength = this.chart.options.symbols[this.symbolType]['line-length'] || this.chart.options['line-length']; |
| 1100 | + var lineLength = this.getAttr('line-length'); |
1074 | 1101 |
|
1075 | 1102 | if (this.bottom_symbol) {
|
1076 | 1103 | var bottomPoint = this.getBottom();
|
|
1123 | 1150 |
|
1124 | 1151 | Condition.prototype.renderLines = function() {
|
1125 | 1152 | if (this.yes_symbol) {
|
1126 |
| - this.drawLineTo(this.yes_symbol, this.chart.options['yes-text'], this.yes_direction); |
| 1153 | + this.drawLineTo(this.yes_symbol, this.getAttr('yes-text'), this.yes_direction); |
1127 | 1154 | }
|
1128 | 1155 |
|
1129 | 1156 | if (this.no_symbol) {
|
1130 |
| - this.drawLineTo(this.no_symbol, this.chart.options['no-text'], this.no_direction); |
| 1157 | + this.drawLineTo(this.no_symbol, this.getAttr('no-text'), this.no_direction); |
1131 | 1158 | }
|
1132 | 1159 | };
|
1133 | 1160 | function parse(input) {
|
|
1272 | 1299 | return next;
|
1273 | 1300 | }
|
1274 | 1301 |
|
1275 |
| - while(lines.length > 0) { |
| 1302 | + while (lines.length > 0) { |
1276 | 1303 | var line = lines.splice(0, 1)[0];
|
1277 | 1304 |
|
1278 | 1305 | if (line.indexOf('=>') >= 0) {
|
|
1283 | 1310 | symbolType: parts[1],
|
1284 | 1311 | text: null,
|
1285 | 1312 | link: null,
|
1286 |
| - target: null |
| 1313 | + target: null, |
| 1314 | + flowstate: null |
1287 | 1315 | };
|
1288 | 1316 |
|
1289 | 1317 | var sub;
|
|
1308 | 1336 | symbol.symbolType = symbol.symbolType.split('\n')[0];
|
1309 | 1337 | }
|
1310 | 1338 |
|
| 1339 | + /* adding support for links */ |
1311 | 1340 | if (symbol.link) {
|
1312 | 1341 | var startIndex = symbol.link.indexOf('[') + 1;
|
1313 | 1342 | var endIndex = symbol.link.indexOf(']');
|
|
1316 | 1345 | symbol.link = symbol.link.substring(0, startIndex - 1);
|
1317 | 1346 | }
|
1318 | 1347 | }
|
| 1348 | + /* end of link support */ |
| 1349 | + |
| 1350 | + /* adding support for flowstates */ |
| 1351 | + if (symbol.text) { |
| 1352 | + if (symbol.text.indexOf('|') >= 0) { |
| 1353 | + var txtAndState = symbol.text.split('|'); |
| 1354 | + symbol.text = txtAndState[0]; |
| 1355 | + symbol.flowstate = txtAndState[1].trim(); |
| 1356 | + } |
| 1357 | + } |
| 1358 | + /* end of flowstate support */ |
1319 | 1359 |
|
1320 | 1360 | chart.symbols[symbol.key] = symbol;
|
1321 | 1361 |
|
|
0 commit comments