UNPKG

@visactor/vtable

Version:

canvas table width high performance

656 lines (636 loc) 82.2 kB
import { HierarchyState, SortType } from "./ts-types"; import { PivotHeaderLayoutMap } from "./layout/pivot-header-layout"; import { FlatDataToObjects } from "./dataset/flatDataToObject"; import { PIVOT_TABLE_EVENT_TYPE } from "./ts-types/pivot-table/PIVOT_TABLE_EVENT_TYPE"; import { cellInRange } from "./tools/helper"; import { Dataset } from "./dataset/dataset"; import { BaseTable } from "./core/BaseTable"; import { cloneDeep, isNumber, isValid } from "@visactor/vutils"; import { Env } from "./tools/env"; import { DimensionTree } from "./layout/tree-helper"; import { TABLE_EVENT_TYPE } from "./core/TABLE_EVENT_TYPE"; import { EditManager } from "./edit/edit-manager"; import * as editors from "./edit/editors"; import { computeColWidth } from "./scenegraph/layout/compute-col-width"; import { computeRowHeight } from "./scenegraph/layout/compute-row-height"; import { isAllDigits } from "./tools/util"; import { cloneDeepSpec } from "@visactor/vutils-extension"; import { deleteHideIndicatorNode, parseColKeyRowKeyForPivotTable, supplementIndicatorNodesForCustomTree } from "./layout/layout-helper"; import { Factory } from "./core/factory"; import { clearChartRenderQueue } from "./scenegraph/graphic/contributions/chart-render-helper"; export class PivotTable extends BaseTable { constructor(container, options) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z; if (super(container, options), this.layoutNodeId = { seqId: 0 }, options = this.options) { options.rowHierarchyType || (options.rowHierarchyType = "grid"), options.columnHierarchyType || (options.columnHierarchyType = "grid"), options.layout && Object.assign(options, options.layout), this.internalProps.columns = cloneDeep(options.columns), this.internalProps.rows = cloneDeep(options.rows), this.internalProps.indicators = cloneDeepSpec(options.indicators), null === (_a = options.indicators) || void 0 === _a || _a.forEach(((indicatorDefine, index) => { "object" == typeof indicatorDefine && (null == indicatorDefine ? void 0 : indicatorDefine.editor) && (this.internalProps.indicators[index].editor = indicatorDefine.editor); })), this.internalProps.columnTree = !options.indicatorsAsCol || (null === (_b = options.columns) || void 0 === _b ? void 0 : _b.length) || options.columnTree ? cloneDeep(options.columnTree) : [], this.internalProps.rowTree = options.indicatorsAsCol || (null === (_c = options.rows) || void 0 === _c ? void 0 : _c.length) || options.rowTree ? cloneDeep(options.rowTree) : [], this.internalProps.records = options.records, this.pagination = options.pagination, this.internalProps.columnResizeType = null !== (_f = null !== (_e = null === (_d = options.resize) || void 0 === _d ? void 0 : _d.columnResizeType) && void 0 !== _e ? _e : options.columnResizeType) && void 0 !== _f ? _f : "column", this.internalProps.rowResizeType = null !== (_j = null !== (_h = null === (_g = options.resize) || void 0 === _g ? void 0 : _g.rowResizeType) && void 0 !== _h ? _h : options.rowResizeType) && void 0 !== _j ? _j : "row", this.internalProps.dataConfig = cloneDeep(options.dataConfig), this.internalProps.columnWidthConfig = options.columnWidthConfig, this.internalProps.columnWidthConfigForRowHeader = options.columnWidthConfigForRowHeader; const records = this.internalProps.records; if (this.internalProps.recordsIsTwoDimensionalArray = !1, (null === (_k = null == records ? void 0 : records[0]) || void 0 === _k ? void 0 : _k.constructor) === Array && (this.internalProps.recordsIsTwoDimensionalArray = !0), !1 === (null === (_l = options.customConfig) || void 0 === _l ? void 0 : _l.enableDataAnalysis)) { const columnDimensionTree = new DimensionTree(null !== (_m = this.internalProps.columnTree) && void 0 !== _m ? _m : [], this.layoutNodeId, this.options.columnHierarchyType, "grid" !== this.options.columnHierarchyType ? null !== (_o = this.options.columnExpandLevel) && void 0 !== _o ? _o : 1 : void 0), rowDimensionTree = new DimensionTree(null !== (_p = this.internalProps.rowTree) && void 0 !== _p ? _p : [], this.layoutNodeId, this.options.rowHierarchyType, "grid" !== this.options.rowHierarchyType ? null !== (_q = this.options.rowExpandLevel) && void 0 !== _q ? _q : 1 : void 0); this.internalProps.layoutMap = new PivotHeaderLayoutMap(this, null, columnDimensionTree, rowDimensionTree), !1 === this.internalProps.recordsIsTwoDimensionalArray && (this.flatDataToObjects = new FlatDataToObjects({ rows: this.internalProps.layoutMap.fullRowDimensionKeys, columns: this.internalProps.layoutMap.colDimensionKeys, indicators: this.internalProps.layoutMap.indicatorKeys, indicatorsAsCol: this.internalProps.layoutMap.indicatorsAsCol, indicatorDimensionKey: this.internalProps.layoutMap.indicatorDimensionKey }, records)); } else { const keysResults = parseColKeyRowKeyForPivotTable(this, options), {rowKeys: rowKeys, columnKeys: columnKeys, indicatorKeys: indicatorKeys} = keysResults; let {columnDimensionTree: columnDimensionTree, rowDimensionTree: rowDimensionTree} = keysResults; this.dataset = new Dataset(this.internalProps.dataConfig, rowKeys, columnKeys, indicatorKeys, this.internalProps.indicators, null === (_r = options.indicatorsAsCol) || void 0 === _r || _r, options.records, options.rowHierarchyType, options.columnHierarchyType, this.internalProps.columnTree, this.internalProps.rowTree, !1, !!options.extensionRows, !!options.parseCustomTreeToMatchRecords), options.columnTree ? columnDimensionTree.hasHideNode && (deleteHideIndicatorNode(columnDimensionTree.tree.children, options.indicators, !0, this), columnDimensionTree.reset(columnDimensionTree.tree.children)) : (!1 !== options.indicatorsAsCol && (this.dataset.colHeaderTree = supplementIndicatorNodesForCustomTree(this.dataset.colHeaderTree, options.indicators)), !1 !== options.indicatorsAsCol && options.indicators && this.dataset.colHeaderTree && deleteHideIndicatorNode(this.dataset.colHeaderTree, options.indicators, !1, this), columnDimensionTree = new DimensionTree(null !== (_s = this.dataset.colHeaderTree) && void 0 !== _s ? _s : [], this.layoutNodeId, this.options.columnHierarchyType, "grid" !== this.options.columnHierarchyType ? null !== (_t = this.options.columnExpandLevel) && void 0 !== _t ? _t : 1 : void 0)), options.rowTree ? rowDimensionTree.hasHideNode && (deleteHideIndicatorNode(rowDimensionTree.tree.children, options.indicators, !0, this), rowDimensionTree.reset(rowDimensionTree.tree.children)) : (!1 === options.indicatorsAsCol && (this.dataset.rowHeaderTree = supplementIndicatorNodesForCustomTree(this.dataset.rowHeaderTree, options.indicators)), !1 === options.indicatorsAsCol && this.dataset.rowHeaderTree && options.indicators && deleteHideIndicatorNode(this.dataset.rowHeaderTree, options.indicators, !1, this), rowDimensionTree = new DimensionTree(null !== (_u = this.dataset.rowHeaderTree) && void 0 !== _u ? _u : [], this.layoutNodeId, this.options.rowHierarchyType, "grid" !== this.options.rowHierarchyType ? null !== (_v = this.options.rowExpandLevel) && void 0 !== _v ? _v : 1 : void 0)), this.internalProps.layoutMap = new PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree); } if (this._changePivotSortStateBySortRules(), (null !== (_x = null === (_w = options.pivotSortState) || void 0 === _w ? void 0 : _w.length) && void 0 !== _x ? _x : 0) > 0 && (this.pivotSortState = [], this.pivotSortState = options.pivotSortState), "node" !== Env.mode && (this.editorManager = new EditManager(this)), this.refreshHeader(), this.internalProps.useOneRowHeightFillAll = !1, this.stateManager.initCheckedState(records), this.scenegraph.createSceneGraph(), options.title) { const Title = Factory.getComponent("title"); this.internalProps.title = new Title(options.title, this); } if (this.options.emptyTip) if (this.internalProps.emptyTip) null === (_y = this.internalProps.emptyTip) || void 0 === _y || _y.resetVisible(); else { const EmptyTip = Factory.getComponent("emptyTip"); this.internalProps.emptyTip = new EmptyTip(this.options.emptyTip, this), null === (_z = this.internalProps.emptyTip) || void 0 === _z || _z.resetVisible(); } this.resize(), setTimeout((() => { this.isReleased || this.fireListeners(TABLE_EVENT_TYPE.INITIALIZED, null); }), 0); } } static get EVENT_TYPE() { return PIVOT_TABLE_EVENT_TYPE; } isListTable() { return !1; } isPivotTable() { return !0; } isPivotChart() { return !1; } get recordsCount() { var _a; return null === (_a = this.records) || void 0 === _a ? void 0 : _a.length; } _canResizeColumn(col, row) { const ifCan = super._canResizeColumn(col, row); if (ifCan) { if (this.internalProps.layoutMap.isSeriesNumber(col, row) && !0 === this.internalProps.rowSeriesNumber.disableColumnResize) return !1; if (!this.internalProps.layoutMap.indicatorsAsCol) { const cellDefine = this.internalProps.layoutMap.getBody(col, this.columnHeaderLevelCount); if (null == cellDefine ? void 0 : cellDefine.disableColumnResize) return !1; } } return ifCan; } updateOption(options, updateConfig = { clearColWidthCache: !0, clearRowHeightCache: !0 }) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1; const internalProps = this.internalProps; if (super.updateOption(options, updateConfig), options.rowHierarchyType || (options.rowHierarchyType = "grid"), options.columnHierarchyType || (options.columnHierarchyType = "grid"), this.layoutNodeId = { seqId: 0 }, this.internalProps.columns = cloneDeep(options.columns), this.internalProps.rows = cloneDeep(options.rows), this.internalProps.indicators = (null === (_a = options.indicators) || void 0 === _a ? void 0 : _a.length) ? cloneDeepSpec(options.indicators) : [], null === (_b = options.indicators) || void 0 === _b || _b.forEach(((indicatorDefine, index) => { "object" == typeof indicatorDefine && (null == indicatorDefine ? void 0 : indicatorDefine.editor) && (this.internalProps.indicators[index].editor = indicatorDefine.editor); })), this.internalProps.columnTree = !options.indicatorsAsCol || (null === (_c = options.columns) || void 0 === _c ? void 0 : _c.length) || options.columnTree ? cloneDeep(options.columnTree) : [], this.internalProps.rowTree = options.indicatorsAsCol || (null === (_d = options.rows) || void 0 === _d ? void 0 : _d.length) || options.rowTree ? cloneDeep(options.rowTree) : [], options.records && (this.internalProps.records = options.records), this.stateManager.initCheckedState(this.internalProps.records), this.stateManager.updateDrillState(void 0, void 0, !1, !1, -1, -1), this.pagination = options.pagination, internalProps.columnResizeType = null !== (_g = null !== (_f = null === (_e = options.resize) || void 0 === _e ? void 0 : _e.columnResizeType) && void 0 !== _f ? _f : options.columnResizeType) && void 0 !== _g ? _g : "column", internalProps.rowResizeType = null !== (_k = null !== (_j = null === (_h = options.resize) || void 0 === _h ? void 0 : _h.rowResizeType) && void 0 !== _j ? _j : options.rowResizeType) && void 0 !== _k ? _k : "row", internalProps.dataConfig = cloneDeep(options.dataConfig), this.internalProps.columnWidthConfig = options.columnWidthConfig, this.internalProps.columnWidthConfigForRowHeader = options.columnWidthConfigForRowHeader, "grid" !== (null == options ? void 0 : options.rowHierarchyType) && "grid" !== this.internalProps.layoutMap.rowHierarchyType && this.internalProps.layoutMap.rowExpandLevel === (null == options ? void 0 : options.rowExpandLevel)) { const beforeRowDimensions = this.internalProps.layoutMap.rowDimensionTree.tree.children; null === (_l = this.internalProps.rowTree) || void 0 === _l || _l.forEach(((node, index) => { const beforeRowDimension = beforeRowDimensions.find((item => item.dimensionKey === node.dimensionKey && item.value === node.value)); beforeRowDimension && this._syncHierarchyState(beforeRowDimension, node); })); } const records = this.internalProps.records; if (this.internalProps.recordsIsTwoDimensionalArray = !1, (null === (_m = null == records ? void 0 : records[0]) || void 0 === _m ? void 0 : _m.constructor) === Array && (this.internalProps.recordsIsTwoDimensionalArray = !0), !1 === (null === (_o = options.customConfig) || void 0 === _o ? void 0 : _o.enableDataAnalysis)) { let columnDimensionTree, rowDimensionTree; options.columnTree && (columnDimensionTree = new DimensionTree(null !== (_p = this.internalProps.columnTree) && void 0 !== _p ? _p : [], this.layoutNodeId, this.options.columnHierarchyType, "grid" !== this.options.columnHierarchyType ? null !== (_q = this.options.columnExpandLevel) && void 0 !== _q ? _q : 1 : void 0)), options.rowTree && (rowDimensionTree = new DimensionTree(null !== (_r = this.internalProps.rowTree) && void 0 !== _r ? _r : [], this.layoutNodeId, this.options.rowHierarchyType, "grid" !== this.options.rowHierarchyType ? null !== (_s = this.options.rowExpandLevel) && void 0 !== _s ? _s : 1 : void 0)), internalProps.layoutMap.clearHeaderPathCache(), internalProps.layoutMap = new PivotHeaderLayoutMap(this, null, columnDimensionTree, rowDimensionTree), !1 === this.internalProps.recordsIsTwoDimensionalArray && (this.flatDataToObjects = new FlatDataToObjects({ rows: internalProps.layoutMap.fullRowDimensionKeys, columns: internalProps.layoutMap.colDimensionKeys, indicators: internalProps.layoutMap.indicatorKeys, indicatorsAsCol: internalProps.layoutMap.indicatorsAsCol, indicatorDimensionKey: internalProps.layoutMap.indicatorDimensionKey }, records)); } else { const keysResults = parseColKeyRowKeyForPivotTable(this, options), {rowKeys: rowKeys, columnKeys: columnKeys, indicatorKeys: indicatorKeys} = keysResults; let {columnDimensionTree: columnDimensionTree, rowDimensionTree: rowDimensionTree} = keysResults; this.dataset = new Dataset(internalProps.dataConfig, rowKeys, columnKeys, indicatorKeys, this.internalProps.indicators, null === (_t = options.indicatorsAsCol) || void 0 === _t || _t, records, options.rowHierarchyType, options.columnHierarchyType, this.internalProps.columnTree, this.internalProps.rowTree, !1, !!options.extensionRows, !!options.parseCustomTreeToMatchRecords), options.columnTree ? columnDimensionTree.hasHideNode && (deleteHideIndicatorNode(columnDimensionTree.tree.children, options.indicators, !0, this), columnDimensionTree.reset(columnDimensionTree.tree.children)) : (!1 !== options.indicatorsAsCol && (this.dataset.colHeaderTree = supplementIndicatorNodesForCustomTree(this.dataset.colHeaderTree, options.indicators)), !1 !== options.indicatorsAsCol && options.indicators && this.dataset.colHeaderTree && deleteHideIndicatorNode(this.dataset.colHeaderTree, options.indicators, !1, this), columnDimensionTree = new DimensionTree(null !== (_u = this.dataset.colHeaderTree) && void 0 !== _u ? _u : [], this.layoutNodeId, this.options.columnHierarchyType, "grid" !== this.options.columnHierarchyType ? null !== (_v = this.options.columnExpandLevel) && void 0 !== _v ? _v : 1 : void 0)), options.rowTree ? rowDimensionTree.hasHideNode && (deleteHideIndicatorNode(rowDimensionTree.tree.children, options.indicators, !0, this), rowDimensionTree.reset(rowDimensionTree.tree.children)) : (!1 === options.indicatorsAsCol && (this.dataset.rowHeaderTree = supplementIndicatorNodesForCustomTree(this.dataset.rowHeaderTree, options.indicators)), !1 === options.indicatorsAsCol && this.dataset.rowHeaderTree && options.indicators && deleteHideIndicatorNode(this.dataset.rowHeaderTree, options.indicators, !1, this), rowDimensionTree = new DimensionTree(null !== (_w = this.dataset.rowHeaderTree) && void 0 !== _w ? _w : [], this.layoutNodeId, this.options.rowHierarchyType, "grid" !== this.options.rowHierarchyType ? null !== (_x = this.options.rowExpandLevel) && void 0 !== _x ? _x : 1 : void 0)), internalProps.layoutMap = new PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree); } if (this._changePivotSortStateBySortRules(), (null !== (_z = null === (_y = options.pivotSortState) || void 0 === _y ? void 0 : _y.length) && void 0 !== _z ? _z : 0) > 0 && (this.pivotSortState = [], this.pivotSortState = options.pivotSortState), this.refreshHeader(), this.internalProps.useOneRowHeightFillAll = !1, internalProps.releaseList && (internalProps.releaseList.forEach((releaseObj => { var _a; return null === (_a = null == releaseObj ? void 0 : releaseObj.release) || void 0 === _a ? void 0 : _a.call(releaseObj); })), internalProps.releaseList = null), this.scenegraph.clearCells(), this.scenegraph.createSceneGraph(), options.title) { const Title = Factory.getComponent("title"); this.internalProps.title = new Title(options.title, this); } if (this.options.emptyTip) if (this.internalProps.emptyTip) null === (_0 = this.internalProps.emptyTip) || void 0 === _0 || _0.resetVisible(); else { const EmptyTip = Factory.getComponent("emptyTip"); this.internalProps.emptyTip = new EmptyTip(this.options.emptyTip, this), null === (_1 = this.internalProps.emptyTip) || void 0 === _1 || _1.resetVisible(); } return this.resize(), setTimeout((() => { this.fireListeners(TABLE_EVENT_TYPE.UPDATED, null); }), 0), new Promise((resolve => { setTimeout(resolve, 0); })); } updatePagination(pagination) { this.internalProps.layoutMap.clearHeaderPathCache(), pagination ? (this.pagination || (this.pagination = { currentPage: 0, perPageCount: 0 }), "number" == typeof pagination.currentPage && pagination.currentPage >= 0 && (this.pagination.currentPage = pagination.currentPage), pagination.perPageCount && (this.pagination.perPageCount = pagination.perPageCount || this.pagination.perPageCount), this.scenegraph.clearCells(), this.internalProps.layoutMap.setPagination(this.pagination), this.refreshRowColCount(), this.scenegraph.createSceneGraph(), this.render()) : this.pagination && (this.pagination = void 0, this.scenegraph.clearCells(), this.internalProps.layoutMap.setPagination(void 0), this.refreshRowColCount(), this.scenegraph.createSceneGraph(), this.render()); } refreshHeader() { this.setMinMaxLimitWidth(!0), this.refreshRowColCount(); } refreshRowColCount() { var _a, _b, _c, _d, _e, _f, _g, _h, _j; const table = this, {layoutMap: layoutMap} = table.internalProps; layoutMap && (table.colCount = null !== (_a = layoutMap.colCount) && void 0 !== _a ? _a : 0, table.rowCount = null !== (_b = layoutMap.rowCount) && void 0 !== _b ? _b : 0, this.internalProps.frozenColCount = null !== (_c = this.options.frozenColCount) && void 0 !== _c ? _c : (null !== (_d = layoutMap.rowHeaderLevelCount) && void 0 !== _d ? _d : 0) + layoutMap.leftRowSeriesNumberColumnCount, table._setFrozenRowCount(Math.max(layoutMap.headerLevelCount, null !== (_e = this.options.frozenRowCount) && void 0 !== _e ? _e : 0)), table.bottomFrozenRowCount !== (null !== (_f = this.options.bottomFrozenRowCount) && void 0 !== _f ? _f : 0) && (table.bottomFrozenRowCount = null !== (_g = this.options.bottomFrozenRowCount) && void 0 !== _g ? _g : 0), table.rightFrozenColCount !== (null !== (_h = this.options.rightFrozenColCount) && void 0 !== _h ? _h : 0) && (table.rightFrozenColCount = null !== (_j = this.options.rightFrozenColCount) && void 0 !== _j ? _j : 0), this.stateManager.setFrozenCol(this.internalProps.frozenColCount), this.stateManager.setFrozenRow(this.frozenRowCount)); } _getSortFuncFromHeaderOption(columns, field, fieldKey) {} get rowHierarchyType() { return this.internalProps.layoutMap.rowHierarchyType; } get columnHierarchyType() { return this.internalProps.layoutMap.columnHierarchyType; } _syncHierarchyState(sourceNode, targetNode) { var _a, _b, _c; sourceNode.value === targetNode.value && sourceNode.dimensionKey === targetNode.dimensionKey && (targetNode.hierarchyState = null !== (_a = targetNode.hierarchyState) && void 0 !== _a ? _a : (null == targetNode ? void 0 : targetNode.children) ? sourceNode.hierarchyState : void 0, null === (_c = null === (_b = null == targetNode ? void 0 : targetNode.children) || void 0 === _b ? void 0 : _b.forEach) || void 0 === _c || _c.call(_b, ((targetChildNode, index) => { var _a; if ((null === (_a = null == sourceNode ? void 0 : sourceNode.children) || void 0 === _a ? void 0 : _a[index]) && targetChildNode) { const beforeRowDimension = sourceNode.children.find((item => item.dimensionKey === targetChildNode.dimensionKey && item.value === targetChildNode.value)); beforeRowDimension && this._syncHierarchyState(beforeRowDimension, targetChildNode); } }))); } getRecordShowIndexByCell(col, row) {} getTableIndexByRecordIndex(recordIndex) {} getTableIndexByField(field) {} getCellAddrByFieldRecord(field, recordIndex) {} getBodyIndexByRow(row) { const {layoutMap: layoutMap} = this.internalProps; return layoutMap.getBodyIndexByRow(row); } getBodyIndexByCol(col) { const {layoutMap: layoutMap} = this.internalProps; return layoutMap.getBodyIndexByCol(col); } getFieldData(field, col, row) { var _a, _b, _c; if (!this.internalProps.layoutMap.isHeader(col, row)) { if (this.internalProps.recordsIsTwoDimensionalArray) { const rowIndex = this.getBodyIndexByRow(row), colIndex = this.getBodyIndexByCol(col); return null === (_a = this.records[rowIndex]) || void 0 === _a ? void 0 : _a[colIndex]; } if (this.dataset) { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row); if (cellDimensionPath) { let indicatorPosition; const colKeys = null === (_b = cellDimensionPath.colHeaderPaths) || void 0 === _b ? void 0 : _b.filter((path => !path.virtual)).map(((colPath, index) => { var _a; return colPath.indicatorKey && (indicatorPosition = { position: "col", index: index }), null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = null === (_c = cellDimensionPath.rowHeaderPaths) || void 0 === _c ? void 0 : _c.filter((path => !path.virtual)).map(((rowPath, index) => { var _a; return rowPath.indicatorKey && (indicatorPosition = { position: "row", index: index }), null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), aggregator = this.dataset.getAggregator(rowKeys, colKeys, this.internalProps.layoutMap.getIndicatorKey(col, row), !0, indicatorPosition); if (aggregator.records && aggregator.records.length >= 1) return aggregator.records[0][field]; } } else if (this.flatDataToObjects) { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = cellDimensionPath.colHeaderPaths.map((colPath => { var _a; return null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath => { var _a; return null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), treeNode = this.flatDataToObjects.getTreeNode(rowKeys, colKeys, this.internalProps.layoutMap.getBody(col, row).indicatorKey, !1); if (null == treeNode ? void 0 : treeNode.record) return null == treeNode ? void 0 : treeNode.record[field]; } } } getCellValue(col, row, skipCustomMerge) { var _a, _b, _c, _d, _e, _f, _g; if (!skipCustomMerge) { const customMergeText = this.getCustomMergeValue(col, row); if (customMergeText) return customMergeText; } if (this.internalProps.layoutMap.isSeriesNumber(col, row)) { if (this.internalProps.layoutMap.isSeriesNumberInHeader(col, row)) { const {title: title} = this.internalProps.layoutMap.getSeriesNumberHeader(col, row); return title; } const {format: format} = this.internalProps.layoutMap.getSeriesNumberBody(col, row); return "function" == typeof format ? format(col, row, this) : row - this.columnHeaderLevelCount + 1; } if (this.internalProps.layoutMap.isHeader(col, row)) { const {title: title, fieldFormat: fieldFormat} = this.internalProps.layoutMap.getHeader(col, row); return "function" == typeof fieldFormat ? fieldFormat(title, col, row, this) : title; } if (this.internalProps.recordsIsTwoDimensionalArray) { const {fieldFormat: fieldFormat} = this.internalProps.layoutMap.getBody(col, row), rowIndex = this.getBodyIndexByRow(row), colIndex = this.getBodyIndexByCol(col), dataValue = null === (_a = this.records[rowIndex]) || void 0 === _a ? void 0 : _a[colIndex]; if ("function" == typeof fieldFormat) { return fieldFormat(dataValue, col, row, this); } return dataValue; } if (this.dataset) { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row); let indicatorPosition; const colKeys = null === (_c = null === (_b = cellDimensionPath.colHeaderPaths) || void 0 === _b ? void 0 : _b.filter((path => !path.virtual))) || void 0 === _c ? void 0 : _c.map(((colPath, index) => { var _a; return colPath.indicatorKey && (indicatorPosition = { position: "col", index: index }), null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = null === (_e = null === (_d = cellDimensionPath.rowHeaderPaths) || void 0 === _d ? void 0 : _d.filter((path => !path.virtual))) || void 0 === _e ? void 0 : _e.map(((rowPath, index) => { var _a; return rowPath.indicatorKey && (indicatorPosition = { position: "row", index: index }), null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), aggregator = this.dataset.getAggregator(rowKeys, colKeys, this.internalProps.layoutMap.getIndicatorKey(col, row), !0, indicatorPosition), {fieldFormat: fieldFormat} = this.internalProps.layoutMap.getBody(col, row); return aggregator.formatValue ? aggregator.formatValue(col, row, this) : "function" == typeof fieldFormat ? fieldFormat(null == aggregator ? void 0 : aggregator.value(), col, row, this) : null !== (_f = null == aggregator ? void 0 : aggregator.value()) && void 0 !== _f ? _f : ""; } if (this.flatDataToObjects) { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = cellDimensionPath.colHeaderPaths.map((colPath => { var _a; return null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath => { var _a; return null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), valueNode = this.flatDataToObjects.getTreeNode(rowKeys, colKeys, this.internalProps.layoutMap.getBody(col, row).indicatorKey), {fieldFormat: fieldFormat} = this.internalProps.layoutMap.getBody(col, row); return "function" == typeof fieldFormat ? fieldFormat(null == valueNode ? void 0 : valueNode.value, col, row, this) : null !== (_g = null == valueNode ? void 0 : valueNode.value) && void 0 !== _g ? _g : ""; } } getCellOriginValue(col, row) { var _a, _b, _c; const table = this; if (table.internalProps.layoutMap.isHeader(col, row)) { const {title: title} = table.internalProps.layoutMap.getHeader(col, row); return "function" == typeof title ? title() : title; } if (this.internalProps.recordsIsTwoDimensionalArray) { const rowIndex = this.getBodyIndexByRow(row), colIndex = this.getBodyIndexByCol(col); return null === (_a = this.records[rowIndex]) || void 0 === _a ? void 0 : _a[colIndex]; } if (this.dataset) { let indicatorPosition; const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = null === (_b = cellDimensionPath.colHeaderPaths) || void 0 === _b ? void 0 : _b.filter((path => !path.virtual)).map(((colPath, index) => { var _a; return colPath.indicatorKey && (indicatorPosition = { position: "col", index: index }), null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = null === (_c = cellDimensionPath.rowHeaderPaths) || void 0 === _c ? void 0 : _c.filter((path => !path.virtual)).map(((rowPath, index) => { var _a; return rowPath.indicatorKey && (indicatorPosition = { position: "row", index: index }), null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), aggregator = this.dataset.getAggregator(rowKeys, colKeys, this.internalProps.layoutMap.getIndicatorKey(col, row), !0, indicatorPosition); return aggregator.value ? aggregator.value() : void 0; } if (this.flatDataToObjects) { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = cellDimensionPath.colHeaderPaths.map((colPath => { var _a; return null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath => { var _a; return null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), treeNode = this.flatDataToObjects.getTreeNode(rowKeys, colKeys, this.internalProps.layoutMap.getBody(col, row).indicatorKey); return null == treeNode ? void 0 : treeNode.value; } } getCellRawValue(col, row) { var _a, _b, _c; const table = this; if (table.internalProps.layoutMap.isHeader(col, row)) { const {title: title} = table.internalProps.layoutMap.getHeader(col, row); return "function" == typeof title ? title() : title; } if (this.internalProps.recordsIsTwoDimensionalArray) { const rowIndex = this.getBodyIndexByRow(row), colIndex = this.getBodyIndexByCol(col); return null === (_a = this.records[rowIndex]) || void 0 === _a ? void 0 : _a[colIndex]; } if (this.dataset) { let indicatorPosition; const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = null === (_b = cellDimensionPath.colHeaderPaths) || void 0 === _b ? void 0 : _b.filter((path => !path.virtual)).map(((colPath, index) => { var _a; return colPath.indicatorKey && (indicatorPosition = { position: "col", index: index }), null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = null === (_c = cellDimensionPath.rowHeaderPaths) || void 0 === _c ? void 0 : _c.filter((path => !path.virtual)).map(((rowPath, index) => { var _a; return rowPath.indicatorKey && (indicatorPosition = { position: "row", index: index }), null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), aggregator = this.dataset.getAggregator(rowKeys, colKeys, this.internalProps.layoutMap.getIndicatorKey(col, row), !1, indicatorPosition); return aggregator.value ? aggregator.value() : void 0; } if (this.flatDataToObjects) { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = cellDimensionPath.colHeaderPaths.map((colPath => { var _a; return null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath => { var _a; return null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), treeNode = this.flatDataToObjects.getTreeNode(rowKeys, colKeys, this.internalProps.layoutMap.getBody(col, row).indicatorKey, !1); return null == treeNode ? void 0 : treeNode.value; } } getCellOriginRecord(col, row) { var _a, _b, _c; if (!this.internalProps.layoutMap.isHeader(col, row)) { if (this.internalProps.recordsIsTwoDimensionalArray) { const rowIndex = this.getBodyIndexByRow(row), colIndex = this.getBodyIndexByCol(col); return null === (_a = this.records[rowIndex]) || void 0 === _a ? void 0 : _a[colIndex]; } if (this.dataset) { let indicatorPosition; const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = null === (_b = cellDimensionPath.colHeaderPaths) || void 0 === _b ? void 0 : _b.filter((path => !path.virtual)).map(((colPath, index) => { var _a; return colPath.indicatorKey && (indicatorPosition = { position: "col", index: index }), null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = null === (_c = cellDimensionPath.rowHeaderPaths) || void 0 === _c ? void 0 : _c.filter((path => !path.virtual)).map(((rowPath, index) => { var _a; return rowPath.indicatorKey && (indicatorPosition = { position: "row", index: index }), null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })); return this.dataset.getAggregator(rowKeys, colKeys, this.internalProps.layoutMap.getIndicatorKey(col, row), !0, indicatorPosition).records; } if (this.flatDataToObjects) { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = cellDimensionPath.colHeaderPaths.map((colPath => { var _a; return null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath => { var _a; return null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), treeNode = this.flatDataToObjects.getTreeNode(rowKeys, colKeys, this.internalProps.layoutMap.getBody(col, row).indicatorKey); return null == treeNode ? void 0 : treeNode.record; } } } getCellRawRecord(col, row) { var _a, _b, _c; if (!this.internalProps.layoutMap.isHeader(col, row)) { if (this.internalProps.recordsIsTwoDimensionalArray) { const rowIndex = this.getBodyIndexByRow(row), colIndex = this.getBodyIndexByCol(col); return null === (_a = this.records[rowIndex]) || void 0 === _a ? void 0 : _a[colIndex]; } if (this.dataset) { let indicatorPosition; const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = null === (_b = cellDimensionPath.colHeaderPaths) || void 0 === _b ? void 0 : _b.filter((path => !path.virtual)).map(((colPath, index) => { var _a; return colPath.indicatorKey && (indicatorPosition = { position: "col", index: index }), null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = null === (_c = cellDimensionPath.rowHeaderPaths) || void 0 === _c ? void 0 : _c.filter((path => !path.virtual)).map(((rowPath, index) => { var _a; return rowPath.indicatorKey && (indicatorPosition = { position: "row", index: index }), null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })); return this.dataset.getAggregator(rowKeys, colKeys, this.internalProps.layoutMap.getIndicatorKey(col, row), !1, indicatorPosition).records; } if (this.flatDataToObjects) { const cellDimensionPath = this.internalProps.layoutMap.getCellHeaderPaths(col, row), colKeys = cellDimensionPath.colHeaderPaths.map((colPath => { var _a; return null !== (_a = colPath.indicatorKey) && void 0 !== _a ? _a : colPath.value; })), rowKeys = cellDimensionPath.rowHeaderPaths.map((rowPath => { var _a; return null !== (_a = rowPath.indicatorKey) && void 0 !== _a ? _a : rowPath.value; })), treeNode = this.flatDataToObjects.getTreeNode(rowKeys, colKeys, this.internalProps.layoutMap.getBody(col, row).indicatorKey, !1); return null == treeNode ? void 0 : treeNode.record; } } } updateSortRules(sortRules, col, row) { this.internalProps.dataConfig ? this.internalProps.dataConfig.sortRules = sortRules : this.internalProps.dataConfig = { sortRules: sortRules }, this.dataset.updateSortRules(sortRules), this._changePivotSortStateBySortRules(), this._filterHideIndicatorNode(); const {layoutMap: layoutMap} = this.internalProps; layoutMap.resetHeaderTree(), this.scenegraph.clearCells(), isNumber(col) && isNumber(row) ? (this.isRowHeader(col, row) ? (this.setMinMaxLimitWidth(!0), this.internalProps._widthResizedColMap.clear()) : this.isCornerHeader(col, row) ? "column" === layoutMap.cornerSetting.titleOnDimension ? (this.setMinMaxLimitWidth(!0), this.internalProps._widthResizedColMap.clear()) : "row" === layoutMap.cornerSetting.titleOnDimension && this.internalProps._heightResizedRowMap.clear() : this.isColumnHeader(col, row) && this.internalProps._heightResizedRowMap.clear(), this.refreshRowColCount()) : this.refreshHeader(), this.internalProps.useOneRowHeightFillAll = !1, this.scenegraph.createSceneGraph(!0), this.render(); } _changePivotSortStateBySortRules() { var _a, _b, _c, _d; this.pivotSortState = []; const sortRules = null !== (_b = null === (_a = this.internalProps.dataConfig) || void 0 === _a ? void 0 : _a.sortRules) && void 0 !== _b ? _b : []; for (let i = 0; i < sortRules.length; i++) { const sortRule = sortRules[i], dimensions = [], sortType = sortRule.sortType ? sortRule.sortType.toUpperCase() : "ASC"; if (sortRule.sortByIndicator && sortRule.sortField === (this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1])) { for (let j = 0; j < sortRule.query.length; j++) dimensions.push({ dimensionKey: this.dataset.indicatorsAsCol ? this.dataset.columns[j] : this.dataset.rows[j], value: sortRule.query[j] }); dimensions.push({ indicatorKey: sortRule.sortByIndicator, value: null !== (_d = null === (_c = this.internalProps.layoutMap.getIndicatorInfo(sortRule.sortByIndicator)) || void 0 === _c ? void 0 : _c.title) && void 0 !== _d ? _d : sortRule.sortByIndicator }), this.pivotSortState.push({ dimensions: dimensions, order: SortType[sortType] }); } else { const sortField = sortRule.sortField, rowIndex = this.dataset.rows.indexOf(sortField), colIndex = this.dataset.columns.indexOf(sortField); let pushed = !1; if (rowIndex >= 0) { const rowDimensions = []; for (let k = 0; k <= rowIndex; k++) rowDimensions.push({ dimensionKey: this.dataset.rows[k], isPivotCorner: !0, value: this.dataset.rows[k] }); this.pivotSortState.push({ dimensions: rowDimensions, order: SortType[sortType] }), pushed = !0; } if (colIndex >= 0) { const colDimensions = []; for (let k = 0; k <= colIndex; k++) colDimensions.push({ dimensionKey: this.dataset.columns[k], isPivotCorner: !0, value: this.dataset.columns[k] }); this.pivotSortState.push({ dimensions: colDimensions, order: SortType[sortType] }), pushed = !0; } pushed || (dimensions.push({ dimensionKey: sortField, isPivotCorner: !0, value: sortField }), this.pivotSortState.push({ dimensions: dimensions, order: SortType[sortType] })); } } } _filterHideIndicatorNode() { const options = this.options; !1 !== options.indicatorsAsCol && options.indicators && this.dataset.colHeaderTree && deleteHideIndicatorNode(this.dataset.colHeaderTree, options.indicators, !1, this), !1 === options.indicatorsAsCol && this.dataset.rowHeaderTree && options.indicators && deleteHideIndicatorNode(this.dataset.rowHeaderTree, options.indicators, !1, this); } updatePivotSortState(pivotSortStateConfig) { this.pivotSortState = pivotSortStateConfig; } sort(col, row, order) { var _a, _b; let dimensions; if (this.isCornerHeader(col, row)) { const dimensionInfo = this.getHeaderDefine(col, row); dimensions = []; const dimension = { isPivotCorner: !0, dimensionKey: dimensionInfo.value, value: dimensionInfo.value }; dimensions.push(dimension); } else dimensions = this.isColumnHeader(col, row) ? this.getCellHeaderPaths(col, row).colHeaderPaths : this.getCellHeaderPaths(col, row).rowHeaderPaths; const sortIndicator = dimensions[dimensions.length - 1].indicatorKey, headerDefine = this.getHeaderDefine(col, row); if (headerDefine.sort) { if (this.dataset.sortRules) { const cacheOldDimensionSortRule = {}; for (let i = this.dataset.sortRules.length - 1; i >= 0; i--) { const sortRule = this.dataset.sortRules[i]; (headerDefine.dimensionKey && sortRule.sortField === headerDefine.dimensionKey || sortIndicator && sortRule.sortField === (this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1])) && (cacheOldDimensionSortRule[sortRule.sortField] = sortRule, this.dataset.sortRules.splice(i, 1)); } if (sortIndicator) { const sortField = this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1]; this.dataset.sortRules.push({ sortField: sortField, sortType: SortType[order], sortByIndicator: sortIndicator, query: dimensions.reduce(((arr, dimension) => (dimension.dimensionKey && arr.push(dimension.value), arr)), []), sortFunc: null === (_a = cacheOldDimensionSortRule[sortField]) || void 0 === _a ? void 0 : _a.sortFunc }); } else this.dataset.sortRules.push(Object.assign(null !== (_b = cacheOldDimensionSortRule[headerDefine.dimensionKey]) && void 0 !== _b ? _b : {}, { sortField: headerDefine.dimensionKey, sortType: SortType[order] })); } else this.dataset.sortRules = sortIndicator ? [ { sortField: this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1], sortType: SortType[order], sortByIndicator: sortIndicator, query: dimensions.reduce(((arr, dimension) => (dimension.dimensionKey && arr.push(dimension.value), arr)), []) } ] : [ { sortField: headerDefine.dimensionKey, sortType: SortType[order] } ]; this.updateSortRules(this.dataset.sortRules, col, row); } } getPivotSortState(col, row) { var _a; if (!this.pivotSortState) return; const cellRange = this.getCellRange(col, row); for (let i = 0; i < this.pivotSortState.length; i++) { const pivotState = this.pivotSortState[i], dimensions = pivotState.dimensions; if (this.isCornerHeader(col, row)) { const layoutMap = this.internalProps.layoutMap, header = layoutMap.getHeader(col, row); if (header && header.pivotInfo && dimensions && dimensions.length > 0) { let cellPathKeys = []; const leftSnCount = null !== (_a = layoutMap.leftRowSeriesNumberColumnCount) && void 0 !== _a ? _a : 0; if ("row" === layoutMap.cornerSetting.titleOnDimension) { const dimIndex = col - leftSnCount; cellPathKeys = layoutMap.rowDimensionKeys.slice(0, dimIndex + 1); } else if ("column" === layoutMap.cornerSetting.titleOnDimension) { const dimIndex = row; cellPathKeys = layoutMap.colDimensionKeys.slice(0, dimIndex + 1); } else if ("all" === layoutMap.cornerSetting.titleOnDimension) if (layoutMap.indicatorsAsCol) { let indicatorAtIndex = layoutMap.colDimensionKeys.indexOf(layoutMap.indicatorDimensionKey); if (-1 === indicatorAtIndex && (indicatorAtIndex = layoutMap.columnHeaderLevelCount - 1), row === indicatorAtIndex) { const dimIndex = col - leftSnCount; cellPathKeys = layoutMap.rowDimensionKeys.slice(0, dimIndex + 1); } else { const dimIndex = row; cellPathKeys = layoutMap.colDimensionKeys.slice(0, dimIndex + 1); } } else { let indicatorAtIndex = layoutMap.rowDimensionKeys.indexOf(layoutMap.indicatorDimensionKey); if (-1 === indicatorAtIndex && (indicatorAtIndex = layoutMap.rowHeaderLevelCount - 1), col - leftSnCount === indicatorAtIndex) { const dimIndex =