all files / diagram/entity-relationship/ er-connector-renderer.js

100% Statements 53/53
90% Branches 36/40
100% Functions 9/9
100% Lines 53/53
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     82×   81× 81× 81× 81×   192×                                             83× 83× 83×   192×               192×   122×   32×                    
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ErConnectorRenderer = (function () {
        function ErConnectorRenderer() {
        }
        ErConnectorRenderer.prototype.render = function (connector) {
            if (!connector.shape || connector.shape.type !== 'Er') {
                return;
            }
            var erConnector = connector.shape;
            this.applyRelationshipStyle(connector);
            connector.sourceDecorator = this.getDecoratorForCardinality(erConnector.sourceMultiplicity);
            connector.targetDecorator = this.getDecoratorForCardinality(erConnector.targetMultiplicity);
        };
        ErConnectorRenderer.prototype.getDecoratorForCardinality = function (cardinality) {
            return {
                shape: 'Custom',
                width: 14,
                height: 14,
                pivot: { x: 0, y: 0.5 },
                pathData: this.getPath(cardinality.type),
                style: {
                    fill: 'transparent'
                }
            };
        };
        ErConnectorRenderer.prototype.update = function (connector, erRelationship, oldRelationship, diagram) {
            var hasCardinalityChanged = ((erRelationship.sourceMultiplicity && oldRelationship.sourceMultiplicity &&
                erRelationship.sourceMultiplicity.type !== oldRelationship.sourceMultiplicity.type) ||
                (erRelationship.targetMultiplicity && oldRelationship.targetMultiplicity &&
                    erRelationship.targetMultiplicity.type !== oldRelationship.targetMultiplicity.type));
            var hasTypeChanged = erRelationship.relationship !== oldRelationship.relationship;
            if (!hasCardinalityChanged && !hasTypeChanged) {
                return false;
            }
            if (hasCardinalityChanged) {
                this.updateDecorators(connector);
            }
            if (hasTypeChanged) {
                this.applyRelationshipStyle(connector);
            }
            return true;
        };
        ErConnectorRenderer.prototype.updateDecorators = function (connector) {
            var erConnector = connector.shape;
            var newSourceDecorator = this.getDecoratorForCardinality(erConnector.sourceMultiplicity);
            var newTargetDecorator = this.getDecoratorForCardinality(erConnector.targetMultiplicity);
            connector.sourceDecorator = newSourceDecorator;
            connector.targetDecorator = newTargetDecorator;
            var points = connector.intermediatePoints;
            Eif (connector.wrapper && connector.wrapper.children && connector.wrapper.children.length > 2 &&
                points && points.length > 1) {
                var srcElement = connector.wrapper.children[1];
                var tarElement = connector.wrapper.children[2];
                Eif (srcElement) {
                    connector.updateDecoratorElement(srcElement, points[0], points[1], newSourceDecorator);
                }
                Eif (tarElement) {
                    connector.updateDecoratorElement(tarElement, points[points.length - 1], points[points.length - 2], newTargetDecorator);
                }
            }
        };
        ErConnectorRenderer.prototype.applyRelationshipStyle = function (connector) {
            var erConnector = connector.shape;
            connector.style = connector.style || {};
            connector.style.strokeDashArray = erConnector.relationship === 'Identifying' ? '' : '5,5';
        };
        ErConnectorRenderer.prototype.getPath = function (cardinality) {
            var ER_PATHS = {
                ONE: 'M7.5 0V5.5M7.5 11V5.5M7.5 5.5H0',
                MANY: 'M1.19067 11.3932L8.19067 5.89319L1.19067 0.393188M8.19067 5.89319H0.69067',
                ONE_ONLY: 'M8.5 0V5.5M8.5 11V5.5M4.5 0V11M8.5 5.5H0',
                ONE_MANY: 'M0.5 0.393188L7.5 5.89319M0.5 11.3932L7.5 5.89319M7.5 5.89319V0.393188M7.5 5.89319V11.3932M7.5 5.89319H0',
                ZERO_ONE: 'M5 0V5.5M5 5.5V11M5 5.5H10.5M5 5.5H0.5M10.5 5.5C10.5 8.26142 12.7386 10.5 15.5 10.5C18.2614 10.5 20.5 8.26142 20.5 5.5C20.5 2.73858 18.2614 0.5 15.5 0.5C12.7386 0.5 10.5 2.73858 10.5 5.5Z',
                ZERO_MANY: 'M0.5 0.393188L7.5 5.89319M7.5 5.89319L0.5 11.3932M7.5 5.89319H0M7.5 5.89319C7.5 8.65461 9.73858 10.8932 12.5 10.8932C15.2614 10.8932 17.5 8.65461 17.5 5.89319C17.5 3.13176 15.2614 0.893188 12.5 0.893188C9.73858 0.893188 7.5 3.13176 7.5 5.89319Z'
            };
            switch (cardinality) {
                case 'One':
                    return ER_PATHS.ONE;
                case 'Many':
                    return ER_PATHS.MANY;
                case 'OneAndOnlyOne':
                    return ER_PATHS.ONE_ONLY;
                case 'ZeroOrOne':
                    return ER_PATHS.ZERO_ONE;
                case 'OneOrMany':
                    return ER_PATHS.ONE_MANY;
                case 'ZeroOrMany':
                    return ER_PATHS.ZERO_MANY;
                default:
                    return ER_PATHS.ONE;
            }
        };
        return ErConnectorRenderer;
    }());
    exports.ErConnectorRenderer = ErConnectorRenderer;
});