all files / diagram/core/elements/ diagram-element.js

100% Statements 97/97
100% Branches 61/61
100% Functions 11/11
100% Lines 97/97
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   198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751× 198751×   32039× 32039×   225547× 131468× 6352×     125116×         94079×     1370588×     160856×         99147× 99147× 99147× 98598× 167×     99147× 99147× 47478×   99147×   57504× 57504× 57504×   511007×   605885× 4646×   605885× 3944×   605885×   398662× 398662×   398662×     605885× 45590×   605885× 46321×   605885× 13579×   605885× 536×   605885×        
define(["require", "exports", "../../enum/enum", "../../primitives/size", "../../primitives/rect", "../../utility/base-util"], function (require, exports, enum_1, size_1, rect_1, base_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DiagramElement = (function () {
        function DiagramElement() {
            this.pivot = { x: 0.5, y: 0.5 };
            this.isDirt = true;
            this.isExport = false;
            this.exportScaleValue = { x: 0, y: 0 };
            this.exportScaleOffset = { x: 0, y: 0 };
            this.canApplyStyle = true;
            this.visible = true;
            this.offsetX = 0;
            this.offsetY = 0;
            this.cornerRadius = 0;
            this.minHeight = undefined;
            this.minWidth = undefined;
            this.maxWidth = undefined;
            this.maxHeight = undefined;
            this.width = undefined;
            this.height = undefined;
            this.rotateAngle = 0;
            this.margin = { left: 0, right: 0, top: 0, bottom: 0 };
            this.connectionDirection = 'Auto';
            this.horizontalAlignment = 'Auto';
            this.verticalAlignment = 'Auto';
            this.flip = 'None';
            this.flipMode = 'All';
            this.relativeMode = 'Point';
            this.transform = enum_1.Transform.Self | enum_1.Transform.Parent;
            this.style = { fill: 'white', strokeColor: 'black', opacity: 1, strokeWidth: 1 };
            this.desiredSize = new size_1.Size();
            this.actualSize = new size_1.Size();
            this.parentTransform = 0;
            this.preventContainer = false;
            this.isSvgRender = false;
            this.bounds = new rect_1.Rect(0, 0, 0, 0);
            this.shadow = null;
            this.description = '';
            this.staticSize = false;
            this.shapeType = '';
            this.isRectElement = false;
            this.isCalculateDesiredSize = true;
            this.flipOffset = { x: 0, y: 0 };
            this.elementActions = enum_1.ElementAction.None;
            this.inversedAlignment = true;
            this.position = undefined;
            this.unitMode = undefined;
            this.float = false;
            this.floatingBounds = undefined;
        }
        DiagramElement.prototype.setOffsetWithRespectToBounds = function (x, y, mode) {
            this.unitMode = mode;
            this.position = { x: x, y: y };
        };
        DiagramElement.prototype.getAbsolutePosition = function (size) {
            if (this.position !== undefined) {
                if (this.unitMode === 'Absolute') {
                    return this.position;
                }
                else {
                    return {
                        x: this.position.x * size.width, y: this.position.y * size.height
                    };
                }
            }
            return undefined;
        };
        Object.defineProperty(DiagramElement.prototype, "outerBounds", {
            get: function () {
                return this.floatingBounds || this.bounds;
            },
            set: function (bounds) {
                this.floatingBounds = bounds;
            },
            enumerable: true,
            configurable: true
        });
        DiagramElement.prototype.measure = function (availableSize, obj, callback) {
            var width = this.width !== undefined ? this.width : (availableSize.width || 0) - this.margin.left - this.margin.right;
            var height = this.height !== undefined ? this.height : (availableSize.height || 0) - this.margin.top - this.margin.bottom;
            if (this.id) {
                if (height === 0 && (this.elementActions & enum_1.ElementAction.HorizontalLaneHeader)) {
                    height = this.actualSize.height;
                }
            }
            this.desiredSize = new size_1.Size(width, height);
            if (this.isCalculateDesiredSize) {
                this.desiredSize = this.validateDesiredSize(this.desiredSize, availableSize);
            }
            return this.desiredSize;
        };
        DiagramElement.prototype.arrange = function (desiredSize) {
            this.actualSize = desiredSize;
            this.updateBounds();
            return this.actualSize;
        };
        DiagramElement.prototype.updateBounds = function () {
            this.bounds = base_util_1.getBounds(this);
        };
        DiagramElement.prototype.validateDesiredSize = function (desiredSize, availableSize) {
            if (this.isRectElement && !this.width && !this.minWidth && !this.maxWidth) {
                desiredSize.width = 50;
            }
            if (this.isRectElement && !this.height && !this.minHeight && !this.maxHeight) {
                desiredSize.height = 50;
            }
            if (desiredSize === undefined || this.width !== undefined &&
                this.height !== undefined) {
                desiredSize = desiredSize || new size_1.Size();
                desiredSize.width = this.width === undefined ? (availableSize.width || 0)
                    - this.margin.left - this.margin.right : this.width;
                desiredSize.height = this.height === undefined ? (availableSize.height || 0)
                    - this.margin.top - this.margin.bottom : this.height;
            }
            if (this.minWidth !== undefined) {
                desiredSize.width = Math.max(desiredSize.width, this.minWidth);
            }
            if (this.minHeight !== undefined) {
                desiredSize.height = Math.max(desiredSize.height, this.minHeight);
            }
            if (this.maxWidth !== undefined && this.maxWidth !== 0) {
                desiredSize.width = Math.min(desiredSize.width, this.maxWidth);
            }
            if (this.maxHeight !== undefined && this.maxHeight !== 0) {
                desiredSize.height = Math.min(desiredSize.height, this.maxHeight);
            }
            return desiredSize;
        };
        return DiagramElement;
    }());
    exports.DiagramElement = DiagramElement;
});