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

97.5% Statements 78/80
90.48% Branches 57/63
100% Functions 16/16
97.4% Lines 75/77
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          94325× 94325× 94325× 94325× 94325× 94325× 94325×     726460×     228813× 67968× 67968×           36434× 36434× 1122× 1121× 1121×     36434× 36434×   242373× 66430×   175943×   69971×   242373× 1169×   241204×       241204×   242373× 242373× 242373×   238823× 68320× 68320× 68320× 46650×     238823× 238823× 238823× 238823×   71191× 71191× 71191× 71191× 71191× 71191× 46222× 46222× 46222×   71191× 71191× 71191× 71191×         71191× 71191×        
/* 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", "./diagram-element", "../../primitives/rect", "./../../utility/dom-util", "../../utility/path-util"], function (require, exports, size_1, diagram_element_1, rect_1, dom_util_1, path_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PathElement = (function (_super) {
        __extends(PathElement, _super);
        function PathElement() {
            var _this = _super.call(this) || this;
            _this.pathData = '';
            _this.transformPath = true;
            _this.absolutePath = '';
            _this.canMeasurePath = false;
            _this.absoluteBounds = new rect_1.Rect();
            return _this;
        }
        Object.defineProperty(PathElement.prototype, "data", {
            get: function () {
                return this.pathData;
            },
            set: function (value) {
                if (this.pathData !== value) {
                    this.pathData = value;
                    this.isDirt = true;
                }
            },
            enumerable: true,
            configurable: true
        });
        PathElement.prototype.getPoints = function () {
            var _this = this;
            if (!this.pointTimer) {
                this.pointTimer = setTimeout(function () {
                    _this.points = null;
                    _this.pointTimer = null;
                }, 200);
            }
            this.points = this.points || dom_util_1.findSegmentPoints(this);
            return dom_util_1.translatePoints(this, this.points);
        };
        PathElement.prototype.measure = function (availableSize) {
            if (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) {
                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;
        };
        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);
                if (!this.staticSize) {
                    this.points = null;
                }
            }
            this.actualSize = this.desiredSize;
            this.updateBounds();
            this.isDirt = false;
            return this.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;
    }(diagram_element_1.DiagramElement));
    exports.PathElement = PathElement;
});