@visactor/vtable-sheet 1.26.0 → 1.26.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.
@@ -444,4 +444,5 @@ class WorkSheet {
444
444
  }
445
445
  }
446
446
 
447
- exports.WorkSheet = WorkSheet;
447
+ exports.WorkSheet = WorkSheet;
448
+ //# sourceMappingURL=WorkSheet.js.map
@@ -72,5 +72,4 @@ class VTableSheetEventBus {
72
72
  }
73
73
  }
74
74
 
75
- exports.VTableSheetEventBus = VTableSheetEventBus;
76
- //# sourceMappingURL=vtable-sheet-event-bus.js.map
75
+ exports.VTableSheetEventBus = VTableSheetEventBus;
package/cjs/index.d.ts CHANGED
@@ -2,5 +2,5 @@ import VTableSheet from './components/vtable-sheet';
2
2
  import type { ISheetDefine, IVTableSheetOptions, IVTableSheetUpdateOptions } from './ts-types';
3
3
  import * as TYPES from './ts-types';
4
4
  import * as VTable from './vtable';
5
- export declare const version = "1.26.0";
5
+ export declare const version = "1.26.1-alpha.0";
6
6
  export { VTableSheet, TYPES, VTable, ISheetDefine, IVTableSheetOptions, IVTableSheetUpdateOptions };
package/cjs/index.js CHANGED
@@ -47,4 +47,4 @@ exports.VTable = VTable;
47
47
 
48
48
  const style_manager_1 = require("./styles/style-manager");
49
49
 
50
- exports.version = "1.26.0", (0, style_manager_1.importStyles)();
50
+ exports.version = "1.26.1-alpha.0", (0, style_manager_1.importStyles)();
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6EAAoD;AAW3C,sBAXF,sBAAW,CAWE;AATpB,kDAAoC;AASd,sBAAK;AAR3B,iDAAmC;AAQN,wBAAM;AAPnC,0DAAsD;AACzC,QAAA,OAAO,GAAG,QAAQ,CAAC;AAEhC,IAAA,4BAAY,GAAE,CAAC","file":"index.js","sourcesContent":["import VTableSheet from './components/vtable-sheet';\nimport type { ISheetDefine, IVTableSheetOptions, IVTableSheetUpdateOptions } from './ts-types';\nimport * as TYPES from './ts-types';\nimport * as VTable from './vtable';\nimport { importStyles } from './styles/style-manager';\nexport const version = \"1.26.0\";\n// 导入样式\nimportStyles();\n/**\n * @namespace VTableSheet\n */\nexport { VTableSheet, TYPES, VTable, ISheetDefine, IVTableSheetOptions, IVTableSheetUpdateOptions };\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6EAAoD;AAW3C,sBAXF,sBAAW,CAWE;AATpB,kDAAoC;AASd,sBAAK;AAR3B,iDAAmC;AAQN,wBAAM;AAPnC,0DAAsD;AACzC,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAExC,IAAA,4BAAY,GAAE,CAAC","file":"index.js","sourcesContent":["import VTableSheet from './components/vtable-sheet';\nimport type { ISheetDefine, IVTableSheetOptions, IVTableSheetUpdateOptions } from './ts-types';\nimport * as TYPES from './ts-types';\nimport * as VTable from './vtable';\nimport { importStyles } from './styles/style-manager';\nexport const version = \"1.26.1-alpha.0\";\n// 导入样式\nimportStyles();\n/**\n * @namespace VTableSheet\n */\nexport { VTableSheet, TYPES, VTable, ISheetDefine, IVTableSheetOptions, IVTableSheetUpdateOptions };\n"]}
@@ -4940,6 +4940,20 @@
4940
4940
  function crossProduct(dir1, dir2) {
4941
4941
  return dir1[0] * dir2[1] - dir1[1] * dir2[0];
4942
4942
  }
