all files / range-navigator/renderer/ slider.js

90.49% Statements 257/284
85.15% Branches 195/229
90.91% Functions 20/22
90.46% Lines 256/283
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   345× 345× 345× 345× 345× 345× 345× 345× 345×     349× 349× 349× 349×       349×         349× 349× 349× 349× 349× 349× 349× 349× 349× 349×     349×     349× 349× 349× 349× 349× 349× 349× 349×   698× 698× 698× 698× 698× 698× 698× 698× 698× 698× 698× 698× 698× 344× 344×                 344×   698×   698× 696×               698× 698×         890× 890× 890× 890× 890× 890×   890× 76×   890× 890× 890× 890× 890× 890× 890× 890× 890× 890× 890× 890× 890× 890× 890× 890×   890× 890× 890×           890×           890×           890× 890× 890× 33× 32×   889× 889×         889× 531×     532× 532× 532×                         532×   345×     345× 345× 345× 345×   240×     240× 240× 240× 240×   34× 34× 34× 34× 34× 34× 34× 29×     20× 20×                           29×     29× 28× 28×                   29× 29×     36× 36× 36× 36×   47× 47× 47× 47×   81× 81× 20× 20×   61× 42× 42×   19×   15×                 41× 41× 41× 41× 41×     41×         35×                           31×   41×   41×   41× 39×         41× 41× 41× 41× 41× 41×   14× 14× 14× 14× 14×   21× 21× 21× 21× 21× 21×     123×     20×     14×   20× 20× 20× 10× 10×   10×                 240×        
define(["require", "exports", "@syncfusion/ej2-base", "../../common/utils/helper", "../utils/helper", "@syncfusion/ej2-svg-base", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1, helper_1, helper_2, ej2_svg_base_1, ej2_base_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RangeSlider = (function () {
        function RangeSlider(range) {
            this.control = range;
            this.points = [];
            this.isIOS = ej2_base_1.Browser.isIos || ej2_base_1.Browser.isIos7;
            var thumb = range.navigatorStyleSettings.thumb;
            this.thumbVisible = (range.themeStyle.thumbWidth !== 0 && range.themeStyle.thumbHeight !== 0);
            this.elementId = range.element.id;
            this.thumpPadding = range.themeStyle.thumbWidth / 2;
            this.addEventListener();
            this.thumbColor = range.disableRangeSelector ? 'transparent' :
                (thumb.fill || range.themeStyle.thumbBackground);
        }
        RangeSlider.prototype.render = function (range) {
            var renderer = range.renderer;
            var style = range.navigatorStyleSettings;
            var disabledColor = (range.disableRangeSelector) ? 'transparent' : null;
            var sliderGroup = renderer.createGroup({
                'id': this.elementId + '_sliders',
                style: (range.disableRangeSelector) ? 'pointer-events:none;' : ''
            });
            var option = new helper_1.RectOption(this.elementId + '_leftUnSelectedArea', disabledColor || style.unselectedRegionColor || range.themeStyle.unselectedRectColor, { width: 0 }, 1, {
                x: range.bounds.x, y: range.bounds.y,
                width: range.bounds.width / 3,
                height: range.bounds.height
            }, 0, 0, '', style.thumb.border.dashArray);
            this.leftUnSelectedElement = renderer.drawRectangle(option);
            option.id = this.elementId + '_rightUnSelectedArea';
            this.rightUnSelectedElement = renderer.drawRectangle(option);
            option.id = this.elementId + '_SelectedArea';
            option.fill = disabledColor || style.selectedRegionColor || range.themeStyle.selectedRegionColor;
            this.selectedElement = renderer.drawRectangle(option);
            this.selectedElement.setAttribute('role', 'region');
            this.selectedElement.setAttribute('aria-label', 'Range Slider with ' + range.rangeSlider.points.length + ' data points');
            this.selectedElement.style.cursor = '-webkit-grab';
            this.leftSlider = renderer.createGroup({
                'id': this.elementId + '_LeftSlider', 'style': 'cursor: ew-resize'
            });
            this.rightSlider = renderer.createGroup({
                'id': this.elementId + '_RightSlider', 'style': 'cursor: ew-resize'
            });
            this.createThump(renderer, range.bounds, this.leftSlider, this.elementId + '_LeftSlider', sliderGroup);
            this.createThump(renderer, range.bounds, this.rightSlider, this.elementId + '_RightSlider');
            sliderGroup.appendChild(this.leftUnSelectedElement);
            sliderGroup.appendChild(this.rightUnSelectedElement);
            sliderGroup.appendChild(this.selectedElement);
            sliderGroup.appendChild(this.leftSlider);
            sliderGroup.appendChild(this.rightSlider);
            range.svgObject.appendChild(sliderGroup);
        };
        RangeSlider.prototype.createThump = function (render, bounds, parent, id, sliderGroup) {
            var control = this.control;
            var thump = control.navigatorStyleSettings.thumb;
            var style = control.themeStyle;
            var y = bounds.y + bounds.height / 2;
            var x = this.thumpPadding;
            var tickLength = (control.themeStyle.thumbHeight / 2) - 5;
            var disabledColor = control.disableRangeSelector ? 'transparent' : null;
            var lineColor = disabledColor || thump.border.color || style.thumpLineColor;
            var shadowElement;
            parent.appendChild(render.drawPath(new ej2_svg_base_1.PathOption(id + '_ThumpLine', 'transparent', thump.border.width, control.series.length ? lineColor : 'transparent', 1, thump.border.dashArray, 'M' + ' ' + (x) + ' ' + (bounds.y) + ' ' + 'L' + ' ' + (x) + ' ' + (bounds.y + bounds.height) + ' ')));
            this.thumpY = y - (control.themeStyle.thumbHeight / 2);
            this.sliderY = bounds.y > this.thumpY ? this.thumpY : bounds.y;
            if (sliderGroup && !control.disableRangeSelector) {
                shadowElement = render.createDefs();
                shadowElement.innerText = '<rect xmlns="http://www.w3.org/2000/svg" id="' + this.control.element.id + '_shadow' + '" x="0" ' +
                    'y="' + this.thumpY + '" width="' + control.themeStyle.thumbWidth + '" height="' + control.themeStyle.thumbHeight + '"' +
                    ' rx="' + (thump.type === 'Circle' ? '50%' : '0%') + '"/>' +
                    '<filter xmlns="http://www.w3.org/2000/svg" x="-25.0%" y="-20.0%" width="150.0%" height="150.0%"' +
                    ' filterUnits="objectBoundingBox" id="ej2-range-shadow"><feOffset dx="0" dy="1" in="SourceAlpha"' +
                    'result="shadowOffsetOuter1"/><feGaussianBlur stdDeviation="1.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"/>' +
                    '<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"/>' +
                    '<feColorMatrix values="0 0 0 0 0   0 0 0 0 0   0 0 0 0 0  0 0 0 0.16 0" type="matrix" in="shadowBlurOuter1"/>' +
                    '</filter>';
                sliderGroup.appendChild(shadowElement);
            }
            parent.innerText += '<use xmlns="http://www.w3.org/2000/svg" fill="black" fill-opacity="1" filter="url(#ej2-range-shadow)"' +
                ' xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#path-1"/>';
            if (thump.type === 'Circle') {
                parent.appendChild(helper_1.drawSymbol({ x: x, y: y }, 'Circle', { width: control.themeStyle.thumbWidth, height: control.themeStyle.thumbHeight }, '', new ej2_svg_base_1.PathOption(id + '_ThumpSymbol', disabledColor || this.thumbColor, thump.border.width, lineColor, 1, null), 'Thumb'));
            }
            else {
                parent.appendChild(render.drawRectangle(new helper_1.RectOption(id + '_ThumpSymbol', disabledColor || this.thumbColor, { width: thump.border.width, color: lineColor }, 1, {
                    x: x - (control.themeStyle.thumbWidth / 2), y: y - (control.themeStyle.thumbHeight / 2),
                    width: control.themeStyle.thumbWidth,
                    height: control.themeStyle.thumbHeight
                }, 2, 2, '', thump.border.dashArray)));
            }
            Eif (this.thumbVisible) {
                parent.appendChild(render.drawPath(new ej2_svg_base_1.PathOption(id + '_ThumpGrip', 'transparent', 1, disabledColor || control.themeStyle.gripColor, 1, null, 'M' + ' ' + (x + 2) + ' ' + (y + tickLength) + ' ' + 'L' + ' ' + (x + 2) + ' ' + (y - tickLength) + ' ' +
                    ((this.control.theme.indexOf('Fluent2') > -1 || this.control.theme.indexOf('Bootstrap5') > -1) ? '' : 'M' + ' ' + (x) + ' ' + (y + tickLength) + ' ' + 'L' + ' ' + (x) + ' ' + (y - tickLength) + ' ') +
                    'M' + ' ' + (x - 2) + ' ' + (y + tickLength) + ' ' + 'L' + ' ' + (x - 2) + ' ' + (y - tickLength) + ' ')));
            }
        };
        RangeSlider.prototype.setSlider = function (start, end, trigger, showTooltip, resize) {
            if (resize === void 0) { resize = false; }
            var range = this.control;
            var padding = range.bounds.x;
            var axisRange = range.chartSeries.xAxis.actualRange;
            var isLeightWeight = range.series.length === 0;
            if (isNaN(start) && isNaN(end)) {
                start = 0;
                end = range.bounds.width;
            }
            if (!(end >= start)) {
                start = [end, end = start][0];
            }
            start = end >= start ? start : [end, end = start][0];
            start = Math.max(start, axisRange.min);
            end = Math.min(end, axisRange.max);
            this.startX = padding + helper_2.getXLocation(start, axisRange, range.bounds.width, range.enableRtl);
            this.endX = padding + helper_2.getXLocation(end, axisRange, range.bounds.width, range.enableRtl);
            var selectedX = range.enableRtl ? this.endX : this.startX;
            var rightPadding = range.enableRtl ? this.startX : this.endX;
            this.sliderWidth = Math.abs(this.endX - this.startX);
            this.selectedElement.setAttribute('x', (selectedX) + '');
            this.selectedElement.setAttribute('width', this.sliderWidth + '');
            this.leftUnSelectedElement.setAttribute('width', (selectedX - padding) + '');
            this.rightUnSelectedElement.setAttribute('x', rightPadding + '');
            this.rightUnSelectedElement.setAttribute('width', (range.bounds.width - (rightPadding - padding)) + '');
            this.leftSlider.setAttribute('transform', 'translate(' + (this.startX - this.thumpPadding) + ', 0)');
            this.rightSlider.setAttribute('transform', 'translate(' + (this.endX - this.thumpPadding) + ', 0)');
            var left = this.control.svgObject.getBoundingClientRect().left -
                this.control.element.getBoundingClientRect().left;
            var leftX = this.control.enableRtl ? this.endX : this.startX;
            var rightX = this.control.enableRtl ? this.startX : this.endX;
            this.leftRect = {
                x: isLeightWeight ? left + padding : padding,
                y: isLeightWeight ? 0 : range.bounds.y,
                width: isLeightWeight ? leftX - padding : leftX,
                height: isLeightWeight ? this.thumpY : range.bounds.height
            };
            this.rightRect = {
                x: isLeightWeight ? left + rightX : rightX,
                y: isLeightWeight ? 0 : range.bounds.y,
                width: (range.bounds.width - (rightPadding - padding)),
                height: isLeightWeight ? this.thumpY : range.bounds.height
            };
            this.midRect = {
                x: isLeightWeight ? leftX + left : 0,
                y: isLeightWeight ? 0 : range.bounds.y,
                width: isLeightWeight ? Math.abs(this.endX - this.startX) : rightX,
                height: isLeightWeight ? this.thumpY : range.bounds.height
            };
            this.currentStart = start;
            this.currentEnd = end;
            if (showTooltip) {
                this.control.rangeTooltipModule.renderLeftTooltip(this);
                this.control.rangeTooltipModule.renderRightTooltip(this);
            }
            var periodSelectorModule = this.control.periodSelectorModule;
            Iif (periodSelectorModule && this.control.redraw && (this.control.getModuleName() === 'rangeNavigator')) {
                var selectedIndex = periodSelectorModule.findSelectedIndex(start, end, periodSelectorModule.control.periods);
                periodSelectorModule.setSelectedStyle(selectedIndex);
                this.control.redraw = false;
            }
            if (trigger && !resize) {
                this.triggerEvent(axisRange);
            }
        };
        RangeSlider.prototype.triggerEvent = function (range) {
            var xAxis = this.control.chartSeries.xAxis;
            var valueType = xAxis.valueType;
            var argsData = {
                cancel: false,
                start: valueType === 'DateTime' ? new Date(this.currentStart) : valueType === 'DateTimeCategory' ? this.currentStart :
                    (valueType === 'Logarithmic' ? Math.pow(xAxis.logBase, this.currentStart) : this.currentStart),
                end: valueType === 'DateTime' ? new Date(this.currentEnd) : valueType === 'DateTimeCategory' ? this.currentEnd :
                    (valueType === 'Logarithmic' ? Math.pow(xAxis.logBase, this.currentEnd) : this.currentEnd),
                name: 'changed',
                selectedData: helper_2.getExactData(this.points, this.currentStart, this.currentEnd),
                zoomPosition: (this.control.enableRtl ? range.max - this.currentEnd :
                    this.currentStart - range.min) / range.delta,
                zoomFactor: (this.currentEnd - this.currentStart) / range.delta,
                selectedPeriod: this.selectedPeriod ? this.selectedPeriod : ''
            };
            this.control.trigger('changed', argsData);
        };
        RangeSlider.prototype.addEventListener = function () {
            Iif (this.control.isDestroyed) {
                return;
            }
            this.control.on(ej2_base_1.Browser.touchMoveEvent, this.mouseMoveHandler, this);
            this.control.on(ej2_base_1.Browser.touchStartEvent, this.mouseDownHandler, this);
            this.control.on(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler, this);
            this.control.on(ej2_base_1.Browser.isPointer ? 'pointerleave' : 'mouseleave', this.mouseCancelHandler, this);
        };
        RangeSlider.prototype.removeEventListener = function () {
            Iif (this.control.isDestroyed) {
                return;
            }
            this.control.off(ej2_base_1.Browser.touchMoveEvent, this.mouseMoveHandler);
            this.control.off(ej2_base_1.Browser.touchStartEvent, this.mouseDownHandler);
            this.control.off(ej2_base_1.Browser.touchEndEvent, this.mouseUpHandler);
            this.control.off(ej2_base_1.Browser.isPointer ? 'pointerleave' : 'mouseleave', this.mouseCancelHandler);
        };
        RangeSlider.prototype.mouseMoveHandler = function (e) {
            var control = this.control;
            var axisRange = control.chartSeries.xAxis.actualRange;
            var bounds = control.bounds;
            var start;
            var end;
            this.getCurrentSlider(e.target.id);
            if (this.isDrag && control.mouseX >= bounds.x) {
                switch (this.currentSlider) {
                    case 'Left':
                        control.startValue = this.getRangeValue(Math.abs(control.mouseX - bounds.x));
                        break;
                    case 'Right':
                        control.endValue = this.getRangeValue(Math.abs(control.mouseX - bounds.x));
                        break;
                    case 'Middle': {
                        start = Math.max(this.getRangeValue(Math.abs(this.startX - (this.previousMoveX - control.mouseX) - bounds.x)), axisRange.min);
                        end = Math.min(this.getRangeValue(Math.abs(this.endX - (this.previousMoveX - control.mouseX) - bounds.x)), axisRange.max);
                        var currentWidth = Math.floor(Math.abs(helper_2.getXLocation(end, axisRange, control.bounds.width, control.enableRtl) -
                            helper_2.getXLocation(start, axisRange, control.bounds.width, control.enableRtl)));
                        Eif (currentWidth === Math.floor(this.sliderWidth)) {
                            control.startValue = start;
                            control.endValue = end;
                        }
                        else {
                            if (end === axisRange.max) {
                                control.endValue = axisRange.max;
                            }
                            if (Math.floor(this.startX) === bounds.x) {
                                control.startValue = axisRange.min;
                            }
                        }
                        break;
                    }
                }
                Iif (e.preventDefault && this.isIOS) {
                    e.preventDefault();
                }
                if (this.currentSlider !== 'Middle') {
                    var periodSelectorModule = this.control.periodSelectorModule;
                    Iif (periodSelectorModule) {
                        var buttons = periodSelectorModule.control.periods;
                        buttons.map(function (period) {
                            period.selected = false;
                        });
                        periodSelectorModule.selectedIndex = undefined;
                        var selectedIndex = periodSelectorModule.findSelectedIndex(control.startValue, control.endValue, buttons);
                        periodSelectorModule.setSelectedStyle(selectedIndex);
                    }
                }
                this.setSlider(control.startValue, control.endValue, !control.enableDeferredUpdate, (control.rangeTooltipModule && control.tooltip.enable));
                this.previousMoveX = control.mouseX;
            }
        };
        RangeSlider.prototype.getRangeValue = function (x) {
            var control = this.control;
            var axisRange = control.chartSeries.xAxis.actualRange;
            var bounds = control.bounds;
            return helper_2.getRangeValueXByPoint(x, bounds.width, axisRange, control.enableRtl);
        };
        RangeSlider.prototype.mouseDownHandler = function (e) {
            this.currentSlider = this.getCurrentSlider(e.target.id);
            this.selectedElement.style.cursor = '-webkit-grabbing';
            this.isDrag = !(this.currentSlider === 'UnSelectedArea' || !this.currentSlider);
            this.previousMoveX = this.control.mouseDownX;
        };
        RangeSlider.prototype.getCurrentSlider = function (id) {
            var hoverColor = this.control.themeStyle.thumbHoverColor;
            if (id.indexOf(this.elementId + '_LeftSlider') > -1) {
                this.leftSlider.childNodes[2].setAttribute('fill', hoverColor);
                return 'Left';
            }
            else if (id.indexOf(this.elementId + '_RightSlider') > -1) {
                this.rightSlider.childNodes[2].setAttribute('fill', hoverColor);
                return 'Right';
            }
            else if (id.indexOf(this.elementId + '_SelectedArea') > -1) {
                return 'Middle';
            }
            else if (id.indexOf('UnSelectedArea') > -1) {
                this.leftSlider.childNodes[2].setAttribute('fill', this.thumbColor);
                this.rightSlider.childNodes[2].setAttribute('fill', this.thumbColor);
                return 'UnSelectedArea';
            }
            else if (id.indexOf(this.elementId + '_AxisLabel_') > -1 && (this.control.valueType === 'DateTime' || this.control.valueType === 'DateTimeCategory')) {
                this.labelIndex = +id.substring(id.lastIndexOf('_') + 1, id.length);
                return 'firstLevelLabels';
            }
            else if (id.indexOf(this.elementId + '_SecondaryLabel') > -1 && (this.control.valueType === 'DateTime' || this.control.valueType === 'DateTimeCategory')) {
                this.labelIndex = +id.substring(id.lastIndexOf('_') + 1, id.length);
                return 'secondLevelLabels';
            }
            else {
                this.leftSlider.childNodes[2].setAttribute('fill', this.thumbColor);
                this.rightSlider.childNodes[2].setAttribute('fill', this.thumbColor);
                Iif (this.control.periodSelectorModule) {
                    this.control.periodSelectorModule.triggerChange = true;
                }
                return null;
            }
        };
        RangeSlider.prototype.mouseUpHandler = function () {
            var control = this.control;
            var range = control.chartSeries.xAxis.actualRange;
            var trigger = control.enableDeferredUpdate;
            var enabledTooltip = control.tooltip.enable;
            Iif (control.stockChart) {
                control.stockChart.zoomChange = false;
            }
            if (this.currentSlider === 'UnSelectedArea') {
                var value = void 0;
                var start = void 0;
                var end = void 0;
                var isRtl = control.enableRtl;
                var difference = control.endValue - control.startValue;
                if (control.mouseDownX < this.startX) {
                    value = Math.max(this.getRangeValue((control.mouseDownX - (this.sliderWidth / 2) - control.bounds.x)), range.min);
                    end = isRtl ? value : (value + difference);
                    start = isRtl ? (value - difference) : value;
                }
                else {
                    value = Math.min(this.getRangeValue((control.mouseDownX + (this.sliderWidth / 2) - control.bounds.x)), range.max);
                    start = isRtl ? value : (value - difference);
                    end = isRtl ? (value + difference) : value;
                }
                this.performAnimation(start, end, control);
                trigger = false;
            }
            else if (this.currentSlider === 'firstLevelLabels' || this.currentSlider === 'secondLevelLabels') {
                var secondLabel = control.rangeAxis[this.currentSlider][this.labelIndex + 1];
                Iif (this.selectedPeriod) {
                    var periodSelectorModule = this.control.periodSelectorModule;
                    if (periodSelectorModule) {
                        var buttons = periodSelectorModule.control.periods;
                        buttons.map(function (period) {
                            period.selected = false;
                        });
                        periodSelectorModule.selectedIndex = undefined;
                        var selectedIndex = periodSelectorModule.findSelectedIndex(control.rangeAxis[this.currentSlider][this.labelIndex].value, (secondLabel ? (control.allowIntervalData ?
                            secondLabel.value - 1 : secondLabel.value) : range.max), buttons);
                        periodSelectorModule.setSelectedStyle(selectedIndex);
                    }
                }
                this.performAnimation(control.rangeAxis[this.currentSlider][this.labelIndex].value, (secondLabel ? (control.allowIntervalData ? secondLabel.value - 1 : secondLabel.value) : range.max), control);
                trigger = false;
            }
            else if (this.currentSlider === null) {
                trigger = false;
            }
            if (this.isDrag && control.allowSnapping) {
                this.setAllowSnapping(control, this.currentStart, this.currentEnd, true, enabledTooltip);
                trigger = false;
            }
            if (trigger) {
                this.setSlider(this.currentStart, this.currentEnd, true, enabledTooltip);
            }
            if (this.currentSlider !== null) {
                if (this.control.periodSelectorSettings.periods.length > 0) {
                    this.control.periodSelectorModule.triggerChange = false;
                    this.control.periodSelectorModule.datePicker.startDate = this.control.periodSelectorModule.isDatetimeCategory ?
                        new Date(this.control.periodSelectorModule.sortedData[Math.floor(this.currentStart)]) : new Date(this.currentStart);
                    this.control.periodSelectorModule.datePicker.endDate = this.control.periodSelectorModule.isDatetimeCategory ?
                        new Date(this.control.periodSelectorModule.sortedData[Math.floor(this.currentEnd)]) : new Date(this.currentEnd);
                }
            }
            this.selectedElement.style.cursor = '-webkit-grab';
            control.startValue = this.currentStart;
            control.endValue = this.currentEnd;
            this.isDrag = false;
            this.labelIndex = null;
            this.currentSlider = null;
        };
        RangeSlider.prototype.setAllowSnapping = function (control, start, end, trigger, tooltip) {
            var values = control.rangeAxis.lowerValues;
            values.push(control.chartSeries.xAxis.actualRange.max);
            this.setSlider(helper_2.getNearestValue(values, start), helper_2.getNearestValue(values, end), trigger, tooltip);
            control.startValue = this.currentStart;
            control.endValue = this.currentEnd;
        };
        RangeSlider.prototype.performAnimation = function (start, end, control) {
            var _this = this;
            var currentStart = this.currentStart;
            var currentEnd = this.currentEnd;
            var isDeffered = control.enableDeferredUpdate;
            var enableTooltip = control.tooltip.enable;
            new ej2_base_2.Animation({}).animate(ej2_base_1.createElement('div'), {
                duration: (this.control.animationDuration === 0 && ej2_base_1.animationMode === 'Enable') ? 1000 : this.control.animationDuration,
                progress: function (args) {
                    _this.setSlider(helper_1.linear(args.timeStamp, 0, start - currentStart, args.duration) + currentStart, helper_1.linear(args.timeStamp, 0, end - currentEnd, args.duration) + currentEnd, !isDeffered, enableTooltip);
                },
                end: function () {
                    if (control.allowSnapping) {
                        _this.setAllowSnapping(control, start, end, true, enableTooltip);
                    }
                    else {
                        _this.setSlider(start, end, true, enableTooltip);
                    }
                    _this.control.startValue = _this.currentStart;
                    _this.control.endValue = _this.currentEnd;
                    if (_this.control.periodSelectorSettings.periods.length > 0) {
                        _this.control.periodSelectorModule.triggerChange = false;
                        _this.control.periodSelectorModule.datePicker.startDate = _this.control.periodSelectorModule.isDatetimeCategory ?
                            new Date(_this.control.periodSelectorModule.sortedData[Math.floor(_this.currentStart)]) : new Date(_this.currentStart);
                        _this.control.periodSelectorModule.datePicker.endDate = _this.control.periodSelectorModule.isDatetimeCategory ?
                            new Date(_this.control.periodSelectorModule.sortedData[Math.floor(_this.currentEnd)]) : new Date(_this.currentEnd);
                    }
                }
            });
        };
        RangeSlider.prototype.mouseCancelHandler = function () {
            Iif (this.isDrag && this.control.allowSnapping) {
                this.setAllowSnapping(this.control, this.currentStart, this.currentEnd, false, this.control.tooltip.enable);
            }
            this.isDrag = false;
            this.currentSlider = null;
            this.control.startValue = this.currentStart;
            this.control.endValue = this.currentEnd;
        };
        RangeSlider.prototype.destroy = function () {
            this.removeEventListener();
        };
        return RangeSlider;
    }());
    exports.RangeSlider = RangeSlider;
});