all files / common/scrollbar/ scrollbar.js

94.89% Statements 427/450
84.48% Branches 392/464
100% Functions 34/34
94.88% Lines 426/449
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   191× 191× 191× 191× 191× 191× 191× 191× 191× 191× 191×   144× 144× 144× 144× 86× 86× 86×     58× 58×   144× 144× 144×   197× 197× 197× 197× 197× 197×   197× 197× 197× 197× 197× 197×   48× 48× 48× 48× 48× 48× 48×   48× 48× 48× 48× 48× 48× 48× 48× 24× 24× 18×     24×       48×     271×   34× 34×               45× 45× 45× 45× 45× 34× 34×   45× 45× 45×   45× 45×   45×     96× 96× 96× 96×     96× 96× 96× 96×   96×   96× 96× 96× 96× 96× 96× 96×   96× 96× 27× 27× 27× 27×     19× 15×     27× 19× 19× 19× 19× 19×   27×   69× 20×                           97× 97× 97× 97× 97× 97× 97× 11×   97× 15× 15×                 15×       97× 97× 97× 97× 97× 97× 17× 17×   97×             15× 15× 15× 15× 15× 15× 15× 15× 15× 15× 15×                   15× 15×     15×   34× 34×       34× 17× 17× 17×       17× 17×   34×       34× 34× 34×             34×   197× 197×   197× 197× 197× 197× 197× 197×   197×   197× 41×     104× 104×       96× 96× 96× 96× 96× 96× 96× 96× 96× 96× 96× 96× 96× 96× 13× 13× 13× 13× 13× 13×     96×   20× 20× 20× 20× 20× 20× 20× 20×   20× 20× 13× 13×   13× 13×                                                                             47× 47× 47× 47× 47× 47× 47× 47× 47× 47×     197× 197× 197× 197× 197× 197× 11× 11×   197× 197×   197× 197×   197× 197×   197× 197× 197× 197× 197× 197× 197×       197×         11× 11× 11× 11× 11× 11× 11× 11×   11×       11× 11× 11×       11× 11× 11×             11× 11× 11× 11× 11× 11× 11× 11× 11× 11× 11× 11×     91×   841× 841× 200× 612×       641× 197× 197×   641×     44601×   98×                     98×        
define(["require", "exports", "@syncfusion/ej2-base", "./scrollbar-elements", "../utils/helper", "../model/theme", "../model/constants"], function (require, exports, ej2_base_1, scrollbar_elements_1, helper_1, theme_1, constants_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ScrollBar = (function () {
        function ScrollBar(component, axis) {
            this.svgExtraWidth = 50;
            this.scrollRange = { max: null, min: null, interval: null, delta: null };
            this.component = component;
            this.elements = [];
            this.scrollElements = new scrollbar_elements_1.ScrollElements(component);
            this.axis = axis;
            this.mouseMoveListener = this.scrollMouseMove.bind(this);
            this.mouseUpListener = this.scrollMouseUp.bind(this);
            this.animateDuration = 500;
            this.isPointer = ej2_base_1.Browser.isPointer;
            this.browserName = ej2_base_1.Browser.info.name;
        }
        ScrollBar.prototype.getMouseXY = function (e) {
            var pageX;
            var pageY;
            var touchArg;
            if (e.type.indexOf('touch') > -1) {
                touchArg = e;
                pageX = touchArg.changedTouches[0].clientX;
                pageY = touchArg.changedTouches[0].clientY;
            }
            else {
                pageX = e.clientX;
                pageY = e.clientY;
            }
            var svgRect = helper_1.getElement(this.component.element.id + '_scrollBar_svg' + this.axis.name).getBoundingClientRect();
            this.mouseX = pageX - Math.max(svgRect.left, 0);
            this.mouseY = pageY - Math.max(svgRect.top, 0);
        };
        ScrollBar.prototype.wireEvents = function (element) {
            ej2_base_1.EventHandler.add(element, ej2_base_1.Browser.touchStartEvent, this.scrollMouseDown, this);
            ej2_base_1.EventHandler.add(element, ej2_base_1.Browser.touchMoveEvent, this.scrollMouseMove, this);
            ej2_base_1.EventHandler.add(element, ej2_base_1.Browser.touchEndEvent, this.scrollMouseUp, this);
            ej2_base_1.EventHandler.add(element, 'mousewheel', this.scrollMouseWheel, this);
            window.addEventListener('mousemove', this.mouseMoveListener, false);
            window.addEventListener('mouseup', this.mouseUpListener, false);
        };
        ScrollBar.prototype.unWireEvents = function (element) {
            ej2_base_1.EventHandler.remove(element, ej2_base_1.Browser.touchStartEvent, this.scrollMouseDown);
            ej2_base_1.EventHandler.remove(element, ej2_base_1.Browser.touchMoveEvent, this.scrollMouseMove);
            ej2_base_1.EventHandler.remove(element, ej2_base_1.Browser.touchEndEvent, this.scrollMouseUp);
            ej2_base_1.EventHandler.remove(element, 'mousewheel', this.scrollMouseWheel);
            window.removeEventListener('mousemove', this.mouseMoveListener, false);
            window.removeEventListener('mouseup', this.mouseUpListener, false);
        };
        ScrollBar.prototype.scrollMouseDown = function (e) {
            var id = e.target.id;
            var elem = this.scrollElements;
            var isInverse = this.axis.isAxisInverse;
            this.getMouseXY(e);
            this.isResizeLeft = this.isExist(id, '_leftCircle_') || this.isExist(id, '_leftArrow_');
            this.isResizeRight = this.isExist(id, '_rightCircle_') || this.isExist(id, '_rightArrow_');
            this.previousXY = (this.isVertical && isInverse) ? this.mouseY : this.isVertical ? this.width -
                this.mouseY : isInverse ? this.width - this.mouseX : this.mouseX;
            this.previousWidth = elem.thumbRectWidth;
            this.previousRectX = elem.thumbRectX;
            this.startZoomPosition = this.axis.zoomPosition;
            this.startZoomFactor = this.axis.zoomFactor;
            this.startRange = this.axis.visibleRange;
            this.scrollStarted = true;
            this.component.trigger(constants_1.scrollStart, this.getArgs(constants_1.scrollStart));
            if (this.isExist(id, 'scrollBarThumb_') || this.isExist(id, 'gripCircle')) {
                this.isThumbDrag = true;
                if (this.axis.scrollbarSettings.height >= 12) {
                    this.svgObject.style.cursor = '-webkit-grabbing';
                }
            }
            else if (this.isExist(id, 'scrollBarBackRect_')) {
                var currentX = this.moveLength(this.previousXY, this.previousRectX);
                elem.thumbRectX = this.isWithIn(currentX) ? currentX : elem.thumbRectX;
                this.positionThumb(elem.thumbRectX, elem.thumbRectWidth);
                this.setZoomFactorPosition(elem.thumbRectX, elem.thumbRectWidth);
                this.axis.zoomPosition = this.zoomPosition < 0 ? 0 : this.zoomPosition > 0.9 ? 1 : this.zoomPosition;
                if (this.isLazyLoad) {
                    var thumbMove = elem.thumbRectX > this.previousRectX ? 'RightMove' : 'LeftMove';
                    var args = this.calculateLazyRange(elem.thumbRectX, elem.thumbRectWidth, thumbMove);
                    Eif (args) {
                        this.component.trigger(constants_1.scrollEnd, args);
                    }
                }
            }
            if (this.component.element.style.height === '') {
                this.isCustomHeight = true;
                this.component.element.style.height = this.component.availableSize.height + 'px';
            }
        };
        ScrollBar.prototype.isExist = function (id, match) {
            return id.indexOf(match) > -1;
        };
        ScrollBar.prototype.isWithIn = function (currentX) {
            var circleRadius = this.axis.scrollbarSettings.height / 2;
            return ((currentX - (this.axis.scrollbarSettings.enableZoom && this.axis.orientation === 'Horizontal' ? this.svgExtraWidth / 2 : 0)) - circleRadius >= 0 &&
                currentX + this.scrollElements.thumbRectWidth + circleRadius <= (this.width + (this.axis.scrollbarSettings.enableZoom && this.axis.orientation === 'Horizontal' ? this.svgExtraWidth / 2 : 0)));
        };
        ScrollBar.prototype.moveLength = function (mouseXY, thumbX, circleRadius) {
            Eif (circleRadius === void 0) { circleRadius = this.axis.scrollbarSettings.height / 2; }
            var moveLength = (10 / 100) * (this.width - circleRadius * 2);
            if (mouseXY < thumbX) {
                moveLength = thumbX - (thumbX - moveLength > circleRadius ? moveLength : circleRadius);
            }
            else {
                moveLength = thumbX + (thumbX + this.scrollElements.thumbRectWidth + moveLength < this.width - circleRadius ?
                    moveLength : circleRadius);
            }
            return moveLength;
        };
        ScrollBar.prototype.setZoomFactorPosition = function (currentX, currentWidth) {
            this.isScrollUI = true;
            var axis = this.axis;
            var circleRadius = this.axis.scrollbarSettings.height / 2;
            var circleWidth = 1;
            if (axis.scrollbarSettings.enableZoom && !this.isVertical) {
                currentX -= (this.svgExtraWidth / 2);
                currentWidth += (this.svgExtraWidth / 2);
            }
            var currentScrollWidth = currentX + currentWidth + circleRadius + circleWidth;
            var currentZPWidth = circleRadius + (circleWidth / 2);
            var axisSize = this.isVertical ? axis.rect.height : this.width +
                (axis.scrollbarSettings.enableZoom ? this.svgExtraWidth : 0);
            this.zoomFactor = (currentWidth + (currentScrollWidth >= this.width ? circleRadius + circleWidth : 0)) / axisSize;
            this.zoomPosition = currentScrollWidth > axisSize ? (1 - axis.zoomFactor) : currentX < (circleRadius + circleWidth) ? 0 :
                (currentX - (currentX - currentZPWidth <= 0 ? currentZPWidth : 0)) / axisSize;
            this.zoomPosition = (this.component.enableRtl && !this.isVertical && !axis.isInversed) || (axis.isInversed &&
                !(this.component.enableRtl && !this.isVertical)) ? 1 - (this.zoomPosition + axis.zoomFactor) : this.zoomPosition;
        };
        ScrollBar.prototype.scrollMouseMove = function (e) {
            var target = e.target;
            var elem = this.scrollElements;
            var isInverse = this.axis.isAxisInverse;
            Iif (!helper_1.getElement(this.svgObject.id)) {
                return null;
            }
            this.getMouseXY(e);
            Eif (!ej2_base_1.isNullOrUndefined(target.id)) {
                this.setCursor(target);
                this.setTheme(target);
            }
            var mouseXY = (this.isVertical && isInverse) ? this.width - this.mouseY : this.isVertical ?
                this.mouseY : this.mouseX;
            var range = this.axis.visibleRange;
            var zoomPosition = this.zoomPosition;
            var zoomFactor = this.zoomFactor;
            var moveLength = this.previousRectX - elem.thumbRectX;
            var thumbMove = moveLength < 0 ? 'RightMove' : 'LeftMove';
            var args;
            if (this.isLazyLoad && (this.isThumbDrag || this.isResizeLeft || this.isResizeRight)) {
                args = this.calculateLazyRange(elem.thumbRectX, elem.thumbRectWidth, thumbMove);
            }
            var currentRange = args ? args.currentRange : null;
            if (this.isThumbDrag) {
                this.component.isScrolling = this.isThumbDrag;
                mouseXY = (this.isVertical || isInverse) ? this.width - mouseXY : mouseXY;
                var currentX = elem.thumbRectX + (mouseXY - this.previousXY);
                if (mouseXY >= currentX + elem.thumbRectWidth) {
                    this.setCursor(target);
                }
                else {
                    if (this.axis.scrollbarSettings.height >= 12) {
                        this.svgObject.style.cursor = '-webkit-grabbing';
                    }
                }
                if (mouseXY >= 0 && mouseXY <= currentX + elem.thumbRectWidth) {
                    elem.thumbRectX = this.isWithIn(currentX) ? currentX : elem.thumbRectX;
                    this.positionThumb(elem.thumbRectX, elem.thumbRectWidth);
                    this.previousXY = mouseXY;
                    this.setZoomFactorPosition(currentX, elem.thumbRectWidth);
                    this.axis.zoomPosition = this.zoomPosition < 0 ? 0 : this.zoomPosition > 0.9 ? 1 : this.zoomPosition;
                }
                this.component.trigger(constants_1.scrollChanged, this.getArgs(constants_1.scrollChanged, range, zoomPosition, zoomFactor, currentRange));
            }
            else if ((this.isResizeLeft && (this.axis.orientation === 'Horizontal' ? (mouseXY > (this.svgExtraWidth / 2 + this.axis.scrollbarSettings.height / 2)) : true)) || (this.isResizeRight && (this.axis.orientation === 'Horizontal' ? (mouseXY < (this.width + this.svgExtraWidth)) : true))) {
                this.resizeThumb();
            }
        };
        ScrollBar.prototype.scrollMouseWheel = function (e) {
            Iif (!this.axis.scrollbarSettings.enableZoom) {
                return null;
            }
            var svgRect = helper_1.getElement(this.component.element.id + '_scrollBar_svg' + this.axis.name).getBoundingClientRect();
            this.mouseX = e.clientX - Math.max(svgRect.left, 0);
            this.mouseY = e.clientY - Math.max(svgRect.top, 0);
            var origin = 0.5;
            var elem = this.scrollElements;
            var axis = this.axis;
            var direction = (this.browserName === 'mozilla' && !this.isPointer) ?
                -(e.detail) / 3 > 0 ? 1 : -1 : (e['wheelDelta'] / 120) > 0 ? 1 : -1;
            var cumulative = Math.max(Math.max(1 / helper_1.minMax(axis.zoomFactor, 0, 1), 1) + (0.25 * direction), 1);
            var range = this.axis.visibleRange;
            var zoomPosition = this.zoomPosition;
            var zoomFactor = this.zoomFactor;
            var args;
            Eif (cumulative >= 1) {
                origin = axis.orientation === 'Horizontal' ? this.mouseX / axis.rect.width : 1 - (this.mouseY / axis.rect.height);
                origin = origin > 1 ? 1 : origin < 0 ? 0 : origin;
                this.zoomFactor = (cumulative === 1) ? 1 : helper_1.minMax(1 / cumulative, 0, 1);
                this.zoomPosition = (cumulative === 1) ? 0 : axis.zoomPosition + ((axis.zoomFactor - this.zoomFactor) * origin);
            }
            elem.thumbRectX = this.isWithIn(this.zoomPosition * this.width) ? this.zoomPosition * this.width : elem.thumbRectX;
            this.isScrollUI = true;
            this.positionThumb(elem.thumbRectX, elem.thumbRectWidth);
            if (this.isLazyLoad) {
                this.setZoomFactorPosition(elem.thumbRectX, elem.thumbRectWidth);
                this.axis.zoomFactor = this.zoomFactor;
                this.axis.zoomPosition = this.zoomPosition < 0 ? 0 : this.zoomPosition > 0.9 ? 1 : this.zoomPosition;
            }
            axis.zoomFactor = this.zoomFactor;
            axis.zoomPosition = this.zoomPosition;
            if (this.isLazyLoad) {
                args = this.calculateMouseWheelRange(elem.thumbRectX, elem.thumbRectWidth);
                Eif (args) {
                    Eif ((args.currentRange.minimum !== args.previousAxisRange.minimum) && (args.currentRange.maximum !==
                        args.previousAxisRange.maximum)) {
                        this.component.trigger(constants_1.scrollEnd, args);
                        this.isScrollEnd = false;
                    }
                }
            }
            if (!this.isLazyLoad) {
                this.component.trigger(constants_1.scrollChanged, this.getArgs(constants_1.scrollChanged, range, zoomPosition, zoomFactor));
            }
        };
        ScrollBar.prototype.scrollMouseUp = function () {
            var args;
            this.startX = this.scrollElements.thumbRectX;
            var circleRadius = this.axis.scrollbarSettings.height / 2;
            var circleWidth = 1;
            var currentScrollWidth = this.startX + this.scrollElements.thumbRectWidth + circleRadius + circleWidth;
            var currentZPWidth = circleRadius + (circleWidth / 2);
            if ((this.isResizeLeft || this.isResizeRight) && !this.isLazyLoad) {
                this.axis.zoomFactor = (currentScrollWidth >= this.width - 1 && (this.startX - currentZPWidth) <= 0) ? 1 : this.zoomFactor;
            }
            if (this.isLazyLoad) {
                var moveLength = this.previousRectX - this.startX;
                if ((moveLength > 0 || moveLength < 0) && this.isThumbDrag) {
                    var thumbMove = moveLength < 0 ? 'RightMove' : 'LeftMove';
                    Eif (thumbMove === 'RightMove') {
                        this.startX = (this.startX + Math.abs(moveLength)) < this.width - circleRadius ? this.startX :
                            this.width - circleRadius - this.scrollElements.thumbRectWidth;
                    }
                    else {
                        this.startX = (this.startX + this.scrollElements.thumbRectWidth - Math.abs(moveLength)) > circleRadius ?
                            this.startX : circleRadius;
                    }
                    args = this.calculateLazyRange(this.startX, this.scrollElements.thumbRectWidth, thumbMove);
                    Eif (args) {
                        this.component.trigger(constants_1.scrollEnd, args);
                        this.scrollStarted = false;
                    }
                }
                if (this.isResizeLeft || this.isResizeRight) {
                    args = this.calculateLazyRange(this.startX, this.scrollElements.thumbRectWidth);
                    Eif (args) {
                        this.component.trigger(constants_1.scrollEnd, args);
                        this.scrollStarted = false;
                    }
                }
            }
            this.isThumbDrag = false;
            this.isResizeLeft = false;
            this.isResizeRight = false;
            this.isScrollEnd = false;
            this.component.isScrolling = false;
            if (this.scrollStarted && !this.isLazyLoad) {
                this.component.trigger(constants_1.scrollEnd, this.getArgs(constants_1.scrollChanged, this.startRange, this.startZoomPosition, this.startZoomFactor));
                this.scrollStarted = false;
            }
            Iif (this.isCustomHeight) {
                this.component.element.style.height = null;
            }
        };
        ScrollBar.prototype.calculateMouseWheelRange = function (scrollThumbX, scrollThumbWidth) {
            var zoomFactor;
            var zoomPosition;
            var args;
            var range = this.scrollRange;
            var previousRange = this.getStartEnd(this.previousStart, this.previousEnd, false);
            var circleRadius = this.axis.scrollbarSettings.height / 2;
            Eif ((scrollThumbX + scrollThumbWidth + circleRadius) <= this.width) {
                zoomPosition = (scrollThumbX - circleRadius) / this.width;
                zoomFactor = scrollThumbWidth / (this.width);
            }
            var currentStart = range.min + zoomPosition * range.delta;
            var currentEnd = currentStart + zoomFactor * range.delta;
            Eif (currentEnd) {
                args = { axis: this.axis, currentRange: this.getStartEnd(currentStart, currentEnd, true), previousAxisRange: previousRange };
            }
            return args;
        };
        ScrollBar.prototype.calculateLazyRange = function (scrollThumbX, scrollThumbWidth, thumbMove) {
            var currentScrollWidth = scrollThumbWidth;
            var zoomFactor;
            var zoomPosition;
            var currentStart;
            var currentEnd;
            var args;
            var range = this.scrollRange;
            var previousRange = this.getStartEnd(this.previousStart, this.previousEnd, false);
            var circleRadius = this.axis.scrollbarSettings.height / 2;
            var circleWidth = 16;
            if (this.isResizeRight || thumbMove === 'RightMove') {
                currentScrollWidth = this.isResizeRight ? currentScrollWidth + circleWidth : currentScrollWidth;
                zoomFactor = (currentScrollWidth) / this.width;
                zoomPosition = thumbMove === 'RightMove' ? (scrollThumbX + circleRadius) / this.width : this.axis.zoomPosition;
                currentStart = thumbMove === 'RightMove' ? (range.min + zoomPosition * range.delta) : this.previousStart;
                currentEnd = currentStart + zoomFactor * range.delta;
            }
            else Eif (this.isResizeLeft || thumbMove === 'LeftMove') {
                zoomPosition = (scrollThumbX - circleRadius) / this.width;
                zoomFactor = currentScrollWidth / this.width;
                currentStart = range.min + zoomPosition * range.delta;
                currentStart = currentStart >= range.min ? currentStart : range.min;
                currentEnd = thumbMove === 'LeftMove' ? (currentStart + zoomFactor * range.delta) : this.previousEnd;
            }
            else if (this.isThumbDrag) {
                zoomPosition = thumbMove === 'RightMove' ? (scrollThumbX + circleRadius) / this.width : (scrollThumbX - circleRadius) / this.width;
                zoomFactor = (this.scrollElements.thumbRectWidth) / this.width;
                currentStart = range.min + zoomPosition * range.delta;
                currentStart = currentStart >= range.min ? currentStart : range.min;
                currentEnd = currentStart + zoomFactor * range.delta;
            }
            Eif (currentEnd) {
                args = { axis: this.axis, currentRange: this.getStartEnd(currentStart, currentEnd, true),
                    previousAxisRange: previousRange };
            }
            return args;
        };
        ScrollBar.prototype.getStartEnd = function (start, end, isCurrentStartEnd) {
            var valueType = this.valueType;
            Iif ((valueType === 'DateTime' || valueType === 'DateTimeCategory') && isCurrentStartEnd) {
                this.previousStart = start;
                this.previousEnd = end;
            }
            else if (isCurrentStartEnd) {
                var currentStart = Math.round(start);
                var currentEnd = Math.ceil(end);
                Iif (this.axis.valueType === 'Category') {
                    currentEnd -= (!this.axis.scrollbarSettings.enableZoom && currentEnd - currentStart >
                        this.previousEnd - this.previousStart) ? (currentEnd - currentStart) - (this.previousEnd - this.previousStart) : 0;
                }
                this.previousStart = start = currentStart;
                this.previousEnd = end = currentEnd;
            }
            switch (valueType) {
                case 'Double':
                case 'Category':
                case 'Logarithmic':
                    start = Math.round(start);
                    end = Math.ceil(end);
                    break;
                case 'DateTime':
                case 'DateTimeCategory':
                    start = new Date(start);
                    end = new Date(end);
                    break;
            }
            return { minimum: start, maximum: end };
        };
        ScrollBar.prototype.render = function (isScrollExist) {
            Eif (this.component.zoomModule || (isScrollExist && this.axis.scrollbarSettings.enable)) {
                this.getDefaults();
            }
            this.getTheme();
            this.removeScrollSvg();
            scrollbar_elements_1.createScrollSvg(this, this.component.svgRenderer);
            this.wireEvents(this.svgObject);
            this.svgObject.appendChild(this.scrollElements.renderElements(this, this.component.svgRenderer));
            return this.svgObject;
        };
        ScrollBar.prototype.getTheme = function () {
            this.scrollbarThemeStyle = theme_1.getScrollbarThemeColor(this.component.theme);
        };
        ScrollBar.prototype.removeScrollSvg = function () {
            if (document.getElementById(this.component.element.id + '_scrollBar_svg' + this.axis.name)) {
                ej2_base_1.remove(document.getElementById(this.component.element.id + '_scrollBar_svg' + this.axis.name));
            }
        };
        ScrollBar.prototype.setCursor = function (target) {
            var id = target.id;
            this.svgObject.style.cursor = ((id.indexOf('scrollBarThumb_') > -1 || id.indexOf('_gripCircle') > -1) && this.axis.scrollbarSettings.height >= 12) ?
                '-webkit-grab' : (id.indexOf('Circle_') > -1 || id.indexOf('Arrow_') > -1) ? this.isVertical ? 'ns-resize' :
                'ew-resize' : 'auto';
        };
        ScrollBar.prototype.setTheme = function (target) {
            var id = target.id;
            var isLeftHover = id.indexOf('_leftCircle_') > -1 || id.indexOf('_leftArrow_') > -1;
            var isRightHover = id.indexOf('_rightCircle_') > -1 || id.indexOf('_rightArrow_') > -1;
            var style = this.scrollbarThemeStyle;
            var leftArrowEle = this.scrollElements.leftArrowEle;
            var rightArrowEle = this.scrollElements.rightArrowEle;
            var leftCircleEle = this.scrollElements.leftCircleEle;
            var rightCircleEle = this.scrollElements.rightCircleEle;
            var isAxis = this.isCurrentAxis(target, leftArrowEle);
            leftCircleEle.style.fill = isLeftHover && isAxis ? style.circleHover : style.circle;
            rightCircleEle.style.fill = isRightHover && isAxis ? style.circleHover : style.circle;
            leftCircleEle.style.stroke = isLeftHover && isAxis ? style.circleHover : style.circle;
            rightCircleEle.style.stroke = isRightHover && isAxis ? style.circleHover : style.circle;
            if (this.component.theme === 'HighContrastLight') {
                leftArrowEle.style.fill = isLeftHover && isAxis ? style.arrowHover : style.arrow;
                leftArrowEle.style.stroke = isLeftHover && isAxis ? style.arrowHover : style.arrow;
                rightArrowEle.style.fill = isRightHover && isAxis ? style.arrowHover : style.arrow;
                rightArrowEle.style.stroke = isRightHover && isAxis ? style.arrowHover : style.arrow;
                leftCircleEle.style.stroke = isLeftHover && isAxis ? style.circleHover : style.circle;
                rightCircleEle.style.stroke = isRightHover && isAxis ? style.circleHover : style.circle;
            }
        };
        ScrollBar.prototype.isCurrentAxis = function (target, ele) {
            return (target.id.split('_')[2] === ele.id.split('_')[2]);
        };
        ScrollBar.prototype.resizeThumb = function () {
            var currentWidth;
            var circleRadius = this.axis.scrollbarSettings.height / 2;
            var padding = 5;
            var gripWidth = 14;
            var minThumbWidth = circleRadius * 2 + padding * 2 + gripWidth;
            var thumbX = this.previousRectX;
            var isInverse = this.axis.isAxisInverse;
            var mouseXY = (this.isVertical && isInverse) ? this.mouseY : this.isVertical ? this.width -
                this.mouseY : isInverse ? this.width - this.mouseX : this.mouseX;
            var diff = Math.abs(this.previousXY - mouseXY);
            if (this.isResizeLeft && mouseXY >= 0) {
                var currentX = thumbX + (mouseXY > this.previousXY ? diff : -diff);
                currentWidth = currentX - circleRadius >= 0 ? this.previousWidth + (mouseXY > this.previousXY ? -diff : diff) :
                    this.previousWidth;
                currentX = currentX - circleRadius >= 0 ? currentX : thumbX;
                if (currentWidth >= minThumbWidth && mouseXY < currentX + currentWidth) {
                    this.scrollElements.thumbRectX = this.previousRectX = currentX;
                    this.scrollElements.thumbRectWidth = this.previousWidth = currentWidth;
                    this.previousXY = mouseXY;
                    this.setZoomFactorPosition(currentX, currentWidth);
                    var argsData = {
                        axis: this.axis,
                        name: constants_1.scrollChanged,
                        range: this.axis.visibleRange,
                        zoomFactor: this.zoomFactor,
                        zoomPosition: this.zoomPosition,
                        previousRange: this.axis.visibleRange,
                        previousZoomFactor: this.axis.zoomFactor,
                        previousZoomPosition: this.axis.zoomPosition,
                        currentRange: null,
                        cancel: false
                    };
                    this.component.trigger(constants_1.scrollChanged, argsData);
                    Eif (!argsData.cancel) {
                        this.positionThumb(currentX, currentWidth);
                        this.axis.zoomFactor = argsData.zoomFactor;
                        this.axis.zoomPosition = argsData.zoomPosition;
                    }
                    else {
                        this.zoomFactor = argsData.previousZoomFactor;
                        this.zoomPosition = argsData.previousZoomPosition;
                    }
                }
            }
            else Eif (this.isResizeRight) {
                currentWidth = mouseXY >= minThumbWidth + this.scrollElements.thumbRectX && mouseXY <= (this.width + (this.axis.orientation === 'Horizontal' ? this.svgExtraWidth / 2 : 0)) - circleRadius ?
                    mouseXY - this.scrollElements.thumbRectX : this.previousWidth;
                this.scrollElements.thumbRectWidth = this.previousWidth = currentWidth;
                this.previousXY = mouseXY;
                this.setZoomFactorPosition(this.startX, currentWidth);
                if (!this.isLazyLoad) {
                    this.setZoomFactorPosition(this.startX, currentWidth);
                }
                var argsData = {
                    axis: this.axis,
                    name: constants_1.scrollChanged,
                    range: this.axis.visibleRange,
                    zoomFactor: this.zoomFactor,
                    zoomPosition: this.zoomPosition,
                    previousRange: this.axis.visibleRange,
                    previousZoomFactor: this.axis.zoomFactor,
                    previousZoomPosition: this.axis.zoomPosition,
                    currentRange: null,
                    cancel: false
                };
                this.component.trigger(constants_1.scrollChanged, argsData);
                Eif (!argsData.cancel) {
                    this.positionThumb(this.startX, currentWidth);
                    this.axis.zoomFactor = argsData.zoomFactor;
                    this.axis.zoomPosition = argsData.zoomPosition;
                }
                else {
                    this.zoomFactor = argsData.previousZoomFactor;
                    this.zoomPosition = argsData.previousZoomPosition;
                }
            }
        };
        ScrollBar.prototype.positionThumb = function (currentX, currentWidth) {
            var elem = this.scrollElements;
            var gripWidth = 14;
            var gripCircleDiameter = 2;
            var padding = gripWidth / 2 - gripCircleDiameter;
            elem.slider.setAttribute('x', this.axis.scrollbarSettings.enableZoom ? currentX.toString() : (currentX - this.axis.scrollbarSettings.height / 2).toString());
            elem.slider.setAttribute('width', this.axis.scrollbarSettings.enableZoom ? currentWidth.toString() : (currentWidth + this.axis.scrollbarSettings.height).toString());
            elem.leftCircleEle.setAttribute('cx', currentX.toString());
            elem.rightCircleEle.setAttribute('cx', (currentX + currentWidth).toString());
            elem.setArrowDirection(currentX, currentWidth, this.height);
            elem.gripCircle.setAttribute('transform', 'translate(' + (currentX + currentWidth / 2 + ((this.isVertical ? 1 : -1) * padding)) +
                ',' + (this.isVertical ? (this.axis.scrollbarSettings.height / 2 + padding / 2) - 0.5 : (this.axis.scrollbarSettings.height / 2 - padding / 2) - 0.5) + ') rotate(' + (this.isVertical ? '180' : '0') + ')');
        };
        ScrollBar.prototype.getDefaults = function () {
            var axis = this.axis;
            var circleRadius = this.axis.scrollbarSettings.height / 2;
            var padding = 5;
            var gripWidth = 14;
            var minThumbWidth = circleRadius * 2 + padding * 2 + gripWidth;
            if (this.axis.scrollbarSettings.enable) {
                this.isLazyLoad = true;
                this.getLazyDefaults(axis);
            }
            this.isVertical = axis.orientation === 'Vertical';
            var isRtlEnabled = (this.component.enableRtl && !this.isVertical && !axis.isInversed) ||
                (axis.isInversed && !(this.component.enableRtl && !this.isVertical));
            this.zoomFactor = this.isLazyLoad ? this.zoomFactor : axis.zoomFactor;
            this.zoomPosition = this.isLazyLoad ? isRtlEnabled ? 1 - (this.zoomPosition + this.zoomFactor) : this.zoomPosition : isRtlEnabled ?
                1 - (axis.zoomPosition + axis.zoomFactor) : axis.zoomPosition;
            var currentWidth = this.zoomFactor * (this.isVertical ? axis.rect.height : axis.rect.width);
            currentWidth = (this.isLazyLoad && !this.axis.scrollbarSettings.enableZoom) ||
                currentWidth > minThumbWidth ? currentWidth : minThumbWidth;
            this.scrollX = axis.rect.x;
            this.scrollY = axis.rect.y;
            this.width = this.isVertical ? axis.rect.height : axis.rect.width;
            this.height = this.axis.scrollbarSettings.height;
            var currentX = this.zoomPosition * (this.isVertical ? axis.rect.height : this.width);
            var minThumbX = (this.width - minThumbWidth - circleRadius);
            this.scrollElements.thumbRectX = currentX > minThumbX ? (!this.isVertical && this.axis.scrollbarSettings.enableZoom ?
                minThumbX + this.svgExtraWidth / 2 : minThumbX) : currentX < circleRadius ?
                (!this.isVertical && this.axis.scrollbarSettings.enableZoom ? circleRadius + this.svgExtraWidth / 2 : circleRadius)
                : (!this.isVertical && this.axis.scrollbarSettings.enableZoom ? (currentX + this.svgExtraWidth / 2) : currentX);
            this.scrollElements.thumbRectWidth = this.isThumbDrag ? this.scrollElements.thumbRectWidth :
                ((currentWidth + this.scrollElements.thumbRectX) < this.width - (circleRadius * 2))
                    ? currentWidth : ((!this.isVertical && this.axis.scrollbarSettings.enableZoom ?
                    this.width + this.svgExtraWidth / 2 : this.width) - this.scrollElements.thumbRectX - circleRadius);
        };
        ScrollBar.prototype.getLazyDefaults = function (axis) {
            var start;
            var end;
            var valueType = axis.valueType;
            var scrollbarSettings = axis.scrollbarSettings;
            var range = axis.scrollbarSettings.range;
            var visibleRange = axis.visibleRange;
            var pointsLength = axis.scrollbarSettings.pointsLength;
            this.valueType = valueType = (!scrollbarSettings.range.minimum || !scrollbarSettings.range.maximum) &&
                scrollbarSettings.pointsLength ? 'Double' : valueType;
            var option = {
                skeleton: 'full',
                type: 'dateTime'
            };
            var dateParser = this.component.intl.getDateParser(option);
            var dateFormatter = this.component.intl.getDateFormat(option);
            switch (valueType) {
                case 'Double':
                case 'Category':
                case 'Logarithmic':
                    start = range.minimum ? range.minimum : pointsLength ? 0 : visibleRange.min;
                    end = range.maximum ? range.maximum : pointsLength ? (pointsLength - 1) : visibleRange.max;
                    break;
                case 'DateTime':
                case 'DateTimeCategory':
                    start = range.minimum ? Date.parse(dateParser(dateFormatter(range.minimum))) : visibleRange.min;
                    end = range.maximum ? Date.parse(dateParser(dateFormatter(range.maximum))) : visibleRange.max;
                    break;
            }
            start = Math.min(start, visibleRange.min);
            end = Math.max(end, visibleRange.max);
            var zoomFactor = (visibleRange.max - visibleRange.min) / (end - start);
            var zoomPosition = (visibleRange.min - start) / (end - start);
            this.zoomFactor = range.minimum || range.maximum ? zoomFactor : (this.axis.maxPointLength / axis.scrollbarSettings.pointsLength);
            this.zoomPosition = range.minimum || range.maximum ? zoomPosition : axis.zoomPosition;
            this.zoomPosition = (this.component.enableRtl && axis.orientation === 'Horizontal' && !axis.isInversed) || (axis.isInversed && !(this.component.enableRtl && axis.orientation === 'Horizontal')) ? 1 - (this.zoomPosition + this.zoomFactor) : this.zoomPosition;
            this.scrollRange.min = start;
            this.scrollRange.max = end;
            this.scrollRange.delta = end - start;
            this.previousStart = visibleRange.min;
            this.previousEnd = visibleRange.max;
        };
        ScrollBar.prototype.getLogRange = function (axis) {
            var range = axis.scrollbarSettings.range;
            var start = helper_1.logBase(range.minimum, axis.logBase);
            var end = helper_1.logBase(range.maximum, axis.logBase);
            start = isFinite(start) ? start : range.minimum;
            end = isFinite(start) ? end : range.maximum;
            return { minimum: Math.floor(start / 1), maximum: Math.ceil(end / 1) };
        };
        ScrollBar.prototype.injectTo = function (axis, component) {
            axis.zoomingScrollBar = new ScrollBar(component, axis);
        };
        ScrollBar.prototype.destroy = function () {
            var _this = this;
            if (this.axes) {
                this.axes.map(function (axis) {
                    axis.zoomingScrollBar.destroy();
                });
            }
            else {
                this.elements.map(function (element) {
                    _this.unWireEvents(element);
                    ej2_base_1.remove(element.firstChild);
                });
                this.elements = [];
            }
        };
        ScrollBar.prototype.getModuleName = function () {
            return 'ScrollBar';
        };
        ScrollBar.prototype.getArgs = function (eventName, range, zoomPosition, zoomFactor, currentRanges) {
            var scrollArgs = {
                axis: this.axis,
                name: eventName,
                range: this.axis.visibleRange,
                zoomFactor: this.axis.zoomFactor,
                zoomPosition: this.axis.zoomPosition,
                previousRange: range,
                previousZoomFactor: zoomFactor,
                previousZoomPosition: zoomPosition,
                currentRange: currentRanges
            };
            return scrollArgs;
        };
        return ScrollBar;
    }());
    exports.ScrollBar = ScrollBar;
});