all files / chart/series/ multi-colored-base.js

95.04% Statements 134/141
88.89% Branches 120/135
100% Functions 22/22
94.93% Lines 131/138
11 statements, 6 functions, 9 branches Ignored     
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          179×   29365× 29365× 29365× 14943× 14943×   29365×   14× 14× 14× 14×   663× 269× 269× 269× 304× 304× 304×   159× 159×     269× 75×   269×     394× 354×     40×       52× 52× 52× 52× 33×     52× 52× 34× 336×   34×   18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 36× 36× 36×   36× 35× 39× 39×                   39×   39×     37×   39× 39× 37×         18× 18× 36×     18×   10×     22× 22×     22×     22×                             36× 36× 36× 36×   36× 36×     35×             35× 35×   35×     434× 74×   434× 39× 39×   395× 73×     73×     322×          
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../../common/utils/helper", "./line-base", "../../common/utils/helper", "@syncfusion/ej2-data"], function (require, exports, helper_1, line_base_1, helper_2, ej2_data_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var MultiColoredSeries = (function (_super) {
        __extends(MultiColoredSeries, _super);
        function MultiColoredSeries() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        MultiColoredSeries.prototype.getAreaPathDirection = function (xValue, yValue, series, isInverted, getPointLocation, startPoint, startPath) {
            var direction = '';
            var firstPoint;
            if (startPoint === null) {
                firstPoint = getPointLocation(xValue, yValue, series.xAxis, series.yAxis, isInverted, series);
                direction += (startPath + ' ' + (firstPoint.x) + ' ' + (firstPoint.y) + ' ');
            }
            return direction;
        };
        MultiColoredSeries.prototype.getAreaEmptyDirection = function (firstPoint, secondPoint, series, isInverted, getPointLocation) {
            var direction = '';
            direction += this.getAreaPathDirection(firstPoint.x, firstPoint.y, series, isInverted, getPointLocation, null, 'L');
            direction += this.getAreaPathDirection(secondPoint.x, secondPoint.y, series, isInverted, getPointLocation, null, 'L');
            return direction;
        };
        MultiColoredSeries.prototype.setPointColor = function (currentPoint, previous, series, isXSegment, segments) {
            if (series.pointColorMapping === '') {
                var segment = void 0;
                var value = void 0;
                for (var i = 0; i < segments.length; i++) {
                    segment = segments[i];
                    value = isXSegment ? currentPoint.xValue : currentPoint.yValue;
                    if (value <= this.getAxisValue(segment.value, isXSegment ? series.xAxis : series.yAxis, series.chart) ||
                        (!segment.value && segment.value !== 0)) {
                        currentPoint.interior = segment.color;
                        break;
                    }
                }
                if (currentPoint.interior == null) {
                    currentPoint.interior = series.interior;
                }
                return false;
            }
            else {
                if (previous) {
                    return series.setPointColor(currentPoint, series.interior) !== series.setPointColor(previous, series.interior);
                }
                else {
                    return false;
                }
            }
        };
        MultiColoredSeries.prototype.sortSegments = function (series, chartSegments) {
            var _this = this;
            var axis = series.segmentAxis === 'X' ? series.xAxis : series.yAxis;
            var segments = [].concat(chartSegments);
            return segments.sort(function (a, b) {
                return _this.getAxisValue(a.value, axis, series.chart) - _this.getAxisValue(b.value, axis, series.chart);
            });
        };
        MultiColoredSeries.prototype.applySegmentAxis = function (series, options, segments, pointAnimate) {
            var _this = this;
            if (series.pointColorMapping !== '') {
                options.map(function (option) {
                    _this[pointAnimate ? 'addMulticolorPath' : 'appendLinePath'](option, series, '');
                });
                return null;
            }
            var isXSegment = series.segmentAxis === 'X';
            var axis = isXSegment ? series.xAxis : series.yAxis;
            var chart = series.chart;
            var segment;
            this.includeSegment(segments, axis, series, segments.length);
            var length = segments.length;
            var value;
            var clipPath;
            var attributeOptions;
            var areaBorderCount = 0;
            var _loop_1 = function (index) {
                segment = segments[index];
                value = this_1.getAxisValue(segment.value, axis, series.chart);
                clipPath = this_1.createClipRect(index ? this_1.getAxisValue(segments[index - 1].value, axis, series.chart)
                    : axis.visibleRange.min, value, series, index, isXSegment);
                if (clipPath) {
                    options.map(function (option) {
                        areaBorderCount += 1;
                        attributeOptions = {
                            'clip-path': clipPath,
                            'stroke-dasharray': segment.dashArray,
                            'opacity': option.opacity,
                            'stroke': series.type.indexOf('Line') > -1 ? segment.color || series.interior : option['stroke'],
                            'stroke-width': option['stroke-width'],
                            'fill': series.type.indexOf('Line') > -1 ? 'none' : segment.color || series.interior,
                            'id': option.id + '_Segment_' + index,
                            'd': option.d
                        };
                        if (areaBorderCount % 2 === 0 && _this.chart.multiColoredAreaSeriesModule && series.border.color !== 'transparent' && attributeOptions['stroke-width'] !== 0) {
                            attributeOptions.fill = 'transparent';
                        }
                        if (pointAnimate) {
                            _this.addMulticolorPath(attributeOptions, series, '', true);
                        }
                        else {
                            helper_1.pathAnimation(helper_2.getElement(attributeOptions.id), attributeOptions.d, chart.redraw);
                        }
                        series.pathElement = chart.renderer.drawPath(attributeOptions);
                        if (!series.chart.enableCanvas && !pointAnimate) {
                            series.seriesElement.appendChild(chart.renderer.drawPath(attributeOptions));
                        }
                    });
                }
            };
            var this_1 = this;
            for (var index = 0; index < length; index++) {
                _loop_1(index);
            }
        };
        MultiColoredSeries.prototype.includeSegment = function (segments, axis, series, length) {
            if (length <= 0) {
                segments.push({ value: axis.visibleRange.max, color: series.interior });
                return null;
            }
            if (this.getAxisValue(segments[length - 1].value, axis, series.chart) < axis.visibleRange.max) {
                segments.push({ value: axis.visibleRange.max, color: series.interior });
            }
        };
        MultiColoredSeries.prototype.addMulticolorPath = function (options, series, clipRect, isSegnment) {
            var points = this.appendPathElement(options, series, clipRect);
            Iif (points.previousDirection === null || points.previousDirection === '') {
                points.previousDirection = 'M ' + (options.d).split(' ').slice(-3)[0] + ' ' + (options.d).split(' ').slice(-5)[0] + ' L ' + (options.d).split(' ').slice(-3)[0] + ' ' + (options.d).split(' ').slice(-5)[0] + ' L ' + (options.d).split(' ').slice(-3)[0] + ' ' + (options.d).split(' ').slice(-5)[0];
            }
            Iif (options.d === null || options.d === '') {
                options.d = 'M ' + (points.previousDirection).split(' ').slice(-3)[0] + ' ' + (points.previousDirection).split(' ').slice(-5)[0] + ' L ' + (points.previousDirection).split(' ').slice(-3)[0] + ' ' + (points.previousDirection).split(' ').slice(-5)[0];
            }
            if (isSegnment) {
                var startPathCommands = points.previousDirection.match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g);
                var endPathCommands = (options.d).match(/[MLHVCSQTAZ][^MLHVCSQTAZ]*/g);
                var maxLength = Math.max(startPathCommands.length, endPathCommands.length);
                var minLength = Math.min(startPathCommands.length, endPathCommands.length);
                Iif (startPathCommands.length === endPathCommands.length) {
                    helper_1.animateAddPoints(helper_2.getElement(options.id), options.d, series.chart.redraw, points.previousDirection, this.chart.duration);
                }
                Iif (startPathCommands.length < endPathCommands.length) {
                    for (var i = minLength; i < maxLength; i++) {
                        if (endPathCommands.length !== startPathCommands.length) {
                            startPathCommands.splice(startPathCommands.length - ((series.type.indexOf('Line') !== -1) ? 1 : 2), 0, startPathCommands[startPathCommands.length - ((series.type.indexOf('Line') !== -1) ? 1 : 2)]);
                        }
                    }
                    helper_1.animateAddPoints(helper_2.getElement(options.id), options.d, series.chart.redraw, startPathCommands.join(' '), this.chart.duration);
                }
                Eif (startPathCommands.length > endPathCommands.length) {
                    for (var i = minLength; i < maxLength; i++) {
                        Eif (endPathCommands.length !== startPathCommands.length) {
                            endPathCommands.splice(1, 0, endPathCommands[1].replace('M', 'L'));
                        }
                    }
                    helper_1.animateAddPoints(points.element, endPathCommands.join(''), series.chart.redraw, startPathCommands.join(''), this.chart.duration, options.d);
                }
            }
        };
        MultiColoredSeries.prototype.createClipRect = function (startValue, endValue, series, index, isX) {
            var isRequired = series.chart.requireInvertedAxis;
            var startPointLocation = helper_1.getPoint(isX ? startValue : series.xAxis.visibleRange.min, isX ? series.yAxis.visibleRange.max : endValue, series.xAxis, series.yAxis, isRequired);
            var endPointLocation = helper_1.getPoint(isX ? endValue : series.xAxis.visibleRange.max, isX ? series.yAxis.visibleRange.min : startValue, series.xAxis, series.yAxis, isRequired);
            endPointLocation = isRequired ?
                [startPointLocation, startPointLocation = endPointLocation][0] : endPointLocation;
            var options;
            if (((series.xAxis.isInversed || series.xAxis.isAxisInverse) ?
                startPointLocation.x - endPointLocation.x > 0 : endPointLocation.x - startPointLocation.x > 0) &&
                (series.yAxis.isInversed ? startPointLocation.y - endPointLocation.y > 0 : endPointLocation.y - startPointLocation.y > 0)) {
                options = new helper_2.RectOption(series.chart.element.id + '_ChartSegment' + series.index + 'ClipRect_' + index, 'transparent', { width: 1, color: 'Gray' }, 1, {
                    x: (series.xAxis.isInversed || series.xAxis.isAxisInverse) ? endPointLocation.x : startPointLocation.x,
                    y: series.yAxis.isInversed ? endPointLocation.y : startPointLocation.y,
                    width: (series.xAxis.isInversed || series.xAxis.isAxisInverse) ? startPointLocation.x - endPointLocation.x :
                        endPointLocation.x - startPointLocation.x,
                    height: series.yAxis.isInversed ? startPointLocation.y - endPointLocation.y : endPointLocation.y - startPointLocation.y
                });
                Eif (!series.chart.enableCanvas) {
                    series.seriesElement.appendChild(helper_1.appendClipElement(series.chart.redraw, options, series.chart.renderer));
                }
                return 'url(#' + series.chart.element.id + '_ChartSegment' + series.index + 'ClipRect_' + index + ')';
            }
            return null;
        };
        MultiColoredSeries.prototype.getAxisValue = function (segmentValue, axis, chart) {
            if (segmentValue === null) {
                segmentValue = axis.visibleRange.max;
            }
            if (axis.valueType === 'DateTime') {
                var option = { skeleton: 'full', type: 'dateTime' };
                return Date.parse(chart.intl.getDateParser(option)(chart.intl.getDateFormat(option)(new Date(ej2_data_1.DataUtil.parse.parseJson({ val: segmentValue }).val))));
            }
            else if (axis.valueType.indexOf('Category') > -1) {
                var xValue = axis.valueType === 'DateTimeCategory' ?
                    (segmentValue.getTime()).toString() :
                    segmentValue;
                return (axis.labels.indexOf(xValue) < 0) ? +segmentValue : axis.labels.indexOf(xValue);
            }
            else {
                return +segmentValue;
            }
        };
        return MultiColoredSeries;
    }(line_base_1.LineBase));
    exports.MultiColoredSeries = MultiColoredSeries;
});