sea-chart 0.0.89-alpha.0 → 0.0.89-beta

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.
@@ -111,7 +111,7 @@ class GroupBy extends Component {
111
111
  type: 'text'
112
112
  },
113
113
  label: /*#__PURE__*/React.createElement("span", {
114
- className: 'select-module select-module-name ml-0'
114
+ className: "ml-0"
115
115
  }, intl.get('Not_used'))
116
116
  });
117
117
  }
@@ -84,6 +84,7 @@ OriginalDataUtils.calculateChart = async (chart, value, callback) => {
84
84
  chartTableColumns
85
85
  });
86
86
  } catch (error) {
87
+ console.log('Error', error);
87
88
  const error_message = getErrorMessage(error);
88
89
  return callback && callback(error_message, '', null);
89
90
  }
@@ -284,10 +284,40 @@ async function calculateTwoDimensionTable(chart, value, _ref2) {
284
284
  if (summary_column_key) {
285
285
  summaryColumn = getTableColumnByKey(table, summary_column_key);
286
286
  }
287
+
288
+ // Single field
287
289
  let {
288
290
  pivot_columns_total,
289
291
  pivot_table_total
290
- } = getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formulaRows, pivot_rows, pivot_columns);
292
+ } = getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formulaRows, pivot_rows, pivot_columns, 0);
293
+
294
+ // Multiple field
295
+ if (Array.isArray(summary_columns) && summary_columns.length > 0) {
296
+ summary_columns.forEach((item, index) => {
297
+ if (item && Object.keys(item).length !== 0) {
298
+ const {
299
+ column_key,
300
+ summary_method
301
+ } = item;
302
+ const itemSummaryColumn = getTableColumnByKey(table, column_key);
303
+ const itemSummaryMethod = summary_method;
304
+ if (itemSummaryColumn && itemSummaryMethod) {
305
+ // The index of a single field is 0, so the index of a multiple-select field starts at 1.
306
+ const currentItemIndex = index + 1;
307
+ const {
308
+ pivot_columns_total: item_pivot_columns_total,
309
+ pivot_table_total: item_pivot_table_total
310
+ } = getTwoDimensionTotal(itemSummaryColumn, summary_type, itemSummaryMethod, formulaRows, pivot_rows, pivot_columns, currentItemIndex);
311
+
312
+ // Update pivot_columns_total and pivot_table_total
313
+ Object.keys(item_pivot_columns_total).forEach(key => {
314
+ pivot_columns_total[key] = pivot_columns_total[key] + item_pivot_columns_total[key];
315
+ });
316
+ pivot_table_total = pivot_table_total + item_pivot_table_total;
317
+ }
318
+ }
319
+ });
320
+ }
291
321
  BaseUtils.sortCharts(pivot_rows, groupbyColumn, 'name');
292
322
  BaseUtils.sortCharts(pivot_columns, rowGroupbyColumn, 'key');
293
323
 
