all files / diagram/load-utility/ connectorProperties.js

98.04% Statements 150/153
93.22% Branches 110/118
90.91% Functions 10/11
98.04% Lines 150/153
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268   1307×   16× 16× 16× 24× 24× 24×   16×   49× 49× 49× 24×   49× 24×   49× 24×   49× 24×   49×   49× 24×   49× 49×   49× 24×   49×   49× 24×   49× 24×   49×   49× 47× 47×   49×   49× 24×                       49× 49×                       49× 12×   49× 12×   49× 24×   49× 24×   49×   49×   49×         49× 24×   49× 23×   49×                                                                 73× 73×     71×   73×   47× 47× 47× 48× 48× 48× 48× 48× 48× 48× 48× 48× 48× 25×   48× 48×   48×     47×   25× 25× 25× 64× 64× 64× 64× 64×     25×   24× 24× 23×   24× 23×   24× 23×   24× 23×   24× 23×   24× 23×   24×     24×   24×   24×     24× 23×   24× 23×   24× 23×   24× 23×   24×            
define(["require", "exports", "../enum/enum"], function (require, exports, enum_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ConnectorProperties = (function () {
        function ConnectorProperties(labelProperties) {
            this.labelProperties = labelProperties;
        }
        ConnectorProperties.prototype.renderConnectorsCollection = function (convertedData, data) {
            convertedData.connectors = [];
            var connectors = [];
            for (var i = 0; i < data.connectors.length; i++) {
                var connector = data.connectors[parseInt(i.toString(), 10)];
                var newConnector = this.convertToConnector(connector);
                connectors.push(newConnector);
            }
            convertedData.connectors = connectors;
        };
        ConnectorProperties.prototype.convertToConnector = function (connector) {
            var newConnector = {};
            newConnector.style = {};
            if (connector.name) {
                newConnector.id = connector.name;
            }
            if (connector.addInfo) {
                newConnector.addInfo = connector.addInfo;
            }
            if (connector.bridgeSpace) {
                newConnector.bridgeSpace = connector.bridgeSpace;
            }
            if (connector.constraints) {
                newConnector.constraints = this.setConnectorConstraints(connector.constraints);
            }
            if (connector.cornerRadius) {
                newConnector.cornerRadius = connector.cornerRadius;
            }
            if (connector.labels) {
                newConnector.annotations = this.labelProperties.setLabelProperties(connector.labels, connector);
            }
            Eif (connector.lineColor) {
                newConnector.style.fill = connector.lineColor;
            }
            if (connector.lineWidth) {
                newConnector.style.strokeWidth = connector.lineWidth;
            }
            if (connector.lineDashArray) {
                newConnector.style.strokeDashArray = connector.lineDashArray;
            }
            if (connector.opacity) {
                newConnector.style.opacity = connector.opacity;
            }
            if (connector.lineHitPadding) {
                newConnector.hitPadding = connector.lineHitPadding;
            }
            if (connector.margin) {
                newConnector.margin = { left: connector.margin.left, right: connector.margin.right, top: connector.margin.top, bottom: connector.margin.bottom };
            }
            if (connector.segments) {
                newConnector.type = connector.segments[0].type.charAt(0).toUpperCase() + (connector.segments[0].type).slice(1);
                newConnector.segments = this.setConnectorSegments(connector.segments);
            }
            if (connector.shape) {
                newConnector.shape = this.getConnectorShape(connector.shape);
            }
            if (connector.sourceDecorator) {
                newConnector.sourceDecorator = {
                    height: connector.sourceDecorator.height,
                    width: connector.sourceDecorator.width,
                    shape: (this.getDecoratorShape(connector.sourceDecorator.shape)),
                    pathData: connector.sourceDecorator.pathData,
                    style: {
                        fill: connector.sourceDecorator.fillColor,
                        strokeColor: connector.sourceDecorator.lineColor,
                        strokeWidth: connector.sourceDecorator.lineWidth
                    }
                };
            }
            Eif (connector.targetDecorator) {
                newConnector.targetDecorator = {
                    height: connector.targetDecorator.height,
                    width: connector.targetDecorator.width,
                    shape: this.getDecoratorShape(connector.targetDecorator.shape),
                    pathData: connector.targetDecorator.pathData,
                    style: {
                        fill: connector.targetDecorator.fillColor,
                        strokeColor: connector.targetDecorator.lineColor,
                        strokeWidth: connector.targetDecorator.lineWidth
                    }
                };
            }
            if (connector.sourceNode) {
                newConnector.sourceID = connector.sourceNode;
            }
            if (connector.targetNode) {
                newConnector.targetID = connector.targetNode;
            }
            if (connector.sourcePoint) {
                newConnector.sourcePoint = { x: connector.sourcePoint.x, y: connector.sourcePoint.y };
            }
            if (connector.targetPoint) {
                newConnector.targetPoint = { x: connector.targetPoint.x, y: connector.targetPoint.y };
            }
            if (connector.sourcePort) {
                newConnector.sourcePortID = connector.sourcePort;
            }
            if (connector.targetPort) {
                newConnector.targetPortID = connector.targetPort;
            }
            if (connector.tooltip) {
                newConnector.tooltip = {
                    content: connector.tooltip.content,
                    relativeMode: connector.tooltip.relativeMode
                };
            }
            if (connector.visible) {
                newConnector.visible = connector.visible;
            }
            if (connector.zOrder) {
                newConnector.zIndex = connector.zOrder;
            }
            return newConnector;
        };
        ConnectorProperties.prototype.getConnectorShape = function (shape) {
            var connectorShape = null;
            Eif (shape) {
                if (shape.type === 'bpmn') {
                    connectorShape = {
                        type: 'Bpmn',
                        flow: (shape.flow).charAt(0).toUpperCase() + (shape.flow).slice(1)
                    };
                    if (shape.flow === 'sequence') {
                        connectorShape.sequence = (shape.sequence).charAt(0).toUpperCase() + (shape.sequence).slice(1);
                    }
                    else if (shape.flow === 'association') {
                        connectorShape.association = (shape.association).charAt(0).toUpperCase() + (shape.association).slice(1);
                    }
                    else {
                        connectorShape.message = (shape.message).charAt(0).toUpperCase() + (shape.message).slice(1);
                    }
                }
                if (shape.type === 'umlclassifier') {
                    connectorShape = {
                        type: 'UmlClassifier',
                        relationship: (shape.relationship).charAt(0).toUpperCase() + (shape.relationship).slice(1),
                        multiplicity: {
                            type: (shape.multiplicity.type).charAt(0).toUpperCase() + (shape.multiplicity.type).slice(1),
                            source: {
                                upperBounds: shape.multiplicity.source.upperBounds,
                                optional: shape.multiplicity.source.optional,
                                lowerBounds: shape.multiplicity.source.lowerBounds
                            },
                            target: {
                                upperBounds: shape.multiplicity.target.upperBounds,
                                optional: shape.multiplicity.target.optional,
                                lowerBounds: shape.multiplicity.target.lowerBounds
                            }
                        }
                    };
                }
                if (shape.type === 'umlactivity') {
                    connectorShape = {
                        type: 'UmlActivity',
                        flow: (shape.flow).charAt(0).toUpperCase() + (shape.flow).slice(1)
                    };
                }
            }
            return connectorShape;
        };
        ConnectorProperties.prototype.getDecoratorShape = function (shape) {
            var decoratorShape = 'None';
            if (shape === 'path') {
                decoratorShape = 'Custom';
            }
            else {
                decoratorShape = (shape).charAt(0).toUpperCase() + (shape).slice(1);
            }
            return decoratorShape;
        };
        ConnectorProperties.prototype.setConnectorSegments = function (segments) {
            var connectorSegments = [];
            Eif (segments.length > 0) {
                for (var i = 0; i < segments.length; i++) {
                    var segment = {};
                    var segmentProp = segments[parseInt(i.toString(), 10)];
                    segment.direction = segmentProp.direction ? segmentProp.direction.charAt(0).toUpperCase() + segmentProp.direction.slice(1) : segmentProp._direction ? segmentProp._direction.charAt(0).toUpperCase() + segmentProp._direction.slice(1) : null;
                    segment.length = segmentProp.length ? segmentProp.length : segmentProp._length ? segmentProp._length : null;
                    segment.point = segmentProp.point ? { x: segmentProp.point.x, y: segmentProp.point.y } : null;
                    segment.point1 = segmentProp.point1 ? { x: segmentProp.point1.x, y: segmentProp.point1.y } : null;
                    segment.point2 = segmentProp.point2 ? { x: segmentProp.point2.x, y: segmentProp.point2.y } : null;
                    segment.vector1 = segmentProp.vector1 ? { angle: segmentProp.vector1.angle, distance: segmentProp.vector1.distance } : null;
                    segment.vector2 = segmentProp.vector2 ? { angle: segmentProp.vector2.angle, distance: segmentProp.vector2.distance } : null;
                    if (segmentProp.points) {
                        segment.points = this.getSegmentPoints(segmentProp.points);
                    }
                    Eif (segmentProp.type) {
                        segment.type = (segmentProp.type).charAt(0).toUpperCase() + (segmentProp.type).slice(1);
                    }
                    connectorSegments.push(segment);
                }
            }
            return connectorSegments;
        };
        ConnectorProperties.prototype.getSegmentPoints = function (points) {
            var pointsCollection = [];
            Eif (points.length > 0) {
                for (var i = 0; i < points.length; i++) {
                    var newPoint = {};
                    var point = points[parseInt(i.toString(), 10)];
                    newPoint.x = point.x;
                    newPoint.y = point.y;
                    pointsCollection.push(newPoint);
                }
            }
            return pointsCollection;
        };
        ConnectorProperties.prototype.setConnectorConstraints = function (constraints) {
            var connectorConstraints = enum_1.ConnectorConstraints.None;
            if (constraints & enum_1.ConnectorConstraints.Select) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.Select;
            }
            if (constraints & enum_1.ConnectorConstraints.Delete) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.Delete;
            }
            if (constraints & enum_1.ConnectorConstraints.Drag) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.Drag;
            }
            if (constraints & enum_1.ConnectorConstraints.DragSourceEnd) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.DragSourceEnd;
            }
            if (constraints & enum_1.ConnectorConstraints.DragTargetEnd) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.DragTargetEnd;
            }
            if (constraints & enum_1.ConnectorConstraints.DragSegmentThumb) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.DragSegmentThumb;
            }
            Iif (constraints & enum_1.ConnectorConstraints.Bridging) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.Bridging;
            }
            if (constraints & enum_1.ConnectorConstraints.InheritBridging) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.InheritBridging;
            }
            if (constraints & enum_1.ConnectorConstraints.AllowDrop) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.AllowDrop;
            }
            Iif (constraints & enum_1.ConnectorConstraints.InheritTooltip) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.InheritTooltip;
            }
            if (constraints & enum_1.ConnectorConstraints.PointerEvents) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.PointerEvents;
            }
            if (constraints & enum_1.ConnectorConstraints.BridgeObstacle) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.BridgeObstacle;
            }
            if (constraints & enum_1.ConnectorConstraints.Interaction) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.Interaction;
            }
            if (constraints & enum_1.ConnectorConstraints.Default) {
                connectorConstraints = connectorConstraints | enum_1.ConnectorConstraints.Default;
            }
            return connectorConstraints;
        };
        ConnectorProperties.prototype.getModuleName = function () {
            return 'ConnectorProperties';
        };
        return ConnectorProperties;
    }());
    exports.ConnectorProperties = ConnectorProperties;
});