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

95.83% Statements 69/72
83.05% Branches 49/59
100% Functions 14/14
95.65% Lines 66/69
11 statements, 6 functions, 9 branches Ignored     
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                      45×       45×       45×       45×   45×     45× 45×           116×           37× 35× 35×                     43×     43×     42×   43× 12×   31×       31×   43× 43× 43×           43× 42× 42× 42× 42×     43× 43× 43× 43×               42× 42× 42× 42× 42× 42× 32× 32× 32×   42× 42× 42× 42×         42× 42×        
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../../primitives/size", "./drawing-element", "../../primitives/rect", "./../../utility/dom-util", "../../utility/path-util"], function (require, exports, size_1, drawing_element_1, rect_1, dom_util_1, path_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**
     * PathElement takes care of how to align the path based on offsetX and offsetY
     */
    var PathElement = /** @class */ (function (_super) {
        __extends(PathElement, _super);
        /**
         * set the id for each element
         */
        function PathElement() {
            var _this = _super.call(this) || this;
            /**
             * Gets or sets the geometry of the path element
             */
            _this.pathData = '';
            /**
             * Gets/Sets whether the path has to be transformed to fit the given x,y, width, height
             */
            _this.transformPath = true;
            /**
             * Gets/Sets the equivalent path, that will have the origin as 0,0
             */
            _this.absolutePath = '';
            /**   @private  */
            _this.canMeasurePath = false;
            //Private variables
            /**   @private  */
            _this.absoluteBounds = new rect_1.Rect();
            return _this;
        }
        Object.defineProperty(PathElement.prototype, "data", {
            /**
             * Gets the geometry of the path element
             */
            get: function () {
                return this.pathData;
            },
            /**
             * Sets the geometry of the path element
             */
            set: function (value) {
                if (this.pathData !== value) {
                    this.pathData = value;
                    this.isDirt = true;
                }
            },
            enumerable: true,
            configurable: true
        });
        /**
         * Measures the minimum space that is required to render the element
         * @param availableSize
         */
        PathElement.prototype.measure = function (availableSize) {
            //Performance issue - Avoiding measuring the connector path
            Iif (this.staticSize && this.width !== undefined && this.height !== undefined) {
                this.absoluteBounds = new rect_1.Rect(this.offsetX - this.width * this.pivot.x, this.offsetY - this.height * this.pivot.y, this.width, this.height);
            }
            else if (this.isDirt && (this.transformPath || (this.width === undefined || this.height === undefined))
                && (!this.absoluteBounds || this.absoluteBounds.height === 0) || this.canMeasurePath) {
                //Measure the element only whent the path data is changed/ size is not specified
                this.absoluteBounds = dom_util_1.measurePath(this.data ? this.data : '');
            }
            if (this.width === undefined) {
                this.desiredSize = new size_1.Size(this.absoluteBounds.width, this.height || this.absoluteBounds.height);
            }
            else Iif (this.height === undefined) {
                this.desiredSize = new size_1.Size(this.width || this.absoluteBounds.width, this.absoluteBounds.height);
            }
            else {
                this.desiredSize = new size_1.Size(this.width, this.height);
            }
            this.desiredSize = this.validateDesiredSize(this.desiredSize, availableSize);
            this.canMeasurePath = false;
            return this.desiredSize;
        };
        /**
         * Arranges the path element
         * @param desiredSize
         */
        PathElement.prototype.arrange = function (desiredSize) {
            if (this.isDirt || this.actualSize.width !== desiredSize.width || this.actualSize.height !== desiredSize.height) {
                this.isDirt = true;
                this.absolutePath = this.updatePath(this.data, this.absoluteBounds, desiredSize);
                Eif (!this.staticSize) {
                    this.points = null;
                }
            }
            this.actualSize = this.desiredSize;
            this.updateBounds();
            this.isDirt = false;
            return this.actualSize;
        };
        /**
         * Translates the path to 0,0 and scales the path based on the actual size
         * @param pathData
         * @param bounds
         * @param actualSize
         */
        PathElement.prototype.updatePath = function (pathData, bounds, actualSize) {
            var isScale = false;
            var newPathString = '';
            var scaleX = -bounds.x;
            var scaleY = -bounds.y;
            var arrayCollection = [];
            if (actualSize.width !== bounds.width || actualSize.height !== bounds.height) {
                scaleX = actualSize.width / Number(bounds.width ? bounds.width : 1);
                scaleY = actualSize.height / Number(bounds.height ? bounds.height : 1);
                isScale = true;
            }
            arrayCollection = path_util_1.processPathData(pathData);
            arrayCollection = path_util_1.splitArrayCollection(arrayCollection);
            Eif ((isScale || this.isDirt) && this.transformPath) {
                newPathString = path_util_1.transformPath(arrayCollection, scaleX, scaleY, isScale, bounds.x, bounds.y, 0, 0);
            }
            else {
                newPathString = path_util_1.getPathString(arrayCollection);
            }
            isScale = false;
            return newPathString;
        };
        return PathElement;
    }(drawing_element_1.DrawingElement));
    exports.PathElement = PathElement;
});