@@ -529,6 +559,7 @@ function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isC
529
559
  function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formula_rows) {
530
560
  let pivot_rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
531
561
  let pivot_columns = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
562
+ let index = arguments.length > 6 ? arguments[6] : undefined;
532
563
  let pivot_columns_total = {};
533
564
  let pivot_table_total = 0;
534
565
  let dateColumnsTotalArr = [];
@@ -551,7 +582,7 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
551
582
  let {
552
583
  rows
553
584
  } = cells[key];
554
- let subTotal = getTotal(summaryColumn, summary_type, summary_method, rows, formula_rows, (_cells$key = cells[key]) === null || _cells$key === void 0 ? void 0 : _cells$key.total);
585
+ let subTotal = getTotal(summaryColumn, summary_type, summary_method, rows, formula_rows, (_cells$key = cells[key]) === null || _cells$key === void 0 ? void 0 : _cells$key.total, index);
555
586
  if (isSummaryDateColumn) {
556
587
  if (subTotal === 0) {
557
588
  cells[key].total = 0;
@@ -564,9 +595,9 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
564
595
  } else {
565
596
  if (Array.isArray(subTotal)) {
566
597
  cells[key].total = subTotal;
567
- total += subTotal[0][1] ? subTotal[0][1] - 0 : 0;
598
+ total += subTotal[index][1] ? subTotal[index][1] - 0 : 0;
568
599
  let columnTotal = pivot_columns_total[key] ? pivot_columns_total[key] : 0;
569
- columnTotal += subTotal[0][1] ? subTotal[0][1] - 0 : 0;
600
+ columnTotal += subTotal[index][1] ? subTotal[index][1] - 0 : 0;
570
601
  pivot_columns_total[key] = columnTotal;
571
602
  } else {
572
603
  cells[key].total = subTotal;
@@ -623,6 +654,7 @@ function getTotal(summary_column, summary_type, summary_method) {
623
654
  let rows = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
624
655
  let formula_rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
625
656
  let oldTotal = arguments.length > 5 ? arguments[5] : undefined;
657
+ let index = arguments.length > 6 ? arguments[6] : undefined;
626
658
  const summary_column_key = summary_column ? summary_column.key : '';
627
659
  const summary_column_type = summary_column ? summary_column.type : '';
628
660
  const rowsLength = rows.length;
@@ -654,7 +686,7 @@ function getTotal(summary_column, summary_type, summary_method) {
654
686
  total++;
655
687
  }
656
688
  });
657
- total = getTotalByType(oldTotal, total);
689
+ total = getTotalByType(oldTotal, total, index);
658
690
  return total;
659
691
  }
660
692
  if (summary_column && isDateColumn(summary_column)) {
@@ -712,10 +744,10 @@ function getTotal(summary_column, summary_type, summary_method) {
712
744
  }
713
745
  });
714
746
  if (summary_method === 'Sum') {
715
- total = getTotalByType(oldTotal, Number.parseFloat(sum.toFixed(8)));
747
+ total = getTotalByType(oldTotal, Number.parseFloat(sum.toFixed(8)), index);
716
748
  } else if (summary_method === 'Mean') {
717
749
  const val = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8));
718
- total = getTotalByType(oldTotal, val);
750
+ total = getTotalByType(oldTotal, val, index);
719
751
  }
720
752
  break;
721
753
  }
@@ -748,15 +780,15 @@ function getTotal(summary_column, summary_type, summary_method) {
748
780
  let formulaRow = formula_rows[result._id];
749
781
  if (formulaRow) {
750
782
  if (formulaRow[summary_column_key] && typeof formulaRow[summary_column_key] === 'object') {
751
- total = getTotalByType(oldTotal, formulaRow[summary_column_key][0]);
783
+ total = getTotalByType(oldTotal, formulaRow[summary_column_key][0], index);
752
784
  } else {
753
- getTotalByType(oldTotal, formulaRow[summary_column_key]);
785
+ getTotalByType(oldTotal, formulaRow[summary_column_key], index);
754
786
  }
755
787
  } else {
756
- total = getTotalByType(oldTotal, null);
788
+ total = getTotalByType(oldTotal, null, index);
757
789
  }
758
790
  } else {
759
- total = getTotalByType(oldTotal, result[summary_column_key]);
791
+ total = getTotalByType(oldTotal, result[summary_column_key], index);
760
792
  }
761
793
  }
762
794
  break;
@@ -770,7 +802,7 @@ function getTotal(summary_column, summary_type, summary_method) {
770
802
  }
771
803
  // formula_rows result can be '#VALUE!'
772
804
  if (total === '#VALUE!') {
773
- total = getTotalByType(oldTotal, 0);
805
+ total = getTotalByType(oldTotal, 0, index);
774
806
  }
775
807
  return total || 0;
776
808
  }
@@ -820,11 +852,11 @@ function getDateMaxOrMinTotal(dateArr, type) {
820
852
  dateIndex = list.indexOf(dateValue);
821
853
  return dateArr[dateIndex];
822
854
  }