4943
+ function fixPrecision$1(num, precision = 10) {
4944
+ return Math.round(num * precision) / precision;
4945
+ }
4946
+ function getDecimalPlaces(n) {
4947
+ const dStr = n.toString().split(/[eE]/),
4948
+ s = (dStr[0].split(".")[1] || "").length - (+dStr[1] || 0);
4949
+ return s > 0 ? s : 0;
4950
+ }
4951
+ function precisionAdd(a, b) {
4952
+ return fixPrecision$1(a + b, 10 ** Math.max(getDecimalPlaces(a), getDecimalPlaces(b)));
4953
+ }
4954
+ function precisionSub(a, b) {
4955
+ return fixPrecision$1(a - b, 10 ** Math.max(getDecimalPlaces(a), getDecimalPlaces(b)));
4956
+ }
4943
4957
 
4944
4958
  class Point {
4945
4959
  constructor(x = 0, y = 0, x1, y1) {
@@ -37697,42 +37711,54 @@
37697
37711
  if (record) if (this.isRecord && this.records && (record.isAggregator ? this.records.push(...record.records) : this.records.push(record)), record.isAggregator && this.children) {
37698
37712
  this.children.push(record);
37699
37713
  const value = record.value();
37700
- this.sum += null != value ? value : 0, this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum += value : value < 0 && (this.nagetiveSum += value));
37714
+ this.sum = precisionAdd(this.sum, null != value ? value : 0), this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum = precisionAdd(this.positiveSum, value) : value < 0 && (this.nagetiveSum = precisionAdd(this.nagetiveSum, value)));
37701
37715
  } else if (this.field && !isNaN(parseFloat(record[this.field]))) {
37702
37716
  const value = parseFloat(record[this.field]);
37703
- this.sum += value, this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum += value : value < 0 && (this.nagetiveSum += value));
37717
+ this.sum = precisionAdd(this.sum, value), this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum = precisionAdd(this.positiveSum, value) : value < 0 && (this.nagetiveSum = precisionAdd(this.nagetiveSum, value)));
37704
37718
  }
37705
37719
  this.clearCacheValue();
37706
37720
  }
37707
37721
  deleteRecord(record) {
37708
- if (record) if (this.isRecord && this.records && (this.records = this.records.filter(item => item !== record)), record.isAggregator && this.children) {
37709
- this.children = this.children.filter(item => item !== record);
37710
- const value = record.value();
37711
- this.sum -= null != value ? value : 0, this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum -= value : value < 0 && (this.nagetiveSum -= value));
37712
- } else if (this.field && !isNaN(parseFloat(record[this.field]))) {
37713
- const value = parseFloat(record[this.field]);
37714
- this.sum -= value, this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum -= value : value < 0 && (this.nagetiveSum -= value));
37722
+ if (record) {
37723
+ if (this.isRecord && this.records) {
37724
+ const index = this.records.indexOf(record);
37725
+ -1 !== index && this.records.splice(index, 1);
37726
+ }
37727
+ if (record.isAggregator && this.children) {
37728
+ const index = this.children.indexOf(record);
37729
+ -1 !== index && this.children.splice(index, 1);
37730
+ const value = record.value();
37731
+ this.sum = precisionSub(this.sum, null != value ? value : 0), this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum = precisionSub(this.positiveSum, value) : value < 0 && (this.nagetiveSum = precisionSub(this.nagetiveSum, value)));
37732
+ } else if (this.field && !isNaN(parseFloat(record[this.field]))) {
37733
+ const value = parseFloat(record[this.field]);
37734
+ this.sum = precisionSub(this.sum, value), this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum = precisionSub(this.positiveSum, value) : value < 0 && (this.nagetiveSum = precisionSub(this.nagetiveSum, value)));
37735
+ }
37715
37736
  }
37716
37737
  this.clearCacheValue();
37717
37738
  }
