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