@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/es/PivotTable.js CHANGED
@@ -1,4 +1,4 @@
1
- import { HierarchyState } from "./ts-types";
1
+ import { HierarchyState, SortType } from "./ts-types";
2
2
 
3
3
  import { PivotHeaderLayoutMap } from "./layout/pivot-header-layout";
4
4
 
@@ -40,7 +40,7 @@ import { EmptyTip } from "./components/empty-tip/empty-tip";
40
40
 
41
41
  export class PivotTable extends BaseTable {
42
42
  constructor(container, options) {
43
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
43
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
44
44
  if ("node" === Env.mode ? (options = container, container = null) : container instanceof HTMLElement || (options = container,
45
45
  container = container.container ? container.container : null), super(container, options),
46
46
  this.layoutNodeId = {
@@ -78,9 +78,9 @@ export class PivotTable extends BaseTable {
78
78
  rowDimensionTree = new 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)),
79
79
  this.internalProps.layoutMap = new PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree);
80
80
  }
81
- this.pivotSortState = [], options.pivotSortState && this.updatePivotSortState(options.pivotSortState),
82
- "node" !== Env.mode && (this.editorManager = new EditManeger(this)), this.refreshHeader(),
83
- this.stateManager.initCheckedState(records), this.scenegraph.createSceneGraph(),
81
+ this._changePivotSortStateBySortRules(), (null !== (_r = null === (_q = options.pivotSortState) || void 0 === _q ? void 0 : _q.length) && void 0 !== _r ? _r : 0) > 0 && (this.pivotSortState = [],
82
+ this.pivotSortState = options.pivotSortState), "node" !== Env.mode && (this.editorManager = new EditManeger(this)),
83
+ this.refreshHeader(), this.stateManager.initCheckedState(records), this.scenegraph.createSceneGraph(),
84
84
  options.title && (this.internalProps.title = new Title(options.title, this), this.scenegraph.resize()),
85
85
  this.options.emptyTip && (this.internalProps.emptyTip || (this.internalProps.emptyTip = new EmptyTip(this.options.emptyTip, this)),
86
86
  this.internalProps.emptyTip.resetVisible()), setTimeout((() => {
@@ -116,7 +116,7 @@ export class PivotTable extends BaseTable {
116
116
  return ifCan;
117
117
  }
118
118
  updateOption(options) {
119
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
119
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
120
120
  const internalProps = this.internalProps;
121
121
  if (super.updateOption(options), this.layoutNodeId = {
122
122
  seqId: 0
@@ -161,8 +161,8 @@ export class PivotTable extends BaseTable {
161
161
  rowDimensionTree = new 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)),
162
162
  internalProps.layoutMap = new PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree);
163
163
  }
164
- return this.pivotSortState = [], options.pivotSortState && this.updatePivotSortState(options.pivotSortState),
165
- this.refreshHeader(), internalProps.releaseList && (internalProps.releaseList.forEach((releaseObj => {
164
+ return this._changePivotSortStateBySortRules(), (null !== (_t = null === (_s = options.pivotSortState) || void 0 === _s ? void 0 : _s.length) && void 0 !== _t ? _t : 0) > 0 && (this.pivotSortState = [],
165
+ this.pivotSortState = options.pivotSortState), this.refreshHeader(), internalProps.releaseList && (internalProps.releaseList.forEach((releaseObj => {
166
166
  var _a;
167
167
  return null === (_a = null == releaseObj ? void 0 : releaseObj.release) || void 0 === _a ? void 0 : _a.call(releaseObj);
168
168
  })), internalProps.releaseList = null), this.scenegraph.clearCells(), this.scenegraph.createSceneGraph(),
@@ -465,26 +465,94 @@ export class PivotTable extends BaseTable {
465
465
  }
466
466
  }
467
467
  updateSortRules(sortRules) {
468
- this.internalProps.dataConfig.sortRules = sortRules, this.dataset.updateSortRules(sortRules),
468
+ this.internalProps.dataConfig ? this.internalProps.dataConfig.sortRules = sortRules : this.internalProps.dataConfig = {
469
+ sortRules: sortRules
470
+ }, this.dataset.updateSortRules(sortRules), this._changePivotSortStateBySortRules(),
469
471
  this.internalProps.layoutMap.resetHeaderTree(), this.scenegraph.clearCells(), this.refreshHeader(),
470
472
  this.scenegraph.createSceneGraph(), this.render();
471
473
  }
474
+ _changePivotSortStateBySortRules() {
475
+ var _a, _b, _c, _d;
476
+ this.pivotSortState = [];
477
+ const sortRules = null !== (_b = null === (_a = this.internalProps.dataConfig) || void 0 === _a ? void 0 : _a.sortRules) && void 0 !== _b ? _b : [];
478
+ for (let i = 0; i < sortRules.length; i++) {
479
+ const sortRule = sortRules[i];
480
+ if (sortRule.sortType) {
481
+ const dimensions = [];
482
+ if (sortRule.sortByIndicator) {
483
+ if (sortRule.sortField === (this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1])) {
484
+ for (let j = 0; j < sortRule.query.length; j++) dimensions.push({
485
+ dimensionKey: this.dataset.indicatorsAsCol ? this.dataset.columns[j] : this.dataset.rows[j],
486
+ value: sortRule.query[j]
487
+ });
488
+ dimensions.push({
489
+ indicatorKey: sortRule.sortByIndicator,
490
+ value: null !== (_d = null === (_c = this.internalProps.layoutMap.getIndicatorInfo(sortRule.sortByIndicator)) || void 0 === _c ? void 0 : _c.title) && void 0 !== _d ? _d : sortRule.sortByIndicator
491
+ });
492
+ }
493
+ } else dimensions.push({
494
+ dimensionKey: sortRule.sortField,
495
+ isPivotCorner: !0,
496
+ value: sortRule.sortField
497
+ });
498
+ this.pivotSortState.push({
499
+ dimensions: dimensions,
500
+ order: sortRule.sortType
501
+ });
502
+ }
503
+ }
504
+ }
472
505
  updatePivotSortState(pivotSortStateConfig) {
473
- for (let i = 0; i < pivotSortStateConfig.length; i++) {
474
- const {dimensions: dimensions, order: order} = pivotSortStateConfig[i], cellAddress = this.internalProps.layoutMap.getPivotCellAdress(dimensions);
475
- cellAddress && this.pivotSortState.push({
476
- col: cellAddress.col,
477
- row: cellAddress.row,
478
- order: order
479
- });
506
+ this.pivotSortState = pivotSortStateConfig;
507
+ }
508
+ sort(col, row, order) {
509
+ let dimensions;
510
+ if (this.isCornerHeader(col, row)) {
511
+ const dimensionInfo = this.getHeaderDefine(col, row);
512
+ dimensions = [];
513
+ const dimension = {
514
+ isPivotCorner: !0,
515
+ dimensionKey: dimensionInfo.value,
516
+ value: dimensionInfo.value
517
+ };
518
+ dimensions.push(dimension);
519
+ } else dimensions = this.isColumnHeader(col, row) ? this.getCellHeaderPaths(col, row).colHeaderPaths : this.getCellHeaderPaths(col, row).rowHeaderPaths;
520
+ const sortIndicator = dimensions[dimensions.length - 1].indicatorKey, headerDefine = this.getHeaderDefine(col, row);
521
+ if (headerDefine.sort) {
522
+ if (this.dataset.sortRules) {
523
+ for (let i = this.dataset.sortRules.length - 1; i >= 0; i--) {
524
+ const sortRule = this.dataset.sortRules[i];
525
+ (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);
526
+ }
527
+ sortIndicator ? this.dataset.sortRules.push({
528
+ sortField: this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1],
529
+ sortType: SortType[order],
530
+ sortByIndicator: sortIndicator,
531
+ query: dimensions.reduce(((arr, dimension) => (dimension.dimensionKey && arr.push(dimension.value),
532
+ arr)), [])
533
+ }) : this.dataset.sortRules.push({
534
+ sortField: headerDefine.dimensionKey,
535
+ sortType: SortType[order]
536
+ });
537
+ } else this.dataset.sortRules = sortIndicator ? [ {
538
+ sortField: this.dataset.indicatorsAsCol ? this.dataset.rows[this.dataset.rows.length - 1] : this.dataset.columns[this.dataset.columns.length - 1],
539
+ sortType: SortType[order],
540
+ sortByIndicator: sortIndicator,
541
+ query: dimensions.reduce(((arr, dimension) => (dimension.dimensionKey && arr.push(dimension.value),
542
+ arr)), [])
543
+ } ] : [ {
544
+ sortField: headerDefine.dimensionKey,
545
+ sortType: SortType[order]
546
+ } ];
547
+ this.updateSortRules(this.dataset.sortRules);
480
548
  }
481
549
  }
482
550
  getPivotSortState(col, row) {
483
551
  if (!this.pivotSortState) return;
484
552
  const cellRange = this.getCellRange(col, row);
485
553
  for (let i = 0; i < this.pivotSortState.length; i++) {
486
- const {col: sortCol, row: sortRow, order: order} = this.pivotSortState[i];
487
- if (cellInRange(cellRange, sortCol, sortRow)) return order;
554
+ const pivotState = this.pivotSortState[i], dimensions = pivotState.dimensions, cell = this.getCellAddressByHeaderPaths(dimensions), order = pivotState.order;
555
+ if (cell && cellInRange(cellRange, cell.col, cell.row)) return order;
488
556
  }
489
557
  }
490
558
  _moveHeaderPosition(source, target) {
@@ -602,7 +670,7 @@ export class PivotTable extends BaseTable {
602
670
  this.dataset.setRecords(records), columnDimensionTree = options.columnTree ? internalProps.layoutMap.columnDimensionTree : new DimensionTree(null !== (_c = this.dataset.colHeaderTree) && void 0 !== _c ? _c : [], this.layoutNodeId),
603
671
  rowDimensionTree = options.rowTree ? internalProps.layoutMap.rowDimensionTree : new 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),
604
672
  internalProps.layoutMap = new PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree),
605
- this.pivotSortState = [], options.pivotSortState && this.updatePivotSortState(options.pivotSortState);
673
+ this.pivotSortState = [], options.pivotSortState && (this.pivotSortState = options.pivotSortState);
606
674
  }
607
675
  this.refreshHeader(), this.scenegraph.clearCells(), this.clearCellStyleCache(),
608
676
  this.scenegraph.createSceneGraph(), this.stateManager.updateHoverPos(oldHoverState.col, oldHoverState.row),