sea-chart 0.0.95-alpha.3 → 0.0.95-alpha.4

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.
@@ -34,6 +34,15 @@ const calculatorMap = {
34
34
  [CHART_TYPE.TREND]: TrendCalculator,
35
35
  [CHART_TYPE.DASHBOARD]: DashboardCalculator
36
36
  };
37
+ let formulaRowsCache = {};
38
+ let tableRowsLengthMap = {};
39
+ function shouldCache(length, cacheKey) {
40
+ if (length !== tableRowsLengthMap[cacheKey]) {
41
+ tableRowsLengthMap[cacheKey] = length;
42
+ return false;
43
+ }
44
+ return true;
45
+ }
37
46
  class OriginalDataUtils {}
38
47
  _OriginalDataUtils = OriginalDataUtils;
39
48
  OriginalDataUtils.dataSources = 'original_data';
@@ -60,16 +69,25 @@ OriginalDataUtils.calculateChart = async (chart, value, callback) => {
60
69
  } = chart;
61
70
  const {
62
71
  table_id,
72
+ view_id,
63
73
  type
64
74
  } = config || {};
65
75
  const table = getTableById(value.tables, table_id);
66
76
  const calculator = calculatorMap[type] || calculatorMap[BASIC_CHART];
67
77
  const result = await calculator(config, value, {
68
- getViewRows: (view, table) => {
69
- const rows = context.getViewRows(view, table, value);
78
+ getViewRows: async (view, table) => {
79
+ const rows = await context.getViewRows(view, table, value);
70
80
  return rows;
71
81
  },
72
- getTableFormulaResults: (table, rows) => context.getTableFormulaResults(table, rows, value)
82
+ getTableFormulaResults: async (table, rows) => {
83
+ const rowsLength = rows.length;
84
+ const cacheKey = table_id + view_id;
85
+ if (shouldCache(rowsLength, cacheKey) && formulaRowsCache[cacheKey]) {
86
+ return formulaRowsCache[cacheKey];
87
+ }
88
+ const res = await context.getTableFormulaResults(table, rows, value);
89
+ return res;
90
+ }
73
91
  });
74
92
  const groupbyColumn = BaseUtils.getGroupColumn(table, chart);
75
93
  const columnGroupbyColumn = BaseUtils.getColumnGroupColumn(table, chart);
@@ -59,7 +59,6 @@ class TwoDimensionTable extends PureComponent {
59
59
  } = selectedCell || {};
60
60
  const isSelectedTotalCellBottom = selectRowIdx === 0 && selectedCellIdx === (Array.isArray(pivot_columns) ? pivot_columns.length : 0);
61
61
  const isCollaborator = columnGroupbyColumn.type === CellType.COLLABORATOR;
62
- console.log('pivot_columns', pivot_columns);
63
62
  return /*#__PURE__*/React.createElement("thead", {
64
63
  className: "seatable-table-header-sm"
65
64
  }, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.95-alpha.3",
3
+ "version": "0.0.95-alpha.4",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",