37718
37739
  updateRecord(oldRecord, newRecord) {
37719
37740
  if (oldRecord && newRecord) {
37720
- if (this.isRecord && this.records && (this.records = this.records.map(item => item === oldRecord ? newRecord : item)), oldRecord.isAggregator && this.children) {
37721
- const oldValue = oldRecord.value();
37722
- this.children = this.children.filter(item => item !== oldRecord);
37741
+ if (this.isRecord && this.records) {
37742
+ const index = this.records.indexOf(oldRecord);
37743
+ -1 !== index && (this.records[index] = newRecord);
37744
+ }
37745
+ if (oldRecord.isAggregator && this.children) {
37746
+ const oldValue = oldRecord.value(),
37747
+ index = this.children.indexOf(oldRecord);
37748
+ -1 !== index && (this.children[index] = newRecord);
37723
37749
  const newValue = newRecord.value();
37724
- this.children.push(newRecord), this.sum += newValue - oldValue, this.needSplitPositiveAndNegativeForSum && (oldValue > 0 ? this.positiveSum -= oldValue : oldValue < 0 && (this.nagetiveSum -= oldValue), newValue > 0 ? this.positiveSum += newValue : newValue < 0 && (this.nagetiveSum += newValue));
37750
+ this.sum = precisionAdd(this.sum, precisionSub(newValue, oldValue)), this.needSplitPositiveAndNegativeForSum && (oldValue > 0 ? this.positiveSum = precisionSub(this.positiveSum, oldValue) : oldValue < 0 && (this.nagetiveSum = precisionSub(this.nagetiveSum, oldValue)), newValue > 0 ? this.positiveSum = precisionAdd(this.positiveSum, newValue) : newValue < 0 && (this.nagetiveSum = precisionAdd(this.nagetiveSum, newValue)));
37725
37751
  } else if (this.field && !isNaN(parseFloat(oldRecord[this.field]))) {
37726
37752
  const oldValue = parseFloat(oldRecord[this.field]),
37727
37753
  newValue = parseFloat(newRecord[this.field]);
37728
- this.sum += newValue - oldValue, this.needSplitPositiveAndNegativeForSum && (oldValue > 0 ? this.positiveSum -= oldValue : oldValue < 0 && (this.nagetiveSum -= oldValue), newValue > 0 ? this.positiveSum += newValue : newValue < 0 && (this.nagetiveSum += newValue));
37754
+ this.sum = precisionAdd(this.sum, precisionSub(newValue, oldValue)), this.needSplitPositiveAndNegativeForSum && (oldValue > 0 ? this.positiveSum = precisionSub(this.positiveSum, oldValue) : oldValue < 0 && (this.nagetiveSum = precisionSub(this.nagetiveSum, oldValue)), newValue > 0 ? this.positiveSum = precisionAdd(this.positiveSum, newValue) : newValue < 0 && (this.nagetiveSum = precisionAdd(this.nagetiveSum, newValue)));
37729
37755
  }
37730
37756
  this.clearCacheValue();
37731
37757
  }
37732
37758
  }
37733
37759
  value() {
37734
- var _a, _b;
37735
- return null !== (_a = this.changedValue) && void 0 !== _a ? _a : (null === (_b = this.records) || void 0 === _b ? void 0 : _b.length) >= 1 ? this.sum : void 0;
37760
+ var _a;
37761
+ return null !== (_a = this.changedValue) && void 0 !== _a ? _a : this.records && this.records.length >= 1 || !1 === this.isRecord ? this.sum : void 0;
37736
37762
  }
37737
37763
  positiveValue() {
37738
37764
  return this.positiveSum;
@@ -37748,16 +37774,16 @@
37748
37774
  const child = this.children[i];
37749
37775
  if (child.isAggregator) {
37750
37776
  const value = child.value();
37751
- this.sum += null != value ? value : 0, this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum += value : value < 0 && (this.nagetiveSum += value));
37777
+ this.sum = precisionAdd(this.sum, null != value ? value : 0), this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum = precisionAdd(this.positiveSum, value) : value < 0 && (this.nagetiveSum = precisionAdd(this.nagetiveSum, value)));
37752
37778
  }
37753
37779
  } else if (this.records) for (let i = 0; i < this.records.length; i++) {
37754
37780
  const record = this.records[i];
37755
37781
  if (record.isAggregator) {
37756
37782
  const value = record.value();
37757
- this.sum += null != value ? value : 0, this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum += value : value < 0 && (this.nagetiveSum += value));
37783
+ this.sum = precisionAdd(this.sum, null != value ? value : 0), this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum = precisionAdd(this.positiveSum, value) : value < 0 && (this.nagetiveSum = precisionAdd(this.nagetiveSum, value)));
37758
37784
  } else if (this.field && !isNaN(parseFloat(record[this.field]))) {
37759
37785
  const value = parseFloat(record[this.field]);
37760
- this.sum += value, this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum += value : value < 0 && (this.nagetiveSum += value));
37786
+ this.sum = precisionAdd(this.sum, value), this.needSplitPositiveAndNegativeForSum && (value > 0 ? this.positiveSum = precisionAdd(this.positiveSum, value) : value < 0 && (this.nagetiveSum = precisionAdd(this.nagetiveSum, value)));
37761
37787
  }
