all files / chart3d/axis/ cartesian-panel.js

95.39% Statements 207/217
89.71% Branches 61/68
100% Functions 16/16
95.39% Lines 207/217
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   691×   749× 749× 749× 749× 749× 749× 749× 749× 749× 749× 749× 749× 749×   749× 749× 749× 749× 749× 749× 749× 749× 749× 749× 749×     1498× 1498× 1498× 1516× 1516× 1516× 1516× 1516× 1516× 1516× 1434×   1516× 170×       1498× 1498× 1498× 1516× 1516× 1516× 1516× 1516× 1516× 1516× 1486×   1516× 24×       3032× 3172× 3172× 3172× 3172×   3032× 202×   3032× 2926×     1498× 1498× 1498× 1498× 1498× 1498× 1498× 1498× 1498× 1498× 1498× 1498× 1498× 1516× 1516× 1516× 1516× 1646× 1646× 1646× 1642× 1642× 1642×       1642× 1642×   1642×   1646× 176× 176× 176×     1470× 1470× 1470×       1498× 1498× 1516× 1516× 1516× 1516× 1526× 1526× 1526× 1522× 1522× 1522×   1522× 1522× 1522×   1526× 32× 32× 32×     1494× 1494× 1494×         696× 696× 696× 696× 696× 696× 696× 1469× 1469× 763× 763× 763× 763× 763× 763×         763×     706× 706× 706× 706× 706× 706×         706×   1469× 1469×     3164×   3164×   1469× 1536× 1469× 1469×       3032× 3032× 6204× 3172×     3032×   706× 706× 706× 706×   763× 763× 763× 763×   2996× 2996× 2996× 2996× 2996× 2996× 3032× 3032× 3032×         3032× 3032× 3032× 3032× 3032×     2996× 2996× 2996× 2996× 2996× 2996× 3032× 3032× 3032×         3032× 3032× 3032× 3032× 3032×          
define(["require", "exports", "../../common/utils/helper", "../../common/utils/helper", "../../common/utils/helper", "@syncfusion/ej2-svg-base"], function (require, exports, helper_1, helper_2, helper_3, ej2_svg_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var axisPadding = 10;
    var CartesianAxisLayoutPanel = (function () {
        function CartesianAxisLayoutPanel(chartModule) {
            this.chart = chartModule;
        }
        CartesianAxisLayoutPanel.prototype.measureAxis = function (rect) {
            var chart = this.chart;
            this.seriesClipRect = new ej2_svg_base_1.Rect(rect.x, rect.y, rect.width, rect.height);
            this.initialClipRect = rect;
            this.leftSize = 0;
            this.rightSize = 0;
            this.topSize = 0;
            this.bottomSize = 0;
            this.measureRowAxis(chart, this.initialClipRect);
            this.initialClipRect = helper_1.subtractThickness(this.initialClipRect, new helper_3.Thickness(this.leftSize, this.rightSize, 0, 0));
            this.measureColumnAxis(chart, this.initialClipRect);
            this.initialClipRect = helper_1.subtractThickness(this.initialClipRect, new helper_3.Thickness(0, 0, this.topSize, this.bottomSize));
            Eif (!this.chart.delayRedraw) {
                this.calculateAxisSize(this.initialClipRect);
            }
            this.leftSize = 0;
            this.rightSize = 0;
            this.topSize = 0;
            this.bottomSize = 0;
            this.measureRowAxis(chart, this.initialClipRect);
            this.seriesClipRect = helper_1.subtractThickness(this.seriesClipRect, new helper_3.Thickness(this.leftSize, this.rightSize, 0, 0));
            this.measureColumnAxis(chart, this.initialClipRect);
            this.seriesClipRect = helper_1.subtractThickness(this.seriesClipRect, new helper_3.Thickness(0, 0, this.topSize, this.bottomSize));
            Eif (!this.chart.delayRedraw) {
                chart.refreshAxis();
                this.calculateAxisSize(this.seriesClipRect);
            }
        };
        CartesianAxisLayoutPanel.prototype.measureRowAxis = function (chart, rect) {
            var row;
            this.calculateRowSize(rect);
            for (var _i = 0, _a = chart.rows; _i < _a.length; _i++) {
                var item = _a[_i];
                row = item;
                row.nearSizes = [];
                row.farSizes = [];
                this.arrangeAxis(row);
                this.measureDefinition(row, chart, new ej2_svg_base_1.Size(chart.availableSize.width, row.computedHeight));
                if (this.leftSize < helper_1.sum(row.nearSizes)) {
                    this.leftSize = helper_1.sum(row.nearSizes);
                }
                if (this.rightSize < helper_1.sum(row.farSizes)) {
                    this.rightSize = helper_1.sum(row.farSizes);
                }
            }
        };
        CartesianAxisLayoutPanel.prototype.measureColumnAxis = function (chart, rect) {
            var column;
            this.calculateColumnSize(rect);
            for (var _i = 0, _a = chart.columns; _i < _a.length; _i++) {
                var item = _a[_i];
                column = item;
                column.farSizes = [];
                column.nearSizes = [];
                this.arrangeAxis(column);
                this.measureDefinition(column, chart, new ej2_svg_base_1.Size(column.computedWidth, chart.availableSize.height));
                if (this.bottomSize < helper_1.sum(column.nearSizes)) {
                    this.bottomSize = helper_1.sum(column.nearSizes);
                }
                if (this.topSize < helper_1.sum(column.farSizes)) {
                    this.topSize = helper_1.sum(column.farSizes);
                }
            }
        };
        CartesianAxisLayoutPanel.prototype.measureDefinition = function (definition, chart, size) {
            for (var _i = 0, _a = definition.axes; _i < _a.length; _i++) {
                var axis = _a[_i];
                axis.getModule(chart);
                axis.baseModule.calculateRangeAndInterval(size, axis);
                definition.computeSize(axis, chart);
            }
            if (definition.farSizes.length > 0) {
                definition.farSizes[definition.farSizes.length - 1] -= axisPadding;
            }
            if (definition.nearSizes.length > 0) {
                definition.nearSizes[definition.nearSizes.length - 1] -= axisPadding;
            }
        };
        CartesianAxisLayoutPanel.prototype.calculateAxisSize = function (rect) {
            var chart = this.chart;
            var row;
            var column;
            var definition;
            var axis;
            var nearCount = 0;
            var farCount = 0;
            var size = 0;
            var x;
            var y;
            var axisOffset;
            this.calculateRowSize(rect);
            for (var i = 0, len = chart.rows.length; i < len; i++) {
                row = chart.rows[i];
                nearCount = 0;
                farCount = 0;
                for (var j = 0, len_1 = row.axes.length; j < len_1; j++) {
                    axis = row.axes[j];
                    axisOffset = axis.plotOffset;
                    if (axis.rect.height === 0) {
                        axis.rect.height = row.computedHeight;
                        size = 0;
                        for (var k = i + 1, len_2 = i + axis.span; k < len_2; k++) {
                            definition = chart.rows[k];
                            size += definition.computedHeight;
                        }
                        axis.rect.y = (row.computedTop - size) + (axis.plotOffsetTop ? axis.plotOffsetTop : axisOffset);
                        axis.rect.height = (axis.rect.height + size) -
                            (this.getAxisOffsetValue(axis.plotOffsetTop, axis.plotOffsetBottom, axis.plotOffset));
                        axis.rect.width = 0;
                    }
                    if (axis.isAxisOpposedPosition) {
                        x = rect.x + rect.width + helper_1.sum(helper_2.subArray(row.farSizes, farCount));
                        axis.rect.x = axis.rect.x >= x ? axis.rect.x : x;
                        farCount++;
                    }
                    else {
                        x = rect.x - helper_1.sum(helper_2.subArray(row.nearSizes, nearCount));
                        axis.rect.x = axis.rect.x <= x ? axis.rect.x : x;
                        nearCount++;
                    }
                }
            }
            this.calculateColumnSize(rect);
            for (var i = 0, len = chart.columns.length; i < len; i++) {
                column = chart.columns[i];
                nearCount = 0;
                farCount = 0;
                for (var j = 0, len_3 = column.axes.length; j < len_3; j++) {
                    axis = column.axes[j];
                    axisOffset = axis.plotOffset;
                    if (axis.rect.width === 0) {
                        for (var k = i, len_4 = (i + axis.span); k < len_4; k++) {
                            definition = chart.columns[k];
                            axis.rect.width += definition.computedWidth;
                        }
                        axis.rect.x = column.computedLeft + (axis.plotOffsetLeft ? axis.plotOffsetLeft : axisOffset);
                        axis.rect.width -= (this.getAxisOffsetValue(axis.plotOffsetLeft, axis.plotOffsetRight, axis.plotOffset));
                        axis.rect.height = 0;
                    }
                    if (axis.isAxisOpposedPosition) {
                        y = rect.y - helper_1.sum(helper_2.subArray(column.farSizes, farCount));
                        axis.rect.y = axis.rect.y <= y ? axis.rect.y : y;
                        farCount++;
                    }
                    else {
                        y = rect.y + rect.height + helper_1.sum(helper_2.subArray(column.nearSizes, nearCount));
                        axis.rect.y = axis.rect.y >= y ? axis.rect.y : y;
                        nearCount++;
                    }
                }
            }
        };
        CartesianAxisLayoutPanel.prototype.measure = function () {
            var chart = this.chart;
            var row;
            var column;
            var definition;
            var actualIndex;
            var span;
            for (var _i = 0, _a = chart.axisCollections; _i < _a.length; _i++) {
                var axis = _a[_i];
                if (axis.orientation === 'Vertical') {
                    chart.verticalAxes.push(axis);
                    actualIndex = this.getActualRow(axis);
                    row = chart.rows[actualIndex];
                    this.pushAxis(row, axis);
                    span = ((actualIndex + axis.span) > chart.rows.length ? chart.rows.length : (actualIndex + axis.span));
                    for (var j = actualIndex + 1; j < span; j++) {
                        definition = chart.rows[j];
                        definition.axes[row.axes.length - 1] = axis;
                        chart.rows[j] = definition;
                    }
                    chart.rows[actualIndex] = row;
                }
                else {
                    chart.horizontalAxes.push(axis);
                    actualIndex = this.getActualColumn(axis);
                    column = chart.columns[actualIndex];
                    this.pushAxis(column, axis);
                    span = ((actualIndex + axis.span) > chart.columns.length ? chart.columns.length : (actualIndex + axis.span));
                    for (var j = actualIndex + 1; j < span; j++) {
                        definition = chart.columns[j];
                        definition.axes[column.axes.length - 1] = axis;
                        chart.columns[j] = definition;
                    }
                    chart.columns[actualIndex] = column;
                }
                axis.isRTLEnabled = chart.enableRtl;
                axis.setIsInversedAndOpposedPosition();
            }
        };
        CartesianAxisLayoutPanel.prototype.getAxisOffsetValue = function (position1, position2, plotOffset) {
            var rangeOffset = position1 ? (position1 + (position2 ? position2 :
                plotOffset)) : (position2 ? position2 + plotOffset : 2 * plotOffset);
            return rangeOffset;
        };
        CartesianAxisLayoutPanel.prototype.pushAxis = function (definition, axis) {
            for (var i = 0, len = definition.axes.length; i <= len; i++) {
                if (!definition.axes[i]) {
                    definition.axes[i] = axis;
                    break;
                }
            }
        };
        CartesianAxisLayoutPanel.prototype.arrangeAxis = function (definition) {
            var axisCollection = [];
            for (var i = 0, len = definition.axes.length; i <= len; i++) {
                if (definition.axes[i]) {
                    axisCollection.push(definition.axes[i]);
                }
            }
            definition.axes = axisCollection;
        };
        CartesianAxisLayoutPanel.prototype.getActualColumn = function (axis) {
            var actualLength = this.chart.columns.length;
            var pos = axis.columnIndex;
            var result = pos >= actualLength ? actualLength - 1 : (pos < 0 ? 0 : pos);
            return result;
        };
        CartesianAxisLayoutPanel.prototype.getActualRow = function (axis) {
            var actualLength = this.chart.rows.length;
            var pos = axis.rowIndex;
            var result = pos >= actualLength ? actualLength - 1 : (pos < 0 ? 0 : pos);
            return result;
        };
        CartesianAxisLayoutPanel.prototype.calculateRowSize = function (rect) {
            var chart = this.chart;
            var row;
            var rowTop = rect.y + rect.height;
            var height = 0;
            var remainingHeight = Math.max(0, rect.height);
            for (var i = 0, len = chart.rows.length; i < len; i++) {
                row = chart.rows[i];
                Eif (row.height.indexOf('%') !== -1) {
                    height = Math.min(remainingHeight, (rect.height * parseInt(row.height, 10) / 100));
                }
                else {
                    height = Math.min(remainingHeight, parseInt(row.height, 10));
                }
                height = (i !== (len - 1)) ? height : remainingHeight;
                row.computedHeight = height;
                rowTop -= height;
                row.computedTop = rowTop;
                remainingHeight -= height;
            }
        };
        CartesianAxisLayoutPanel.prototype.calculateColumnSize = function (rect) {
            var chart = this.chart;
            var column;
            var columnLeft = rect.x;
            var width = 0;
            var remainingWidth = Math.max(0, rect.width);
            for (var i = 0, len = chart.columns.length; i < len; i++) {
                column = chart.columns[i];
                Eif (column.width.indexOf('%') !== -1) {
                    width = Math.min(remainingWidth, (rect.width * parseInt(column.width, 10) / 100));
                }
                else {
                    width = Math.min(remainingWidth, parseInt(column.width, 10));
                }
                width = (i !== (len - 1)) ? width : remainingWidth;
                column.computedWidth = width;
                column.computedLeft = columnLeft;
                columnLeft += width;
                remainingWidth -= width;
            }
        };
        return CartesianAxisLayoutPanel;
    }());
    exports.CartesianAxisLayoutPanel = CartesianAxisLayoutPanel;
});