all files / chart/user-interaction/ data-editing.js

97.78% Statements 88/90
85.07% Branches 57/67
100% Functions 10/10
97.78% Lines 88/90
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   47× 47×   24× 24× 24× 24× 24× 24× 23× 23× 23× 23× 23×         23× 23×       70× 70× 70×     70× 70× 70× 37×     33×   70× 23× 23×   23×     37× 37×     37×   36×     32×     23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23×     21× 21×   23× 23× 23×   23×   23× 23×   23× 23× 166×   23× 23× 23× 23× 23×       23×     24× 24× 23× 23×           23×   23× 23× 23×       41538×          
define(["require", "exports", "../utils/get-data", "../../common/utils/helper", "../../common/model/constants", "@syncfusion/ej2-base"], function (require, exports, get_data_1, helper_1, constants_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DataEditing = (function () {
        function DataEditing(chart) {
            this.isPointDragging = false;
            this.chart = chart;
        }
        DataEditing.prototype.pointMouseDown = function () {
            var chart = this.chart;
            var series;
            var data = new get_data_1.ChartData(chart);
            var pointData = data.getData();
            var isZooming = chart.zoomSettings.enableSelectionZooming || chart.zoomSettings.enablePinchZooming;
            if (pointData.point && (data.insideRegion || !pointData.series.isRectSeries)) {
                this.seriesIndex = pointData.series.index;
                this.pointIndex = pointData.point.index;
                series = chart.series[this.seriesIndex];
                Eif (series.dragSettings.enable && !isZooming) {
                    chart.trigger(constants_1.dragStart, {
                        series: pointData.series, seriesIndex: this.seriesIndex, pointIndex: this.pointIndex, point: pointData.point,
                        oldValue: chart.visibleSeries[this.seriesIndex].yData[this.pointIndex],
                        newValue: chart.visibleSeries[this.seriesIndex].points[this.pointIndex].yValue
                    });
                    chart.isPointMouseDown = true;
                    chart.zoomSettings.enableDeferredZooming = false;
                }
            }
        };
        DataEditing.prototype.pointMouseMove = function (event) {
            var chart = this.chart;
            var series;
            Iif (event.type === 'touchmove' && event.preventDefault) {
                event.preventDefault();
            }
            var data = new get_data_1.ChartData(chart);
            var pointData = data.getData();
            if (pointData.series.dragSettings.enable && pointData.point && (data.insideRegion || !pointData.series.isRectSeries)) {
                this.getCursorStyle(pointData);
            }
            else {
                chart.svgObject.style.cursor = 'null';
            }
            if (chart.isPointMouseDown) {
                series = chart.series[this.seriesIndex];
                if (series.type.indexOf('Spline') > -1) {
                    chart[helper_1.firstToLowerCase(series.type) + 'SeriesModule'].findSplinePoint(series);
                }
                this.pointDragging(this.seriesIndex, this.pointIndex);
            }
        };
        DataEditing.prototype.getCursorStyle = function (pointData) {
            var chart = this.chart;
            Iif (pointData.series.type.indexOf('Stacking') > -1) {
                chart.svgObject.style.cursor = '';
            }
            else if (pointData.series.type === 'Bar' && chart.isTransposed) {
                chart.svgObject.style.cursor = 'ns-resize';
            }
            else if (chart.isTransposed || pointData.series.type === 'Bar') {
                chart.svgObject.style.cursor = 'ew-resize';
            }
            else {
                chart.svgObject.style.cursor = 'ns-resize';
            }
        };
        DataEditing.prototype.pointDragging = function (si, pi) {
            var chart = this.chart;
            var yValueArray = [];
            var y;
            var ySize;
            var yValue;
            var series = chart.visibleSeries[si];
            var pointDrag = series.dragSettings;
            var xAxis = series.xAxis;
            var yAxis = series.yAxis;
            var extra = series.isRectSeries ? 1 : 0;
            var axis = helper_1.getTransform(xAxis, yAxis, chart.requireInvertedAxis);
            if (series.type === 'Bar') {
                y = chart.isTransposed ? (axis.y + axis.height) - chart.mouseY : chart.mouseX - axis.x;
                ySize = chart.isTransposed ? axis.height : axis.width;
            }
            else {
                y = chart.isTransposed ? chart.mouseX - axis.x : (axis.y + axis.height) - chart.mouseY;
                ySize = chart.isTransposed ? axis.width : axis.height;
            }
            yValue = yAxis.isAxisInverse ? (1 - (y / ySize)) : (y / ySize);
            yValue = (yValue * yAxis.visibleRange.delta) + yAxis.visibleRange.min;
            var minRange = yAxis.minimum !== null ? yAxis.visibleRange.min + extra : (ej2_base_1.isNullOrUndefined(pointDrag.minY) ?
                (yValue) : pointDrag.minY);
            var maxRange = yAxis.maximum !== null ? yAxis.visibleRange.max + extra : (ej2_base_1.isNullOrUndefined(pointDrag.maxY) ?
                (yValue) : pointDrag.maxY);
            Eif (maxRange >= yValue && minRange <= yValue) {
                series.points[pi].yValue = series.points[pi].y = chart.dragY = (yAxis.valueType === 'Logarithmic') ?
                    Math.pow(yAxis.logBase, yValue) : parseFloat(yValue.toFixed(2));
                series.points[pi].interior = pointDrag.fill;
                for (var i = 0; i < series.points.length; i++) {
                    yValueArray[i] = series.points[i].yValue;
                }
                series.yMin = Math.min.apply(null, yValueArray);
                series.yMax = Math.max.apply(null, yValueArray);
                this.isPointDragging = true;
                chart.refreshBound();
                chart.trigger(constants_1.drag, {
                    seriesIndex: si, pointIndex: pi, series: series, point: series.points[pi],
                    oldValue: chart.visibleSeries[this.seriesIndex].yData[this.pointIndex], newValue: series.points[pi].yValue
                });
                chart.zoomRedraw = false;
            }
        };
        DataEditing.prototype.pointMouseUp = function () {
            var chart = this.chart;
            if (chart.isPointMouseDown) {
                Eif (chart.series[this.seriesIndex].dragSettings.enable) {
                    chart.trigger(constants_1.dragEnd, {
                        series: chart.series[this.seriesIndex], point: chart.visibleSeries[this.seriesIndex].points[this.pointIndex],
                        seriesIndex: this.seriesIndex,
                        pointIndex: this.pointIndex, oldValue: chart.visibleSeries[this.seriesIndex].yData[this.pointIndex],
                        newValue: chart.visibleSeries[this.seriesIndex].points[this.pointIndex].yValue
                    });
                    chart.visibleSeries[this.seriesIndex].points[this.pointIndex].y =
                        chart.visibleSeries[this.seriesIndex].points[this.pointIndex].yValue;
                    chart.isPointMouseDown = false;
                    this.isPointDragging = false;
                    this.seriesIndex = this.pointIndex = undefined;
                }
            }
        };
        DataEditing.prototype.getModuleName = function () {
            return 'DataEditing';
        };
        DataEditing.prototype.destroy = function () {
        };
        return DataEditing;
    }());
    exports.DataEditing = DataEditing;
});