logitude-dashboard-library 3.2.64 → 3.2.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2150,847 +2150,1089 @@ var TableChart = function TableChart(props) {
2150
2150
  }));
2151
2151
  };
2152
2152
 
2153
- var PivotTable = React.forwardRef(function (props, comRef) {
2154
- var _useState = React.useState(),
2155
- widget = _useState[0],
2156
- setWidget = _useState[1];
2153
+ var PIVOT_DATE_DATA_CELL_CLASS = 'dl-pivot-date-data-cell';
2154
+ var getPivotDataCellClassNames = function getPivotDataCellClassNames(measure) {
2155
+ if (isPivotDateMinMaxMeasure(measure)) {
2156
+ return "dl-ag-pivot-data-cell " + PIVOT_DATE_DATA_CELL_CLASS;
2157
+ }
2157
2158
 
2158
- var _useState2 = React.useState(true),
2159
- isLoading = _useState2[0],
2160
- setIsLoading = _useState2[1];
2159
+ return 'dl-ag-pivot-data-cell';
2160
+ };
2161
+ var isPivotDateMinMaxMeasure = function isPivotDateMinMaxMeasure(measure) {
2162
+ if (!measure) return false;
2163
+ if (measure.MeasureCode !== 'Min' && measure.MeasureCode !== 'Max') return false;
2164
+ return FieldDataType.isDateOrDateTimeType(measure.MeasureFieldDataType);
2165
+ };
2161
2166
 
2162
- var widgetRefData = React.useRef(null);
2163
- var tabledata = React.useRef();
2164
- var pivotGridRef = React.useRef(null);
2167
+ var toValidDate = function toValidDate(value) {
2168
+ if (isPivotMeasureValueEmpty(value)) return null;
2169
+ var date = moment(value);
2170
+ if (!date || !date.isValid()) return null;
2171
+ return date.toDate();
2172
+ };
2165
2173
 
2166
- var _useState3 = React.useState(new PivotGridDataSource({
2167
- store: [],
2168
- fields: []
2169
- })),
2170
- dataSource = _useState3[0],
2171
- setDataSource = _useState3[1];
2174
+ var formatPivotDateMeasureValue = function formatPivotDateMeasureValue(value) {
2175
+ if (isPivotMeasureValueEmpty(value)) return '';
2176
+ var date = moment(value);
2177
+ if (!date || !date.isValid()) return '';
2178
+ return date.format('DD.MM.YYYY');
2179
+ };
2180
+ var isRowPivotField = function isRowPivotField(field) {
2181
+ return !!(field.PivotCode && field.PivotCode.indexOf('Row') !== -1);
2182
+ };
2183
+ var truncateToTwoDecimals = function truncateToTwoDecimals(value) {
2184
+ var numericValue = isNullOrUndefinedOrEmpty(value) ? 0 : Number(value);
2185
+ var safeValue = isNaN(numericValue) ? 0 : numericValue;
2186
+ var decimalParts = safeValue.toString().split('.');
2187
+ var firstPart = decimalParts[0] ? decimalParts[0] : '0';
2188
+ var secondPart = decimalParts[1] ? decimalParts[1].toString().substr(0, 2) : '0';
2189
+ return Number(firstPart + '.' + secondPart);
2190
+ };
2191
+ var isPivotMeasureValueEmpty = function isPivotMeasureValueEmpty(value) {
2192
+ return value === null || value === undefined || value === '';
2193
+ };
2194
+ var logitudeSumAgg = function logitudeSumAgg(params) {
2195
+ var values = params && params.values ? params.values : [];
2196
+ if (values.length === 0) return null;
2197
+ var total = 0;
2198
+ var hasValue = false;
2172
2199
 
2173
- React.useEffect(function () {
2174
- var _props$customChartPro;
2200
+ for (var i = 0; i < values.length; i++) {
2201
+ if (isPivotMeasureValueEmpty(values[i])) continue;
2202
+ hasValue = true;
2203
+ total += truncateToTwoDecimals(values[i]);
2204
+ }
2175
2205
 
2176
- if (props.customChartProps && props.customChartProps.widget) {
2177
- setWidget(props.customChartProps.widget);
2178
- widgetRefData.current = props.customChartProps.widget;
2179
- getPivotTableData();
2180
- }
2206
+ return hasValue ? total : null;
2207
+ };
2181
2208
 
2182
- (_props$customChartPro = props.customChartProps.dataBinding) === null || _props$customChartPro === void 0 ? void 0 : _props$customChartPro.widgetUpdated.subscribe(function (updatedWidget) {
2183
- var _widgetRefData$curren;
2209
+ var isAgGridDateMeasureTotalAggregation = function isAgGridDateMeasureTotalAggregation(params) {
2210
+ var aggParams = params;
2211
+ var rowNode = aggParams.rowNode;
2184
2212
 
2185
- if ((updatedWidget === null || updatedWidget === void 0 ? void 0 : updatedWidget.key) != ((_widgetRefData$curren = widgetRefData.current) === null || _widgetRefData$curren === void 0 ? void 0 : _widgetRefData$curren.key)) return;
2186
- setWidget(_extends({}, updatedWidget));
2187
- });
2188
- document.addEventListener("resizeStop", handleResize);
2189
- return function () {
2190
- document.removeEventListener("resizeStop", handleResize);
2191
- };
2192
- }, []);
2193
- React.useEffect(function () {
2194
- if (props.customChartProps.isInEditMode) {
2195
- var _pivotGridRef$current;
2213
+ if (rowNode && rowNode.footer) {
2214
+ return true;
2215
+ }
2196
2216
 
2197
- if (pivotGridRef.current && (_pivotGridRef$current = pivotGridRef.current) !== null && _pivotGridRef$current !== void 0 && _pivotGridRef$current.instance && pivotGridRef.current.instance.element && pivotGridRef.current.instance.element().classList) {
2198
- pivotGridRef.current.instance.element().classList.add('force-overflow-hidden');
2199
- }
2217
+ if (rowNode && rowNode.group && rowNode.leafGroup === false) {
2218
+ return true;
2219
+ }
2200
2220
 
2201
- setTimeout(function () {
2202
- var _pivotGridRef$current2;
2221
+ var colDef = aggParams.colDef || aggParams.column && aggParams.column.getColDef && aggParams.column.getColDef();
2203
2222
 
2204
- handleResize();
2223
+ if (!colDef) {
2224
+ return false;
2225
+ }
2205
2226
 
2206
- if (pivotGridRef.current && (_pivotGridRef$current2 = pivotGridRef.current) !== null && _pivotGridRef$current2 !== void 0 && _pivotGridRef$current2.instance && pivotGridRef.current.instance.element && pivotGridRef.current.instance.element().classList) {
2207
- pivotGridRef.current.instance.element().classList.remove('force-overflow-hidden');
2208
- }
2209
- }, 5);
2210
- }
2211
- }, [props.customChartProps.isInEditMode]);
2227
+ if (colDef.pivotTotalColumnIds !== undefined && colDef.pivotTotalColumnIds !== null) {
2228
+ return true;
2229
+ }
2212
2230
 
2213
- var handleResize = function handleResize() {
2214
- var _pivotGridRef$current3, _pivotGridRef$current4;
2231
+ var colId = colDef.colId || aggParams.column && aggParams.column.getColId && aggParams.column.getColId();
2232
+ return !!(colId && String(colId).indexOf('PivotRowTotal_') === 0);
2233
+ };
2215
2234
 
2216
- if (pivotGridRef.current && (_pivotGridRef$current3 = pivotGridRef.current) !== null && _pivotGridRef$current3 !== void 0 && _pivotGridRef$current3.instance && (_pivotGridRef$current4 = pivotGridRef.current) !== null && _pivotGridRef$current4 !== void 0 && _pivotGridRef$current4.instance.repaint) {
2217
- var _pivotGridRef$current5;
2235
+ var isDevExtremePivotDataCellTotalOrGrandTotal = function isDevExtremePivotDataCellTotalOrGrandTotal(cell, hasRowFields, hasColumnFields) {
2236
+ if (!cell) {
2237
+ return false;
2238
+ }
2218
2239
 
2219
- (_pivotGridRef$current5 = pivotGridRef.current) === null || _pivotGridRef$current5 === void 0 ? void 0 : _pivotGridRef$current5.instance.repaint();
2220
- }
2221
- };
2240
+ if (hasRowFields && (cell.rowType === 'T' || cell.rowType === 'GT')) {
2241
+ return true;
2242
+ }
2222
2243
 
2223
- var getPivotTableData = function getPivotTableData(widget) {
2224
- if (Session.Tenant == 0) {
2225
- tabledata.current = [];
2226
- setIsLoading(false);
2227
- return;
2228
- }
2244
+ if (hasColumnFields && (cell.columnType === 'T' || cell.columnType === 'GT')) {
2245
+ return true;
2246
+ }
2229
2247
 
2230
- var dashboardAnalyticsService = new DashboardAnalyticsService();
2231
- var widgetLoadLogger = new WidgetLoadLogger(props.customChartProps.widget, props.customChartProps.isPreviewModeActive, "PostGetPivotData");
2232
- dashboardAnalyticsService.getPivotData(props.customChartProps.widget).then(function (res) {
2233
- tabledata.current = res.data;
2234
- setPivotDataSourceFields();
2235
- setIsLoading(false);
2236
- widgetLoadLogger.log(res);
2237
- })["catch"](function (err) {
2238
- console.log("Error while Getting Pivot Table Data: ", err);
2239
- tabledata.current = null;
2240
- setPivotDataSourceFields();
2241
- setIsLoading(false);
2242
- });
2243
- };
2248
+ return false;
2249
+ };
2250
+ var isDevExtremeSummaryCellTotalOrGrandTotal = function isDevExtremeSummaryCellTotalOrGrandTotal(cell, hasRowFields, hasColumnFields) {
2251
+ if (!cell) {
2252
+ return false;
2253
+ }
2244
2254
 
2245
- var customizeCells = React.useCallback(function (e) {
2246
- if (e.cell.rowPath && e.cell.rowPath[0] === "Germany" && e.cell.columnPath && e.cell.columnPath[0] === "Export" && e.cell.columnPath[1] === "Air") {
2247
- e.cellElement.children[0].style.padding = "6px";
2248
- e.cellElement.children[0].style.borderRadius = "6px";
2249
- e.cellElement.children[0].style.backgroundColor = "#f4433673";
2250
- }
2255
+ var rowPath = cell._rowPath;
2256
+ var columnPath = cell._columnPath;
2257
+ var rowType = rowPath && rowPath[0] ? rowPath[0].type : null;
2258
+ var columnType = columnPath && columnPath[0] ? columnPath[0].type : null;
2251
2259
 
2252
- if (e.cell.rowPath && e.cell.rowPath[0] === "USA" && e.cell.columnPath && e.cell.columnPath[0] === "Import" && e.cell.columnPath[1] === "Inland") {
2253
- e.cellElement.children[0].style.padding = "6px";
2254
- e.cellElement.children[0].style.borderRadius = "6px";
2255
- e.cellElement.children[0].style.backgroundColor = "#03a9f4ad";
2256
- }
2257
- }, []);
2258
- var onCellClick = React.useCallback(function (e) {
2259
- if (e.area === 'data') {
2260
- var pivotFields = [];
2261
- e.columnFields.forEach(function (c, index) {
2262
- var fieldValue = e.cell.columnPath[index];
2260
+ if (hasRowFields && (rowType === 'T' || rowType === 'GT')) {
2261
+ return true;
2262
+ }
2263
2263
 
2264
- if (fieldValue !== undefined) {
2265
- pivotFields.push(_extends({}, c.fieldData, {
2266
- FieldValue: fieldValue
2267
- }));
2268
- }
2269
- });
2270
- e.rowFields.forEach(function (r, index) {
2271
- var fieldValue = e.cell.rowPath[index];
2264
+ if (hasColumnFields && (columnType === 'T' || columnType === 'GT')) {
2265
+ return true;
2266
+ }
2272
2267
 
2273
- if (fieldValue !== undefined) {
2274
- pivotFields.push(_extends({}, r.fieldData, {
2275
- FieldValue: fieldValue
2276
- }));
2277
- }
2278
- });
2279
- props.customChartProps.onSelectDataPoint({
2280
- MeasureFieldId: '',
2281
- Widget: props.customChartProps.widget,
2282
- MeasureCode: '',
2283
- Formula: '',
2284
- GroupById: '',
2285
- PivotFields: pivotFields
2286
- });
2287
- }
2288
- }, []);
2268
+ return false;
2269
+ };
2270
+ var isAgGridPivotDateMeasureTotalDisplayCell = function isAgGridPivotDateMeasureTotalDisplayCell(params) {
2271
+ var node = params && params.node;
2272
+ var colDef = params && params.colDef;
2289
2273
 
2290
- var getColumnNameByColumnId = function getColumnNameByColumnId(fieldName, dataField, datafieldValue) {
2291
- var data = tabledata.current.PivotData.find(function (el) {
2292
- return el[dataField] == datafieldValue;
2293
- });
2294
- return data ? ConvertStringToPascalCaseHelper(data[fieldName]) : '';
2295
- };
2274
+ if (node && node.footer) {
2275
+ return true;
2276
+ }
2296
2277
 
2297
- var SortRowAndColumnHeaders = function SortRowAndColumnHeaders(a, b, field) {
2298
- if (field.DateCode == 'Month') {
2299
- var aValue = a.value == null ? -1 : Number(a.value);
2300
- var bValue = b.value == null ? -1 : Number(b.value);
2278
+ if (node && node.group && node.leafGroup === false) {
2279
+ return true;
2280
+ }
2301
2281
 
2302
- if (aValue < bValue) {
2303
- return -1;
2304
- }
2282
+ if (!colDef) {
2283
+ return false;
2284
+ }
2305
2285
 
2306
- if (aValue > bValue) {
2307
- return 1;
2308
- }
2286
+ if (colDef.pivotTotalColumnIds !== undefined && colDef.pivotTotalColumnIds !== null) {
2287
+ return true;
2288
+ }
2309
2289
 
2310
- return 0;
2311
- } else if (field.DateCode != null) {
2312
- var _aValue = a.value == null ? '' : a.value;
2290
+ return isPivotRowGrandTotalColumnDef(colDef);
2291
+ };
2292
+ var logitudeMinAgg = function logitudeMinAgg(params) {
2293
+ if (isAgGridDateMeasureTotalAggregation(params)) {
2294
+ return null;
2295
+ }
2313
2296
 
2314
- var _bValue = b.value == null ? '' : b.value;
2297
+ var values = params && params.values ? params.values : [];
2298
+ var minDate = null;
2299
+ var minValue = null;
2315
2300
 
2316
- if (_aValue < _bValue) {
2317
- return -1;
2318
- }
2301
+ for (var i = 0; i < values.length; i++) {
2302
+ var currentDate = toValidDate(values[i]);
2303
+ if (!currentDate) continue;
2319
2304
 
2320
- if (_aValue > _bValue) {
2321
- return 1;
2322
- }
2305
+ if (!minDate || currentDate.getTime() < minDate.getTime()) {
2306
+ minDate = currentDate;
2307
+ minValue = values[i];
2308
+ }
2309
+ }
2323
2310
 
2324
- return 0;
2325
- } else {
2326
- var aText = a.text == null ? '' : a.text;
2327
- var bText = b.text == null ? '' : b.text;
2311
+ return minValue;
2312
+ };
2313
+ var logitudeMaxAgg = function logitudeMaxAgg(params) {
2314
+ if (isAgGridDateMeasureTotalAggregation(params)) {
2315
+ return null;
2316
+ }
2328
2317
 
2329
- if (aText < bText) {
2330
- return -1;
2331
- }
2318
+ var values = params && params.values ? params.values : [];
2319
+ var maxDate = null;
2320
+ var maxValue = null;
2332
2321
 
2333
- if (aText > bText) {
2334
- return 1;
2335
- }
2322
+ for (var i = 0; i < values.length; i++) {
2323
+ var currentDate = toValidDate(values[i]);
2324
+ if (!currentDate) continue;
2336
2325
 
2337
- return 0;
2326
+ if (!maxDate || currentDate.getTime() > maxDate.getTime()) {
2327
+ maxDate = currentDate;
2328
+ maxValue = values[i];
2338
2329
  }
2339
- };
2330
+ }
2340
2331
 
2341
- var setPivotDataSourceFields = function setPivotDataSourceFields() {
2342
- if (tabledata.current && tabledata.current.PivoFields && tabledata.current.PivotMeasures) {
2343
- var pivotRowsAndColumnsFields = tabledata.current.PivoFields.map(function (field) {
2344
- return {
2345
- dataField: field.PivotCode,
2346
- caption: field.DisplayName,
2347
- name: field.PivotName,
2348
- width: 100,
2349
- allowSorting: false,
2350
- allowFiltering: false,
2351
- area: field.PivotCode && field.PivotCode.includes('Row') ? 'row' : 'column',
2352
- sortingMethod: function sortingMethod(a, b) {
2353
- return SortRowAndColumnHeaders(a, b, field);
2354
- },
2355
- expanded: true,
2356
- wordWrapEnabled: true,
2357
- fieldData: {
2358
- FieldId: field.FieldId,
2359
- FieldType: field.FieldType ? field.FieldType : "Field",
2360
- FieldValue: '',
2361
- DateCode: field.DateCode
2362
- },
2363
- customizeText: function customizeText(cellInfo) {
2364
- return getColumnNameByColumnId(field.PivotName, field.PivotCode, cellInfo.value);
2365
- }
2366
- };
2367
- });
2368
- var pivotDataCellsFields = tabledata.current.PivotMeasures.map(function (measure) {
2369
- return {
2370
- dataField: measure.PivotMeasureCode,
2371
- area: 'data',
2372
- dataType: 'number',
2373
- wordWrapEnabled: true,
2374
- caption: measure.MeasureCode == 'Sum' && typeof measure.DisplayName == 'string' ? ConvertStringToPascalCaseHelper(measure.DisplayName.replace("Sum of ", "")) : ConvertStringToPascalCaseHelper(measure.DisplayName),
2375
- summaryType: 'custom',
2376
- calculateCustomSummary: function calculateCustomSummary(options) {
2377
- if (options.summaryProcess == 'calculate') {
2378
- var _value = !isNullOrUndefinedOrEmpty(options.value) ? options.value : 0;
2332
+ return maxValue;
2333
+ };
2334
+ var formatPivotMeasureValue = function formatPivotMeasureValue(value, measure) {
2335
+ if (isPivotMeasureValueEmpty(value)) return '';
2379
2336
 
2380
- var decimalParts = _value.toString().split(".");
2337
+ if (isPivotDateMinMaxMeasure(measure)) {
2338
+ return formatPivotDateMeasureValue(value);
2339
+ }
2381
2340
 
2382
- var firstPart = decimalParts[0] ? decimalParts[0] : 0;
2383
- var secondPart = decimalParts[1] ? decimalParts[1] : 0;
2384
- secondPart = secondPart.toString().substr(0, 2);
2341
+ var isInteger = isValueInteger(measure.MeasureCode, measure.MeasureFieldDataType);
2342
+ var minimumFraction = isInteger ? 0 : 2;
2343
+ return getNumberInSystemLocalFormat(value, 2, minimumFraction);
2344
+ };
2345
+ var getPivotGroupFooterLabel = function getPivotGroupFooterLabel(node, fieldCode, rawValue, lookupDisplayName) {
2346
+ if (!node || !node.footer) return '';
2385
2347
 
2386
- var _finalVal = firstPart + "." + secondPart;
2348
+ if (node.level === -1) {
2349
+ return 'Grand Total';
2350
+ }
2387
2351
 
2388
- options.value = Number(_finalVal);
2389
- options.totalValue = (!isNullOrUndefinedOrEmpty(options.totalValue) ? options.totalValue : 0) + options.value;
2390
- }
2391
- },
2392
- format: function format(value) {
2393
- var isInteger = isValueInteger(measure.MeasureCode, measure.MeasureFieldDataType);
2394
- var minimumFraction = isInteger ? 0 : 2;
2352
+ if (!fieldCode) return '';
2353
+ var displayName = lookupDisplayName(fieldCode, rawValue);
2354
+ return displayName ? displayName + " Total" : '';
2355
+ };
2356
+ var compareDimensionValues = function compareDimensionValues(aValue, bValue, dateCode, aText, bText) {
2357
+ if (dateCode === 'Month') {
2358
+ var aNumber = aValue == null ? -1 : Number(aValue);
2359
+ var bNumber = bValue == null ? -1 : Number(bValue);
2360
+ if (aNumber < bNumber) return -1;
2361
+ if (aNumber > bNumber) return 1;
2362
+ return 0;
2363
+ }
2395
2364
 
2396
- var _value = isNullOrUndefinedOrEmpty(value) ? 0 : value;
2365
+ if (dateCode != null) {
2366
+ var aCompare = aValue == null ? '' : aValue;
2367
+ var bCompare = bValue == null ? '' : bValue;
2368
+ if (aCompare < bCompare) return -1;
2369
+ if (aCompare > bCompare) return 1;
2370
+ return 0;
2371
+ }
2397
2372
 
2398
- return getNumberInSystemLocalFormat(_value, 2, minimumFraction);
2399
- }
2400
- };
2401
- });
2402
- var AllfieldsData = [].concat(pivotRowsAndColumnsFields, pivotDataCellsFields);
2403
- setDataSource(new PivotGridDataSource({
2404
- store: tabledata.current.PivotData,
2405
- fields: AllfieldsData
2406
- }));
2373
+ var aDisplay = aText == null || aText === '' ? aValue == null ? '' : aValue : aText;
2374
+ var bDisplay = bText == null || bText === '' ? bValue == null ? '' : bValue : bText;
2375
+ if (aDisplay < bDisplay) return -1;
2376
+ if (aDisplay > bDisplay) return 1;
2377
+ return 0;
2378
+ };
2379
+ var getPivotDisplayName = function getPivotDisplayName(pivotData, fieldName, dataField, dataFieldValue) {
2380
+ if (!pivotData || pivotData.length === 0) return '';
2381
+ var data = pivotData.find(function (el) {
2382
+ return el[dataField] == dataFieldValue;
2383
+ });
2384
+ return data ? ConvertStringToPascalCaseHelper(data[fieldName]) : '';
2385
+ };
2386
+ var isPivotRowGrandTotalColumnDef = function isPivotRowGrandTotalColumnDef(colDef) {
2387
+ if (!colDef || !colDef.colId) {
2388
+ return false;
2389
+ }
2390
+
2391
+ return String(colDef.colId).indexOf('PivotRowTotal_') === 0;
2392
+ };
2393
+ var isPivotRowGrandTotalGroupDef = function isPivotRowGrandTotalGroupDef(colGroupDef) {
2394
+ if (!colGroupDef) {
2395
+ return false;
2396
+ }
2397
+
2398
+ var groupId = colGroupDef.groupId || colGroupDef.colId || '';
2399
+
2400
+ if (String(groupId).indexOf('PivotRowTotal') >= 0) {
2401
+ return true;
2402
+ }
2403
+
2404
+ var children = colGroupDef.children;
2405
+
2406
+ if (!children || children.length === 0) {
2407
+ return false;
2408
+ }
2409
+
2410
+ return children.every(function (child) {
2411
+ if (child && child.children) {
2412
+ return isPivotRowGrandTotalGroupDef(child);
2407
2413
  }
2408
- };
2409
2414
 
2410
- var isRowsEmptyAndColumnsNotEmpty = function isRowsEmptyAndColumnsNotEmpty() {
2411
- var pivotRows = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotRows) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotRows) : [];
2412
- var pivotColumns = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotColumns) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotColumns) : [];
2413
- return (pivotRows === null || pivotRows === void 0 ? void 0 : pivotRows.length) === 0 && (pivotColumns === null || pivotColumns === void 0 ? void 0 : pivotColumns.length) > 0;
2414
- };
2415
+ return isPivotRowGrandTotalColumnDef(child);
2416
+ });
2417
+ };
2418
+ var resolvePivotGroupHeaderName = function resolvePivotGroupHeaderName(colGroupDef, columnFields, lookupDisplayName) {
2419
+ if (isPivotRowGrandTotalGroupDef(colGroupDef)) {
2420
+ return 'Grand Total';
2421
+ }
2415
2422
 
2416
- var canShowRowsGrandTotal = function canShowRowsGrandTotal() {
2417
- if (isRowsEmptyAndColumnsNotEmpty()) {
2418
- return true;
2423
+ var pivotKeys = colGroupDef && colGroupDef.pivotKeys ? colGroupDef.pivotKeys : [];
2424
+
2425
+ if (pivotKeys.length === 0) {
2426
+ return null;
2427
+ }
2428
+
2429
+ var field = columnFields[pivotKeys.length - 1];
2430
+
2431
+ if (!field) {
2432
+ return null;
2433
+ }
2434
+
2435
+ return lookupDisplayName(field, pivotKeys[pivotKeys.length - 1]);
2436
+ };
2437
+ var getPivotValueColumnId = function getPivotValueColumnId(pivotValueColumn) {
2438
+ if (!pivotValueColumn) {
2439
+ return null;
2440
+ }
2441
+
2442
+ if (typeof pivotValueColumn.getId === 'function') {
2443
+ return pivotValueColumn.getId();
2444
+ }
2445
+
2446
+ if (typeof pivotValueColumn.getColId === 'function') {
2447
+ return pivotValueColumn.getColId();
2448
+ }
2449
+
2450
+ if (pivotValueColumn.colId) {
2451
+ return String(pivotValueColumn.colId);
2452
+ }
2453
+
2454
+ if (pivotValueColumn.field) {
2455
+ return String(pivotValueColumn.field);
2456
+ }
2457
+
2458
+ return null;
2459
+ };
2460
+ var resolveMeasureFromPivotValueColumn = function resolveMeasureFromPivotValueColumn(colDef, measures) {
2461
+ if (!colDef || measures.length === 0) {
2462
+ return undefined;
2463
+ }
2464
+
2465
+ if (measures.length === 1) {
2466
+ return measures[0];
2467
+ }
2468
+
2469
+ var valueColumnId = getPivotValueColumnId(colDef.pivotValueColumn);
2470
+
2471
+ if (valueColumnId) {
2472
+ var measureByValueColumn = measures.find(function (measure) {
2473
+ return measure.PivotMeasureCode === valueColumnId;
2474
+ });
2475
+
2476
+ if (measureByValueColumn) {
2477
+ return measureByValueColumn;
2419
2478
  }
2479
+ }
2420
2480
 
2421
- var pivotTotalsSettings = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) : {};
2422
- return !isNullOrUndefinedOrEmpty(pivotTotalsSettings.ShowRowsGrandTotal) ? pivotTotalsSettings.ShowRowsGrandTotal : false;
2423
- };
2481
+ var colId = colDef.colId ? String(colDef.colId) : '';
2424
2482
 
2425
- var isRowsNotEmptyAndColumnsEmpty = function isRowsNotEmptyAndColumnsEmpty() {
2426
- var pivotRows = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotRows) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotRows) : [];
2427
- var pivotColumns = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotColumns) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotColumns) : [];
2428
- return (pivotRows === null || pivotRows === void 0 ? void 0 : pivotRows.length) > 0 && (pivotColumns === null || pivotColumns === void 0 ? void 0 : pivotColumns.length) === 0;
2429
- };
2483
+ if (colId) {
2484
+ var sortedMeasures = [].concat(measures).sort(function (left, right) {
2485
+ return right.PivotMeasureCode.length - left.PivotMeasureCode.length;
2486
+ });
2430
2487
 
2431
- var canShowColumnsGrandTotal = function canShowColumnsGrandTotal() {
2432
- if (isRowsNotEmptyAndColumnsEmpty()) {
2433
- return true;
2488
+ for (var index = 0; index < sortedMeasures.length; index++) {
2489
+ var measureCode = sortedMeasures[index].PivotMeasureCode;
2490
+
2491
+ if (colId.endsWith('_' + measureCode)) {
2492
+ return sortedMeasures[index];
2493
+ }
2434
2494
  }
2495
+ }
2435
2496
 
2436
- var pivotTotalsSettings = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) : {};
2437
- return !isNullOrUndefinedOrEmpty(pivotTotalsSettings.ShowColumnsGrandTotal) ? pivotTotalsSettings.ShowColumnsGrandTotal : false;
2438
- };
2497
+ return undefined;
2498
+ };
2499
+ var resolvePivotLeafHeaderName = function resolvePivotLeafHeaderName(colDef, columnFields, lookupDisplayName, measureCount, measures) {
2500
+ if (isPivotRowGrandTotalColumnDef(colDef)) {
2501
+ return null;
2502
+ }
2439
2503
 
2440
- var canShowRowsTotal = function canShowRowsTotal() {
2441
- var pivotTotalsSettings = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) : {};
2442
- return !isNullOrUndefinedOrEmpty(pivotTotalsSettings.ShowRowsTotal) ? pivotTotalsSettings.ShowRowsTotal : false;
2443
- };
2504
+ if (measureCount > 1 && colDef.pivotValueColumn) {
2505
+ return null;
2506
+ }
2444
2507
 
