@visactor/vtable 1.2.0 → 1.2.1-alpha.0

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.
Files changed (69) hide show
  1. package/cjs/PivotChart.d.ts +1 -5
  2. package/cjs/PivotChart.js +7 -30
  3. package/cjs/PivotChart.js.map +1 -1
  4. package/cjs/PivotTable.d.ts +7 -2
  5. package/cjs/PivotTable.js +85 -17
  6. package/cjs/PivotTable.js.map +1 -1
  7. package/cjs/core/BaseTable.js +5 -5
  8. package/cjs/core/BaseTable.js.map +1 -1
  9. package/cjs/header-helper/header-helper.d.ts +1 -0
  10. package/cjs/header-helper/header-helper.js +12 -2
  11. package/cjs/header-helper/header-helper.js.map +1 -1
  12. package/cjs/index.d.ts +1 -1
  13. package/cjs/index.js +2 -2
  14. package/cjs/index.js.map +1 -1
  15. package/cjs/layout/pivot-header-layout.js +26 -8
  16. package/cjs/layout/pivot-header-layout.js.map +1 -1
  17. package/cjs/layout/tree-helper.js +4 -1
  18. package/cjs/layout/tree-helper.js.map +1 -1
  19. package/cjs/state/state.js +2 -2
  20. package/cjs/state/state.js.map +1 -1
  21. package/cjs/themes/theme.js +1 -1
  22. package/cjs/themes/theme.js.map +1 -1
  23. package/cjs/ts-types/common.d.ts +4 -13
  24. package/cjs/ts-types/common.js.map +1 -1
  25. package/cjs/ts-types/list-table/layout-map/api.d.ts +2 -1
  26. package/cjs/ts-types/list-table/layout-map/api.js.map +1 -1
  27. package/cjs/ts-types/pivot-table/dimension/basic-dimension.d.ts +3 -1
  28. package/cjs/ts-types/pivot-table/dimension/basic-dimension.js.map +1 -1
  29. package/cjs/ts-types/pivot-table/indicator/basic-indicator.d.ts +1 -0
  30. package/cjs/ts-types/pivot-table/indicator/basic-indicator.js.map +1 -1
  31. package/cjs/ts-types/table-engine.d.ts +4 -1
  32. package/cjs/ts-types/table-engine.js.map +1 -1
  33. package/cjs/vrender.js.map +1 -1
  34. package/dist/vtable.js +229 -64
  35. package/dist/vtable.min.js +2 -2
  36. package/es/PivotChart.d.ts +1 -5
  37. package/es/PivotChart.js +6 -31
  38. package/es/PivotChart.js.map +1 -1
  39. package/es/PivotTable.d.ts +7 -2
  40. package/es/PivotTable.js +87 -19
  41. package/es/PivotTable.js.map +1 -1
  42. package/es/core/BaseTable.js +5 -5
  43. package/es/core/BaseTable.js.map +1 -1
  44. package/es/header-helper/header-helper.d.ts +1 -0
  45. package/es/header-helper/header-helper.js +12 -2
  46. package/es/header-helper/header-helper.js.map +1 -1
  47. package/es/index.d.ts +1 -1
  48. package/es/index.js +1 -1
  49. package/es/index.js.map +1 -1
  50. package/es/layout/pivot-header-layout.js +26 -8
  51. package/es/layout/pivot-header-layout.js.map +1 -1
  52. package/es/layout/tree-helper.js +4 -1
  53. package/es/layout/tree-helper.js.map +1 -1
  54. package/es/state/state.js +2 -2
  55. package/es/state/state.js.map +1 -1
  56. package/es/themes/theme.js +1 -1
  57. package/es/themes/theme.js.map +1 -1
  58. package/es/ts-types/common.d.ts +4 -13
  59. package/es/ts-types/common.js.map +1 -1
  60. package/es/ts-types/list-table/layout-map/api.d.ts +2 -1
  61. package/es/ts-types/list-table/layout-map/api.js.map +1 -1
  62. package/es/ts-types/pivot-table/dimension/basic-dimension.d.ts +3 -1
  63. package/es/ts-types/pivot-table/dimension/basic-dimension.js.map +1 -1
  64. package/es/ts-types/pivot-table/indicator/basic-indicator.d.ts +1 -0
  65. package/es/ts-types/pivot-table/indicator/basic-indicator.js.map +1 -1
  66. package/es/ts-types/table-engine.d.ts +4 -1
  67. package/es/ts-types/table-engine.js.map +1 -1
  68. package/es/vrender.js.map +1 -1
  69. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import type { FieldData, FieldDef, PivotTableAPI, SortRules, PivotSortState, CellAddress, ICellHeaderPaths, DropDownMenuEventInfo, FieldKeyDef, PivotTableConstructorOptions, IHeaderTreeDefine, IDimensionInfo, SortOrder, IPagination, CellLocation } from './ts-types';