823
- function getTotalByType(oldTotal, value) {
855
+ function getTotalByType(oldTotal, value, index) {
824
856
  let newTotal = '';
825
857
  if (Array.isArray(oldTotal)) {
826
858
  newTotal = JSON.parse(JSON.stringify(oldTotal));
827
- newTotal[0][1] = value;
859
+ newTotal[index][1] = value;
828
860
  } else {
829
861
  newTotal = value;
830
862
  }
@@ -60,7 +60,7 @@ SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, chart) => {
60
60
  {
61
61
  if (!Array.isArray(collaborators) || collaborators.length === 0) return [];
62
62
  if (!Array.isArray(cellValue) || cellValue.length === 0) return [];
63
- return cellValue;
63
+ return cellValue.filter(email => collaborators.find(option => option.email === email));
64
64
  }
65
65
  case CellType.CREATOR:
66
66
  case CellType.LAST_MODIFIER:
@@ -1,5 +1,6 @@
1
1
  import React, { PureComponent } from 'react';
2
2
  import classnames from 'classnames';
3
+ import { isNumber } from 'dtable-utils';
3
4
  import { BaseUtils } from '../../../utils';
4
5
  import intl from '../../../intl';
5
6
  import { CHART_THEME_COLOR } from '../../../constants';
@@ -22,14 +23,24 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
22
23
  });
23
24
  }
24
25
  };
26
+ this.getRowTotal = (rowTotal, value) => {
27
+ if (value && isNumber(value)) {
28
+ return rowTotal + value;
29
+ }
30
+ return rowTotal;
31
+ };
25
32
  this.renderHeader = () => {
26
33
  const {
27
34
  result,
28
35
  groupbyColumn,
29
36
  columnGroupbyColumn,
30
37
  selectedCell,
31
- chartTableColumns
38
+ chartTableColumns,
39
+ chart
32
40
  } = this.props;
41
+ const {
42
+ display_total = true
43
+ } = chart.config;
33
44
  const {
34
45
  name: groupName
35
46
  } = groupbyColumn;
@@ -43,6 +54,7 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
43
54
  rowIdx: selectRowIdx,
44
55
  cellIdx: selectedCellIdx
45
56
  } = selectedCell || {};
57
+ const isSelectedTotalHeaderBottom = selectRowIdx === 0 && selectedCellIdx === (pivot_columns === null || pivot_columns === void 0 ? void 0 : pivot_columns.length);
46
58
  return /*#__PURE__*/React.createElement("thead", {
47
59
  className: "seatable-table-header-sm"
48
60
  }, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", {
@@ -59,7 +71,11 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
59
71
  }),
60
72
  key: "pivot-column-".concat(index)
61
73
  }, /*#__PURE__*/React.createElement("div", null, column.name));
62
- })));
74
+ }), display_total && /*#__PURE__*/React.createElement("th", {
75
+ className: classnames('pivot-table-header', {
76
+ 'selected-pivot-cell-top': isSelectedTotalHeaderBottom
77
+ })
78
+ }, /*#__PURE__*/React.createElement("div", null, intl.get('Total')))));
63
79
  };
64
80
  this.toggleRecords = (cell, selectedCell) => {
65
81
  if (window.isMobile) return;
@@ -108,13 +124,20 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
108
124
  const pivotRowsLen = Array.isArray(pivot_rows) ? pivot_rows.length : 0;
109
125
  let pivotColumnCells = [];
110
126
  const isSelectRowTotalCellRight = selectRowIdx === pivotRowsLen && selectedCellIdx === 0;
127
+ let lastRowTotal = 0;
128
+ let lastRows = [];
111
129
  return /*#__PURE__*/React.createElement("tbody", null, pivotRowsLen > 0 && pivot_rows.map((rowItem, rowIdx) => {
112
130
  const {
113
131
  name,
114
132
  total,
115
133
  rows
116
134
  } = rowItem;
135
+ lastRows.push(rows);
117
136
  const isSelectedRowNameRight = selectRowIdx === rowIdx && selectedCellIdx === 0;
137
+ const isSelectedTotalCell = selectRowIdx === rowIdx && selectedCellIdx === (pivot_columns === null || pivot_columns === void 0 ? void 0 : pivot_columns.length);
138
+ const isSelectedTotalCellTop = selectRowIdx - 1 === rowIdx && selectedCellIdx === (pivot_columns === null || pivot_columns === void 0 ? void 0 : pivot_columns.length);
139
+ const isSelectedTotalCellLeft = selectRowIdx === rowIdx && selectedCellIdx - 1 === (pivot_columns === null || pivot_columns === void 0 ? void 0 : pivot_columns.length) - 1;
140
+ let rowTotal = 0;
118
141
  if (!Array.isArray(pivot_columns)) {
119
142
  pivotColumnCells[rowIdx] = rowItem.rows || [];
120
143
  }
@@ -137,6 +160,7 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
137
160
  key
138
161
  } = columnMap;
139
162
  const column = chartTableColumns.find(item => item.key === key);
163
+ rowTotal = this.getRowTotal(rowTotal, total[key]);
140
164
  const displayValue = BaseUtils.getSummaryValueDisplayString(column, total[key], this.summaryColumnsMethodMap[key]);
141
165
  const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
142
166
  if (Array.isArray(rows) && rows.length > 0) {
@@ -168,7 +192,25 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
168
192
  'selected-pivot-cell-border': isSelectedCell
169
193
  })
170
194
  }));