2445
- var canShowColumnsTotal = function canShowColumnsTotal() {
2446
- var pivotTotalsSettings = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) : {};
2447
- return !isNullOrUndefinedOrEmpty(pivotTotalsSettings.ShowColumnsTotal) ? pivotTotalsSettings.ShowColumnsTotal : false;
2448
- };
2508
+ var pivotKeys = colDef && colDef.pivotKeys ? colDef.pivotKeys : [];
2449
2509
 
2450
- return React__default.createElement(React__default.Fragment, null, isLoading ? React__default.createElement("div", {
2451
- className: 'dl-full-hight dl-flex-content-center spinner-custome'
2452
- }, React__default.createElement(progressspinner.ProgressSpinner, {
2453
- style: {
2454
- width: '40px',
2455
- height: '40px'
2456
- },
2457
- strokeWidth: "4",
2458
- animationDuration: "2s"
2459
- })) : React__default.createElement(PivotGrid__default, {
2460
- id: "pivotGridId",
2461
- ref: pivotGridRef,
2462
- dataSource: dataSource,
2463
- allowExpandAll: true,
2464
- showBorders: true,
2465
- className: 'pivot-grid-element',
2466
- onCellClick: onCellClick,
2467
- showRowGrandTotals: canShowRowsGrandTotal(),
2468
- showColumnGrandTotals: canShowColumnsGrandTotal(),
2469
- showRowTotals: canShowRowsTotal(),
2470
- showColumnTotals: canShowColumnsTotal(),
2471
- showTotalsPrior: 'none',
2472
- wordWrapEnabled: true
2473
- }, React__default.createElement(PivotGrid.FieldPanel, {
2474
- showColumnFields: false,
2475
- showDataFields: false,
2476
- showFilterFields: false,
2477
- showRowFields: false,
2478
- texts: {
2479
- rowFieldArea: ""
2480
- },
2481
- allowFieldDragging: false,
2482
- visible: true
2483
- }), React__default.createElement(PivotGrid.FieldChooser, {
2484
- enabled: false
2485
- }), React__default.createElement(PivotGrid.Scrolling, {
2486
- mode: "virtual"
2487
- })));
2488
- });
2510
+ if (pivotKeys.length === 0) {
2511
+ return null;
2512
+ }
2489
2513
 