1
+ import type { FieldData, FieldDef, PivotTableAPI, SortRules, CellAddress, ICellHeaderPaths, DropDownMenuEventInfo, FieldKeyDef, PivotTableConstructorOptions, IHeaderTreeDefine, IDimensionInfo, SortOrder, IPagination, CellLocation } from './ts-types';
2
2
  import { HierarchyState } from './ts-types';
3
3
  import { FlatDataToObjects } from './dataset/flatDataToObject';
4
4
  import { PIVOT_TABLE_EVENT_TYPE } from './ts-types/pivot-table/PIVOT_TABLE_EVENT_TYPE';
@@ -14,7 +14,10 @@ export declare class PivotTable extends BaseTable implements PivotTableAPI {
14
14
  };
15
15
  internalProps: PivotTableProtected;
16
16
  options: PivotTableConstructorOptions;
17
- pivotSortState: PivotSortState[];
17
+ pivotSortState: {
18
+ dimensions: IDimensionInfo[];
19
+ order: SortOrder;
20
+ }[];
18
21
  editorManager: EditManeger;
19
22
  dataset?: Dataset;
20
23
  flatDataToObjects?: FlatDataToObjects;
@@ -46,10 +49,12 @@ export declare class PivotTable extends BaseTable implements PivotTableAPI {
46
49
  getCellOriginRecord(col: number, row: number): any;
47
50
  getCellRawRecord(col: number, row: number): any;
48
51
  updateSortRules(sortRules: SortRules): void;
52
+ _changePivotSortStateBySortRules(): void;
49
53
  updatePivotSortState(pivotSortStateConfig: {
50
54
  dimensions: IDimensionInfo[];
51
55
  order: SortOrder;
52
56
  }[]): void;
57
+ sort(col: number, row: number, order: SortOrder): void;
53
58
  getPivotSortState(col: number, row: number): SortOrder;
54
59
  _moveHeaderPosition(source: CellAddress, target: CellAddress): {
55
60
  sourceIndex: number;
package/cjs/PivotTable.js CHANGED
@@ -33,7 +33,7 @@ const ts_types_1 = require("./ts-types"), pivot_header_layout_1 = require("./lay
33
33
 
34
34
  class PivotTable extends BaseTable_1.BaseTable {
35
35
  constructor(container, options) {
36
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
36
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
37
37
  if ("node" === env_1.Env.mode ? (options = container, container = null) : container instanceof HTMLElement || (options = container,
38
38
  container = container.container ? container.container : null), super(container, options),
39
39
  this.layoutNodeId = {
@@ -74,8 +74,8 @@ class PivotTable extends BaseTable_1.BaseTable {
74
74
  rowDimensionTree = new tree_helper_1.DimensionTree(null !== (_o = this.dataset.rowHeaderTree) && void 0 !== _o ? _o : [], this.layoutNodeId, this.options.rowHierarchyType, "tree" === this.options.rowHierarchyType ? null !== (_p = this.options.rowExpandLevel) && void 0 !== _p ? _p : 1 : void 0)),
75
75
  this.internalProps.layoutMap = new pivot_header_layout_1.PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree);
76
76
  }
77
- this.pivotSortState = [], options.pivotSortState && this.updatePivotSortState(options.pivotSortState),
78
- "node" !== env_1.Env.mode && (this.editorManager = new edit_manager_1.EditManeger(this)),
77
+ this._changePivotSortStateBySortRules(), (null !== (_r = null === (_q = options.pivotSortState) || void 0 === _q ? void 0 : _q.length) && void 0 !== _r ? _r : 0) > 0 && (this.pivotSortState = [],
78
+ this.pivotSortState = options.pivotSortState), "node" !== env_1.Env.mode && (this.editorManager = new edit_manager_1.EditManeger(this)),
79
79
  this.refreshHeader(), this.stateManager.initCheckedState(records), this.scenegraph.createSceneGraph(),
80
80
  options.title && (this.internalProps.title = new title_1.Title(options.title, this),
81
81
  this.scenegraph.resize()), this.options.emptyTip && (this.internalProps.emptyTip || (this.internalProps.emptyTip = new empty_tip_1.EmptyTip(this.options.emptyTip, this)),
@@ -112,7 +112,7 @@ class PivotTable extends BaseTable_1.BaseTable {
112
112
  return ifCan;
113
113
  }
114
114
  updateOption(options) {
115
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
115
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
116
116
  const internalProps = this.internalProps;
117
117
  if (super.updateOption(options), this.layoutNodeId = {
118
118
  seqId: 0
@@ -159,8 +159,8 @@ class PivotTable extends BaseTable_1.BaseTable {
159
159
  rowDimensionTree = new tree_helper_1.DimensionTree(null !== (_q = this.dataset.rowHeaderTree) && void 0 !== _q ? _q : [], this.layoutNodeId, this.options.rowHierarchyType, "tree" === this.options.rowHierarchyType ? null !== (_r = this.options.rowExpandLevel) && void 0 !== _r ? _r : 1 : void 0)),
160
160
  internalProps.layoutMap = new pivot_header_layout_1.PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree);
161
161
  }
162
- return this.pivotSortState = [], options.pivotSortState && this.updatePivotSortState(options.pivotSortState),
163
- this.refreshHeader(), internalProps.releaseList && (internalProps.releaseList.forEach((releaseObj => {
162
+ return this._changePivotSortStateBySortRules(), (null !== (_t = null === (_s = options.pivotSortState) || void 0 === _s ? void 0 : _s.length) && void 0 !== _t ? _t : 0) > 0 && (this.pivotSortState = [],
163
+ this.pivotSortState = options.pivotSortState), this.refreshHeader(), internalProps.releaseList && (internalProps.releaseList.forEach((releaseObj => {
164
164
  var _a;
165
165
  return null === (_a = null == releaseObj ? void 0 : releaseObj.release) || void 0 === _a ? void 0 : _a.call(releaseObj);
166
166
  })), internalProps.releaseList = null), this.scenegraph.clearCells(), this.scenegraph.createSceneGraph(),
@@ -463,26 +463,94 @@ class PivotTable extends BaseTable_1.BaseTable {
463
463
  }
464
464
  }
465
465
  updateSortRules(sortRules) {
466
- this.internalProps.dataConfig.sortRules = sortRules, this.dataset.updateSortRules(sortRules),
466
+ this.internalProps.dataConfig ? this.internalProps.dataConfig.sortRules = sortRules : this.internalProps.dataConfig = {
467
+ sortRules: sortRules
468
+ }, this.dataset.updateSortRules(sortRules), this._changePivotSortStateBySortRules(),
467
469
  this.internalProps.layoutMap.resetHeaderTree(), this.scenegraph.clearCells(), this.refreshHeader(),
468
470
  this.scenegraph.createSceneGraph(), this.render();
469
471
  }
472
+ _changePivotSortStateBySortRules() {
473
+ var _a, _b, _c, _d;
474
+ this.pivotSortState = [];
475
+ const sortRules = null !== (_b = null === (_a = this.internalProps.dataConfig) || void 0 === _a ? void 0 : _a.sortRules) && void 0 !== _b ? _b : [];
476
+ for (let i = 0; i < sortRules.length; i++) {
477
+ const sortRule = sortRules[i];
478
+ if (sortRule.sortType) {
479
+ const dimensions = [];
480
+ if (sortRule.sortByIndicator) {
481
+ if (sortRule.sortField === (this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1])) {
482
+ for (let j = 0; j < sortRule.query.length; j++) dimensions.push({
483
+ dimensionKey: this.dataset.indicatorsAsCol ? this.dataset.columns[j] : this.dataset.rows[j],
484
+ value: sortRule.query[j]
485
+ });
486
+ dimensions.push({
487
+ indicatorKey: sortRule.sortByIndicator,
488
+ value: null !== (_d = null === (_c = this.internalProps.layoutMap.getIndicatorInfo(sortRule.sortByIndicator)) || void 0 === _c ? void 0 : _c.title) && void 0 !== _d ? _d : sortRule.sortByIndicator
489
+ });
490
+ }
491
+ } else dimensions.push({
492
+ dimensionKey: sortRule.sortField,
493
+ isPivotCorner: !0,
494
+ value: sortRule.sortField
495
+ });
496
+ this.pivotSortState.push({
497
+ dimensions: dimensions,
498
+ order: sortRule.sortType
499
+ });
500
+ }
501
+ }
502
+ }
470
503
  updatePivotSortState(pivotSortStateConfig) {
471
- for (let i = 0; i < pivotSortStateConfig.length; i++) {
472
- const {dimensions: dimensions, order: order} = pivotSortStateConfig[i], cellAddress = this.internalProps.layoutMap.getPivotCellAdress(dimensions);
473
- cellAddress && this.pivotSortState.push({
474
- col: cellAddress.col,
475
- row: cellAddress.row,
476
- order: order
477
- });
504
+ this.pivotSortState = pivotSortStateConfig;
505
+ }
506
+ sort(col, row, order) {
507
+ let dimensions;
508
+ if (this.isCornerHeader(col, row)) {
509
+ const dimensionInfo = this.getHeaderDefine(col, row);
510
+ dimensions = [];
511
+ const dimension = {
512
+ isPivotCorner: !0,
513
+ dimensionKey: dimensionInfo.value,
514
+ value: dimensionInfo.value
515
+ };
516
+ dimensions.push(dimension);
517
+ } else dimensions = this.isColumnHeader(col, row) ? this.getCellHeaderPaths(col, row).colHeaderPaths : this.getCellHeaderPaths(col, row).rowHeaderPaths;
518
+ const sortIndicator = dimensions[dimensions.length - 1].indicatorKey, headerDefine = this.getHeaderDefine(col, row);
519
+ if (headerDefine.sort) {
520
+ if (this.dataset.sortRules) {
521
+ for (let i = this.dataset.sortRules.length - 1; i >= 0; i--) {
522
+ const sortRule = this.dataset.sortRules[i];
523
+ (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])) && this.dataset.sortRules.splice(i, 1);
524
+ }
525
+ sortIndicator ? this.dataset.sortRules.push({
526
+ sortField: this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1],
527
+ sortType: ts_types_1.SortType[order],
528
+ sortByIndicator: sortIndicator,
529
+ query: dimensions.reduce(((arr, dimension) => (dimension.dimensionKey && arr.push(dimension.value),
530
+ arr)), [])
531
+ }) : this.dataset.sortRules.push({
532
+ sortField: headerDefine.dimensionKey,
533
+ sortType: ts_types_1.SortType[order]
534
+ });
535
+ } else this.dataset.sortRules = sortIndicator ? [ {
536
+ sortField: this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1],
537
+ sortType: ts_types_1.SortType[order],
538
+ sortByIndicator: sortIndicator,
539
+ query: dimensions.reduce(((arr, dimension) => (dimension.dimensionKey && arr.push(dimension.value),
540
+ arr)), [])
541
+ } ] : [ {
542
+ sortField: headerDefine.dimensionKey,
543
+ sortType: ts_types_1.SortType[order]
544
+ } ];
545
+ this.updateSortRules(this.dataset.sortRules);
478
546
  }
479
547
  }
480
548
  getPivotSortState(col, row) {
481
549
  if (!this.pivotSortState) return;
482
550
  const cellRange = this.getCellRange(col, row);
483
551
  for (let i = 0; i < this.pivotSortState.length; i++) {
484
- const {col: sortCol, row: sortRow, order: order} = this.pivotSortState[i];
485
- if ((0, helper_1.cellInRange)(cellRange, sortCol, sortRow)) return order;
552
+ const pivotState = this.pivotSortState[i], dimensions = pivotState.dimensions, cell = this.getCellAddressByHeaderPaths(dimensions), order = pivotState.order;
553
+ if (cell && (0, helper_1.cellInRange)(cellRange, cell.col, cell.row)) return order;
486
554
  }
487
555
  }
488
556
  _moveHeaderPosition(source, target) {
@@ -600,7 +668,7 @@ class PivotTable extends BaseTable_1.BaseTable {
600
668
  this.dataset.setRecords(records), columnDimensionTree = options.columnTree ? internalProps.layoutMap.columnDimensionTree : new tree_helper_1.DimensionTree(null !== (_c = this.dataset.colHeaderTree) && void 0 !== _c ? _c : [], this.layoutNodeId),
601
669
  rowDimensionTree = options.rowTree ? internalProps.layoutMap.rowDimensionTree : new tree_helper_1.DimensionTree(null !== (_d = this.dataset.rowHeaderTree) && void 0 !== _d ? _d : [], this.layoutNodeId, this.options.rowHierarchyType, "tree" === this.options.rowHierarchyType ? null !== (_e = this.options.rowExpandLevel) && void 0 !== _e ? _e : 1 : void 0),
602
670
  internalProps.layoutMap = new pivot_header_layout_1.PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree),
603
- this.pivotSortState = [], options.pivotSortState && this.updatePivotSortState(options.pivotSortState);
671
+ this.pivotSortState = [], options.pivotSortState && (this.pivotSortState = options.pivotSortState);
604
672
  }
605
673
  this.refreshHeader(), this.scenegraph.clearCells(), this.clearCellStyleCache(),
606
674
  this.scenegraph.createSceneGraph(), this.stateManager.updateHoverPos(oldHoverState.col, oldHoverState.row),