171
- }));
195
+ }), display_total && /*#__PURE__*/React.createElement("td", {
196
+ className: classnames('pivot-cell', {
197
+ 'selected-pivot-cell': isSelectedTotalCell,
198
+ 'selected-pivot-cell-top': isSelectedTotalCellTop,
199
+ 'selected-pivot-cell-left': isSelectedTotalCellLeft
200
+ }),
201
+ onClick: () => this.toggleRecords({
202
+ rows,
203
+ name: rowItem === null || rowItem === void 0 ? void 0 : rowItem.name,
204
+ total: rowTotal
205
+ }, {
206
+ rowIdx
207
+ }),
208
+ title: rowTotal ? rowTotal : 0
209
+ }, rowTotal ? rowTotal : /*#__PURE__*/React.createElement("i", null, "0"), /*#__PURE__*/React.createElement("span", {
210
+ className: classnames({
211
+ 'selected-pivot-cell-border': isSelectedTotalCell
212
+ })
213
+ })));
172
214
  }), display_total && /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
173
215
  className: classnames('pivot-column-total', {
174
216
  'selected-pivot-cell-left': isSelectRowTotalCellRight
@@ -181,6 +223,7 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
181
223
  const isValidTotalDisplayValue = BaseUtils.isValidValue(totalDisplayValue, display_empty);
182
224
  const isSelectRowTotalCell = selectRowIdx === pivot_rows.length && selectedCellIdx === index;
183
225
  const isSelectRowTotalCellLeft = selectRowIdx === pivot_rows.length && selectedCellIdx - 1 === index;
226
+ lastRowTotal = this.getRowTotal(lastRowTotal, pivotColumnTotal);
184
227
  return /*#__PURE__*/React.createElement("td", {
185
228
  className: classnames('pivot-cell', {
186
229
  'pivot-empty-cell': !isValidTotalDisplayValue,
@@ -201,7 +244,19 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
201
244
  'selected-pivot-cell-border': isSelectRowTotalCell
202
245
  })
203
246
  }));
204
- })));
247
+ }), /*#__PURE__*/React.createElement("td", {
248
+ className: classnames('pivot-cell', {
249
+ 'pivot-empty-cell': !BaseUtils.isValidValue(lastRowTotal, display_empty)
250
+ }),
251
+ onClick: () => this.toggleRecords({
252
+ rows: lastRows,
253
+ total: lastRowTotal
254
+ }, {
255
+ rowIdx: pivot_rows.length,
256
+ cellIdx: pivot_columns === null || pivot_columns === void 0 ? void 0 : pivot_columns.length
257
+ }),
258
+ title: lastRowTotal
259
+ }, BaseUtils.isValidValue(lastRowTotal, display_empty) ? lastRowTotal : /*#__PURE__*/React.createElement("i", null))));
205
260
  };
206
261
  this.init(_props);
207
262
  }
@@ -1,7 +1,6 @@
1
1
  import React, { PureComponent } from 'react';
2
2
  import classnames from 'classnames';
3
- import { CellType } from 'dtable-utils';
4
- import classNames from 'classnames';
3
+ import { CellType, isNumber } from 'dtable-utils';
5
4
  import { BaseUtils } from '../../../utils';