37762
37788
  }
37763
37789
  }
@@ -37800,17 +37826,43 @@
37800
37826
  super(...arguments), this.type = AggregationType.AVG, this.sum = 0, this.count = 0;
37801
37827
  }
37802
37828
  push(record) {
37803
- record && (this.isRecord && this.records && (record.isAggregator ? this.records.push(...record.records) : this.records.push(record)), record.isAggregator && record.type === AggregationType.AVG ? (this.children && this.children.push(record), this.sum += record.sum, this.count += record.count) : this.field && !isNaN(parseFloat(record[this.field])) && (this.sum += parseFloat(record[this.field]), this.count++)), this.clearCacheValue();
37829
+ record && (this.isRecord && this.records && (record.isAggregator ? this.records.push(...record.records) : this.records.push(record)), record.isAggregator && record.type === AggregationType.AVG ? (this.children && this.children.push(record), this.sum = precisionAdd(this.sum, record.sum), this.count += record.count) : this.field && !isNaN(parseFloat(record[this.field])) && (this.sum = precisionAdd(this.sum, parseFloat(record[this.field])), this.count++)), this.clearCacheValue();
37804
37830
  }
37805
37831
  deleteRecord(record) {
37806
- record && (this.isRecord && this.records && (this.records = this.records.filter(item => item !== record)), record.isAggregator && record.type === AggregationType.AVG ? (this.children && (this.children = this.children.filter(item => item !== record)), this.sum -= record.sum, this.count -= record.count) : this.field && !isNaN(parseFloat(record[this.field])) && (this.sum -= parseFloat(record[this.field]), this.count--)), this.clearCacheValue();
37832
+ if (record) {
37833
+ if (this.isRecord && this.records) {
37834
+ const index = this.records.indexOf(record);
37835
+ -1 !== index && this.records.splice(index, 1);
37836
+ }
37837
+ if (record.isAggregator && record.type === AggregationType.AVG) {
37838
+ if (this.children) {
37839
+ const index = this.children.indexOf(record);
37840
+ -1 !== index && this.children.splice(index, 1);
37841
+ }
37842
+ this.sum = precisionSub(this.sum, record.sum), this.count -= record.count;
37843
+ } else this.field && !isNaN(parseFloat(record[this.field])) && (this.sum = precisionSub(this.sum, parseFloat(record[this.field])), this.count--);
37844
+ }
37845
+ this.clearCacheValue();
37807
37846
  }
37808
37847
  updateRecord(oldRecord, newRecord) {
37809
- oldRecord && newRecord && (this.isRecord && this.records && (this.records = this.records.map(item => item === oldRecord ? newRecord : item)), oldRecord.isAggregator && oldRecord.type === AggregationType.AVG ? (this.children && newRecord.isAggregator && (this.children = this.children.map(item => item === oldRecord ? newRecord : item)), this.sum += newRecord.sum - oldRecord.sum, this.count += newRecord.count - oldRecord.count) : this.field && !isNaN(parseFloat(oldRecord[this.field])) && (this.sum += parseFloat(newRecord[this.field]) - parseFloat(oldRecord[this.field])), this.clearCacheValue());
37848
+ if (oldRecord && newRecord) {
37849
+ if (this.isRecord && this.records) {
37850
+ const index = this.records.indexOf(oldRecord);
37851
+ -1 !== index && (this.records[index] = newRecord);
37852
+ }
37853
+ if (oldRecord.isAggregator && oldRecord.type === AggregationType.AVG) {
37854
+ if (this.children && newRecord.isAggregator) {
37855
+ const index = this.children.indexOf(oldRecord);
37856
+ -1 !== index && (this.children[index] = newRecord);
37857
+ }
37858
+ this.sum = precisionAdd(this.sum, precisionSub(newRecord.sum, oldRecord.sum)), this.count += newRecord.count - oldRecord.count;
37859
+ } else this.field && !isNaN(parseFloat(oldRecord[this.field])) && (this.sum = precisionAdd(this.sum, precisionSub(parseFloat(newRecord[this.field]), parseFloat(oldRecord[this.field]))));
37860
+ this.clearCacheValue();
37861
+ }
37810
37862
  }
