all files / diagram/rendering/ svg-renderer.js

98.06% Statements 455/464
92.55% Branches 298/322
96.43% Functions 27/28
98.06% Lines 454/463
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721     132× 132× 132× 132× 132× 132× 131×   132× 120× 120× 120×   132×             132× 131× 131× 45×     132× 132× 98×   34× 34×     57× 57×   131170× 98×   131170× 131170×       131170×   131170× 131170× 119850×   131170× 84668× 84668×   131170× 131170× 119753× 119753×     131170× 131170× 33339×                 97831×               131170× 103678× 103678×   131170× 131170× 98035× 203×     131170× 38988×   131170× 131170× 27492×   131170× 131170×   158× 158× 158×           158× 158× 158×   158× 158×   78546× 78546×   5363× 5363× 5363× 5363× 5363×                     5363× 4888×   5363× 5363×   196× 196× 196× 196×     196×               196× 196× 196×   196× 196× 196×   87588× 87588× 87588× 87588× 87588× 34×   87588× 87588× 80971× 80971×     87588× 87588× 81005×   87588× 47754× 47754×   87588× 87588× 87588× 414×             87174×           87588× 84395× 84395×   87588× 7039×   87588× 87588×   87622× 87622× 87622× 87622× 87622× 87622× 87622× 87622× 87622× 87622× 87622× 370223× 370223× 370223× 370223× 93690×   370223× 92707×   370223× 93690×   370223× 92707×   370223× 325955×   370223× 325955×   370223×   67013× 67013×   162465× 162465×   92707× 92707× 92707×   983× 983×   2787× 2787× 2787×     44268× 44268×     87622×   8234× 8234× 8234× 8234×   14141× 14141× 14141× 14141× 14141× 14141× 14141× 14141× 14141× 14141× 14141× 14141× 14141× 14093×   14141× 7820× 1899× 2194×         6321× 6321× 6321× 56×   6321× 6282×   6321× 24× 24× 24×     6297×     14141× 14141× 14141× 14141× 8234× 14×   8234× 8234× 8234× 8234× 8234× 8234× 8234×   8234× 9915× 9915× 9915× 9915× 9915× 300×     9615×   9915× 9915×   117× 117× 108× 21× 21× 21×     108× 108×           9798×       14141×         14141×   14141×           14141× 14139× 14139×   14141×     9906× 9884×     22× 11× 11× 11×     11×       9906× 9884×     22×   9906× 9906× 9906×   254× 254× 244×   254× 253× 253×   254× 254× 254× 254× 254× 254× 252×   254×             254× 254×   219× 219× 219× 219×   219× 148×   148× 143×       143×   148×       148× 148× 148× 148× 14×   148× 14×           14×       134×     134×   127× 125×     148×   148× 148×   219× 219×           137× 137× 137× 137× 137×   137× 92× 92× 92× 92× 92× 92×   137×   137×   137× 137×   137×   137× 137× 137× 137× 137×                         119× 119× 119× 119× 119× 119× 28× 28×   119× 119× 119× 119× 119× 238×   238×     119× 101× 101× 101× 101×     18× 18× 18× 18×   119× 238× 238× 238× 238× 238×     119×   101× 101×     101× 101×   18× 18×     18× 18×   232709× 232709× 6114×   232709× 25677×   232709× 232709× 232709× 18457× 18457×   232709× 119× 119×       119×       232590×   232709× 225238×   232709× 229446×   232709× 232709×   232709× 231298×       8234× 8234× 8234× 8234× 8234× 8234× 8234× 8234× 8234× 276×   7958× 7952× 13×     11×       7939×       8234× 8234× 8234×        
define(["require", "exports", "./../primitives/point", "./../primitives/size", "./../utility/path-util", "./../utility/dom-util", "./../utility/base-util", "./../rendering/canvas-renderer", "../core/elements/native-element", "../utility/dom-util", "../utility/diagram-util"], function (require, exports, point_1, size_1, path_util_1, dom_util_1, base_util_1, canvas_renderer_1, native_element_1, dom_util_2, diagram_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var SvgRenderer = (function () {
        function SvgRenderer() {
        }
        SvgRenderer.prototype.renderShadow = function (options, canvas, collection, parentSvg) {
            if (collection === void 0) { collection = null; }
            var pointModel = { x: 0, y: 0 };
            var point = point_1.Point.transform(pointModel, options.shadow.angle, options.shadow.distance);
            var type;
            var shadowElement;
            if (parentSvg) {
                shadowElement = parentSvg.getElementById(canvas.id + '_shadow');
            }
            if (!shadowElement) {
                type = collection ? 'path' : 'rect';
                shadowElement = document.createElementNS('http://www.w3.org/2000/svg', type);
                canvas.appendChild(shadowElement);
            }
            var attr = {
                'id': canvas.id + '_shadow', 'fill': options.shadow.color, 'stroke': options.shadow.color,
                'opacity': options.shadow.opacity.toString(),
                'transform': 'rotate(' + options.angle + ',' + (options.x + options.width * options.pivotX) + ','
                    + (options.y + options.height * options.pivotY) + ')' +
                    'translate(' + (options.x + point.x) + ',' + (options.y + point.y) + ')'
            };
            if (parentSvg) {
                var svgContainer = parentSvg.getElementById(canvas.id);
                if (svgContainer) {
                    svgContainer.insertBefore(shadowElement, svgContainer.firstChild);
                }
            }
            dom_util_1.setAttributeSvg(shadowElement, attr);
            if (!collection) {
                dom_util_1.setAttributeSvg(shadowElement, { 'width': options.width, 'height': options.height });
            }
            else Eif (collection) {
                this.renderPath(shadowElement, options, collection);
            }
        };
        SvgRenderer.prototype.parseDashArray = function (dashArray) {
            var dashes = [];
            return dashes;
        };
        SvgRenderer.prototype.drawRectangle = function (svg, options, diagramId, onlyRect, isSelector, parentSvg, ariaLabel, isCircularHandle, enableSelector) {
            if (options.shadow && !onlyRect) {
                this.renderShadow(options, svg, undefined, parentSvg);
            }
            var id;
            Iif (options.id === svg.id) {
                id = options.id + '_container';
            }
            else {
                id = options.id;
            }
            var rect;
            if (parentSvg) {
                rect = parentSvg.getElementById(id);
            }
            if (!rect || isSelector) {
                rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
                svg.appendChild(rect);
            }
            var shadowElement;
            if (parentSvg && !options.shadow) {
                shadowElement = parentSvg.getElementById(options.id + '_groupElement_shadow');
                if (shadowElement) {
                    shadowElement.parentNode.removeChild(shadowElement);
                }
            }
            var attr;
            if (isCircularHandle) {
                attr = {
                    'id': id, 'x': options.x.toString(), 'y': options.y.toString(), 'width': options.width.toString(),
                    'height': options.height.toString(), 'visibility': options.visible ? 'visible' : 'hidden',
                    'transform': 'rotate(' + options.angle + ','
                        + (options.x + options.width / 2) + ',' + (options.y + options.height / 2) + ')',
                    'rx': options.cornerRadius || 0, 'ry': options.cornerRadius || 0, 'opacity': options.opacity
                };
            }
            else {
                attr = {
                    'id': id, 'x': options.x.toString(), 'y': options.y.toString(), 'width': options.width.toString(),
                    'height': options.height.toString(), 'visibility': options.visible ? 'visible' : 'hidden',
                    'transform': 'rotate(' + options.angle + ','
                        + (options.x + options.width * options.pivotX) + ',' + (options.y + options.height * options.pivotY) + ')',
                    'rx': options.cornerRadius || 0, 'ry': options.cornerRadius || 0, 'opacity': options.opacity
                };
            }
            if (ariaLabel) {
                attr['role'] = 'img';
                attr['aria-label'] = ariaLabel;
            }
            var classval = options.class || '';
            if (!enableSelector) {
                if (classval.includes('e-diagram-resize-handle') || classval.includes('e-diagram-endpoint-handle') || classval.includes('e-diagram-bezier-control-handle')) {
                    classval += ' e-disabled';
                }
            }
            if (options.class) {
                attr['class'] = classval;
            }
            var poiterEvents = 'pointer-events';
            if (!ariaLabel) {
                attr["" + poiterEvents] = 'none';
            }
            dom_util_1.setAttributeSvg(rect, attr);
            this.setSvgStyle(rect, options, diagramId);
        };
        SvgRenderer.prototype.updateSelectionRegion = function (gElement, options) {
            var rect;
            rect = gElement.parentNode.getElementById(options.id);
            var attr = {
                'id': options.id, 'x': options.x.toString(), 'y': options.y.toString(), 'width': options.width.toString(),
                'height': options.height.toString(), 'transform': 'rotate(' + options.angle + ','
                    + (options.x + options.width * options.pivotX) + ',' + (options.y + options.height * options.pivotY) + ')',
                class: 'e-diagram-selected-region'
            };
            Eif (!rect) {
                rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
                gElement.appendChild(rect);
            }
            this.setSvgStyle(rect, options);
            dom_util_1.setAttributeSvg(rect, attr);
        };
        SvgRenderer.prototype.createGElement = function (elementType, attribute) {
            var gElement = dom_util_2.createSvgElement(elementType, attribute);
            return gElement;
        };
        SvgRenderer.prototype.drawLine = function (gElement, options) {
            var line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
            this.setSvgStyle(line, options);
            var pivotX = options.x + options.width * options.pivotX;
            var pivotY = options.y + options.height * options.pivotY;
            var attr = {
                'id': options.id,
                'x1': options.startPoint.x + options.x,
                'y1': options.startPoint.y + options.y,
                'x2': options.endPoint.x + options.x,
                'y2': options.endPoint.y + options.y,
                'stroke': options.stroke,
                'stroke-width': options.strokeWidth.toString(), 'opacity': options.opacity.toString(),
                'transform': 'rotate(' + options.angle + ' ' + pivotX + ' ' + pivotY + ')',
                'visibility': options.visible ? 'visible' : 'hidden'
            };
            if (options.class) {
                attr['class'] = options.class;
            }
            dom_util_1.setAttributeSvg(line, attr);
            gElement.appendChild(line);
        };
        SvgRenderer.prototype.drawCircle = function (gElement, options, enableSelector, ariaLabel) {
            var circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
            this.setSvgStyle(circle, options);
            var classval = options.class || '';
            Iif (!enableSelector) {
                classval += ' e-disabled';
            }
            var attr = {
                'id': options.id,
                'cx': options.centerX,
                'cy': options.centerY,
                'r': options.radius,
                'visibility': options.visible ? 'visible' : 'hidden',
                'class': classval
            };
            Eif (ariaLabel) {
                attr['role'] = 'img';
                attr['aria-label'] = ariaLabel;
            }
            circle.style.display = options.visible ? 'block' : 'none';
            dom_util_1.setAttributeSvg(circle, attr);
            gElement.appendChild(circle);
        };
        SvgRenderer.prototype.drawPath = function (svg, options, diagramId, isSelector, parentSvg, ariaLabel, scale) {
            var x = Math.floor((Math.random() * 10) + 1);
            var collection = [];
            collection = path_util_1.processPathData(options.data);
            collection = path_util_1.pathSegmentCollection(collection);
            if (options.shadow) {
                this.renderShadow(options, svg, collection, parentSvg);
            }
            var shadowElement;
            if (parentSvg && !options.shadow) {
                shadowElement = parentSvg.getElementById(options.id + '_groupElement_shadow');
                if (shadowElement) {
                    shadowElement.parentNode.removeChild(shadowElement);
                }
            }
            var path;
            if (parentSvg) {
                path = parentSvg.getElementById(options.id);
            }
            if (!path || isSelector) {
                path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
                svg.appendChild(path);
            }
            this.renderPath(path, options, collection);
            var attr = {};
            if (scale) {
                attr = {
                    'id': options.id, 'transform': 'rotate(' + options.angle + ',' + (options.x + options.width * options.pivotX) + ','
                        + (options.y + options.height * options.pivotY) + ')' + 'translate(' + (options.x) + ',' + (options.y) + '),scale(' + scale + ')',
                    'visibility': options.visible ? 'visible' : 'hidden', 'opacity': options.opacity
                };
            }
            else {
                attr = {
                    'id': options.id, 'transform': 'rotate(' + options.angle + ',' + (options.x + options.width * options.pivotX) + ','
                        + (options.y + options.height * options.pivotY) + ')' + 'translate(' + (options.x) + ',' + (options.y) + ')',
                    'visibility': options.visible ? 'visible' : 'hidden', 'opacity': options.opacity
                };
            }
            if (ariaLabel) {
                attr['role'] = 'img';
                attr['aria-label'] = ariaLabel;
            }
            if (options.class) {
                attr['class'] = options.class;
            }
            dom_util_1.setAttributeSvg(path, attr);
            this.setSvgStyle(path, options, diagramId);
        };
        SvgRenderer.prototype.renderPath = function (svg, options, collection) {
            var x1;
            var y1;
            var x2;
            var y2;
            var x;
            var y;
            var length;
            var i;
            var segments = collection;
            var d = '';
            for (x = 0, y = 0, i = 0, length = segments.length; i < length; ++i) {
                var obj = segments[parseInt(i.toString(), 10)];
                var segment = obj;
                var char = segment.command;
                if ('x1' in segment) {
                    x1 = segment.x1;
                }
                if ('x2' in segment) {
                    x2 = segment.x2;
                }
                if ('y1' in segment) {
                    y1 = segment.y1;
                }
                if ('y2' in segment) {
                    y2 = segment.y2;
                }
                if ('x' in segment) {
                    x = segment.x;
                }
                if ('y' in segment) {
                    y = segment.y;
                }
                switch (char) {
                    case 'M':
                        d = d + 'M' + x.toString() + ',' + y.toString() + ' ';
                        break;
                    case 'L':
                        d = d + 'L' + x.toString() + ',' + y.toString() + ' ';
                        break;
                    case 'C':
                        d = d + 'C' + x1.toString() + ',' + y1.toString() + ',' + x2.toString() + ',' + y2.toString() + ',';
                        d += x.toString() + ',' + y.toString() + ' ';
                        break;
                    case 'Q':
                        d = d + 'Q' + x1.toString() + ',' + y1.toString() + ',' + x.toString() + ',' + y.toString() + ' ';
                        break;
                    case 'A':
                        d = d + 'A' + segment.r1.toString() + ',' + segment.r2.toString() + ',' + segment.angle.toString() + ',';
                        d += segment.largeArc.toString() + ',' + segment.sweep + ',' + x.toString() + ',' + y.toString() + ' ';
                        break;
                    case 'Z':
                    case 'z':
                        d = d + 'Z' + ' ';
                        break;
                }
            }
            svg.setAttribute('d', d);
        };
        SvgRenderer.prototype.setSvgFontStyle = function (text, options) {
            text.style.fontStyle = options.italic ? 'italic' : 'normal';
            text.style.fontWeight = options.bold ? 'bold' : 'normal';
            text.style.fontSize = options.fontSize.toString() + 'px';
            text.style.fontFamily = options.fontFamily;
        };
        SvgRenderer.prototype.drawText = function (canvas, options, parentSvg, ariaLabel, diagramId, scaleValue, parentNode) {
            Eif (options.content !== undefined) {
                var textNode = void 0;
                var childNodes = void 0;
                var wrapBounds = void 0;
                var position = void 0;
                var child = void 0;
                var tspanElement = void 0;
                var offsetX = 0;
                var offsetY = 0;
                var i = 0;
                var text = void 0;
                var nodeContent = void 0;
                if (parentSvg) {
                    text = parentSvg.getElementById(options.id + '_text');
                }
                if (text) {
                    if (options.doWrap) {
                        while (text.firstChild) {
                            text.removeChild(text.firstChild);
                        }
                    }
                }
                else {
                    options.doWrap = true;
                    text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
                    if (options.whiteSpace === 'pre-wrap') {
                        text.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
                    }
                    if (parentNode) {
                        nodeContent = document.getElementById(parentNode.id + '_content_groupElement');
                    }
                    if (nodeContent && parentNode && parentNode.children && parentNode.children[0] instanceof native_element_1.DiagramNativeElement) {
                        var textTag = this.createGElement('g', { id: ariaLabel + '_groupElement' });
                        nodeContent.appendChild(textTag);
                        textTag.appendChild(text);
                    }
                    else {
                        canvas.appendChild(text);
                    }
                }
                var pivotX = options.x + options.width * options.pivotX;
                var pivotY = options.y + options.height * options.pivotY;
                var childNodesHeight = 0;
                if (options.doWrap || options.textOverflow !== 'Wrap') {
                    while (text.firstChild) {
                        text.removeChild(text.firstChild);
                    }
                    this.setSvgStyle(text, options, diagramId);
                    this.setSvgFontStyle(text, options);
                    textNode = document.createTextNode(options.content);
                    childNodes = options.childNodes;
                    wrapBounds = options.wrapBounds;
                    position = this.svgLabelAlign(options, wrapBounds, childNodes);
                    if (wrapBounds.width > options.width && options.textOverflow !== 'Wrap' && options.textWrapping === 'NoWrap') {
                        childNodes[0].text = base_util_1.overFlow(options.content, options);
                    }
                    for (i = 0; i < childNodes.length; i++) {
                        tspanElement = document.createElementNS('http://www.w3.org/2000/svg', 'tspan');
                        textNode = document.createTextNode(childNodes[parseInt(i.toString(), 10)].text);
                        child = childNodes[parseInt(i.toString(), 10)];
                        child.x = dom_util_1.setChildPosition(child, childNodes, i, options);
                        if (options.textAlign === 'justify' || options.textAlign === 'left') {
                            offsetX = 0;
                        }
                        else {
                            offsetX = position.x + child.x - wrapBounds.x;
                        }
                        offsetY = position.y + child.dy * (i) + ((options.fontSize) * 0.8);
                        if ((options.textOverflow === 'Clip' || options.textOverflow === 'Ellipsis') &&
                            (options.textWrapping === 'WrapWithOverflow' || options.textWrapping === 'Wrap') && parentNode) {
                            var size = (options.isHorizontalLane) ? parentNode.actualSize.width : parentNode.actualSize.height;
                            if (offsetY < size) {
                                if (options.textOverflow === 'Ellipsis' && childNodes[i + 1]) {
                                    var temp = childNodes[i + 1];
                                    var y = position.y + temp.dy * (i + 1) + ((options.fontSize) * 0.8);
                                    if (y > size) {
                                        child.text = child.text.slice(0, child.text.length - 3);
                                        child.text = child.text.concat('...');
                                        textNode.data = child.text;
                                    }
                                }
                                this.alignText(text, tspanElement, child, textNode, offsetX, offsetY, i, options, childNodes);
                                childNodesHeight += child.dy;
                            }
                            else {
                                break;
                            }
                        }
                        else {
                            this.alignText(text, tspanElement, child, textNode, offsetX, offsetY, i, options, childNodes);
                        }
                    }
                }
                Iif (childNodesHeight && options.isHorizontalLane) {
                    pivotX = options.parentOffsetX + options.pivotX;
                    pivotY = options.parentOffsetY + options.pivotY;
                    options.y = options.parentOffsetY - childNodesHeight * options.pivotY + 0.5;
                }
                if (options.textDecoration && options.textDecoration === 'LineThrough') {
                    options.textDecoration = base_util_1.wordBreakToString(options.textDecoration);
                }
                var attr = {
                    'id': options.id + '_text', 'fill': options.color, 'visibility': options.visible ? 'visible' : 'hidden',
                    'text-decoration': options.textDecoration, 'transform': 'rotate(' + options.angle + ','
                        + (pivotX) + ',' + (pivotY) + ')'
                        + 'translate(' + (options.x) + ',' + (options.y) + ')', 'opacity': options.opacity
                };
                if (ariaLabel) {
                    attr['role'] = 'img';
                    attr['aria-label'] = ariaLabel;
                }
                dom_util_1.setAttributeSvg(text, attr);
            }
        };
        SvgRenderer.prototype.alignText = function (text, tspanElement, child, textNode, offsetX, offsetY, i, options, childNodes) {
            if (options.textAlign !== 'justify') {
                this.setText(text, tspanElement, child, textNode, offsetX, offsetY, options);
            }
            else {
                if (i !== childNodes.length - 1) {
                    var textlength = options.width;
                    var adjustlen = 'spacing';
                    this.setText(text, tspanElement, child, textNode, offsetX, offsetY, options, textlength, adjustlen);
                }
                else {
                    this.setText(text, tspanElement, child, textNode, offsetX, offsetY, options);
                }
            }
        };
        SvgRenderer.prototype.setText = function (text, tspanElement, child, textNode, offsetX, offsetY, options, textlength, adjustlen) {
            if (options.textAlign !== 'justify') {
                dom_util_1.setAttributeSvg(tspanElement, { 'x': offsetX.toString(), 'y': offsetY.toString() });
            }
            else {
                dom_util_1.setAttributeSvg(tspanElement, { 'x': offsetX.toString(), 'y': offsetY.toString(), 'textLength': textlength ? textlength : 0, 'lengthAdjust': adjustlen ? adjustlen : 'spacing' });
            }
            text.setAttribute('fill', child.text);
            tspanElement.appendChild(textNode);
            text.appendChild(tspanElement);
        };
        SvgRenderer.prototype.drawImage = function (canvas, obj, parentSvg, fromPalette) {
            var image;
            if (parentSvg) {
                image = parentSvg.getElementById(obj.id + 'image');
            }
            if (!image) {
                image = document.createElementNS('http://www.w3.org/2000/svg', 'image');
                canvas.appendChild(image);
            }
            var imageObj = new Image();
            imageObj.src = obj.source;
            var scale = obj.scale !== 'None' ? obj.scale : '';
            var imgAlign = obj.alignment;
            var aspectRatio = imgAlign.charAt(0).toLowerCase() + imgAlign.slice(1);
            if (scale !== 'Stretch') {
                aspectRatio += ' ' + scale.charAt(0).toLowerCase() + scale.slice(1);
            }
            var attr = {
                'id': obj.id + 'image', 'x': obj.x.toString(), 'y': obj.y.toString(), 'transform': 'rotate(' + obj.angle + ','
                    + (obj.x + obj.width * obj.pivotX) + ',' + (obj.y + obj.height * obj.pivotY) + ')',
                'width': obj.width.toString(), 'visibility': obj.visible ? 'visible' : 'hidden',
                'height': obj.height.toString(), 'preserveAspectRatio': aspectRatio,
                'opacity': obj.opacity.toString()
            };
            dom_util_1.setAttributeSvg(image, attr);
            image.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', imageObj.src.toString());
        };
        SvgRenderer.prototype.drawHTMLContent = function (element, canvas, transform, value, indexValue) {
            var htmlElement;
            var parentHtmlElement;
            Eif (canvas) {
                htmlElement = canvas.querySelector('#' + element.id + '_html_element');
            }
            if (!htmlElement) {
                parentHtmlElement = canvas.querySelector(('#' + element.id + '_html_element')) ||
                    canvas.querySelector(('#' + element.nodeId + '_html_element'));
                if (!parentHtmlElement) {
                    var attr_1 = {
                        'id': element.nodeId + '_html_element',
                        'class': 'foreign-object'
                    };
                    parentHtmlElement = dom_util_2.createHtmlElement('div', attr_1);
                }
                var attr = {
                    'id': element.id + '_html_element',
                    'class': 'foreign-object'
                };
                htmlElement = dom_util_2.createHtmlElement('div', attr);
                var diagram = document.getElementById(element.diagramId).ej2_instances[0];
                var isOverviewLayer = false;
                if (canvas.parentNode && canvas.parentNode.parentNode && canvas.parentNode.parentNode.parentNode && canvas.parentNode.parentNode.parentNode.classList.contains('e-overview')) {
                    isOverviewLayer = true;
                }
                if (isOverviewLayer) {
                    Iif (diagram.isReact) {
                        diagram.renderReactTemplates(function () {
                            htmlElement.appendChild(element.template.cloneNode(true));
                        });
                    }
                    else {
                        htmlElement.appendChild(element.template.cloneNode(true));
                    }
                }
                else {
                    if (typeof element.template === 'string') {
                        var temp = document.createElement('div');
                        temp.innerHTML = element.template;
                        element.template = temp;
                        var handle = diagram.selectedItems.userHandles.filter(function (x) {
                            return x.name === (element.id.split('_shape')[0]) && x.template !== '';
                        });
                        handle[0].template = element.template;
                    }
                    if (element.isTemplate && element.template) {
                        htmlElement.appendChild(element.template);
                    }
                    else if (element.template) {
                        htmlElement.appendChild(element.template.cloneNode(true));
                    }
                }
                if (indexValue !== undefined && canvas.childNodes.length > indexValue) {
                    canvas.insertBefore(htmlElement, canvas.childNodes[parseInt(indexValue.toString(), 10)]);
                }
                parentHtmlElement.appendChild(htmlElement);
                canvas.appendChild(parentHtmlElement);
            }
            var point = base_util_1.cornersPointsBeforeRotation(element).topLeft;
            htmlElement.setAttribute('style', 'height:' + (element.actualSize.height) + 'px; width:' + (element.actualSize.width) +
                'px;left:' + point.x + 'px; top:' + point.y + 'px;' +
                'position:absolute;transform:rotate(' + (element.rotateAngle + element.parentTransform) + 'deg);' +
                'pointer-events:' + (value ? 'all' : 'none')
                + ';visibility:' + ((element.visible) ? 'visible' : 'hidden') + ';opacity:' + element.style.opacity + ';');
        };
        SvgRenderer.prototype.drawNativeContent = function (element, canvas, height, width, parentSvg) {
            var nativeElement;
            var clipPath;
            Eif (parentSvg) {
                nativeElement = parentSvg.getElementById(element.id + '_native_element');
                clipPath = parentSvg.getElementById(element.id + '_clip');
            }
            if (!nativeElement) {
                nativeElement = document.createElementNS('http://www.w3.org/2000/svg', 'g');
                nativeElement.setAttribute('id', element.id + '_native_element');
                nativeElement.appendChild(element.template.cloneNode(true));
                var svgContentTag = this.createGElement('g', { id: element.id + '_inner_native_element' });
                svgContentTag.appendChild(nativeElement);
                canvas.appendChild(svgContentTag);
            }
            if (clipPath) {
                nativeElement.removeChild(clipPath);
            }
            nativeElement.setAttribute('style', 'visibility:' +
                ((element.visible) ? 'visible' : 'hidden') + ';opacity:' + element.style.opacity + ';');
            this.setNativTransform(element, nativeElement, height, width);
            if (element.scale === 'Slice') {
                this.drawClipPath(element, nativeElement, height, width, parentSvg);
            }
            dom_util_1.setAttributeSvg(nativeElement, element.description ? { 'role': 'img', 'aria-label': element.description } : {});
        };
        SvgRenderer.prototype.setNativTransform = function (element, nativeElement, height, width) {
            var contentWidth = element.contentSize.width !== 0 ? element.contentSize.width : 1;
            var contentHeight = element.contentSize.height !== 0 ? element.contentSize.height : 1;
            var x = element.templatePosition.x * width / contentWidth;
            var y = element.templatePosition.y * height / contentHeight;
            nativeElement.setAttribute('transform', 'rotate(' + element.parentTransform + ',' + element.offsetX + ',' + element.offsetY +
                ') translate(' + (element.offsetX - x - width * element.pivot.x) + ',' + (element.offsetY - y - height * element.pivot.y) +
                ') scale(' + (width / contentWidth) + ',' + (height / contentHeight) + ')');
        };
        SvgRenderer.prototype.drawClipPath = function (node, group, height, width, parentSvg) {
            var contentWidth = node.contentSize.width;
            var contentHeight = node.contentSize.height;
            var clipWidth = node.width / (width / contentWidth);
            var clipHeight = node.height / (height / contentHeight);
            var x = node.templatePosition.x + (node.width >= node.height ? 0 : (contentWidth - clipWidth) / 2);
            var y = node.templatePosition.y + (node.height >= node.width ? 0 : (contentHeight - clipHeight) / 2);
            var clipPath = parentSvg.getElementById(node.id + '_clip');
            clipPath = document.createElementNS('http://www.w3.org/2000/svg', 'clipPath');
            clipPath.setAttribute('id', node.id + '_clip');
            group.appendChild(clipPath);
            var rect = parentSvg.getElementById(node.id + '_clip_rect');
            rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
            clipPath.appendChild(rect);
            var attr = {
                'id': node.id + '_clip_rect', 'width': clipWidth.toString(), 'height': clipHeight.toString(),
                'x': x.toString(), 'y': y.toString()
            };
            dom_util_1.setAttributeSvg(rect, attr);
            Iif (diagram_util_1.checkBrowserInfo()) {
                group.setAttribute('clip-path', 'url(' + location.protocol + '//' + location.host + location.pathname +
                    '#' + node.id + '_clip)');
            }
            else {
                group.setAttribute('clip-path', 'url(#' + node.id + '_clip)');
            }
            return group;
        };
        SvgRenderer.prototype.renderGradient = function (options, svg, diagramId) {
            var max;
            var min;
            var grd;
            var svgContainer = dom_util_2.getBackgroundLayerSvg(diagramId);
            var defs = svgContainer.getElementById(diagramId + 'gradient_pattern');
            if (!defs) {
                defs = dom_util_2.createSvgElement('defs', { id: diagramId + 'gradient_pattern' });
                svgContainer.insertBefore(defs, svgContainer.firstChild);
            }
            var radial;
            var linear;
            diagram_util_1.removeGradient(svg.id);
            Eif (options.gradient.type !== 'None') {
                for (var i = 0; i < options.gradient.stops.length; i++) {
                    max = !max ? options.gradient.stops[parseInt(i.toString(), 10)].offset
                        : Math.max(max, options.gradient.stops[parseInt(i.toString(), 10)].offset);
                    min = !min ? options.gradient.stops[parseInt(i.toString(), 10)].offset
                        : Math.min(min, options.gradient.stops[parseInt(i.toString(), 10)].offset);
                }
                if (options.gradient.type === 'Linear') {
                    linear = options.gradient;
                    linear.id = svg.id + '_linear';
                    grd = this.createLinearGradient(linear);
                    defs.appendChild(grd);
                }
                else {
                    radial = options.gradient;
                    radial.id = svg.id + '_radial';
                    grd = this.createRadialGradient(radial);
                    defs.appendChild(grd);
                }
                for (var i = 0; i < options.gradient.stops.length; i++) {
                    var stop_1 = options.gradient.stops[parseInt(i.toString(), 10)];
                    var offset = min < 0 ? (max + stop_1.offset) / (2 * max) : stop_1.offset / max;
                    var stopElement = document.createElementNS('http://www.w3.org/2000/svg', 'stop');
                    dom_util_1.setAttributeSvg(stopElement, { 'offset': offset.toString(), 'style': 'stop-color:' + stop_1.color });
                    grd.appendChild(stopElement);
                }
            }
            return grd;
        };
        SvgRenderer.prototype.createLinearGradient = function (linear) {
            var lineargradient = document.createElementNS('http://www.w3.org/2000/svg', 'linearGradient');
            var attr = {
                'id': linear.id, 'x1': linear.x1 + '%', 'y1': linear.y1 + '%', 'x2': linear.x2 + '%', 'y2': linear.y2 + '%'
            };
            dom_util_1.setAttributeSvg(lineargradient, attr);
            return lineargradient;
        };
        SvgRenderer.prototype.createRadialGradient = function (radial) {
            var radialgradient = document.createElementNS('http://www.w3.org/2000/svg', 'radialGradient');
            var attr = {
                'id': radial.id, 'cx': radial.cx + '%', 'cy': radial.cy + '%', 'r': radial.r + '%', 'fx': radial.fx + '%', 'fy': radial.fy + '%'
            };
            dom_util_1.setAttributeSvg(radialgradient, attr);
            return radialgradient;
        };
        SvgRenderer.prototype.setSvgStyle = function (svg, style, diagramId) {
            Eif (style.canApplyStyle || style.canApplyStyle === undefined) {
                if (style.fill === 'none') {
                    style.fill = 'transparent';
                }
                if (style.stroke === 'none') {
                    style.stroke = 'transparent';
                }
                var dashArray = [];
                var fill = void 0;
                if (style.dashArray) {
                    var canvasRenderer = new canvas_renderer_1.CanvasRenderer();
                    dashArray = canvasRenderer.parseDashArray(style.dashArray);
                }
                if (style.gradient && style.gradient.type !== 'None' && diagramId) {
                    var grd = this.renderGradient(style, svg, diagramId);
                    Iif (diagram_util_1.checkBrowserInfo()) {
                        fill = 'url(' + location.protocol + '//' + location.host + location.pathname + '#' + grd.id + ')';
                    }
                    else {
                        fill = 'url(#' + grd.id + ')';
                    }
                }
                else {
                    fill = style.fill;
                }
                if (style.stroke) {
                    svg.setAttribute('stroke', style.stroke);
                }
                if (style.strokeWidth !== undefined && style.strokeWidth !== null) {
                    svg.setAttribute('stroke-width', style.strokeWidth.toString());
                }
                Eif (dashArray) {
                    svg.setAttribute('stroke-dasharray', dashArray.toString() || 'none');
                }
                if (fill) {
                    svg.setAttribute('fill', fill);
                }
            }
        };
        SvgRenderer.prototype.svgLabelAlign = function (text, wrapBound, childNodes) {
            var bounds = new size_1.Size(wrapBound.width, childNodes.length * (text.fontSize * 1.2));
            var pos = { x: 0, y: 0 };
            var x = 0;
            var y = 1.2;
            var offsetX = text.width * 0.5;
            var offsety = text.height * 0.5;
            var pointX = offsetX;
            var pointY = offsety;
            if (text.textAlign === 'left' || text.textAlign === 'justify') {
                pointX = 0;
            }
            else if (text.textAlign === 'center') {
                if (wrapBound.width > text.width && (text.textOverflow === 'Ellipsis' || text.textOverflow === 'Clip')) {
                    if (text.textWrapping === 'NoWrap') {
                        pointX = 0;
                    }
                    else {
                        pointX = text.width * 0.5;
                    }
                }
                else {
                    pointX = text.width * 0.5;
                }
            }
            else Eif (text.textAlign === 'right') {
                pointX = (text.width * 1);
            }
            pos.x = x + pointX + (wrapBound ? wrapBound.x : 0);
            pos.y = y + pointY - bounds.height / 2;
            return pos;
        };
        return SvgRenderer;
    }());
    exports.SvgRenderer = SvgRenderer;
});