2490
- var isRowPivotField = function isRowPivotField(field) {
2491
- return !!(field.PivotCode && field.PivotCode.indexOf('Row') !== -1);
2514
+ var field = columnFields[pivotKeys.length - 1];
2515
+
2516
+ if (!field) {
2517
+ return null;
2518
+ }
2519
+
2520
+ return lookupDisplayName(field, pivotKeys[pivotKeys.length - 1]);
2492
2521
  };
2493
- var truncateToTwoDecimals = function truncateToTwoDecimals(value) {
2494
- var numericValue = isNullOrUndefinedOrEmpty(value) ? 0 : Number(value);
2495
- var safeValue = isNaN(numericValue) ? 0 : numericValue;
2496
- var decimalParts = safeValue.toString().split('.');
2497
- var firstPart = decimalParts[0] ? decimalParts[0] : '0';
2498
- var secondPart = decimalParts[1] ? decimalParts[1].toString().substr(0, 2) : '0';
2499
- return Number(firstPart + '.' + secondPart);
2522
+ var resolveMeasureForSecondaryColDef = function resolveMeasureForSecondaryColDef(colDef, measures) {
2523
+ return resolveMeasureFromPivotValueColumn(colDef, measures);
2500
2524
  };
2501
- var isPivotMeasureValueEmpty = function isPivotMeasureValueEmpty(value) {
2502
- return value === null || value === undefined || value === '';
2525
+
2526
+ var getColumnGroupAtHeaderLevel = function getColumnGroupAtHeaderLevel(column, targetLevel) {
2527
+ if (!column || typeof column.getParent !== 'function') {
2528
+ return null;
2529
+ }
2530
+
2531
+ var groupPointer = column.getParent();
2532
+
2533
+ while (groupPointer) {
2534
+ var providedColumnGroup = typeof groupPointer.getProvidedColumnGroup === 'function' ? groupPointer.getProvidedColumnGroup() : null;
2535
+
2536
+ if (!providedColumnGroup) {
2537
+ groupPointer = typeof groupPointer.getParent === 'function' ? groupPointer.getParent() : null;
2538
+ continue;
2539
+ }
2540
+
2541
+ var originalGroupLevel = typeof providedColumnGroup.getLevel === 'function' ? providedColumnGroup.getLevel() : 0;
2542
+ var groupPointerLevel = typeof groupPointer.getPaddingLevel === 'function' ? groupPointer.getPaddingLevel() : 0;
2543
+
2544
+ if (originalGroupLevel + groupPointerLevel <= targetLevel) {
2545
+ return groupPointer;
2546
+ }
2547
+
2548
+ groupPointer = typeof groupPointer.getParent === 'function' ? groupPointer.getParent() : null;
2549
+ }
2550
+
2551
+ return null;
2503
2552
  };
2504
- var logitudeSumAgg = function logitudeSumAgg(params) {
2505
- var values = params && params.values ? params.values : [];
2506
- if (values.length === 0) return null;
2507
- var total = 0;
2508
- var hasValue = false;
2509
2553
 
2510
- for (var i = 0; i < values.length; i++) {
2511
- if (isPivotMeasureValueEmpty(values[i])) continue;
2512
- hasValue = true;
2513
- total += truncateToTwoDecimals(values[i]);
2554
+ var escapeColumnIdSelector = function escapeColumnIdSelector(columnId) {
2555
+ if (typeof CSS !== 'undefined' && typeof CSS.escape === 'function') {
2556
+ return CSS.escape(columnId);
2514
2557
  }
2515
2558
 
2516
- return hasValue ? total : null;
2559
+ return columnId.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
2517
2560
  };
2518
- var formatPivotMeasureValue = function formatPivotMeasureValue(value, measure) {
2519
- if (isPivotMeasureValueEmpty(value)) return '';
2520
- var isInteger = isValueInteger(measure.MeasureCode, measure.MeasureFieldDataType);
2521
- var minimumFraction = isInteger ? 0 : 2;
2522
- return getNumberInSystemLocalFormat(value, 2, minimumFraction);
2561
+
2562
+ var findHeaderGroupCellByColumnGroup = function findHeaderGroupCellByColumnGroup(headerContainer, groupRows, targetGroupLevel, columnGroup) {
2563
+ if (!columnGroup || typeof columnGroup.getUniqueId !== 'function') {
2564
+ return null;
2565
+ }
2566
+
2567
+ var groupId = columnGroup.getUniqueId();
2568
+ var groupRowIndex = Math.min(Math.max(targetGroupLevel, 0), groupRows.length - 1);
2569
+ var targetGroupRow = groupRows[groupRowIndex];
2570
+
2571
+ if (!targetGroupRow) {
2572
+ return null;
2573
+ }
2574
+
2575
+ return targetGroupRow.querySelector("[col-id=\"" + escapeColumnIdSelector(groupId) + "\"]");
2523
2576
  };
2524
- var getPivotGroupFooterLabel = function getPivotGroupFooterLabel(node, fieldCode, rawValue, lookupDisplayName) {
2525
- if (!node || !node.footer) return '';
2526
2577
 
2527
- if (node.level === -1) {
2528
- return 'Grand Total';
2578
+ var applyPivotRowGrandTotalGroupHeaderLabel = function applyPivotRowGrandTotalGroupHeaderLabel(gridRootElement, columnApi, measureCount, columnPivotFieldCount) {
2579
+ if (!gridRootElement || !columnApi || measureCount <= 1) {
2580
+ return;
2529
2581
  }
2530
2582
 
2531
- if (!fieldCode) return '';
2532
- var displayName = lookupDisplayName(fieldCode, rawValue);
2533
- return displayName ? displayName + " Total" : '';
2583
+ clearPivotRowGrandTotalGroupHeaderMarkup(gridRootElement);
2584
+ var displayedColumns = typeof columnApi.getAllDisplayedColumns === 'function' ? columnApi.getAllDisplayedColumns() : [];
2585
+ var rowGrandTotalColumns = displayedColumns.filter(function (column) {
2586
+ return String(column.getColId()).indexOf('PivotRowTotal_') === 0;
2587
+ });
2588
+
2589
+ if (rowGrandTotalColumns.length <= 1) {
2590
+ return;
2591
+ }
2592
+
2593
+ var centerHeaderContainer = gridRootElement.querySelector('.ag-header-viewport .ag-header-container');
2594
+
2595
+ if (!centerHeaderContainer) {
2596
+ return;
2597
+ }
2598
+
2599
+ var groupRows = Array.from(centerHeaderContainer.querySelectorAll('.ag-header-row-column-group'));
2600
+
2601
+ if (groupRows.length === 0) {
2602
+ return;
2603
+ }
2604
+
2605
+ var targetGroupLevel = columnPivotFieldCount > 0 ? columnPivotFieldCount - 1 : 0;
2606
+ var rowGrandTotalGroupCells = findRowGrandTotalGroupHeaderCells(centerHeaderContainer, groupRows, targetGroupLevel, rowGrandTotalColumns);
2607
+
2608
+ if (rowGrandTotalGroupCells.length === 0) {
2609
+ return;
2610
+ }
2611
+
2612
+ applyGrandTotalLabelToGroupHeaderCells(rowGrandTotalGroupCells);
2534
2613
  };
2535
- var compareDimensionValues = function compareDimensionValues(aValue, bValue, dateCode, aText, bText) {
2536
- if (dateCode === 'Month') {
2537
- var aNumber = aValue == null ? -1 : Number(aValue);
2538
- var bNumber = bValue == null ? -1 : Number(bValue);
2539
- if (aNumber < bNumber) return -1;
2540
- if (aNumber > bNumber) return 1;
2541
- return 0;
2614
+
2615
+ var clearPivotRowGrandTotalGroupHeaderMarkup = function clearPivotRowGrandTotalGroupHeaderMarkup(gridRootElement) {
2616
+ gridRootElement.querySelectorAll('.dl-pivot-row-grand-total-group-header, .dl-pivot-row-grand-total-group-header-sibling').forEach(function (element) {
2617
+ element.classList.remove('dl-pivot-row-grand-total-group-header', 'dl-pivot-row-grand-total-group-header-sibling');
2618
+ });
2619
+ gridRootElement.querySelectorAll('.dl-pivot-row-grand-total-group-header-label').forEach(function (label) {
2620
+ label.classList.remove('dl-pivot-row-grand-total-group-header-label');
2621
+ var labelElement = label;
2622
+ labelElement.textContent = '';
2623
+ labelElement.style.width = '';
2624
+ labelElement.style.display = '';
2625
+ labelElement.style.textAlign = '';
2626
+ });
2627
+ };
2628
+
2629
+ var findRowGrandTotalGroupHeaderCells = function findRowGrandTotalGroupHeaderCells(centerHeaderContainer, groupRows, targetGroupLevel, rowGrandTotalColumns) {
2630
+ var cellsByColumnGroup = [];
2631
+ rowGrandTotalColumns.forEach(function (column) {
2632
+ var columnGroup = getColumnGroupAtHeaderLevel(column, targetGroupLevel);
2633
+ var matchingCell = findHeaderGroupCellByColumnGroup(centerHeaderContainer, groupRows, targetGroupLevel, columnGroup);
2634
+
2635
+ if (matchingCell) {
2636
+ cellsByColumnGroup.push(matchingCell);
2637
+ }
2638
+ });
2639
+
2640
+ if (cellsByColumnGroup.length === rowGrandTotalColumns.length) {
2641
+ return cellsByColumnGroup;
2542
2642
  }
2543
2643
 
2544
- if (dateCode != null) {
2545
- var aCompare = aValue == null ? '' : aValue;
2546
- var bCompare = bValue == null ? '' : bValue;
2547
- if (aCompare < bCompare) return -1;
2548
- if (aCompare > bCompare) return 1;
2549
- return 0;
2644
+ var groupRowIndex = Math.min(Math.max(targetGroupLevel, 0), groupRows.length - 1);
2645
+ var targetGroupRow = groupRows[groupRowIndex];
2646
+
2647
+ if (!targetGroupRow) {
2648
+ return cellsByColumnGroup;
2550
2649
  }
2551
2650
 
2552
- var aDisplay = aText == null || aText === '' ? aValue == null ? '' : aValue : aText;
2553
- var bDisplay = bText == null || bText === '' ? bValue == null ? '' : bValue : bText;
2554
- if (aDisplay < bDisplay) return -1;
2555
- if (aDisplay > bDisplay) return 1;
2556
- return 0;
2557
- };
2558
- var getPivotDisplayName = function getPivotDisplayName(pivotData, fieldName, dataField, dataFieldValue) {
2559
- if (!pivotData || pivotData.length === 0) return '';
2560
- var data = pivotData.find(function (el) {
2561
- return el[dataField] == dataFieldValue;
2562
- });
2563
- return data ? ConvertStringToPascalCaseHelper(data[fieldName]) : '';
2564
- };
2565
- var isPivotRowGrandTotalColumnDef = function isPivotRowGrandTotalColumnDef(colDef) {
2566
- if (!colDef || !colDef.colId) {
2567
- return false;
2651
+ var paddingCells = Array.from(targetGroupRow.querySelectorAll('.ag-header-group-cell-no-group'));
2652
+ var trailingPaddingCells = paddingCells.slice(-rowGrandTotalColumns.length);
2653
+
2654
+ if (trailingPaddingCells.length === rowGrandTotalColumns.length) {
2655
+ return trailingPaddingCells;
2568
2656
  }
2569
2657
 
2570
- return String(colDef.colId).indexOf('PivotRowTotal_') === 0;
2658
+ return cellsByColumnGroup;
2571
2659
  };
2572
- var isPivotRowGrandTotalGroupDef = function isPivotRowGrandTotalGroupDef(colGroupDef) {
2573
- if (!colGroupDef) {
2574
- return false;
2575
- }
2576
2660
 
2577
- var groupId = colGroupDef.groupId || colGroupDef.colId || '';
2661
+ var applyGrandTotalLabelToGroupHeaderCells = function applyGrandTotalLabelToGroupHeaderCells(rowGrandTotalGroupCells) {
2662
+ var firstCell = rowGrandTotalGroupCells[0];
2663
+ var firstLabel = firstCell.querySelector('.ag-header-group-text, .ag-header-cell-text');
2578
2664
 
2579
- if (String(groupId).indexOf('PivotRowTotal') >= 0) {
2580
- return true;
2665
+ if (!firstLabel) {
2666
+ return;
2581
2667
  }
2582
2668
 
2583
- var children = colGroupDef.children;
2669
+ var combinedWidth = rowGrandTotalGroupCells.reduce(function (totalWidth, cell) {
2670
+ return totalWidth + cell.offsetWidth;
2671
+ }, 0);
2672
+ firstLabel.textContent = 'Grand Total';
2673
+ firstLabel.style.width = combinedWidth + "px";
2674
+ firstLabel.style.display = 'inline-block';
2675
+ firstLabel.style.textAlign = 'center';
2676
+ firstLabel.classList.add('dl-pivot-row-grand-total-group-header-label');
2677
+ firstCell.classList.add('dl-pivot-row-grand-total-group-header');
2584
2678
 
2585
- if (!children || children.length === 0) {
2586
- return false;
2587
- }
2679
+ for (var index = 1; index < rowGrandTotalGroupCells.length; index++) {
2680
+ rowGrandTotalGroupCells[index].classList.add('dl-pivot-row-grand-total-group-header-sibling');
2681
+ var siblingLabel = rowGrandTotalGroupCells[index].querySelector('.ag-header-group-text, .ag-header-cell-text');
2588
2682
 
2589
- return children.every(function (child) {
2590
- if (child && child.children) {
2591
- return isPivotRowGrandTotalGroupDef(child);
2683
+ if (siblingLabel) {
2684
+ siblingLabel.textContent = '';
2592
2685
  }
2593
-
2594
- return isPivotRowGrandTotalColumnDef(child);
2595
- });
2596
- };
2597
- var resolvePivotGroupHeaderName = function resolvePivotGroupHeaderName(colGroupDef, columnFields, lookupDisplayName) {
2598
- if (isPivotRowGrandTotalGroupDef(colGroupDef)) {
2599
- return 'Grand Total';
2600
2686
  }
2687
+ };
2601
2688
 
2602
- var pivotKeys = colGroupDef && colGroupDef.pivotKeys ? colGroupDef.pivotKeys : [];
2689
+ var applyPivotRowGrandTotalHeader = function applyPivotRowGrandTotalHeader(colDef, measureCount, measures) {
2690
+ if (!isPivotRowGrandTotalColumnDef(colDef)) {
2691
+ return;
2692
+ }
2603
2693
 
2604
- if (pivotKeys.length === 0) {
2605
- return null;
2694
+ if (measureCount <= 1) {
2695
+ colDef.headerName = 'Grand Total';
2696
+ return;
2606
2697
  }
2607
2698
 
2608
- var field = columnFields[pivotKeys.length - 1];
2699
+ var measure = resolveMeasureFromPivotValueColumn(colDef, measures);
2609
2700
 
2610
- if (!field) {
2611
- return null;
2701
+ if (measure) {
2702
+ colDef.headerName = getMeasureCaption(measure);
2612
2703
  }
2613
2704
 
2614
- return lookupDisplayName(field, pivotKeys[pivotKeys.length - 1]);
2705
+ delete colDef.headerValueGetter;
2615
2706
  };
2616
- var getPivotValueColumnId = function getPivotValueColumnId(pivotValueColumn) {
2617
- if (!pivotValueColumn) {
2618
- return null;
2619
- }
2707
+ var collectPivotRowPath = function collectPivotRowPath(startNode) {
2708
+ var path = [];
2620
2709
 
2621
- if (typeof pivotValueColumn.getId === 'function') {
2622
- return pivotValueColumn.getId();
2710
+ if (!startNode) {
2711
+ return path;
2623
2712
  }
2624
2713
 
2625
- if (typeof pivotValueColumn.getColId === 'function') {
2626
- return pivotValueColumn.getColId();
2627
- }
2714
+ if (startNode.footer) {
2715
+ if (startNode.level === -1) {
2716
+ return path;
2717
+ }
2628
2718
 
2629
- if (pivotValueColumn.colId) {
2630
- return String(pivotValueColumn.colId);
2719
+ if (startNode.field != null && startNode.key !== undefined) {
2720
+ path.unshift({
2721
+ field: startNode.field,
2722
+ key: startNode.key
2723
+ });
2724
+ }
2631
2725
  }
2632
2726
 
2633
- if (pivotValueColumn.field) {
2634
- return String(pivotValueColumn.field);
2727
+ var node = startNode.parent;
2728
+
2729
+ while (node && node.level >= 0) {
2730
+ if (!node.footer && node.field != null && node.key !== undefined) {
2731
+ path.unshift({
2732
+ field: node.field,
2733
+ key: node.key
2734
+ });
2735
+ }
2736
+
2737
+ node = node.parent;
2635
2738
  }
2636
2739
 
2637
- return null;
2740
+ return path;
2638
2741
  };
2639
- var resolveMeasureFromPivotValueColumn = function resolveMeasureFromPivotValueColumn(colDef, measures) {
2640
- if (!colDef || measures.length === 0) {
2641
- return undefined;
2642
- }
2742
+ var buildPivotDrillDownPivotFields = function buildPivotDrillDownPivotFields(colDef, startNode, apiFields) {
2743
+ var columnFields = apiFields.filter(function (field) {
2744
+ return !isRowPivotField(field);
2745
+ });
2746
+ var rowFields = apiFields.filter(isRowPivotField);
2747
+ var pivotFields = [];
2748
+ var columnKeys = colDef && colDef.pivotKeys ? colDef.pivotKeys : [];
2749
+ columnKeys.forEach(function (key, index) {
2750
+ if (key === undefined) {
2751
+ return;
2752
+ }
2643
2753
 
2644
- if (measures.length === 1) {
2645
- return measures[0];
2646
- }
2754
+ var field = columnFields[index];
2647
2755
 
2648
- var valueColumnId = getPivotValueColumnId(colDef.pivotValueColumn);
2756
+ if (!field) {
2757
+ return;
2758
+ }
2649
2759
 
2650
- if (valueColumnId) {
2651
- var measureByValueColumn = measures.find(function (measure) {
2652
- return measure.PivotMeasureCode === valueColumnId;
2760
+ pivotFields.push({
2761
+ FieldId: field.FieldId,
2762
+ FieldType: field.FieldType ? field.FieldType : 'Field',
2763
+ FieldValue: key,
2764
+ DateCode: field.DateCode
2765
+ });
2766
+ });
2767
+ collectPivotRowPath(startNode).forEach(function (pathItem) {
2768
+ var field = rowFields.find(function (f) {
2769
+ return f.PivotCode === pathItem.field;
2770
+ }) || apiFields.find(function (f) {
2771
+ return f.PivotCode === pathItem.field;
2653
2772
  });
2654
2773
 
2655
- if (measureByValueColumn) {
2656
- return measureByValueColumn;
2774
+ if (!field) {
2775
+ return;
2657
2776
  }
2658
- }
2659
-
2660
- var colId = colDef.colId ? String(colDef.colId) : '';
2661
2777
 
2662
- if (colId) {
2663
- var sortedMeasures = [].concat(measures).sort(function (left, right) {
2664
- return right.PivotMeasureCode.length - left.PivotMeasureCode.length;
2778
+ pivotFields.push({
2779
+ FieldId: field.FieldId,
2780
+ FieldType: field.FieldType ? field.FieldType : 'Field',
2781
+ FieldValue: pathItem.key,
2782
+ DateCode: field.DateCode
2665
2783
  });
2784
+ });
2785
+ return pivotFields;
2786
+ };
2787
+ var getMeasureCaption = function getMeasureCaption(measure) {
2788
+ var displayName = typeof measure.DisplayName == 'string' ? measure.DisplayName : '';
2666
2789
 
2667
- for (var index = 0; index < sortedMeasures.length; index++) {
2668
- var measureCode = sortedMeasures[index].PivotMeasureCode;
2669
-
2670
- if (colId.endsWith('_' + measureCode)) {
2671
- return sortedMeasures[index];
2672
- }
2673
- }
2790
+ if (measure.MeasureCode == 'Sum') {
2791
+ return ConvertStringToPascalCaseHelper(displayName.replace('Sum of ', ''));
2674
2792
  }
2675
2793
 
2676
- return undefined;
2794
+ return ConvertStringToPascalCaseHelper(displayName);
2677
2795
  };
2678
- var resolvePivotLeafHeaderName = function resolvePivotLeafHeaderName(colDef, columnFields, lookupDisplayName, measureCount, measures) {
2679
- if (isPivotRowGrandTotalColumnDef(colDef)) {
2680
- return null;
2796
+ var parseJsonArray = function parseJsonArray(json) {
2797
+ if (isNullOrUndefinedOrEmpty(json)) return [];
2798
+
2799
+ try {
2800
+ var parsed = JSON.parse(json);
2801
+ return parsed || [];
2802
+ } catch (error) {
2803
+ return [];
2681
2804
  }
2805
+ };
2806
+ var parsePivotTotalsSettings = function parsePivotTotalsSettings(json) {
2807
+ if (isNullOrUndefinedOrEmpty(json)) return {};
2682
2808
 
2683
- if (measureCount > 1 && colDef.pivotValueColumn) {
2684
- return null;
2809
+ try {
2810
+ return JSON.parse(json) || {};
2811
+ } catch (error) {
2812
+ return {};
2685
2813
  }
2814
+ };
2686
2815
 
2687
- var pivotKeys = colDef && colDef.pivotKeys ? colDef.pivotKeys : [];
2816
+ var PivotTable = React.forwardRef(function (props, comRef) {
2817
+ var _useState = React.useState(),
2818
+ widget = _useState[0],
2819
+ setWidget = _useState[1];
2688
2820
 
2689
- if (pivotKeys.length === 0) {
2690
- return null;
2691
- }
2821
+ var _useState2 = React.useState(true),
2822
+ isLoading = _useState2[0],
2823
+ setIsLoading = _useState2[1];
2692
2824
 
2693
- var field = columnFields[pivotKeys.length - 1];
2825
+ var widgetRefData = React.useRef(null);
2826
+ var tabledata = React.useRef();
2827
+ var pivotGridRef = React.useRef(null);
2828
+ var dateMeasureDataFieldsRef = React.useRef(new Set());
2829
+ var pivotHasRowFieldsRef = React.useRef(false);
2830
+ var pivotHasColumnFieldsRef = React.useRef(false);
2831
+
2832
+ var _useState3 = React.useState(new PivotGridDataSource({
2833
+ store: [],
2834
+ fields: []
2835
+ })),
2836
+ dataSource = _useState3[0],
2837
+ setDataSource = _useState3[1];
2838
+
2839
+ React.useEffect(function () {
2840
+ var _props$customChartPro;
2841
+
2842
+ if (props.customChartProps && props.customChartProps.widget) {
2843
+ setWidget(props.customChartProps.widget);
2844
+ widgetRefData.current = props.customChartProps.widget;
2845
+ getPivotTableData();
2846
+ }
2694
2847
 
2695
- if (!field) {
2696
- return null;
2697
- }
2848
+ (_props$customChartPro = props.customChartProps.dataBinding) === null || _props$customChartPro === void 0 ? void 0 : _props$customChartPro.widgetUpdated.subscribe(function (updatedWidget) {
2849
+ var _widgetRefData$curren;
2698
2850
 
2699
- return lookupDisplayName(field, pivotKeys[pivotKeys.length - 1]);
2700
- };
2701
- var resolveMeasureForSecondaryColDef = function resolveMeasureForSecondaryColDef(colDef, measures) {
2702
- return resolveMeasureFromPivotValueColumn(colDef, measures);
2703
- };
2851
+ if ((updatedWidget === null || updatedWidget === void 0 ? void 0 : updatedWidget.key) != ((_widgetRefData$curren = widgetRefData.current) === null || _widgetRefData$curren === void 0 ? void 0 : _widgetRefData$curren.key)) return;
2852
+ setWidget(_extends({}, updatedWidget));
2853
+ });
2854
+ document.addEventListener("resizeStop", handleResize);
2855
+ return function () {
2856
+ document.removeEventListener("resizeStop", handleResize);
2857
+ };
2858
+ }, []);
2859
+ React.useEffect(function () {
2860
+ if (props.customChartProps.isInEditMode) {
2861
+ var _pivotGridRef$current;
2704
2862
 
2705
- var getColumnGroupAtHeaderLevel = function getColumnGroupAtHeaderLevel(column, targetLevel) {
2706
- if (!column || typeof column.getParent !== 'function') {
2707
- return null;
2708
- }
2863
+ if (pivotGridRef.current && (_pivotGridRef$current = pivotGridRef.current) !== null && _pivotGridRef$current !== void 0 && _pivotGridRef$current.instance && pivotGridRef.current.instance.element && pivotGridRef.current.instance.element().classList) {
2864
+ pivotGridRef.current.instance.element().classList.add('force-overflow-hidden');
2865
+ }
2709
2866
 
2710
- var groupPointer = column.getParent();
2867
+ setTimeout(function () {
2868
+ var _pivotGridRef$current2;
2711
2869
 
2712
- while (groupPointer) {
2713
- var providedColumnGroup = typeof groupPointer.getProvidedColumnGroup === 'function' ? groupPointer.getProvidedColumnGroup() : null;
2870
+ handleResize();
2714
2871
 
2715
- if (!providedColumnGroup) {
2716
- groupPointer = typeof groupPointer.getParent === 'function' ? groupPointer.getParent() : null;
2717
- continue;
2872
+ if (pivotGridRef.current && (_pivotGridRef$current2 = pivotGridRef.current) !== null && _pivotGridRef$current2 !== void 0 && _pivotGridRef$current2.instance && pivotGridRef.current.instance.element && pivotGridRef.current.instance.element().classList) {
2873
+ pivotGridRef.current.instance.element().classList.remove('force-overflow-hidden');
2874
+ }
2875
+ }, 5);
2718
2876
  }
2877
+ }, [props.customChartProps.isInEditMode]);
2719
2878
 
2720
- var originalGroupLevel = typeof providedColumnGroup.getLevel === 'function' ? providedColumnGroup.getLevel() : 0;
2721
- var groupPointerLevel = typeof groupPointer.getPaddingLevel === 'function' ? groupPointer.getPaddingLevel() : 0;
2879
+ var handleResize = function handleResize() {
2880
+ var _pivotGridRef$current3, _pivotGridRef$current4;
2722
2881
 
2723
- if (originalGroupLevel + groupPointerLevel <= targetLevel) {
2724
- return groupPointer;
2725
- }
2882
+ if (pivotGridRef.current && (_pivotGridRef$current3 = pivotGridRef.current) !== null && _pivotGridRef$current3 !== void 0 && _pivotGridRef$current3.instance && (_pivotGridRef$current4 = pivotGridRef.current) !== null && _pivotGridRef$current4 !== void 0 && _pivotGridRef$current4.instance.repaint) {
2883
+ var _pivotGridRef$current5;
2726
2884
 
2727
- groupPointer = typeof groupPointer.getParent === 'function' ? groupPointer.getParent() : null;
2728
- }
2885
+ (_pivotGridRef$current5 = pivotGridRef.current) === null || _pivotGridRef$current5 === void 0 ? void 0 : _pivotGridRef$current5.instance.repaint();
2886
+ }
2887
+ };
2729
2888
 
2730
- return null;
2731
- };
2889
+ var getPivotTableData = function getPivotTableData(widget) {
2890
+ if (Session.Tenant == 0) {
2891
+ tabledata.current = [];
2892
+ setIsLoading(false);
2893
+ return;
2894
+ }
2732
2895
 
2733
- var escapeColumnIdSelector = function escapeColumnIdSelector(columnId) {
2734
- if (typeof CSS !== 'undefined' && typeof CSS.escape === 'function') {
2735
- return CSS.escape(columnId);
2736
- }
2896
+ var dashboardAnalyticsService = new DashboardAnalyticsService();
2897
+ var widgetLoadLogger = new WidgetLoadLogger(props.customChartProps.widget, props.customChartProps.isPreviewModeActive, "PostGetPivotData");
2898
+ dashboardAnalyticsService.getPivotData(props.customChartProps.widget).then(function (res) {
2899
+ tabledata.current = res.data;
2900
+ setPivotDataSourceFields();
2901
+ setIsLoading(false);
2902
+ widgetLoadLogger.log(res);
2903
+ })["catch"](function (err) {
2904
+ console.log("Error while Getting Pivot Table Data: ", err);
2905
+ tabledata.current = null;
2906
+ setPivotDataSourceFields();
2907
+ setIsLoading(false);
2908
+ });
2909
+ };
2737
2910
 
2738
- return columnId.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
2739
- };
2911
+ var customizeCells = React.useCallback(function (e) {
2912
+ if (e.cell.rowPath && e.cell.rowPath[0] === "Germany" && e.cell.columnPath && e.cell.columnPath[0] === "Export" && e.cell.columnPath[1] === "Air") {
2913
+ e.cellElement.children[0].style.padding = "6px";
2914
+ e.cellElement.children[0].style.borderRadius = "6px";
2915
+ e.cellElement.children[0].style.backgroundColor = "#f4433673";
2916
+ }
2740
2917
 
2741
- var findHeaderGroupCellByColumnGroup = function findHeaderGroupCellByColumnGroup(headerContainer, groupRows, targetGroupLevel, columnGroup) {
2742
- if (!columnGroup || typeof columnGroup.getUniqueId !== 'function') {
2743
- return null;
2744
- }
2918
+ if (e.cell.rowPath && e.cell.rowPath[0] === "USA" && e.cell.columnPath && e.cell.columnPath[0] === "Import" && e.cell.columnPath[1] === "Inland") {
2919
+ e.cellElement.children[0].style.padding = "6px";
2920
+ e.cellElement.children[0].style.borderRadius = "6px";
2921
+ e.cellElement.children[0].style.backgroundColor = "#03a9f4ad";
2922
+ }
2923
+ }, []);
2924
+ var onCellClick = React.useCallback(function (e) {
2925
+ if (e.area === 'data') {
2926
+ var pivotFields = [];
2927
+ e.columnFields.forEach(function (c, index) {
2928
+ var fieldValue = e.cell.columnPath[index];
2745
2929
 
2746
- var groupId = columnGroup.getUniqueId();
2747
- var groupRowIndex = Math.min(Math.max(targetGroupLevel, 0), groupRows.length - 1);
2748
- var targetGroupRow = groupRows[groupRowIndex];
2930
+ if (fieldValue !== undefined) {
2931
+ pivotFields.push(_extends({}, c.fieldData, {
2932
+ FieldValue: fieldValue
2933
+ }));
2934
+ }
2935
+ });
2936
+ e.rowFields.forEach(function (r, index) {
2937
+ var fieldValue = e.cell.rowPath[index];
2749
2938
 
2750
- if (!targetGroupRow) {
2751
- return null;
2752
- }
2939
+ if (fieldValue !== undefined) {
2940
+ pivotFields.push(_extends({}, r.fieldData, {
2941
+ FieldValue: fieldValue
2942
+ }));
2943
+ }
2944
+ });
2945
+ props.customChartProps.onSelectDataPoint({
2946
+ MeasureFieldId: '',
2947
+ Widget: props.customChartProps.widget,
2948
+ MeasureCode: '',
2949
+ Formula: '',
2950
+ GroupById: '',
2951
+ PivotFields: pivotFields
2952
+ });
2953
+ }
2954
+ }, []);
2955
+ var onCellPrepared = React.useCallback(function (e) {
2956
+ if (e.area !== 'data') {
2957
+ return;
2958
+ }
2753
2959
 
2754
- return targetGroupRow.querySelector("[col-id=\"" + escapeColumnIdSelector(groupId) + "\"]");
2755
- };
2960
+ var dataFields = e.component.getDataSource().getAreaFields('data');
2961
+ var dataField = dataFields && dataFields[e.cell.dataIndex];
2756
2962
 
2757
- var applyPivotRowGrandTotalGroupHeaderLabel = function applyPivotRowGrandTotalGroupHeaderLabel(gridRootElement, columnApi, measureCount, columnPivotFieldCount) {
2758
- if (!gridRootElement || !columnApi || measureCount <= 1) {
2759
- return;
2760
- }
2963
+ if (!dataField || !dateMeasureDataFieldsRef.current.has(dataField.dataField)) {
2964
+ return;
2965
+ }
2761
2966
 
2762
- clearPivotRowGrandTotalGroupHeaderMarkup(gridRootElement);
2763
- var displayedColumns = typeof columnApi.getAllDisplayedColumns === 'function' ? columnApi.getAllDisplayedColumns() : [];
2764
- var rowGrandTotalColumns = displayedColumns.filter(function (column) {
2765
- return String(column.getColId()).indexOf('PivotRowTotal_') === 0;
2766
- });
2967
+ e.cellElement.classList.add(PIVOT_DATE_DATA_CELL_CLASS);
2767
2968
 
2768
- if (rowGrandTotalColumns.length <= 1) {
2769
- return;
2770
- }
2969
+ if (isDevExtremePivotDataCellTotalOrGrandTotal(e.cell, pivotHasRowFieldsRef.current, pivotHasColumnFieldsRef.current)) {
2970
+ e.cell.text = '';
2971
+ var contentSpan = e.cellElement ? e.cellElement.querySelector('span') : null;
2771
2972
 
2772
- var centerHeaderContainer = gridRootElement.querySelector('.ag-header-viewport .ag-header-container');
2973
+ if (contentSpan) {
2974
+ contentSpan.textContent = '';
2975
+ }
2976
+ }
2977
+ }, []);
2773
2978
 
2774
- if (!centerHeaderContainer) {
2775
- return;
2776
- }
2979
+ var getColumnNameByColumnId = function getColumnNameByColumnId(fieldName, dataField, datafieldValue) {
2980
+ var data = tabledata.current.PivotData.find(function (el) {
2981
+ return el[dataField] == datafieldValue;
2982
+ });
2983
+ return data ? ConvertStringToPascalCaseHelper(data[fieldName]) : '';
2984
+ };
2777
2985
 
2778
- var groupRows = Array.from(centerHeaderContainer.querySelectorAll('.ag-header-row-column-group'));
2986
+ var SortRowAndColumnHeaders = function SortRowAndColumnHeaders(a, b, field) {
2987
+ if (field.DateCode == 'Month') {
2988
+ var aValue = a.value == null ? -1 : Number(a.value);
2989
+ var bValue = b.value == null ? -1 : Number(b.value);
2779
2990
 
2780
- if (groupRows.length === 0) {
2781
- return;
2782
- }
2991
+ if (aValue < bValue) {
2992
+ return -1;
2993
+ }
2783
2994
 
2784
- var targetGroupLevel = columnPivotFieldCount > 0 ? columnPivotFieldCount - 1 : 0;
2785
- var rowGrandTotalGroupCells = findRowGrandTotalGroupHeaderCells(centerHeaderContainer, groupRows, targetGroupLevel, rowGrandTotalColumns);
2995
+ if (aValue > bValue) {
2996
+ return 1;
2997
+ }
2786
2998
 
2787
- if (rowGrandTotalGroupCells.length === 0) {
2788
- return;
2789
- }
2999
+ return 0;
3000
+ } else if (field.DateCode != null) {
3001
+ var _aValue = a.value == null ? '' : a.value;
2790
3002
 
2791
- applyGrandTotalLabelToGroupHeaderCells(rowGrandTotalGroupCells);
2792
- };
3003
+ var _bValue = b.value == null ? '' : b.value;
2793
3004
 
2794
- var clearPivotRowGrandTotalGroupHeaderMarkup = function clearPivotRowGrandTotalGroupHeaderMarkup(gridRootElement) {
2795
- gridRootElement.querySelectorAll('.dl-pivot-row-grand-total-group-header, .dl-pivot-row-grand-total-group-header-sibling').forEach(function (element) {
2796
- element.classList.remove('dl-pivot-row-grand-total-group-header', 'dl-pivot-row-grand-total-group-header-sibling');
2797
- });
2798
- gridRootElement.querySelectorAll('.dl-pivot-row-grand-total-group-header-label').forEach(function (label) {
2799
- label.classList.remove('dl-pivot-row-grand-total-group-header-label');
2800
- var labelElement = label;
2801
- labelElement.textContent = '';
2802
- labelElement.style.width = '';
2803
- labelElement.style.display = '';
2804
- labelElement.style.textAlign = '';
2805
- });
2806
- };
3005
+ if (_aValue < _bValue) {
3006
+ return -1;
3007
+ }
2807
3008
 
2808
- var findRowGrandTotalGroupHeaderCells = function findRowGrandTotalGroupHeaderCells(centerHeaderContainer, groupRows, targetGroupLevel, rowGrandTotalColumns) {
2809
- var cellsByColumnGroup = [];
2810
- rowGrandTotalColumns.forEach(function (column) {
2811
- var columnGroup = getColumnGroupAtHeaderLevel(column, targetGroupLevel);
2812
- var matchingCell = findHeaderGroupCellByColumnGroup(centerHeaderContainer, groupRows, targetGroupLevel, columnGroup);
3009
+ if (_aValue > _bValue) {
3010
+ return 1;
3011
+ }
2813
3012
 
2814
- if (matchingCell) {
2815
- cellsByColumnGroup.push(matchingCell);
2816
- }
2817
- });
3013
+ return 0;
3014
+ } else {
3015
+ var aText = a.text == null ? '' : a.text;
3016
+ var bText = b.text == null ? '' : b.text;
2818
3017
 
2819
- if (cellsByColumnGroup.length === rowGrandTotalColumns.length) {
2820
- return cellsByColumnGroup;
2821
- }
3018
+ if (aText < bText) {
3019
+ return -1;
3020
+ }
2822
3021
 
2823
- var groupRowIndex = Math.min(Math.max(targetGroupLevel, 0), groupRows.length - 1);
2824
- var targetGroupRow = groupRows[groupRowIndex];
3022
+ if (aText > bText) {
3023
+ return 1;
3024
+ }
2825
3025
 
2826
- if (!targetGroupRow) {
2827
- return cellsByColumnGroup;
2828
- }
3026
+ return 0;
3027
+ }
3028
+ };
2829
3029
 
2830
- var paddingCells = Array.from(targetGroupRow.querySelectorAll('.ag-header-group-cell-no-group'));
2831
- var trailingPaddingCells = paddingCells.slice(-rowGrandTotalColumns.length);
3030
+ var setPivotDataSourceFields = function setPivotDataSourceFields() {
3031
+ if (tabledata.current && tabledata.current.PivoFields && tabledata.current.PivotMeasures) {
3032
+ var pivotRowsAndColumnsFields = tabledata.current.PivoFields.map(function (field) {
3033
+ return {
3034
+ dataField: field.PivotCode,
3035
+ caption: field.DisplayName,
3036
+ name: field.PivotName,
3037
+ width: 100,
3038
+ allowSorting: false,
3039
+ allowFiltering: false,
3040
+ area: field.PivotCode && field.PivotCode.includes('Row') ? 'row' : 'column',
3041
+ sortingMethod: function sortingMethod(a, b) {
3042
+ return SortRowAndColumnHeaders(a, b, field);
3043
+ },
3044
+ expanded: true,
3045
+ wordWrapEnabled: true,
3046
+ fieldData: {
3047
+ FieldId: field.FieldId,
3048
+ FieldType: field.FieldType ? field.FieldType : "Field",
3049
+ FieldValue: '',
3050
+ DateCode: field.DateCode
3051
+ },
3052
+ customizeText: function customizeText(cellInfo) {
3053
+ return getColumnNameByColumnId(field.PivotName, field.PivotCode, cellInfo.value);
3054
+ }
3055
+ };
3056
+ });
3057
+ var hasRowFields = tabledata.current.PivoFields.some(function (field) {
3058
+ return field.PivotCode && field.PivotCode.includes('Row');
3059
+ });
3060
+ var hasColumnFields = tabledata.current.PivoFields.some(function (field) {
3061
+ return field.PivotCode && !field.PivotCode.includes('Row');
3062
+ });
3063
+ pivotHasRowFieldsRef.current = hasRowFields;
3064
+ pivotHasColumnFieldsRef.current = hasColumnFields;
3065
+ dateMeasureDataFieldsRef.current = new Set(tabledata.current.PivotMeasures.filter(function (measure) {
3066
+ return (measure.MeasureCode === 'Min' || measure.MeasureCode === 'Max') && FieldDataType.isDateOrDateTimeType(measure.MeasureFieldDataType);
3067
+ }).map(function (measure) {
3068
+ return measure.PivotMeasureCode;
3069
+ }));
3070
+ var pivotDataCellsFields = tabledata.current.PivotMeasures.map(function (measure) {
3071
+ var isDateMinMaxMeasure = (measure.MeasureCode === 'Min' || measure.MeasureCode === 'Max') && FieldDataType.isDateOrDateTimeType(measure.MeasureFieldDataType);
3072
+ return _extends({
3073
+ dataField: measure.PivotMeasureCode,
3074
+ area: 'data',
3075
+ dataType: isDateMinMaxMeasure ? 'string' : 'number',
3076
+ wordWrapEnabled: true,
3077
+ caption: measure.MeasureCode == 'Sum' && typeof measure.DisplayName == 'string' ? ConvertStringToPascalCaseHelper(measure.DisplayName.replace("Sum of ", "")) : ConvertStringToPascalCaseHelper(measure.DisplayName),
3078
+ summaryType: 'custom',
3079
+ calculateCustomSummary: function calculateCustomSummary(options) {
3080
+ if (options.summaryProcess == 'start') {
3081
+ options.totalValue = null;
3082
+ return;
3083
+ }
2832
3084
 
2833
- if (trailingPaddingCells.length === rowGrandTotalColumns.length) {
2834
- return trailingPaddingCells;
2835
- }
3085
+ if (options.summaryProcess != 'calculate') {
3086
+ return;
3087
+ }
2836
3088
 
2837
- return cellsByColumnGroup;
2838
- };
3089
+ if (isDateMinMaxMeasure) {
3090
+ if (isNullOrUndefinedOrEmpty(options.value)) {
3091
+ return;
3092
+ }
2839
3093
 
2840
- var applyGrandTotalLabelToGroupHeaderCells = function applyGrandTotalLabelToGroupHeaderCells(rowGrandTotalGroupCells) {
2841
- var firstCell = rowGrandTotalGroupCells[0];
2842
- var firstLabel = firstCell.querySelector('.ag-header-group-text, .ag-header-cell-text');
3094
+ var currentDate = moment(options.value);
2843
3095
 
2844
- if (!firstLabel) {
2845
- return;
2846
- }
3096
+ if (!currentDate || !currentDate.isValid()) {
3097
+ return;
3098
+ }
2847
3099
 
2848
- var combinedWidth = rowGrandTotalGroupCells.reduce(function (totalWidth, cell) {
2849
- return totalWidth + cell.offsetWidth;
2850
- }, 0);
2851
- firstLabel.textContent = 'Grand Total';
2852
- firstLabel.style.width = combinedWidth + "px";
2853
- firstLabel.style.display = 'inline-block';
2854
- firstLabel.style.textAlign = 'center';
2855
- firstLabel.classList.add('dl-pivot-row-grand-total-group-header-label');
2856
- firstCell.classList.add('dl-pivot-row-grand-total-group-header');
3100
+ if (isNullOrUndefinedOrEmpty(options.totalValue)) {
3101
+ options.totalValue = options.value;
3102
+ return;
3103
+ }
2857
3104
 
2858
- for (var index = 1; index < rowGrandTotalGroupCells.length; index++) {
2859
- rowGrandTotalGroupCells[index].classList.add('dl-pivot-row-grand-total-group-header-sibling');
2860
- var siblingLabel = rowGrandTotalGroupCells[index].querySelector('.ag-header-group-text, .ag-header-cell-text');
3105
+ var totalDate = moment(options.totalValue);
2861
3106
 
2862
- if (siblingLabel) {
2863
- siblingLabel.textContent = '';
2864
- }
2865
- }
2866
- };
3107
+ if (!totalDate || !totalDate.isValid()) {
3108
+ options.totalValue = options.value;
3109
+ return;
3110
+ }
2867
3111
 
2868
- var applyPivotRowGrandTotalHeader = function applyPivotRowGrandTotalHeader(colDef, measureCount, measures) {
2869
- if (!isPivotRowGrandTotalColumnDef(colDef)) {
2870
- return;
2871
- }
3112
+ if (measure.MeasureCode === 'Max') {
3113
+ if (currentDate.isAfter(totalDate)) {
3114
+ options.totalValue = options.value;
3115
+ }
3116
+ } else if (currentDate.isBefore(totalDate)) {
3117
+ options.totalValue = options.value;
3118
+ }
2872
3119
 
2873
- if (measureCount <= 1) {
2874
- colDef.headerName = 'Grand Total';
2875
- return;
2876
- }
3120
+ return;
3121
+ }
2877
3122
 
2878
- var measure = resolveMeasureFromPivotValueColumn(colDef, measures);
3123
+ var _value = !isNullOrUndefinedOrEmpty(options.value) ? options.value : 0;
2879
3124
 
2880
- if (measure) {
2881
- colDef.headerName = getMeasureCaption(measure);
2882
- }
3125
+ var decimalParts = _value.toString().split(".");
2883
3126
 
2884
- delete colDef.headerValueGetter;
2885
- };
2886
- var collectPivotRowPath = function collectPivotRowPath(startNode) {
2887
- var path = [];
3127
+ var firstPart = decimalParts[0] ? decimalParts[0] : 0;
3128
+ var secondPart = decimalParts[1] ? decimalParts[1] : 0;
3129
+ secondPart = secondPart.toString().substr(0, 2);
2888
3130
 
2889
- if (!startNode) {
2890
- return path;
2891
- }
3131
+ var _finalVal = firstPart + "." + secondPart;
2892
3132
 
2893
- if (startNode.footer) {
2894
- if (startNode.level === -1) {
2895
- return path;
2896
- }
3133
+ options.value = Number(_finalVal);
3134
+ options.totalValue = (!isNullOrUndefinedOrEmpty(options.totalValue) ? options.totalValue : 0) + options.value;
3135
+ }
3136
+ }, isDateMinMaxMeasure ? {
3137
+ calculateSummaryValue: function calculateSummaryValue(cell) {
3138
+ if (isDevExtremeSummaryCellTotalOrGrandTotal(cell, hasRowFields, hasColumnFields)) {
3139
+ return null;
3140
+ }
2897
3141
 
2898
- if (startNode.field != null && startNode.key !== undefined) {
2899
- path.unshift({
2900
- field: startNode.field,
2901
- key: startNode.key
2902
- });
2903
- }
2904
- }
3142
+ return cell.value();
3143
+ },
3144
+ customizeText: function customizeText(cellInfo) {
3145
+ return formatPivotDateMeasureValue(cellInfo.value);
3146
+ }
3147
+ } : {
3148
+ format: function format(value) {
3149
+ var isInteger = isValueInteger(measure.MeasureCode, measure.MeasureFieldDataType);
3150
+ var minimumFraction = isInteger ? 0 : 2;
2905
3151
 
2906
- var node = startNode.parent;
3152
+ var _value = isNullOrUndefinedOrEmpty(value) ? 0 : value;
2907
3153
 
2908
- while (node && node.level >= 0) {
2909
- if (!node.footer && node.field != null && node.key !== undefined) {
2910
- path.unshift({
2911
- field: node.field,
2912
- key: node.key
3154
+ return getNumberInSystemLocalFormat(_value, 2, minimumFraction);
3155
+ }
3156
+ });
2913
3157
  });
3158
+ var AllfieldsData = [].concat(pivotRowsAndColumnsFields, pivotDataCellsFields);
3159
+ setDataSource(new PivotGridDataSource({
3160
+ store: tabledata.current.PivotData,
3161
+ fields: AllfieldsData
3162
+ }));
2914
3163
  }
3164
+ };
2915
3165
 
2916
- node = node.parent;
2917
- }
2918
-
2919
- return path;
2920
- };
2921
- var buildPivotDrillDownPivotFields = function buildPivotDrillDownPivotFields(colDef, startNode, apiFields) {
2922
- var columnFields = apiFields.filter(function (field) {
2923
- return !isRowPivotField(field);
2924
- });
2925
- var rowFields = apiFields.filter(isRowPivotField);
2926
- var pivotFields = [];
2927
- var columnKeys = colDef && colDef.pivotKeys ? colDef.pivotKeys : [];
2928
- columnKeys.forEach(function (key, index) {
2929
- if (key === undefined) {
2930
- return;
2931
- }
2932
-
2933
- var field = columnFields[index];
2934
-
2935
- if (!field) {
2936
- return;
2937
- }
3166
+ var canShowRowsGrandTotal = function canShowRowsGrandTotal() {
3167
+ var pivotTotalsSettings = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) : {};
3168
+ return !isNullOrUndefinedOrEmpty(pivotTotalsSettings.ShowRowsGrandTotal) ? pivotTotalsSettings.ShowRowsGrandTotal : false;
3169
+ };
2938
3170
 
2939
- pivotFields.push({
2940
- FieldId: field.FieldId,
2941
- FieldType: field.FieldType ? field.FieldType : 'Field',
2942
- FieldValue: key,
2943
- DateCode: field.DateCode
2944
- });
2945
- });
2946
- collectPivotRowPath(startNode).forEach(function (pathItem) {
2947
- var field = rowFields.find(function (f) {
2948
- return f.PivotCode === pathItem.field;
2949
- }) || apiFields.find(function (f) {
2950
- return f.PivotCode === pathItem.field;
2951
- });
3171
+ var isRowsNotEmptyAndColumnsEmpty = function isRowsNotEmptyAndColumnsEmpty() {
3172
+ var pivotRows = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotRows) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotRows) : [];
3173
+ var pivotColumns = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotColumns) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotColumns) : [];
3174
+ return (pivotRows === null || pivotRows === void 0 ? void 0 : pivotRows.length) > 0 && (pivotColumns === null || pivotColumns === void 0 ? void 0 : pivotColumns.length) === 0;
3175
+ };
2952
3176
 
2953
- if (!field) {
2954
- return;
3177
+ var canShowColumnsGrandTotal = function canShowColumnsGrandTotal() {
3178
+ if (isRowsNotEmptyAndColumnsEmpty()) {
3179
+ return true;
2955
3180
  }
2956
3181
 
2957
- pivotFields.push({
2958
- FieldId: field.FieldId,
2959
- FieldType: field.FieldType ? field.FieldType : 'Field',
2960
- FieldValue: pathItem.key,
2961
- DateCode: field.DateCode
2962
- });
2963
- });
2964
- return pivotFields;
2965
- };
2966
- var getMeasureCaption = function getMeasureCaption(measure) {
2967
- var displayName = typeof measure.DisplayName == 'string' ? measure.DisplayName : '';
2968
-
2969
- if (measure.MeasureCode == 'Sum') {
2970
- return ConvertStringToPascalCaseHelper(displayName.replace('Sum of ', ''));
2971
- }
3182
+ var pivotTotalsSettings = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) : {};
3183
+ return !isNullOrUndefinedOrEmpty(pivotTotalsSettings.ShowColumnsGrandTotal) ? pivotTotalsSettings.ShowColumnsGrandTotal : false;
3184
+ };
2972
3185
 
2973
- return ConvertStringToPascalCaseHelper(displayName);
2974
- };
2975
- var parseJsonArray = function parseJsonArray(json) {
2976
- if (isNullOrUndefinedOrEmpty(json)) return [];
3186
+ var canShowRowsTotal = function canShowRowsTotal() {
3187
+ var pivotTotalsSettings = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) : {};
3188
+ return !isNullOrUndefinedOrEmpty(pivotTotalsSettings.ShowRowsTotal) ? pivotTotalsSettings.ShowRowsTotal : false;
3189
+ };
2977
3190
 
2978
- try {
2979
- var parsed = JSON.parse(json);
2980
- return parsed || [];
2981
- } catch (error) {
2982
- return [];
2983
- }
2984
- };
2985
- var parsePivotTotalsSettings = function parsePivotTotalsSettings(json) {
2986
- if (isNullOrUndefinedOrEmpty(json)) return {};
3191
+ var canShowColumnsTotal = function canShowColumnsTotal() {
3192
+ var pivotTotalsSettings = widget && !isNullOrUndefinedOrEmpty(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) ? JSON.parse(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings) : {};
3193
+ return !isNullOrUndefinedOrEmpty(pivotTotalsSettings.ShowColumnsTotal) ? pivotTotalsSettings.ShowColumnsTotal : false;
3194
+ };
2987
3195
 
2988
- try {
2989
- return JSON.parse(json) || {};
2990
- } catch (error) {
2991
- return {};
2992
- }
2993
- };
3196
+ return React__default.createElement(React__default.Fragment, null, isLoading ? React__default.createElement("div", {
3197
+ className: 'dl-full-hight dl-flex-content-center spinner-custome'
3198
+ }, React__default.createElement(progressspinner.ProgressSpinner, {
3199
+ style: {
3200
+ width: '40px',
3201
+ height: '40px'
3202
+ },
3203
+ strokeWidth: "4",
3204
+ animationDuration: "2s"
3205
+ })) : React__default.createElement(PivotGrid__default, {
3206
+ id: "pivotGridId",
3207
+ ref: pivotGridRef,
3208
+ dataSource: dataSource,
3209
+ allowExpandAll: true,
3210
+ showBorders: true,
3211
+ className: 'pivot-grid-element',
3212
+ onCellClick: onCellClick,
3213
+ onCellPrepared: onCellPrepared,
3214
+ showRowGrandTotals: canShowRowsGrandTotal(),
3215
+ showColumnGrandTotals: canShowColumnsGrandTotal(),
3216
+ showRowTotals: canShowRowsTotal(),
3217
+ showColumnTotals: canShowColumnsTotal(),
3218
+ showTotalsPrior: 'none',
3219
+ wordWrapEnabled: true
3220
+ }, React__default.createElement(PivotGrid.FieldPanel, {
3221
+ showColumnFields: false,
3222
+ showDataFields: false,
3223
+ showFilterFields: false,
3224
+ showRowFields: false,
3225
+ texts: {
3226
+ rowFieldArea: ""
3227
+ },
3228
+ allowFieldDragging: false,
3229
+ visible: true
3230
+ }), React__default.createElement(PivotGrid.FieldChooser, {
3231
+ enabled: false
3232
+ }), React__default.createElement(PivotGrid.Scrolling, {
3233
+ mode: "virtual"
3234
+ })));
3235
+ });
2994
3236
 
2995
3237
  var ROW_GROUP_COLUMN_MIN_WIDTH = 100;
2996
3238
 
@@ -3107,11 +3349,14 @@ var AgPivotGrid = React.forwardRef(function (props, _comRef) {
3107
3349
  return lookupDisplayName(field, rawValue);
3108
3350
  };
3109
3351
 
3110
- var applyPivotDataCellFormatting = function applyPivotDataCellFormatting(colDef) {
3352
+ var applyPivotDataCellFormatting = function applyPivotDataCellFormatting(colDef, measure) {
3111
3353
  colDef.sortable = false;
3112
3354
  colDef.filter = false;
3113
- colDef.cellClass = 'dl-ag-pivot-data-cell';
3114
- colDef.type = 'numericColumn';
3355
+ colDef.cellClass = measure ? getPivotDataCellClassNames(measure) : 'dl-ag-pivot-data-cell';
3356
+
3357
+ if (!measure || !isPivotDateMinMaxMeasure(measure)) {
3358
+ colDef.type = 'numericColumn';
3359
+ }
3115
3360
  };
3116
3361
 
3117
3362
  var buildGridFromPivotResponse = function buildGridFromPivotResponse() {
@@ -3181,28 +3426,36 @@ var AgPivotGrid = React.forwardRef(function (props, _comRef) {
3181
3426
  };
3182
3427
  };
3183
3428
 
3429
+ var getMeasureAggFunc = function getMeasureAggFunc(measure) {
3430
+ if (!isPivotDateMinMaxMeasure(measure)) return 'logitudeSum';
3431
+ return measure.MeasureCode === 'Max' ? 'logitudeMax' : 'logitudeMin';
3432
+ };
3433
+
3184
3434
  var createMeasureColDef = function createMeasureColDef(measure) {
3185
- return {
3435
+ var colDef = {
3186
3436
  field: measure.PivotMeasureCode,
3187
3437
  headerName: getMeasureCaption(measure),
3188
- aggFunc: 'logitudeSum',
3438
+ aggFunc: getMeasureAggFunc(measure),
3189
3439
  enableValue: true,
3190
3440
  wrapText: true,
3191
3441
  autoHeight: true,
3192
3442
  sortable: false,
3193
3443
  filter: false,
3194
- cellClass: 'dl-ag-pivot-data-cell',
3195
- type: 'numericColumn',
3444
+ cellClass: getPivotDataCellClassNames(measure),
3196
3445
  valueFormatter: function valueFormatter(params) {
3446
+ if (isPivotDateMinMaxMeasure(measure) && isAgGridPivotDateMeasureTotalDisplayCell(params)) {
3447
+ return '';
3448
+ }
3449
+
3197
3450
  return formatPivotMeasureValue(params.value, measure);
3198
3451
  }
3199
3452
  };
3200
- };
3201
3453
 
3202
- var isRowsEmptyAndColumnsNotEmpty = function isRowsEmptyAndColumnsNotEmpty() {
3203
- var pivotRows = parseJsonArray(widget === null || widget === void 0 ? void 0 : widget.PivotRows);
3204
- var pivotColumns = parseJsonArray(widget === null || widget === void 0 ? void 0 : widget.PivotColumns);
3205
- return pivotRows.length === 0 && pivotColumns.length > 0;
3454
+ if (!isPivotDateMinMaxMeasure(measure)) {
3455
+ colDef.type = 'numericColumn';
3456
+ }
3457
+
3458
+ return colDef;
3206
3459
  };
3207
3460
 
3208
3461
  var isRowsNotEmptyAndColumnsEmpty = function isRowsNotEmptyAndColumnsEmpty() {
@@ -3212,7 +3465,6 @@ var AgPivotGrid = React.forwardRef(function (props, _comRef) {
3212
3465
  };
3213
3466
 
3214
3467
  var canShowRowsGrandTotal = function canShowRowsGrandTotal() {
3215
- if (isRowsEmptyAndColumnsNotEmpty()) return true;
3216
3468
  var settings = parsePivotTotalsSettings(widget === null || widget === void 0 ? void 0 : widget.PivotTotalsSettings);
3217
3469
  return !isNullOrUndefinedOrEmpty(settings.ShowRowsGrandTotal) ? !!settings.ShowRowsGrandTotal : false;
3218
3470
  };
@@ -3260,12 +3512,18 @@ var AgPivotGrid = React.forwardRef(function (props, _comRef) {
3260
3512
  }
3261
3513
  }
3262
3514
 
3263
- applyPivotDataCellFormatting(colDef);
3515
+ var measure = resolveMeasureForSecondaryColDef(colDef, pivotMeasuresRef.current);
3516
+ applyPivotDataCellFormatting(colDef, measure);
3264
3517
 
3265
3518
  colDef.valueFormatter = function (params) {
3266
- var measure = resolveMeasureForSecondaryColDef(params.colDef, pivotMeasuresRef.current);
3267
- if (!measure) return '';
3268
- return formatPivotMeasureValue(params.value, measure);
3519
+ var resolvedMeasure = measure || resolveMeasureForSecondaryColDef(params.colDef, pivotMeasuresRef.current);
3520
+ if (!resolvedMeasure) return '';
3521
+
3522
+ if (isPivotDateMinMaxMeasure(resolvedMeasure) && isAgGridPivotDateMeasureTotalDisplayCell(params)) {
3523
+ return '';
3524
+ }
3525
+
3526
+ return formatPivotMeasureValue(params.value, resolvedMeasure);
3269
3527
  };
3270
3528
  }, []);
3271
3529
  var onCellClicked = React.useCallback(function (event) {
@@ -3331,7 +3589,9 @@ var AgPivotGrid = React.forwardRef(function (props, _comRef) {
3331
3589
  }, []);
3332
3590
  var aggFuncs = React.useMemo(function () {
3333
3591
  return {
3334
- logitudeSum: logitudeSumAgg
3592
+ logitudeSum: logitudeSumAgg,
3593
+ logitudeMin: logitudeMinAgg,
3594
+ logitudeMax: logitudeMaxAgg
3335
3595
  };
3336
3596
  }, []);
3337
3597
  var scheduleRowGrandTotalHeaderLabel = React.useCallback(function () {