6
5
  import intl from '../../../intl';
7
6
  import { CHART_SUMMARY_TYPE, CHART_THEME_COLOR } from '../../../constants';
@@ -104,7 +103,7 @@ class TwoDimensionTable extends PureComponent {
104
103
  globalTheme: globalTheme
105
104
  }));
106
105
  })));
107
- }), /*#__PURE__*/React.createElement("th", {
106
+ }), display_total && /*#__PURE__*/React.createElement("th", {
108
107
  className: "pivot-table-header"
109
108
  })));
110
109
  };
@@ -148,6 +147,12 @@ class TwoDimensionTable extends PureComponent {
148
147
  })
149
148
  }, /*#__PURE__*/React.createElement("i", null));
150
149
  };
150
+ this.getRowTotal = (rowTotal, value) => {
151
+ if (value && isNumber(value)) {
152
+ return rowTotal + value;
153
+ }
154
+ return rowTotal;
155
+ };
151
156
  this.renderRows = () => {
152
157
  const {
153
158
  result,
@@ -199,8 +204,7 @@ class TwoDimensionTable extends PureComponent {
199
204
  if (!Array.isArray(pivot_columns)) {
200
205
  pivotColumnCells[rowIdx] = rowItem.rows || [];
201
206
  }
202
- const summaryDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, total, summaryMethod);
203
- const isValidSummaryDisplayValue = BaseUtils.isValidValue(summaryDisplayValue, display_empty);
207
+ let rowTotal = 0;
204
208
  return /*#__PURE__*/React.createElement("tr", {
205
209
  key: 'table-row' + rowIdx
206
210
  }, /*#__PURE__*/React.createElement("td", {
@@ -222,6 +226,7 @@ class TwoDimensionTable extends PureComponent {
222
226
  if (isCount) {
223
227
  const displayValue = total;
224
228
  const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
229
+ rowTotal = this.getRowTotal(rowTotal, displayValue);
225
230
  if (c && Array.isArray(c.rows) && c.rows.length > 0) {
226
231
  pivotRowCells.push(...c.rows);
227
232
  if (pivotColumnCells[cellIdx]) {
@@ -262,6 +267,7 @@ class TwoDimensionTable extends PureComponent {
262
267
  const summaryCellColumn = summaryColumns === null || summaryColumns === void 0 ? void 0 : summaryColumns.find(item => item.key === summaryCellColumnKey);
263
268
  const displayValue = BaseUtils.getSummaryValueDisplayString(summaryCellColumn, summaryCell[1], summaryMethod);
264
269
  const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
270
+ rowTotal = this.getRowTotal(rowTotal, summaryCell[1]);
265
271
  return /*#__PURE__*/React.createElement("div", {
266
272
  key: "table-cell-".concat(cellIdx, "-").concat(idx),
267
273
  className: classnames('pivot-cell', {
@@ -278,7 +284,6 @@ class TwoDimensionTable extends PureComponent {
278
284
  }), !total && !(typeof total === 'number') && this.renderEmpty(summaryColumns, cellIdx)));
279
285
  }), display_total && /*#__PURE__*/React.createElement("td", {
280
286
  className: classnames('pivot-cell', {
281
- 'pivot-empty-cell': !isValidSummaryDisplayValue,
282
287
  'selected-pivot-cell': isSelectedTotalCell,
283
288
  'selected-pivot-cell-top': isSelectedTotalCellTop,
284
289
  'selected-pivot-cell-left': isSelectedTotalCellLeft
@@ -291,8 +296,8 @@ class TwoDimensionTable extends PureComponent {
291
296
  rowIdx,
292
297
  cellIdx: cells.length
293
298
  }),
294
- title: summaryDisplayValue
295
- }, isValidSummaryDisplayValue ? summaryDisplayValue : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
299
+ title: rowTotal
300
+ }, BaseUtils.isValidValue(rowTotal, display_empty) ? rowTotal : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
296
301
  className: classnames({
297
302
  'selected-pivot-cell-border': isSelectedTotalCell
298
303
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.89-alpha.0",
3
+ "version": "0.0.89beta",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",