37811
37863
  value() {
37812
- var _a, _b;
37813
- return null !== (_a = this.changedValue) && void 0 !== _a ? _a : (null === (_b = this.records) || void 0 === _b ? void 0 : _b.length) >= 1 ? this.sum / this.count : void 0;
37864
+ var _a;
37865
+ return null !== (_a = this.changedValue) && void 0 !== _a ? _a : this.records && this.records.length >= 1 || !1 === this.isRecord && this.count > 0 ? this.sum / this.count : void 0;
37814
37866
  }
37815
37867
  reset() {
37816
37868
  this.changedValue = void 0, this.children = [], this.records = [], this.sum = 0, this.count = 0;
@@ -37820,11 +37872,11 @@
37820
37872
  const child = this.children[i];
37821
37873
  if (child.isAggregator && child.type === AggregationType.AVG) {
37822
37874
  const childValue = child.value();
37823
- this.sum += childValue * child.count, this.count += child.count;
37875
+ this.sum = precisionAdd(this.sum, childValue * child.count), this.count += child.count;
37824
37876
  }
37825
37877
  } else if (this.records) for (let i = 0; i < this.records.length; i++) {
37826
37878
  const record = this.records[i];
37827
- record.isAggregator && record.type === AggregationType.AVG ? (this.sum += record.sum, this.count += record.count) : this.field && !isNaN(parseFloat(record[this.field])) && (this.sum += parseFloat(record[this.field]), this.count++);
37879
+ record.isAggregator && record.type === AggregationType.AVG ? (this.sum = precisionAdd(this.sum, record.sum), this.count += record.count) : this.field && !isNaN(parseFloat(record[this.field])) && (this.sum = precisionAdd(this.sum, parseFloat(record[this.field])), this.count++);
37828
37880
  }
37829
37881
  }
37830
37882
  }
@@ -61178,7 +61230,7 @@
61178
61230
  }
61179
61231
  constructor(container, options = {}) {
61180
61232
  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;
61181
- if (super(), this.showFrozenIcon = !0, this._scrollToRowCorrectTimer = null, this._tableBorderWidth_left = 0, this._tableBorderWidth_right = 0, this._tableBorderWidth_top = 0, this._tableBorderWidth_bottom = 0, this.version = "1.26.0", this.id = `VTable${Date.now()}`, this.isReleased = !1, this._chartEventMap = {}, this.throttleInvalidate = throttle2(this.render.bind(this), 200), "undefined" != typeof window) {
61233
+ if (super(), this.showFrozenIcon = !0, this._scrollToRowCorrectTimer = null, this._tableBorderWidth_left = 0, this._tableBorderWidth_right = 0, this._tableBorderWidth_top = 0, this._tableBorderWidth_bottom = 0, this.version = "1.26.1-alpha.0", this.id = `VTable${Date.now()}`, this.isReleased = !1, this._chartEventMap = {}, this.throttleInvalidate = throttle2(this.render.bind(this), 200), "undefined" != typeof window) {
61182
61234
  const g = window;
61183
61235
  g[this.id] = this;
61184
61236
  const registry = g.__vtable__ || (g.__vtable__ = {
@@ -83720,7 +83772,7 @@
83720
83772
  function getCellMatrix(table) {
83721
83773
  return {
83722
83774
  getValue: (row, col) => {
83723
- const value = table.getCellValue(col, row);
83775
+ const value = table.getCellOriginValue(col, row);
83724
83776
  return "number" != typeof value && isNaN(Number(value)) ? {
83725
83777
  v: value || "",
83726
83778
  t: CellValueType.STRING
@@ -95772,7 +95824,7 @@
95772
95824
  importStyle();
95773
95825
  }
95774
95826
 
95775
- const version = "1.26.0";
95827
+ const version = "1.26.1-alpha.0";
95776
95828
  importStyles();
95777
95829
 
95778
95830
  exports.TYPES = index;