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

90.91% Statements 80/88
87.93% Branches 51/58
85.71% Functions 6/7
90.91% Lines 80/88
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   1307×   124× 124× 99× 100× 100× 100× 100× 75×   100×   100× 20×   100× 75×   100×   100× 75×         100×   100× 75×     100× 75×     100×   100× 75×         100× 100× 75×     71×     100× 100× 100× 100× 100× 100× 75×   100×     100×     100× 75×     100× 75×   75×       100× 100× 100× 100× 100× 75×   100×     124×   100× 100× 75×   100× 75×   100× 75×   100×   75× 75×     75×     75×     75×     75×            
define(["require", "exports", "../enum/enum"], function (require, exports, enum_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var LabelProperties = (function () {
        function LabelProperties(modelProperties) {
            this.modelProperties = modelProperties;
        }
        LabelProperties.prototype.setLabelProperties = function (oldLabels, item) {
            var labelCollection = [];
            if (oldLabels.length > 0) {
                for (var i = 0; i < oldLabels.length; i++) {
                    var label = oldLabels[parseInt(i.toString(), 10)];
                    var newLabel = {};
                    (newLabel).style = {};
                    if (label.name) {
                        newLabel.id = label.name;
                    }
                    if (label.addInfo) {
                        newLabel.addInfo = label.addInfo;
                    }
                    if (label.text) {
                        newLabel.content = label.text;
                    }
                    if (label.constraints) {
                        newLabel.constraints = this.setLabelConstraints(label.constraints);
                    }
                    if (label.readOnly) {
                        newLabel.constraints = newLabel.constraints | enum_1.AnnotationConstraints.ReadOnly;
                    }
                    if (label.dragLimit) {
                        newLabel.dragLimit = {
                            left: label.dragLimit.left, right: label.dragLimit.right,
                            top: label.dragLimit.top, bottom: label.dragLimit.bottom
                        };
                    }
                    if (label.height) {
                        newLabel.height = label.height;
                    }
                    if (label.horizontalAlignment) {
                        newLabel.horizontalAlignment = label.horizontalAlignment.charAt(0).toUpperCase() +
                            label.horizontalAlignment.slice(1).toLowerCase();
                    }
                    if (label.verticalAlignment) {
                        newLabel.verticalAlignment = label.verticalAlignment.charAt(0).toUpperCase() +
                            label.verticalAlignment.slice(1).toLowerCase();
                    }
                    if (label.hyperlink) {
                        newLabel.hyperlink = { link: label.hyperlink, color: 'blue' };
                    }
                    if (label.margin) {
                        newLabel.margin = {
                            left: label.margin.left, right: label.margin.right,
                            top: label.margin.top, bottom: label.margin.bottom
                        };
                    }
                    newLabel.rotateAngle = label.rotateAngle;
                    if (label.offset) {
                        if (item) {
                            newLabel.offset = label.offset.x;
                        }
                        else {
                            newLabel.offset = { x: label.offset.x, y: label.offset.y };
                        }
                    }
                    newLabel.style.color = label.fontColor;
                    newLabel.style.fontFamily = label.fontFamily;
                    newLabel.style.fontSize = label.fontSize;
                    newLabel.style.italic = label.italic;
                    newLabel.style.bold = label.bold;
                    if (label.borderColor) {
                        newLabel.style.strokeColor = label.borderColor;
                    }
                    Iif (label.borderWidth) {
                        newLabel.style.strokeWidth = label.borderWidth;
                    }
                    Iif (label.textWrapping) {
                        newLabel.style.textWrapping = label.textWrapping;
                    }
                    if (label.textAlign) {
                        newLabel.style.textAlign = label.textAlign.charAt(0).toUpperCase() +
                            label.textAlign.slice(1).toLowerCase();
                    }
                    if (label.textDecoration) {
                        newLabel.style.textDecoration = label.textDecoration.charAt(0).toUpperCase() +
                            label.textDecoration.slice(1).toLowerCase();
                        Iif (newLabel.style.textDecoration === 'Linethrough') {
                            newLabel.style.textDecoration = 'LineThrough';
                        }
                    }
                    var appearance = this.setLabelAppearance(newLabel, label);
                    newLabel.style.fill = appearance.fill;
                    newLabel.style.opacity = appearance.opacity;
                    newLabel.visibility = appearance.visibility;
                    if (label.width) {
                        newLabel.width = label.width;
                    }
                    labelCollection.push(newLabel);
                }
            }
            return labelCollection;
        };
        LabelProperties.prototype.setLabelAppearance = function (newLabel, label) {
            var appearance = {};
            if (label.fillColor) {
                appearance.fill = label.fillColor === 'white' ? 'transparent' : label.fillColor;
            }
            if (label.opacity) {
                appearance.opacity = label.opacity;
            }
            if (label.visible) {
                appearance.visibility = label.visible;
            }
            return appearance;
        };
        LabelProperties.prototype.setLabelConstraints = function (constraints) {
            var annotationConstraints = enum_1.AnnotationConstraints.None;
            Iif (constraints & enum_1.AnnotationConstraints.Select) {
                annotationConstraints = annotationConstraints | enum_1.AnnotationConstraints.Select;
            }
            Iif (constraints & enum_1.AnnotationConstraints.Drag) {
                annotationConstraints = annotationConstraints | enum_1.AnnotationConstraints.Drag;
            }
            Iif (constraints & enum_1.AnnotationConstraints.Resize) {
                annotationConstraints = annotationConstraints | enum_1.AnnotationConstraints.Resize;
            }
            Iif (constraints & enum_1.AnnotationConstraints.Rotate) {
                annotationConstraints = annotationConstraints | enum_1.AnnotationConstraints.Rotate;
            }
            return annotationConstraints;
        };
        LabelProperties.prototype.getModuleName = function () {
            return 'LabelProperties';
        };
        return LabelProperties;
    }());
    exports.LabelProperties = LabelProperties;
});