From 4b0ca55eb79e963523eb6c8197825e9e8ae904e2 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 4 May 2015 15:53:29 +0800 Subject: First commit, version 0.2.7 --- public/vendor/flowchart/flowchart-1.4.0.js | 1423 ++++++++++++++++++++++++ public/vendor/flowchart/flowchart-1.4.0.min.js | 5 + 2 files changed, 1428 insertions(+) create mode 100644 public/vendor/flowchart/flowchart-1.4.0.js create mode 100644 public/vendor/flowchart/flowchart-1.4.0.min.js (limited to 'public/vendor/flowchart') diff --git a/public/vendor/flowchart/flowchart-1.4.0.js b/public/vendor/flowchart/flowchart-1.4.0.js new file mode 100644 index 00000000..ffe2bacf --- /dev/null +++ b/public/vendor/flowchart/flowchart-1.4.0.js @@ -0,0 +1,1423 @@ +// flowchart, v1.4.0 +// Copyright (c)2015 Adriano Raiano (adrai). +// Distributed under MIT license +// http://adrai.github.io/flowchart.js +(function() { + + // add indexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) { + "use strict"; + if (this === null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n !== 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + // add lastIndexOf to non ECMA-262 standard compliant browsers + if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) { + "use strict"; + if (this === null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = len; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } else if (n !== 0 && n != (1 / 0) && n != -(1 / 0)) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + var k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; + } + + if (!String.prototype.trim) { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + }; + } + + var root = this, + flowchart = {}; + + // Export the flowchart object for **CommonJS**. + // If we're not in CommonJS, add `flowchart` to the + // global object or to jquery. + if (typeof module !== 'undefined' && module.exports) { + module.exports = flowchart; + } else { + root.flowchart = root.flowchart || flowchart; + } + // defaults + var o = { + 'x': 0, + 'y': 0, + 'line-width': 3, + 'line-length': 50, + 'text-margin': 10, + 'font-size': 14, + 'font-color': 'black', + // 'font': 'normal', + // 'font-family': 'calibri', + // 'font-weight': 'normal', + 'line-color': 'black', + 'element-color': 'black', + 'fill': 'white', + 'yes-text': 'yes', + 'no-text': 'no', + 'arrow-end': 'block', + 'class': 'flowchart', + 'scale': 1, + 'symbols': { + 'start': {}, + 'end': {}, + 'condition': {}, + 'inputoutput': {}, + 'operation': {}, + 'subroutine': {} + }//, + // 'flowstate' : { + // 'past' : { 'fill': '#CCCCCC', 'font-size': 12}, + // 'current' : {'fill': 'yellow', 'font-color': 'red', 'font-weight': 'bold'}, + // 'future' : { 'fill': '#FFFF99'}, + // 'invalid': {'fill': '#444444'} + // } + }; + function _defaults(options, defaultOptions) { + if (!options || typeof options === 'function') { + return defaultOptions; + } + + var merged = {}; + for (var attrname in defaultOptions) { + merged[attrname] = defaultOptions[attrname]; + } + + for (attrname in options) { + if (options[attrname]) { + if (typeof merged[attrname] === 'object') { + merged[attrname] = _defaults(merged[attrname], options[attrname]); + } else { + merged[attrname] = options[attrname]; + } + } + } + return merged; + } + + function _inherits(ctor, superCtor) { + if (typeof(Object.create) === 'function') { + // implementation from standard node.js 'util' module + ctor.super_ = superCtor; + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + } else { + // old school shim for old browsers + ctor.super_ = superCtor; + var TempCtor = function () {}; + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } + } + + // move dependent functions to a container so that + // they can be overriden easier in no jquery environment (node.js) + var f = { + defaults: _defaults, + inherits: _inherits + }; + function drawPath(chart, location, points) { + var i, len; + var path = 'M{0},{1}'; + for (i = 2, len = 2 * points.length + 2; i < len; i+=2) { + path += ' L{' + i + '},{' + (i + 1) + '}'; + } + var pathValues = [location.x, location.y]; + for (i = 0, len = points.length; i < len; i++) { + pathValues.push(points[i].x); + pathValues.push(points[i].y); + } + var symbol = chart.paper.path(path, pathValues); + symbol.attr('stroke', chart.options['element-color']); + symbol.attr('stroke-width', chart.options['line-width']); + + var font = chart.options['font']; + var fontF = chart.options['font-family']; + var fontW = chart.options['font-weight']; + + if (font) symbol.attr({ 'font': font }); + if (fontF) symbol.attr({ 'font-family': fontF }); + if (fontW) symbol.attr({ 'font-weight': fontW }); + + return symbol; + } + + function drawLine(chart, from, to, text) { + var i, len; + + if (Object.prototype.toString.call(to) !== '[object Array]') { + to = [to]; + } + + var path = 'M{0},{1}'; + for (i = 2, len = 2 * to.length + 2; i < len; i+=2) { + path += ' L{' + i + '},{' + (i + 1) + '}'; + } + var pathValues = [from.x, from.y]; + for (i = 0, len = to.length; i < len; i++) { + pathValues.push(to[i].x); + pathValues.push(to[i].y); + } + + var line = chart.paper.path(path, pathValues); + line.attr({ + stroke: chart.options['line-color'], + 'stroke-width': chart.options['line-width'], + 'arrow-end': chart.options['arrow-end'] + }); + + var font = chart.options['font']; + var fontF = chart.options['font-family']; + var fontW = chart.options['font-weight']; + + if (font) line.attr({ 'font': font }); + if (fontF) line.attr({ 'font-family': fontF }); + if (fontW) line.attr({ 'font-weight': fontW }); + + if (text) { + + var centerText = false; + + var textPath = chart.paper.text(0, 0, text); + + var isHorizontal = false; + var firstTo = to[0]; + + if (from.y === firstTo.y) { + isHorizontal = true; + } + + var x = 0, + y = 0; + + if (centerText) { + if (from.x > firstTo.x) { + x = from.x - (from.x - firstTo.x)/2; + } else { + x = firstTo.x - (firstTo.x - from.x)/2; + } + + if (from.y > firstTo.y) { + y = from.y - (from.y - firstTo.y)/2; + } else { + y = firstTo.y - (firstTo.y - from.y)/2; + } + + if (isHorizontal) { + x -= textPath.getBBox().width/2; + y -= chart.options['text-margin']; + } else { + x += chart.options['text-margin']; + y -= textPath.getBBox().height/2; + } + } else { + x = from.x; + y = from.y; + + if (isHorizontal) { + x += chart.options['text-margin']/2; + y -= chart.options['text-margin']; + } else { + x += chart.options['text-margin']/2; + y += chart.options['text-margin']; + } + } + + textPath.attr({ + 'text-anchor': 'start', + 'font-size': chart.options['font-size'], + 'fill': chart.options['font-color'], + x: x, + y: y + }); + + if (font) textPath.attr({ 'font': font }); + if (fontF) textPath.attr({ 'font-family': fontF }); + if (fontW) textPath.attr({ 'font-weight': fontW }); + } + + return line; + } + + function checkLineIntersection(line1StartX, line1StartY, line1EndX, line1EndY, line2StartX, line2StartY, line2EndX, line2EndY) { + // if the lines intersect, the result contains the x and y of the intersection (treating the lines as infinite) and booleans for whether line segment 1 or line segment 2 contain the point + var denominator, a, b, numerator1, numerator2, result = { + x: null, + y: null, + onLine1: false, + onLine2: false + }; + denominator = ((line2EndY - line2StartY) * (line1EndX - line1StartX)) - ((line2EndX - line2StartX) * (line1EndY - line1StartY)); + if (denominator === 0) { + return result; + } + a = line1StartY - line2StartY; + b = line1StartX - line2StartX; + numerator1 = ((line2EndX - line2StartX) * a) - ((line2EndY - line2StartY) * b); + numerator2 = ((line1EndX - line1StartX) * a) - ((line1EndY - line1StartY) * b); + a = numerator1 / denominator; + b = numerator2 / denominator; + + // if we cast these lines infinitely in both directions, they intersect here: + result.x = line1StartX + (a * (line1EndX - line1StartX)); + result.y = line1StartY + (a * (line1EndY - line1StartY)); + /* + // it is worth noting that this should be the same as: + x = line2StartX + (b * (line2EndX - line2StartX)); + y = line2StartX + (b * (line2EndY - line2StartY)); + */ + // if line1 is a segment and line2 is infinite, they intersect if: + if (a > 0 && a < 1) { + result.onLine1 = true; + } + // if line2 is a segment and line1 is infinite, they intersect if: + if (b > 0 && b < 1) { + result.onLine2 = true; + } + // if line1 and line2 are segments, they intersect if both of the above are true + return result; + } + function FlowChart(container, options) { + options = options || {}; + + this.paper = new Raphael(container); + + this.options = f.defaults(options, o); + + this.symbols = []; + this.lines = []; + this.start = null; + } + + FlowChart.prototype.handle = function(symbol) { + if (this.symbols.indexOf(symbol) <= -1) { + this.symbols.push(symbol); + } + + var flowChart = this; + + if (symbol instanceof(Condition)) { + symbol.yes = function(nextSymbol) { + symbol.yes_symbol = nextSymbol; + if(symbol.no_symbol) { + symbol.pathOk = true; + } + return flowChart.handle(nextSymbol); + }; + symbol.no = function(nextSymbol) { + symbol.no_symbol = nextSymbol; + if(symbol.yes_symbol) { + symbol.pathOk = true; + } + return flowChart.handle(nextSymbol); + }; + } else { + symbol.then = function(nextSymbol) { + symbol.next = nextSymbol; + symbol.pathOk = true; + return flowChart.handle(nextSymbol); + }; + } + + return symbol; + }; + + FlowChart.prototype.startWith = function(symbol) { + this.start = symbol; + return this.handle(symbol); + }; + + FlowChart.prototype.render = function() { + var maxWidth = 0, + maxHeight = 0, + i = 0, + len = 0, + maxX = 0, + maxY = 0, + symbol; + + for (i = 0, len = this.symbols.length; i < len; i++) { + symbol = this.symbols[i]; + if (symbol.width > maxWidth) { + maxWidth = symbol.width; + } + if (symbol.height > maxHeight) { + maxHeight = symbol.height; + } + } + + for (i = 0, len = this.symbols.length; i < len; i++) { + symbol = this.symbols[i]; + symbol.shiftX(this.options.x + (maxWidth - symbol.width)/2 + this.options['line-width']); + symbol.shiftY(this.options.y + (maxHeight - symbol.height)/2 + this.options['line-width']); + } + + this.start.render(); + // for (i = 0, len = this.symbols.length; i < len; i++) { + // symbol = this.symbols[i]; + // symbol.render(); + // } + + for (i = 0, len = this.symbols.length; i < len; i++) { + symbol = this.symbols[i]; + symbol.renderLines(); + } + + maxX = this.maxXFromLine; + + for (i = 0, len = this.symbols.length; i < len; i++) { + symbol = this.symbols[i]; + var x = symbol.getX() + symbol.width; + var y = symbol.getY() + symbol.height; + if (x > maxX) { + maxX = x; + } + if (y > maxY) { + maxY = y; + } + } + + var scale = this.options['scale']; + var lineWidth = this.options['line-width']; + this.paper.setSize((maxX * scale) + (lineWidth * scale), (maxY * scale) + (lineWidth * scale)); + this.paper.setViewBox(0, 0, maxX + lineWidth, maxY + lineWidth, true); + }; + + FlowChart.prototype.clean = function() { + if (this.paper) { + var paperDom = this.paper.canvas; + paperDom.parentNode.removeChild(paperDom); + } + }; + function Symbol(chart, options, symbol) { + this.chart = chart; + this.group = this.chart.paper.set(); + this.symbol = symbol; + this.connectedTo = []; + this.symbolType = options.symbolType; + this.flowstate = (options.flowstate || 'future'); + + this.next_direction = options.next && options['direction_next'] ? options['direction_next'] : undefined; + + this.text = this.chart.paper.text(0, 0, options.text); + //Raphael does not support the svg group tag so setting the text node id to the symbol node id plus t + if (options.key) { this.text.node.id = options.key + 't'; } + this.text.node.setAttribute('class', this.getAttr('class') + 't'); + + this.text.attr({ + 'text-anchor': 'start', + 'x' : this.getAttr('text-margin'), + 'fill' : this.getAttr('font-color'), + 'font-size' : this.getAttr('font-size') + }); + + var font = this.getAttr('font'); + var fontF = this.getAttr('font-family'); + var fontW = this.getAttr('font-weight'); + + if (font) this.text.attr({ 'font': font }); + if (fontF) this.text.attr({ 'font-family': fontF }); + if (fontW) this.text.attr({ 'font-weight': fontW }); + + if (options.link) { this.text.attr('href', options.link); } + if (options.target) { this.text.attr('target', options.target); } + + var maxWidth = this.getAttr('maxWidth'); + if (maxWidth) { + // using this approach: http://stackoverflow.com/a/3153457/22466 + var words = options.text.split(' '); + var tempText = ""; + for (var i=0, ii=words.length; i maxWidth) { + tempText += "\n" + word; + } else { + tempText += " " + word; + } + } + this.text.attr("text", tempText.substring(1)); + } + + this.group.push(this.text); + + if (symbol) { + var tmpMargin = this.getAttr('text-margin'); + + symbol.attr({ + 'fill' : this.getAttr('fill'), + 'stroke' : this.getAttr('element-color'), + 'stroke-width' : this.getAttr('line-width'), + 'width' : this.text.getBBox().width + 2 * tmpMargin, + 'height' : this.text.getBBox().height + 2 * tmpMargin + }); + + symbol.node.setAttribute('class', this.getAttr('class')); + + if (options.link) { symbol.attr('href', options.link); } + if (options.target) { symbol.attr('target', options.target); } + if (options.key) { symbol.node.id = options.key; } + + this.group.push(symbol); + symbol.insertBefore(this.text); + + this.text.attr({ + 'y': symbol.getBBox().height/2 + }); + + this.initialize(); + } + + } + + /* Gets the attribute based on Flowstate, Symbol-Name and default, first found wins */ + Symbol.prototype.getAttr = function(attName) { + if (!this.chart) { + return undefined; + } + var opt3 = (this.chart.options) ? this.chart.options[attName] : undefined; + var opt2 = (this.chart.options.symbols) ? this.chart.options.symbols[this.symbolType][attName] : undefined; + var opt1; + if (this.chart.options.flowstate && this.chart.options.flowstate[this.flowstate]) { + opt1 = this.chart.options.flowstate[this.flowstate][attName]; + } + return (opt1 || opt2 || opt3); + }; + + Symbol.prototype.initialize = function() { + this.group.transform('t' + this.getAttr('line-width') + ',' + this.getAttr('line-width')); + + this.width = this.group.getBBox().width; + this.height = this.group.getBBox().height; + }; + + Symbol.prototype.getCenter = function() { + return {x: this.getX() + this.width/2, + y: this.getY() + this.height/2}; + }; + + Symbol.prototype.getX = function() { + return this.group.getBBox().x; + }; + + Symbol.prototype.getY = function() { + return this.group.getBBox().y; + }; + + Symbol.prototype.shiftX = function(x) { + this.group.transform('t' + (this.getX() + x) + ',' + this.getY()); + }; + + Symbol.prototype.setX = function(x) { + this.group.transform('t' + x + ',' + this.getY()); + }; + + Symbol.prototype.shiftY = function(y) { + this.group.transform('t' + this.getX() + ',' + (this.getY() + y)); + }; + + Symbol.prototype.setY = function(y) { + this.group.transform('t' + this.getX() + ',' + y); + }; + + Symbol.prototype.getTop = function() { + var y = this.getY(); + var x = this.getX() + this.width/2; + return {x: x, y: y}; + }; + + Symbol.prototype.getBottom = function() { + var y = this.getY() + this.height; + var x = this.getX() + this.width/2; + return {x: x, y: y}; + }; + + Symbol.prototype.getLeft = function() { + var y = this.getY() + this.group.getBBox().height/2; + var x = this.getX(); + return {x: x, y: y}; + }; + + Symbol.prototype.getRight = function() { + var y = this.getY() + this.group.getBBox().height/2; + var x = this.getX() + this.group.getBBox().width; + return {x: x, y: y}; + }; + + Symbol.prototype.render = function() { + if (this.next) { + + var lineLength = this.getAttr('line-length'); + + if (this.next_direction === 'right') { + + var rightPoint = this.getRight(); + var leftPoint = this.next.getLeft(); + + if (!this.next.isPositioned) { + + this.next.setY(rightPoint.y - this.next.height/2); + this.next.shiftX(this.group.getBBox().x + this.width + lineLength); + + var self = this; + (function shift() { + var hasSymbolUnder = false; + var symb; + for (var i = 0, len = self.chart.symbols.length; i < len; i++) { + symb = self.chart.symbols[i]; + + var diff = Math.abs(symb.getCenter().x - self.next.getCenter().x); + if (symb.getCenter().y > self.next.getCenter().y && diff <= self.next.width/2) { + hasSymbolUnder = true; + break; + } + } + + if (hasSymbolUnder) { + self.next.setX(symb.getX() + symb.width + lineLength); + shift(); + } + })(); + + this.next.isPositioned = true; + + this.next.render(); + } + } else { + var bottomPoint = this.getBottom(); + var topPoint = this.next.getTop(); + + if (!this.next.isPositioned) { + this.next.shiftY(this.getY() + this.height + lineLength); + this.next.setX(bottomPoint.x - this.next.width/2); + this.next.isPositioned = true; + + this.next.render(); + } + } + } + }; + + Symbol.prototype.renderLines = function() { + if (this.next) { + if (this.next_direction) { + this.drawLineTo(this.next, '', this.next_direction); + } else { + this.drawLineTo(this.next); + } + } + }; + + Symbol.prototype.drawLineTo = function(symbol, text, origin) { + if (this.connectedTo.indexOf(symbol) < 0) { + this.connectedTo.push(symbol); + } + + var x = this.getCenter().x, + y = this.getCenter().y, + top = this.getTop(), + right = this.getRight(), + bottom = this.getBottom(), + left = this.getLeft(); + + var symbolX = symbol.getCenter().x, + symbolY = symbol.getCenter().y, + symbolTop = symbol.getTop(), + symbolRight = symbol.getRight(), + symbolBottom = symbol.getBottom(), + symbolLeft = symbol.getLeft(); + + var isOnSameColumn = x === symbolX, + isOnSameLine = y === symbolY, + isUnder = y < symbolY, + isUpper = y > symbolY, + isLeft = x > symbolX, + isRight = x < symbolX; + + var maxX = 0, + line, + lineLength = this.getAttr('line-length'), + lineWith = this.getAttr('line-width'); + + if ((!origin || origin === 'bottom') && isOnSameColumn && isUnder) { + line = drawLine(this.chart, bottom, symbolTop, text); + this.bottomStart = true; + symbol.topEnd = true; + maxX = bottom.x; + } else if ((!origin || origin === 'right') && isOnSameLine && isRight) { + line = drawLine(this.chart, right, symbolLeft, text); + this.rightStart = true; + symbol.leftEnd = true; + maxX = symbolLeft.x; + } else if ((!origin || origin === 'left') && isOnSameLine && isLeft) { + line = drawLine(this.chart, left, symbolRight, text); + this.leftStart = true; + symbol.rightEnd = true; + maxX = symbolRight.x; + } else if ((!origin || origin === 'right') && isOnSameColumn && isUpper) { + line = drawLine(this.chart, right, [ + {x: right.x + lineLength/2, y: right.y}, + {x: right.x + lineLength/2, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + this.rightStart = true; + symbol.topEnd = true; + maxX = right.x + lineLength/2; + } else if ((!origin || origin === 'right') && isOnSameColumn && isUnder) { + line = drawLine(this.chart, right, [ + {x: right.x + lineLength/2, y: right.y}, + {x: right.x + lineLength/2, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + this.rightStart = true; + symbol.topEnd = true; + maxX = right.x + lineLength/2; + } else if ((!origin || origin === 'bottom') && isLeft) { + if (this.leftEnd && isUpper) { + line = drawLine(this.chart, bottom, [ + {x: bottom.x, y: bottom.y + lineLength/2}, + {x: bottom.x + (bottom.x - symbolTop.x)/2, y: bottom.y + lineLength/2}, + {x: bottom.x + (bottom.x - symbolTop.x)/2, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + } else { + line = drawLine(this.chart, bottom, [ + {x: bottom.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + } + this.bottomStart = true; + symbol.topEnd = true; + maxX = bottom.x + (bottom.x - symbolTop.x)/2; + } else if ((!origin || origin === 'bottom') && isRight) { + line = drawLine(this.chart, bottom, [ + {x: bottom.x, y: bottom.y + lineLength/2}, + {x: bottom.x + (bottom.x - symbolTop.x)/2, y: bottom.y + lineLength/2}, + {x: bottom.x + (bottom.x - symbolTop.x)/2, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + this.bottomStart = true; + symbol.topEnd = true; + maxX = bottom.x + (bottom.x - symbolTop.x)/2; + } else if ((origin && origin === 'right') && isLeft) { + line = drawLine(this.chart, right, [ + {x: right.x + lineLength/2, y: right.y}, + {x: right.x + lineLength/2, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + this.rightStart = true; + symbol.topEnd = true; + maxX = right.x + lineLength/2; + } else if ((origin && origin === 'right') && isRight) { + line = drawLine(this.chart, right, [ + {x: symbolTop.x, y: right.y}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + this.rightStart = true; + symbol.topEnd = true; + maxX = right.x + lineLength/2; + } else if ((origin && origin === 'bottom') && isOnSameColumn && isUpper) { + line = drawLine(this.chart, bottom, [ + {x: bottom.x, y: bottom.y + lineLength/2}, + {x: right.x + lineLength/2, y: bottom.y + lineLength/2}, + {x: right.x + lineLength/2, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + this.bottomStart = true; + symbol.topEnd = true; + maxX = bottom.x + lineLength/2; + } else if ((origin === 'left') && isOnSameColumn && isUpper) { + var diffX = left.x - lineLength/2; + if (symbolLeft.x < left.x) { + diffX = symbolLeft.x - lineLength/2; + } + line = drawLine(this.chart, left, [ + {x: diffX, y: left.y}, + {x: diffX, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + this.leftStart = true; + symbol.topEnd = true; + maxX = left.x; + } else if ((origin === 'left')) { + line = drawLine(this.chart, left, [ + {x: symbolTop.x + (left.x - symbolTop.x)/ 2, y: left.y}, + {x: symbolTop.x + (left.x - symbolTop.x)/ 2, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y - lineLength/2}, + {x: symbolTop.x, y: symbolTop.y} + ], text); + this.leftStart = true; + symbol.topEnd = true; + maxX = left.x; + } + + if (line) { + var self = this; + for (var l = 0, llen = this.chart.lines.length; l < llen; l++) { + var otherLine = this.chart.lines[l]; + var i, + len, + intersections, + inter; + + var ePath = otherLine.attr('path'), + lPath = line.attr('path'); + + for (var iP = 0, lenP = ePath.length - 1; iP < lenP; iP++) { + var newPath = []; + newPath.push(['M', ePath[iP][1], ePath[iP][2]]); + newPath.push(['L', ePath[iP + 1][1], ePath[iP + 1][2]]); + + var line1_from_x = newPath[0][1]; + var line1_from_y = newPath[0][2]; + var line1_to_x = newPath[1][1]; + var line1_to_y = newPath[1][2]; + + for (var lP = 0, lenlP = lPath.length - 1; lP < lenlP; lP++) { + var newLinePath = []; + newLinePath.push(['M', lPath[lP][1], lPath[lP][2]]); + newLinePath.push(['L', lPath[lP + 1][1], lPath[lP + 1][2]]); + + var line2_from_x = newLinePath[0][1]; + var line2_from_y = newLinePath[0][2]; + var line2_to_x = newLinePath[1][1]; + var line2_to_y = newLinePath[1][2]; + + var res = checkLineIntersection(line1_from_x, line1_from_y, line1_to_x, line1_to_y, line2_from_x, line2_from_y, line2_to_x, line2_to_y); + if (res.onLine1 && res.onLine2) { + + var newSegment; + if (line2_from_y === line2_to_y) { + if (line2_from_x > line2_to_x) { + newSegment = ['L', res.x + lineWith * 2, line2_from_y]; + lPath.splice(lP + 1, 0, newSegment); + newSegment = ['C', res.x + lineWith * 2, line2_from_y, res.x, line2_from_y - lineWith * 4, res.x - lineWith * 2, line2_from_y]; + lPath.splice(lP + 2, 0, newSegment); + line.attr('path', lPath); + } else { + newSegment = ['L', res.x - lineWith * 2, line2_from_y]; + lPath.splice(lP + 1, 0, newSegment); + newSegment = ['C', res.x - lineWith * 2, line2_from_y, res.x, line2_from_y - lineWith * 4, res.x + lineWith * 2, line2_from_y]; + lPath.splice(lP + 2, 0, newSegment); + line.attr('path', lPath); + } + } else { + if (line2_from_y > line2_to_y) { + newSegment = ['L', line2_from_x, res.y + lineWith * 2]; + lPath.splice(lP + 1, 0, newSegment); + newSegment = ['C', line2_from_x, res.y + lineWith * 2, line2_from_x + lineWith * 4, res.y, line2_from_x, res.y - lineWith * 2]; + lPath.splice(lP + 2, 0, newSegment); + line.attr('path', lPath); + } else { + newSegment = ['L', line2_from_x, res.y - lineWith * 2]; + lPath.splice(lP + 1, 0, newSegment); + newSegment = ['C', line2_from_x, res.y - lineWith * 2, line2_from_x + lineWith * 4, res.y, line2_from_x, res.y + lineWith * 2]; + lPath.splice(lP + 2, 0, newSegment); + line.attr('path', lPath); + } + } + + lP += 2; + len += 2; + } + } + } + } + + this.chart.lines.push(line); + } + + if (!this.chart.maxXFromLine || (this.chart.maxXFromLine && maxX > this.chart.maxXFromLine)) { + this.chart.maxXFromLine = maxX; + } + }; + function Start(chart, options) { + var symbol = chart.paper.rect(0, 0, 0, 0, 20); + options = options || {}; + options.text = options.text || 'Start'; + Symbol.call(this, chart, options, symbol); + } + f.inherits(Start, Symbol); + + + // Start.prototype.render = function() { + // if (this.next) { + // var lineLength = this.chart.options.symbols[this.symbolType]['line-length'] || this.chart.options['line-length']; + + // var bottomPoint = this.getBottom(); + // var topPoint = this.next.getTop(); + + // if (!this.next.isPositioned) { + // this.next.shiftY(this.getY() + this.height + lineLength); + // this.next.setX(bottomPoint.x - this.next.width/2); + // this.next.isPositioned = true; + + // this.next.render(); + // } + // } + // }; + + // Start.prototype.renderLines = function() { + // if (this.next) { + // this.drawLineTo(this.next); + // } + // }; + function End(chart, options) { + var symbol = chart.paper.rect(0, 0, 0, 0, 20); + options = options || {}; + options.text = options.text || 'End'; + Symbol.call(this, chart, options, symbol); + } + f.inherits(End, Symbol); + function Operation(chart, options) { + var symbol = chart.paper.rect(0, 0, 0, 0); + options = options || {}; + Symbol.call(this, chart, options, symbol); + } + f.inherits(Operation, Symbol); + function Subroutine(chart, options) { + var symbol = chart.paper.rect(0, 0, 0, 0); + options = options || {}; + Symbol.call(this, chart, options, symbol); + + symbol.attr({ + width: this.text.getBBox().width + 4 * this.getAttr('text-margin') + }); + + this.text.attr({ + 'x': 2 * this.getAttr('text-margin') + }); + + var innerWrap = chart.paper.rect(0, 0, 0, 0); + innerWrap.attr({ + x: this.getAttr('text-margin'), + stroke: this.getAttr('element-color'), + 'stroke-width': this.getAttr('line-width'), + width: this.text.getBBox().width + 2 * this.getAttr('text-margin'), + height: this.text.getBBox().height + 2 * this.getAttr('text-margin'), + fill: this.getAttr('fill') + }); + if (options.key) { innerWrap.node.id = options.key + 'i'; } + + var font = this.getAttr('font'); + var fontF = this.getAttr('font-family'); + var fontW = this.getAttr('font-weight'); + + if (font) innerWrap.attr({ 'font': font }); + if (fontF) innerWrap.attr({ 'font-family': fontF }); + if (fontW) innerWrap.attr({ 'font-weight': fontW }); + + if (options.link) { innerWrap.attr('href', options.link); } + if (options.target) { innerWrap.attr('target', options.target); } + this.group.push(innerWrap); + innerWrap.insertBefore(this.text); + + this.initialize(); + } + f.inherits(Subroutine, Symbol); + function InputOutput(chart, options) { + options = options || {}; + Symbol.call(this, chart, options); + this.textMargin = this.getAttr('text-margin'); + + this.text.attr({ + x: this.textMargin * 3 + }); + + var width = this.text.getBBox().width + 4 * this.textMargin; + var height = this.text.getBBox().height + 2 * this.textMargin; + var startX = this.textMargin; + var startY = height/2; + + var start = {x: startX, y: startY}; + var points = [ + {x: startX - this.textMargin, y: height}, + {x: startX - this.textMargin + width, y: height}, + {x: startX - this.textMargin + width + 2 * this.textMargin, y: 0}, + {x: startX - this.textMargin + 2 * this.textMargin, y: 0}, + {x: startX, y: startY} + ]; + + var symbol = drawPath(chart, start, points); + + symbol.attr({ + stroke: this.getAttr('element-color'), + 'stroke-width': this.getAttr('line-width'), + fill: this.getAttr('fill') + }); + if (options.link) { symbol.attr('href', options.link); } + if (options.target) { symbol.attr('target', options.target); } + if (options.key) { symbol.node.id = options.key; } + symbol.node.setAttribute('class', this.getAttr('class')); + + this.text.attr({ + y: symbol.getBBox().height/2 + }); + + this.group.push(symbol); + symbol.insertBefore(this.text); + + this.initialize(); + } + f.inherits(InputOutput, Symbol); + + InputOutput.prototype.getLeft = function() { + var y = this.getY() + this.group.getBBox().height/2; + var x = this.getX() + this.textMargin; + return {x: x, y: y}; + }; + + InputOutput.prototype.getRight = function() { + var y = this.getY() + this.group.getBBox().height/2; + var x = this.getX() + this.group.getBBox().width - this.textMargin; + return {x: x, y: y}; + }; + function Condition(chart, options) { + options = options || {}; + Symbol.call(this, chart, options); + this.textMargin = this.getAttr('text-margin'); + this.yes_direction = 'bottom'; + this.no_direction = 'right'; + if (options.yes && options['direction_yes'] && options.no && !options['direction_no']) { + if (options['direction_yes'] === 'right') { + this.no_direction = 'bottom'; + this.yes_direction = 'right'; + } else { + this.no_direction = 'right'; + this.yes_direction = 'bottom'; + } + } else if (options.yes && !options['direction_yes'] && options.no && options['direction_no']) { + if (options['direction_no'] === 'right') { + this.yes_direction = 'bottom'; + this.no_direction = 'right'; + } else { + this.yes_direction = 'right'; + this.no_direction = 'bottom'; + } + } else { + this.yes_direction = 'bottom'; + this.no_direction = 'right'; + } + + this.yes_direction = this.yes_direction || 'bottom'; + this.no_direction = this.no_direction || 'right'; + + this.text.attr({ + x: this.textMargin * 2 + }); + + var width = this.text.getBBox().width + 3 * this.textMargin; + width += width/2; + var height = this.text.getBBox().height + 2 * this.textMargin; + height += height/2; + height = Math.max(width * 0.5, height); + var startX = width/4; + var startY = height/4; + + this.text.attr({ + x: startX + this.textMargin/2 + }); + + var start = {x: startX, y: startY}; + var points = [ + {x: startX - width/4, y: startY + height/4}, + {x: startX - width/4 + width/2, y: startY + height/4 + height/2}, + {x: startX - width/4 + width, y: startY + height/4}, + {x: startX - width/4 + width/2, y: startY + height/4 - height/2}, + {x: startX - width/4, y: startY + height/4} + ]; + + var symbol = drawPath(chart, start, points); + + symbol.attr({ + stroke: this.getAttr('element-color'), + 'stroke-width': this.getAttr('line-width'), + fill: this.getAttr('fill') + }); + if (options.link) { symbol.attr('href', options.link); } + if (options.target) { symbol.attr('target', options.target); } + if (options.key) { symbol.node.id = options.key; } + symbol.node.setAttribute('class', this.getAttr('class')); + + this.text.attr({ + y: symbol.getBBox().height/2 + }); + + this.group.push(symbol); + symbol.insertBefore(this.text); + + this.initialize(); + } + f.inherits(Condition, Symbol); + + Condition.prototype.render = function() { + + if (this.yes_direction) { + this[this.yes_direction + '_symbol'] = this.yes_symbol; + } + + if (this.no_direction) { + this[this.no_direction + '_symbol'] = this.no_symbol; + } + + var lineLength = this.getAttr('line-length'); + + if (this.bottom_symbol) { + var bottomPoint = this.getBottom(); + var topPoint = this.bottom_symbol.getTop(); + + if (!this.bottom_symbol.isPositioned) { + this.bottom_symbol.shiftY(this.getY() + this.height + lineLength); + this.bottom_symbol.setX(bottomPoint.x - this.bottom_symbol.width/2); + this.bottom_symbol.isPositioned = true; + + this.bottom_symbol.render(); + } + } + + if (this.right_symbol) { + var rightPoint = this.getRight(); + var leftPoint = this.right_symbol.getLeft(); + + if (!this.right_symbol.isPositioned) { + + this.right_symbol.setY(rightPoint.y - this.right_symbol.height/2); + this.right_symbol.shiftX(this.group.getBBox().x + this.width + lineLength); + + var self = this; + (function shift() { + var hasSymbolUnder = false; + var symb; + for (var i = 0, len = self.chart.symbols.length; i < len; i++) { + symb = self.chart.symbols[i]; + + var diff = Math.abs(symb.getCenter().x - self.right_symbol.getCenter().x); + if (symb.getCenter().y > self.right_symbol.getCenter().y && diff <= self.right_symbol.width/2) { + hasSymbolUnder = true; + break; + } + } + + if (hasSymbolUnder) { + self.right_symbol.setX(symb.getX() + symb.width + lineLength); + shift(); + } + })(); + + this.right_symbol.isPositioned = true; + + this.right_symbol.render(); + } + } + }; + + Condition.prototype.renderLines = function() { + if (this.yes_symbol) { + this.drawLineTo(this.yes_symbol, this.getAttr('yes-text'), this.yes_direction); + } + + if (this.no_symbol) { + this.drawLineTo(this.no_symbol, this.getAttr('no-text'), this.no_direction); + } + }; + function parse(input) { + input = input || ''; + input = input.trim(); + + var chart = { + symbols: {}, + start: null, + drawSVG: function(container, options) { + var self = this; + + if (this.diagram) { + this.diagram.clean(); + } + + var diagram = new FlowChart(container, options); + this.diagram = diagram; + var dispSymbols = {}; + + function getDisplaySymbol(s) { + if (dispSymbols[s.key]) { + return dispSymbols[s.key]; + } + + switch (s.symbolType) { + case 'start': + dispSymbols[s.key] = new Start(diagram, s); + break; + case 'end': + dispSymbols[s.key] = new End(diagram, s); + break; + case 'operation': + dispSymbols[s.key] = new Operation(diagram, s); + break; + case 'inputoutput': + dispSymbols[s.key] = new InputOutput(diagram, s); + break; + case 'subroutine': + dispSymbols[s.key] = new Subroutine(diagram, s); + break; + case 'condition': + dispSymbols[s.key] = new Condition(diagram, s); + break; + default: + return new Error('Wrong symbol type!'); + } + + return dispSymbols[s.key]; + } + + (function constructChart(s, prevDisp, prev) { + var dispSymb = getDisplaySymbol(s); + + if (self.start === s) { + diagram.startWith(dispSymb); + } else if (prevDisp && prev && !prevDisp.pathOk) { + if (prevDisp instanceof(Condition)) { + if (prev.yes === s) { + prevDisp.yes(dispSymb); + } + if (prev.no === s) { + prevDisp.no(dispSymb); + } + } else { + prevDisp.then(dispSymb); + } + } + + if (dispSymb.pathOk) { + return dispSymb; + } + + if (dispSymb instanceof(Condition)) { + if (s.yes) { + constructChart(s.yes, dispSymb, s); + } + if (s.no) { + constructChart(s.no, dispSymb, s); + } + } else if (s.next) { + constructChart(s.next, dispSymb, s); + } + + return dispSymb; + })(this.start); + + diagram.render(); + }, + clean: function() { + this.diagram.clean(); + } + }; + + var lines = []; + var prevBreak = 0; + for (var i0 = 1, i0len = input.length; i0 < i0len; i0++) { + if(input[i0] === '\n' && input[i0 - 1] !== '\\') { + var line0 = input.substring(prevBreak, i0); + prevBreak = i0 + 1; + lines.push(line0.replace(/\\\n/g, '\n')); + } + } + + if(prevBreak < input.length) { + lines.push(input.substr(prevBreak)); + } + + for (var l = 1, len = lines.length; l < len;) { + var currentLine = lines[l]; + + if (currentLine.indexOf(': ') < 0 && currentLine.indexOf('(') < 0 && currentLine.indexOf(')') < 0 && currentLine.indexOf('->') < 0 && currentLine.indexOf('=>') < 0) { + lines[l - 1] += '\n' + currentLine; + lines.splice(l, 1); + len--; + } else { + l++; + } + } + + function getSymbol(s) { + var startIndex = s.indexOf('(') + 1; + var endIndex = s.indexOf(')'); + if (startIndex >= 0 && endIndex >= 0) { + return chart.symbols[s.substring(0, startIndex - 1)]; + } + return chart.symbols[s]; + } + + function getNextPath(s) { + var next = 'next'; + var startIndex = s.indexOf('(') + 1; + var endIndex = s.indexOf(')'); + if (startIndex >= 0 && endIndex >= 0) { + next = flowSymb.substring(startIndex, endIndex); + if (next.indexOf(',') < 0) { + if (next !== 'yes' && next !== 'no') { + next = 'next, ' + next; + } + } + } + return next; + } + + while (lines.length > 0) { + var line = lines.splice(0, 1)[0]; + + if (line.indexOf('=>') >= 0) { + // definition + var parts = line.split('=>'); + var symbol = { + key: parts[0], + symbolType: parts[1], + text: null, + link: null, + target: null, + flowstate: null + }; + + var sub; + + if (symbol.symbolType.indexOf(': ') >= 0) { + sub = symbol.symbolType.split(': '); + symbol.symbolType = sub[0]; + symbol.text = sub[1]; + } + + if (symbol.text && symbol.text.indexOf(':>') >= 0) { + sub = symbol.text.split(':>'); + symbol.text = sub[0]; + symbol.link = sub[1]; + } else if (symbol.symbolType.indexOf(':>') >= 0) { + sub = symbol.symbolType.split(':>'); + symbol.symbolType = sub[0]; + symbol.link = sub[1]; + } + + if (symbol.symbolType.indexOf('\n') >= 0) { + symbol.symbolType = symbol.symbolType.split('\n')[0]; + } + + /* adding support for links */ + if (symbol.link) { + var startIndex = symbol.link.indexOf('[') + 1; + var endIndex = symbol.link.indexOf(']'); + if (startIndex >= 0 && endIndex >= 0) { + symbol.target = symbol.link.substring(startIndex, endIndex); + symbol.link = symbol.link.substring(0, startIndex - 1); + } + } + /* end of link support */ + + /* adding support for flowstates */ + if (symbol.text) { + if (symbol.text.indexOf('|') >= 0) { + var txtAndState = symbol.text.split('|'); + symbol.text = txtAndState[0]; + symbol.flowstate = txtAndState[1].trim(); + } + } + /* end of flowstate support */ + + chart.symbols[symbol.key] = symbol; + + } else if (line.indexOf('->') >= 0) { + // flow + var flowSymbols = line.split('->'); + for (var i = 0, lenS = flowSymbols.length; i < lenS; i++) { + var flowSymb = flowSymbols[i]; + + var realSymb = getSymbol(flowSymb); + var next = getNextPath(flowSymb); + + var direction = null; + if (next.indexOf(',') >= 0) { + var condOpt = next.split(','); + next = condOpt[0]; + direction = condOpt[1].trim(); + } + + if (!chart.start) { + chart.start = realSymb; + } + + if (i + 1 < lenS) { + var nextSymb = flowSymbols[i + 1]; + realSymb[next] = getSymbol(nextSymb); + realSymb['direction_' + next] = direction; + direction = null; + } + } + } + + } + return chart; + } + // public api interface + flowchart.parse = parse; + +})(); \ No newline at end of file diff --git a/public/vendor/flowchart/flowchart-1.4.0.min.js b/public/vendor/flowchart/flowchart-1.4.0.min.js new file mode 100644 index 00000000..3940d37b --- /dev/null +++ b/public/vendor/flowchart/flowchart-1.4.0.min.js @@ -0,0 +1,5 @@ +// flowchart, v1.4.0 +// Copyright (c)2015 Adriano Raiano (adrai). +// Distributed under MIT license +// http://adrai.github.io/flowchart.js +!function(){function a(b,c){if(!b||"function"==typeof b)return c;var d={};for(var e in c)d[e]=c[e];for(e in b)b[e]&&(d[e]="object"==typeof d[e]?a(d[e],b[e]):b[e]);return d}function b(a,b){if("function"==typeof Object.create)a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}});else{a.super_=b;var c=function(){};c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a}}function c(a,b,c){var d,e,f="M{0},{1}";for(d=2,e=2*c.length+2;e>d;d+=2)f+=" L{"+d+"},{"+(d+1)+"}";var g=[b.x,b.y];for(d=0,e=c.length;e>d;d++)g.push(c[d].x),g.push(c[d].y);var h=a.paper.path(f,g);h.attr("stroke",a.options["element-color"]),h.attr("stroke-width",a.options["line-width"]);var i=a.options.font,j=a.options["font-family"],k=a.options["font-weight"];return i&&h.attr({font:i}),j&&h.attr({"font-family":j}),k&&h.attr({"font-weight":k}),h}function d(a,b,c,d){var e,f;"[object Array]"!==Object.prototype.toString.call(c)&&(c=[c]);var g="M{0},{1}";for(e=2,f=2*c.length+2;f>e;e+=2)g+=" L{"+e+"},{"+(e+1)+"}";var h=[b.x,b.y];for(e=0,f=c.length;f>e;e++)h.push(c[e].x),h.push(c[e].y);var i=a.paper.path(g,h);i.attr({stroke:a.options["line-color"],"stroke-width":a.options["line-width"],"arrow-end":a.options["arrow-end"]});var j=a.options.font,k=a.options["font-family"],l=a.options["font-weight"];if(j&&i.attr({font:j}),k&&i.attr({"font-family":k}),l&&i.attr({"font-weight":l}),d){var m=!1,n=a.paper.text(0,0,d),o=!1,p=c[0];b.y===p.y&&(o=!0);var q=0,r=0;m?(q=b.x>p.x?b.x-(b.x-p.x)/2:p.x-(p.x-b.x)/2,r=b.y>p.y?b.y-(b.y-p.y)/2:p.y-(p.y-b.y)/2,o?(q-=n.getBBox().width/2,r-=a.options["text-margin"]):(q+=a.options["text-margin"],r-=n.getBBox().height/2)):(q=b.x,r=b.y,o?(q+=a.options["text-margin"]/2,r-=a.options["text-margin"]):(q+=a.options["text-margin"]/2,r+=a.options["text-margin"])),n.attr({"text-anchor":"start","font-size":a.options["font-size"],fill:a.options["font-color"],x:q,y:r}),j&&n.attr({font:j}),k&&n.attr({"font-family":k}),l&&n.attr({"font-weight":l})}return i}function e(a,b,c,d,e,f,g,h){var i,j,k,l,m,n={x:null,y:null,onLine1:!1,onLine2:!1};return i=(h-f)*(c-a)-(g-e)*(d-b),0===i?n:(j=b-f,k=a-e,l=(g-e)*j-(h-f)*k,m=(c-a)*j-(d-b)*k,j=l/i,k=m/i,n.x=a+j*(c-a),n.y=b+j*(d-b),j>0&&1>j&&(n.onLine1=!0),k>0&&1>k&&(n.onLine2=!0),n)}function f(a,b){b=b||{},this.paper=new Raphael(a),this.options=r.defaults(b,q),this.symbols=[],this.lines=[],this.start=null}function g(a,b,c){this.chart=a,this.group=this.chart.paper.set(),this.symbol=c,this.connectedTo=[],this.symbolType=b.symbolType,this.flowstate=b.flowstate||"future",this.next_direction=b.next&&b.direction_next?b.direction_next:void 0,this.text=this.chart.paper.text(0,0,b.text),b.key&&(this.text.node.id=b.key+"t"),this.text.node.setAttribute("class",this.getAttr("class")+"t"),this.text.attr({"text-anchor":"start",x:this.getAttr("text-margin"),fill:this.getAttr("font-color"),"font-size":this.getAttr("font-size")});var d=this.getAttr("font"),e=this.getAttr("font-family"),f=this.getAttr("font-weight");d&&this.text.attr({font:d}),e&&this.text.attr({"font-family":e}),f&&this.text.attr({"font-weight":f}),b.link&&this.text.attr("href",b.link),b.target&&this.text.attr("target",b.target);var g=this.getAttr("maxWidth");if(g){for(var h=b.text.split(" "),i="",j=0,k=h.length;k>j;j++){var l=h[j];this.text.attr("text",i+" "+l),i+=this.text.getBBox().width>g?"\n"+l:" "+l}this.text.attr("text",i.substring(1))}if(this.group.push(this.text),c){var m=this.getAttr("text-margin");c.attr({fill:this.getAttr("fill"),stroke:this.getAttr("element-color"),"stroke-width":this.getAttr("line-width"),width:this.text.getBBox().width+2*m,height:this.text.getBBox().height+2*m}),c.node.setAttribute("class",this.getAttr("class")),b.link&&c.attr("href",b.link),b.target&&c.attr("target",b.target),b.key&&(c.node.id=b.key),this.group.push(c),c.insertBefore(this.text),this.text.attr({y:c.getBBox().height/2}),this.initialize()}}function h(a,b){var c=a.paper.rect(0,0,0,0,20);b=b||{},b.text=b.text||"Start",g.call(this,a,b,c)}function i(a,b){var c=a.paper.rect(0,0,0,0,20);b=b||{},b.text=b.text||"End",g.call(this,a,b,c)}function j(a,b){var c=a.paper.rect(0,0,0,0);b=b||{},g.call(this,a,b,c)}function k(a,b){var c=a.paper.rect(0,0,0,0);b=b||{},g.call(this,a,b,c),c.attr({width:this.text.getBBox().width+4*this.getAttr("text-margin")}),this.text.attr({x:2*this.getAttr("text-margin")});var d=a.paper.rect(0,0,0,0);d.attr({x:this.getAttr("text-margin"),stroke:this.getAttr("element-color"),"stroke-width":this.getAttr("line-width"),width:this.text.getBBox().width+2*this.getAttr("text-margin"),height:this.text.getBBox().height+2*this.getAttr("text-margin"),fill:this.getAttr("fill")}),b.key&&(d.node.id=b.key+"i");var e=this.getAttr("font"),f=this.getAttr("font-family"),h=this.getAttr("font-weight");e&&d.attr({font:e}),f&&d.attr({"font-family":f}),h&&d.attr({"font-weight":h}),b.link&&d.attr("href",b.link),b.target&&d.attr("target",b.target),this.group.push(d),d.insertBefore(this.text),this.initialize()}function l(a,b){b=b||{},g.call(this,a,b),this.textMargin=this.getAttr("text-margin"),this.text.attr({x:3*this.textMargin});var d=this.text.getBBox().width+4*this.textMargin,e=this.text.getBBox().height+2*this.textMargin,f=this.textMargin,h=e/2,i={x:f,y:h},j=[{x:f-this.textMargin,y:e},{x:f-this.textMargin+d,y:e},{x:f-this.textMargin+d+2*this.textMargin,y:0},{x:f-this.textMargin+2*this.textMargin,y:0},{x:f,y:h}],k=c(a,i,j);k.attr({stroke:this.getAttr("element-color"),"stroke-width":this.getAttr("line-width"),fill:this.getAttr("fill")}),b.link&&k.attr("href",b.link),b.target&&k.attr("target",b.target),b.key&&(k.node.id=b.key),k.node.setAttribute("class",this.getAttr("class")),this.text.attr({y:k.getBBox().height/2}),this.group.push(k),k.insertBefore(this.text),this.initialize()}function m(a,b){b=b||{},g.call(this,a,b),this.textMargin=this.getAttr("text-margin"),this.yes_direction="bottom",this.no_direction="right",b.yes&&b.direction_yes&&b.no&&!b.direction_no?"right"===b.direction_yes?(this.no_direction="bottom",this.yes_direction="right"):(this.no_direction="right",this.yes_direction="bottom"):b.yes&&!b.direction_yes&&b.no&&b.direction_no?"right"===b.direction_no?(this.yes_direction="bottom",this.no_direction="right"):(this.yes_direction="right",this.no_direction="bottom"):(this.yes_direction="bottom",this.no_direction="right"),this.yes_direction=this.yes_direction||"bottom",this.no_direction=this.no_direction||"right",this.text.attr({x:2*this.textMargin});var d=this.text.getBBox().width+3*this.textMargin;d+=d/2;var e=this.text.getBBox().height+2*this.textMargin;e+=e/2,e=Math.max(.5*d,e);var f=d/4,h=e/4;this.text.attr({x:f+this.textMargin/2});var i={x:f,y:h},j=[{x:f-d/4,y:h+e/4},{x:f-d/4+d/2,y:h+e/4+e/2},{x:f-d/4+d,y:h+e/4},{x:f-d/4+d/2,y:h+e/4-e/2},{x:f-d/4,y:h+e/4}],k=c(a,i,j);k.attr({stroke:this.getAttr("element-color"),"stroke-width":this.getAttr("line-width"),fill:this.getAttr("fill")}),b.link&&k.attr("href",b.link),b.target&&k.attr("target",b.target),b.key&&(k.node.id=b.key),k.node.setAttribute("class",this.getAttr("class")),this.text.attr({y:k.getBBox().height/2}),this.group.push(k),k.insertBefore(this.text),this.initialize()}function n(a){function b(a){var b=a.indexOf("(")+1,c=a.indexOf(")");return b>=0&&c>=0?d.symbols[a.substring(0,b-1)]:d.symbols[a]}function c(a){var b="next",c=a.indexOf("(")+1,d=a.indexOf(")");return c>=0&&d>=0&&(b=D.substring(c,d),b.indexOf(",")<0&&"yes"!==b&&"no"!==b&&(b="next, "+b)),b}a=a||"",a=a.trim();for(var d={symbols:{},start:null,drawSVG:function(a,b){function c(a){if(g[a.key])return g[a.key];switch(a.symbolType){case"start":g[a.key]=new h(e,a);break;case"end":g[a.key]=new i(e,a);break;case"operation":g[a.key]=new j(e,a);break;case"inputoutput":g[a.key]=new l(e,a);break;case"subroutine":g[a.key]=new k(e,a);break;case"condition":g[a.key]=new m(e,a);break;default:return new Error("Wrong symbol type!")}return g[a.key]}var d=this;this.diagram&&this.diagram.clean();var e=new f(a,b);this.diagram=e;var g={};!function n(a,b,f){var g=c(a);return d.start===a?e.startWith(g):b&&f&&!b.pathOk&&(b instanceof m?(f.yes===a&&b.yes(g),f.no===a&&b.no(g)):b.then(g)),g.pathOk?g:(g instanceof m?(a.yes&&n(a.yes,g,a),a.no&&n(a.no,g,a)):a.next&&n(a.next,g,a),g)}(this.start),e.render()},clean:function(){this.diagram.clean()}},e=[],g=0,n=1,o=a.length;o>n;n++)if("\n"===a[n]&&"\\"!==a[n-1]){var p=a.substring(g,n);g=n+1,e.push(p.replace(/\\\n/g,"\n"))}gq;){var s=e[q];s.indexOf(": ")<0&&s.indexOf("(")<0&&s.indexOf(")")<0&&s.indexOf("->")<0&&s.indexOf("=>")<0?(e[q-1]+="\n"+s,e.splice(q,1),r--):q++}for(;e.length>0;){var t=e.splice(0,1)[0];if(t.indexOf("=>")>=0){var u,v=t.split("=>"),w={key:v[0],symbolType:v[1],text:null,link:null,target:null,flowstate:null};if(w.symbolType.indexOf(": ")>=0&&(u=w.symbolType.split(": "),w.symbolType=u[0],w.text=u[1]),w.text&&w.text.indexOf(":>")>=0?(u=w.text.split(":>"),w.text=u[0],w.link=u[1]):w.symbolType.indexOf(":>")>=0&&(u=w.symbolType.split(":>"),w.symbolType=u[0],w.link=u[1]),w.symbolType.indexOf("\n")>=0&&(w.symbolType=w.symbolType.split("\n")[0]),w.link){var x=w.link.indexOf("[")+1,y=w.link.indexOf("]");x>=0&&y>=0&&(w.target=w.link.substring(x,y),w.link=w.link.substring(0,x-1))}if(w.text&&w.text.indexOf("|")>=0){var z=w.text.split("|");w.text=z[0],w.flowstate=z[1].trim()}d.symbols[w.key]=w}else if(t.indexOf("->")>=0)for(var A=t.split("->"),B=0,C=A.length;C>B;B++){var D=A[B],E=b(D),F=c(D),G=null;if(F.indexOf(",")>=0){var H=F.split(",");F=H[0],G=H[1].trim()}if(d.start||(d.start=E),C>B+1){var I=A[B+1];E[F]=b(I),E["direction_"+F]=G,G=null}}}return d}Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>0&&(d=Number(arguments[1]),d!=d?d=0:0!==d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=c;arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!==d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));for(var e=d>=0?Math.min(d,c-1):c-Math.abs(d);e>=0;e--)if(e in b&&b[e]===a)return e;return-1}),String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var o=this,p={};"undefined"!=typeof module&&module.exports?module.exports=p:o.flowchart=o.flowchart||p;var q={x:0,y:0,"line-width":3,"line-length":50,"text-margin":10,"font-size":14,"font-color":"black","line-color":"black","element-color":"black",fill:"white","yes-text":"yes","no-text":"no","arrow-end":"block","class":"flowchart",scale:1,symbols:{start:{},end:{},condition:{},inputoutput:{},operation:{},subroutine:{}}},r={defaults:a,inherits:b};f.prototype.handle=function(a){this.symbols.indexOf(a)<=-1&&this.symbols.push(a);var b=this;return a instanceof m?(a.yes=function(c){return a.yes_symbol=c,a.no_symbol&&(a.pathOk=!0),b.handle(c)},a.no=function(c){return a.no_symbol=c,a.yes_symbol&&(a.pathOk=!0),b.handle(c)}):a.then=function(c){return a.next=c,a.pathOk=!0,b.handle(c)},a},f.prototype.startWith=function(a){return this.start=a,this.handle(a)},f.prototype.render=function(){var a,b=0,c=0,d=0,e=0,f=0,g=0;for(d=0,e=this.symbols.length;e>d;d++)a=this.symbols[d],a.width>b&&(b=a.width),a.height>c&&(c=a.height);for(d=0,e=this.symbols.length;e>d;d++)a=this.symbols[d],a.shiftX(this.options.x+(b-a.width)/2+this.options["line-width"]),a.shiftY(this.options.y+(c-a.height)/2+this.options["line-width"]);for(this.start.render(),d=0,e=this.symbols.length;e>d;d++)a=this.symbols[d],a.renderLines();for(f=this.maxXFromLine,d=0,e=this.symbols.length;e>d;d++){a=this.symbols[d];var h=a.getX()+a.width,i=a.getY()+a.height;h>f&&(f=h),i>g&&(g=i)}var j=this.options.scale,k=this.options["line-width"];this.paper.setSize(f*j+k*j,g*j+k*j),this.paper.setViewBox(0,0,f+k,g+k,!0)},f.prototype.clean=function(){if(this.paper){var a=this.paper.canvas;a.parentNode.removeChild(a)}},g.prototype.getAttr=function(a){if(!this.chart)return void 0;var b,c=this.chart.options?this.chart.options[a]:void 0,d=this.chart.options.symbols?this.chart.options.symbols[this.symbolType][a]:void 0;return this.chart.options.flowstate&&this.chart.options.flowstate[this.flowstate]&&(b=this.chart.options.flowstate[this.flowstate][a]),b||d||c},g.prototype.initialize=function(){this.group.transform("t"+this.getAttr("line-width")+","+this.getAttr("line-width")),this.width=this.group.getBBox().width,this.height=this.group.getBBox().height},g.prototype.getCenter=function(){return{x:this.getX()+this.width/2,y:this.getY()+this.height/2}},g.prototype.getX=function(){return this.group.getBBox().x},g.prototype.getY=function(){return this.group.getBBox().y},g.prototype.shiftX=function(a){this.group.transform("t"+(this.getX()+a)+","+this.getY())},g.prototype.setX=function(a){this.group.transform("t"+a+","+this.getY())},g.prototype.shiftY=function(a){this.group.transform("t"+this.getX()+","+(this.getY()+a))},g.prototype.setY=function(a){this.group.transform("t"+this.getX()+","+a)},g.prototype.getTop=function(){var a=this.getY(),b=this.getX()+this.width/2;return{x:b,y:a}},g.prototype.getBottom=function(){var a=this.getY()+this.height,b=this.getX()+this.width/2;return{x:b,y:a}},g.prototype.getLeft=function(){var a=this.getY()+this.group.getBBox().height/2,b=this.getX();return{x:b,y:a}},g.prototype.getRight=function(){var a=this.getY()+this.group.getBBox().height/2,b=this.getX()+this.group.getBBox().width;return{x:b,y:a}},g.prototype.render=function(){if(this.next){var a=this.getAttr("line-length");if("right"===this.next_direction){{var b=this.getRight();this.next.getLeft()}if(!this.next.isPositioned){this.next.setY(b.y-this.next.height/2),this.next.shiftX(this.group.getBBox().x+this.width+a);var c=this;!function e(){for(var b,d=!1,f=0,g=c.chart.symbols.length;g>f;f++){b=c.chart.symbols[f];var h=Math.abs(b.getCenter().x-c.next.getCenter().x);if(b.getCenter().y>c.next.getCenter().y&&h<=c.next.width/2){d=!0;break}}d&&(c.next.setX(b.getX()+b.width+a),e())}(),this.next.isPositioned=!0,this.next.render()}}else{{var d=this.getBottom();this.next.getTop()}this.next.isPositioned||(this.next.shiftY(this.getY()+this.height+a),this.next.setX(d.x-this.next.width/2),this.next.isPositioned=!0,this.next.render())}}},g.prototype.renderLines=function(){this.next&&(this.next_direction?this.drawLineTo(this.next,"",this.next_direction):this.drawLineTo(this.next))},g.prototype.drawLineTo=function(a,b,c){this.connectedTo.indexOf(a)<0&&this.connectedTo.push(a);var f,g=this.getCenter().x,h=this.getCenter().y,i=(this.getTop(),this.getRight()),j=this.getBottom(),k=this.getLeft(),l=a.getCenter().x,m=a.getCenter().y,n=a.getTop(),o=a.getRight(),p=(a.getBottom(),a.getLeft()),q=g===l,r=h===m,s=m>h,t=h>m,u=g>l,v=l>g,w=0,x=this.getAttr("line-length"),y=this.getAttr("line-width");if(c&&"bottom"!==c||!q||!s)if(c&&"right"!==c||!r||!v)if(c&&"left"!==c||!r||!u)if(c&&"right"!==c||!q||!t)if(c&&"right"!==c||!q||!s)if(c&&"bottom"!==c||!u)if(c&&"bottom"!==c||!v)if(c&&"right"===c&&u)f=d(this.chart,i,[{x:i.x+x/2,y:i.y},{x:i.x+x/2,y:n.y-x/2},{x:n.x,y:n.y-x/2},{x:n.x,y:n.y}],b),this.rightStart=!0,a.topEnd=!0,w=i.x+x/2;else if(c&&"right"===c&&v)f=d(this.chart,i,[{x:n.x,y:i.y},{x:n.x,y:n.y}],b),this.rightStart=!0,a.topEnd=!0,w=i.x+x/2;else if(c&&"bottom"===c&&q&&t)f=d(this.chart,j,[{x:j.x,y:j.y+x/2},{x:i.x+x/2,y:j.y+x/2},{x:i.x+x/2,y:n.y-x/2},{x:n.x,y:n.y-x/2},{x:n.x,y:n.y}],b),this.bottomStart=!0,a.topEnd=!0,w=j.x+x/2;else if("left"===c&&q&&t){var z=k.x-x/2;p.xA;A++)for(var C,D=this.chart.lines[A],E=D.attr("path"),F=f.attr("path"),G=0,H=E.length-1;H>G;G++){var I=[];I.push(["M",E[G][1],E[G][2]]),I.push(["L",E[G+1][1],E[G+1][2]]);for(var J=I[0][1],K=I[0][2],L=I[1][1],M=I[1][2],N=0,O=F.length-1;O>N;N++){var P=[];P.push(["M",F[N][1],F[N][2]]),P.push(["L",F[N+1][1],F[N+1][2]]);var Q=P[0][1],R=P[0][2],S=P[1][1],T=P[1][2],U=e(J,K,L,M,Q,R,S,T);if(U.onLine1&&U.onLine2){var V;R===T?Q>S?(V=["L",U.x+2*y,R],F.splice(N+1,0,V),V=["C",U.x+2*y,R,U.x,R-4*y,U.x-2*y,R],F.splice(N+2,0,V),f.attr("path",F)):(V=["L",U.x-2*y,R],F.splice(N+1,0,V),V=["C",U.x-2*y,R,U.x,R-4*y,U.x+2*y,R],F.splice(N+2,0,V),f.attr("path",F)):R>T?(V=["L",Q,U.y+2*y],F.splice(N+1,0,V),V=["C",Q,U.y+2*y,Q+4*y,U.y,Q,U.y-2*y],F.splice(N+2,0,V),f.attr("path",F)):(V=["L",Q,U.y-2*y],F.splice(N+1,0,V),V=["C",Q,U.y-2*y,Q+4*y,U.y,Q,U.y+2*y],F.splice(N+2,0,V),f.attr("path",F)),N+=2,C+=2}}}this.chart.lines.push(f)}(!this.chart.maxXFromLine||this.chart.maxXFromLine&&w>this.chart.maxXFromLine)&&(this.chart.maxXFromLine=w)},r.inherits(h,g),r.inherits(i,g),r.inherits(j,g),r.inherits(k,g),r.inherits(l,g),l.prototype.getLeft=function(){var a=this.getY()+this.group.getBBox().height/2,b=this.getX()+this.textMargin;return{x:b,y:a}},l.prototype.getRight=function(){var a=this.getY()+this.group.getBBox().height/2,b=this.getX()+this.group.getBBox().width-this.textMargin;return{x:b,y:a}},r.inherits(m,g),m.prototype.render=function(){this.yes_direction&&(this[this.yes_direction+"_symbol"]=this.yes_symbol),this.no_direction&&(this[this.no_direction+"_symbol"]=this.no_symbol);var a=this.getAttr("line-length");if(this.bottom_symbol){{var b=this.getBottom();this.bottom_symbol.getTop()}this.bottom_symbol.isPositioned||(this.bottom_symbol.shiftY(this.getY()+this.height+a),this.bottom_symbol.setX(b.x-this.bottom_symbol.width/2),this.bottom_symbol.isPositioned=!0,this.bottom_symbol.render())}if(this.right_symbol){{var c=this.getRight();this.right_symbol.getLeft()}if(!this.right_symbol.isPositioned){this.right_symbol.setY(c.y-this.right_symbol.height/2),this.right_symbol.shiftX(this.group.getBBox().x+this.width+a);var d=this;!function e(){for(var b,c=!1,f=0,g=d.chart.symbols.length;g>f;f++){b=d.chart.symbols[f];var h=Math.abs(b.getCenter().x-d.right_symbol.getCenter().x);if(b.getCenter().y>d.right_symbol.getCenter().y&&h<=d.right_symbol.width/2){c=!0;break}}c&&(d.right_symbol.setX(b.getX()+b.width+a),e())}(),this.right_symbol.isPositioned=!0,this.right_symbol.render()}}},m.prototype.renderLines=function(){this.yes_symbol&&this.drawLineTo(this.yes_symbol,this.getAttr("yes-text"),this.yes_direction),this.no_symbol&&this.drawLineTo(this.no_symbol,this.getAttr("no-text"),this.no_direction)},p.parse=n}(); \ No newline at end of file -- cgit v1.2.3